Skip to content

Commit b8463cc

Browse files
author
Maximillian Dornseif
committed
Author: Maximillian Dornseif <[email protected]>
Date: Thu Dec 31 18:42:07 2009 +0100 Add authentiation for GET requests. This for example allows you to list private repositories: >>> from github2.client import Github >>> github = Github(username="company", api_token="2e66a5c7e24d1d066230f368ce8b094e") >>> repos = github.repos.list("company") `repos` now contains a list of public and private repositories of "company".
1 parent af67998 commit b8463cc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

github2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
__doc__ = "Github API v2 library for Python"
33
__author__ = "Ask Solem"
44
__contact__ = "[email protected]"
5-
__homepage__ = "http://github.com/ask/pygithub-issues"
5+
__homepage__ = "http://github.com/ask/python-github2"
66
__version__ = ".".join(map(str, VERSION))
77

github2/request.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
import httplib
33
import simplejson
4-
from urlparse import urlparse
4+
from urlparse import urlparse, parse_qs, urlunparse
55
from urllib import urlencode
66

77
GITHUB_URL = "http://github.com"
@@ -57,21 +57,27 @@ def make_request(self, path, extra_post_data=None, method="GET"):
5757

5858
def raw_request(self, url, extra_post_data, method="GET"):
5959
resource = urlparse(url)
60+
scheme, netloc, path, params, query, fragment = urlparse(url)
61+
hostname = netloc.split(':')[0]
6062
post_data = None
6163
headers = self.http_headers
6264
headers["Accept"] = "text/html"
6365
method = method.upper()
6466
if extra_post_data or method == "POST":
6567
post_data = self.encode_authentication_data(extra_post_data)
6668
headers["Content-Length"] = str(len(post_data))
67-
connector = self.connector_for_scheme[resource.scheme]
68-
connection = connector(resource.hostname, resource.port)
69-
connection.request(method, resource.path, post_data, headers)
69+
else:
70+
path = urlunparse((scheme, netloc, path, params,
71+
self.encode_authentication_data(parse_qs(query)),
72+
fragment))
73+
connector = self.connector_for_scheme[scheme]
74+
connection = connector(hostname)
75+
connection.request(method, path, post_data, headers)
7076
response = connection.getresponse()
7177
response_text = response.read()
7278
if self.debug:
7379
sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % (
74-
url, post_data, response_text))
80+
path, post_data, response_text))
7581
json = simplejson.loads(response_text)
7682
if json.get("error"):
7783
raise self.GithubError(json["error"][0]["error"])

0 commit comments

Comments
 (0)