Skip to content

Commit 46dcb7f

Browse files
MichaelsJPclaudepkoebi
authored
chore: Remove old Python2 syntax (#86)
Co-authored-by: Julian Psotta <[email protected]> Co-authored-by: Claude Paroz <[email protected]> Co-authored-by: Jakob Schnell <[email protected]>
1 parent 77a1219 commit 46dcb7f

File tree

7 files changed

+9
-53
lines changed

7 files changed

+9
-53
lines changed

docs/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
#
32
# openrouteservice-py documentation build configuration file, created by
43
# sphinx-quickstart on Wed Jan 31 20:43:55 2018.
54
#

openrouteservice/client.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from datetime import datetime
2222
from datetime import timedelta
23+
from urllib.parse import urlencode
2324
import cgi
2425
import functools
2526
import requests
@@ -30,18 +31,13 @@
3031

3132
from openrouteservice import exceptions, __version__, get_ordinal
3233

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-
3834
_USER_AGENT = "ORSClientPython.v{}".format(__version__)
3935
_DEFAULT_BASE_URL = "https://api.openrouteservice.org"
4036

4137
_RETRIABLE_STATUSES = set([503]) # noqa
4238

4339

44-
class Client(object):
40+
class Client:
4541
"""Performs requests to the ORS API services."""
4642

4743
def __init__(
@@ -360,34 +356,8 @@ def _urlencode_params(params):
360356
361357
:rtype: string
362358
"""
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
367361
# by urllib.urlencode, causing invalid auth signatures. See GH #72
368362
# for more info.
369363
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

openrouteservice/elevation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
32
# Copyright (C) 2018 HeiGIT, University of Heidelberg.
43
#
54
#

openrouteservice/optimization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def optimization(
101101
)
102102

103103

104-
class Job(object):
104+
class Job:
105105
"""
106106
Class to create a Job object for optimization endpoint.
107107
@@ -172,7 +172,7 @@ def __init__(
172172
self.time_windows = time_windows
173173

174174

175-
class ShipmentStep(object):
175+
class ShipmentStep:
176176
"""
177177
Class to create a Shipment object for optimization endpoint.
178178
@@ -222,7 +222,7 @@ def __init__(
222222
self.time_windows = time_windows
223223

224224

225-
class Shipment(object):
225+
class Shipment:
226226
"""
227227
Class to create a Shipment object for optimization endpoint.
228228
@@ -272,7 +272,7 @@ def __init__(
272272
self.priority = priority
273273

274274

275-
class Vehicle(object):
275+
class Vehicle:
276276
"""
277277
Class to create a Vehicle object for optimization endpoint.
278278

openrouteservice/places.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
32
# Copyright (C) 2018 HeiGIT, University of Heidelberg.
43
#
54
#

test/__init__.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
#
1818

1919
import unittest
20-
import codecs
2120
import openrouteservice
2221

23-
try: # Python 3
24-
from urllib.parse import urlparse, parse_qsl
25-
except ImportError: # Python 2
26-
from urlparse import urlparse, parse_qsl
22+
from urllib.parse import urlparse, parse_qsl
2723

2824
# For relative imports to work in Python 3.6
2925
import os
@@ -49,12 +45,6 @@ def assertURLEqual(self, first, second, msg=None):
4945
second_qsl = sorted(parse_qsl(second_parsed.query))
5046
self.assertEqual(first_qsl, second_qsl, msg)
5147

52-
@staticmethod
53-
def u(string):
54-
"""Create a unicode string, compatible across all versions of Python."""
55-
# NOTE(cbro): Python 3-3.2 does not have the u'' syntax.
56-
return codecs.unicode_escape_decode(string)[0]
57-
5848
def assertDictContainsSubset(self, a, b, **kwargs):
5949
"""Replaces deprecated unittest.TestCase.assertDictContainsSubset"""
6050
c = dict([(k, b[k]) for k in a.keys() if k in b.keys()])

test/test_elevation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
32
# Copyright (C) 2018 HeiGIT, University of Heidelberg.
43
#
54
#

0 commit comments

Comments
 (0)