<s> """<STR_LIT>""" <EOL> from logging import getLogger <EOL> from suds import * <EOL> import suds . metrics as metrics <EOL> from suds . sax import Namespace <EOL> log = getLogger ( __name__ ) <EOL> class ServiceDefinition : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wsdl , service ) : <EOL> """<STR_LIT>""" <EOL> self . wsdl = wsdl <EOL> self . service = service <EOL> self . ports = [ ] <EOL> self . params = [ ] <EOL> self . types = [ ] <EOL> self . prefixes = [ ] <EOL> self . addports ( ) <EOL> self . paramtypes ( ) <EOL> self . publictypes ( ) <EOL> self . getprefixes ( ) <EOL> self . pushprefixes ( ) <EOL> def pushprefixes ( self ) : <EOL> """<STR_LIT>""" <EOL> for ns in self . prefixes : <EOL> self . wsdl . root . addPrefix ( ns [ <NUM_LIT:0> ] , ns [ <NUM_LIT:1> ] ) <EOL> def addports ( self ) : <EOL> """<STR_LIT>""" <EOL> timer = metrics . Timer ( ) <EOL> timer . start ( ) <EOL> for port in self . service . ports : <EOL> p = self . findport ( port ) <EOL> for op in port . binding . operations . values ( ) : <EOL> m = p [ <NUM_LIT:0> ] . method ( op . name ) <EOL> binding = m . binding . input <EOL> method = ( m . name , binding . param_defs ( m ) ) <EOL> p [ <NUM_LIT:1> ] . append ( method ) <EOL> p [ <NUM_LIT:1> ] . sort ( ) <EOL> timer . stop ( ) <EOL> def findport ( self , port ) : <EOL> """<STR_LIT>""" <EOL> for p in self . ports : <EOL> if p [ <NUM_LIT:0> ] == p : return p <EOL> p = ( port , [ ] ) <EOL> self . ports . append ( p ) <EOL> return p <EOL> def getprefixes ( self ) : <EOL> """<STR_LIT>""" <EOL> namespaces = [ ] <EOL> for l in ( self . params , self . types ) : <EOL> for t , r in l : <EOL> ns = r . namespace ( ) <EOL> if ns [ <NUM_LIT:1> ] is None : continue <EOL> if ns [ <NUM_LIT:1> ] in namespaces : continue <EOL> if Namespace . xs ( ns ) or Namespace . xsd ( ns ) : <EOL> continue <EOL> namespaces . append ( ns [ <NUM_LIT:1> ] ) <EOL> if t == r : continue <EOL> ns = t . namespace ( ) <EOL> if ns [ <NUM_LIT:1> ] is None : continue <EOL> if ns [ <NUM_LIT:1> ] in namespaces : continue <EOL> namespaces . append ( ns [ <NUM_LIT:1> ] ) <EOL> i = <NUM_LIT:0> <EOL> namespaces . sort ( ) <EOL> for u in namespaces : <EOL> p = self . nextprefix ( ) <EOL> ns = ( p , u ) <EOL> self . prefixes . append ( ns ) <EOL> def paramtypes ( self ) : <EOL> """<STR_LIT>""" <EOL> for m in [ p [ <NUM_LIT:1> ] for p in self . ports ] : <EOL> for p in [ p [ <NUM_LIT:1> ] for p in m ] : <EOL> for pd in p : <EOL> if pd [ <NUM_LIT:1> ] in self . params : continue <EOL> item = ( pd [ <NUM_LIT:1> ] , pd [ <NUM_LIT:1> ] . resolve ( ) ) <EOL> self . params . append ( item ) <EOL> def publictypes ( self ) : <EOL> """<STR_LIT>""" <EOL> for t in self . wsdl . schema . types . values ( ) : <EOL> if t in self . params : continue <EOL> if t in self . types : continue <EOL> item = ( t , t ) <EOL> self . types . append ( item ) <EOL> tc = lambda x , y : cmp ( x [ <NUM_LIT:0> ] . name , y [ <NUM_LIT:0> ] . name ) <EOL> self . types . sort ( cmp = tc ) <EOL> def nextprefix ( self ) : <EOL> """<STR_LIT>""" <EOL> used = [ ns [ <NUM_LIT:0> ] for ns in self . prefixes ] <EOL> used += [ ns [ <NUM_LIT:0> ] for ns in self . wsdl . root . nsprefixes . items ( ) ] <EOL> for n in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> p = '<STR_LIT>' % n <EOL> if p not in used : <EOL> return p <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def getprefix ( self , u ) : <EOL> """<STR_LIT>""" <EOL> for ns in Namespace . all : <EOL> if u == ns [ <NUM_LIT:1> ] : return ns [ <NUM_LIT:0> ] <EOL> for ns in self . prefixes : <EOL> if u == ns [ <NUM_LIT:1> ] : return ns [ <NUM_LIT:0> ] <EOL> raise Exception ( '<STR_LIT>' % u ) <EOL> def xlate ( self , type ) : <EOL> """<STR_LIT>""" <EOL> resolved = type . resolve ( ) <EOL> name = resolved . name <EOL> if type . unbounded ( ) : <EOL> name += '<STR_LIT>' <EOL> ns = resolved . namespace ( ) <EOL> if ns [ <NUM_LIT:1> ] == self . wsdl . tns [ <NUM_LIT:1> ] : <EOL> return name <EOL> prefix = self . getprefix ( ns [ <NUM_LIT:1> ] ) <EOL> return '<STR_LIT::>' . join ( ( prefix , name ) ) <EOL> def description ( self ) : <EOL> """<STR_LIT>""" <EOL> s = [ ] <EOL> indent = ( lambda n : '<STR_LIT>' % ( n * <NUM_LIT:3> , '<STR_LIT:U+0020>' ) ) <EOL> s . append ( '<STR_LIT>' % ( self . service . name , self . wsdl . tns [ <NUM_LIT:1> ] ) ) <EOL> s . append ( indent ( <NUM_LIT:1> ) ) <EOL> s . append ( '<STR_LIT>' % len ( self . prefixes ) ) <EOL> for p in self . prefixes : <EOL> s . append ( indent ( <NUM_LIT:2> ) ) <EOL> s . append ( '<STR_LIT>' % p ) <EOL> s . append ( indent ( <NUM_LIT:1> ) ) <EOL> s . append ( '<STR_LIT>' % len ( self . ports ) ) <EOL> for p in self . ports : <EOL> s . append ( indent ( <NUM_LIT:2> ) ) <EOL> s . append ( '<STR_LIT>' % p [ <NUM_LIT:0> ] . name ) <EOL> s . append ( indent ( <NUM_LIT:3> ) ) <EOL> s . append ( '<STR_LIT>' % len ( p [ <NUM_LIT:1> ] ) ) <EOL> for m in p [ <NUM_LIT:1> ] : <EOL> sig = [ ] <EOL> s . append ( indent ( <NUM_LIT:4> ) ) <EOL> sig . append ( m [ <NUM_LIT:0> ] ) <EOL> sig . append ( '<STR_LIT:(>' ) <EOL> for p in m [ <NUM_LIT:1> ] : <EOL> sig . append ( self . xlate ( p [ <NUM_LIT:1> ] ) ) <EOL> sig . append ( '<STR_LIT:U+0020>' ) <EOL> sig . append ( p [ <NUM_LIT:0> ] ) <EOL> sig . append ( '<STR_LIT:U+002CU+0020>' ) <EOL> sig . append ( '<STR_LIT:)>' ) <EOL> try : <EOL> s . append ( '<STR_LIT>' . join ( sig ) ) <EOL> except : <EOL> pass <EOL> s . append ( indent ( <NUM_LIT:3> ) ) <EOL> s . append ( '<STR_LIT>' % len ( self . types ) ) <EOL> for t in self . types : <EOL> s . append ( indent ( <NUM_LIT:4> ) ) <EOL> s . append ( self . xlate ( t [ <NUM_LIT:0> ] ) ) <EOL> s . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( s ) <EOL> def __str__ ( self ) : <EOL> return unicode ( self ) . encode ( '<STR_LIT:utf-8>' ) <EOL> def __unicode__ ( self ) : <EOL> try : <EOL> return self . description ( ) <EOL> except Exception , e : <EOL> log . exception ( e ) <EOL> return tostr ( e ) </s>
