Skip to content

Commit 3ea6db1

Browse files
committed
logging compatible with py3, fixes mvexel#72
1 parent f7bc789 commit 3ea6db1

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

overpass/api.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
import json
33
import geojson
4+
import logging
45

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

1314
# defaults for the API class
14-
_timeout = 25 # seconds
15+
_timeout = 25 # second
1516
_endpoint = "http://overpass-api.de/api/interpreter"
1617
_debug = False
1718

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

2728
if self.debug:
28-
import httplib
29-
import logging
30-
httplib.HTTPConnection.debuglevel = 1
31-
29+
# http://stackoverflow.com/a/16630836
30+
try:
31+
import http.client as http_client
32+
except ImportError:
33+
# Python 2
34+
import httplib as http_client
35+
http_client.HTTPConnection.debuglevel = 1
36+
37+
# You must initialize logging, otherwise you'll not see debug output.
3238
logging.basicConfig()
3339
logging.getLogger().setLevel(logging.DEBUG)
3440
requests_log = logging.getLogger("requests.packages.urllib3")
3541
requests_log.setLevel(logging.DEBUG)
3642
requests_log.propagate = True
3743

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

@@ -43,6 +50,9 @@ def Get(self, query, responseformat="geojson", verbosity="body", build=True):
4350
full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity)
4451
else:
4552
full_query = query
53+
54+
if self.debug:
55+
logging.getLogger().info(query)
4656

4757
# Get the response from Overpass
4858
raw_response = self._GetFromOverpass(full_query)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
geojson==1.3.1
22
requests==2.8.1
33
wheel==0.24.0
4-
nose==1.3.7
4+
nose==1.3.7

0 commit comments

Comments
 (0)