<s> """<STR_LIT>""" <EOL> import sys <EOL> import xml <EOL> import xml . dom . minidom <EOL> try : import simplejson as json <EOL> except ImportError : import json <EOL> from urllib import urlencode <EOL> import hclient <EOL> def _string_parser ( x ) : <EOL> """<STR_LIT>""" <EOL> return x . firstChild . data <EOL> _types = { <EOL> '<STR_LIT:string>' : _string_parser , <EOL> '<STR_LIT>' : lambda x : int ( _string_parser ( x ) ) , <EOL> '<STR_LIT:float>' : lambda x : float ( _string_parser ( x ) ) , <EOL> '<STR_LIT>' : _string_parser , <EOL> '<STR_LIT>' : lambda x : _string_parser ( x ) == '<STR_LIT:true>' <EOL> } <EOL> def _parse ( el ) : <EOL> """<STR_LIT>""" <EOL> type = '<STR_LIT:string>' <EOL> if el . attributes and '<STR_LIT:type>' in list ( el . attributes . keys ( ) ) : <EOL> type = el . attributes [ '<STR_LIT:type>' ] . value <EOL> elif el . localName in _types : <EOL> type = el . localName <EOL> elif len ( el . childNodes ) > <NUM_LIT:1> : <EOL> type = None <EOL> ch = el . firstChild <EOL> while ch and not type : <EOL> if ch . localName == '<STR_LIT:type>' : <EOL> type = ch . firstChild . data <EOL> ch = ch . nextSibling <EOL> if not type : <EOL> raise Exception ( "<STR_LIT>" <EOL> % ( el . toxml ( ) , repr ( list ( _types . keys ( ) ) ) ) ) <EOL> return _types [ type ] ( el ) <EOL> def parses ( t ) : <EOL> """<STR_LIT>""" <EOL> def f ( orig ) : <EOL> orig . parses = t <EOL> return orig <EOL> return f <EOL> def with_temporary_mappings ( m ) : <EOL> """<STR_LIT>""" <EOL> def f ( orig ) : <EOL> def every ( self , * args ) : <EOL> global _types <EOL> o = _types . copy ( ) <EOL> for k , v in list ( m . items ( ) ) : <EOL> if v : <EOL> _types [ k ] = v <EOL> else : <EOL> del _types [ k ] <EOL> try : <EOL> return orig ( self , * args ) <EOL> finally : <EOL> _types = o <EOL> return every <EOL> return f <EOL> @ parses ( '<STR_LIT>' ) <EOL> def _parseArray ( el ) : <EOL> rv = [ ] <EOL> ch = el . firstChild <EOL> while ch : <EOL> if ch . nodeType != xml . dom . Node . TEXT_NODE and ch . firstChild : <EOL> rv . append ( _parse ( ch ) ) <EOL> ch = ch . nextSibling <EOL> return rv <EOL> class BaseResponse ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , el ) : <EOL> ch = el . firstChild <EOL> while ch : <EOL> if ch . nodeType != xml . dom . Node . TEXT_NODE and ch . firstChild : <EOL> ln = ch . localName . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> self . __dict__ [ ln ] = _parse ( ch ) <EOL> ch = ch . nextSibling <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % str ( self . __class__ ) <EOL> class User ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT:user>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> class Plan ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> class Repository ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> @ property <EOL> def owner_name ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . owner <EOL> else : <EOL> return self . username <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . owner_name , self . name ) <EOL> class PublicKey ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> title = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . title <EOL> class Commit ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . id <EOL> class Parent ( Commit ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> class Author ( User ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> class Committer ( User ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> class Issue ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . number <EOL> class IssueComment ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . body <EOL> class Label ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT:label>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> class Tree ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> class Blob ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . name <EOL> class Modification ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . filename <EOL> class Network ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . owner , self . name ) <EOL> class Organization ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> parses = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % getattr ( self , '<STR_LIT:name>' , self . login ) <EOL> for __t in ( t for t in list ( globals ( ) . values ( ) ) if hasattr ( t , '<STR_LIT>' ) ) : <EOL> _types [ __t . parses ] = __t <EOL> class BaseEndpoint ( object ) : <EOL> BASE_URL = '<STR_LIT>' <EOL> def __init__ ( self , user , token , fetcher ) : <EOL> self . user = user <EOL> self . token = token <EOL> self . fetcher = fetcher <EOL> def _raw_fetch ( self , path , base = None , data = None , httpAuth = False , method = None ) : <EOL> if not base : <EOL> base = self . BASE_URL <EOL> p = base + path <EOL> args = '<STR_LIT>' <EOL> if self . user and self . token and not httpAuth : <EOL> params = '<STR_LIT:&>' . join ( [ '<STR_LIT>' + hclient . quote ( self . user ) , <EOL> '<STR_LIT>' + hclient . quote ( self . token ) ] ) <EOL> if '<STR_LIT:?>' in path : <EOL> p += '<STR_LIT:&>' + params <EOL> else : <EOL> p += '<STR_LIT:?>' + params <EOL> if httpAuth : <EOL> return self . fetcher ( p , data , <EOL> username = self . user , password = self . token , <EOL> method = method ) <EOL> else : <EOL> return self . fetcher ( p , data ) <EOL> def _fetch ( self , path , parselang = False ) : <EOL> rawfetch = self . _raw_fetch ( path ) . read ( ) <EOL> if parselang : <EOL> rawfetch = rawfetch . replace ( '<STR_LIT:#>' , '<STR_LIT>' ) <EOL> rawfetch = rawfetch . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> rawfetch = rawfetch . replace ( '<STR_LIT:+>' , '<STR_LIT:p>' ) <EOL> rawfetch = rawfetch . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rawfetch = rawfetch . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rawfetch = rawfetch . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rawfetch = rawfetch . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return xml . dom . minidom . parseString ( rawfetch ) <EOL> def _jfetch ( self , path , httpAuth = True ) : <EOL> return json . load ( self . _raw_fetch ( path , '<STR_LIT>' , <EOL> httpAuth = httpAuth ) ) <EOL> def _jpost ( self , path , data , httpAuth = True ) : <EOL> return json . load ( self . _raw_fetch ( path , '<STR_LIT>' , <EOL> data = data , <EOL> httpAuth = httpAuth ) ) <EOL> def _post ( self , path , ** kwargs ) : <EOL> p = { '<STR_LIT>' : self . user , '<STR_LIT>' : self . token } <EOL> p . update ( kwargs ) <EOL> return self . fetcher ( self . BASE_URL + path , urlencode ( p ) ) . read ( ) <EOL> def _put ( self , path , ** kwargs ) : <EOL> p = { '<STR_LIT>' : self . user , '<STR_LIT>' : self . token } <EOL> p . update ( kwargs ) <EOL> import urllib2 <EOL> opener = urllib2 . build_opener ( urllib2 . HTTPHandler ) <EOL> request = urllib2 . Request ( self . BASE_URL + path , data = hclient . urlencode ( p ) ) <EOL> request . get_method = lambda : '<STR_LIT>' <EOL> return opener . open ( request ) . read ( ) <EOL> def _parsed ( self , path ) : <EOL> doc = self . _fetch ( path ) <EOL> return _parse ( doc . documentElement ) <EOL> def _posted ( self , path , ** kwargs ) : <EOL> stuff = self . _post ( path , ** kwargs ) <EOL> doc = xml . dom . minidom . parseString ( stuff ) <EOL> return _parse ( doc . documentElement ) <EOL> class UserEndpoint ( BaseEndpoint ) : <EOL> def search ( self , query ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + query ) <EOL> def show ( self , username ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + username ) <EOL> def keys ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' ) <EOL> def removeKey ( self , keyId ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' , id = keyId ) <EOL> def addKey ( self , name , key ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' , name = name , key = key ) <EOL> class RepositoryEndpoint ( BaseEndpoint ) : <EOL> def forUser ( self , username , page = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + username + "<STR_LIT>" + str ( page ) ) <EOL> def branches ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> doc = self . _fetch ( "<STR_LIT>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" ) <EOL> rv = { } <EOL> for c in doc . documentElement . childNodes : <EOL> if c . nodeType != xml . dom . Node . TEXT_NODE : <EOL> rv [ c . localName ] = str ( c . firstChild . data ) <EOL> return rv <EOL> def languages ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> doc = self . _fetch ( "<STR_LIT>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" , True ) <EOL> rv = { } <EOL> for c in doc . documentElement . childNodes : <EOL> if c . nodeType != xml . dom . Node . TEXT_NODE : <EOL> rv [ c . localName ] = str ( c . firstChild . data ) <EOL> return rv <EOL> def tags ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> doc = self . _fetch ( "<STR_LIT>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" ) <EOL> rv = { } <EOL> for c in doc . documentElement . childNodes : <EOL> if c . nodeType != xml . dom . Node . TEXT_NODE : <EOL> rv [ c . localName ] = str ( c . firstChild . data ) <EOL> return rv <EOL> def search ( self , term , ** args ) : <EOL> """<STR_LIT>""" <EOL> path = '<STR_LIT>' + hclient . quote_plus ( term ) <EOL> params = "<STR_LIT:&>" . join ( [ "<STR_LIT>" % ( k , v ) for k , v in list ( args . items ( ) ) ] ) <EOL> if params : <EOL> path += '<STR_LIT>' % params <EOL> return self . _parsed ( path ) <EOL> def show ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo ] ) ) <EOL> def set ( self , user , repo , ** args ) : <EOL> """<STR_LIT>""" <EOL> prepared_args = { } <EOL> for k , v in list ( args . items ( ) ) : <EOL> prepared_args [ '<STR_LIT>' + k + '<STR_LIT:]>' ] = v <EOL> return self . _post ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo ] ) , <EOL> ** prepared_args ) <EOL> def watch ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + user + '<STR_LIT:/>' + repo ) <EOL> def unwatch ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + user + '<STR_LIT:/>' + repo ) <EOL> def watched ( self , user ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + user ) <EOL> def network ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + user + '<STR_LIT:/>' + repo + '<STR_LIT>' ) <EOL> def setVisible ( self , repo , public = True ) : <EOL> """<STR_LIT>""" <EOL> if public : <EOL> path = '<STR_LIT>' + repo <EOL> else : <EOL> path = '<STR_LIT>' + repo <EOL> self . _post ( path ) <EOL> def create ( self , name , description = '<STR_LIT>' , homepage = '<STR_LIT>' , public = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' , name = name , description = description , <EOL> homepage = homepage , public = str ( public ) ) <EOL> def delete ( self , repo ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + repo ) <EOL> def fork ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + user + '<STR_LIT:/>' + repo ) <EOL> def watchers ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' % ( user , repo ) ) <EOL> def collaborators ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' % ( user , repo ) ) <EOL> def addCollaborator ( self , repo , username ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + repo + '<STR_LIT>' + username ) <EOL> def removeCollaborator ( self , repo , username ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + repo + '<STR_LIT>' + username ) <EOL> def collaborators_all ( self ) : <EOL> """<STR_LIT>""" <EOL> ret = { } <EOL> for reponame in ( rp . name for rp in self . forUser ( self . user ) ) : <EOL> ret [ reponame ] = self . collaborators ( self . user , reponame ) <EOL> return ret <EOL> def addCollaborator_all ( self , username ) : <EOL> """<STR_LIT>""" <EOL> for reponame in ( rp . name for rp in self . forUser ( self . user ) ) : <EOL> self . addCollaborator ( reponame , username ) <EOL> def removeCollaborator_all ( self , username ) : <EOL> """<STR_LIT>""" <EOL> for reponame in ( rp . name for rp in self . forUser ( self . user ) ) : <EOL> self . removeCollaborator ( reponame , username ) <EOL> def deployKeys ( self , repo ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + repo ) <EOL> def addDeployKey ( self , repo , title , key ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + repo + '<STR_LIT>' , title = title , key = key ) <EOL> def removeDeployKey ( self , repo , keyId ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + repo + '<STR_LIT>' , id = keyId ) <EOL> def discoverHooks ( self ) : <EOL> """<STR_LIT>""" <EOL> hooks = self . _jfetch ( '<STR_LIT>' , httpAuth = False ) <EOL> return dict ( ( h [ '<STR_LIT:name>' ] , h ) for h in hooks ) <EOL> def listHooks ( self , user , repo ) : <EOL> """<STR_LIT>""" <EOL> return self . _jfetch ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , user , repo , '<STR_LIT>' ] ) ) <EOL> def getHook ( self , user , repo , hookid ) : <EOL> """<STR_LIT>""" <EOL> return self . _jfetch ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , user , repo , '<STR_LIT>' , <EOL> str ( hookid ) ] ) ) <EOL> def createHook ( self , user , repo , name , config , <EOL> events = [ "<STR_LIT>" ] , active = True ) : <EOL> """<STR_LIT>""" <EOL> doc = json . dumps ( { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : active , <EOL> '<STR_LIT>' : config , <EOL> '<STR_LIT>' : events } ) <EOL> return self . _jpost ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , user , repo , '<STR_LIT>' ] ) , doc ) <EOL> def testHook ( self , user , repo , hookid ) : <EOL> """<STR_LIT>""" <EOL> return self . _raw_fetch ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , user , repo , '<STR_LIT>' , <EOL> str ( hookid ) , '<STR_LIT:test>' ] ) , <EOL> base = '<STR_LIT>' , <EOL> data = '<STR_LIT>' , httpAuth = True ) . read ( ) <EOL> def deleteHook ( self , user , repo , hookid ) : <EOL> """<STR_LIT>""" <EOL> return self . _raw_fetch ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , user , repo , '<STR_LIT>' , <EOL> str ( hookid ) ] ) , <EOL> base = '<STR_LIT>' , <EOL> data = '<STR_LIT>' , httpAuth = True , method = '<STR_LIT>' ) . read ( ) <EOL> class CommitEndpoint ( BaseEndpoint ) : <EOL> def forBranch ( self , user , repo , branch = '<STR_LIT>' , page = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT:list>' , user , repo , branch ] ) + "<STR_LIT>" + str ( page ) ) <EOL> def forFile ( self , user , repo , path , branch = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT:list>' , user , repo , branch , path ] ) ) <EOL> @ with_temporary_mappings ( { '<STR_LIT>' : _parseArray , <EOL> '<STR_LIT>' : _parseArray , <EOL> '<STR_LIT>' : Modification , <EOL> '<STR_LIT>' : _string_parser , <EOL> '<STR_LIT:filename>' : _string_parser } ) <EOL> def show ( self , user , repo , sha ) : <EOL> """<STR_LIT>""" <EOL> c = self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , sha ] ) ) <EOL> if hasattr ( c , '<STR_LIT>' ) : <EOL> c . removed = [ i [ <NUM_LIT:0> ] for i in c . removed ] <EOL> if hasattr ( c , '<STR_LIT>' ) : <EOL> c . added = [ i [ <NUM_LIT:0> ] for i in c . added ] <EOL> return c <EOL> class IssuesEndpoint ( BaseEndpoint ) : <EOL> @ with_temporary_mappings ( { '<STR_LIT:user>' : None } ) <EOL> def search ( self , user , repo , state , search_term ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , state , <EOL> hclient . quote_plus ( search_term ) ] ) ) <EOL> @ with_temporary_mappings ( { '<STR_LIT:user>' : None } ) <EOL> def list ( self , user , repo , state = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT:list>' , user , repo , state ] ) ) <EOL> @ with_temporary_mappings ( { '<STR_LIT:user>' : None } ) <EOL> def comments ( self , user , repo , issue_id ) : <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , str ( issue_id ) ] ) ) <EOL> def add_comment ( self , user , repo , issue_id , comment ) : <EOL> """<STR_LIT>""" <EOL> return self . _post ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , <EOL> repo , str ( issue_id ) ] ) , <EOL> comment = comment ) <EOL> @ with_temporary_mappings ( { '<STR_LIT:user>' : None } ) <EOL> def show ( self , user , repo , issue_id ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , str ( issue_id ) ] ) ) <EOL> def add_label ( self , user , repo , issue_id , label ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + user + '<STR_LIT:/>' <EOL> + repo + '<STR_LIT:/>' + label + '<STR_LIT:/>' + str ( issue_id ) ) <EOL> def remove_label ( self , user , repo , issue_id , label ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT>' + user + '<STR_LIT:/>' <EOL> + repo + '<STR_LIT:/>' + label + '<STR_LIT:/>' + str ( issue_id ) ) <EOL> def close ( self , user , repo , issue_id ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , str ( issue_id ) ] ) ) <EOL> def reopen ( self , user , repo , issue_id ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , str ( issue_id ) ] ) ) <EOL> def new ( self , user , repo , title , body = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return self . _posted ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo ] ) , <EOL> title = title , body = body ) <EOL> def edit ( self , user , repo , issue_id , title , body ) : <EOL> """<STR_LIT>""" <EOL> self . _post ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , str ( issue_id ) ] ) , <EOL> title = title , body = body ) <EOL> class ObjectsEndpoint ( BaseEndpoint ) : <EOL> @ with_temporary_mappings ( { '<STR_LIT>' : Tree , '<STR_LIT:type>' : _string_parser } ) <EOL> def tree ( self , user , repo , t ) : <EOL> """<STR_LIT>""" <EOL> tl = self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , t ] ) ) <EOL> return dict ( [ ( t . name , t ) for t in tl ] ) <EOL> @ with_temporary_mappings ( { '<STR_LIT>' : Blob } ) <EOL> def blob ( self , user , repo , t , fn ) : <EOL> return self . _parsed ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , '<STR_LIT>' , user , repo , t , fn ] ) ) <EOL> def raw_blob ( self , user , repo , sha ) : <EOL> """<STR_LIT>""" <EOL> path = '<STR_LIT>' % ( user , repo , sha ) <EOL> return self . _raw_fetch ( path ) . read ( ) <EOL> class OrganizationsEndpoint ( BaseEndpoint ) : <EOL> def show ( self , org ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + org ) <EOL> def forUser ( self , username ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' + username + "<STR_LIT>" ) <EOL> def forMe ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( '<STR_LIT>' ) <EOL> def set ( self , org , ** args ) : <EOL> """<STR_LIT>""" <EOL> prepared_args = { } <EOL> for k , v in args . items ( ) : <EOL> prepared_args [ '<STR_LIT>' + k + '<STR_LIT:]>' ] = v <EOL> return self . _put ( '<STR_LIT:/>' . join ( [ '<STR_LIT>' , org ] ) , <EOL> ** prepared_args ) <EOL> def repositories ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( "<STR_LIT>" ) <EOL> def owners ( self , org ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( "<STR_LIT>" + org + "<STR_LIT>" ) <EOL> def publicRepositories ( self , org ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( "<STR_LIT>" + org + "<STR_LIT>" ) <EOL> def publicMembers ( self , org ) : <EOL> """<STR_LIT>""" <EOL> return self . _parsed ( "<STR_LIT>" + org + "<STR_LIT>" ) <EOL> class TeamsEndpoint ( BaseEndpoint ) : <EOL> def addUserToTeam ( self , team_id , username ) : <EOL> self . _post ( '<STR_LIT>' % str ( team_id ) , name = username ) <EOL> def addRepoToTeam ( self , team_id , user , repo ) : <EOL> self . _post ( '<STR_LIT>' % team_id , name = "<STR_LIT>" % ( user , repo ) ) <EOL> class GitHub ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , user = None , token = None , fetcher = hclient . fetch , base_url = None ) : <EOL> self . user = user <EOL> self . token = token <EOL> self . fetcher = fetcher <EOL> if base_url : <EOL> BaseEndpoint . BASE_URL = base_url <EOL> @ property <EOL> def users ( self ) : <EOL> """<STR_LIT>""" <EOL> return UserEndpoint ( self . user , self . token , self . fetcher ) <EOL> @ property <EOL> def repos ( self ) : <EOL> """<STR_LIT>""" <EOL> return RepositoryEndpoint ( self . user , self . token , self . fetcher ) <EOL> @ property <EOL> def commits ( self ) : <EOL> return CommitEndpoint ( self . user , self . token , self . fetcher ) <EOL> @ property <EOL> def issues ( self ) : <EOL> return IssuesEndpoint ( self . user , self . token , self . fetcher ) <EOL> @ property <EOL> def objects ( self ) : <EOL> return ObjectsEndpoint ( self . user , self . token , self . fetcher ) <EOL> @ property <EOL> def organizations ( self ) : <EOL> return OrganizationsEndpoint ( self . user , self . token , self . fetcher ) <EOL> @ property <EOL> def teams ( self ) : <EOL> return TeamsEndpoint ( self . user , self . token , self . fetcher ) </s>
