From f1fa75f631cda18d65b6d4d18fb89ade5db7b2fc Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Mon, 16 Jul 2018 14:10:40 +0200 Subject: [PATCH 1/9] new parameter context added to the query function in order to define an optinal ssl context for the query. This is required in order to send a query to a site which has an unverified ssl certificate, i.e a self signed certificate. --- overpy/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/overpy/__init__.py b/overpy/__init__.py index 6aa887a..b9a855c 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -110,11 +110,12 @@ def _handle_remark_msg(self, msg): raise exception.OverpassRuntimeRemark(msg=msg) raise exception.OverpassUnknownError(msg=msg) - def query(self, query): + def query(self, query, context=None): """ Query the Overpass API :param String|Bytes query: The query string in Overpass QL + :param SSLContext context: An optional context for an SSL connection :return: The parsed result :rtype: overpy.Result """ @@ -129,7 +130,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=context) except HTTPError as e: f = e From 7be1bb71ac3115d905310542e395f3e34db207a7 Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Mon, 16 Jul 2018 14:28:01 +0200 Subject: [PATCH 2/9] Due to the fact that the context is dependent on the url, I've moved the context parameter from the query function to the constructor. --- overpy/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/overpy/__init__.py b/overpy/__init__.py index b9a855c..c993c81 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): @@ -110,12 +113,11 @@ def _handle_remark_msg(self, msg): raise exception.OverpassRuntimeRemark(msg=msg) raise exception.OverpassUnknownError(msg=msg) - def query(self, query, context=None): + def query(self, query): """ Query the Overpass API :param String|Bytes query: The query string in Overpass QL - :param SSLContext context: An optional context for an SSL connection :return: The parsed result :rtype: overpy.Result """ @@ -130,7 +132,7 @@ def query(self, query, context=None): time.sleep(self.retry_timeout) retry_num += 1 try: - f = urlopen(self.url, query, context=context) + f = urlopen(self.url, query, context=self.context) except HTTPError as e: f = e From 9e3f576afcf4ed6d01aa39fb13bdc64d97b6028d Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Tue, 9 Oct 2018 13:51:13 +0200 Subject: [PATCH 3/9] Only support python >= 3.4 --- README.rst | 3 +-- setup.py | 4 ---- tox.ini | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index b68a2b3..18175e8 100644 --- a/README.rst +++ b/README.rst @@ -33,8 +33,7 @@ Install Supported Python versions: -* Python 2.7 -* Python >= 3.2 +* Python >= 3.4 * PyPy and PyPy3 **Install:** 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 From 8915306ca3acbd6d93e5e6e47847281377033abf Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Tue, 9 Oct 2018 13:51:58 +0200 Subject: [PATCH 4/9] update travis file to only support python >= 3.4 --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) 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" From 11a1b9de5fcece8a12486e7496956acab4a62767 Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Fri, 8 Feb 2019 16:37:13 +0100 Subject: [PATCH 5/9] fix content-type handling --- overpy/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/overpy/__init__.py b/overpy/__init__.py index c993c81..2fb1ba5 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -151,6 +151,11 @@ 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) From 979518e8fff6b694af96ea79b4ff0b665239a54d Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Fri, 8 Feb 2019 16:39:41 +0100 Subject: [PATCH 6/9] fix intendation --- overpy/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/overpy/__init__.py b/overpy/__init__.py index 2fb1ba5..491663a 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -151,10 +151,9 @@ 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 ";" in content_type: + content_type, charset = content_type.split(";") + charset = charset.split("=")[1] if content_type == "application/json": return self.parse_json(response) From cc5c09e1d9d03faa6c718e122efaa9df7222f81f Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 7 Jun 2019 15:41:50 +0200 Subject: [PATCH 7/9] Add a new strict parameter to get_nodes() function Sometimes, the openstreetmap server is inconsistent in that way that the list of node ids of a `Way` contains nodes that actually do not exist. In that case, no nodes of a `Way` will be retrieved even if there are valid nodes. You can now set the strict_mode to False so that invalid nodes will be removed from a Way. The default behaviour still is to try to retrieve the missing nodes and if the node does not exist, a DataIncomplete exception is thrown. --- overpy/__about__.py | 2 +- overpy/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/overpy/__about__.py b/overpy/__about__.py index 33c6c49..c390a9a 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.1" __author__ = "PhiBo (DinoTools)" __email__ = "" diff --git a/overpy/__init__.py b/overpy/__init__.py index 491663a..9e4da79 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -913,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 @@ -937,11 +937,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" From 3ba686def2f51c876fbee45c8b691b0ebd7baa0b Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 7 Jun 2019 17:29:17 +0200 Subject: [PATCH 8/9] Nodes will now be removed from the Way in strict mode --- overpy/__about__.py | 2 +- overpy/__init__.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/overpy/__about__.py b/overpy/__about__.py index c390a9a..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.1" +__version__ = "0.4.2" __author__ = "PhiBo (DinoTools)" __email__ = "" diff --git a/overpy/__init__.py b/overpy/__init__.py index 9e4da79..fed39dc 100644 --- a/overpy/__init__.py +++ b/overpy/__init__.py @@ -927,6 +927,9 @@ def get_nodes(self, resolve_missing=False, strict_mode=True): result = [] resolved = False + if not strict_mode: + invalid_nodes = [] + for node_id in self._node_ids: try: node = self._result.get_node(node_id) @@ -963,12 +966,20 @@ def get_nodes(self, resolve_missing=False, strict_mode=True): 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): """ From bfced661137fccc164addb587d308ff3dddd609a Mon Sep 17 00:00:00 2001 From: Lars Klitzke Date: Thu, 25 Jul 2019 20:04:07 +0200 Subject: [PATCH 9/9] update install instruction --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 18175e8..b81fbdb 100644 --- a/README.rst +++ b/README.rst @@ -40,7 +40,7 @@ Supported Python versions: .. code-block:: console - $ pip install overpy + $ pip install overpy2 Examples --------