From b8463cc8df0f25aa36f19b6c4b808b472e4e8911 Mon Sep 17 00:00:00 2001 From: Maximillian Dornseif Date: Thu, 31 Dec 2009 19:02:02 +0100 Subject: [PATCH] Author: Maximillian Dornseif 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". --- github2/__init__.py | 2 +- github2/request.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/github2/__init__.py b/github2/__init__.py index b2cbbf6..39f8b86 100644 --- a/github2/__init__.py +++ b/github2/__init__.py @@ -2,6 +2,6 @@ VERSION = (0, 1, 1) __doc__ = "Github API v2 library for Python" __author__ = "Ask Solem" __contact__ = "askh@opera.com" -__homepage__ = "http://github.com/ask/pygithub-issues" +__homepage__ = "http://github.com/ask/python-github2" __version__ = ".".join(map(str, VERSION)) diff --git a/github2/request.py b/github2/request.py index 4f79d3e..7f4a0f4 100644 --- a/github2/request.py +++ b/github2/request.py @@ -1,7 +1,7 @@ import sys import httplib import simplejson -from urlparse import urlparse +from urlparse import urlparse, parse_qs, urlunparse from urllib import urlencode GITHUB_URL = "http://github.com" @@ -57,6 +57,8 @@ class GithubRequest(object): def raw_request(self, url, extra_post_data, method="GET"): resource = urlparse(url) + scheme, netloc, path, params, query, fragment = urlparse(url) + hostname = netloc.split(':')[0] post_data = None headers = self.http_headers headers["Accept"] = "text/html" @@ -64,14 +66,18 @@ class GithubRequest(object): if extra_post_data or method == "POST": post_data = self.encode_authentication_data(extra_post_data) headers["Content-Length"] = str(len(post_data)) - connector = self.connector_for_scheme[resource.scheme] - connection = connector(resource.hostname, resource.port) - connection.request(method, resource.path, post_data, headers) + else: + path = urlunparse((scheme, netloc, path, params, + self.encode_authentication_data(parse_qs(query)), + fragment)) + connector = self.connector_for_scheme[scheme] + connection = connector(hostname) + connection.request(method, path, post_data, headers) response = connection.getresponse() response_text = response.read() if self.debug: sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % ( - url, post_data, response_text)) + path, post_data, response_text)) json = simplejson.loads(response_text) if json.get("error"): raise self.GithubError(json["error"][0]["error"])