Skip to content

Commit

Permalink
Merge branch 'topic/Timeout' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	github/Requester.py
  • Loading branch information
jacquev6 committed Sep 5, 2012
2 parents 353fe2e + 7ae6c60 commit 1322002
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/ReferenceOfClasses.md
Expand Up @@ -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
----------
Expand Down
5 changes: 3 additions & 2 deletions github/Github.py
Expand Up @@ -24,10 +24,11 @@
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 ):
Expand Down
6 changes: 3 additions & 3 deletions github/Requester.py
Expand Up @@ -32,7 +32,7 @@ def injectConnectionClasses( cls, httpConnectionClass, httpsConnectionClass ):
cls.__httpConnectionClass = httpConnectionClass
cls.__httpsConnectionClass = httpsConnectionClass

def __init__( self, login_or_token, password, base_url ):
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', '' )
Expand All @@ -47,13 +47,13 @@ def __init__( self, login_or_token, password, base_url ):
self.__hostname = o.hostname
self.__port = o.port
self.__prefix = o.path
self.__timeout = timeout
if o.scheme == "https":
self.__connectionClass = self.__httpsConnectionClass
elif o.scheme == "http":
self.__connectionClass = self.__httpConnectionClass
else:
assert( False ) #pragma no cover

self.rate_limiting = ( 5000, 5000 )

def requestAndCheck( self, verb, url, parameters, input ):
Expand All @@ -79,7 +79,7 @@ def requestRaw( self, verb, url, parameters, input ):
if self.__authorizationHeader is not None:
headers[ "Authorization" ] = self.__authorizationHeader

cnx = self.__connectionClass( host = self.__hostname, port = self.__port, strict = True )
cnx = self.__connectionClass( host = self.__hostname, port = self.__port, strict = True, timeout= self.__timeout )
cnx.request(
verb,
self.__completeUrl( url, parameters ),
Expand Down

0 comments on commit 1322002

Please sign in to comment.