<s> import re <EOL> import time <EOL> import getopt <EOL> import imp <EOL> import sys <EOL> import types <EOL> import errno <EOL> __version__ = <NUM_LIT:0.5> <EOL> from xml . etree import cElementTree as ElementTree <EOL> INDENT = <NUM_LIT:4> * "<STR_LIT:U+0020>" <EOL> DEBUG = False <EOL> XMLSCHEMA = "<STR_LIT>" <EOL> XML_NAMESPACE = '<STR_LIT>' <EOL> CLASS_PROP = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> BASE_ELEMENT = [ "<STR_LIT:text>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> class MissingPrerequisite ( Exception ) : <EOL> pass <EOL> def sd_copy ( arg ) : <EOL> try : <EOL> return arg . copy ( ) <EOL> except AttributeError : <EOL> return { } <EOL> def class_pyify ( ref ) : <EOL> return ref . replace ( "<STR_LIT:->" , "<STR_LIT:_>" ) <EOL> PROTECTED_KEYWORDS = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def def_init ( imports , attributes ) : <EOL> indent = INDENT + INDENT <EOL> indent3 = INDENT + INDENT + INDENT <EOL> line = [ "<STR_LIT>" % INDENT ] <EOL> for elem in attributes : <EOL> if elem [ <NUM_LIT:0> ] in PROTECTED_KEYWORDS : <EOL> _name = elem [ <NUM_LIT:0> ] + "<STR_LIT:_>" <EOL> else : <EOL> _name = elem [ <NUM_LIT:0> ] <EOL> if elem [ <NUM_LIT:2> ] : <EOL> line . append ( "<STR_LIT>" % ( indent3 , _name , elem [ <NUM_LIT:2> ] ) ) <EOL> else : <EOL> line . append ( "<STR_LIT>" % ( indent3 , _name , elem [ <NUM_LIT:2> ] ) ) <EOL> for _ , elems in imports . items ( ) : <EOL> for elem in elems : <EOL> if elem in PROTECTED_KEYWORDS : <EOL> _name = elem + "<STR_LIT:_>" <EOL> else : <EOL> _name = elem <EOL> line . append ( "<STR_LIT>" % ( indent3 , _name ) ) <EOL> line . append ( "<STR_LIT>" % indent3 ) <EOL> line . append ( "<STR_LIT>" % indent3 ) <EOL> line . append ( "<STR_LIT>" % indent3 ) <EOL> line . append ( "<STR_LIT>" % indent ) <EOL> return line <EOL> def base_init ( imports ) : <EOL> line = [ ] <EOL> indent4 = INDENT + INDENT + INDENT + INDENT <EOL> if not imports : <EOL> line . append ( "<STR_LIT>" % ( INDENT + INDENT ) ) <EOL> for attr in BASE_ELEMENT : <EOL> if attr in PROTECTED_KEYWORDS : <EOL> _name = attr + "<STR_LIT:_>" <EOL> else : <EOL> _name = attr <EOL> line . append ( "<STR_LIT>" % ( indent4 , _name , _name ) ) <EOL> line . append ( "<STR_LIT>" % indent4 ) <EOL> else : <EOL> for sup , elems in imports . items ( ) : <EOL> line . append ( "<STR_LIT>" % ( INDENT + INDENT , sup ) ) <EOL> lattr = elems [ : ] <EOL> lattr . extend ( BASE_ELEMENT ) <EOL> for attr in lattr : <EOL> if attr in PROTECTED_KEYWORDS : <EOL> _name = attr + "<STR_LIT:_>" <EOL> else : <EOL> _name = attr <EOL> line . append ( "<STR_LIT>" % ( indent4 , _name , _name ) ) <EOL> line . append ( "<STR_LIT>" % indent4 ) <EOL> return line <EOL> def initialize ( attributes ) : <EOL> indent = INDENT + INDENT <EOL> line = [ ] <EOL> for prop , val , _default in attributes : <EOL> if prop in PROTECTED_KEYWORDS : <EOL> _name = prop + "<STR_LIT:_>" <EOL> else : <EOL> _name = prop <EOL> if val in PROTECTED_KEYWORDS : <EOL> _vname = val + "<STR_LIT:_>" <EOL> else : <EOL> _vname = val <EOL> line . append ( "<STR_LIT>" % ( indent , _name , _vname ) ) <EOL> return line <EOL> def _mod_typ ( prop ) : <EOL> try : <EOL> ( mod , typ ) = prop . type <EOL> except ValueError : <EOL> typ = prop . type <EOL> mod = None <EOL> except TypeError : <EOL> try : <EOL> ( mod , typ ) = prop . ref <EOL> except ValueError : <EOL> if prop . class_name : <EOL> typ = prop . class_name <EOL> else : <EOL> typ = prop . ref <EOL> mod = None <EOL> return mod , typ <EOL> def _mod_cname ( prop , cdict ) : <EOL> if hasattr ( prop , "<STR_LIT>" ) : <EOL> cname = prop . class_name <EOL> mod = None <EOL> else : <EOL> ( mod , typ ) = _mod_typ ( prop ) <EOL> if not mod : <EOL> try : <EOL> cname = cdict [ typ ] . class_name <EOL> except KeyError : <EOL> cname = cdict [ class_pyify ( typ ) ] . class_name <EOL> else : <EOL> cname = typ <EOL> return mod , cname <EOL> def leading_uppercase ( string ) : <EOL> try : <EOL> return string [ <NUM_LIT:0> ] . upper ( ) + string [ <NUM_LIT:1> : ] <EOL> except IndexError : <EOL> return string <EOL> except TypeError : <EOL> return "<STR_LIT>" <EOL> def leading_lowercase ( string ) : <EOL> try : <EOL> return string [ <NUM_LIT:0> ] . lower ( ) + string [ <NUM_LIT:1> : ] <EOL> except IndexError : <EOL> return string <EOL> except TypeError : <EOL> return "<STR_LIT>" <EOL> def rm_duplicates ( properties ) : <EOL> keys = [ ] <EOL> clist = [ ] <EOL> for prop in properties : <EOL> if prop . name in keys : <EOL> continue <EOL> else : <EOL> clist . append ( prop ) <EOL> keys . append ( prop . name ) <EOL> return clist <EOL> def klass_namn ( obj ) : <EOL> if obj . class_name : <EOL> return obj . class_name <EOL> else : <EOL> return obj . name <EOL> class PyObj ( object ) : <EOL> def __init__ ( self , name = None , pyname = None , root = None ) : <EOL> self . name = name <EOL> self . done = False <EOL> self . local = True <EOL> self . root = root <EOL> self . superior = [ ] <EOL> self . value_type = "<STR_LIT>" <EOL> self . properties = ( [ ] , [ ] ) <EOL> self . abstract = False <EOL> self . class_name = "<STR_LIT>" <EOL> if pyname : <EOL> self . pyname = pyname <EOL> elif name : <EOL> self . pyname = pyify ( name ) <EOL> else : <EOL> self . pyname = name <EOL> self . type = None <EOL> def child_spec ( self , target_namespace , prop , mod , typ , lista ) : <EOL> if mod : <EOL> namesp = external_namespace ( self . root . modul [ mod ] ) <EOL> pkey = '<STR_LIT>' % ( namesp , prop . name ) <EOL> typ = "<STR_LIT>" % ( mod , typ ) <EOL> else : <EOL> pkey = '<STR_LIT>' % ( target_namespace , prop . name ) <EOL> if lista : <EOL> return "<STR_LIT>" % ( <EOL> pkey , prop . pyname , typ ) <EOL> else : <EOL> return "<STR_LIT>" % ( <EOL> pkey , prop . pyname , typ ) <EOL> def knamn ( self , sup , cdict ) : <EOL> cname = cdict [ sup ] . class_name <EOL> if not cname : <EOL> ( namesp , tag ) = cdict [ sup ] . name . split ( '<STR_LIT:.>' ) <EOL> if namesp : <EOL> ctag = self . root . modul [ namesp ] . factory ( tag ) . __class__ . __name__ <EOL> cname = '<STR_LIT>' % ( namesp , ctag ) <EOL> else : <EOL> cname = tag + "<STR_LIT:_>" <EOL> return cname <EOL> def _do_properties ( self , line , cdict , ignore , target_namespace ) : <EOL> args = [ ] <EOL> child = [ ] <EOL> try : <EOL> ( own , inh ) = self . properties <EOL> except AttributeError : <EOL> ( own , inh ) = ( [ ] , [ ] ) <EOL> for prop in own : <EOL> if isinstance ( prop , PyAttribute ) : <EOL> line . append ( "<STR_LIT>" % ( INDENT , <EOL> prop . name , prop . spec ( ) ) ) <EOL> if prop . fixed : <EOL> args . append ( ( prop . pyname , prop . fixed , None ) ) <EOL> else : <EOL> if prop . default : <EOL> args . append ( ( prop . pyname , prop . pyname , prop . default ) ) <EOL> else : <EOL> args . append ( ( prop . pyname , prop . pyname , None ) ) <EOL> elif isinstance ( prop , PyElement ) : <EOL> ( mod , cname ) = _mod_cname ( prop , cdict ) <EOL> if prop . max == "<STR_LIT>" : <EOL> lista = True <EOL> pmax = <NUM_LIT:0> <EOL> else : <EOL> pmax = int ( prop . max ) <EOL> lista = False <EOL> if prop . name in ignore : <EOL> pass <EOL> else : <EOL> line . append ( "<STR_LIT>" % ( INDENT , self . child_spec ( <EOL> target_namespace , prop , <EOL> mod , cname , <EOL> lista ) ) ) <EOL> pmin = int ( getattr ( prop , '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> if pmax == <NUM_LIT:1> and pmin == <NUM_LIT:1> : <EOL> pass <EOL> elif prop . max == "<STR_LIT>" : <EOL> line . append ( "<STR_LIT>" % ( <EOL> INDENT , prop . pyname , pmin ) ) <EOL> else : <EOL> line . append ( <EOL> "<STR_LIT>" % ( <EOL> INDENT , prop . pyname , pmin , pmax ) ) <EOL> child . append ( prop . pyname ) <EOL> if lista : <EOL> args . append ( ( prop . pyname , "<STR_LIT>" % ( prop . pyname , ) , <EOL> None ) ) <EOL> else : <EOL> args . append ( ( prop . pyname , prop . pyname , None ) ) <EOL> return args , child , inh <EOL> def _superiors ( self , cdict ) : <EOL> imps = { } <EOL> try : <EOL> superior = self . superior <EOL> sups = [ ] <EOL> for sup in superior : <EOL> klass = self . knamn ( sup , cdict ) <EOL> sups . append ( klass ) <EOL> imps [ klass ] = [ ] <EOL> for cla in cdict [ sup ] . properties [ <NUM_LIT:0> ] : <EOL> if cla . pyname and cla . pyname not in imps [ klass ] : <EOL> imps [ klass ] . append ( cla . pyname ) <EOL> except AttributeError : <EOL> superior = [ ] <EOL> sups = [ ] <EOL> return superior , sups , imps <EOL> def class_definition ( self , target_namespace , cdict = None , ignore = None ) : <EOL> line = [ ] <EOL> if self . root : <EOL> if self . name not in [ c . name for c in self . root . elems ] : <EOL> self . root . elems . append ( self ) <EOL> ( superior , sups , imps ) = self . _superiors ( cdict ) <EOL> c_name = klass_namn ( self ) <EOL> if not superior : <EOL> line . append ( "<STR_LIT>" % ( c_name , ) ) <EOL> else : <EOL> line . append ( "<STR_LIT>" % ( c_name , "<STR_LIT:U+002C>" . join ( sups ) ) ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> pass <EOL> else : <EOL> line . append ( "<STR_LIT>" % ( INDENT , <EOL> target_namespace , <EOL> self . name ) ) <EOL> line . append ( "<STR_LIT>" ) <EOL> line . append ( "<STR_LIT>" % ( INDENT , self . name ) ) <EOL> line . append ( "<STR_LIT>" % ( INDENT , ) ) <EOL> try : <EOL> if self . value_type : <EOL> if isinstance ( self . value_type , basestring ) : <EOL> line . append ( "<STR_LIT>" % ( INDENT , <EOL> self . value_type ) ) <EOL> else : <EOL> line . append ( "<STR_LIT>" % ( INDENT , <EOL> self . value_type ) ) <EOL> except AttributeError : <EOL> pass <EOL> if not superior : <EOL> for var , cps in CLASS_PROP : <EOL> line . append ( "<STR_LIT>" % ( INDENT , var , var , cps ) ) <EOL> else : <EOL> for sup in sups : <EOL> for var , cps in CLASS_PROP : <EOL> line . append ( "<STR_LIT>" % ( INDENT , var , sup , var , <EOL> cps ) ) <EOL> ( args , child , inh ) = self . _do_properties ( line , cdict , ignore , <EOL> target_namespace ) <EOL> if child : <EOL> line . append ( "<STR_LIT>" % ( INDENT , <EOL> "<STR_LIT:'>" + "<STR_LIT>" . join ( child ) + "<STR_LIT:'>" ) ) <EOL> if args : <EOL> if inh : <EOL> cname = self . knamn ( self . superior [ <NUM_LIT:0> ] , cdict ) <EOL> imps = { cname : [ c . pyname for c in inh if c . pyname ] } <EOL> line . append ( "<STR_LIT>" ) <EOL> line . extend ( def_init ( imps , args ) ) <EOL> line . extend ( base_init ( imps ) ) <EOL> line . extend ( initialize ( args ) ) <EOL> line . append ( "<STR_LIT>" ) <EOL> if not self . abstract or not self . class_name . endswith ( "<STR_LIT:_>" ) : <EOL> line . append ( "<STR_LIT>" % pyify ( <EOL> self . class_name ) ) <EOL> line . append ( <EOL> "<STR_LIT>" % ( <EOL> INDENT , self . class_name ) ) <EOL> line . append ( "<STR_LIT>" ) <EOL> self . done = True <EOL> return "<STR_LIT:\n>" . join ( line ) <EOL> def prepend ( add , orig ) : <EOL> res = [ add ] <EOL> if orig : <EOL> res . extend ( orig ) <EOL> return res <EOL> def pyobj_factory ( name , value_type , elms = None ) : <EOL> pyobj = PyObj ( name , pyify ( name ) ) <EOL> pyobj . value_type = value_type <EOL> if elms : <EOL> if name not in [ c . name for c in elms ] : <EOL> elms . append ( pyobj ) <EOL> return pyobj <EOL> def pyelement_factory ( name , value_type , elms = None ) : <EOL> obj = PyElement ( name , pyify ( name ) ) <EOL> obj . value_type = value_type <EOL> if elms : <EOL> if name not in [ c . name for c in elms ] : <EOL> elms . append ( obj ) <EOL> return obj <EOL> def expand_groups ( properties , cdict ) : <EOL> res = [ ] <EOL> for prop in properties : <EOL> if isinstance ( prop , PyGroup ) : <EOL> cname = prop . ref [ <NUM_LIT:1> ] <EOL> res . extend ( cdict [ cname ] . properties [ <NUM_LIT:0> ] ) <EOL> else : <EOL> res . append ( prop ) <EOL> return res <EOL> class PyElement ( PyObj ) : <EOL> def __init__ ( self , name = None , pyname = None , root = None , parent = "<STR_LIT>" ) : <EOL> PyObj . __init__ ( self , name , pyname , root ) <EOL> if parent : <EOL> self . class_name = "<STR_LIT>" % ( leading_uppercase ( parent ) , self . name ) <EOL> else : <EOL> self . class_name = leading_uppercase ( self . name ) <EOL> self . ref = None <EOL> self . min = <NUM_LIT:1> <EOL> self . max = <NUM_LIT:1> <EOL> self . definition = None <EOL> self . orig = None <EOL> def undefined ( self , cdict ) : <EOL> try : <EOL> ( mod , typ ) = self . type <EOL> if not mod : <EOL> cname = leading_uppercase ( typ ) <EOL> if not cdict [ cname ] . done : <EOL> return [ cdict [ cname ] ] , [ ] <EOL> except ValueError : <EOL> pass <EOL> except TypeError : <EOL> if isinstance ( self . type , PyType ) : <EOL> return self . type . undefined ( cdict ) <EOL> elif isinstance ( self . ref , tuple ) : <EOL> pass <EOL> else : <EOL> cname = leading_uppercase ( self . ref ) <EOL> if not cdict [ cname ] . done : <EOL> return [ cdict [ cname ] ] , [ ] <EOL> return [ ] , [ ] <EOL> def _local_class ( self , typ , cdict , child , target_namespace , ignore ) : <EOL> if typ in cdict and not cdict [ typ ] . done : <EOL> raise MissingPrerequisite ( typ ) <EOL> else : <EOL> self . orig = { "<STR_LIT:type>" : self . type } <EOL> try : <EOL> self . orig [ "<STR_LIT>" ] = self . superior <EOL> except AttributeError : <EOL> self . orig [ "<STR_LIT>" ] = [ ] <EOL> self . superior = [ typ ] <EOL> req = self . class_definition ( target_namespace , cdict , <EOL> ignore ) <EOL> if not child : <EOL> req = [ req ] <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> cdict [ self . name ] = self <EOL> cdict [ self . name ] . done = True <EOL> if child : <EOL> cdict [ self . name ] . local = True <EOL> self . type = ( None , self . name ) <EOL> return req <EOL> def _external_class ( self , mod , typ , cdict , child , target_namespace , <EOL> ignore ) : <EOL> cname = self . root . modul [ mod ] . factory ( typ ) . __class__ . __name__ <EOL> imp_name = "<STR_LIT>" % ( mod , cname ) <EOL> if imp_name not in cdict : <EOL> impo = pyelement_factory ( imp_name , None , None ) <EOL> impo . properties = [ _import_attrs ( self . root . modul [ mod ] , typ , <EOL> self . root ) , [ ] ] <EOL> impo . class_name = imp_name <EOL> cdict [ imp_name ] = impo <EOL> impo . done = True <EOL> if child : <EOL> impo . local = True <EOL> self . superior = [ imp_name ] <EOL> text = self . class_definition ( target_namespace , cdict , <EOL> ignore = ignore ) <EOL> return text <EOL> def text ( self , target_namespace , cdict , child = True , ignore = None ) : <EOL> if ignore is None : <EOL> ignore = [ ] <EOL> if child : <EOL> text = [ ] <EOL> else : <EOL> text = None <EOL> req = [ ] <EOL> try : <EOL> ( mod , typ ) = self . type <EOL> if not mod : <EOL> req = self . _local_class ( typ , cdict , child , <EOL> target_namespace , ignore ) <EOL> else : <EOL> text = self . _external_class ( mod , typ , cdict , child , <EOL> target_namespace , ignore ) <EOL> except ValueError : <EOL> if self . type : <EOL> text = self . class_definition ( target_namespace , cdict , <EOL> ignore = ignore ) <EOL> if child : <EOL> self . local = True <EOL> self . done = True <EOL> except TypeError : <EOL> if isinstance ( self . type , PyObj ) : <EOL> pyobj = self . type <EOL> pyobj . name = self . name <EOL> pyobj . pyname = self . pyname <EOL> pyobj . class_name = self . class_name <EOL> cdict [ self . name ] = pyobj <EOL> return pyobj . text ( target_namespace , cdict , ignore = ignore ) <EOL> elif isinstance ( self . ref , tuple ) : <EOL> ( mod , typ ) = self . ref <EOL> if mod : <EOL> if verify_import ( self . root . modul [ mod ] , typ ) : <EOL> return req , text <EOL> else : <EOL> raise Exception ( <EOL> "<STR_LIT>" % ( <EOL> typ , mod ) ) <EOL> elif not child : <EOL> self . superior = [ typ ] <EOL> text = self . class_definition ( target_namespace , cdict , <EOL> ignore = ignore ) <EOL> else : <EOL> if not cdict [ class_pyify ( self . ref ) ] . done : <EOL> raise MissingPrerequisite ( self . ref ) <EOL> self . done = True <EOL> return req , text <EOL> def _do ( obj , target_namespace , cdict , prep ) : <EOL> try : <EOL> ( req , text ) = obj . text ( target_namespace , cdict ) <EOL> except MissingPrerequisite : <EOL> return [ ] , None <EOL> if text is None : <EOL> if req : <EOL> prep . append ( req ) <EOL> return prep , None <EOL> else : <EOL> obj . done = True <EOL> if req : <EOL> if isinstance ( req , basestring ) : <EOL> prep . append ( req ) <EOL> else : <EOL> prep . extend ( req ) <EOL> if text : <EOL> prep . append ( text ) <EOL> return prep <EOL> def reqursive_superior ( supc , cdict ) : <EOL> properties = supc . properties [ <NUM_LIT:0> ] <EOL> for sup in supc . superior : <EOL> rsup = cdict [ sup ] <EOL> if rsup . properties [ <NUM_LIT:1> ] : <EOL> properties . extend ( rsup . properties [ <NUM_LIT:1> ] ) <EOL> else : <EOL> properties . extend ( reqursive_superior ( rsup , cdict ) ) <EOL> return properties <EOL> class PyType ( PyObj ) : <EOL> def __init__ ( self , name = None , pyname = None , root = None , superior = None , <EOL> internal = True , namespace = None ) : <EOL> PyObj . __init__ ( self , name , pyname , root ) <EOL> self . class_name = leading_uppercase ( self . name + '<STR_LIT:_>' ) <EOL> self . properties = ( [ ] , [ ] ) <EOL> if superior : <EOL> self . superior = [ superior ] <EOL> else : <EOL> self . superior = [ ] <EOL> self . value_type = None <EOL> self . internal = internal <EOL> self . namespace = namespace <EOL> def text ( self , target_namespace , cdict , _child = True , ignore = None , <EOL> _session = None ) : <EOL> if not self . properties and not self . type and not self . superior : <EOL> self . done = True <EOL> return [ ] , self . class_definition ( target_namespace , cdict ) <EOL> if ignore is None : <EOL> ignore = [ ] <EOL> req = [ ] <EOL> inherited_properties = [ ] <EOL> for sup in self . superior : <EOL> try : <EOL> supc = cdict [ sup ] <EOL> except KeyError : <EOL> ( mod , typ ) = sup . split ( '<STR_LIT:.>' ) <EOL> supc = pyobj_factory ( sup , None , None ) <EOL> if mod : <EOL> supc . properties = [ _import_attrs ( self . root . modul [ mod ] , <EOL> typ , self . root ) , [ ] ] <EOL> cdict [ sup ] = supc <EOL> supc . done = True <EOL> if not supc . done : <EOL> res = _do ( supc , target_namespace , cdict , req ) <EOL> if isinstance ( res , tuple ) : <EOL> return res <EOL> if not self . properties [ <NUM_LIT:1> ] : <EOL> inherited_properties = reqursive_superior ( supc , cdict ) <EOL> if inherited_properties : <EOL> self . properties = ( self . properties [ <NUM_LIT:0> ] , <EOL> rm_duplicates ( inherited_properties ) ) <EOL> ( own , inh ) = self . properties <EOL> own = rm_duplicates ( expand_groups ( own , cdict ) ) <EOL> self . properties = ( own , inh ) <EOL> for prop in own : <EOL> if not prop . name : <EOL> continue <EOL> if not prop . done : <EOL> if prop . name in ignore : <EOL> continue <EOL> res = _do ( prop , target_namespace , cdict , req ) <EOL> if res == ( [ ] , None ) : <EOL> res = ( req , None ) <EOL> if isinstance ( res , tuple ) : <EOL> return res <EOL> return req , self . class_definition ( target_namespace , cdict , ignore ) <EOL> def undefined ( self , cdict ) : <EOL> undef = ( [ ] , [ ] ) <EOL> for sup in self . superior : <EOL> supc = cdict [ sup ] <EOL> if not supc . done : <EOL> undef [ <NUM_LIT:0> ] . append ( supc ) <EOL> ( own , _ ) = self . properties <EOL> for prop in own : <EOL> if not prop . name : <EOL> continue <EOL> if isinstance ( prop , PyAttribute ) : <EOL> continue <EOL> if not prop . done : <EOL> undef [ <NUM_LIT:1> ] . append ( prop ) <EOL> return undef <EOL> class PyAttribute ( PyObj ) : <EOL> def __init__ ( self , name = None , pyname = None , root = None , external = False , <EOL> namespace = "<STR_LIT>" , required = False , typ = "<STR_LIT>" ) : <EOL> PyObj . __init__ ( self , name , pyname , root ) <EOL> self . required = required <EOL> self . external = external <EOL> self . namespace = namespace <EOL> self . base = None <EOL> self . type = typ <EOL> self . fixed = False <EOL> self . default = None <EOL> def text ( self , _target_namespace , cdict , _child = True ) : <EOL> if isinstance ( self . type , PyObj ) : <EOL> if not cdict [ self . type . name ] . done : <EOL> raise MissingPrerequisite ( self . type . name ) <EOL> return [ ] , [ ] <EOL> def spec ( self ) : <EOL> if isinstance ( self . type , PyObj ) : <EOL> return "<STR_LIT>" % ( self . pyname , self . type . class_name , <EOL> self . required ) <EOL> else : <EOL> if self . type : <EOL> return "<STR_LIT>" % ( self . pyname , self . type , <EOL> self . required ) <EOL> else : <EOL> return "<STR_LIT>" % ( self . pyname , self . base , <EOL> self . required ) <EOL> class PyAny ( PyObj ) : <EOL> def __init__ ( self , name = None , pyname = None , _external = False , _namespace = "<STR_LIT>" ) : <EOL> PyObj . __init__ ( self , name , pyname ) <EOL> self . done = True <EOL> class PyAttributeGroup ( object ) : <EOL> def __init__ ( self , name , root ) : <EOL> self . name = name <EOL> self . root = root <EOL> self . properties = [ ] <EOL> class PyGroup ( object ) : <EOL> def __init__ ( self , name , root ) : <EOL> self . name = name <EOL> self . root = root <EOL> self . properties = [ ] <EOL> self . done = False <EOL> self . ref = [ ] <EOL> def text ( self , _target_namespace , _dict , _child , _ignore ) : <EOL> return [ ] , [ ] <EOL> def undefined ( self , _cdict ) : <EOL> undef = ( [ ] , [ ] ) <EOL> ( own , _ ) = self . properties <EOL> for prop in own : <EOL> if not prop . name : <EOL> continue <EOL> if not prop . done : <EOL> undef [ <NUM_LIT:1> ] . append ( prop ) <EOL> return undef <EOL> def verify_import ( modul , tag ) : <EOL> try : <EOL> _ = modul . factory ( tag ) <EOL> return True <EOL> except Exception : <EOL> return False <EOL> def external_namespace ( modul ) : <EOL> return modul . NAMESPACE <EOL> def _import_attrs ( modul , tag , top ) : <EOL> obj = modul . factory ( tag ) <EOL> properties = [ PyAttribute ( key , val [ <NUM_LIT:0> ] , top , True , obj . c_namespace , val [ <NUM_LIT:2> ] , <EOL> val [ <NUM_LIT:1> ] ) for key , val in obj . c_attributes . items ( ) ] <EOL> for child in obj . c_child_order : <EOL> for key , val in obj . c_children . items ( ) : <EOL> ( pyn , mul ) = val <EOL> maximum = <NUM_LIT:1> <EOL> if isinstance ( mul , list ) : <EOL> mul = mul [ <NUM_LIT:0> ] <EOL> maximum = "<STR_LIT>" <EOL> if pyn == child : <EOL> cpy = PyElement ( name = mul . c_tag , pyname = pyn , root = top ) <EOL> cpy . max = maximum <EOL> properties . append ( cpy ) <EOL> return properties <EOL> def _spec ( elem ) : <EOL> try : <EOL> name = elem . name <EOL> except AttributeError : <EOL> name = "<STR_LIT>" <EOL> txt = "<STR_LIT:%s>" % name <EOL> try : <EOL> txt += "<STR_LIT>" % elem . ref <EOL> except AttributeError : <EOL> try : <EOL> txt += "<STR_LIT>" % elem . type <EOL> except AttributeError : <EOL> pass <EOL> return txt <EOL> def _do_from_string ( name ) : <EOL> print <EOL> print "<STR_LIT>" % pyify ( name ) <EOL> print "<STR_LIT>" % ( <EOL> INDENT , name ) <EOL> def _namespace_and_tag ( obj , param , top ) : <EOL> try : <EOL> ( namespace , tag ) = param . split ( "<STR_LIT::>" ) <EOL> except ValueError : <EOL> namespace = "<STR_LIT>" <EOL> tag = param <EOL> return namespace , tag <EOL> class Simple ( object ) : <EOL> def __init__ ( self , elem ) : <EOL> self . default = None <EOL> self . fixed = None <EOL> self . xmlns_map = [ ] <EOL> self . name = "<STR_LIT>" <EOL> self . type = None <EOL> self . use = None <EOL> self . ref = None <EOL> self . scoped = False <EOL> self . itemType = None <EOL> for attribute , value in elem . attrib . iteritems ( ) : <EOL> self . __setattr__ ( attribute , value ) <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> argv_copy = sd_copy ( argv ) <EOL> rval = self . repr ( top , sup , argv_copy , True , parent ) <EOL> if rval : <EOL> return [ rval ] , [ ] <EOL> else : <EOL> return [ ] , [ ] <EOL> def repr ( self , _top = None , _sup = None , _argv = None , _child = True , _parent = "<STR_LIT>" ) : <EOL> return None <EOL> def elements ( self , _top ) : <EOL> return [ ] <EOL> class Any ( Simple ) : <EOL> def repr ( self , _top = None , _sup = None , _argv = None , _child = True , _parent = "<STR_LIT>" ) : <EOL> return PyAny ( ) <EOL> class AnyAttribute ( Simple ) : <EOL> def repr ( self , _top = None , _sup = None , _argv = None , _child = True , _parent = "<STR_LIT>" ) : <EOL> return PyAny ( ) <EOL> class Attribute ( Simple ) : <EOL> def repr ( self , top = None , sup = None , _argv = None , _child = True , _parent = "<STR_LIT>" ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" , self . __dict__ <EOL> external = False <EOL> name = "<STR_LIT>" <EOL> try : <EOL> ( namespace , tag ) = _namespace_and_tag ( self , self . ref , top ) <EOL> ref = True <EOL> pyname = tag <EOL> if namespace in self . xmlns_map : <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> name = tag <EOL> else : <EOL> external = True <EOL> name = "<STR_LIT>" % ( self . xmlns_map [ namespace ] , tag ) <EOL> else : <EOL> if namespace == "<STR_LIT>" : <EOL> name = "<STR_LIT>" % ( XML_NAMESPACE , tag ) <EOL> except AttributeError : <EOL> name = self . name <EOL> pyname = pyify ( name ) <EOL> ref = False <EOL> except ValueError : <EOL> ref = True <EOL> if "<STR_LIT>" == top . target_namespace : <EOL> name = self . ref <EOL> pyname = pyify ( name ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % self . ref ) <EOL> objekt = PyAttribute ( name , pyname , external = external , root = top ) <EOL> if not ref : <EOL> try : <EOL> ( namespace , klass ) = _namespace_and_tag ( self , self . type , top ) <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> ctyp = get_type_def ( klass , top . parts ) <EOL> if not ctyp . py_class : <EOL> ctyp . repr ( top , sup ) <EOL> objekt . type = ctyp . py_class <EOL> elif self . xmlns_map [ namespace ] == XMLSCHEMA : <EOL> objekt . type = klass <EOL> else : <EOL> objekt . type = self . type <EOL> except ValueError : <EOL> if self . xmlns_map [ "<STR_LIT>" ] == top . target_namespace : <EOL> ctyp = get_type_def ( self . type . replace ( "<STR_LIT:->" , "<STR_LIT:_>" ) , top . parts ) <EOL> if not ctyp . py_class : <EOL> ctyp . repr ( top , sup ) <EOL> objekt . type = ctyp . py_class <EOL> else : <EOL> objekt . type = self . type <EOL> except AttributeError : <EOL> objekt . type = None <EOL> try : <EOL> if self . use == "<STR_LIT>" : <EOL> objekt . required = True <EOL> except AttributeError : <EOL> pass <EOL> try : <EOL> objekt . default = self . default <EOL> except AttributeError : <EOL> pass <EOL> try : <EOL> objekt . fixed = self . fixed <EOL> except AttributeError : <EOL> pass <EOL> if DEBUG : <EOL> print "<STR_LIT>" % ( objekt , ) <EOL> return objekt <EOL> class Enumeration ( Simple ) : <EOL> pass <EOL> class Union ( Simple ) : <EOL> pass <EOL> class Import ( Simple ) : <EOL> pass <EOL> class Documentation ( Simple ) : <EOL> pass <EOL> class MaxLength ( Simple ) : <EOL> pass <EOL> class Length ( Simple ) : <EOL> pass <EOL> class MinInclusive ( Simple ) : <EOL> pass <EOL> class MaxInclusive ( Simple ) : <EOL> pass <EOL> class MinExclusive ( Simple ) : <EOL> pass <EOL> class MaxExclusive ( Simple ) : <EOL> pass <EOL> class List ( Simple ) : <EOL> pass <EOL> class Include ( Simple ) : <EOL> pass <EOL> def sequence ( elem ) : <EOL> return [ evaluate ( child . tag , child ) for child in elem ] <EOL> def name_or_ref ( elem , top ) : <EOL> try : <EOL> ( namespace , name ) = _namespace_and_tag ( elem , elem . ref , top ) <EOL> if namespace and elem . xmlns_map [ namespace ] == top . target_namespace : <EOL> return name <EOL> else : <EOL> return elem . ref <EOL> except AttributeError : <EOL> return elem . name <EOL> class Complex ( object ) : <EOL> def __init__ ( self , elem ) : <EOL> self . value_of = "<STR_LIT>" <EOL> self . parts = [ ] <EOL> self . _own = [ ] <EOL> self . _inherited = [ ] <EOL> self . _generated = False <EOL> self . py_class = None <EOL> self . properties = [ ] <EOL> self . ref = None <EOL> self . type = None <EOL> self . xmlns_map = [ ] <EOL> self . maxOccurs = <NUM_LIT:1> <EOL> self . minOccurs = <NUM_LIT:1> <EOL> self . base = None <EOL> self . scoped = False <EOL> self . abstract = False <EOL> for attribute , value in elem . attrib . iteritems ( ) : <EOL> self . __setattr__ ( attribute , value ) <EOL> try : <EOL> if elem . text . strip ( ) : <EOL> self . value_of = elem . text . strip ( ) <EOL> except AttributeError : <EOL> pass <EOL> self . do_child ( elem ) <EOL> try : <EOL> self . name = self . name . replace ( "<STR_LIT:->" , "<STR_LIT:_>" ) <EOL> except AttributeError : <EOL> pass <EOL> def _extend ( self , top , sup , argv = None , parent = "<STR_LIT>" , base = "<STR_LIT>" ) : <EOL> argv_copy = sd_copy ( argv ) <EOL> for part in self . parts : <EOL> ( own , inh ) = part . collect ( top , sup , argv_copy , parent ) <EOL> if own and base : <EOL> if len ( own ) == <NUM_LIT:1> and isinstance ( own [ <NUM_LIT:0> ] , PyAttribute ) : <EOL> own [ <NUM_LIT:0> ] . base = base <EOL> self . _own . extend ( own ) <EOL> self . _inherited . extend ( inh ) <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> if self . _own or self . _inherited : <EOL> return self . _own , self . _inherited <EOL> if DEBUG : <EOL> print self . __dict__ <EOL> print "<STR_LIT>" % len ( self . parts ) <EOL> self . _extend ( top , sup , argv , parent ) <EOL> return self . _own , self . _inherited <EOL> def do_child ( self , elem ) : <EOL> for child in elem : <EOL> self . parts . append ( evaluate ( child . tag , child ) ) <EOL> def elements ( self , top ) : <EOL> res = [ ] <EOL> for part in self . parts : <EOL> if isinstance ( part , Element ) : <EOL> res . append ( name_or_ref ( part , top ) ) <EOL> else : <EOL> if isinstance ( part , Extension ) : <EOL> res . append ( part . base ) <EOL> res . extend ( part . elements ( top ) ) <EOL> return res <EOL> def repr ( self , _top = None , _sup = None , _argv = None , _child = True , parent = "<STR_LIT>" ) : <EOL> return None <EOL> def significant_parts ( self ) : <EOL> res = [ ] <EOL> for p in self . parts : <EOL> if isinstance ( p , Annotation ) : <EOL> continue <EOL> else : <EOL> res . append ( p ) <EOL> return res <EOL> def min_max ( cls , objekt , argv ) : <EOL> try : <EOL> objekt . max = argv [ "<STR_LIT>" ] <EOL> if cls . maxOccurs != <NUM_LIT:1> : <EOL> objekt . max = cls . maxOccurs <EOL> except ( KeyError , TypeError ) : <EOL> objekt . max = cls . maxOccurs <EOL> try : <EOL> objekt . min = argv [ "<STR_LIT>" ] <EOL> if cls . minOccurs != <NUM_LIT:1> : <EOL> objekt . min = cls . minOccurs <EOL> except ( KeyError , TypeError ) : <EOL> objekt . min = cls . minOccurs <EOL> class Element ( Complex ) : <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT:%s>" % ( self . __dict__ , ) <EOL> def klass ( self , top ) : <EOL> xns = None <EOL> ctyp = None <EOL> ref = False <EOL> try : <EOL> ( namespace , name ) = _namespace_and_tag ( self , self . ref , top ) <EOL> ref = True <EOL> except AttributeError : <EOL> try : <EOL> ( namespace , name ) = self . type . split ( "<STR_LIT::>" ) <EOL> except ValueError : <EOL> namespace = None <EOL> name = self . type <EOL> except AttributeError : <EOL> namespace = name = None <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> ctyp = get_type_def ( name , top . parts ) <EOL> else : <EOL> xns = namespace <EOL> return namespace , name , ctyp , xns , ref <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> argv_copy = sd_copy ( argv ) <EOL> return [ self . repr ( top , sup , argv_copy , parent = parent ) ] , [ ] <EOL> except AttributeError , exc : <EOL> print "<STR_LIT>" , exc <EOL> return [ ] , [ ] <EOL> def elements ( self , top ) : <EOL> ( _namespace , name , ctyp , xns , _ ) = self . klass ( top ) <EOL> if ctyp : <EOL> return ctyp . elements ( top ) <EOL> elif xns : <EOL> return [ "<STR_LIT>" % ( xns , name ) ] <EOL> else : <EOL> return [ ] <EOL> def repr ( self , top = None , sup = None , argv = None , child = True , parent = "<STR_LIT>" ) : <EOL> if self . py_class : <EOL> return self . py_class <EOL> try : <EOL> myname = self . name <EOL> except AttributeError : <EOL> myname = "<STR_LIT>" <EOL> if DEBUG : <EOL> print "<STR_LIT>" % ( myname , <EOL> child , <EOL> self . _generated ) <EOL> self . py_class = objekt = PyElement ( myname , root = top ) <EOL> min_max ( self , objekt , argv ) <EOL> try : <EOL> ( namespace , superkl ) = _namespace_and_tag ( self , self . ref , top ) <EOL> if not myname : <EOL> objekt . name = superkl <EOL> objekt . pyname = pyify ( superkl ) <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> objekt . ref = superkl <EOL> else : <EOL> objekt . ref = ( namespace , superkl ) <EOL> except AttributeError , exc : <EOL> if DEBUG : <EOL> print "<STR_LIT>" , exc <EOL> typ = self . type <EOL> try : <EOL> ( namespace , klass ) = _namespace_and_tag ( self , typ , top ) <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> objekt . type = ( None , klass ) <EOL> elif self . xmlns_map [ namespace ] == XMLSCHEMA : <EOL> objekt . type = klass <EOL> objekt . value_type = { "<STR_LIT>" : klass } <EOL> else : <EOL> objekt . type = ( namespace , klass ) <EOL> except ValueError : <EOL> objekt . type = typ <EOL> objekt . value_type = { "<STR_LIT>" : typ } <EOL> except AttributeError : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> if len ( self . parts ) == <NUM_LIT:1> : <EOL> if isinstance ( self . parts [ <NUM_LIT:0> ] , ComplexType ) or isinstance ( self . parts [ <NUM_LIT:0> ] , SimpleType ) : <EOL> self . parts [ <NUM_LIT:0> ] . name = self . name <EOL> objekt . type = self . parts [ <NUM_LIT:0> ] . repr ( top , sup , <EOL> parent = self . name ) <EOL> objekt . scoped = True <EOL> elif len ( self . parts ) == <NUM_LIT:2> : <EOL> if isinstance ( self . parts [ <NUM_LIT:0> ] , Annotation ) : <EOL> self . parts [ <NUM_LIT:1> ] . name = self . name <EOL> objekt . type = self . parts [ <NUM_LIT:1> ] . repr ( top , sup , <EOL> parent = self . name ) <EOL> objekt . scoped = True <EOL> elif isinstance ( self . parts [ <NUM_LIT:1> ] , Annotation ) : <EOL> self . parts [ <NUM_LIT:0> ] . name = self . name <EOL> objekt . type = self . parts [ <NUM_LIT:0> ] . repr ( top , sup , <EOL> parent = self . name ) <EOL> objekt . scoped = True <EOL> else : <EOL> if DEBUG : <EOL> print "<STR_LIT:$>" , self <EOL> raise <EOL> if parent : <EOL> objekt . class_name = "<STR_LIT>" % ( <EOL> leading_uppercase ( parent ) , <EOL> objekt . name ) <EOL> objekt . scoped = True <EOL> return objekt <EOL> class SimpleType ( Complex ) : <EOL> def repr ( self , top = None , _sup = None , _argv = None , _child = True , parent = "<STR_LIT>" ) : <EOL> if self . py_class : <EOL> return self . py_class <EOL> obj = PyType ( self . name , root = top ) <EOL> try : <EOL> if len ( self . parts ) == <NUM_LIT:1> : <EOL> part = self . parts [ <NUM_LIT:0> ] <EOL> if isinstance ( part , Restriction ) : <EOL> if part . parts : <EOL> if isinstance ( part . parts [ <NUM_LIT:0> ] , Enumeration ) : <EOL> lista = [ p . value for p in part . parts ] <EOL> obj . value_type = { "<STR_LIT>" : part . base , <EOL> "<STR_LIT>" : lista } <EOL> elif isinstance ( part . parts [ <NUM_LIT:0> ] , MaxLength ) : <EOL> obj . value_type = { "<STR_LIT>" : part . base , <EOL> "<STR_LIT>" : part . parts [ <NUM_LIT:0> ] . value } <EOL> elif isinstance ( part . parts [ <NUM_LIT:0> ] , Length ) : <EOL> obj . value_type = { "<STR_LIT>" : part . base , <EOL> "<STR_LIT>" : part . parts [ <NUM_LIT:0> ] . value } <EOL> else : <EOL> obj . value_type = { "<STR_LIT>" : part . base } <EOL> elif isinstance ( part , List ) : <EOL> if part . itemType : <EOL> obj . value_type = { "<STR_LIT>" : "<STR_LIT:list>" , "<STR_LIT>" : part . itemType } <EOL> except ValueError : <EOL> pass <EOL> self . py_class = obj <EOL> return obj <EOL> class Sequence ( Complex ) : <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> argv_copy = sd_copy ( argv ) <EOL> for key , val in self . __dict__ . items ( ) : <EOL> if key not in [ '<STR_LIT>' ] and not key . startswith ( "<STR_LIT:_>" ) : <EOL> argv_copy [ key ] = val <EOL> if DEBUG : <EOL> print "<STR_LIT>" % argv <EOL> return Complex . collect ( self , top , sup , argv_copy , parent ) <EOL> class SimpleContent ( Complex ) : <EOL> pass <EOL> class ComplexContent ( Complex ) : <EOL> pass <EOL> class Key ( Complex ) : <EOL> pass <EOL> class Redefine ( Complex ) : <EOL> pass <EOL> class Extension ( Complex ) : <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> if self . _own or self . _inherited : <EOL> return self . _own , self . _inherited <EOL> if DEBUG : <EOL> print "<STR_LIT>" , self . __dict__ <EOL> try : <EOL> base = self . base <EOL> ( namespace , tag ) = _namespace_and_tag ( self , base , top ) <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> cti = get_type_def ( tag , top . parts ) <EOL> if not cti . py_class : <EOL> cti . repr ( top , sup ) <EOL> self . _inherited = cti . py_class . properties [ <NUM_LIT:0> ] [ : ] <EOL> self . _inherited . extend ( cti . py_class . properties [ <NUM_LIT:1> ] ) <EOL> elif self . xmlns_map [ namespace ] == XMLSCHEMA : <EOL> base = tag <EOL> else : <EOL> iattr = _import_attrs ( top . modul [ namespace ] , tag , top ) <EOL> self . _inherited = iattr <EOL> except ( AttributeError , ValueError ) : <EOL> base = None <EOL> self . _extend ( top , sup , argv , parent , base ) <EOL> return self . _own , self . _inherited <EOL> class Choice ( Complex ) : <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> argv_copy = sd_copy ( argv ) <EOL> for key , val in self . __dict__ . items ( ) : <EOL> if key not in [ '<STR_LIT>' ] and not key . startswith ( "<STR_LIT:_>" ) : <EOL> argv_copy [ key ] = val <EOL> argv_copy [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> if DEBUG : <EOL> print "<STR_LIT>" % argv <EOL> return Complex . collect ( self , top , sup , argv_copy , parent = parent ) <EOL> class Restriction ( Complex ) : <EOL> pass <EOL> class ComplexType ( Complex ) : <EOL> def repr ( self , top = None , sup = None , _argv = None , _child = True , parent = "<STR_LIT>" ) : <EOL> if self . py_class : <EOL> return self . py_class <EOL> significant_parts = self . significant_parts ( ) <EOL> value_type = "<STR_LIT>" <EOL> if len ( significant_parts ) == <NUM_LIT:1> : <EOL> if isinstance ( significant_parts [ <NUM_LIT:0> ] , ComplexContent ) or isinstance ( significant_parts [ <NUM_LIT:0> ] , SimpleContent ) : <EOL> cci = significant_parts [ <NUM_LIT:0> ] <EOL> if len ( cci . parts ) == <NUM_LIT:1> : <EOL> if isinstance ( cci . parts [ <NUM_LIT:0> ] , Extension ) : <EOL> ext = cci . parts [ <NUM_LIT:0> ] <EOL> ( namespace , name ) = _namespace_and_tag ( ext , ext . base , <EOL> top ) <EOL> if ext . xmlns_map [ namespace ] == top . target_namespace : <EOL> new_sup = name <EOL> cti = get_type_def ( new_sup , top . parts ) <EOL> if cti and not cti . py_class : <EOL> cti . repr ( top , sup ) <EOL> elif ext . xmlns_map [ namespace ] == XMLSCHEMA : <EOL> new_sup = None <EOL> value_type = name <EOL> else : <EOL> new_sup = "<STR_LIT>" % ( namespace , name ) <EOL> if new_sup : <EOL> sup = new_sup <EOL> else : <EOL> pass <EOL> try : <EOL> self . py_class = PyType ( self . name , superior = sup , <EOL> namespace = top . target_namespace , root = top ) <EOL> except AttributeError : <EOL> self . py_class = PyType ( "<STR_LIT>" , superior = sup , <EOL> namespace = top . target_namespace , root = top ) <EOL> try : <EOL> self . py_class . abstract = self . abstract <EOL> except AttributeError : <EOL> pass <EOL> if value_type : <EOL> self . py_class . value_type = { "<STR_LIT>" : value_type } <EOL> try : <EOL> if not parent : <EOL> try : <EOL> parent = self . name <EOL> except AttributeError : <EOL> parent = "<STR_LIT>" <EOL> self . py_class . properties = self . collect ( top , sup , parent = parent ) <EOL> except ValueError : <EOL> pass <EOL> return self . py_class <EOL> class Annotation ( Complex ) : <EOL> pass <EOL> class All ( Complex ) : <EOL> pass <EOL> class Group ( Complex ) : <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> ( namespace , tag ) = _namespace_and_tag ( self , self . ref , top ) <EOL> try : <EOL> if self . xmlns_map [ namespace ] == top . target_namespace : <EOL> cti = get_type_def ( tag , top . parts ) <EOL> try : <EOL> return cti . py_class . properties <EOL> except ValueError : <EOL> return cti . collect ( top , sup ) <EOL> else : <EOL> raise Exception ( <EOL> "<STR_LIT>" ) <EOL> except KeyError : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except AttributeError , exc : <EOL> print "<STR_LIT>" , exc <EOL> return [ ] , [ ] <EOL> def repr ( self , top = None , sup = None , argv = None , _child = True , parent = "<STR_LIT>" ) : <EOL> if self . py_class : <EOL> return self . py_class <EOL> self . py_class = objekt = PyGroup ( self . name , root = top ) <EOL> min_max ( self , objekt , argv ) <EOL> try : <EOL> self . _extend ( top , sup , argv ) <EOL> objekt . properties = ( self . _own , self . _inherited ) <EOL> except ValueError : <EOL> pass <EOL> return objekt <EOL> class Unique ( Complex ) : <EOL> pass <EOL> class Selector ( Complex ) : <EOL> pass <EOL> class Field ( Complex ) : <EOL> pass <EOL> class AttributeGroup ( Complex ) : <EOL> def collect ( self , top , sup , argv = None , parent = "<STR_LIT>" ) : <EOL> try : <EOL> ( _namespace , typ ) = _namespace_and_tag ( self , self . ref , top ) <EOL> cti = get_type_def ( typ , top . parts ) <EOL> return cti . collect ( top , sup ) <EOL> except AttributeError : <EOL> if self . _own or self . _inherited : <EOL> return self . _own , self . _inherited <EOL> argv_copy = sd_copy ( argv ) <EOL> for prop in self . parts : <EOL> if isinstance ( prop , Attribute ) : <EOL> self . _own . append ( prop . repr ( top , sup , argv_copy , parent ) ) <EOL> return self . _own , self . _inherited <EOL> def repr ( self , top = None , sup = None , _argv = None , _child = True , parent = "<STR_LIT>" ) : <EOL> if self . py_class : <EOL> return self . py_class <EOL> self . py_class = PyAttributeGroup ( self . name , root = top ) <EOL> try : <EOL> self . py_class . properties = self . collect ( top , sup ) <EOL> except ValueError : <EOL> pass <EOL> return self . py_class <EOL> def pyify_0 ( name ) : <EOL> res = "<STR_LIT>" <EOL> match = re . match ( <EOL> r"<STR_LIT>" , <EOL> name ) <EOL> res += match . group ( <NUM_LIT:1> ) . lower ( ) <EOL> for num in range ( <NUM_LIT:3> , len ( match . groups ( ) ) , <NUM_LIT:2> ) : <EOL> try : <EOL> res += "<STR_LIT:_>" + match . group ( num + <NUM_LIT:1> ) . lower ( ) + match . group ( num ) [ <NUM_LIT:1> : ] <EOL> except AttributeError : <EOL> break <EOL> res = res . replace ( "<STR_LIT:->" , "<STR_LIT:_>" ) <EOL> if res in [ "<STR_LIT:class>" ] : <EOL> res += "<STR_LIT:_>" <EOL> return res <EOL> def pyify ( name ) : <EOL> res = [ ] <EOL> upc = [ ] <EOL> pre = "<STR_LIT>" <EOL> for char in name : <EOL> if "<STR_LIT:A>" <= char <= "<STR_LIT>" : <EOL> upc . append ( char ) <EOL> elif char == "<STR_LIT:->" : <EOL> upc . append ( "<STR_LIT:_>" ) <EOL> else : <EOL> if upc : <EOL> if len ( upc ) == <NUM_LIT:1> : <EOL> res . append ( pre + upc [ <NUM_LIT:0> ] . lower ( ) ) <EOL> else : <EOL> if pre : <EOL> res . append ( pre ) <EOL> for uch in upc [ : - <NUM_LIT:1> ] : <EOL> res . append ( uch . lower ( ) ) <EOL> res . append ( "<STR_LIT:_>" + upc [ - <NUM_LIT:1> ] . lower ( ) ) <EOL> upc = [ ] <EOL> res . append ( char ) <EOL> pre = "<STR_LIT:_>" <EOL> if upc : <EOL> if len ( upc ) == len ( name ) : <EOL> return name . lower ( ) <EOL> else : <EOL> res . append ( "<STR_LIT:_>" + ( "<STR_LIT>" . join ( upc ) . lower ( ) ) ) <EOL> return "<STR_LIT>" . join ( res ) <EOL> def get_type_def ( typ , defs ) : <EOL> for cdef in defs : <EOL> try : <EOL> if cdef . name == typ : <EOL> return cdef <EOL> except AttributeError : <EOL> pass <EOL> return None <EOL> def sort_elements ( els ) : <EOL> res = [ ] <EOL> diff = False <EOL> for key , val in els . items ( ) : <EOL> if not val : <EOL> res . append ( key ) <EOL> del els [ key ] <EOL> diff = True <EOL> res . sort ( ) <EOL> while diff : <EOL> diff = False <EOL> for key , val in els . items ( ) : <EOL> pres = [ v for v in val if v not in res and '<STR_LIT::>' not in v ] <EOL> els [ key ] = pres <EOL> if pres != val : <EOL> diff = True <EOL> partres = [ ] <EOL> for key , val in els . items ( ) : <EOL> if not val : <EOL> partres . append ( key ) <EOL> del els [ key ] <EOL> diff = True <EOL> partres . sort ( ) <EOL> res . extend ( partres ) <EOL> return res , els <EOL> def output ( elem , target_namespace , eldict , ignore = None ) : <EOL> done = <NUM_LIT:0> <EOL> if ignore is None : <EOL> ignore = [ ] <EOL> try : <EOL> ( preps , text ) = elem . text ( target_namespace , eldict , False , ignore ) <EOL> except TypeError : <EOL> return done <EOL> except MissingPrerequisite : <EOL> return done <EOL> for prep in preps : <EOL> if prep : <EOL> done = <NUM_LIT:1> <EOL> if isinstance ( prep , basestring ) : <EOL> print prep <EOL> else : <EOL> for item in prep : <EOL> print item <EOL> print <EOL> print <EOL> if text : <EOL> done = <NUM_LIT:1> <EOL> elem . done = True <EOL> print text <EOL> print <EOL> return done <EOL> def intro ( ) : <EOL> print """<STR_LIT>""" % ( time . ctime ( ) , __version__ ) <EOL> def block_items ( objekt , block , eldict ) : <EOL> if objekt not in block : <EOL> if isinstance ( objekt . type , PyType ) : <EOL> if objekt . type not in block : <EOL> block . append ( objekt . type ) <EOL> block . append ( objekt ) <EOL> if isinstance ( objekt , PyType ) : <EOL> others = [ p for p in eldict . values ( ) if isinstance ( p , <EOL> PyElement ) and p . type [ <NUM_LIT:1> ] == objekt . name ] <EOL> for item in others : <EOL> if item not in block : <EOL> block . append ( item ) <EOL> return block <EOL> def find_parent ( elm , eldict ) : <EOL> if isinstance ( elm , PyElement ) : <EOL> if elm . type : <EOL> sup = eldict [ elm . type [ <NUM_LIT:1> ] ] <EOL> return find_parent ( sup , eldict ) <EOL> elif elm . ref : <EOL> sup = eldict [ elm . ref ] <EOL> if sup . name == elm . name : <EOL> return elm <EOL> return find_parent ( sup , eldict ) <EOL> else : <EOL> if elm . superior : <EOL> sup = eldict [ elm . superior [ <NUM_LIT:0> ] ] <EOL> if sup . done : <EOL> return elm <EOL> return find_parent ( sup , eldict ) <EOL> return elm <EOL> class Schema ( Complex ) : <EOL> def __init__ ( self , elem , impo , add , modul , defs ) : <EOL> Complex . __init__ ( self , elem ) <EOL> self . impo = impo <EOL> self . add = add <EOL> self . modul = modul <EOL> self . py_elements = { } <EOL> self . py_attributes = { } <EOL> self . elems = [ ] <EOL> self . attrgrp = [ ] <EOL> self . defs = [ ] <EOL> try : <EOL> self . target_namespace = self . targetNamespace <EOL> except AttributeError : <EOL> self . target_namespace = "<STR_LIT>" <EOL> for def_file in defs : <EOL> self . defs . append ( open ( def_file ) . read ( ) ) <EOL> def _mk_list ( self , objekt , alla , eldict ) : <EOL> tup = [ ] <EOL> for prop in alla : <EOL> ( mod , cname ) = _mod_cname ( prop , eldict ) <EOL> if prop . max == "<STR_LIT>" : <EOL> lista = True <EOL> else : <EOL> lista = False <EOL> spec = objekt . child_spec ( self . target_namespace , <EOL> prop , mod , cname , <EOL> lista ) <EOL> lines = [ "<STR_LIT>" % ( objekt . class_name , spec ) ] <EOL> tup . append ( ( prop , lines , spec ) ) <EOL> return tup <EOL> def adjust ( self , eldict , block ) : <EOL> udict = { } <EOL> for elem in self . elems : <EOL> if isinstance ( elem , PyAttribute ) or isinstance ( elem , PyGroup ) : <EOL> elem . done = True <EOL> continue <EOL> if elem in block : <EOL> continue <EOL> if not elem . done : <EOL> udict [ elem ] = elem . undefined ( eldict ) <EOL> keys = [ k . name for k in udict . keys ( ) ] <EOL> print "<STR_LIT:#>" , keys <EOL> res = ( None , [ ] ) <EOL> if not udict : <EOL> return res <EOL> level = <NUM_LIT:1> <EOL> rblocked = [ p . name for p in block ] <EOL> while True : <EOL> non_child = <NUM_LIT:0> <EOL> for objekt , ( sup , elems ) in udict . items ( ) : <EOL> if sup : <EOL> continue <EOL> else : <EOL> non_child += <NUM_LIT:1> <EOL> signif = [ ] <EOL> other = [ ] <EOL> for elem in elems : <EOL> if elem . name in keys : <EOL> signif . append ( elem ) <EOL> elif elem . ref in rblocked : <EOL> other . append ( elem ) <EOL> if len ( signif ) <= level : <EOL> alla = signif <EOL> alla . extend ( other ) <EOL> tup = self . _mk_list ( objekt , alla , eldict ) <EOL> res = ( objekt , tup ) <EOL> break <EOL> if res [ <NUM_LIT:0> ] : <EOL> ref = res [ <NUM_LIT:0> ] . name <EOL> tups = res [ <NUM_LIT:1> ] <EOL> for objekt , ( sups , elems ) in udict . items ( ) : <EOL> if sups : <EOL> for sup in sups : <EOL> if sup . name == ref : <EOL> for tup in tups : <EOL> tup [ <NUM_LIT:1> ] . append ( "<STR_LIT>" % ( objekt . class_name , <EOL> tup [ <NUM_LIT:2> ] ) ) <EOL> break <EOL> else : <EOL> pass <EOL> elif not non_child or level > <NUM_LIT:10> : <EOL> elm = udict . keys ( ) [ <NUM_LIT:0> ] <EOL> parent = find_parent ( elm , eldict ) <EOL> signif = [ ] <EOL> other = [ ] <EOL> tot = parent . properties [ <NUM_LIT:0> ] <EOL> tot . extend ( parent . properties [ <NUM_LIT:1> ] ) <EOL> alla = [ ] <EOL> for elem in tot : <EOL> if isinstance ( elem , PyAttribute ) : <EOL> continue <EOL> else : <EOL> alla . append ( elem ) <EOL> tup = self . _mk_list ( parent , alla , eldict ) <EOL> res = ( parent , tup ) <EOL> if res [ <NUM_LIT:0> ] : <EOL> break <EOL> else : <EOL> level += <NUM_LIT:1> <EOL> return res <EOL> def _do ( self , eldict ) : <EOL> not_done = <NUM_LIT:1> <EOL> undone = <NUM_LIT:0> <EOL> while not_done : <EOL> not_done = <NUM_LIT:0> <EOL> undone = <NUM_LIT:0> <EOL> for elem in self . elems : <EOL> if isinstance ( elem , PyGroup ) or elem . done : <EOL> continue <EOL> undone += <NUM_LIT:1> <EOL> not_done += output ( elem , self . target_namespace , eldict ) <EOL> return undone <EOL> def _element_from_string ( self ) : <EOL> print "<STR_LIT>" <EOL> for elem in self . elems : <EOL> if isinstance ( elem , PyAttribute ) or isinstance ( elem , PyGroup ) : <EOL> continue <EOL> if elem . abstract : <EOL> continue <EOL> print "<STR_LIT>" % ( INDENT , elem . class_name , <EOL> pyify ( elem . class_name ) ) <EOL> print "<STR_LIT:}>" <EOL> print <EOL> def _element_by_tag ( self ) : <EOL> print "<STR_LIT>" <EOL> listed = [ ] <EOL> for elem in self . elems : <EOL> if isinstance ( elem , PyAttribute ) or isinstance ( elem , PyGroup ) : <EOL> continue <EOL> if elem . abstract : <EOL> continue <EOL> lcen = elem . name <EOL> print "<STR_LIT>" % ( INDENT , lcen , elem . class_name ) <EOL> listed . append ( lcen ) <EOL> for elem in self . elems : <EOL> if isinstance ( elem , PyAttribute ) or isinstance ( elem , PyGroup ) : <EOL> continue <EOL> lcen = elem . name <EOL> if elem . abstract and lcen not in listed : <EOL> print "<STR_LIT>" % ( INDENT , lcen , elem . class_name ) <EOL> listed . append ( lcen ) <EOL> print "<STR_LIT:}>" <EOL> print <EOL> def out ( self ) : <EOL> for part in self . parts : <EOL> if isinstance ( part , Import ) : <EOL> continue <EOL> if part is None : <EOL> continue <EOL> elem = part . repr ( self , "<STR_LIT>" , { } , False ) <EOL> if elem : <EOL> if isinstance ( elem , PyAttributeGroup ) : <EOL> self . attrgrp . append ( elem ) <EOL> else : <EOL> self . elems . append ( elem ) <EOL> eldict = { } <EOL> for elem in self . elems : <EOL> eldict [ elem . name ] = elem <EOL> intro ( ) <EOL> for modul in self . add : <EOL> print "<STR_LIT>" % modul <EOL> for _namespace , ( mod , namn ) in self . impo . items ( ) : <EOL> if namn : <EOL> print "<STR_LIT>" % ( mod , namn ) <EOL> print <EOL> print "<STR_LIT>" % self . target_namespace <EOL> print <EOL> for defs in self . defs : <EOL> print defs <EOL> print <EOL> exceptions = [ ] <EOL> block = [ ] <EOL> while self . _do ( eldict ) : <EOL> print "<STR_LIT>" <EOL> ( objekt , tups ) = self . adjust ( eldict , block ) <EOL> if not objekt : <EOL> break <EOL> ignore = [ p . name for ( p , _l , _s ) in tups ] <EOL> done = output ( objekt , self . target_namespace , eldict , ignore ) <EOL> if done : <EOL> for ( prop , lines , _ ) in tups : <EOL> exceptions . extend ( lines ) <EOL> block = [ ] <EOL> else : <EOL> block = block_items ( objekt , block , eldict ) <EOL> if exceptions : <EOL> print "<STR_LIT:#>" , <NUM_LIT> * '<STR_LIT:+>' <EOL> for line in exceptions : <EOL> print line <EOL> print "<STR_LIT:#>" , <NUM_LIT> * '<STR_LIT:+>' <EOL> print <EOL> for attrgrp in self . attrgrp : <EOL> print "<STR_LIT>" % attrgrp . name <EOL> for prop in attrgrp . properties [ <NUM_LIT:0> ] : <EOL> if isinstance ( prop . type , PyObj ) : <EOL> print "<STR_LIT>" % ( INDENT , prop . name , <EOL> prop . type . name , prop . required ) <EOL> else : <EOL> print "<STR_LIT>" % ( INDENT , prop . name , <EOL> prop . type , prop . required ) <EOL> print "<STR_LIT:]>" <EOL> print <EOL> self . _element_from_string ( ) <EOL> self . _element_by_tag ( ) <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print <EOL> NAMESPACE_BASE = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> _MAP = { <EOL> "<STR_LIT>" : Element , <EOL> "<STR_LIT>" : ComplexType , <EOL> "<STR_LIT>" : Sequence , <EOL> "<STR_LIT>" : Any , <EOL> "<STR_LIT:all>" : All , <EOL> "<STR_LIT>" : AnyAttribute , <EOL> "<STR_LIT>" : SimpleContent , <EOL> "<STR_LIT>" : Extension , <EOL> "<STR_LIT>" : Union , <EOL> "<STR_LIT>" : Restriction , <EOL> "<STR_LIT>" : Enumeration , <EOL> "<STR_LIT>" : Import , <EOL> "<STR_LIT>" : Annotation , <EOL> "<STR_LIT>" : AttributeGroup , <EOL> "<STR_LIT>" : Attribute , <EOL> "<STR_LIT>" : Choice , <EOL> "<STR_LIT>" : ComplexContent , <EOL> "<STR_LIT>" : Documentation , <EOL> "<STR_LIT>" : SimpleType , <EOL> "<STR_LIT>" : MaxLength , <EOL> "<STR_LIT:list>" : List , <EOL> "<STR_LIT>" : Unique , <EOL> "<STR_LIT>" : Group , <EOL> "<STR_LIT>" : Selector , <EOL> "<STR_LIT>" : Field , <EOL> "<STR_LIT:key>" : Key , <EOL> "<STR_LIT>" : Include , <EOL> "<STR_LIT>" : Redefine <EOL> } <EOL> ELEMENTFUNCTION = { } <EOL> for nsp in NAMESPACE_BASE : <EOL> for nskey , func in _MAP . items ( ) : <EOL> ELEMENTFUNCTION [ "<STR_LIT>" % ( nsp , nskey ) ] = func <EOL> def evaluate ( typ , elem ) : <EOL> try : <EOL> return ELEMENTFUNCTION [ typ ] ( elem ) <EOL> except KeyError : <EOL> print "<STR_LIT>" , typ <EOL> NS_MAP = "<STR_LIT>" <EOL> def parse_nsmap ( fil ) : <EOL> events = "<STR_LIT:start>" , "<STR_LIT>" , "<STR_LIT>" <EOL> root = None <EOL> ns_map = [ ] <EOL> for event , elem in ElementTree . iterparse ( fil , events ) : <EOL> if event == "<STR_LIT>" : <EOL> ns_map . append ( elem ) <EOL> elif event == "<STR_LIT>" : <EOL> ns_map . pop ( ) <EOL> elif event == "<STR_LIT:start>" : <EOL> if root is None : <EOL> root = elem <EOL> elem . set ( NS_MAP , dict ( ns_map ) ) <EOL> return ElementTree . ElementTree ( root ) <EOL> def usage ( ) : <EOL> print "<STR_LIT>" <EOL> def recursive_find_module ( name , path = None ) : <EOL> parts = name . split ( "<STR_LIT:.>" ) <EOL> mod_a = None <EOL> for part in parts : <EOL> try : <EOL> ( fil , pathname , desc ) = imp . find_module ( part , path ) <EOL> except ImportError : <EOL> raise <EOL> mod_a = imp . load_module ( name , fil , pathname , desc ) <EOL> sys . modules [ name ] = mod_a <EOL> path = mod_a . __path__ <EOL> return mod_a <EOL> def get_mod ( name , path = None ) : <EOL> try : <EOL> mod_a = sys . modules [ name ] <EOL> if not isinstance ( mod_a , types . ModuleType ) : <EOL> raise KeyError <EOL> except KeyError : <EOL> try : <EOL> ( fil , pathname , desc ) = imp . find_module ( name , path ) <EOL> mod_a = imp . load_module ( name , fil , pathname , desc ) <EOL> except ImportError : <EOL> if "<STR_LIT:.>" in name : <EOL> mod_a = recursive_find_module ( name , path ) <EOL> else : <EOL> raise <EOL> sys . modules [ name ] = mod_a <EOL> return mod_a <EOL> def recursive_add_xmlns_map ( _sch , base ) : <EOL> for _part in _sch . parts : <EOL> _part . xmlns_map . update ( base . xmlns_map ) <EOL> if isinstance ( _part , Complex ) : <EOL> recursive_add_xmlns_map ( _part , base ) <EOL> def find_and_replace ( base , mods ) : <EOL> base . xmlns_map = mods . xmlns_map <EOL> recursive_add_xmlns_map ( base , mods ) <EOL> rm = [ ] <EOL> for part in mods . parts : <EOL> try : <EOL> _name = part . name <EOL> except AttributeError : <EOL> continue <EOL> for _part in base . parts : <EOL> try : <EOL> if _name == _part . name : <EOL> rm . append ( _part ) <EOL> except AttributeError : <EOL> continue <EOL> for part in rm : <EOL> base . parts . remove ( part ) <EOL> base . parts . extend ( mods . parts ) <EOL> return base <EOL> def read_schema ( doc , add , defs , impo , modul , ignore , sdir ) : <EOL> for path in sdir : <EOL> fil = "<STR_LIT>" % ( path , doc ) <EOL> try : <EOL> fp = open ( fil ) <EOL> fp . close ( ) <EOL> break <EOL> except IOError as e : <EOL> if e . errno == errno . EACCES : <EOL> continue <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> tree = parse_nsmap ( fil ) <EOL> known = NAMESPACE_BASE [ : ] <EOL> known . append ( XML_NAMESPACE ) <EOL> for key , namespace in tree . _root . attrib [ "<STR_LIT>" ] . items ( ) : <EOL> if namespace in known : <EOL> continue <EOL> else : <EOL> try : <EOL> modul [ key ] = modul [ namespace ] <EOL> impo [ namespace ] [ <NUM_LIT:1> ] = key <EOL> except KeyError : <EOL> if namespace == tree . _root . attrib [ "<STR_LIT>" ] : <EOL> continue <EOL> elif namespace in ignore : <EOL> continue <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % namespace ) <EOL> _schema = Schema ( tree . _root , impo , add , modul , defs ) <EOL> _included_parts = [ ] <EOL> _remove_parts = [ ] <EOL> _replace = [ ] <EOL> for part in _schema . parts : <EOL> if isinstance ( part , Include ) : <EOL> _sch = read_schema ( part . schemaLocation , add , defs , impo , modul , <EOL> ignore , sdir ) <EOL> recursive_add_xmlns_map ( _sch , _schema ) <EOL> _included_parts . extend ( _sch . parts ) <EOL> _remove_parts . append ( part ) <EOL> elif isinstance ( part , Redefine ) : <EOL> _redef = read_schema ( part . schemaLocation , add , defs , impo , modul , <EOL> ignore , sdir ) <EOL> _replacement = find_and_replace ( _redef , part ) <EOL> _replace . append ( ( part , _replacement . parts ) ) <EOL> for part in _remove_parts : <EOL> _schema . parts . remove ( part ) <EOL> _schema . parts . extend ( _included_parts ) <EOL> if _replace : <EOL> for vad , med in _replace : <EOL> _schema . parts . remove ( vad ) <EOL> _schema . parts . extend ( med ) <EOL> return _schema <EOL> def main ( argv ) : <EOL> try : <EOL> opts , args = getopt . getopt ( argv , "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> except getopt . GetoptError , err : <EOL> print str ( err ) <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> add = [ ] <EOL> defs = [ ] <EOL> impo = { } <EOL> modul = { } <EOL> ignore = [ ] <EOL> sdir = [ "<STR_LIT>" ] <EOL> for opt , arg in opts : <EOL> if opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> add . append ( arg ) <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> defs . append ( arg ) <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> usage ( ) <EOL> sys . exit ( ) <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> sdir . append ( arg ) <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> mod = get_mod ( arg , [ '<STR_LIT:.>' ] ) <EOL> modul [ mod . NAMESPACE ] = mod <EOL> impo [ mod . NAMESPACE ] = [ arg , None ] <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> ignore . append ( arg ) <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> if not args : <EOL> print "<STR_LIT>" <EOL> usage ( ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> schema = read_schema ( args [ <NUM_LIT:0> ] , add , defs , impo , modul , ignore , sdir ) <EOL> schema . out ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( sys . argv [ <NUM_LIT:1> : ] ) </s>
