<s> from lxml import etree <EOL> class Base ( object ) : <EOL> @ property <EOL> def is_optional ( self ) : <EOL> return self . min_occurs == <NUM_LIT:0> <EOL> class Any ( Base ) : <EOL> def __init__ ( self , max_occurs = <NUM_LIT:1> , min_occurs = <NUM_LIT:1> ) : <EOL> self . name = '<STR_LIT>' <EOL> self . max_occurs = max_occurs <EOL> self . min_occurs = min_occurs <EOL> from zeep . xsd . builtins import AnyType <EOL> self . type = AnyType ( ) <EOL> def render ( self , parent , value ) : <EOL> assert parent is not None <EOL> if value is None : <EOL> return <EOL> if isinstance ( value . value , list ) : <EOL> for val in value . value : <EOL> value . xsd_type . render ( parent , val ) <EOL> else : <EOL> value . xsd_type . render ( parent , value . value ) <EOL> def __call__ ( self , any_object ) : <EOL> return any_object <EOL> class Element ( Base ) : <EOL> def __init__ ( self , name , type_ = None , min_occurs = <NUM_LIT:1> , max_occurs = <NUM_LIT:1> ) : <EOL> self . name = name . localname if name else None <EOL> self . qname = name <EOL> self . type = type_ <EOL> self . min_occurs = min_occurs <EOL> self . max_occurs = max_occurs <EOL> self . nillable = False <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , self . name , self . type ) <EOL> def serialize ( self , value ) : <EOL> return self . type . serialize ( value ) <EOL> def resolve_type ( self , schema ) : <EOL> self . type = self . type . resolve ( schema ) <EOL> def render ( self , parent , value ) : <EOL> assert parent is not None <EOL> if value is None : <EOL> if not self . is_optional : <EOL> node = etree . SubElement ( parent , self . qname ) <EOL> return <EOL> if self . name is None : <EOL> return self . type . render ( parent , value ) <EOL> node = etree . SubElement ( parent , self . qname ) <EOL> return self . type . render ( node , value ) <EOL> def parse ( self , value ) : <EOL> return self . type . parse_xmlelement ( value ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . type ( * args , ** kwargs ) <EOL> def _signature ( self , name ) : <EOL> return '<STR_LIT>' % ( <EOL> name , '<STR_LIT>' if self . is_optional else '<STR_LIT>' , <EOL> self . type . name , '<STR_LIT>' if self . max_occurs != <NUM_LIT:1> else '<STR_LIT>' <EOL> ) <EOL> class Attribute ( Element ) : <EOL> def render ( self , parent , value ) : <EOL> value = self . type . xmlvalue ( value ) <EOL> parent . set ( self . qname , value ) <EOL> class ListElement ( Element ) : <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return [ self . type ( * args , ** kwargs ) ] <EOL> def serialize ( self , value ) : <EOL> if value : <EOL> return [ self . type . serialize ( val ) for val in value ] <EOL> return [ ] <EOL> def render ( self , parent , value ) : <EOL> for val in value : <EOL> node = etree . SubElement ( parent , self . qname ) <EOL> self . type . render ( node , val ) <EOL> class GroupElement ( Element ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . children = kwargs . pop ( '<STR_LIT>' , [ ] ) <EOL> assert self . children <EOL> super ( GroupElement , self ) . __init__ ( * args , ** kwargs ) <EOL> def __iter__ ( self , * args , ** kwargs ) : <EOL> for item in self . properties ( ) : <EOL> yield item <EOL> def properties ( self ) : <EOL> return self . children <EOL> class Choice ( object ) : <EOL> def __init__ ( self , elements , max_occurs = <NUM_LIT:1> , min_occurs = <NUM_LIT:1> ) : <EOL> self . name = '<STR_LIT>' <EOL> self . type = None <EOL> self . elements = elements <EOL> self . max_occurs = max_occurs <EOL> self . min_occurs = min_occurs <EOL> @ property <EOL> def is_optional ( self ) : <EOL> return True <EOL> def key ( self ) : <EOL> return '<STR_LIT::>' . join ( elm . name for elm in self . elements ) <EOL> def _signature ( self ) : <EOL> part = '<STR_LIT:U+002CU+0020>' . join ( [ <EOL> element . _signature ( element . name ) <EOL> for element in self . elements <EOL> ] ) <EOL> return '<STR_LIT>' % part <EOL> class RefElement ( object ) : <EOL> def __init__ ( self , tag , ref , schema ) : <EOL> self . _ref = ref <EOL> self . _schema = schema <EOL> @ property <EOL> def _elm ( self ) : <EOL> return self . _schema . get_element ( self . _ref ) <EOL> def __iter__ ( self , * args , ** kwargs ) : <EOL> elm = self . _elm <EOL> for item in elm . properties ( ) : <EOL> yield item <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . _elm ( * args , ** kwargs ) <EOL> def __getattr__ ( self , name ) : <EOL> if not name . startswith ( '<STR_LIT:_>' ) : <EOL> return getattr ( self . _elm , name ) <EOL> return getattr ( self , name ) </s>
