Skip to content

Commit 552a62d

Browse files
committed
Initial conversion to logging.
1 parent 7d1c855 commit 552a62d

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

github2/client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class Github(object):
1212

13-
def __init__(self, username=None, api_token=None, debug=False,
14-
requests_per_second=None, access_token=None, cache=None,
15-
proxy_host=None, proxy_port=8080):
13+
def __init__(self, username=None, api_token=None, requests_per_second=None,
14+
access_token=None, cache=None, proxy_host=None,
15+
proxy_port=8080):
1616
"""
1717
An interface to GitHub's API:
1818
http://develop.github.com/
@@ -27,7 +27,6 @@ def __init__(self, username=None, api_token=None, debug=False,
2727
:param str username: your own GitHub username.
2828
:param str api_token: can be found at https://github.com/account
2929
(while logged in as that user):
30-
:param bool debug: enable debugging information.
3130
:param str access_token: can be used when no ``username`` and/or
3231
``api_token`` is used. The ``access_token`` is the OAuth access
3332
token that is received after successful OAuth authentication.
@@ -41,9 +40,7 @@ def __init__(self, username=None, api_token=None, debug=False,
4140
default to 8080 if a proxy_host is set and no port is set).
4241
"""
4342

44-
self.debug = debug
4543
self.request = GithubRequest(username=username, api_token=api_token,
46-
debug=self.debug,
4744
requests_per_second=requests_per_second,
4845
access_token=access_token, cache=cache,
4946
proxy_host=proxy_host,

github2/request.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import logging
23
import re
34
import sys
45
import time
@@ -22,6 +23,9 @@
2223
#: Hostname for API access
2324
GITHUB_URL = "https://github.com"
2425

26+
#: Logger for requests module
27+
LOGGER = logging.getLogger('github2.request')
28+
2529

2630
def charset_from_headers(headers):
2731
"""Parse charset from headers
@@ -49,8 +53,8 @@ class GithubRequest(object):
4953
GithubError = GithubError
5054

5155
def __init__(self, username=None, api_token=None, url_prefix=None,
52-
debug=False, requests_per_second=None, access_token=None,
53-
cache=None, proxy_host=None, proxy_port=None):
56+
requests_per_second=None, access_token=None,
57+
cache=None, proxy_host=None, proxy_port=None):
5458
"""Make an API request.
5559
5660
:see: :class:`github2.client.Github`
@@ -59,7 +63,6 @@ def __init__(self, username=None, api_token=None, url_prefix=None,
5963
self.api_token = api_token
6064
self.access_token = access_token
6165
self.url_prefix = url_prefix
62-
self.debug = debug
6366
if requests_per_second is None:
6467
self.delay = 0
6568
else:
@@ -117,8 +120,7 @@ def make_request(self, path, extra_post_data=None, method="GET"):
117120
since_last_in_seconds = (since_last.days * 24 * 60 * 60) + since_last.seconds + (since_last.microseconds/1000000.0)
118121
if since_last_in_seconds < self.delay:
119122
duration = self.delay - since_last_in_seconds
120-
if self.debug:
121-
sys.stderr.write("delaying API call %s\n" % duration)
123+
LOGGER.warning("delaying API call %s second(s)", duration)
122124
time.sleep(duration)
123125

124126
extra_post_data = extra_post_data or {}
@@ -142,9 +144,9 @@ def raw_request(self, url, extra_post_data, method="GET"):
142144
query = self.encode_authentication_data(parse_qs(query))
143145
url = urlunsplit((scheme, netloc, path, query, fragment))
144146
response, content = self._http.request(url, method, post_data, headers)
145-
if self.debug:
146-
sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % (
147-
url, post_data, content))
147+
if LOGGER.isEnabledFor(logging.DEBUG):
148+
logging.debug("URL: %r POST_DATA: %r RESPONSE_TEXT: %r", url,
149+
post_data, content)
148150
if response.status >= 400:
149151
raise RuntimeError("unexpected response from github.com %d: %r" % (
150152
response.status, content))

0 commit comments

Comments
 (0)