|
20 | 20 |
|
21 | 21 | from datetime import datetime |
22 | 22 | from datetime import timedelta |
| 23 | +from urllib.parse import urlencode |
23 | 24 | import cgi |
24 | 25 | import functools |
25 | 26 | import requests |
|
30 | 31 |
|
31 | 32 | from openrouteservice import exceptions, __version__, get_ordinal |
32 | 33 |
|
33 | | -try: # Python 3 |
34 | | - from urllib.parse import urlencode |
35 | | -except ImportError: # pragma: no cover # Python 2 |
36 | | - from urllib import urlencode # noqa |
37 | | - |
38 | 34 | _USER_AGENT = "ORSClientPython.v{}".format(__version__) |
39 | 35 | _DEFAULT_BASE_URL = "https://api.openrouteservice.org" |
40 | 36 |
|
41 | 37 | _RETRIABLE_STATUSES = set([503]) # noqa |
42 | 38 |
|
43 | 39 |
|
44 | | -class Client(object): |
| 40 | +class Client: |
45 | 41 | """Performs requests to the ORS API services.""" |
46 | 42 |
|
47 | 43 | def __init__( |
@@ -360,34 +356,8 @@ def _urlencode_params(params): |
360 | 356 |
|
361 | 357 | :rtype: string |
362 | 358 | """ |
363 | | - # urlencode does not handle unicode strings in Python 2. |
364 | | - # Firstly, normalize the values so they get encoded correctly. |
365 | | - params = [(key, _normalize_for_urlencode(val)) for key, val in params] |
366 | | - # Secondly, unquote unreserved chars which are incorrectly quoted |
| 359 | + params = [(key, val) for key, val in params] |
| 360 | + # Unquote unreserved chars which are incorrectly quoted |
367 | 361 | # by urllib.urlencode, causing invalid auth signatures. See GH #72 |
368 | 362 | # for more info. |
369 | 363 | return requests.utils.unquote_unreserved(urlencode(params)) |
370 | | - |
371 | | - |
372 | | -try: |
373 | | - unicode # noqa |
374 | | - |
375 | | - # NOTE(cbro): `unicode` was removed in Python 3. In Python 3, NameError is |
376 | | - # raised here, and caught below. |
377 | | - |
378 | | - def _normalize_for_urlencode(value): # pragma: no cover |
379 | | - """(Python 2) Converts the value to a `str` (raw bytes).""" |
380 | | - if isinstance(value, unicode): # noqa |
381 | | - return value.encode("utf8") |
382 | | - |
383 | | - if isinstance(value, str): |
384 | | - return value |
385 | | - |
386 | | - return _normalize_for_urlencode(str(value)) |
387 | | - |
388 | | -except NameError: |
389 | | - |
390 | | - def _normalize_for_urlencode(value): |
391 | | - """(Python 3) No-op.""" |
392 | | - # urlencode in Python 3 handles all the types we are passing it. |
393 | | - return value |
0 commit comments