Skip to content
Myr

Merge pull request #766 from Lukasa/develop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Accept objects with string representations as URLs.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents bc7b2f9, 6166ba7 · Browse files · 2 files+26 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+26 added−1 removed

  • tests:+18 added−0 removed
  • other:+8 added−1 removed

2 files+26 added−1 removed

modified:requests/models.py+8 added-1 removed
69 unmodified lines
70 # (Use socket.setdefaulttimeout() as fallback)71 self.timeout = timeout7273 #: Request URL.74 #: Accept objects that have string representations.75 try:76 self.url = unicode(url)77 except NameError:78 # We're on Python 3.79 self.url = str(url)80 except UnicodeDecodeError:74 self.url = url81 self.url = url8283 #: Dictionary of HTTP Headers to attach to the :class:`Request <Request>`.84 self.headers = dict(headers or [])85
773 unmodified lines
modified:tests/test_requests.py+18 added
994 unmodified lines
995 # content should not have been prefetched, and iter_lines should succeed996 first_line = next(req.response.iter_lines())997 self.assertTrue(first_line.strip().decode('utf-8').startswith('{'))998999 def test_accept_objects_with_string_representations_as_urls(self):1000 """Test that URLs can be set to objects with string representations,1001 e.g. for use with furl."""1002 class URL():1003 def __unicode__(self):1004 # Can't have unicode literals in Python3, so avoid them.1005 # TODO: fixup when moving to Python 3.31006 if (sys.version_info[0] == 2):1007 return 'http://httpbin.org/get'.decode('utf-8')1008 else:1009 return 'http://httpbin.org/get'10101011 def __str__(self):1012 return 'http://httpbin.org/get'10131014 r = get(URL())1015 self.assertEqual(r.status_code, 200)10161017if __name__ == '__main__':1018 unittest.main()