<s> """<STR_LIT>""" <EOL> ident = '<STR_LIT>' <EOL> from version import __version__ <EOL> import urllib <EOL> from types import * <EOL> import re <EOL> import base64 <EOL> from Errors import * <EOL> from Config import Config <EOL> from Parser import parseSOAPRPC <EOL> from SOAPBuilder import buildSOAP <EOL> from Utilities import * <EOL> from Types import faultType , simplify <EOL> def SOAPUserAgent ( ) : <EOL> return "<STR_LIT>" + __version__ + "<STR_LIT>" <EOL> class SOAPAddress : <EOL> def __init__ ( self , url , config = Config ) : <EOL> proto , uri = urllib . splittype ( url ) <EOL> if uri [ <NUM_LIT:0> : <NUM_LIT:2> ] != '<STR_LIT>' : <EOL> if proto != None : <EOL> uri = proto + '<STR_LIT::>' + uri <EOL> uri = '<STR_LIT>' + uri <EOL> proto = '<STR_LIT:http>' <EOL> host , path = urllib . splithost ( uri ) <EOL> try : <EOL> int ( host ) <EOL> host = '<STR_LIT>' + host <EOL> except : <EOL> pass <EOL> if not path : <EOL> path = '<STR_LIT:/>' <EOL> if proto not in ( '<STR_LIT:http>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise IOError , "<STR_LIT>" <EOL> if proto == '<STR_LIT>' and not config . GSIclient : <EOL> raise AttributeError , "<STR_LIT>" <EOL> if proto == '<STR_LIT>' and not config . SSLclient : <EOL> raise AttributeError , "<STR_LIT>" <EOL> self . user , host = urllib . splituser ( host ) <EOL> self . proto = proto <EOL> self . host = host <EOL> self . path = path <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . __dict__ <EOL> __repr__ = __str__ <EOL> class HTTPTransport : <EOL> def getNS ( self , original_namespace , data ) : <EOL> """<STR_LIT>""" <EOL> if type ( original_namespace ) == StringType : <EOL> pattern = "<STR_LIT>" + original_namespace + "<STR_LIT>" <EOL> match = re . search ( pattern , data ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> else : <EOL> return original_namespace <EOL> else : <EOL> return original_namespace <EOL> def call ( self , addr , data , namespace , soapaction = None , encoding = None , <EOL> http_proxy = None , config = Config ) : <EOL> import httplib <EOL> if not isinstance ( addr , SOAPAddress ) : <EOL> addr = SOAPAddress ( addr , config ) <EOL> if http_proxy : <EOL> real_addr = http_proxy <EOL> real_path = addr . proto + "<STR_LIT>" + addr . host + addr . path <EOL> else : <EOL> real_addr = addr . host <EOL> real_path = addr . path <EOL> if addr . proto == '<STR_LIT>' : <EOL> from pyGlobus . io import GSIHTTP <EOL> r = GSIHTTP ( real_addr , tcpAttr = config . tcpAttr ) <EOL> elif addr . proto == '<STR_LIT>' : <EOL> r = httplib . HTTPS ( real_addr ) <EOL> else : <EOL> r = httplib . HTTP ( real_addr ) <EOL> r . putrequest ( "<STR_LIT:POST>" , real_path ) <EOL> r . putheader ( "<STR_LIT>" , addr . host ) <EOL> r . putheader ( "<STR_LIT>" , SOAPUserAgent ( ) ) <EOL> t = '<STR_LIT>' ; <EOL> if encoding != None : <EOL> t += '<STR_LIT>' % encoding <EOL> r . putheader ( "<STR_LIT>" , t ) <EOL> r . putheader ( "<STR_LIT>" , str ( len ( data ) ) ) <EOL> if addr . user != None : <EOL> val = base64 . encodestring ( addr . user ) <EOL> r . putheader ( '<STR_LIT>' , '<STR_LIT>' + val . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if soapaction == None or len ( soapaction ) == <NUM_LIT:0> : <EOL> r . putheader ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> r . putheader ( "<STR_LIT>" , '<STR_LIT>' % soapaction ) <EOL> if config . dumpHeadersOut : <EOL> s = '<STR_LIT>' <EOL> debugHeader ( s ) <EOL> print "<STR_LIT>" % ( real_path , r . _http_vsn_str ) <EOL> print "<STR_LIT>" , addr . host <EOL> print "<STR_LIT>" + __version__ + "<STR_LIT>" <EOL> print "<STR_LIT>" , t <EOL> print "<STR_LIT>" , len ( data ) <EOL> print '<STR_LIT>' % soapaction <EOL> debugFooter ( s ) <EOL> r . endheaders ( ) <EOL> if config . dumpSOAPOut : <EOL> s = '<STR_LIT>' <EOL> debugHeader ( s ) <EOL> print data , <EOL> if data [ - <NUM_LIT:1> ] != '<STR_LIT:\n>' : <EOL> print <EOL> debugFooter ( s ) <EOL> r . send ( data ) <EOL> code , msg , headers = r . getreply ( ) <EOL> if headers : <EOL> content_type = headers . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> content_length = headers . get ( "<STR_LIT>" ) <EOL> else : <EOL> content_type = None <EOL> content_length = None <EOL> if content_length : <EOL> comma = content_length . find ( '<STR_LIT:U+002C>' ) <EOL> if comma > <NUM_LIT:0> : <EOL> content_length = content_length [ : comma ] <EOL> try : <EOL> message_len = int ( content_length ) <EOL> except : <EOL> message_len = - <NUM_LIT:1> <EOL> if message_len < <NUM_LIT:0> : <EOL> data = r . getfile ( ) . read ( ) <EOL> message_len = len ( data ) <EOL> else : <EOL> data = r . getfile ( ) . read ( message_len ) <EOL> if ( config . debug ) : <EOL> print "<STR_LIT>" , code <EOL> print "<STR_LIT>" , msg <EOL> print "<STR_LIT>" , headers <EOL> print "<STR_LIT>" , content_type <EOL> print "<STR_LIT>" , data <EOL> if config . dumpHeadersIn : <EOL> s = '<STR_LIT>' <EOL> debugHeader ( s ) <EOL> if headers . headers : <EOL> print "<STR_LIT>" % ( code , msg ) <EOL> print "<STR_LIT:\n>" . join ( map ( lambda x : x . strip ( ) , headers . headers ) ) <EOL> else : <EOL> print "<STR_LIT>" % ( code , msg ) <EOL> debugFooter ( s ) <EOL> def startswith ( string , val ) : <EOL> return string [ <NUM_LIT:0> : len ( val ) ] == val <EOL> if code == <NUM_LIT> and not ( startswith ( content_type , "<STR_LIT>" ) and message_len > <NUM_LIT:0> ) : <EOL> raise HTTPError ( code , msg ) <EOL> if config . dumpSOAPIn : <EOL> s = '<STR_LIT>' <EOL> debugHeader ( s ) <EOL> print data , <EOL> if ( len ( data ) > <NUM_LIT:0> ) and ( data [ - <NUM_LIT:1> ] != '<STR_LIT:\n>' ) : <EOL> print <EOL> debugFooter ( s ) <EOL> if code not in ( <NUM_LIT:200> , <NUM_LIT> ) : <EOL> raise HTTPError ( code , msg ) <EOL> if namespace is None : <EOL> new_ns = None <EOL> else : <EOL> new_ns = self . getNS ( namespace , data ) <EOL> return data , new_ns <EOL> class SOAPProxy : <EOL> def __init__ ( self , proxy , namespace = None , soapaction = None , <EOL> header = None , methodattrs = None , transport = HTTPTransport , <EOL> encoding = '<STR_LIT>' , throw_faults = <NUM_LIT:1> , unwrap_results = None , <EOL> http_proxy = None , config = Config , noroot = <NUM_LIT:0> , <EOL> simplify_objects = None ) : <EOL> if encoding != None : <EOL> '<STR_LIT>' . encode ( encoding ) <EOL> if unwrap_results is None : <EOL> self . unwrap_results = config . unwrap_results <EOL> else : <EOL> self . unwrap_results = unwrap_results <EOL> if simplify_objects is None : <EOL> self . simplify_objects = config . simplify_objects <EOL> else : <EOL> self . simplify_objects = simplify_objects <EOL> self . proxy = SOAPAddress ( proxy , config ) <EOL> self . namespace = namespace <EOL> self . soapaction = soapaction <EOL> self . header = header <EOL> self . methodattrs = methodattrs <EOL> self . transport = transport ( ) <EOL> self . encoding = encoding <EOL> self . throw_faults = throw_faults <EOL> self . http_proxy = http_proxy <EOL> self . config = config <EOL> self . noroot = noroot <EOL> if hasattr ( config , "<STR_LIT>" ) and hasattr ( config , "<STR_LIT>" ) : <EOL> self . channel_mode = config . channel_mode <EOL> self . delegation_mode = config . delegation_mode <EOL> def invoke ( self , method , args ) : <EOL> return self . __call ( method , args , { } ) <EOL> def __call ( self , name , args , kw , ns = None , sa = None , hd = None , <EOL> ma = None ) : <EOL> ns = ns or self . namespace <EOL> ma = ma or self . methodattrs <EOL> if sa : <EOL> if type ( sa ) == TupleType : <EOL> sa = sa [ <NUM_LIT:0> ] <EOL> else : <EOL> if self . soapaction : <EOL> sa = self . soapaction <EOL> else : <EOL> sa = name <EOL> if hd : <EOL> if type ( hd ) == TupleType : <EOL> hd = hd [ <NUM_LIT:0> ] <EOL> else : <EOL> hd = self . header <EOL> hd = hd or self . header <EOL> if ma : <EOL> if type ( ma ) == TupleType : ma = ma [ <NUM_LIT:0> ] <EOL> else : <EOL> ma = self . methodattrs <EOL> ma = ma or self . methodattrs <EOL> m = buildSOAP ( args = args , kw = kw , method = name , namespace = ns , <EOL> header = hd , methodattrs = ma , encoding = self . encoding , <EOL> config = self . config , noroot = self . noroot ) <EOL> call_retry = <NUM_LIT:0> <EOL> try : <EOL> r , self . namespace = self . transport . call ( self . proxy , m , ns , sa , <EOL> encoding = self . encoding , <EOL> http_proxy = self . http_proxy , <EOL> config = self . config ) <EOL> except Exception , ex : <EOL> if hasattr ( self . config , "<STR_LIT>" ) : <EOL> if callable ( self . config . faultHandler ) : <EOL> call_retry = self . config . faultHandler ( self . proxy , ex ) <EOL> if not call_retry : <EOL> raise <EOL> else : <EOL> raise <EOL> else : <EOL> raise <EOL> if call_retry : <EOL> r , self . namespace = self . transport . call ( self . proxy , m , ns , sa , <EOL> encoding = self . encoding , <EOL> http_proxy = self . http_proxy , <EOL> config = self . config ) <EOL> p , attrs = parseSOAPRPC ( r , attrs = <NUM_LIT:1> ) <EOL> try : <EOL> throw_struct = self . throw_faults and isinstance ( p , faultType ) <EOL> except : <EOL> throw_struct = <NUM_LIT:0> <EOL> if throw_struct : <EOL> if Config . debug : <EOL> print p <EOL> raise p <EOL> if self . unwrap_results : <EOL> try : <EOL> count = <NUM_LIT:0> <EOL> for i in p . __dict__ . keys ( ) : <EOL> if i [ <NUM_LIT:0> ] != "<STR_LIT:_>" : <EOL> count += <NUM_LIT:1> <EOL> t = getattr ( p , i ) <EOL> if count == <NUM_LIT:1> : <EOL> p = t <EOL> except : <EOL> pass <EOL> if self . simplify_objects : <EOL> p = simplify ( p ) <EOL> if self . config . returnAllAttrs : <EOL> return p , attrs <EOL> return p <EOL> def _callWithBody ( self , body ) : <EOL> return self . __call ( None , body , { } ) <EOL> def __getattr__ ( self , name ) : <EOL> if name == '<STR_LIT>' : <EOL> raise AttributeError , name <EOL> return self . __Method ( self . __call , name , config = self . config ) <EOL> class __Method : <EOL> def __init__ ( self , call , name , ns = None , sa = None , hd = None , <EOL> ma = None , config = Config ) : <EOL> self . __call = call <EOL> self . __name = name <EOL> self . __ns = ns <EOL> self . __sa = sa <EOL> self . __hd = hd <EOL> self . __ma = ma <EOL> self . __config = config <EOL> return <EOL> def __call__ ( self , * args , ** kw ) : <EOL> if self . __name [ <NUM_LIT:0> ] == "<STR_LIT:_>" : <EOL> if self . __name in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return self . __repr__ ( ) <EOL> else : <EOL> return self . __f_call ( * args , ** kw ) <EOL> else : <EOL> return self . __r_call ( * args , ** kw ) <EOL> def __getattr__ ( self , name ) : <EOL> if name == '<STR_LIT>' : <EOL> raise AttributeError , name <EOL> if self . __name [ <NUM_LIT:0> ] == "<STR_LIT:_>" : <EOL> return self . __class__ ( self . __call , name , self . __ns , <EOL> self . __sa , self . __hd , self . __ma ) <EOL> return self . __class__ ( self . __call , "<STR_LIT>" % ( self . __name , name ) , <EOL> self . __ns , self . __sa , self . __hd , self . __ma ) <EOL> def __f_call ( self , * args , ** kw ) : <EOL> if self . __name == "<STR_LIT>" : self . __ns = args <EOL> elif self . __name == "<STR_LIT>" : self . __sa = args <EOL> elif self . __name == "<STR_LIT>" : self . __hd = args <EOL> elif self . __name == "<STR_LIT>" : self . __ma = args <EOL> return self <EOL> def __r_call ( self , * args , ** kw ) : <EOL> return self . __call ( self . __name , args , kw , self . __ns , self . __sa , <EOL> self . __hd , self . __ma ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ , id ( self ) ) </s>
