Skip to content

Commit fa23062

Browse files
committed
Reformatted to pep-8 specification
1 parent 244cecc commit fa23062

19 files changed

+993
-955
lines changed

docs/source/conf.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#
1919
import os
2020
import sys
21-
#sys.path.insert(0, 'C:\\Users\\gisadmin\\Documents\\Dev\\Git\\Uni\\ORS\\infrastructure\\SDK\\openrouteservice-python-api\\openrouteservice')
21+
22+
# sys.path.insert(0, 'C:\\Users\\gisadmin\\Documents\\Dev\\Git\\Uni\\ORS\\infrastructure\\SDK\\openrouteservice-python-api\\openrouteservice')
2223
sys.path.insert(0, os.path.abspath('../..'))
2324

2425
# -- General configuration ------------------------------------------------
@@ -30,9 +31,11 @@
3031
# Add any Sphinx extension module names here, as strings. They can be
3132
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3233
# ones.
33-
extensions = ['sphinx.ext.autodoc',
34+
extensions = [
35+
'sphinx.ext.autodoc',
3436
'sphinx.ext.todo',
35-
'sphinx.ext.coverage']
37+
'sphinx.ext.coverage'
38+
]
3639

3740
# Add any paths that contain templates here, relative to this directory.
3841
templates_path = ['.templates']
@@ -78,7 +81,6 @@
7881
# If true, `todo` and `todoList` produce output, else they produce nothing.
7982
todo_include_todos = True
8083

81-
8284
# -- Options for HTML output ----------------------------------------------
8385

8486
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -112,13 +114,11 @@
112114
]
113115
}
114116

115-
116117
# -- Options for HTMLHelp output ------------------------------------------
117118

118119
# Output file base name for HTML help builder.
119120
htmlhelp_basename = 'openrouteservice-pydoc'
120121

121-
122122
# -- Options for LaTeX output ---------------------------------------------
123123

124124
latex_elements = {
@@ -147,7 +147,6 @@
147147
u'Nils Nolde', 'manual'),
148148
]
149149

150-
151150
# -- Options for manual page output ---------------------------------------
152151

153152
# One entry per manual page. List of tuples
@@ -157,7 +156,6 @@
157156
[author], 1)
158157
]
159158

160-
161159
# -- Options for Texinfo output -------------------------------------------
162160

163161
# Grouping the document tree into Texinfo files. List of tuples
@@ -168,6 +166,3 @@
168166
author, 'openrouteservice-py', 'One line description of project.',
169167
'Miscellaneous'),
170168
]
171-
172-
173-

openrouteservice/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
__version__ = "2.0.0"
2121

22+
2223
# Make sure QGIS plugin can import openrouteservice-py
2324

2425

@@ -37,4 +38,4 @@ def get_ordinal(number):
3738

3839
from openrouteservice.client import Client
3940
## Allow sphinx to pick up these symbols for the documentation.
40-
#__all__ = ["Client"]
41+
# __all__ = ["Client"]

openrouteservice/client.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232

3333
from openrouteservice import exceptions, __version__, get_ordinal
3434

35-
try: # Python 3
35+
try: # Python 3
3636
from urllib.parse import urlencode
37-
except ImportError: # Python 2
37+
except ImportError: # Python 2
3838
from urllib import urlencode
3939

40-
4140
_USER_AGENT = "ORSClientPython.v{}".format(__version__)
4241
_DEFAULT_BASE_URL = "https://api.openrouteservice.org"
4342

4443
_RETRIABLE_STATUSES = set([503])
4544

45+
4646
class Client(object):
4747
"""Performs requests to the ORS API services."""
4848

