<s> """<STR_LIT>""" <EOL> from warnings import warnpy3k <EOL> warnpy3k ( "<STR_LIT>" , stacklevel = <NUM_LIT:2> ) <EOL> import MacOS <EOL> import EasyDialogs <EOL> import os <EOL> import string <EOL> import sys <EOL> import types <EOL> import StringIO <EOL> import keyword <EOL> import macresource <EOL> import aetools <EOL> import distutils . sysconfig <EOL> import OSATerminology <EOL> from Carbon . Res import * <EOL> import Carbon . Folder <EOL> import MacOS <EOL> import getopt <EOL> import plistlib <EOL> _MAC_LIB_FOLDER = os . path . dirname ( aetools . __file__ ) <EOL> DEFAULT_STANDARD_PACKAGEFOLDER = os . path . join ( _MAC_LIB_FOLDER , '<STR_LIT>' ) <EOL> DEFAULT_USER_PACKAGEFOLDER = distutils . sysconfig . get_python_lib ( ) <EOL> def usage ( ) : <EOL> sys . stderr . write ( "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] ) <EOL> sys . stderr . write ( """<STR_LIT>""" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def main ( ) : <EOL> if len ( sys . argv ) > <NUM_LIT:1> : <EOL> SHORTOPTS = "<STR_LIT>" <EOL> LONGOPTS = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , SHORTOPTS , LONGOPTS ) <EOL> except getopt . GetoptError : <EOL> usage ( ) <EOL> process_func = processfile <EOL> basepkgname = '<STR_LIT>' <EOL> output = None <EOL> edit_modnames = [ ] <EOL> creatorsignature = None <EOL> dump = None <EOL> verbose = None <EOL> for o , a in opts : <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> process_func = processfile_fromresource <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> basepkgname = a <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> output = a <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> split = a . split ( '<STR_LIT:=>' ) <EOL> if len ( split ) != <NUM_LIT:2> : <EOL> usage ( ) <EOL> edit_modnames . append ( split ) <EOL> if o in ( '<STR_LIT:-c>' , '<STR_LIT>' ) : <EOL> if len ( a ) != <NUM_LIT:4> : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> creatorsignature = a <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> dump = sys . stdout <EOL> if o in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> verbose = sys . stderr <EOL> if output and len ( args ) > <NUM_LIT:1> : <EOL> sys . stderr . write ( "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> for filename in args : <EOL> process_func ( filename , output = output , basepkgname = basepkgname , <EOL> edit_modnames = edit_modnames , creatorsignature = creatorsignature , <EOL> dump = dump , verbose = verbose ) <EOL> else : <EOL> main_interactive ( ) <EOL> def main_interactive ( interact = <NUM_LIT:0> , basepkgname = '<STR_LIT>' ) : <EOL> if interact : <EOL> edit_modnames = None <EOL> else : <EOL> edit_modnames = [ ] <EOL> appsfolder = Carbon . Folder . FSFindFolder ( - <NUM_LIT> , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> filename = EasyDialogs . AskFileForOpen ( <EOL> message = '<STR_LIT>' , <EOL> dialogOptionFlags = <NUM_LIT> , <EOL> defaultLocation = appsfolder ) <EOL> if not filename : <EOL> return <EOL> if not is_scriptable ( filename ) : <EOL> if EasyDialogs . AskYesNoCancel ( <EOL> "<STR_LIT>" , <EOL> yes = "<STR_LIT>" , default = <NUM_LIT:2> , no = "<STR_LIT>" ) <= <NUM_LIT:0> : <EOL> return <EOL> try : <EOL> processfile ( filename , edit_modnames = edit_modnames , basepkgname = basepkgname , <EOL> verbose = sys . stderr ) <EOL> except MacOS . Error , arg : <EOL> print "<STR_LIT>" , arg <EOL> print "<STR_LIT>" <EOL> processfile_fromresource ( filename , edit_modnames = edit_modnames , <EOL> basepkgname = basepkgname , verbose = sys . stderr ) <EOL> def is_scriptable ( application ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isdir ( application ) : <EOL> plistfile = os . path . join ( application , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( plistfile ) : <EOL> return False <EOL> plist = plistlib . Plist . fromFile ( plistfile ) <EOL> return plist . get ( '<STR_LIT>' , False ) <EOL> currf = CurResFile ( ) <EOL> try : <EOL> refno = macresource . open_pathname ( application ) <EOL> except MacOS . Error : <EOL> return False <EOL> UseResFile ( refno ) <EOL> n_terminology = Count1Resources ( '<STR_LIT>' ) + Count1Resources ( '<STR_LIT>' ) + Count1Resources ( '<STR_LIT>' ) + Count1Resources ( '<STR_LIT>' ) <EOL> CloseResFile ( refno ) <EOL> UseResFile ( currf ) <EOL> return n_terminology > <NUM_LIT:0> <EOL> def processfile_fromresource ( fullname , output = None , basepkgname = None , <EOL> edit_modnames = None , creatorsignature = None , dump = None , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> if not is_scriptable ( fullname ) and verbose : <EOL> print >> verbose , "<STR_LIT>" % fullname <EOL> cur = CurResFile ( ) <EOL> if verbose : <EOL> print >> verbose , "<STR_LIT>" , fullname <EOL> rf = macresource . open_pathname ( fullname ) <EOL> try : <EOL> UseResFile ( rf ) <EOL> resources = [ ] <EOL> for i in range ( Count1Resources ( '<STR_LIT>' ) ) : <EOL> res = Get1IndResource ( '<STR_LIT>' , <NUM_LIT:1> + i ) <EOL> resources . append ( res ) <EOL> for i in range ( Count1Resources ( '<STR_LIT>' ) ) : <EOL> res = Get1IndResource ( '<STR_LIT>' , <NUM_LIT:1> + i ) <EOL> resources . append ( res ) <EOL> if verbose : <EOL> print >> verbose , "<STR_LIT>" , repr ( fullname ) <EOL> aetelist = [ ] <EOL> for res in resources : <EOL> if verbose : <EOL> print >> verbose , "<STR_LIT>" , res . GetResInfo ( ) , "<STR_LIT>" <EOL> data = res . data <EOL> aete = decode ( data , verbose ) <EOL> aetelist . append ( ( aete , res . GetResInfo ( ) ) ) <EOL> finally : <EOL> if rf != cur : <EOL> CloseResFile ( rf ) <EOL> UseResFile ( cur ) <EOL> UseResFile ( cur ) <EOL> if dump : <EOL> dumpaetelist ( aetelist , dump ) <EOL> compileaetelist ( aetelist , fullname , output = output , <EOL> basepkgname = basepkgname , edit_modnames = edit_modnames , <EOL> creatorsignature = creatorsignature , verbose = verbose ) <EOL> def processfile ( fullname , output = None , basepkgname = None , <EOL> edit_modnames = None , creatorsignature = None , dump = None , <EOL> verbose = None ) : <EOL> """<STR_LIT>""" <EOL> if not is_scriptable ( fullname ) and verbose : <EOL> print >> verbose , "<STR_LIT>" % fullname <EOL> if verbose : <EOL> print >> verbose , "<STR_LIT>" , repr ( fullname ) <EOL> try : <EOL> aedescobj , launched = OSATerminology . GetAppTerminology ( fullname ) <EOL> except MacOS . Error , arg : <EOL> if arg [ <NUM_LIT:0> ] in ( - <NUM_LIT> , - <NUM_LIT> ) : <EOL> if verbose : <EOL> print >> verbose , "<STR_LIT>" <EOL> aedata , sig = getappterminology ( fullname , verbose = verbose ) <EOL> if not creatorsignature : <EOL> creatorsignature = sig <EOL> else : <EOL> raise <EOL> else : <EOL> if launched : <EOL> if verbose : <EOL> print >> verbose , "<STR_LIT>" , fullname <EOL> raw = aetools . unpack ( aedescobj ) <EOL> if not raw : <EOL> if verbose : <EOL> print >> verbose , '<STR_LIT>' , raw <EOL> return <EOL> if not raw [ <NUM_LIT:0> ] . data : <EOL> if verbose : <EOL> print >> verbose , '<STR_LIT>' , raw <EOL> return <EOL> aedata = raw [ <NUM_LIT:0> ] <EOL> aete = decode ( aedata . data , verbose ) <EOL> if dump : <EOL> dumpaetelist ( [ aete ] , dump ) <EOL> return <EOL> compileaete ( aete , None , fullname , output = output , basepkgname = basepkgname , <EOL> creatorsignature = creatorsignature , edit_modnames = edit_modnames , <EOL> verbose = verbose ) <EOL> def getappterminology ( fullname , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> if not MacOS . WMAvailable ( ) : <EOL> raise RuntimeError , "<STR_LIT>" <EOL> import Carbon . Evt <EOL> Carbon . Evt . WaitNextEvent ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> if os . path . isdir ( fullname ) : <EOL> pkginfo = os . path . join ( fullname , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not os . path . exists ( pkginfo ) : <EOL> raise RuntimeError , "<STR_LIT>" <EOL> tp_cr = open ( pkginfo , '<STR_LIT:rb>' ) . read ( ) <EOL> cr = tp_cr [ <NUM_LIT:4> : <NUM_LIT:8> ] <EOL> else : <EOL> cr , tp = MacOS . GetCreatorAndType ( fullname ) <EOL> talker = aetools . TalkTo ( cr ) <EOL> try : <EOL> talker . _start ( ) <EOL> except ( MacOS . Error , aetools . Error ) , arg : <EOL> if verbose : <EOL> print >> verbose , '<STR_LIT>' , arg <EOL> reply = talker . send ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return reply [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , cr <EOL> def compileaetelist ( aetelist , fullname , output = None , basepkgname = None , <EOL> edit_modnames = None , creatorsignature = None , verbose = None ) : <EOL> for aete , resinfo in aetelist : <EOL> compileaete ( aete , resinfo , fullname , output = output , <EOL> basepkgname = basepkgname , edit_modnames = edit_modnames , <EOL> creatorsignature = creatorsignature , verbose = verbose ) <EOL> def dumpaetelist ( aetelist , output ) : <EOL> import pprint <EOL> pprint . pprint ( aetelist , output ) <EOL> def decode ( data , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> f = StringIO . StringIO ( data ) <EOL> aete = generic ( getaete , f ) <EOL> aete = simplify ( aete ) <EOL> processed = f . tell ( ) <EOL> unprocessed = len ( f . read ( ) ) <EOL> total = f . tell ( ) <EOL> if unprocessed and verbose : <EOL> verbose . write ( "<STR_LIT>" % <EOL> ( processed , unprocessed , total ) ) <EOL> return aete <EOL> def simplify ( item ) : <EOL> """<STR_LIT>""" <EOL> if type ( item ) is types . ListType : <EOL> return map ( simplify , item ) <EOL> elif type ( item ) == types . TupleType and len ( item ) == <NUM_LIT:2> : <EOL> return simplify ( item [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return item <EOL> def getbyte ( f , * args ) : <EOL> c = f . read ( <NUM_LIT:1> ) <EOL> if not c : <EOL> raise EOFError , '<STR_LIT>' + str ( args ) <EOL> return ord ( c ) <EOL> def getword ( f , * args ) : <EOL> getalign ( f ) <EOL> s = f . read ( <NUM_LIT:2> ) <EOL> if len ( s ) < <NUM_LIT:2> : <EOL> raise EOFError , '<STR_LIT>' + str ( args ) <EOL> return ( ord ( s [ <NUM_LIT:0> ] ) << <NUM_LIT:8> ) | ord ( s [ <NUM_LIT:1> ] ) <EOL> def getlong ( f , * args ) : <EOL> getalign ( f ) <EOL> s = f . read ( <NUM_LIT:4> ) <EOL> if len ( s ) < <NUM_LIT:4> : <EOL> raise EOFError , '<STR_LIT>' + str ( args ) <EOL> return ( ord ( s [ <NUM_LIT:0> ] ) << <NUM_LIT> ) | ( ord ( s [ <NUM_LIT:1> ] ) << <NUM_LIT:16> ) | ( ord ( s [ <NUM_LIT:2> ] ) << <NUM_LIT:8> ) | ord ( s [ <NUM_LIT:3> ] ) <EOL> def getostype ( f , * args ) : <EOL> getalign ( f ) <EOL> s = f . read ( <NUM_LIT:4> ) <EOL> if len ( s ) < <NUM_LIT:4> : <EOL> raise EOFError , '<STR_LIT>' + str ( args ) <EOL> return s <EOL> def getpstr ( f , * args ) : <EOL> c = f . read ( <NUM_LIT:1> ) <EOL> if len ( c ) < <NUM_LIT:1> : <EOL> raise EOFError , '<STR_LIT>' + str ( args ) <EOL> nbytes = ord ( c ) <EOL> if nbytes == <NUM_LIT:0> : return '<STR_LIT>' <EOL> s = f . read ( nbytes ) <EOL> if len ( s ) < nbytes : <EOL> raise EOFError , '<STR_LIT>' + str ( args ) <EOL> return s <EOL> def getalign ( f ) : <EOL> if f . tell ( ) & <NUM_LIT:1> : <EOL> c = f . read ( <NUM_LIT:1> ) <EOL> def getlist ( f , description , getitem ) : <EOL> count = getword ( f ) <EOL> list = [ ] <EOL> for i in range ( count ) : <EOL> list . append ( generic ( getitem , f ) ) <EOL> getalign ( f ) <EOL> return list <EOL> def alt_generic ( what , f , * args ) : <EOL> print "<STR_LIT>" , repr ( what ) , args <EOL> res = vageneric ( what , f , args ) <EOL> print '<STR_LIT>' , repr ( res ) <EOL> return res <EOL> def generic ( what , f , * args ) : <EOL> if type ( what ) == types . FunctionType : <EOL> return apply ( what , ( f , ) + args ) <EOL> if type ( what ) == types . ListType : <EOL> record = [ ] <EOL> for thing in what : <EOL> item = apply ( generic , thing [ : <NUM_LIT:1> ] + ( f , ) + thing [ <NUM_LIT:1> : ] ) <EOL> record . append ( ( thing [ <NUM_LIT:1> ] , item ) ) <EOL> return record <EOL> return "<STR_LIT>" % ( what , ) <EOL> getdata = [ <EOL> ( getostype , "<STR_LIT:type>" ) , <EOL> ( getpstr , "<STR_LIT:description>" ) , <EOL> ( getword , "<STR_LIT>" ) <EOL> ] <EOL> getargument = [ <EOL> ( getpstr , "<STR_LIT:name>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getdata , "<STR_LIT>" ) <EOL> ] <EOL> getevent = [ <EOL> ( getpstr , "<STR_LIT:name>" ) , <EOL> ( getpstr , "<STR_LIT:description>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getdata , "<STR_LIT>" ) , <EOL> ( getdata , "<STR_LIT>" ) , <EOL> ( getlist , "<STR_LIT>" , getargument ) <EOL> ] <EOL> getproperty = [ <EOL> ( getpstr , "<STR_LIT:name>" ) , <EOL> ( getostype , "<STR_LIT:code>" ) , <EOL> ( getdata , "<STR_LIT>" ) <EOL> ] <EOL> getelement = [ <EOL> ( getostype , "<STR_LIT:type>" ) , <EOL> ( getlist , "<STR_LIT>" , getostype ) <EOL> ] <EOL> getclass = [ <EOL> ( getpstr , "<STR_LIT:name>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getpstr , "<STR_LIT:description>" ) , <EOL> ( getlist , "<STR_LIT>" , getproperty ) , <EOL> ( getlist , "<STR_LIT>" , getelement ) <EOL> ] <EOL> getcomparison = [ <EOL> ( getpstr , "<STR_LIT>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getpstr , "<STR_LIT>" ) , <EOL> ] <EOL> getenumerator = [ <EOL> ( getpstr , "<STR_LIT>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getpstr , "<STR_LIT>" ) <EOL> ] <EOL> getenumeration = [ <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getlist , "<STR_LIT>" , getenumerator ) <EOL> ] <EOL> getsuite = [ <EOL> ( getpstr , "<STR_LIT>" ) , <EOL> ( getpstr , "<STR_LIT>" ) , <EOL> ( getostype , "<STR_LIT>" ) , <EOL> ( getword , "<STR_LIT>" ) , <EOL> ( getword , "<STR_LIT>" ) , <EOL> ( getlist , "<STR_LIT>" , getevent ) , <EOL> ( getlist , "<STR_LIT>" , getclass ) , <EOL> ( getlist , "<STR_LIT>" , getcomparison ) , <EOL> ( getlist , "<STR_LIT>" , getenumeration ) <EOL> ] <EOL> getaete = [ <EOL> ( getword , "<STR_LIT>" ) , <EOL> ( getword , "<STR_LIT>" ) , <EOL> ( getword , "<STR_LIT>" ) , <EOL> ( getlist , "<STR_LIT>" , getsuite ) <EOL> ] <EOL> def compileaete ( aete , resinfo , fname , output = None , basepkgname = None , <EOL> edit_modnames = None , creatorsignature = None , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> [ version , language , script , suites ] = aete <EOL> major , minor = divmod ( version , <NUM_LIT> ) <EOL> if not creatorsignature : <EOL> creatorsignature , dummy = MacOS . GetCreatorAndType ( fname ) <EOL> packagename = identify ( os . path . splitext ( os . path . basename ( fname ) ) [ <NUM_LIT:0> ] ) <EOL> if language : <EOL> packagename = packagename + '<STR_LIT>' % language <EOL> if script : <EOL> packagename = packagename + '<STR_LIT>' % script <EOL> if len ( packagename ) > <NUM_LIT> : <EOL> packagename = packagename [ : <NUM_LIT> ] <EOL> if output : <EOL> if not os . path . exists ( output ) : <EOL> os . mkdir ( output ) <EOL> pathname = output <EOL> else : <EOL> pathname = EasyDialogs . AskFolder ( message = '<STR_LIT>' % packagename , <EOL> defaultLocation = DEFAULT_USER_PACKAGEFOLDER ) <EOL> output = pathname <EOL> if not pathname : <EOL> return <EOL> packagename = os . path . split ( os . path . normpath ( pathname ) ) [ <NUM_LIT:1> ] <EOL> if not basepkgname : <EOL> basepkgname = EasyDialogs . AskFolder ( message = '<STR_LIT>' , <EOL> defaultLocation = DEFAULT_STANDARD_PACKAGEFOLDER ) <EOL> if basepkgname : <EOL> dirname , basepkgname = os . path . split ( os . path . normpath ( basepkgname ) ) <EOL> if dirname and not dirname in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , dirname ) <EOL> basepackage = __import__ ( basepkgname ) <EOL> else : <EOL> basepackage = None <EOL> suitelist = [ ] <EOL> allprecompinfo = [ ] <EOL> allsuites = [ ] <EOL> for suite in suites : <EOL> compiler = SuiteCompiler ( suite , basepackage , output , edit_modnames , verbose ) <EOL> code , modname , precompinfo = compiler . precompilesuite ( ) <EOL> if not code : <EOL> continue <EOL> allprecompinfo = allprecompinfo + precompinfo <EOL> suiteinfo = suite , pathname , modname <EOL> suitelist . append ( ( code , modname ) ) <EOL> allsuites . append ( compiler ) <EOL> for compiler in allsuites : <EOL> compiler . compilesuite ( major , minor , language , script , fname , allprecompinfo ) <EOL> initfilename = os . path . join ( output , '<STR_LIT>' ) <EOL> fp = open ( initfilename , '<STR_LIT:w>' ) <EOL> MacOS . SetCreatorAndType ( initfilename , '<STR_LIT>' , '<STR_LIT>' ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( "<STR_LIT>" % ascii ( fname ) ) <EOL> if resinfo : <EOL> fp . write ( "<STR_LIT>" % ( ascii ( resinfo [ <NUM_LIT:1> ] ) , resinfo [ <NUM_LIT:0> ] , ascii ( resinfo [ <NUM_LIT:2> ] ) ) ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> suitelist . sort ( ) <EOL> for code , modname in suitelist : <EOL> fp . write ( "<STR_LIT>" % modname ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> for code , modname in suitelist : <EOL> fp . write ( "<STR_LIT>" % ( ascii ( code ) , modname ) ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> for code , modname in suitelist : <EOL> fp . write ( "<STR_LIT>" % ( ascii ( code ) , packagename , modname , modname ) ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> for code , modname in suitelist : <EOL> fp . write ( "<STR_LIT>" % modname ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT:\n>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> allprecompinfo . sort ( ) <EOL> if allprecompinfo : <EOL> fp . write ( "<STR_LIT>" ) <EOL> for codenamemapper in allprecompinfo : <EOL> for k , v in codenamemapper . getall ( '<STR_LIT:class>' ) : <EOL> fp . write ( "<STR_LIT>" % v ) <EOL> application_class = None <EOL> if allprecompinfo : <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> for codenamemapper in allprecompinfo : <EOL> for k , v in codenamemapper . getall ( '<STR_LIT:class>' ) : <EOL> fp . write ( "<STR_LIT>" % ( k , v ) ) <EOL> if k == '<STR_LIT>' : <EOL> application_class = v <EOL> fp . write ( "<STR_LIT>" ) <EOL> if suitelist : <EOL> fp . write ( "<STR_LIT>" % ( packagename , suitelist [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) ) <EOL> for code , modname in suitelist [ <NUM_LIT:1> : ] : <EOL> fp . write ( "<STR_LIT>" % modname ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" % ( creatorsignature , ) ) <EOL> fp . write ( "<STR_LIT>" % packagename ) <EOL> if application_class : <EOL> fp . write ( "<STR_LIT>" % application_class ) <EOL> fp . write ( "<STR_LIT>" % application_class ) <EOL> fp . close ( ) <EOL> class SuiteCompiler : <EOL> def __init__ ( self , suite , basepackage , output , edit_modnames , verbose ) : <EOL> self . suite = suite <EOL> self . basepackage = basepackage <EOL> self . edit_modnames = edit_modnames <EOL> self . output = output <EOL> self . verbose = verbose <EOL> self . pathname = None <EOL> self . modname = None <EOL> self . fp = None <EOL> self . basemodule = None <EOL> self . enumsneeded = { } <EOL> def precompilesuite ( self ) : <EOL> """<STR_LIT>""" <EOL> [ name , desc , code , level , version , events , classes , comps , enums ] = self . suite <EOL> modname = identify ( name ) <EOL> if len ( modname ) > <NUM_LIT> : <EOL> modname = modname [ : <NUM_LIT> ] <EOL> if self . edit_modnames is None : <EOL> self . pathname = EasyDialogs . AskFileForSave ( message = '<STR_LIT>' , <EOL> savedFileName = modname + '<STR_LIT>' ) <EOL> else : <EOL> for old , new in self . edit_modnames : <EOL> if old == modname : <EOL> modname = new <EOL> if modname : <EOL> self . pathname = os . path . join ( self . output , modname + '<STR_LIT>' ) <EOL> else : <EOL> self . pathname = None <EOL> if not self . pathname : <EOL> return None , None , None <EOL> self . modname = os . path . splitext ( os . path . split ( self . pathname ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:0> ] <EOL> if self . basepackage and code in self . basepackage . _code_to_module : <EOL> basemodule = self . basepackage . _code_to_module [ code ] <EOL> else : <EOL> basemodule = None <EOL> self . enumsneeded = { } <EOL> for event in events : <EOL> self . findenumsinevent ( event ) <EOL> objc = ObjectCompiler ( None , self . modname , basemodule , interact = ( self . edit_modnames is None ) , <EOL> verbose = self . verbose ) <EOL> for cls in classes : <EOL> objc . compileclass ( cls ) <EOL> for cls in classes : <EOL> objc . fillclasspropsandelems ( cls ) <EOL> for comp in comps : <EOL> objc . compilecomparison ( comp ) <EOL> for enum in enums : <EOL> objc . compileenumeration ( enum ) <EOL> for enum in self . enumsneeded . keys ( ) : <EOL> objc . checkforenum ( enum ) <EOL> objc . dumpindex ( ) <EOL> precompinfo = objc . getprecompinfo ( self . modname ) <EOL> return code , self . modname , precompinfo <EOL> def compilesuite ( self , major , minor , language , script , fname , precompinfo ) : <EOL> """<STR_LIT>""" <EOL> [ name , desc , code , level , version , events , classes , comps , enums ] = self . suite <EOL> def class_sorter ( k1 , k2 ) : <EOL> """<STR_LIT>""" <EOL> if k1 [ <NUM_LIT:1> ] < k2 [ <NUM_LIT:1> ] : return - <NUM_LIT:1> <EOL> if k1 [ <NUM_LIT:1> ] > k2 [ <NUM_LIT:1> ] : return <NUM_LIT:1> <EOL> if not k2 [ <NUM_LIT:3> ] or k2 [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> return - <NUM_LIT:1> <EOL> if not k1 [ <NUM_LIT:3> ] or k1 [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> events . sort ( ) <EOL> classes . sort ( class_sorter ) <EOL> comps . sort ( ) <EOL> enums . sort ( ) <EOL> self . fp = fp = open ( self . pathname , '<STR_LIT:w>' ) <EOL> MacOS . SetCreatorAndType ( self . pathname , '<STR_LIT>' , '<STR_LIT>' ) <EOL> fp . write ( '<STR_LIT>' % ( ascii ( name ) , ascii ( desc ) ) ) <EOL> fp . write ( "<STR_LIT>" % ( level , version ) ) <EOL> fp . write ( "<STR_LIT>" % ascii ( fname ) ) <EOL> fp . write ( "<STR_LIT>" % ( major , minor , language , script ) ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( "<STR_LIT>" % ( code , ) ) <EOL> if self . basepackage and code in self . basepackage . _code_to_module : <EOL> fp . write ( '<STR_LIT>' % self . basepackage . _code_to_fullname [ code ] [ <NUM_LIT:0> ] ) <EOL> basemodule = self . basepackage . _code_to_module [ code ] <EOL> elif self . basepackage and code . lower ( ) in self . basepackage . _code_to_module : <EOL> fp . write ( '<STR_LIT>' % self . basepackage . _code_to_fullname [ code . lower ( ) ] [ <NUM_LIT:0> ] ) <EOL> basemodule = self . basepackage . _code_to_module [ code . lower ( ) ] <EOL> else : <EOL> basemodule = None <EOL> self . basemodule = basemodule <EOL> self . compileclassheader ( ) <EOL> self . enumsneeded = { } <EOL> if events : <EOL> for event in events : <EOL> self . compileevent ( event ) <EOL> else : <EOL> fp . write ( "<STR_LIT>" ) <EOL> objc = ObjectCompiler ( fp , self . modname , basemodule , precompinfo , interact = ( self . edit_modnames is None ) , <EOL> verbose = self . verbose ) <EOL> for cls in classes : <EOL> objc . compileclass ( cls ) <EOL> for cls in classes : <EOL> objc . fillclasspropsandelems ( cls ) <EOL> for comp in comps : <EOL> objc . compilecomparison ( comp ) <EOL> for enum in enums : <EOL> objc . compileenumeration ( enum ) <EOL> for enum in self . enumsneeded . keys ( ) : <EOL> objc . checkforenum ( enum ) <EOL> objc . dumpindex ( ) <EOL> def compileclassheader ( self ) : <EOL> """<STR_LIT>""" <EOL> classname = '<STR_LIT>' % self . modname <EOL> if self . basemodule : <EOL> modshortname = string . split ( self . basemodule . __name__ , '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> baseclassname = '<STR_LIT>' % modshortname <EOL> self . fp . write ( "<STR_LIT>" % ( classname , baseclassname ) ) <EOL> else : <EOL> self . fp . write ( "<STR_LIT>" % classname ) <EOL> def compileevent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> [ name , desc , code , subcode , returns , accepts , arguments ] = event <EOL> fp = self . fp <EOL> funcname = identify ( name ) <EOL> if arguments : <EOL> fp . write ( "<STR_LIT>" % funcname ) <EOL> for a in arguments : <EOL> fp . write ( "<STR_LIT>" % ( identify ( a [ <NUM_LIT:0> ] ) , a [ <NUM_LIT:1> ] ) ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> has_arg = ( not is_null ( accepts ) ) <EOL> opt_arg = ( has_arg and is_optional ( accepts ) ) <EOL> fp . write ( "<STR_LIT>" % funcname ) <EOL> if has_arg : <EOL> if not opt_arg : <EOL> fp . write ( "<STR_LIT>" ) <EOL> else : <EOL> fp . write ( "<STR_LIT>" ) <EOL> else : <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( '<STR_LIT>' % ( ascii ( name ) , ascii ( desc ) ) ) <EOL> if has_arg : <EOL> fp . write ( "<STR_LIT>" % getdatadoc ( accepts ) ) <EOL> elif opt_arg : <EOL> fp . write ( "<STR_LIT>" % getdatadoc ( accepts ) ) <EOL> for arg in arguments : <EOL> fp . write ( "<STR_LIT>" % ( identify ( arg [ <NUM_LIT:0> ] ) , <EOL> getdatadoc ( arg [ <NUM_LIT:2> ] ) ) ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> if not is_null ( returns ) : <EOL> fp . write ( "<STR_LIT>" % getdatadoc ( returns ) ) <EOL> fp . write ( '<STR_LIT>' ) <EOL> fp . write ( "<STR_LIT>" % ( code , ) ) <EOL> fp . write ( "<STR_LIT>" % ( subcode , ) ) <EOL> if arguments : <EOL> fp . write ( "<STR_LIT>" % funcname ) <EOL> else : <EOL> fp . write ( "<STR_LIT>" ) <EOL> if has_arg : <EOL> fp . write ( "<STR_LIT>" ) <EOL> elif opt_arg : <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> else : <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT:\n>" ) <EOL> for a in arguments : <EOL> if is_enum ( a [ <NUM_LIT:2> ] ) : <EOL> kname = a [ <NUM_LIT:1> ] <EOL> ename = a [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] <EOL> if ename != '<STR_LIT>' : <EOL> fp . write ( "<STR_LIT>" % <EOL> ( kname , identify ( ename ) ) ) <EOL> self . enumsneeded [ ename ] = <NUM_LIT:1> <EOL> fp . write ( "<STR_LIT:\n>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> if is_enum ( returns ) : <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT>" ) <EOL> fp . write ( "<STR_LIT:\n>" ) <EOL> def findenumsinevent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> [ name , desc , code , subcode , returns , accepts , arguments ] = event <EOL> for a in arguments : <EOL> if is_enum ( a [ <NUM_LIT:2> ] ) : <EOL> ename = a [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] <EOL> if ename != '<STR_LIT>' : <EOL> self . enumsneeded [ ename ] = <NUM_LIT:1> <EOL> class CodeNameMapper : <EOL> def __init__ ( self , interact = <NUM_LIT:1> , verbose = None ) : <EOL> self . code2name = { <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:class>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> } <EOL> self . name2code = { <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:class>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> } <EOL> self . modulename = None <EOL> self . star_imported = <NUM_LIT:0> <EOL> self . can_interact = interact <EOL> self . verbose = verbose <EOL> def addnamecode ( self , type , name , code ) : <EOL> self . name2code [ type ] [ name ] = code <EOL> if code not in self . code2name [ type ] : <EOL> self . code2name [ type ] [ code ] = name <EOL> def hasname ( self , name ) : <EOL> for dict in self . name2code . values ( ) : <EOL> if name in dict : <EOL> return True <EOL> return False <EOL> def hascode ( self , type , code ) : <EOL> return code in self . code2name [ type ] <EOL> def findcodename ( self , type , code ) : <EOL> if not self . hascode ( type , code ) : <EOL> return None , None , None <EOL> name = self . code2name [ type ] [ code ] <EOL> if self . modulename and not self . star_imported : <EOL> qualname = '<STR_LIT>' % ( self . modulename , name ) <EOL> else : <EOL> qualname = name <EOL> return name , qualname , self . modulename <EOL> def getall ( self , type ) : <EOL> return self . code2name [ type ] . items ( ) <EOL> def addmodule ( self , module , name , star_imported ) : <EOL> self . modulename = name <EOL> self . star_imported = star_imported <EOL> for code , name in module . _propdeclarations . items ( ) : <EOL> self . addnamecode ( '<STR_LIT>' , name , code ) <EOL> for code , name in module . _classdeclarations . items ( ) : <EOL> self . addnamecode ( '<STR_LIT:class>' , name , code ) <EOL> for code in module . _enumdeclarations . keys ( ) : <EOL> self . addnamecode ( '<STR_LIT>' , '<STR_LIT>' + identify ( code ) , code ) <EOL> for code , name in module . _compdeclarations . items ( ) : <EOL> self . addnamecode ( '<STR_LIT>' , name , code ) <EOL> def prepareforexport ( self , name = None ) : <EOL> if not self . modulename : <EOL> self . modulename = name <EOL> return self <EOL> class ObjectCompiler : <EOL> def __init__ ( self , fp , modname , basesuite , othernamemappers = None , interact = <NUM_LIT:1> , <EOL> verbose = None ) : <EOL> self . fp = fp <EOL> self . verbose = verbose <EOL> self . basesuite = basesuite <EOL> self . can_interact = interact <EOL> self . modulename = modname <EOL> self . namemappers = [ CodeNameMapper ( self . can_interact , self . verbose ) ] <EOL> if othernamemappers : <EOL> self . othernamemappers = othernamemappers [ : ] <EOL> else : <EOL> self . othernamemappers = [ ] <EOL> if basesuite : <EOL> basemapper = CodeNameMapper ( self . can_interact , self . verbose ) <EOL> basemapper . addmodule ( basesuite , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . namemappers . append ( basemapper ) <EOL> def getprecompinfo ( self , modname ) : <EOL> list = [ ] <EOL> for mapper in self . namemappers : <EOL> emapper = mapper . prepareforexport ( modname ) <EOL> if emapper : <EOL> list . append ( emapper ) <EOL> return list <EOL> def findcodename ( self , type , code ) : <EOL> while <NUM_LIT:1> : <EOL> for mapper in self . namemappers : <EOL> if mapper . hascode ( type , code ) : <EOL> return mapper . findcodename ( type , code ) <EOL> for mapper in self . othernamemappers : <EOL> if mapper . hascode ( type , code ) : <EOL> self . othernamemappers . remove ( mapper ) <EOL> self . namemappers . append ( mapper ) <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % mapper . modulename ) <EOL> break <EOL> else : <EOL> if self . fp : <EOL> m = self . askdefinitionmodule ( type , code ) <EOL> else : <EOL> m = None <EOL> if not m : return None , None , None <EOL> mapper = CodeNameMapper ( self . can_interact , self . verbose ) <EOL> mapper . addmodule ( m , m . __name__ , <NUM_LIT:0> ) <EOL> self . namemappers . append ( mapper ) <EOL> def hasname ( self , name ) : <EOL> for mapper in self . othernamemappers : <EOL> if mapper . hasname ( name ) and mapper . modulename != self . modulename : <EOL> if self . verbose : <EOL> print >> self . verbose , "<STR_LIT>" , name , self . modulename , mapper . modulename <EOL> return True <EOL> return False <EOL> def askdefinitionmodule ( self , type , code ) : <EOL> if not self . can_interact : <EOL> if self . verbose : <EOL> print >> self . verbose , "<STR_LIT>" % ( type , code ) <EOL> return None <EOL> path = EasyDialogs . AskFileForSave ( message = '<STR_LIT>' % ( type , code ) ) <EOL> if not path : return <EOL> path , file = os . path . split ( path ) <EOL> modname = os . path . splitext ( file ) [ <NUM_LIT:0> ] <EOL> if not path in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , path ) <EOL> m = __import__ ( modname ) <EOL> self . fp . write ( "<STR_LIT>" % modname ) <EOL> return m <EOL> def compileclass ( self , cls ) : <EOL> [ name , code , desc , properties , elements ] = cls <EOL> pname = identify ( name ) <EOL> if self . namemappers [ <NUM_LIT:0> ] . hascode ( '<STR_LIT:class>' , code ) : <EOL> othername , dummy , dummy = self . namemappers [ <NUM_LIT:0> ] . findcodename ( '<STR_LIT:class>' , code ) <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( pname , othername ) ) <EOL> else : <EOL> if self . fp : <EOL> self . fp . write ( '<STR_LIT>' % pname ) <EOL> self . fp . write ( '<STR_LIT>' % ( ascii ( name ) , ascii ( desc ) ) ) <EOL> self . fp . write ( '<STR_LIT>' % ( code , ) ) <EOL> self . namemappers [ <NUM_LIT:0> ] . addnamecode ( '<STR_LIT:class>' , pname , code ) <EOL> is_application_class = ( code == '<STR_LIT>' ) <EOL> properties . sort ( ) <EOL> for prop in properties : <EOL> self . compileproperty ( prop , is_application_class ) <EOL> elements . sort ( ) <EOL> for elem in elements : <EOL> self . compileelement ( elem ) <EOL> def compileproperty ( self , prop , is_application_class = False ) : <EOL> [ name , code , what ] = prop <EOL> if code == '<STR_LIT>' : <EOL> return <EOL> pname = identify ( name ) <EOL> if self . namemappers [ <NUM_LIT:0> ] . hascode ( '<STR_LIT>' , code ) : <EOL> othername , dummy , dummy = self . namemappers [ <NUM_LIT:0> ] . findcodename ( '<STR_LIT>' , code ) <EOL> if pname == othername : <EOL> return <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( pname , othername ) ) <EOL> else : <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % pname ) <EOL> self . fp . write ( '<STR_LIT>' % ( ascii ( name ) , ascii ( what [ <NUM_LIT:1> ] ) ) ) <EOL> self . fp . write ( "<STR_LIT>" % ( code , ) ) <EOL> self . fp . write ( "<STR_LIT>" % ( what [ <NUM_LIT:0> ] , ) ) <EOL> self . namemappers [ <NUM_LIT:0> ] . addnamecode ( '<STR_LIT>' , pname , code ) <EOL> if is_application_class and self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( pname , pname ) ) <EOL> def compileelement ( self , elem ) : <EOL> [ code , keyform ] = elem <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( code , keyform ) ) <EOL> def fillclasspropsandelems ( self , cls ) : <EOL> [ name , code , desc , properties , elements ] = cls <EOL> cname = identify ( name ) <EOL> if self . namemappers [ <NUM_LIT:0> ] . hascode ( '<STR_LIT:class>' , code ) and self . namemappers [ <NUM_LIT:0> ] . findcodename ( '<STR_LIT:class>' , code ) [ <NUM_LIT:0> ] != cname : <EOL> if self . fp and ( elements or len ( properties ) > <NUM_LIT:1> or ( len ( properties ) == <NUM_LIT:1> and <EOL> properties [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] != '<STR_LIT>' ) ) : <EOL> if self . verbose : <EOL> print >> self . verbose , '<STR_LIT>' % ( cname , self . namemappers [ <NUM_LIT:0> ] . findcodename ( '<STR_LIT:class>' , code ) [ <NUM_LIT:0> ] , code ) <EOL> raise RuntimeError , "<STR_LIT>" <EOL> return <EOL> plist = [ ] <EOL> elist = [ ] <EOL> superclasses = [ ] <EOL> for prop in properties : <EOL> [ pname , pcode , what ] = prop <EOL> if pcode == "<STR_LIT>" : <EOL> superclasses . append ( what ) <EOL> if pcode == '<STR_LIT>' : <EOL> continue <EOL> pname = identify ( pname ) <EOL> plist . append ( pname ) <EOL> superclassnames = [ ] <EOL> for superclass in superclasses : <EOL> superId , superDesc , dummy = superclass <EOL> superclassname , fullyqualifiedname , module = self . findcodename ( "<STR_LIT:class>" , superId ) <EOL> if superclassname == cname : <EOL> pass <EOL> else : <EOL> superclassnames . append ( superclassname ) <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( cname , superclassnames ) ) <EOL> for elem in elements : <EOL> [ ecode , keyform ] = elem <EOL> if ecode == '<STR_LIT>' : <EOL> continue <EOL> name , ename , module = self . findcodename ( '<STR_LIT:class>' , ecode ) <EOL> if not name : <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( cname , ecode ) ) <EOL> else : <EOL> elist . append ( ( name , ename ) ) <EOL> plist . sort ( ) <EOL> elist . sort ( ) <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % cname ) <EOL> for n in plist : <EOL> self . fp . write ( "<STR_LIT>" % ( n , n ) ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> self . fp . write ( "<STR_LIT>" % cname ) <EOL> for n , fulln in elist : <EOL> self . fp . write ( "<STR_LIT>" % ( n , fulln ) ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> def compilecomparison ( self , comp ) : <EOL> [ name , code , comment ] = comp <EOL> iname = identify ( name ) <EOL> self . namemappers [ <NUM_LIT:0> ] . addnamecode ( '<STR_LIT>' , iname , code ) <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % iname ) <EOL> self . fp . write ( '<STR_LIT>' % ( ascii ( name ) , ascii ( comment ) ) ) <EOL> def compileenumeration ( self , enum ) : <EOL> [ code , items ] = enum <EOL> name = "<STR_LIT>" % identify ( code ) <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % name ) <EOL> for item in items : <EOL> self . compileenumerator ( item ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> self . namemappers [ <NUM_LIT:0> ] . addnamecode ( '<STR_LIT>' , name , code ) <EOL> return code <EOL> def compileenumerator ( self , item ) : <EOL> [ name , code , desc ] = item <EOL> self . fp . write ( "<STR_LIT>" % ( identify ( name ) , code , ascii ( desc ) ) ) <EOL> def checkforenum ( self , enum ) : <EOL> """<STR_LIT>""" <EOL> name , fullname , module = self . findcodename ( '<STR_LIT>' , enum ) <EOL> if not name : <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( identify ( enum ) , ascii ( enum ) ) ) <EOL> return <EOL> if module : <EOL> if self . fp : <EOL> self . fp . write ( "<STR_LIT>" % ( module , name ) ) <EOL> def dumpindex ( self ) : <EOL> if not self . fp : <EOL> return <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> classlist = self . namemappers [ <NUM_LIT:0> ] . getall ( '<STR_LIT:class>' ) <EOL> classlist . sort ( ) <EOL> for k , v in classlist : <EOL> self . fp . write ( "<STR_LIT>" % ( k , v ) ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> proplist = self . namemappers [ <NUM_LIT:0> ] . getall ( '<STR_LIT>' ) <EOL> proplist . sort ( ) <EOL> for k , v in proplist : <EOL> self . fp . write ( "<STR_LIT>" % ( k , v ) ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> complist = self . namemappers [ <NUM_LIT:0> ] . getall ( '<STR_LIT>' ) <EOL> complist . sort ( ) <EOL> for k , v in complist : <EOL> self . fp . write ( "<STR_LIT>" % ( k , v ) ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> enumlist = self . namemappers [ <NUM_LIT:0> ] . getall ( '<STR_LIT>' ) <EOL> enumlist . sort ( ) <EOL> for k , v in enumlist : <EOL> self . fp . write ( "<STR_LIT>" % ( k , v ) ) <EOL> self . fp . write ( "<STR_LIT>" ) <EOL> def compiledata ( data ) : <EOL> [ type , description , flags ] = data <EOL> return "<STR_LIT>" % ( type , description , compiledataflags ( flags ) ) <EOL> def is_null ( data ) : <EOL> return data [ <NUM_LIT:0> ] == '<STR_LIT:null>' <EOL> def is_optional ( data ) : <EOL> return ( data [ <NUM_LIT:2> ] & <NUM_LIT> ) <EOL> def is_enum ( data ) : <EOL> return ( data [ <NUM_LIT:2> ] & <NUM_LIT> ) <EOL> def getdatadoc ( data ) : <EOL> [ type , descr , flags ] = data <EOL> if descr : <EOL> return ascii ( descr ) <EOL> if type == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> if type == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> return "<STR_LIT>" % ( type , ) <EOL> dataflagdict = { <NUM_LIT:15> : "<STR_LIT>" , <NUM_LIT> : "<STR_LIT:list>" , <NUM_LIT> : "<STR_LIT>" , <NUM_LIT:12> : "<STR_LIT>" } <EOL> def compiledataflags ( flags ) : <EOL> bits = [ ] <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> if flags & ( <NUM_LIT:1> << i ) : <EOL> if i in dataflagdict . keys ( ) : <EOL> bits . append ( dataflagdict [ i ] ) <EOL> else : <EOL> bits . append ( repr ( i ) ) <EOL> return '<STR_LIT>' % string . join ( bits ) <EOL> def ascii ( str ) : <EOL> """<STR_LIT>""" <EOL> if type ( str ) != type ( '<STR_LIT>' ) : <EOL> return map ( ascii , str ) <EOL> rv = '<STR_LIT>' <EOL> for c in str : <EOL> if c in ( '<STR_LIT:\t>' , '<STR_LIT:\n>' , '<STR_LIT:\r>' ) or '<STR_LIT:U+0020>' <= c < chr ( <NUM_LIT> ) : <EOL> rv = rv + c <EOL> else : <EOL> rv = rv + '<STR_LIT:\\>' + '<STR_LIT>' % ord ( c ) <EOL> return rv <EOL> def identify ( str ) : <EOL> """<STR_LIT>""" <EOL> if not str : <EOL> return "<STR_LIT>" <EOL> rv = '<STR_LIT>' <EOL> ok = string . ascii_letters + '<STR_LIT:_>' <EOL> ok2 = ok + string . digits <EOL> for c in str : <EOL> if c in ok : <EOL> rv = rv + c <EOL> elif c == '<STR_LIT:U+0020>' : <EOL> rv = rv + '<STR_LIT:_>' <EOL> else : <EOL> rv = rv + '<STR_LIT>' % ord ( c ) <EOL> ok = ok2 <EOL> if keyword . iskeyword ( rv ) : <EOL> rv = rv + '<STR_LIT:_>' <EOL> return rv <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
