<s> "<STR_LIT>" <EOL> __author__ = "<STR_LIT>" <EOL> __copyright__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" <EOL> TIMEOUT = <NUM_LIT> <EOL> import cPickle as pickle <EOL> import hashlib <EOL> import logging <EOL> import os <EOL> import tempfile <EOL> import urllib2 <EOL> from urlparse import urlsplit <EOL> from simplexml import SimpleXMLElement , TYPE_MAP , REVERSE_TYPE_MAP , OrderedDict <EOL> from transport import get_http_wrapper , set_http_wrapper , get_Http <EOL> log = logging . getLogger ( __name__ ) <EOL> logging . basicConfig ( format = '<STR_LIT>' , level = logging . WARNING ) <EOL> class SoapFault ( RuntimeError ) : <EOL> def __init__ ( self , faultcode , faultstring ) : <EOL> self . faultcode = faultcode <EOL> self . faultstring = faultstring <EOL> RuntimeError . __init__ ( self , faultcode , faultstring ) <EOL> def __str__ ( self ) : <EOL> return self . __unicode__ ( ) . encode ( "<STR_LIT:ascii>" , "<STR_LIT:ignore>" ) <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT>' % ( self . faultcode , self . faultstring ) <EOL> def __repr__ ( self ) : <EOL> return u"<STR_LIT>" % ( repr ( self . faultcode ) , <EOL> repr ( self . faultstring ) ) <EOL> soap_namespaces = dict ( <EOL> soap11 = "<STR_LIT>" , <EOL> soap = "<STR_LIT>" , <EOL> soapenv = "<STR_LIT>" , <EOL> soap12 = "<STR_LIT>" , <EOL> ) <EOL> _USE_GLOBAL_DEFAULT = object ( ) <EOL> class SoapClient ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , location = None , action = None , namespace = None , <EOL> cert = None , trace = False , exceptions = True , proxy = None , ns = False , <EOL> soap_ns = None , wsdl = None , cache = False , cacert = None , <EOL> sessions = False , soap_server = None , timeout = _USE_GLOBAL_DEFAULT , <EOL> http_headers = { } <EOL> ) : <EOL> """<STR_LIT>""" <EOL> self . certssl = cert <EOL> self . keyssl = None <EOL> self . location = location <EOL> self . action = action <EOL> self . namespace = namespace <EOL> self . trace = trace <EOL> self . exceptions = exceptions <EOL> self . xml_request = self . xml_response = '<STR_LIT>' <EOL> self . http_headers = http_headers <EOL> if not soap_ns and not ns : <EOL> self . __soap_ns = '<STR_LIT>' <EOL> elif not soap_ns and ns : <EOL> self . __soap_ns = '<STR_LIT>' <EOL> else : <EOL> self . __soap_ns = soap_ns <EOL> self . __soap_server = soap_server <EOL> self . __headers = { } <EOL> self . __call_headers = None <EOL> if cacert and cacert . startswith ( "<STR_LIT>" ) : <EOL> fd , filename = tempfile . mkstemp ( ) <EOL> f = os . fdopen ( fd , '<STR_LIT>' , - <NUM_LIT:1> ) <EOL> if self . trace : log . info ( u"<STR_LIT>" % filename ) <EOL> f . write ( cacert ) <EOL> cacert = filename <EOL> f . close ( ) <EOL> self . cacert = cacert <EOL> if timeout is _USE_GLOBAL_DEFAULT : <EOL> timeout = TIMEOUT <EOL> else : <EOL> timeout = timeout <EOL> Http = get_Http ( ) <EOL> self . http = Http ( timeout = timeout , cacert = cacert , proxy = proxy , sessions = sessions ) <EOL> self . __ns = ns <EOL> if not ns : <EOL> self . __xml = """<STR_LIT>""" <EOL> else : <EOL> self . __xml = """<STR_LIT>""" <EOL> self . services = wsdl and self . wsdl_parse ( wsdl , debug = trace , cache = cache ) <EOL> self . service_port = None <EOL> def __getattr__ ( self , attr ) : <EOL> "<STR_LIT>" <EOL> if not self . services : <EOL> return lambda self = self , * args , ** kwargs : self . call ( attr , * args , ** kwargs ) <EOL> else : <EOL> return lambda * args , ** kwargs : self . wsdl_call ( attr , * args , ** kwargs ) <EOL> def call ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> xml = self . __xml % dict ( method = method , namespace = self . namespace , ns = self . __ns , <EOL> soap_ns = self . __soap_ns , soap_uri = soap_namespaces [ self . __soap_ns ] ) <EOL> request = SimpleXMLElement ( xml , namespace = self . __ns and self . namespace , prefix = self . __ns ) <EOL> try : <EOL> request_headers = kwargs . pop ( '<STR_LIT>' ) <EOL> except KeyError : <EOL> request_headers = None <EOL> if kwargs : <EOL> parameters = kwargs . items ( ) <EOL> else : <EOL> parameters = args <EOL> if parameters and isinstance ( parameters [ <NUM_LIT:0> ] , SimpleXMLElement ) : <EOL> if parameters [ <NUM_LIT:0> ] . children ( ) is not None : <EOL> for param in parameters [ <NUM_LIT:0> ] . children ( ) : <EOL> getattr ( request , method ) . import_node ( param ) <EOL> elif parameters : <EOL> for k , v in parameters : <EOL> getattr ( request , method ) . marshall ( k , v ) <EOL> elif not self . __soap_server in ( '<STR_LIT>' , ) or self . __soap_server in ( '<STR_LIT>' , ) : <EOL> delattr ( request ( "<STR_LIT>" , ns = soap_namespaces . values ( ) , ) , method ) <EOL> if self . __headers and not self . services : <EOL> self . __call_headers = dict ( [ ( k , v ) for k , v in self . __headers . items ( ) <EOL> if not k . startswith ( "<STR_LIT>" ) ] ) <EOL> if '<STR_LIT>' in self . __headers : <EOL> header = request ( '<STR_LIT>' , ns = soap_namespaces . values ( ) , ) <EOL> k = '<STR_LIT>' <EOL> v = self . __headers [ k ] <EOL> header . marshall ( k , v , ns = False , add_children_ns = False ) <EOL> header ( k ) [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if self . __call_headers : <EOL> header = request ( '<STR_LIT>' , ns = soap_namespaces . values ( ) , ) <EOL> for k , v in self . __call_headers . items ( ) : <EOL> header . marshall ( k , v , ns = self . __ns , add_children_ns = False ) <EOL> if request_headers : <EOL> header = request ( '<STR_LIT>' , ns = soap_namespaces . values ( ) , ) <EOL> for subheader in request_headers . children ( ) : <EOL> header . import_node ( subheader ) <EOL> self . xml_request = request . as_xml ( ) <EOL> self . xml_response = self . send ( method , self . xml_request ) <EOL> response = SimpleXMLElement ( self . xml_response , namespace = self . namespace ) <EOL> if self . exceptions and response ( "<STR_LIT>" , ns = soap_namespaces . values ( ) , error = False ) : <EOL> raise SoapFault ( unicode ( response . faultcode ) , unicode ( response . faultstring ) ) <EOL> return response <EOL> def send ( self , method , xml ) : <EOL> "<STR_LIT>" <EOL> if self . location == '<STR_LIT:test>' : return <EOL> location = self . location <EOL> if self . services : <EOL> soap_action = self . action <EOL> else : <EOL> soap_action = self . action + method <EOL> headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( len ( xml ) ) , <EOL> "<STR_LIT>" : "<STR_LIT>" % ( soap_action ) <EOL> } <EOL> headers . update ( self . http_headers ) <EOL> log . info ( "<STR_LIT>" % location ) <EOL> log . info ( "<STR_LIT>" % headers ) <EOL> if self . trace : <EOL> print "<STR_LIT:->" * <NUM_LIT> <EOL> print "<STR_LIT>" % location <EOL> print '<STR_LIT:\n>' . join ( [ "<STR_LIT>" % ( k , v ) for k , v in headers . items ( ) ] ) <EOL> print u"<STR_LIT>" % xml . decode ( "<STR_LIT:utf8>" , "<STR_LIT:ignore>" ) <EOL> response , content = self . http . request ( <EOL> location , "<STR_LIT:POST>" , body = xml , headers = headers ) <EOL> self . response = response <EOL> self . content = content <EOL> if self . trace : <EOL> print <EOL> print '<STR_LIT:\n>' . join ( [ "<STR_LIT>" % ( k , v ) for k , v in response . items ( ) ] ) <EOL> print content <EOL> print "<STR_LIT:=>" * <NUM_LIT> <EOL> return content <EOL> def get_operation ( self , method ) : <EOL> soap_ver = self . __soap_ns == '<STR_LIT>' and '<STR_LIT>' or '<STR_LIT>' <EOL> if not self . service_port : <EOL> for service_name , service in self . services . items ( ) : <EOL> for port_name , port in [ port for port in service [ '<STR_LIT>' ] . items ( ) ] : <EOL> if port [ '<STR_LIT>' ] == soap_ver : <EOL> self . service_port = service_name , port_name <EOL> break <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % soap_ver ) <EOL> else : <EOL> port = self . services [ self . service_port [ <NUM_LIT:0> ] ] [ '<STR_LIT>' ] [ self . service_port [ <NUM_LIT:1> ] ] <EOL> self . location = port [ '<STR_LIT:location>' ] <EOL> operation = port [ '<STR_LIT>' ] . get ( unicode ( method ) ) <EOL> if not operation : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( method , self . service_port ) ) <EOL> return operation <EOL> def wsdl_call ( self , method , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> soap_uri = soap_namespaces [ self . __soap_ns ] <EOL> operation = self . get_operation ( method ) <EOL> input = operation [ '<STR_LIT:input>' ] <EOL> output = operation [ '<STR_LIT>' ] <EOL> header = operation . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT:action>' in operation : <EOL> self . action = operation [ '<STR_LIT:action>' ] <EOL> def sort_dict ( od , d ) : <EOL> if isinstance ( od , dict ) : <EOL> ret = OrderedDict ( ) <EOL> for k in od . keys ( ) : <EOL> v = d . get ( k ) <EOL> if v is not None : <EOL> if isinstance ( v , dict ) : <EOL> v = sort_dict ( od [ k ] , v ) <EOL> elif isinstance ( v , list ) : <EOL> v = [ sort_dict ( od [ k ] [ <NUM_LIT:0> ] , v1 ) <EOL> for v1 in v ] <EOL> ret [ str ( k ) ] = v <EOL> return ret <EOL> else : <EOL> return d <EOL> if header : <EOL> self . __call_headers = sort_dict ( header , self . __headers ) <EOL> if input and args : <EOL> d = [ ( k , arg ) for k , arg in zip ( input . values ( ) [ <NUM_LIT:0> ] . keys ( ) , args ) ] <EOL> kwargs . update ( dict ( d ) ) <EOL> if input and kwargs : <EOL> params = sort_dict ( input . values ( ) [ <NUM_LIT:0> ] , kwargs ) . items ( ) <EOL> if self . __soap_server == "<STR_LIT>" : <EOL> method = method <EOL> else : <EOL> method = input . keys ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> params = kwargs and kwargs . items ( ) <EOL> response = self . call ( method , * params ) <EOL> resp = response ( '<STR_LIT>' , ns = soap_uri ) . children ( ) . unmarshall ( output ) <EOL> return resp and resp . values ( ) [ <NUM_LIT:0> ] <EOL> def help ( self , method ) : <EOL> "<STR_LIT>" <EOL> operation = self . get_operation ( method ) <EOL> input = operation . get ( '<STR_LIT:input>' ) <EOL> input = input and input . values ( ) and input . values ( ) [ <NUM_LIT:0> ] <EOL> if isinstance ( input , dict ) : <EOL> input = "<STR_LIT:U+002CU+0020>" . join ( "<STR_LIT>" % ( k , repr ( v ) ) for k , v <EOL> in input . items ( ) ) <EOL> elif isinstance ( input , list ) : <EOL> input = repr ( input ) <EOL> output = operation . get ( '<STR_LIT>' ) <EOL> if output : <EOL> output = operation [ '<STR_LIT>' ] . values ( ) [ <NUM_LIT:0> ] <EOL> headers = operation . get ( '<STR_LIT>' ) or None <EOL> return u"<STR_LIT>" % ( <EOL> method , <EOL> input or "<STR_LIT>" , <EOL> output and output or "<STR_LIT>" , <EOL> operation . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> headers , <EOL> ) <EOL> def wsdl_parse ( self , url , debug = False , cache = False ) : <EOL> "<STR_LIT>" <EOL> log . debug ( "<STR_LIT>" % url ) <EOL> force_download = False <EOL> if cache : <EOL> filename_pkl = "<STR_LIT>" % hashlib . md5 ( url ) . hexdigest ( ) <EOL> if isinstance ( cache , basestring ) : <EOL> filename_pkl = os . path . join ( cache , filename_pkl ) <EOL> if os . path . exists ( filename_pkl ) : <EOL> log . debug ( "<STR_LIT>" % ( filename_pkl , ) ) <EOL> f = open ( filename_pkl , "<STR_LIT:r>" ) <EOL> pkl = pickle . load ( f ) <EOL> f . close ( ) <EOL> if pkl [ '<STR_LIT:version>' ] [ : - <NUM_LIT:1> ] != __version__ . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:0> ] [ : - <NUM_LIT:1> ] or pkl [ '<STR_LIT:url>' ] != url : <EOL> import warnings <EOL> warnings . warn ( '<STR_LIT>' , RuntimeWarning ) <EOL> if debug : <EOL> log . debug ( '<STR_LIT>' % ( pkl [ '<STR_LIT:version>' ] , __version__ ) ) <EOL> log . debug ( '<STR_LIT>' % ( pkl [ '<STR_LIT:url>' ] , url ) ) <EOL> force_download = True <EOL> else : <EOL> self . namespace = pkl [ '<STR_LIT>' ] <EOL> self . documentation = pkl [ '<STR_LIT>' ] <EOL> return pkl [ '<STR_LIT>' ] <EOL> soap_ns = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> } <EOL> wsdl_uri = "<STR_LIT>" <EOL> xsd_uri = "<STR_LIT>" <EOL> xsi_uri = "<STR_LIT>" <EOL> get_local_name = lambda s : s and str ( ( '<STR_LIT::>' in s ) and s . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] or s ) <EOL> get_namespace_prefix = lambda s : s and str ( ( '<STR_LIT::>' in s ) and s . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] or None ) <EOL> REVERSE_TYPE_MAP [ u'<STR_LIT:string>' ] = unicode <EOL> def fetch ( url ) : <EOL> "<STR_LIT>" <EOL> url_scheme , netloc , path , query , fragment = urlsplit ( url ) <EOL> if not url_scheme in ( '<STR_LIT:http>' , '<STR_LIT>' , '<STR_LIT:file>' ) : <EOL> for scheme in ( '<STR_LIT:http>' , '<STR_LIT>' , '<STR_LIT:file>' ) : <EOL> try : <EOL> if not url . startswith ( "<STR_LIT:/>" ) and scheme in ( '<STR_LIT:http>' , '<STR_LIT>' ) : <EOL> tmp_url = "<STR_LIT>" % ( scheme , url ) <EOL> else : <EOL> tmp_url = "<STR_LIT>" % ( scheme , url ) <EOL> if debug : log . debug ( "<STR_LIT>" % scheme ) <EOL> return fetch ( tmp_url ) <EOL> except Exception , e : <EOL> log . error ( e ) <EOL> raise RuntimeError ( "<STR_LIT>" % url ) <EOL> filename = "<STR_LIT>" % hashlib . md5 ( url ) . hexdigest ( ) <EOL> if isinstance ( cache , basestring ) : <EOL> filename = os . path . join ( cache , filename ) <EOL> if cache and os . path . exists ( filename ) and not force_download : <EOL> log . info ( "<STR_LIT>" % ( filename , ) ) <EOL> f = open ( filename , "<STR_LIT:r>" ) <EOL> xml = f . read ( ) <EOL> f . close ( ) <EOL> else : <EOL> if url_scheme == '<STR_LIT:file>' : <EOL> log . info ( "<STR_LIT>" % ( url , ) ) <EOL> f = urllib2 . urlopen ( url ) <EOL> xml = f . read ( ) <EOL> else : <EOL> log . info ( "<STR_LIT>" % ( url , self . http . _wrapper_version ) ) <EOL> response , xml = self . http . request ( url , "<STR_LIT:GET>" , None , { } ) <EOL> if cache : <EOL> log . info ( "<STR_LIT>" % ( filename , ) ) <EOL> if not os . path . isdir ( cache ) : <EOL> os . makedirs ( cache ) <EOL> f = open ( filename , "<STR_LIT:w>" ) <EOL> f . write ( xml ) <EOL> f . close ( ) <EOL> return xml <EOL> xml = fetch ( url ) <EOL> wsdl = SimpleXMLElement ( xml , namespace = wsdl_uri ) <EOL> xsd_ns = None <EOL> soap_uris = { } <EOL> for k , v in wsdl [ : ] : <EOL> if v in soap_ns and k . startswith ( "<STR_LIT>" ) : <EOL> soap_uris [ get_local_name ( k ) ] = v <EOL> if v == xsd_uri and k . startswith ( "<STR_LIT>" ) : <EOL> xsd_ns = get_local_name ( k ) <EOL> self . namespace = wsdl [ '<STR_LIT>' ] <EOL> self . documentation = unicode ( wsdl ( '<STR_LIT>' , error = False ) or '<STR_LIT>' ) <EOL> services = { } <EOL> bindings = { } <EOL> operations = { } <EOL> port_type_bindings = { } <EOL> messages = { } <EOL> elements = { } <EOL> for service in wsdl . service : <EOL> service_name = service [ '<STR_LIT:name>' ] <EOL> if not service_name : <EOL> continue <EOL> if debug : log . debug ( "<STR_LIT>" % service_name ) <EOL> serv = services . setdefault ( service_name , { '<STR_LIT>' : { } } ) <EOL> serv [ '<STR_LIT>' ] = service [ '<STR_LIT>' ] or '<STR_LIT>' <EOL> for port in service . port : <EOL> binding_name = get_local_name ( port [ '<STR_LIT>' ] ) <EOL> address = port ( '<STR_LIT:address>' , ns = soap_uris . values ( ) , error = False ) <EOL> location = address and address [ '<STR_LIT:location>' ] or None <EOL> soap_uri = address and soap_uris . get ( address . get_prefix ( ) ) <EOL> soap_ver = soap_uri and soap_ns . get ( soap_uri ) <EOL> bindings [ binding_name ] = { '<STR_LIT>' : service_name , <EOL> '<STR_LIT:location>' : location , <EOL> '<STR_LIT>' : soap_uri , '<STR_LIT>' : soap_ver , <EOL> } <EOL> serv [ '<STR_LIT>' ] [ port [ '<STR_LIT:name>' ] ] = bindings [ binding_name ] <EOL> for binding in wsdl . binding : <EOL> binding_name = binding [ '<STR_LIT:name>' ] <EOL> if debug : log . debug ( "<STR_LIT>" % service_name ) <EOL> soap_binding = binding ( '<STR_LIT>' , ns = soap_uris . values ( ) , error = False ) <EOL> transport = soap_binding and soap_binding [ '<STR_LIT>' ] or None <EOL> port_type_name = get_local_name ( binding [ '<STR_LIT:type>' ] ) <EOL> bindings [ binding_name ] . update ( { <EOL> '<STR_LIT>' : port_type_name , <EOL> '<STR_LIT>' : transport , '<STR_LIT>' : { } , <EOL> } ) <EOL> port_type_bindings [ port_type_name ] = bindings [ binding_name ] <EOL> for operation in binding . operation : <EOL> op_name = operation [ '<STR_LIT:name>' ] <EOL> op = operation ( '<STR_LIT>' , ns = soap_uris . values ( ) , error = False ) <EOL> action = op and op [ '<STR_LIT>' ] <EOL> d = operations . setdefault ( op_name , { } ) <EOL> bindings [ binding_name ] [ '<STR_LIT>' ] [ op_name ] = d <EOL> d . update ( { '<STR_LIT:name>' : op_name } ) <EOL> d [ '<STR_LIT>' ] = { } <EOL> input = operation ( '<STR_LIT:input>' , error = False ) <EOL> body = input and input ( '<STR_LIT:body>' , ns = soap_uris . values ( ) , error = False ) <EOL> d [ '<STR_LIT>' ] [ '<STR_LIT>' ] = body and body [ '<STR_LIT>' ] or None <EOL> output = operation ( '<STR_LIT>' , error = False ) <EOL> body = output and output ( '<STR_LIT:body>' , ns = soap_uris . values ( ) , error = False ) <EOL> d [ '<STR_LIT>' ] [ '<STR_LIT>' ] = body and body [ '<STR_LIT>' ] or None <EOL> header = input and input ( '<STR_LIT>' , ns = soap_uris . values ( ) , error = False ) <EOL> d [ '<STR_LIT>' ] [ '<STR_LIT>' ] = header and { '<STR_LIT:message>' : header [ '<STR_LIT:message>' ] , '<STR_LIT>' : header [ '<STR_LIT>' ] } or None <EOL> headers = output and output ( '<STR_LIT>' , ns = soap_uris . values ( ) , error = False ) <EOL> d [ '<STR_LIT>' ] [ '<STR_LIT>' ] = header and { '<STR_LIT:message>' : header [ '<STR_LIT:message>' ] , '<STR_LIT>' : header [ '<STR_LIT>' ] } or None <EOL> if action : <EOL> d [ "<STR_LIT:action>" ] = action <EOL> def make_key ( element_name , element_type ) : <EOL> "<STR_LIT>" <EOL> if element_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> eltype = '<STR_LIT>' <EOL> else : <EOL> eltype = element_type <EOL> if eltype not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise RuntimeError ( "<STR_LIT>" % ( unicode ( element_name ) , eltype ) ) <EOL> return ( unicode ( element_name ) , eltype ) <EOL> def process_element ( element_name , node , element_type ) : <EOL> "<STR_LIT>" <EOL> if debug : <EOL> log . debug ( "<STR_LIT>" % ( element_name , element_type ) ) <EOL> for tag in node : <EOL> if tag . get_local_name ( ) in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> continue <EOL> elif tag . get_local_name ( ) in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if debug : log . debug ( "<STR_LIT>" % ( element_name , tag ) ) <EOL> children = tag <EOL> alias = True <EOL> elif tag . children ( ) : <EOL> children = tag . children ( ) <EOL> alias = False <EOL> else : <EOL> if debug : log . debug ( "<STR_LIT>" % ( element_name , tag ) ) <EOL> continue <EOL> d = OrderedDict ( ) <EOL> for e in children : <EOL> t = e [ '<STR_LIT:type>' ] <EOL> if not t : <EOL> t = e [ '<STR_LIT>' ] <EOL> if not t : <EOL> t = '<STR_LIT>' <EOL> t = t . split ( "<STR_LIT::>" ) <EOL> if len ( t ) > <NUM_LIT:1> : <EOL> ns , type_name = t <EOL> else : <EOL> ns , type_name = None , t [ <NUM_LIT:0> ] <EOL> if element_name == type_name : <EOL> pass <EOL> uri = ns and e . get_namespace_uri ( ns ) or xsd_uri <EOL> if uri == xsd_uri : <EOL> fn = REVERSE_TYPE_MAP . get ( unicode ( type_name ) , None ) <EOL> else : <EOL> fn = None <EOL> if not fn : <EOL> fn = elements . setdefault ( make_key ( type_name , "<STR_LIT>" ) , OrderedDict ( ) ) <EOL> if e [ '<STR_LIT:name>' ] is not None and not alias : <EOL> e_name = unicode ( e [ '<STR_LIT:name>' ] ) <EOL> d [ e_name ] = fn <EOL> else : <EOL> if debug : log . debug ( "<STR_LIT>" % ( element_name , type_name ) ) <EOL> d [ None ] = fn <EOL> if e [ '<STR_LIT>' ] == "<STR_LIT>" or ( ns == '<STR_LIT>' and type_name == '<STR_LIT>' ) : <EOL> d . array = True <EOL> if e is not None and e . get_local_name ( ) == '<STR_LIT>' and e . children ( ) : <EOL> process_element ( element_name , e . children ( ) , element_type ) <EOL> elements . setdefault ( make_key ( element_name , element_type ) , OrderedDict ( ) ) . update ( d ) <EOL> self . namespace = dict ( wsdl . types ( "<STR_LIT>" , ns = xsd_uri ) [ : ] ) . get ( '<STR_LIT>' , self . namespace ) <EOL> imported_schemas = { } <EOL> def preprocess_schema ( schema ) : <EOL> "<STR_LIT>" <EOL> for element in schema . children ( ) or [ ] : <EOL> if element . get_local_name ( ) in ( '<STR_LIT>' , ) : <EOL> schema_namespace = element [ '<STR_LIT>' ] <EOL> schema_location = element [ '<STR_LIT>' ] <EOL> if schema_location is None : <EOL> if debug : log . debug ( "<STR_LIT>" % ( schema_namespace , ) ) <EOL> continue <EOL> if schema_location in imported_schemas : <EOL> if debug : log . debug ( "<STR_LIT>" % ( schema_location , ) ) <EOL> continue <EOL> imported_schemas [ schema_location ] = schema_namespace <EOL> if debug : print "<STR_LIT>" % ( schema_namespace , schema_location ) <EOL> xml = fetch ( schema_location ) <EOL> imported_schema = SimpleXMLElement ( xml , namespace = xsd_uri ) <EOL> preprocess_schema ( imported_schema ) <EOL> element_type = element . get_local_name ( ) <EOL> if element_type in ( '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) : <EOL> element_name = unicode ( element [ '<STR_LIT:name>' ] ) <EOL> if debug : log . debug ( "<STR_LIT>" % ( element_type , element_name ) ) <EOL> if element . get_local_name ( ) == '<STR_LIT>' : <EOL> children = element . children ( ) <EOL> elif element . get_local_name ( ) == '<STR_LIT>' : <EOL> children = element ( "<STR_LIT>" , ns = xsd_uri ) <EOL> elif element . get_local_name ( ) == '<STR_LIT>' and element [ '<STR_LIT:type>' ] : <EOL> children = element <EOL> else : <EOL> children = element . children ( ) <EOL> if children : <EOL> children = children . children ( ) <EOL> elif element . get_local_name ( ) == '<STR_LIT>' : <EOL> children = element <EOL> if children : <EOL> process_element ( element_name , children , element_type ) <EOL> def postprocess_element ( elements ) : <EOL> "<STR_LIT>" <EOL> for k , v in elements . items ( ) : <EOL> if isinstance ( v , OrderedDict ) : <EOL> if v . array : <EOL> elements [ k ] = [ v ] <EOL> if v != elements : <EOL> postprocess_element ( v ) <EOL> if None in v and v [ None ] : <EOL> if isinstance ( v [ None ] , dict ) : <EOL> for i , kk in enumerate ( v [ None ] ) : <EOL> if v [ None ] is not None : <EOL> elements [ k ] . insert ( kk , v [ None ] [ kk ] , i ) <EOL> del v [ None ] <EOL> else : <EOL> if debug : log . debug ( "<STR_LIT>" % ( k , v [ None ] ) ) <EOL> elements [ k ] = v [ None ] <EOL> if isinstance ( v , list ) : <EOL> for n in v : <EOL> postprocess_element ( n ) <EOL> for schema in wsdl . types ( "<STR_LIT>" , ns = xsd_uri ) : <EOL> preprocess_schema ( schema ) <EOL> postprocess_element ( elements ) <EOL> for message in wsdl . message : <EOL> if debug : log . debug ( "<STR_LIT>" % message [ '<STR_LIT:name>' ] ) <EOL> for part in message ( '<STR_LIT>' , error = False ) or [ ] : <EOL> element = { } <EOL> element_name = part [ '<STR_LIT>' ] <EOL> if not element_name : <EOL> element_name = part [ '<STR_LIT:type>' ] <EOL> type_ns = get_namespace_prefix ( element_name ) <EOL> type_uri = wsdl . get_namespace_uri ( type_ns ) <EOL> if type_uri == xsd_uri : <EOL> element_name = get_local_name ( element_name ) <EOL> fn = REVERSE_TYPE_MAP . get ( unicode ( element_name ) , None ) <EOL> element = { part [ '<STR_LIT:name>' ] : fn } <EOL> messages . setdefault ( ( message [ '<STR_LIT:name>' ] , None ) , { message [ '<STR_LIT:name>' ] : OrderedDict ( ) } ) . values ( ) [ <NUM_LIT:0> ] . update ( element ) <EOL> else : <EOL> element_name = get_local_name ( element_name ) <EOL> fn = elements . get ( make_key ( element_name , '<STR_LIT>' ) ) <EOL> if not fn : <EOL> fn = elements . get ( make_key ( element_name , '<STR_LIT>' ) ) <EOL> element = { message [ '<STR_LIT:name>' ] : { part [ '<STR_LIT:name>' ] : fn } } <EOL> else : <EOL> element = { element_name : fn } <EOL> messages [ ( message [ '<STR_LIT:name>' ] , part [ '<STR_LIT:name>' ] ) ] = element <EOL> def get_message ( message_name , part_name ) : <EOL> if part_name : <EOL> return messages . get ( ( message_name , part_name ) ) <EOL> else : <EOL> for ( message_name_key , part_name_key ) , message in messages . items ( ) : <EOL> if message_name_key == message_name : <EOL> return message <EOL> for port_type in wsdl . portType : <EOL> port_type_name = port_type [ '<STR_LIT:name>' ] <EOL> if debug : log . debug ( "<STR_LIT>" % port_type_name ) <EOL> binding = port_type_bindings [ port_type_name ] <EOL> for operation in port_type . operation : <EOL> op_name = operation [ '<STR_LIT:name>' ] <EOL> op = operations [ op_name ] <EOL> op [ '<STR_LIT>' ] = unicode ( operation ( '<STR_LIT>' , error = False ) or '<STR_LIT>' ) <EOL> if binding [ '<STR_LIT>' ] : <EOL> if operation ( "<STR_LIT:input>" , error = False ) : <EOL> input_msg = get_local_name ( operation . input [ '<STR_LIT:message>' ] ) <EOL> input_header = op [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> if input_header : <EOL> header_msg = get_local_name ( input_header . get ( '<STR_LIT:message>' ) ) <EOL> header_part = get_local_name ( input_header . get ( '<STR_LIT>' ) ) <EOL> header = get_message ( header_msg or input_msg , header_part ) <EOL> else : <EOL> header = None <EOL> op [ '<STR_LIT:input>' ] = get_message ( input_msg , op [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) ) <EOL> op [ '<STR_LIT>' ] = header <EOL> else : <EOL> op [ '<STR_LIT:input>' ] = None <EOL> op [ '<STR_LIT>' ] = None <EOL> if operation ( "<STR_LIT>" , error = False ) : <EOL> output_msg = get_local_name ( operation . output [ '<STR_LIT:message>' ] ) <EOL> op [ '<STR_LIT>' ] = get_message ( output_msg , op [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) ) <EOL> else : <EOL> op [ '<STR_LIT>' ] = None <EOL> if debug : <EOL> import pprint <EOL> log . debug ( pprint . pformat ( services ) ) <EOL> if cache : <EOL> f = open ( filename_pkl , "<STR_LIT:wb>" ) <EOL> pkl = { <EOL> '<STR_LIT:version>' : __version__ . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:0> ] , <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : self . namespace , <EOL> '<STR_LIT>' : self . documentation , <EOL> '<STR_LIT>' : services , <EOL> } <EOL> pickle . dump ( pkl , f ) <EOL> f . close ( ) <EOL> return services <EOL> def __setitem__ ( self , item , value ) : <EOL> "<STR_LIT>" <EOL> self . __headers [ item ] = value <EOL> def close ( self ) : <EOL> "<STR_LIT>" <EOL> self . http . close ( ) <EOL> if self . cacert . startswith ( tempfile . gettempdir ( ) ) : <EOL> if self . trace : log . info ( "<STR_LIT>" % self . cacert ) <EOL> os . unlink ( self . cacert ) <EOL> def parse_proxy ( proxy_str ) : <EOL> "<STR_LIT>" <EOL> if isinstance ( proxy_str , unicode ) : <EOL> proxy_str = proxy_str . encode ( "<STR_LIT:utf8>" ) <EOL> proxy_dict = { } <EOL> if proxy_str is None : <EOL> return <EOL> if "<STR_LIT:@>" in proxy_str : <EOL> user_pass , host_port = proxy_str . split ( "<STR_LIT:@>" ) <EOL> else : <EOL> user_pass , host_port = "<STR_LIT>" , proxy_str <EOL> if "<STR_LIT::>" in host_port : <EOL> host , port = host_port . split ( "<STR_LIT::>" ) <EOL> proxy_dict [ '<STR_LIT>' ] , proxy_dict [ '<STR_LIT>' ] = host , int ( port ) <EOL> if "<STR_LIT::>" in user_pass : <EOL> proxy_dict [ '<STR_LIT>' ] , proxy_dict [ '<STR_LIT>' ] = user_pass . split ( "<STR_LIT::>" ) <EOL> return proxy_dict <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> pass </s>