@@ -91,16 +91,19 @@ def __init__(self,
9191
self._base_url = base_url
9292

9393
if self._base_url == _DEFAULT_BASE_URL and key is None:
94-
raise ValueError("No API key was specified. Please visit https://openrouteservice.org/sign-up to create one.")
94+
raise ValueError(
95+
"No API key was specified. Please visit https://openrouteservice.org/sign-up to create one.")
9596

9697
self._timeout = timeout
9798
self._retry_over_query_limit = retry_over_query_limit
9899
self._retry_timeout = timedelta(seconds=retry_timeout)
99100
self._requests_kwargs = requests_kwargs or {}
100101
self._requests_kwargs.update({
101-
"headers": {"User-Agent": _USER_AGENT,
102-
'Content-type': 'application/json',
103-
"Authorization": self._key},
102+
"headers": {
103+
"User-Agent": _USER_AGENT,
104+
'Content-type': 'application/json',
105+
"Authorization": self._key
106+
},
104107
"timeout": self._timeout,
105108
})
106109

@@ -229,7 +232,7 @@ def req(self):
229232
def _get_body(response):
230233
"""Returns the body of a response object, raises status code exceptions if necessary."""
231234
body = response.json()
232-
# error = body.get('error')
235+
# error = body.get('error')
233236
status_code = response.status_code
234237

235238
if status_code == 429:
@@ -288,6 +291,7 @@ def _make_api_method(func):
288291
Please note that this is an unsupported feature for advanced use only.
289292
It's also currently incompatibile with multiple threads, see GH #160.
290293
"""
294+
291295
@functools.wraps(func)
292296
def wrapper(*args, **kwargs):
293297
args[0]._extra_params = kwargs.pop("extra_params", None)
@@ -297,6 +301,7 @@ def wrapper(*args, **kwargs):
297301
except AttributeError:
298302
pass
299303
return result
304+
300305
return wrapper
301306

302307

openrouteservice/convert.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
"""Converts Python types to string representations suitable for ORS API server.
2121
"""
2222

23+
2324
def _pipe_list(arg):
2425
"""Convert list of values to pipe-delimited string"""
2526
if not _is_list(arg):
2627
raise TypeError(
2728
"Expected a list or tuple, "
2829
"but got {}".format(type(arg).__name__))
29-
return "|".join(map(str,arg))
30+
return "|".join(map(str, arg))
3031

3132

3233
def _comma_list(arg):
@@ -35,12 +36,12 @@ def _comma_list(arg):
3536
raise TypeError(
3637
"Expected a list or tuple, "
3738
"but got {}".format(type(arg).__name__))
38-
return ",".join(map(str,arg))
39+
return ",".join(map(str, arg))
3940

4041

4142
def _convert_bool(boolean):
4243
"""Convert to stringified boolean"""
43-
44+
4445
return str(boolean).lower()
4546

4647

@@ -105,10 +106,10 @@ def _concat_coords(arg):
105106

106107

107108
def _is_list(arg):
108-
"""Checks if arg is list-like."""
109+
"""Checks if arg is list-like."""
109110
if isinstance(arg, dict):
110111
return False
111-
if isinstance(arg, str): # Python 3-only, as str has __iter__
112+
if isinstance(arg, str): # Python 3-only, as str has __iter__
112113
return False
113114
return (not _has_method(arg, "strip")
114115
and _has_method(arg, "__getitem__")
@@ -141,7 +142,7 @@ def decode_polyline(polyline, is3d=False):
141142
:rtype: dict
142143
"""
143144
points = []
144-
index = lat = lng = z= 0
145+
index = lat = lng = z = 0
145146

146147
while index < len(polyline):
147148
result = 1
@@ -165,7 +166,7 @@ def decode_polyline(polyline, is3d=False):
165166
if b < 0x1f:
166167
break
167168
lng += ~(result >> 1) if (result & 1) != 0 else (result >> 1)
168-
169+
169170
if is3d:
170171
result = 1
171172
shift = 0
@@ -179,13 +180,13 @@ def decode_polyline(polyline, is3d=False):
179180
if (result & 1) != 0:
180181
z += ~(result >> 1)
181182
else:
182-
z += (result >> 1)
183-
184-
points.append([round(lng * 1e-5, 6), round(lat * 1e-5, 6), round(z*1e-2,1)])
185-
183+
z += (result >> 1)
184+
185+
points.append([round(lng * 1e-5, 6), round(lat * 1e-5, 6), round(z * 1e-2, 1)])
186+
186187
else:
187188
points.append([round(lng * 1e-5, 6), round(lat * 1e-5, 6)])
188-
189+
189190
geojson = {u'type': u'LineString', u'coordinates': points}
190191

191192
return geojson

openrouteservice/directions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from openrouteservice import validator, deprecation
2323

24+
2425
def directions(client,
2526
coordinates,
2627
profile='driving-car',

openrouteservice/elevation.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from openrouteservice import validator
2121

22+
2223
def elevation_point(client, format_in, geometry,
2324
format_out='geojson',
2425
dataset='srtm',
@@ -49,18 +50,21 @@ def elevation_point(client, format_in, geometry,
4950
if validate:
5051
validator.validator(locals(), 'elevation_point')
5152

52-
params = {'format_in': format_in,
53-
'geometry': geometry,
54-
'format_out': format_out,
55-
'dataset': dataset}
56-
53+
params = {
54+
'format_in': format_in,
55+
'geometry': geometry,
56+
'format_out': format_out,
57+
'dataset': dataset
58+
}
59+
5760
return client.request('/elevation/point', {}, post_json=params, dry_run=dry_run)
5861

62+
5963
def elevation_line(client, format_in, geometry,
60-
format_out='geojson',
61-
dataset='srtm',
62-
validate=True,
63-
dry_run=None):
64+
format_out='geojson',
65+
dataset='srtm',
66+
validate=True,
67+
dry_run=None):
6468
"""
6569
POSTs 2D point to be enriched with elevation.
6670
@@ -88,9 +92,11 @@ def elevation_line(client, format_in, geometry,
8892
if validate:
8993
validator.validator(locals(), 'elevation_line')
9094

91-
params = {'format_in': format_in,
92-
'geometry': geometry,
93-
'format_out': format_out,
94-
'dataset': dataset}
95-
96-
return client.request('/elevation/line', {}, post_json=params, dry_run=dry_run)
95+
params = {
96+
'format_in': format_in,
97+
'geometry': geometry,
98+
'format_out': format_out,
99+
'dataset': dataset
100+
}
101+
102+
return client.request('/elevation/line', {}, post_json=params, dry_run=dry_run)

openrouteservice/exceptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@
2121
Defines exceptions that are thrown by the ORS client.
2222
"""
2323

24+
2425
class ValidationError(Exception):
2526
"""Something went wrong during cerberus validation"""
27+
2628
def __init__(self, errors):
2729
msg = '\n'.join(["{}".format(str(errors))])
2830
Exception.__init__(self, msg)
2931

32+
3033
class ApiError(Exception):
3134
"""Represents an exception returned by the remote API."""
35+
3236
def __init__(self, status, message=None):
3337
self.status = status
3438
self.message = message
@@ -39,22 +43,27 @@ def __str__(self):
3943
else:
4044
return "%s (%s)" % (self.status, self.message)
4145

46+
4247
class HTTPError(Exception):
4348
"""An unexpected HTTP error occurred."""
49+
4450
def __init__(self, status_code):
4551
self.status_code = status_code
4652

4753
def __str__(self):
4854
return "HTTP Error: %d" % self.status_code
4955

56+
5057
class Timeout(Exception):
5158
"""The request timed out."""
5259
pass
5360

61+
5462
class _RetriableRequest(Exception):
5563
"""Signifies that the request can be retried."""
5664
pass
5765

66+
5867
class _OverQueryLimit(ApiError, _RetriableRequest):
5968
"""Signifies that the request failed because the client exceeded its query rate limit.
6069

openrouteservice/isochrones.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def isochrones(client, locations,
119119
interval = interval or segments
120120
if interval:
121121
params['interval'] = interval
122-
122+
123123
if units:
124124
params["units"] = units
125125

0 commit comments

Comments
 (0)