Skip to content

Commit 0ffc5b1

Browse files
committed
Merge branch 'add_proxy_support'
* add_proxy_support: Adding SocksiPy-branch to install.rst. Making socks support optional. Adding HTTP proxy settings support to the client.
2 parents a20672b + fb95587 commit 0ffc5b1

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ Barthelemy Dagenais <bart@cs.mcgill.ca>
2323
Surajram Kumarave <root@surajram.com>
2424
broderboy <timothy.broder@gmail.com>
2525
Patryk Zawadzki <patrys@pld-linux.org>
26+
hub-cap <mbasnight@gmail.com>

doc/install.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ following::
2424
Gregorio for handling HTTP sessions. :pypi:`simplejson` is also required when
2525
using :mod:`github2` with Python 2.4 or 2.5. If you install via ``pip`` or
2626
``easy_install`` the dependencies should be installed automatically for you.
27+
:pypi:`SocksiPy-branch` is an optional dependency if proxy support is needed.

github2/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
class Github(object):
1111

1212
def __init__(self, username=None, api_token=None, debug=False,
13-
requests_per_second=None, access_token=None, cache=None):
13+
requests_per_second=None, access_token=None, cache=None,
14+
proxy_host=None, proxy_port=8080):
1415
"""
1516
An interface to GitHub's API:
1617
http://develop.github.com/
@@ -31,13 +32,17 @@ def __init__(self, username=None, api_token=None, debug=False,
3132
or None to disable delays. The default is to disable delays (for
3233
backwards compatibility).
3334
:param str cache: a directory for caching GitHub responses.
35+
:param str proxy_host: the hostname for the HTTP proxy, if needed.
36+
:param str proxy_port: the hostname for the HTTP proxy, if needed (will
37+
default to 8080 if a proxy_host is set and no port is set.
3438
"""
3539

3640
self.debug = debug
3741
self.request = GithubRequest(username=username, api_token=api_token,
3842
debug=self.debug,
3943
requests_per_second=requests_per_second,
40-
access_token=access_token, cache=cache)
44+
access_token=access_token, cache=cache,
45+
proxy_host=proxy_host, proxy_port=proxy_port)
4146
self.issues = Issues(self.request)
4247
self.users = Users(self.request)
4348
self.repos = Repositories(self.request)

github2/request.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import json as simplejson # For Python 2.6
77
except ImportError:
88
import simplejson
9+
try:
10+
import socks # SOCKS support may not be installed
11+
except ImportError:
12+
socks = None
913
from urlparse import (urlsplit, urlunsplit)
1014
try:
1115
from urlparse import parse_qs
@@ -31,7 +35,7 @@ class GithubRequest(object):
3135

3236
def __init__(self, username=None, api_token=None, url_prefix=None,
3337
debug=False, requests_per_second=None, access_token=None,
34-
cache=None):
38+
cache=None, proxy_host=None, proxy_port=None):
3539
"""Make an API request.
3640
3741
:see: :py:class:`github2.client.Github`
@@ -52,7 +56,14 @@ def __init__(self, username=None, api_token=None, url_prefix=None,
5256
"api_version": self.api_version,
5357
"api_format": self.api_format,
5458
}
55-
self._http = httplib2.Http(cache=cache)
59+
if proxy_host is None:
60+
self._http = httplib2.Http(cache=cache)
61+
elif proxy_host and socks is None:
62+
raise GithubError('Proxy support missing. Install a python SOCKS library.')
63+
else:
64+
self._http = httplib2.Http(proxy_info=httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP,
65+
proxy_host, proxy_port),
66+
cache=cache)
5667

5768
def encode_authentication_data(self, extra_post_data):
5869
if self.access_token:

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
zip_safe=True,
3434
test_suite="nose.collector",
3535
tests_require=['nose'],
36+
extras_require={
37+
'SOCKS': ['SocksiPy-branch==1.01'],
38+
},
3639
classifiers=[
3740
"Development Status :: 3 - Alpha",
3841
"Intended Audience :: Developers",

0 commit comments

Comments
 (0)