From 651562997560c91333f0df44c09d948f1beb6ebe Mon Sep 17 00:00:00 2001 From: Dima Kukushkin Date: Sat, 25 Aug 2012 23:34:19 +0400 Subject: [PATCH 1/3] Add timeout option --- github/Github.py | 5 +++-- github/Requester.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/github/Github.py b/github/Github.py index 360ae0eb..e34204a2 100644 --- a/github/Github.py +++ b/github/Github.py @@ -24,10 +24,11 @@ import Legacy import GithubObject DEFAULT_BASE_URL = "https://api.github.com" +DEFAULT_TIMEOUT = 10 class Github( object ): - def __init__( self, login_or_token = None, password = None, base_url = DEFAULT_BASE_URL ): - self.__requester = Requester( login_or_token, password, base_url ) + def __init__( self, login_or_token = None, password = None, base_url = DEFAULT_BASE_URL, timeout = DEFAULT_TIMEOUT): + self.__requester = Requester( login_or_token, password, base_url, timeout ) @property def rate_limiting( self ): diff --git a/github/Requester.py b/github/Requester.py index 5d9c8857..8308b053 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -24,7 +24,7 @@ except ImportError: #pragma no cover: only for Python 2.5 import GithubException class Requester: - def __init__( self, login_or_token, password, base_url ): + def __init__( self, login_or_token, password, base_url, timeout=10 ): if password is not None: login = login_or_token self.__authorizationHeader = "Basic " + base64.b64encode( login + ":" + password ).replace( '\n', '' ) @@ -39,13 +39,13 @@ class Requester: self.__hostname = o.hostname self.__port = o.port self.__prefix = o.path + self.__timeout = timeout if o.scheme == "https": self.__connection_class = httplib.HTTPSConnection elif o.scheme == "http": self.__connection_class = httplib.HTTPConnection else: assert( False ) #pragma no cover - self.rate_limiting = ( 5000, 5000 ) def requestAndCheck( self, verb, url, parameters, input ): @@ -71,7 +71,7 @@ class Requester: if self.__authorizationHeader is not None: headers[ "Authorization" ] = self.__authorizationHeader - cnx = self.__connection_class( host = self.__hostname, port = self.__port, strict = True ) + cnx = self.__connection_class( host = self.__hostname, port = self.__port, strict = True, timeout = self.__timeout) cnx.request( verb, self.__completeUrl( url, parameters ), From 7186391d9cbc47a8f1ea12e9bc34f3e36bc66ecd Mon Sep 17 00:00:00 2001 From: Dima Kukushkin Date: Sat, 25 Aug 2012 23:40:48 +0400 Subject: [PATCH 2/3] Add notice about timeout to documentation. --- doc/ReferenceOfClasses.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index dad3e8db..010d7b84 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -18,6 +18,7 @@ Constructed from user's login and password or OAuth token or nothing: g = Github() You can add an argument `base_url = "http://my.enterprise.com:8080/path/to/github"` to connect to a local install of Github (ie. Github Enterprise). +Another argument, that can be passed is `timeout` which has default value `10`. Attributes ---------- From 7ae6c608435cbc3fd988f66cb7ba7dd577902b65 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 5 Sep 2012 19:16:19 +0200 Subject: [PATCH 3/3] Remove duplicated default value --- github/Requester.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/Requester.py b/github/Requester.py index 8308b053..b01c73d4 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -24,7 +24,7 @@ except ImportError: #pragma no cover: only for Python 2.5 import GithubException class Requester: - def __init__( self, login_or_token, password, base_url, timeout=10 ): + def __init__( self, login_or_token, password, base_url, timeout ): if password is not None: login = login_or_token self.__authorizationHeader = "Basic " + base64.b64encode( login + ":" + password ).replace( '\n', '' )