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

Support unverified SSL certificates #74

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: python
sudo: false
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
2 changes: 1 addition & 1 deletion overpy/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = ""
Expand Down
34 changes: 26 additions & 8 deletions overpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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):
"""
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py32,py33,py34,py35,py36,pypy,pypy3
envlist = py34,py35,py36,pypy,pypy3

[testenv]
deps = pytest
Expand Down