Skip to content

Commit

Permalink
logging compatible with py3, fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Dec 21, 2016
1 parent f7bc789 commit 3ea6db1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions overpass/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import json
import geojson
import logging

from .errors import (OverpassSyntaxError, TimeoutError, MultipleRequestsError,
ServerLoadError, UnknownOverpassError, ServerRuntimeError)
Expand All @@ -11,7 +12,7 @@ class API(object):
SUPPORTED_FORMATS = ["geojson", "json", "xml"]

# defaults for the API class
_timeout = 25 # seconds
_timeout = 25 # second
_endpoint = "http://overpass-api.de/api/interpreter"
_debug = False

Expand All @@ -25,16 +26,22 @@ def __init__(self, *args, **kwargs):
self._status = None

if self.debug:
import httplib
import logging
httplib.HTTPConnection.debuglevel = 1

# http://stackoverflow.com/a/16630836
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True


def Get(self, query, responseformat="geojson", verbosity="body", build=True):
"""Pass in an Overpass query in Overpass QL"""

Expand All @@ -43,6 +50,9 @@ def Get(self, query, responseformat="geojson", verbosity="body", build=True):
full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity)
else:
full_query = query

if self.debug:
logging.getLogger().info(query)

# Get the response from Overpass
raw_response = self._GetFromOverpass(full_query)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
geojson==1.3.1
requests==2.8.1
wheel==0.24.0
nose==1.3.7
nose==1.3.7

0 comments on commit 3ea6db1

Please sign in to comment.