Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor clean up of python2 syntax #6098

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,4 @@ Patches and Suggestions
- Alessio Izzo (`@aless10 <https://github.com/aless10>`_)
- Sylvain Marié (`@smarie <https://github.com/smarie>`_)
- Hod Bin Noon (`@hodbn <https://github.com/hodbn>`_)
- Maksim Beliaev (`@beliaev-maksim <https://github.com/beliaev-maksim>`_)
6 changes: 3 additions & 3 deletions requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def SOCKSProxyManager(*args, **kwargs):
DEFAULT_POOL_TIMEOUT = None


class BaseAdapter(object):
class BaseAdapter:
"""The Base Transport Adapter"""

def __init__(self):
super(BaseAdapter, self).__init__()
super().__init__()

def send(self, request, stream=False, timeout=None, verify=True,
cert=None, proxies=None):
Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(self, pool_connections=DEFAULT_POOLSIZE,
self.config = {}
self.proxy_manager = {}

super(HTTPAdapter, self).__init__()
super().__init__()

self._pool_connections = pool_connections
self._pool_maxsize = pool_maxsize
Expand Down
2 changes: 1 addition & 1 deletion requests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _basic_auth_str(username, password):
return authstr


class AuthBase(object):
class AuthBase:
"""Base class that all auth implementations derive from"""

def __call__(self, r):
Expand Down
10 changes: 5 additions & 5 deletions requests/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import dummy_threading as threading


class MockRequest(object):
class MockRequest:
"""Wraps a `requests.Request` to mimic a `urllib2.Request`.

The code in `cookielib.CookieJar` expects this interface in order to correctly
Expand Down Expand Up @@ -94,7 +94,7 @@ def host(self):
return self.get_host()


class MockResponse(object):
class MockResponse:
"""Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.

...what? Basically, expose the parsed HTTP headers from the server response
Expand Down Expand Up @@ -314,7 +314,7 @@ def get_dict(self, domain=None, path=None):

def __contains__(self, name):
try:
return super(RequestsCookieJar, self).__contains__(name)
return super().__contains__(name)
except CookieConflictError:
return True

Expand Down Expand Up @@ -343,15 +343,15 @@ def __delitem__(self, name):
def set_cookie(self, cookie, *args, **kwargs):
if hasattr(cookie.value, 'startswith') and cookie.value.startswith('"') and cookie.value.endswith('"'):
cookie.value = cookie.value.replace('\\"', '')
return super(RequestsCookieJar, self).set_cookie(cookie, *args, **kwargs)
return super().set_cookie(cookie, *args, **kwargs)

def update(self, other):
"""Updates this jar with cookies from another CookieJar or dict-like"""
if isinstance(other, cookielib.CookieJar):
for cookie in other:
self.set_cookie(copy.copy(cookie))
else:
super(RequestsCookieJar, self).update(other)
super().update(other)

def _find(self, name, domain=None, path=None):
"""Requests uses this method internally to get cookie values.
Expand Down
2 changes: 1 addition & 1 deletion requests/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
if (response is not None and not self.request and
hasattr(response, 'request')):
self.request = self.response.request
super(RequestException, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class InvalidJSONError(RequestException):
Expand Down
6 changes: 3 additions & 3 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
ITER_CHUNK_SIZE = 512


class RequestEncodingMixin(object):
class RequestEncodingMixin:
@property
def path_url(self):
"""Build the path URL to use."""
Expand Down Expand Up @@ -178,7 +178,7 @@ def _encode_files(files, data):
return body, content_type


class RequestHooksMixin(object):
class RequestHooksMixin:
def register_hook(self, event, hook):
"""Properly register a hook."""

Expand Down Expand Up @@ -586,7 +586,7 @@ def prepare_hooks(self, hooks):
self.register_hook(event, hooks[event])


class Response(object):
class Response:
"""The :class:`Response <Response>` object, which contains a
server's response to an HTTP request.
"""
Expand Down
2 changes: 1 addition & 1 deletion requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict):
return merge_setting(request_hooks, session_hooks, dict_class)


class SessionRedirectMixin(object):
class SessionRedirectMixin:

def get_redirect_target(self, resp):
"""Receives a Response. Returns a redirect URI or ``None``"""
Expand Down
2 changes: 1 addition & 1 deletion requests/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class LookupDict(dict):

def __init__(self, name=None):
self.name = name
super(LookupDict, self).__init__()
super().__init__()

def __repr__(self):
return '<lookup \'%s\'>' % (self.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_system_ssl():
assert info()['system_ssl']['version'] != ''


class VersionedPackage(object):
class VersionedPackage:
def __init__(self, version):
self.__version__ = version

Expand Down
4 changes: 2 additions & 2 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def test_invalid_files_input(self, httpbin):

def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):

class TestStream(object):
class TestStream:
def __init__(self, data):
self.data = data.encode()
self.length = len(self.data)
Expand Down Expand Up @@ -2499,7 +2499,7 @@ def test_urllib3_pool_connection_closed(httpbin):
assert u"Pool is closed." in str(e)


class TestPreparingURLs(object):
class TestPreparingURLs:
@pytest.mark.parametrize(
'url,expected',
(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_super_len_correctly_calculates_len_of_partially_read_file(self):
@pytest.mark.parametrize('error', [IOError, OSError])
def test_super_len_handles_files_raising_weird_errors_in_tell(self, error):
"""If tell() raises errors, assume the cursor is at position zero."""
class BoomFile(object):
class BoomFile:
def __len__(self):
return 5

Expand All @@ -63,7 +63,7 @@ def tell(self):
@pytest.mark.parametrize('error', [IOError, OSError])
def test_super_len_tell_ioerror(self, error):
"""Ensure that if tell gives an IOError super_len doesn't fail"""
class NoLenBoomFile(object):
class NoLenBoomFile:
def tell(self):
raise error()

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_super_len_with__len__(self):
assert len_foo == 4

def test_super_len_with_no__len__(self):
class LenFile(object):
class LenFile:
def __init__(self):
self.len = 5

Expand Down
2 changes: 1 addition & 1 deletion tests/testserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Server(threading.Thread):
WAIT_EVENT_TIMEOUT = 5

def __init__(self, handler=None, host='localhost', port=0, requests_to_handle=1, wait_to_close_event=None):
super(Server, self).__init__()
super().__init__()

self.handler = handler or consume_socket_content
self.handler_results = []
Expand Down