mirror of https://github.com/python/cpython
Megre from tip
This commit is contained in:
commit
8247b188f3
|
@ -385,12 +385,6 @@ request.
|
||||||
|
|
||||||
.. versionadded:: 3.3
|
.. versionadded:: 3.3
|
||||||
|
|
||||||
.. method:: Request.add_data(data)
|
|
||||||
|
|
||||||
Set the :class:`Request` data to *data*. This is ignored by all handlers except
|
|
||||||
HTTP handlers --- and there it should be a byte string, and will change the
|
|
||||||
request to be ``POST`` rather than ``GET``.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.get_method()
|
.. method:: Request.get_method()
|
||||||
|
|
||||||
|
@ -403,16 +397,6 @@ request.
|
||||||
get_method now looks at the value of :attr:`Request.method`.
|
get_method now looks at the value of :attr:`Request.method`.
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.has_data()
|
|
||||||
|
|
||||||
Return whether the instance has a non-\ ``None`` data.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.get_data()
|
|
||||||
|
|
||||||
Return the instance's data.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.add_header(key, val)
|
.. method:: Request.add_header(key, val)
|
||||||
|
|
||||||
Add another header to the request. Headers are currently ignored by all
|
Add another header to the request. Headers are currently ignored by all
|
||||||
|
@ -440,21 +424,6 @@ request.
|
||||||
Return the URL given in the constructor.
|
Return the URL given in the constructor.
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.get_type()
|
|
||||||
|
|
||||||
Return the type of the URL --- also known as the scheme.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.get_host()
|
|
||||||
|
|
||||||
Return the host to which a connection will be made.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.get_selector()
|
|
||||||
|
|
||||||
Return the selector --- the part of the URL that is sent to the server.
|
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.set_proxy(host, type)
|
.. method:: Request.set_proxy(host, type)
|
||||||
|
|
||||||
Prepare the request by connecting to a proxy server. The *host* and *type* will
|
Prepare the request by connecting to a proxy server. The *host* and *type* will
|
||||||
|
@ -462,16 +431,71 @@ request.
|
||||||
URL given in the constructor.
|
URL given in the constructor.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: Request.add_data(data)
|
||||||
|
|
||||||
|
Set the :class:`Request` data to *data*. This is ignored by all handlers except
|
||||||
|
HTTP handlers --- and there it should be a byte string, and will change the
|
||||||
|
request to be ``POST`` rather than ``GET``. Deprecated in 3.3, use
|
||||||
|
:attr:`Request.data`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: Request.has_data()
|
||||||
|
|
||||||
|
Return whether the instance has a non-\ ``None`` data. Deprecated in 3.3,
|
||||||
|
use :attr:`Request.data`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: Request.get_data()
|
||||||
|
|
||||||
|
Return the instance's data. Deprecated in 3.3, use :attr:`Request.data`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: Request.get_type()
|
||||||
|
|
||||||
|
Return the type of the URL --- also known as the scheme. Deprecated in 3.3,
|
||||||
|
use :attr:`Request.type`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: Request.get_host()
|
||||||
|
|
||||||
|
Return the host to which a connection will be made. Deprecated in 3.3, use
|
||||||
|
:attr:`Request.host`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: Request.get_selector()
|
||||||
|
|
||||||
|
Return the selector --- the part of the URL that is sent to the server.
|
||||||
|
Deprecated in 3.3, use :attr:`Request.selector`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.get_origin_req_host()
|
.. method:: Request.get_origin_req_host()
|
||||||
|
|
||||||
Return the request-host of the origin transaction, as defined by :rfc:`2965`.
|
Return the request-host of the origin transaction, as defined by
|
||||||
See the documentation for the :class:`Request` constructor.
|
:rfc:`2965`. See the documentation for the :class:`Request` constructor.
|
||||||
|
Deprecated in 3.3, use :attr:`Request.origin_req_host`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
.. method:: Request.is_unverifiable()
|
.. method:: Request.is_unverifiable()
|
||||||
|
|
||||||
Return whether the request is unverifiable, as defined by RFC 2965. See the
|
Return whether the request is unverifiable, as defined by RFC 2965. See the
|
||||||
documentation for the :class:`Request` constructor.
|
documentation for the :class:`Request` constructor. Deprecated in 3.3, use
|
||||||
|
:attr:`Request.is_unverifiable`.
|
||||||
|
|
||||||
|
.. deprecated:: 3.3
|
||||||
|
|
||||||
|
|
||||||
.. _opener-director-objects:
|
.. _opener-director-objects:
|
||||||
|
|
|
@ -298,6 +298,10 @@ Content-Type: text/html; charset=iso-8859-1
|
||||||
finally:
|
finally:
|
||||||
self.unfakehttp()
|
self.unfakehttp()
|
||||||
|
|
||||||
|
def test_URLopener_deprecation(self):
|
||||||
|
with support.check_warnings(('',DeprecationWarning)):
|
||||||
|
warn = urllib.request.URLopener()
|
||||||
|
|
||||||
class urlretrieve_FileTests(unittest.TestCase):
|
class urlretrieve_FileTests(unittest.TestCase):
|
||||||
"""Test urllib.urlretrieve() on local files"""
|
"""Test urllib.urlretrieve() on local files"""
|
||||||
|
|
||||||
|
|
|
@ -553,10 +553,6 @@ class OpenerDirectorTests(unittest.TestCase):
|
||||||
self.assertRaises(urllib.error.URLError, o.open, req)
|
self.assertRaises(urllib.error.URLError, o.open, req)
|
||||||
self.assertEqual(o.calls, [(handlers[0], "http_open", (req,), {})])
|
self.assertEqual(o.calls, [(handlers[0], "http_open", (req,), {})])
|
||||||
|
|
||||||
## def test_error(self):
|
|
||||||
## # XXX this doesn't actually seem to be used in standard library,
|
|
||||||
## # but should really be tested anyway...
|
|
||||||
|
|
||||||
def test_http_error(self):
|
def test_http_error(self):
|
||||||
# XXX http_error_default
|
# XXX http_error_default
|
||||||
# http errors are a special case
|
# http errors are a special case
|
||||||
|
@ -584,6 +580,7 @@ class OpenerDirectorTests(unittest.TestCase):
|
||||||
self.assertEqual((handler, method_name), got[:2])
|
self.assertEqual((handler, method_name), got[:2])
|
||||||
self.assertEqual(args, got[2])
|
self.assertEqual(args, got[2])
|
||||||
|
|
||||||
|
|
||||||
def test_processors(self):
|
def test_processors(self):
|
||||||
# *_request / *_response methods get called appropriately
|
# *_request / *_response methods get called appropriately
|
||||||
o = OpenerDirector()
|
o = OpenerDirector()
|
||||||
|
@ -619,6 +616,24 @@ class OpenerDirectorTests(unittest.TestCase):
|
||||||
self.assertTrue(args[1] is None or
|
self.assertTrue(args[1] is None or
|
||||||
isinstance(args[1], MockResponse))
|
isinstance(args[1], MockResponse))
|
||||||
|
|
||||||
|
def test_method_deprecations(self):
|
||||||
|
req = Request("http://www.example.com")
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.add_data("data")
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.has_data()
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.get_data()
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.get_full_url()
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.get_host()
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.get_selector()
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.is_unverifiable()
|
||||||
|
with support.check_warnings(('', DeprecationWarning)):
|
||||||
|
req.get_origin_req_host()
|
||||||
|
|
||||||
def sanepathname2url(path):
|
def sanepathname2url(path):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# mock.py
|
# mock.py
|
||||||
# Test tools for mocking and patching.
|
# Test tools for mocking and patching.
|
||||||
|
# Maintained by Michael Foord
|
||||||
|
# Backport for other versions of Python available from
|
||||||
|
# http://pypi.python.org/pypi/mock
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Mock',
|
'Mock',
|
||||||
|
@ -259,11 +262,6 @@ _missing = sentinel.MISSING
|
||||||
_deleted = sentinel.DELETED
|
_deleted = sentinel.DELETED
|
||||||
|
|
||||||
|
|
||||||
class OldStyleClass:
|
|
||||||
pass
|
|
||||||
ClassType = type(OldStyleClass)
|
|
||||||
|
|
||||||
|
|
||||||
def _copy(value):
|
def _copy(value):
|
||||||
if type(value) in (dict, list, tuple, set):
|
if type(value) in (dict, list, tuple, set):
|
||||||
return type(value)(value)
|
return type(value)(value)
|
||||||
|
|
|
@ -96,6 +96,7 @@ import time
|
||||||
import collections
|
import collections
|
||||||
import tempfile
|
import tempfile
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
from urllib.error import URLError, HTTPError, ContentTooShortError
|
from urllib.error import URLError, HTTPError, ContentTooShortError
|
||||||
|
@ -291,36 +292,52 @@ class Request:
|
||||||
else:
|
else:
|
||||||
return "GET"
|
return "GET"
|
||||||
|
|
||||||
# Begin deprecated methods
|
|
||||||
|
|
||||||
def add_data(self, data):
|
|
||||||
self.data = data
|
|
||||||
|
|
||||||
def has_data(self):
|
|
||||||
return self.data is not None
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
return self.data
|
|
||||||
|
|
||||||
def get_full_url(self):
|
def get_full_url(self):
|
||||||
if self.fragment:
|
if self.fragment:
|
||||||
return '%s#%s' % (self.full_url, self.fragment)
|
return '%s#%s' % (self.full_url, self.fragment)
|
||||||
else:
|
else:
|
||||||
return self.full_url
|
return self.full_url
|
||||||
|
|
||||||
|
# Begin deprecated methods
|
||||||
|
|
||||||
|
def add_data(self, data):
|
||||||
|
msg = "Request.add_data method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
def has_data(self):
|
||||||
|
msg = "Request.has_data method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
|
return self.data is not None
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
msg = "Request.get_data method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
|
return self.data
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
|
msg = "Request.get_type method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
return self.type
|
return self.type
|
||||||
|
|
||||||
def get_host(self):
|
def get_host(self):
|
||||||
|
msg = "Request.get_host method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
return self.host
|
return self.host
|
||||||
|
|
||||||
def get_selector(self):
|
def get_selector(self):
|
||||||
|
msg = "Request.get_selector method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
return self.selector
|
return self.selector
|
||||||
|
|
||||||
def is_unverifiable(self):
|
def is_unverifiable(self):
|
||||||
|
msg = "Request.is_unverifiable method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
return self.unverifiable
|
return self.unverifiable
|
||||||
|
|
||||||
def get_origin_req_host(self):
|
def get_origin_req_host(self):
|
||||||
|
msg = "Request.get_origin_req_host method is deprecated."
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=1)
|
||||||
return self.origin_req_host
|
return self.origin_req_host
|
||||||
|
|
||||||
# End deprecated methods
|
# End deprecated methods
|
||||||
|
@ -1552,6 +1569,9 @@ class URLopener:
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
def __init__(self, proxies=None, **x509):
|
def __init__(self, proxies=None, **x509):
|
||||||
|
msg = "%(class)s style of invoking requests is deprecated."\
|
||||||
|
"Use newer urlopen functions/methods" % {'class': self.__class__.__name__}
|
||||||
|
warnings.warn(msg, DeprecationWarning, stacklevel=3)
|
||||||
if proxies is None:
|
if proxies is None:
|
||||||
proxies = getproxies()
|
proxies = getproxies()
|
||||||
assert hasattr(proxies, 'keys'), "proxies must be a mapping"
|
assert hasattr(proxies, 'keys'), "proxies must be a mapping"
|
||||||
|
@ -1753,7 +1773,6 @@ class URLopener:
|
||||||
if proxy_bypass(realhost):
|
if proxy_bypass(realhost):
|
||||||
host = realhost
|
host = realhost
|
||||||
|
|
||||||
#print "proxy via http:", host, selector
|
|
||||||
if not host: raise IOError('http error', 'no host given')
|
if not host: raise IOError('http error', 'no host given')
|
||||||
|
|
||||||
if proxy_passwd:
|
if proxy_passwd:
|
||||||
|
@ -2554,7 +2573,6 @@ elif os.name == 'nt':
|
||||||
test = test.replace("*", r".*") # change glob sequence
|
test = test.replace("*", r".*") # change glob sequence
|
||||||
test = test.replace("?", r".") # change glob char
|
test = test.replace("?", r".") # change glob char
|
||||||
for val in host:
|
for val in host:
|
||||||
# print "%s <--> %s" %( test, val )
|
|
||||||
if re.match(test, val, re.I):
|
if re.match(test, val, re.I):
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue