Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #85

Closed
wants to merge 162 commits into from
Closed

test #85

Changes from 2 commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
a76f9c5
Add Honda Insight
energee Nov 2, 2018
9f0b815
Brake error bits are high on insight so we should really let ACC hand…
energee Nov 14, 2018
e4ed489
GM: remove refactor leftovers (#440)
vntarasov Nov 19, 2018
53c6ca6
Move calibration values (#441)
dek3rr Nov 19, 2018
e32463e
Keep steering on radar fault (#442)
vntarasov Nov 20, 2018
0c9ba7a
Add readme
energee Nov 20, 2018
c9dd7fe
Add initial support for Holden/Opel Astra BK (#431)
AlexHill Nov 21, 2018
6ec0d23
Added Astra support to README and RELEASE notes (#443)
rbiasini Nov 21, 2018
9d76070
Honda Nidec: avoid giraffe setting alert when car is turned off (#449)
rbiasini Nov 30, 2018
68e56c8
Adding support for 2018 GMC Acadia Denali (#453)
CryptoKylan Dec 4, 2018
024870d
GM: Cadillac ATS Coupe 2018 support (#445)
vntarasov Dec 7, 2018
29bea62
Fixed Capitalization + Made CT6 Comment Cleaner (#456)
VirtuallyChris Dec 8, 2018
5c4ae7a
Add Lexus RX450HL as sub to RX450H (#458)
chassdesk Dec 8, 2018
dc331df
Merge opendbc subtree
Dec 10, 2018
0002cc7
Squashed 'opendbc/' changes from 3f6cd74..e108b6b
Dec 10, 2018
30ec405
Squashed 'pyextra/' changes from fb152de..8cc1594
Dec 10, 2018
573a691
Merge pyextra subtree
Dec 10, 2018
210db68
openpilot v0.5.7 release
Dec 10, 2018
e3c934b
0.5.7 hotfixes
rbiasini Dec 11, 2018
b87af61
Honda Pilot PID Tuning
NeonGalaxy75 Oct 22, 2018
905e4f5
Adjustable Follow Distance w/HUD (#12)
NeonGalaxy75 Nov 9, 2018
27905e1
Code Cleanup for Distance Adjustment
NeonGalaxy75 Nov 10, 2018
157a0d8
Auto-distance at surface street speeds
NeonGalaxy75 Nov 10, 2018
29c59a6
Physical LKAS button disables OP steer and shows dashed lines on HUD …
NeonGalaxy75 Nov 16, 2018
1c2a4f2
Remove chime disable when steering overriden
NeonGalaxy75 Nov 17, 2018
c334b60
Adjust BRAKE_STOPPING_TARGET to 0.25
NeonGalaxy75 Nov 17, 2018
692576e
Add relative velocity to auto distance for 1 bar setting (#26)
NeonGalaxy75 Nov 19, 2018
b69e402
Disable OP steering and audio alarm when blinkers on (#28)
NeonGalaxy75 Nov 21, 2018
5b52529
Critical alarm if cruise disengages while braking (#32)
NeonGalaxy75 Nov 24, 2018
38419e2
Revert CAMERA_OFFSET to 0.06 (comma default)
NeonGalaxy75 Nov 27, 2018
227d5a9
Lane width reduction to 2.85m
NeonGalaxy75 Nov 27, 2018
2a303b3
Reduce tailgating for one bar distance at surface street speeds & cod…
NeonGalaxy75 Nov 30, 2018
fb60db5
Revert CAMERA_OFFSET to Comma default of 0.06
NeonGalaxy75 Nov 30, 2018
b8526af
Merge Gernby's Resonant Steering (#51)
NeonGalaxy75 Dec 2, 2018
1278617
Revert CAMERA_OFFSET to 0.06
NeonGalaxy75 Dec 2, 2018
fd18582
Revert auto-distance for 1 bar distance setting
NeonGalaxy75 Dec 2, 2018
d45a61a
Revert "Merge Gernby's Resonant Steering" (#53)
NeonGalaxy75 Dec 3, 2018
337cc3a
better crowned road centering: learn_angle +/-7
NeonGalaxy75 Dec 4, 2018
4cd7d83
slightly harder braking when tailgating
NeonGalaxy75 Dec 4, 2018
234e57d
Merge Gernby's Resonant FF steering (#62)
NeonGalaxy75 Dec 5, 2018
d7220b2
Boost kF for pilot by 30%
NeonGalaxy75 Dec 5, 2018
924ca5c
x_lead < 7.5 or (x_lead < 17.5 and self.v_rel < 1)
NeonGalaxy75 Dec 6, 2018
19c264e
x_lead < 7.5 or (x_lead < 17.5 and self.v_rel < 0.5)
NeonGalaxy75 Dec 6, 2018
f245669
if x_lead < 5 or (x_lead < 17.5 and self.v_rel < 0.5)
NeonGalaxy75 Dec 6, 2018
8858f51
Boost KF for all
NeonGalaxy75 Dec 6, 2018
2114e91
x_lead < 17.5 and self.v_rel < 0.75
NeonGalaxy75 Dec 6, 2018
89e21f9
x_lead < 5 or (x_lead < 17.5 and self.v_rel < 0.5)
NeonGalaxy75 Dec 7, 2018
61613c2
more conservative kF for Civics
NeonGalaxy75 Dec 7, 2018
c9434f3
Civic kF 0.00003 - Pilot kF 0.000078
NeonGalaxy75 Dec 7, 2018
2d5ee5e
Revert Civic kF values to default
NeonGalaxy75 Dec 9, 2018
a78102b
x_lead < 6 or (x_lead < 17.5 and self.v_rel < 0.5)
NeonGalaxy75 Dec 10, 2018
72ccad5
Proper alerts on Eon and disable flashing HUD alert when blinkers on …
NeonGalaxy75 Dec 12, 2018
35e8b67
Implement csouers 67-70% charging to preserve batt
zeeexsixare Oct 15, 2018
083741a
Reduce steerKpV for Civics by 20% for Gernby FF steering
NeonGalaxy75 Dec 13, 2018
84e25f3
Reduce kPV for civic v2
NeonGalaxy75 Dec 13, 2018
af9bb3f
Reduce Civic kP further
NeonGalaxy75 Dec 13, 2018
ada566b
Honda Pilot PID Tuning
NeonGalaxy75 Oct 22, 2018
64a5a96
Adjustable Follow Distance w/HUD (#12)
NeonGalaxy75 Nov 9, 2018
5a3edee
Code Cleanup for Distance Adjustment
NeonGalaxy75 Nov 10, 2018
842b956
Auto-distance at surface street speeds
NeonGalaxy75 Nov 10, 2018
2206388
Physical LKAS button disables OP steer and shows dashed lines on HUD …
NeonGalaxy75 Nov 16, 2018
8cec2fa
Remove chime disable when steering overriden
NeonGalaxy75 Nov 17, 2018
f0eb11a
Adjust BRAKE_STOPPING_TARGET to 0.25
NeonGalaxy75 Nov 17, 2018
cf62e45
Add relative velocity to auto distance for 1 bar setting (#26)
NeonGalaxy75 Nov 19, 2018
7392e3f
Disable OP steering and audio alarm when blinkers on (#28)
NeonGalaxy75 Nov 21, 2018
980620c
Critical alarm if cruise disengages while braking (#32)
NeonGalaxy75 Nov 24, 2018
aa6839b
Revert CAMERA_OFFSET to 0.06 (comma default)
NeonGalaxy75 Nov 27, 2018
5add5ef
Lane width reduction to 2.85m
NeonGalaxy75 Nov 27, 2018
54ef828
Reduce tailgating for one bar distance at surface street speeds & cod…
NeonGalaxy75 Nov 30, 2018
151fec8
Revert CAMERA_OFFSET to Comma default of 0.06
NeonGalaxy75 Nov 30, 2018
336d536
Merge Gernby's Resonant Steering (#51)
NeonGalaxy75 Dec 2, 2018
66f68f9
Revert CAMERA_OFFSET to 0.06
NeonGalaxy75 Dec 2, 2018
e62b197
Revert auto-distance for 1 bar distance setting
NeonGalaxy75 Dec 2, 2018
b06ac98
Revert "Merge Gernby's Resonant Steering" (#53)
NeonGalaxy75 Dec 3, 2018
ad6c098
better crowned road centering: learn_angle +/-7
NeonGalaxy75 Dec 4, 2018
6be3181
slightly harder braking when tailgating
NeonGalaxy75 Dec 4, 2018
f1856be
x_lead < 5 or (x_lead < 17.5 and self.v_rel < 0.5)
NeonGalaxy75 Dec 7, 2018
5a9f7dd
Proper alerts on Eon and disable flashing HUD alert when blinkers on …
NeonGalaxy75 Dec 12, 2018
e3249be
Implement csouers 67-70% charging to preserve batt
zeeexsixare Oct 15, 2018
b44d301
x_lead = 6
NeonGalaxy75 Dec 12, 2018
907854c
Revert "Implement csouers 67-70% charging to preserve batt"
NeonGalaxy75 Dec 14, 2018
509fb87
Revert "Implement csouers 67-70% charging to preserve batt"
NeonGalaxy75 Dec 14, 2018
067f1bf
hotfix: wait longer in CDP mode before switching to fast charge, so E…
rbiasini Dec 17, 2018
2ccc171
Merge with latest kegman-devel without Gernby's FF steer (#72)
NeonGalaxy75 Dec 21, 2018
4610a6e
Faster NEOS download and auto removal of NEOS image after installatio…
rbiasini Dec 21, 2018
853bcda
Adds 2019 Ridgeline fingerprint (#473)
energee Dec 21, 2018
b5d8230
add self.CP = CP as with other carstate files (#459)
arne182 Dec 21, 2018
f41cb3b
Replaced 60 msg. C-HR print w/ 73 msg. C-HR print (#467)
ErichMoraga Dec 21, 2018
08f2477
Merge branch 'kegman-devel-pilotFFsteer' into kegman-devel-noFFsteer
NeonGalaxy75 Dec 22, 2018
d27db22
Revert "Merge branch 'kegman-devel-pilotFFsteer' into kegman-devel-no…
NeonGalaxy75 Dec 25, 2018
58e716f
Read from usb/present instead of usb/online (#484)
braden337 Dec 25, 2018
5e0f5cc
60-70% Battery Limit Charging for longevity
NeonGalaxy75 Dec 25, 2018
4d2ff10
Clean Up hyundai (#481)
emmertex Dec 27, 2018
67e7f6d
Update 0x365 for Rav4H from @squall and my observations (#490)
arne182 Dec 29, 2018
0fded2c
Added EX-L subsection for the existing 2019 Pilot (#489)
ErichMoraga Dec 31, 2018
f890ffb
Merge remote-tracking branch 'upstream/devel' into kegman-devel-noFFs…
NeonGalaxy75 Dec 31, 2018
f2b7571
Increase brightness for Eon and Leon
NeonGalaxy75 Dec 31, 2018
d84e64b
Fixed TOC anchor links (#492)
energee Jan 3, 2019
bda1d42
Kill video uploader if car is running
NeonGalaxy75 Jan 1, 2019
ca5fcb4
Display set speed in km/h in ACC HUD if metric
geohot Jan 6, 2019
518920b
Revert "Display set speed in km/h in ACC HUD if metric"
NeonGalaxy75 Jan 6, 2019
5dc6220
Display set speed in km/h in ACC HUD if metric
geohot Jan 6, 2019
b78ed77
Adding GM Steering Rate (#495)
CryptoKylan Jan 9, 2019
03cd3a3
Disable NEOS 8 update
NeonGalaxy75 Jan 11, 2019
9eb1666
Merge new 2019 Civic and existing 2017-18 Civic Hatch (#446)
csouers Jan 12, 2019
b04cc08
Merge branch '2019-insight' of https://github.com/energee/openpilot i…
NeonGalaxy75 Jan 12, 2019
fb2af38
Merge branch 'energee-2019-insight' into kegman
NeonGalaxy75 Jan 12, 2019
4413cc4
Update honda_insight_ex_2019_can.dbc
NeonGalaxy75 Jan 12, 2019
a0d4eef
Update honda_insight_ex_2019_can_generated.dbc
NeonGalaxy75 Jan 12, 2019
8b9cee4
Change README.md for fork particulars
NeonGalaxy75 Jan 12, 2019
45fbcc9
Update README.md
NeonGalaxy75 Jan 12, 2019
41118af
Update README.md
NeonGalaxy75 Jan 12, 2019
00dba62
Update README.md
NeonGalaxy75 Jan 13, 2019
83898c7
Update README.md
NeonGalaxy75 Jan 13, 2019
e47bec3
Merge remote-tracking branch 'upstream/devel' into kegman
NeonGalaxy75 Jan 13, 2019
ac58c99
Revert "Disable NEOS 8 update"
NeonGalaxy75 Jan 14, 2019
9cf542d
Updated links from Slack to Discord
rbiasini Jan 14, 2019
5e4035b
Add GM
NeonGalaxy75 Jan 15, 2019
3f0da1d
Update README.md
NeonGalaxy75 Jan 15, 2019
14c7d5d
Update README.md
NeonGalaxy75 Jan 15, 2019
aff793a
Update README.md
NeonGalaxy75 Jan 15, 2019
f3c9c6a
Update README.md
NeonGalaxy75 Jan 15, 2019
9b22b17
Update README.md
NeonGalaxy75 Jan 15, 2019
7a5b069
Update README.md
NeonGalaxy75 Jan 15, 2019
fc6c514
Update README.md
NeonGalaxy75 Jan 15, 2019
e380a09
Update README.md
NeonGalaxy75 Jan 15, 2019
d58e242
Update README.md
NeonGalaxy75 Jan 15, 2019
92e3651
Update README.md
NeonGalaxy75 Jan 15, 2019
56d2403
adding gm support (#103)
CryptoKylan Jan 15, 2019
3fc230d
Update README.md
NeonGalaxy75 Jan 16, 2019
4f1d5fd
Remove Gernby's gm/interface.py stuff for GM
NeonGalaxy75 Jan 16, 2019
d4ee7a8
GM: Auto-resume from stop-and-go
vntarasov Nov 20, 2018
48eeb7f
Separate events and alerts for blinker signals. (#105)
metroshica Jan 18, 2019
5b2683f
Revert "Separate events and alerts for blinker signals. (#105)"
NeonGalaxy75 Jan 19, 2019
45f4815
Update README.md
NeonGalaxy75 Jan 19, 2019
97794f6
Add GM LKAS Toggle
rdm128 Jan 20, 2019
d5f8643
Increment hatchback year (#508)
csouers Jan 22, 2019
aea3706
Lower minimum enable speed to 8 (#107)
Aryeh95 Jan 22, 2019
0d40ac2
Add Ridgeline to Pedal Grinding fix
NeonGalaxy75 Jan 23, 2019
1297d77
Copy Pilot PID values to Ridgeline
NeonGalaxy75 Jan 23, 2019
b454fc9
Update README.md
NeonGalaxy75 Jan 23, 2019
109ead1
Update README.md
NeonGalaxy75 Jan 23, 2019
fa42624
Update README.md
NeonGalaxy75 Jan 23, 2019
d21c659
Squashed 'panda/' changes from 293fa33..9ee6285
Jan 23, 2019
ece9cf9
Merge panda subtree
Jan 23, 2019
ea35a00
Squashed 'opendbc/' changes from e108b6b..b632acf
Jan 23, 2019
f364a3e
Merge opendbc subtree
Jan 23, 2019
b967da5
openpilot v0.5.8 release
Jan 23, 2019
1d3bbb3
Revert visiond to 0.5.7 for merge
NeonGalaxy75 Jan 26, 2019
e42f9c4
Merge remote-tracking branch 'upstream/devel' into kegman
NeonGalaxy75 Jan 26, 2019
47cb43d
Reduce lane width to 2.85m @0 to 3.5m @33+ m/s
geohot Jan 17, 2019
ff1709d
Add Lane Width documentation
NeonGalaxy75 Jan 30, 2019
a842695
Refactor adjustable distance code for easier tuning
NeonGalaxy75 Jan 27, 2019
dce9882
Slightly harder braking for 1 and 2 bars w/ Pullaway speed to 0.25 tweak
NeonGalaxy75 Jan 28, 2019
b6ac089
Honda ACC distance intervals (1.1s, 1.5s, 2.1s, 2.8s)
NeonGalaxy75 Feb 7, 2019
ff5786b
Enable 4 distance intervals
NeonGalaxy75 Feb 7, 2019
a51b68e
Update README.md
NeonGalaxy75 Feb 7, 2019
1714ed6
Update README.md
NeonGalaxy75 Feb 7, 2019
732a0b1
Update README.md
NeonGalaxy75 Feb 7, 2019
7033ce2
Increase braking further
NeonGalaxy75 Feb 8, 2019
ce4a449
Revert "Increase braking further"
NeonGalaxy75 Feb 9, 2019
d9d5581
Restore STOPPING_DISTANCE to 2 and PULLAWAY to 0.5
NeonGalaxy75 Feb 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions pyextra/overpy-0.4-py2.7.egg-info/PKG-INFO

This file was deleted.

61 changes: 0 additions & 61 deletions pyextra/overpy-0.4-py2.7.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion pyextra/overpy-0.4-py2.7.egg-info/dependency_links.txt

This file was deleted.

56 changes: 0 additions & 56 deletions pyextra/overpy-0.4-py2.7.egg-info/installed-files.txt

This file was deleted.

1 change: 0 additions & 1 deletion pyextra/overpy-0.4-py2.7.egg-info/not-zip-safe

This file was deleted.

2 changes: 0 additions & 2 deletions pyextra/overpy-0.4-py2.7.egg-info/top_level.txt

This file was deleted.

221 changes: 152 additions & 69 deletions pyextra/overpy/__init__.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import json
import re
import sys
import time
import requests

from overpy import exception
from overpy.__about__ import (
@@ -18,12 +20,15 @@
XML_PARSER_DOM = 1
XML_PARSER_SAX = 2

if PY2:
from urllib2 import urlopen
from urllib2 import HTTPError
elif PY3:
from urllib.request import urlopen
from urllib.error import HTTPError
# Try to convert some common attributes
# http://wiki.openstreetmap.org/wiki/Elements#Common_attributes
GLOBAL_ATTRIBUTE_MODIFIERS = {
"changeset": int,
"timestamp": lambda ts: datetime.strptime(ts, "%Y-%m-%dT%H:%M:%SZ"),
"uid": int,
"version": int,
"visible": lambda v: v.lower() == "true"
}


def is_valid_type(element, cls):
@@ -41,18 +46,31 @@ def is_valid_type(element, cls):
class Overpass(object):
"""
Class to access the Overpass API
:cvar default_max_retry_count: Global max number of retries (Default: 0)
:cvar default_retry_timeout: Global time to wait between tries (Default: 1.0s)
"""
default_max_retry_count = 0
default_read_chunk_size = 4096
default_retry_timeout = 1.0
default_url = "http://overpass-api.de/api/interpreter"

def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX):
def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX, max_retry_count=None, retry_timeout=None, timeout=5.0, headers=None):
"""
:param read_chunk_size: Max size of each chunk read from the server response
:type read_chunk_size: Integer
:param url: Optional URL of the Overpass server. Defaults to http://overpass-api.de/api/interpreter
:type url: str
:param xml_parser: The xml parser to use
:type xml_parser: Integer
:param max_retry_count: Max number of retries (Default: default_max_retry_count)
:type max_retry_count: Integer
:param retry_timeout: Time to wait between tries (Default: default_retry_timeout)
:type retry_timeout: float
:param timeout: HTTP request timeout
:type timeout: float
:param headers: HTTP request headers
:type headers: dict
"""
self.url = self.default_url
if url is not None:
@@ -63,7 +81,34 @@ def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX):
if read_chunk_size is None:
read_chunk_size = self.default_read_chunk_size
self.read_chunk_size = read_chunk_size

if max_retry_count is None:
max_retry_count = self.default_max_retry_count
self.max_retry_count = max_retry_count

if retry_timeout is None:
retry_timeout = self.default_retry_timeout
self.retry_timeout = retry_timeout

self.xml_parser = xml_parser
self.timeout = timeout
self.headers = headers

def _handle_remark_msg(self, msg):
"""
Try to parse the message provided with the remark tag or element.
:param str msg: The message
:raises overpy.exception.OverpassRuntimeError: If message starts with 'runtime error:'
:raises overpy.exception.OverpassRuntimeRemark: If message starts with 'runtime remark:'
:raises overpy.exception.OverpassUnknownError: If we are unable to identify the error
"""
msg = msg.strip()
if msg.startswith("runtime error:"):
raise exception.OverpassRuntimeError(msg=msg)
elif msg.startswith("runtime remark:"):
raise exception.OverpassRuntimeRemark(msg=msg)
raise exception.OverpassUnknownError(msg=msg)

def query(self, query):
"""
@@ -76,56 +121,79 @@ def query(self, query):
if not isinstance(query, bytes):
query = query.encode("utf-8")

try:
f = urlopen(self.url, query)
except HTTPError as e:
f = e

response = f.read(self.read_chunk_size)
while True:
data = f.read(self.read_chunk_size)
if len(data) == 0:
break
response = response + data
f.close()

if f.code == 200:
if PY2:
http_info = f.info()
content_type = http_info.getheader("content-type")
else:
content_type = f.getheader("Content-Type")

if content_type == "application/json":
return self.parse_json(response)
retry_num = 0
retry_exceptions = []
do_retry = True if self.max_retry_count > 0 else False
while retry_num <= self.max_retry_count:
if retry_num > 0:
time.sleep(self.retry_timeout)
retry_num += 1

if content_type == "application/osm3s+xml":
return self.parse_xml(response)
try:
if self.headers is not None:
r = requests.post(self.url, query, timeout=self.timeout, headers=self.headers)
else:
r = requests.post(self.url, query, timeout=self.timeout)
response = r.content
except (requests.exceptions.BaseHTTPError, requests.exceptions.RequestException) as e:
if not do_retry:
raise e
retry_exceptions.append(e)
continue

raise exception.OverpassUnknownContentType(content_type)
if r.status_code == 200:
content_type = r.headers["Content-Type"]

if f.code == 400:
msgs = []
for msg in self._regex_extract_error_msg.finditer(response):
tmp = self._regex_remove_tag.sub(b"", msg.group("msg"))
try:
tmp = tmp.decode("utf-8")
except UnicodeDecodeError:
tmp = repr(tmp)
msgs.append(tmp)
if content_type == "application/json":
return self.parse_json(response)

raise exception.OverpassBadRequest(
query,
msgs=msgs
)
if content_type == "application/osm3s+xml":
return self.parse_xml(response)

if f.code == 429:
raise exception.OverpassTooManyRequests
e = exception.OverpassUnknownContentType(content_type)
if not do_retry:
raise e
retry_exceptions.append(e)
continue
elif r.status_code == 400:
msgs = []
for msg in self._regex_extract_error_msg.finditer(response):
tmp = self._regex_remove_tag.sub(b"", msg.group("msg"))
try:
tmp = tmp.decode("utf-8")
except UnicodeDecodeError:
tmp = repr(tmp)
msgs.append(tmp)

e = exception.OverpassBadRequest(
query,
msgs=msgs
)
if not do_retry:
raise e
retry_exceptions.append(e)
continue
elif r.status_code == 429:
e = exception.OverpassTooManyRequests
if not do_retry:
raise e
retry_exceptions.append(e)
continue
elif r.status_code == 504:
e = exception.OverpassGatewayTimeout
if not do_retry:
raise e
retry_exceptions.append(e)
continue

if f.code == 504:
raise exception.OverpassGatewayTimeout
# No valid response code
e = exception.OverpassUnknownHTTPStatusCode(r.status_code)
if not do_retry:
raise e
retry_exceptions.append(e)
continue

raise exception.OverpassUnknownHTTPStatusCode(f.code)
raise exception.MaxRetriesReached(retry_count=retry_num, exceptions=retry_exceptions)

def parse_json(self, data, encoding="utf-8"):
"""
@@ -139,8 +207,11 @@ def parse_json(self, data, encoding="utf-8"):
:rtype: overpy.Result
"""
if isinstance(data, bytes):
data = data.decode(encoding)
data = data.decode(encoding)

data = json.loads(data, parse_float=Decimal)
if "remark" in data:
self._handle_remark_msg(msg=data.get("remark"))
return Result.from_json(data, api=self)

def parse_xml(self, data, encoding="utf-8", parser=None):
@@ -155,13 +226,16 @@ def parse_xml(self, data, encoding="utf-8", parser=None):
"""
if parser is None:
parser = self.xml_parser

if isinstance(data, bytes):
data = data.decode(encoding)
if PY2 and not isinstance(data, str):
# Python 2.x: Convert unicode strings
data = data.encode(encoding)

m = re.compile("<remark>(?P<msg>[^<>]*)</remark>").search(data)
if m:
self._handle_remark_msg(m.group("msg"))

return Result.from_xml(data, api=self, parser=parser)


@@ -279,23 +353,39 @@ def from_json(cls, data, api=None):
return result

@classmethod
def from_xml(cls, data, api=None, parser=XML_PARSER_SAX):
def from_xml(cls, data, api=None, parser=None):
"""
Create a new instance and load data from xml object.
Create a new instance and load data from xml data or object.
.. note::
If parser is set to None, the functions tries to find the best parse.
By default the SAX parser is chosen if a string is provided as data.
The parser is set to DOM if an xml.etree.ElementTree.Element is provided as data value.
:param data: Root element
:type data: xml.etree.ElementTree.Element
:param api:
:type data: str | xml.etree.ElementTree.Element
:param api: The instance to query additional information if required.
:type api: Overpass
:param parser: Specify the parser to use(DOM or SAX)
:type parser: Integer
:param parser: Specify the parser to use(DOM or SAX)(Default: None = autodetect, defaults to SAX)
:type parser: Integer | None
:return: New instance of Result object
:rtype: Result
"""
if parser is None:
if isinstance(data, str):
parser = XML_PARSER_SAX
else:
parser = XML_PARSER_DOM

result = cls(api=api)
if parser == XML_PARSER_DOM:
import xml.etree.ElementTree as ET
root = ET.fromstring(data)
if isinstance(data, str):
root = ET.fromstring(data)
elif isinstance(data, ET.Element):
root = data
else:
raise exception.OverPyException("Unable to detect data type.")

for elem_cls in [Node, Way, Relation, Area]:
for child in root:
@@ -522,17 +612,10 @@ def __init__(self, attributes=None, result=None, tags=None):
"""

self._result = result
# Try to convert some common attributes
# http://wiki.openstreetmap.org/wiki/Elements#Common_attributes
self._attribute_modifiers = {
"changeset": int,
"timestamp": lambda ts: datetime.strptime(ts, "%Y-%m-%dT%H:%M:%SZ"),
"uid": int,
"version": int,
"visible": lambda v: v.lower() == "true"
}
self.attributes = attributes
for n, m in self._attribute_modifiers.items():
# ToDo: Add option to modify attribute modifiers
attribute_modifiers = dict(GLOBAL_ATTRIBUTE_MODIFIERS.items())
for n, m in attribute_modifiers.items():
if n in self.attributes:
self.attributes[n] = m(self.attributes[n])
self.id = None
58 changes: 58 additions & 0 deletions pyextra/overpy/exception.py
Original file line number Diff line number Diff line change
@@ -37,6 +37,18 @@ def __str__(self):
)


class MaxRetriesReached(OverPyException):
"""
Raised if max retries reached and the Overpass server didn't respond with a result.
"""
def __init__(self, retry_count, exceptions):
self.exceptions = exceptions
self.retry_count = retry_count

def __str__(self):
return "Unable get any result from the Overpass API server after %d retries." % self.retry_count


class OverpassBadRequest(OverPyException):
"""
Raised if the Overpass API service returns a syntax error.
@@ -62,6 +74,29 @@ def __str__(self):
return "\n".join(tmp_msgs)


class OverpassError(OverPyException):
"""
Base exception to report errors if the response returns a remark tag or element.
.. note::
If you are not sure which of the subexceptions you should use, use this one and try to parse the message.
For more information have a look at https://github.com/DinoTools/python-overpy/issues/62
:param str msg: The message from the remark tag or element
"""
def __init__(self, msg=None):
#: The message from the remark tag or element
self.msg = msg

def __str__(self):
if self.msg is None:
return "No error message provided"
if not isinstance(self.msg, str):
return str(self.msg)
return self.msg


class OverpassGatewayTimeout(OverPyException):
"""
Raised if load of the Overpass API service is too high and it can't handle the request.
@@ -70,6 +105,22 @@ def __init__(self):
OverPyException.__init__(self, "Server load too high")


class OverpassRuntimeError(OverpassError):
"""
Raised if the server returns a remark-tag(xml) or remark element(json) with a message starting with
'runtime error:'.
"""
pass


class OverpassRuntimeRemark(OverpassError):
"""
Raised if the server returns a remark-tag(xml) or remark element(json) with a message starting with
'runtime remark:'.
"""
pass


class OverpassTooManyRequests(OverPyException):
"""
Raised if the Overpass API service returns a 429 status code.
@@ -94,6 +145,13 @@ def __str__(self):
return "Unknown content type: %s" % self.content_type


class OverpassUnknownError(OverpassError):
"""
Raised if the server returns a remark-tag(xml) or remark element(json) and we are unable to find any reason.
"""
pass


class OverpassUnknownHTTPStatusCode(OverPyException):
"""
Raised if the returned HTTP status code isn't handled by OverPy.