<s> """<STR_LIT>""" <EOL> import httplib2 <EOL> import logging <EOL> import googlecl <EOL> from apiclient . discovery import build_from_document <EOL> from googlecl . discovery import authentication <EOL> from googlecl . discovery import output <EOL> from googlecl . discovery import data <EOL> from googlecl . discovery import docs <EOL> import simplejson as json <EOL> LOG = logging . getLogger ( googlecl . LOGGER_NAME ) <EOL> DISCOVERY_URI = '<STR_LIT>' <EOL> class DiscoveryManager ( ) : <EOL> def __init__ ( self , email ) : <EOL> self . dataManager = data . DefaultManager ( email ) <EOL> self . docManager = docs . DocManager ( <EOL> self . dataManager . local_apis , self . dataManager . base_url ) <EOL> def run ( self , argv ) : <EOL> try : <EOL> """<STR_LIT>""" <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> isHelp = argv [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> verbose = False <EOL> if isHelp : <EOL> argv = argv [ <NUM_LIT:1> : ] <EOL> if argv [ - <NUM_LIT:1> ] == '<STR_LIT>' or argv [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> verbose = True <EOL> argv = argv [ : - <NUM_LIT:1> ] <EOL> http = httplib2 . Http ( ) <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> try : <EOL> servicename , version , doc , args = self . docManager . run ( argv , isHelp , <EOL> verbose ) <EOL> except TypeError : <EOL> return <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in doc : <EOL> if '<STR_LIT>' in args : <EOL> args . remove ( '<STR_LIT>' ) <EOL> force_auth = True <EOL> else : <EOL> force_auth = False <EOL> http = authentication . authenticate ( self . dataManager . email , servicename , doc , http , <EOL> self . dataManager . client_id , self . dataManager . client_secret , force_auth ) <EOL> service = build_from_document ( json . dumps ( <EOL> doc ) , DISCOVERY_URI % self . dataManager . base_url , http = http ) <EOL> else : <EOL> service = build_from_document ( json . dumps ( doc ) , DISCOVERY_URI % self . dataManager . base_url , <EOL> developerKey = self . dataManager . devkey2 , http = http ) <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> try : <EOL> metinfo , method , args = getMethod ( service , doc , args ) <EOL> except : <EOL> return <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> try : <EOL> kwargs = self . dataManager . fill_out_options ( metinfo , doc , args ) <EOL> except TypeError , err : <EOL> raise <EOL> return <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> try : <EOL> resp = method ( ** kwargs ) . execute ( ) <EOL> except Exception , err : <EOL> LOG . error ( err ) <EOL> return <EOL> LOG . debug ( '<STR_LIT>' ) <EOL> output . output ( resp , self . dataManager . formatting ) <EOL> except Exception , err : <EOL> print '<STR_LIT>' <EOL> raise <EOL> def apis_list ( self ) : <EOL> return [ str ( d [ '<STR_LIT:name>' ] ) for d in self . docManager . directory [ '<STR_LIT>' ] ] <EOL> def getMethod ( service , doc , args ) : <EOL> """<STR_LIT>""" <EOL> obj = doc <EOL> attr = service <EOL> i = <NUM_LIT:0> <EOL> while '<STR_LIT>' in obj or '<STR_LIT>' in obj : <EOL> if i < len ( args ) and '<STR_LIT>' in obj and args [ i ] in obj [ '<STR_LIT>' ] : <EOL> attr = getattr ( attr , args [ i ] ) <EOL> obj = obj [ '<STR_LIT>' ] [ args [ i ] ] <EOL> i = i + <NUM_LIT:1> <EOL> elif i < len ( args ) and '<STR_LIT>' in obj and args [ i ] in obj [ '<STR_LIT>' ] : <EOL> attr = getattr ( attr , args [ i ] ) <EOL> obj = obj [ '<STR_LIT>' ] [ args [ i ] ] <EOL> i = i + <NUM_LIT:1> <EOL> elif ( '<STR_LIT>' in obj and not '<STR_LIT>' in obj and <EOL> len ( obj [ '<STR_LIT>' ] ) == <NUM_LIT:1> ) : <EOL> attr = getattr ( attr , obj [ '<STR_LIT>' ] . keys ( ) [ <NUM_LIT:0> ] ) <EOL> obj = obj [ '<STR_LIT>' ] [ obj [ '<STR_LIT>' ] . keys ( ) [ <NUM_LIT:0> ] ] <EOL> elif '<STR_LIT>' in obj and not '<STR_LIT>' in obj and len ( obj [ '<STR_LIT>' ] ) == <NUM_LIT:1> : <EOL> attr = getattr ( attr , obj [ '<STR_LIT>' ] . keys ( ) [ <NUM_LIT:0> ] ) <EOL> obj = obj [ '<STR_LIT>' ] [ obj [ '<STR_LIT>' ] . keys ( ) [ <NUM_LIT:0> ] ] <EOL> else : <EOL> print '<STR_LIT>' <EOL> if '<STR_LIT>' in obj : <EOL> LOG . error ( '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( obj [ '<STR_LIT>' ] ) ) <EOL> if '<STR_LIT>' in obj : <EOL> LOG . error ( '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( obj [ '<STR_LIT>' ] ) ) <EOL> return <EOL> if not '<STR_LIT:id>' in obj : <EOL> attr = attr ( ) <EOL> return obj , attr , args [ i : ] </s>
