<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import copy <EOL> from oauth2client import util <EOL> from oauth2client . anyjson import simplejson <EOL> class Schemas ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , discovery ) : <EOL> """<STR_LIT>""" <EOL> self . schemas = discovery . get ( '<STR_LIT>' , { } ) <EOL> self . pretty = { } <EOL> @ util . positional ( <NUM_LIT:2> ) <EOL> def _prettyPrintByName ( self , name , seen = None , dent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if seen is None : <EOL> seen = [ ] <EOL> if name in seen : <EOL> return '<STR_LIT>' % name <EOL> seen . append ( name ) <EOL> if name not in self . pretty : <EOL> self . pretty [ name ] = _SchemaToStruct ( self . schemas [ name ] , <EOL> seen , dent = dent ) . to_str ( self . _prettyPrintByName ) <EOL> seen . pop ( ) <EOL> return self . pretty [ name ] <EOL> def prettyPrintByName ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . _prettyPrintByName ( name , seen = [ ] , dent = <NUM_LIT:1> ) [ : - <NUM_LIT:2> ] <EOL> @ util . positional ( <NUM_LIT:2> ) <EOL> def _prettyPrintSchema ( self , schema , seen = None , dent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if seen is None : <EOL> seen = [ ] <EOL> return _SchemaToStruct ( schema , seen , dent = dent ) . to_str ( self . _prettyPrintByName ) <EOL> def prettyPrintSchema ( self , schema ) : <EOL> """<STR_LIT>""" <EOL> return self . _prettyPrintSchema ( schema , dent = <NUM_LIT:1> ) [ : - <NUM_LIT:2> ] <EOL> def get ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . schemas [ name ] <EOL> class _SchemaToStruct ( object ) : <EOL> """<STR_LIT>""" <EOL> @ util . positional ( <NUM_LIT:3> ) <EOL> def __init__ ( self , schema , seen , dent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . value = [ ] <EOL> self . string = None <EOL> self . schema = schema <EOL> self . dent = dent <EOL> self . from_cache = None <EOL> self . seen = seen <EOL> def emit ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . value . extend ( [ "<STR_LIT:U+0020>" * self . dent , text , '<STR_LIT:\n>' ] ) <EOL> def emitBegin ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . value . extend ( [ "<STR_LIT:U+0020>" * self . dent , text ] ) <EOL> def emitEnd ( self , text , comment ) : <EOL> """<STR_LIT>""" <EOL> if comment : <EOL> divider = '<STR_LIT:\n>' + '<STR_LIT:U+0020>' * ( self . dent + <NUM_LIT:2> ) + '<STR_LIT>' <EOL> lines = comment . splitlines ( ) <EOL> lines = [ x . rstrip ( ) for x in lines ] <EOL> comment = divider . join ( lines ) <EOL> self . value . extend ( [ text , '<STR_LIT>' , comment , '<STR_LIT:\n>' ] ) <EOL> else : <EOL> self . value . extend ( [ text , '<STR_LIT:\n>' ] ) <EOL> def indent ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dent += <NUM_LIT:1> <EOL> def undent ( self ) : <EOL> """<STR_LIT>""" <EOL> self . dent -= <NUM_LIT:1> <EOL> def _to_str_impl ( self , schema ) : <EOL> """<STR_LIT>""" <EOL> stype = schema . get ( '<STR_LIT:type>' ) <EOL> if stype == '<STR_LIT:object>' : <EOL> self . emitEnd ( '<STR_LIT:{>' , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> self . indent ( ) <EOL> if '<STR_LIT>' in schema : <EOL> for pname , pschema in schema . get ( '<STR_LIT>' , { } ) . iteritems ( ) : <EOL> self . emitBegin ( '<STR_LIT>' % pname ) <EOL> self . _to_str_impl ( pschema ) <EOL> elif '<STR_LIT>' in schema : <EOL> self . emitBegin ( '<STR_LIT>' ) <EOL> self . _to_str_impl ( schema [ '<STR_LIT>' ] ) <EOL> self . undent ( ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> elif '<STR_LIT>' in schema : <EOL> schemaName = schema [ '<STR_LIT>' ] <EOL> description = schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) <EOL> s = self . from_cache ( schemaName , seen = self . seen ) <EOL> parts = s . splitlines ( ) <EOL> self . emitEnd ( parts [ <NUM_LIT:0> ] , description ) <EOL> for line in parts [ <NUM_LIT:1> : ] : <EOL> self . emit ( line . rstrip ( ) ) <EOL> elif stype == '<STR_LIT>' : <EOL> value = schema . get ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> self . emitEnd ( '<STR_LIT>' % str ( value ) , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> elif stype == '<STR_LIT:string>' : <EOL> value = schema . get ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> self . emitEnd ( '<STR_LIT>' % str ( value ) , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> elif stype == '<STR_LIT>' : <EOL> value = schema . get ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> self . emitEnd ( '<STR_LIT>' % str ( value ) , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> elif stype == '<STR_LIT>' : <EOL> value = schema . get ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> self . emitEnd ( '<STR_LIT>' % str ( value ) , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> elif stype == '<STR_LIT:null>' : <EOL> self . emitEnd ( '<STR_LIT>' , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> elif stype == '<STR_LIT>' : <EOL> self . emitEnd ( '<STR_LIT>' , schema . get ( '<STR_LIT:description>' , '<STR_LIT>' ) ) <EOL> elif stype == '<STR_LIT>' : <EOL> self . emitEnd ( '<STR_LIT:[>' , schema . get ( '<STR_LIT:description>' ) ) <EOL> self . indent ( ) <EOL> self . emitBegin ( '<STR_LIT>' ) <EOL> self . _to_str_impl ( schema [ '<STR_LIT>' ] ) <EOL> self . undent ( ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> else : <EOL> self . emit ( '<STR_LIT>' % stype ) <EOL> self . emitEnd ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . string = '<STR_LIT>' . join ( self . value ) <EOL> return self . string <EOL> def to_str ( self , from_cache ) : <EOL> """<STR_LIT>""" <EOL> self . from_cache = from_cache <EOL> return self . _to_str_impl ( self . schema ) </s>
