diff --git a/.travis.yml b/.travis.yml index ddf968c..7d04d2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: python sudo: false python: - - "2.7" - - "3.2" - - "3.3" - "3.4" - "3.5" - "3.6" diff --git a/README.rst b/README.rst index b68a2b3..b81fbdb 100644 --- a/README.rst +++ b/README.rst @@ -33,15 +33,14 @@ Install Supported Python versions: -* Python 2.7 -* Python >= 3.2 +* Python >= 3.4 * PyPy and PyPy3 **Install:** .. code-block:: console - $ pip install overpy + $ pip install overpy2 Examples -------- diff --git a/overpy/__about__.py b/overpy/__about__.py index 33c6c49..da2a80f 100644 --- a/overpy/__about__.py +++ b/overpy/__about__.py @@ -13,7 +13,7 @@ __summary__ = "Python Wrapper to access the OpenStreepMap Overpass API" __uri__ = "https://github.com/DinoTools/python-overpy" -__version__ = "0.4" +__version__ = "0.4.2" __author__ = "PhiBo (DinoTools)" __email__ = "" diff --git a/overpy/__init__.py b/overpy/__init__.py index 6aa887a..fed39dc 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -61,7 +61,7 @@ class Overpass(object): 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, max_retry_count=None, retry_timeout=None): + def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX, max_retry_count=None, retry_timeout=None, context=None): """ :param read_chunk_size: Max size of each chunk read from the server response :type read_chunk_size: Integer @@ -73,6 +73,7 @@ def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX, ma :type max_retry_count: Integer :param retry_timeout: Time to wait between tries (Default: default_retry_timeout) :type retry_timeout: float + :param context: SSL content of the query. Can be used for connections to servers with unverified certificates. """ self.url = self.default_url if url is not None: @@ -92,6 +93,8 @@ def __init__(self, read_chunk_size=None, url=None, xml_parser=XML_PARSER_SAX, ma retry_timeout = self.default_retry_timeout self.retry_timeout = retry_timeout + self.context = context + self.xml_parser = xml_parser def _handle_remark_msg(self, msg): @@ -129,7 +132,7 @@ def query(self, query): time.sleep(self.retry_timeout) retry_num += 1 try: - f = urlopen(self.url, query) + f = urlopen(self.url, query, context=self.context) except HTTPError as e: f = e @@ -148,6 +151,10 @@ def query(self, query): else: content_type = f.getheader("Content-Type") + if ";" in content_type: + content_type, charset = content_type.split(";") + charset = charset.split("=")[1] + if content_type == "application/json": return self.parse_json(response) @@ -906,7 +913,7 @@ def nodes(self): """ return self.get_nodes() - def get_nodes(self, resolve_missing=False): + def get_nodes(self, resolve_missing=False, strict_mode=True): """ Get the nodes defining the geometry of the way @@ -920,6 +927,9 @@ def get_nodes(self, resolve_missing=False): result = [] resolved = False + if not strict_mode: + invalid_nodes = [] + for node_id in self._node_ids: try: node = self._result.get_node(node_id) @@ -930,11 +940,11 @@ def get_nodes(self, resolve_missing=False): result.append(node) continue - if not resolve_missing: + if not resolve_missing and strict_mode: raise exception.DataIncomplete("Resolve missing nodes is disabled") # We tried to resolve the data but some nodes are still missing - if resolved: + if resolved and strict_mode: raise exception.DataIncomplete("Unable to resolve all nodes") query = ("\n" @@ -956,12 +966,20 @@ def get_nodes(self, resolve_missing=False): node = None if node is None: - raise exception.DataIncomplete("Unable to resolve all nodes") - - result.append(node) + if strict_mode: + raise exception.DataIncomplete("Unable to resolve all nodes") + else: + # remove the id of the note from the internal list of nodes + invalid_nodes.append(node_id) + else: + result.append(node) + if not strict_mode: + for node_id in invalid_nodes: + self._node_ids.remove(node_id) return result + @classmethod def from_json(cls, data, result=None): """ diff --git a/setup.py b/setup.py index 65ec27f..54861fe 100644 --- a/setup.py +++ b/setup.py @@ -33,10 +33,6 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.2", - "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", diff --git a/tox.ini b/tox.ini index abbdf5d..0cd1dcb 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py32,py33,py34,py35,py36,pypy,pypy3 +envlist = py34,py35,py36,pypy,pypy3 [testenv] deps = pytest