<s> """<STR_LIT>""" <EOL> from logging import getLogger <EOL> from suds import * <EOL> from suds . bindings . binding import Binding <EOL> from suds . sax . element import Element <EOL> log = getLogger ( __name__ ) <EOL> class Document ( Binding ) : <EOL> """<STR_LIT>""" <EOL> def bodycontent ( self , method , args , kwargs ) : <EOL> if not len ( method . soap . input . body . parts ) : <EOL> return ( ) <EOL> wrapped = method . soap . input . body . wrapped <EOL> if wrapped : <EOL> pts = self . bodypart_types ( method ) <EOL> root = self . document ( pts [ <NUM_LIT:0> ] ) <EOL> else : <EOL> root = [ ] <EOL> n = <NUM_LIT:0> <EOL> for pd in self . param_defs ( method ) : <EOL> if n < len ( args ) : <EOL> value = args [ n ] <EOL> else : <EOL> value = kwargs . get ( pd [ <NUM_LIT:0> ] ) <EOL> n += <NUM_LIT:1> <EOL> p = self . mkparam ( method , pd , value ) <EOL> if p is None : <EOL> continue <EOL> if not wrapped : <EOL> ns = pd [ <NUM_LIT:1> ] . namespace ( '<STR_LIT>' ) <EOL> p . setPrefix ( ns [ <NUM_LIT:0> ] , ns [ <NUM_LIT:1> ] ) <EOL> root . append ( p ) <EOL> return root <EOL> def replycontent ( self , method , body ) : <EOL> wrapped = method . soap . output . body . wrapped <EOL> if wrapped : <EOL> return body [ <NUM_LIT:0> ] . children <EOL> else : <EOL> return body . children <EOL> def document ( self , wrapper ) : <EOL> """<STR_LIT>""" <EOL> tag = wrapper [ <NUM_LIT:1> ] . name <EOL> ns = wrapper [ <NUM_LIT:1> ] . namespace ( '<STR_LIT>' ) <EOL> d = Element ( tag , ns = ns ) <EOL> return d <EOL> def mkparam ( self , method , pdef , object ) : <EOL> if isinstance ( object , ( list , tuple ) ) : <EOL> tags = [ ] <EOL> for item in object : <EOL> tags . append ( self . mkparam ( method , pdef , item ) ) <EOL> return tags <EOL> else : <EOL> return Binding . mkparam ( self , method , pdef , object ) <EOL> def param_defs ( self , method ) : <EOL> pts = self . bodypart_types ( method ) <EOL> wrapped = method . soap . input . body . wrapped <EOL> if not wrapped : <EOL> return pts <EOL> result = [ ] <EOL> for p in pts : <EOL> resolved = p [ <NUM_LIT:1> ] . resolve ( ) <EOL> for child , ancestry in resolved : <EOL> if child . isattr ( ) : <EOL> continue <EOL> if self . bychoice ( ancestry ) : <EOL> continue <EOL> result . append ( ( child . name , child ) ) <EOL> return result <EOL> def returned_types ( self , method ) : <EOL> result = [ ] <EOL> wrapped = method . soap . output . body . wrapped <EOL> rts = self . bodypart_types ( method , input = False ) <EOL> if wrapped : <EOL> for pt in rts : <EOL> resolved = pt . resolve ( nobuiltin = True ) <EOL> for child , ancestry in resolved : <EOL> result . append ( child ) <EOL> break <EOL> else : <EOL> result += rts <EOL> return result <EOL> def bychoice ( self , ancestry ) : <EOL> """<STR_LIT>""" <EOL> for x in ancestry : <EOL> if x . choice ( ) : <EOL> return True <EOL> return False </s>
