summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.org>2018-03-12 11:45:29 -0400
committerKenneth Reitz <me@kennethreitz.org>2018-03-12 11:45:29 -0400
commit4e76e142d11229a4511086e09cefb33adab28325 (patch)
treeb42196d1f091bf50eb366c24cc7bae93fc531aec
parentd207c345968857d488ed573b56b8ea20cc0d41de (diff)
downloadpython-requests-threedotoh.tar.gz
working on itthreedotoh
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
-rw-r--r--requests/compat.py2
-rw-r--r--requests/models.py2
-rw-r--r--tests/test_requests.py32
-rw-r--r--tests/test_utils.py23
4 files changed, 24 insertions, 35 deletions
diff --git a/requests/compat.py b/requests/compat.py
index 67b19e10..94039379 100644
--- a/requests/compat.py
+++ b/requests/compat.py
@@ -11,3 +11,5 @@ Python 3.
basestring = (str, bytes)
numeric_types = (int, float)
integer_types = (int,)
+bytes = bytes
+str = str \ No newline at end of file
diff --git a/requests/models.py b/requests/models.py
index bc6e9ade..a749e11c 100644
--- a/requests/models.py
+++ b/requests/models.py
@@ -503,7 +503,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
length = super_len(body)
if length:
- self.headers['Content-Length'] = builtin_str(length)
+ self.headers['Content-Length'] = str(length)
elif is_stream(body):
self.headers['Transfer-Encoding'] = 'chunked'
else:
diff --git a/tests/test_requests.py b/tests/test_requests.py
index 14120a2c..16a8cbd7 100644
--- a/tests/test_requests.py
+++ b/tests/test_requests.py
@@ -9,6 +9,7 @@ import pickle
import collections
import contextlib
import warnings
+from urllib.parse import urlparse
import io
import requests
@@ -16,11 +17,10 @@ import pytest
import pytest_httpbin
from requests.adapters import HTTPAdapter
from requests.auth import HTTPDigestAuth, _basic_auth_str
-from requests.compat import (
- Morsel, cookielib, getproxies, str, urlparse,
- builtin_str)
+
from requests.cookies import (
- cookiejar_from_dict, morsel_to_cookie)
+ Morsel, cookielib, cookiejar_from_dict, morsel_to_cookie
+)
from requests.exceptions import (
ConnectionError, ConnectTimeout, InvalidScheme, InvalidURL,
MissingScheme, ReadTimeout, Timeout, RetryError, TooManyRedirects,
@@ -33,7 +33,6 @@ from requests.models import urlencode
from requests.hooks import default_hooks
from requests.utils import DEFAULT_CA_BUNDLE_PATH
-from .compat import StringIO, u
from .utils import override_environ
from urllib3.util import Timeout as Urllib3Timeout
@@ -849,7 +848,6 @@ class TestRequests:
url = httpbin('post')
with open('Pipfile') as f:
pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})")
- pytest.raises(ValueError, "requests.post(url, data=u('[{\"some\": \"data\"}]'), files={'some': f})")
def test_request_ok_set(self, httpbin):
r = requests.get(httpbin('status', '404'))
@@ -956,8 +954,8 @@ class TestRequests:
@pytest.mark.parametrize('data',
(
- {'stuff': u('ëlïxr')},
- {'stuff': u('ëlïxr').encode('utf-8')},
+ {'stuff': 'ëlïxr'},
+ {'stuff': 'ëlïxr'.encode('utf-8')},
{'stuff': 'elixr'},
{'stuff': 'elixr'.encode('utf-8')},
))
@@ -980,13 +978,13 @@ class TestRequests:
def test_unicode_method_name(self, httpbin):
files = {'file': open(__file__, 'rb')}
r = requests.request(
- method=u('POST'), url=httpbin('post'), files=files)
+ method='POST', url=httpbin('post'), files=files)
assert r.status_code == 200
def test_unicode_method_name_with_request_object(self, httpbin):
files = {'file': open(__file__, 'rb')}
s = requests.Session()
- req = requests.Request(u('POST'), httpbin('post'), files=files)
+ req = requests.Request('POST', httpbin('post'), files=files)
prep = s.prepare_request(req)
assert isinstance(prep.method, builtin_str)
assert prep.method == 'POST'
@@ -996,7 +994,7 @@ class TestRequests:
def test_non_prepared_request_error(self):
s = requests.Session()
- req = requests.Request(u('POST'), '/')
+ req = requests.Request('POST', '/')
with pytest.raises(ValueError) as e:
s.send(req)
@@ -1263,7 +1261,7 @@ class TestRequests:
def test_response_is_iterable(self):
r = requests.Response()
- io = StringIO.StringIO('abc')
+ io = io.StringIO('abc')
read_ = io.read
def read_mock(amt, decode_content=None):
@@ -1612,7 +1610,7 @@ class TestRequests:
assert r.url == url
def test_header_keys_are_native(self, httpbin):
- headers = {u('unicode'): 'blah', 'byte'.encode('ascii'): 'blah'}
+ headers = {'unicode': 'blah', 'byte'.encode('ascii'): 'blah'}
r = requests.Request('GET', httpbin('get'), headers=headers)
p = r.prepare()
@@ -2033,7 +2031,7 @@ class TestRequests:
Should work when `release_conn` attr doesn't exist on `response.raw`.
"""
resp = requests.Response()
- resp.raw = StringIO.StringIO('test')
+ resp.raw = io.StringIO('test')
assert not resp.raw.closed
resp.close()
assert resp.raw.closed
@@ -2130,7 +2128,7 @@ class TestRequests:
(None, ('Content-Length', '0')),
('test_data', ('Content-Length', '9')),
(io.BytesIO(b'test_data'), ('Content-Length', '9')),
- (StringIO.StringIO(''), ('Transfer-Encoding', 'chunked'))
+ (io.StringIO(''), ('Transfer-Encoding', 'chunked'))
))
def test_prepare_content_length(self, httpbin, body, expected):
"""Test prepare_content_length creates expected header."""
@@ -2515,7 +2513,7 @@ class RedirectSession(SessionRedirectMixin):
return r
def _build_raw(self):
- string = StringIO.StringIO('')
+ string = io.StringIO('')
setattr(string, 'release_conn', lambda *args: args)
return string
@@ -2612,7 +2610,7 @@ def test_data_argument_accepts_tuples(data):
},
{
'method': 'GET',
- 'url': u('http://www.example.com/üniçø∂é')
+ 'url': 'http://www.example.com/üniçø∂é'
},
))
def test_prepared_copy(kwargs):
diff --git a/tests/test_utils.py b/tests/test_utils.py
index e7d32384..44f9b2c0 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -16,21 +16,20 @@ from requests.utils import (
is_valid_cidr, iter_slices, parse_dict_header,
parse_header_links, prepend_scheme_if_needed,
requote_uri, select_proxy, should_bypass_proxies, super_len,
- to_key_val_list, to_native_string,
+ to_key_val_list,
unquote_header_value, unquote_unreserved,
urldefragauth, add_dict_to_cookiejar, set_environ)
from requests._internal_utils import unicode_is_ascii
-from .compat import StringIO, cStringIO
+from io import StringIO
class TestSuperLen:
@pytest.mark.parametrize(
'stream, value', (
- (StringIO.StringIO, 'Test'),
- (BytesIO, b'Test'),
- pytest.mark.skipif('cStringIO is None')((cStringIO, 'Test')),
+ (StringIO, 'Test'),
+ (BytesIO, b'Test')
))
def test_io_streams(self, stream, value):
"""Ensures that we properly deal with different kinds of IO streams."""
@@ -39,7 +38,7 @@ class TestSuperLen:
def test_super_len_correctly_calculates_len_of_partially_read_file(self):
"""Ensure that we handle partially consumed file like objects."""
- s = StringIO.StringIO()
+ s = StringIO()
s.write('foobarbogus')
assert super_len(s) == 0
@@ -95,7 +94,7 @@ class TestSuperLen:
assert super_len(LenFile()) == 5
def test_super_len_with_tell(self):
- foo = StringIO.StringIO('12345')
+ foo = StringIO('12345')
assert super_len(foo) == 5
foo.read(2)
assert super_len(foo) == 3
@@ -517,16 +516,6 @@ def test_prepend_scheme_if_needed(value, expected):
@pytest.mark.parametrize(
- 'value, expected', (
- ('T', 'T'),
- (b'T', 'T'),
- (u'T', 'T'),
- ))
-def test_to_native_string(value, expected):
- assert to_native_string(value) == expected
-
-
-@pytest.mark.parametrize(
'url, expected', (
('http://u:p@example.com/path?a=1#test', 'http://example.com/path?a=1'),
('http://example.com/path', 'http://example.com/path'),