signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def link(self, other):
|
p = other.__pts__<EOL>return self.properties.link(p)<EOL>
|
Link (associate) this object with anI{other} properties object
to create a network of properties. Links are bidirectional.
@param other: The object to link.
@type other: L{Properties}
@return: self
@rtype: L{Properties}
|
f9693:c7:m3
|
def unlink(self, other):
|
p = other.__pts__<EOL>return self.properties.unlink(p)<EOL>
|
Unlink (disassociate) the specified properties object.
@param other: The object to unlink.
@type other: L{Properties}
@return: self
@rtype: L{Properties}
|
f9693:c7:m4
|
def xml(self):
|
root = Element('<STR_LIT>', ns=wssens)<EOL>root.set('<STR_LIT>', str(self.mustUnderstand).lower())<EOL>for t in self.tokens:<EOL><INDENT>root.append(t.xml())<EOL><DEDENT>return root<EOL>
|
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
|
f9694:c0:m1
|
def __init__(self, username=None, password=None):
|
Token.__init__(self)<EOL>self.username = username<EOL>self.password = password<EOL>self.nonce = None<EOL>self.created = None<EOL>
|
@param username: A username.
@type username: str
@param password: A password.
@type password: str
|
f9694:c2:m0
|
def setnonce(self, text=None):
|
if text is None:<EOL><INDENT>s = []<EOL>s.append(self.username)<EOL>s.append(self.password)<EOL>s.append(Token.sysdate())<EOL>m = md5()<EOL>m.update('<STR_LIT::>'.join(s).encode("<STR_LIT:utf-8>"))<EOL>self.nonce = m.hexdigest()<EOL><DEDENT>else:<EOL><INDENT>self.nonce = text<EOL><DEDENT>
|
Set I{nonce} which is arbitraty set of bytes to prevent
reply attacks.
@param text: The nonce text value.
Generated when I{None}.
@type text: str
|
f9694:c2:m1
|
def setcreated(self, dt=None):
|
if dt is None:<EOL><INDENT>self.created = Token.utc()<EOL><DEDENT>else:<EOL><INDENT>self.created = dt<EOL><DEDENT>
|
Set I{created}.
@param dt: The created date & time.
Set as datetime.utc() when I{None}.
@type dt: L{datetime}
|
f9694:c2:m2
|
def xml(self):
|
root = Element('<STR_LIT>', ns=wssens)<EOL>u = Element('<STR_LIT>', ns=wssens)<EOL>u.setText(self.username)<EOL>root.append(u)<EOL>p = Element('<STR_LIT>', ns=wssens)<EOL>p.setText(self.password)<EOL>root.append(p)<EOL>if self.nonce is not None:<EOL><INDENT>n = Element('<STR_LIT>', ns=wssens)<EOL>n.setText(self.nonce)<EOL>root.append(n)<EOL><DEDENT>if self.created is not None:<EOL><INDENT>n = Element('<STR_LIT>', ns=wsuns)<EOL>n.setText(str(DateTime(self.created)))<EOL>root.append(n)<EOL><DEDENT>return root<EOL>
|
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
|
f9694:c2:m3
|
def __init__(self, validity=<NUM_LIT>):
|
Token.__init__(self)<EOL>self.created = Token.utc()<EOL>self.expires = self.created + timedelta(seconds=validity)<EOL>
|
@param validity: The time in seconds.
@type validity: int
|
f9694:c3:m0
|
def __init__(self, url, **kwargs):
|
client = Client(url, **kwargs)<EOL>self.__client__ = client<EOL>
|
@param url: The URL for the WSDL.
@type url: str
@param kwargs: keyword arguments.
@keyword faults: Raise faults raised by server (default:True),
else return tuple from service method invocation as
(http code, object).
@type faults: boolean
@keyword proxy: An http proxy to be specified on requests (default:{}).
The proxy is defined as {protocol:proxy,}
@type proxy: dict
|
f9695:c0:m0
|
def get_instance(self, name):
|
return self.__client__.factory.create(name)<EOL>
|
Get an instance of a WSDL type by name
@param name: The name of a type defined in the WSDL.
@type name: str
@return: An instance on success, else None
@rtype: L{sudsobject.Object}
|
f9695:c0:m1
|
def get_enum(self, name):
|
return self.__client__.factory.create(name)<EOL>
|
Get an instance of an enumeration defined in the WSDL by name.
@param name: The name of a enumeration defined in the WSDL.
@type name: str
@return: An instance on success, else None
@rtype: L{sudsobject.Object}
|
f9695:c0:m2
|
def __init__(self, wsdl):
|
self.wsdl = wsdl<EOL>self.multiref = MultiRef()<EOL>
|
@param wsdl: A wsdl.
@type wsdl: L{wsdl.Definitions}
|
f9696:c0:m0
|
def unmarshaller(self, typed=True):
|
if typed:<EOL><INDENT>return UmxTyped(self.schema())<EOL><DEDENT>else:<EOL><INDENT>return UmxBasic()<EOL><DEDENT>
|
Get the appropriate XML decoder.
@return: Either the (basic|typed) unmarshaller.
@rtype: L{UmxTyped}
|
f9696:c0:m3
|
def marshaller(self):
|
return MxLiteral(self.schema(), self.options().xstq)<EOL>
|
Get the appropriate XML encoder.
@return: An L{MxLiteral} marshaller.
@rtype: L{MxLiteral}
|
f9696:c0:m4
|
def param_defs(self, method):
|
raise Exception('<STR_LIT>')<EOL>
|
Get parameter definitions.
Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
@param method: A service method.
@type method: I{service.Method}
@return: A collection of parameter definitions
@rtype: [I{pdef},..]
|
f9696:c0:m5
|
def get_message(self, method, args, kwargs):
|
content = self.headercontent(method)<EOL>header = self.header(content)<EOL>content = self.bodycontent(method, args, kwargs)<EOL>body = self.body(content)<EOL>env = self.envelope(header, body)<EOL>if self.options().prefixes:<EOL><INDENT>body.normalizePrefixes()<EOL>env.promotePrefixes()<EOL><DEDENT>else:<EOL><INDENT>env.refitPrefixes()<EOL><DEDENT>return Document(env)<EOL>
|
Get the soap message for the specified method, args and soapheaders.
This is the entry point for creating the outbound soap message.
@param method: The method being invoked.
@type method: I{service.Method}
@param args: A list of args for the method invoked.
@type args: list
@param kwargs: Named (keyword) args for the method invoked.
@type kwargs: dict
@return: The soap envelope.
@rtype: L{Document}
|
f9696:c0:m6
|
def get_reply(self, method, reply):
|
reply = self.replyfilter(reply)<EOL>sax = Parser()<EOL>replyroot = sax.parse(string=reply)<EOL>plugins = PluginContainer(self.options().plugins)<EOL>plugins.message.parsed(reply=replyroot)<EOL>soapenv = replyroot.getChild('<STR_LIT>')<EOL>soapenv.promotePrefixes()<EOL>soapbody = soapenv.getChild('<STR_LIT>')<EOL>self.detect_fault(soapbody)<EOL>soapbody = self.multiref.process(soapbody)<EOL>nodes = self.replycontent(method, soapbody)<EOL>rtypes = self.returned_types(method)<EOL>if len(rtypes) > <NUM_LIT:1>:<EOL><INDENT>result = self.replycomposite(rtypes, nodes)<EOL>return (replyroot, result)<EOL><DEDENT>if len(rtypes) == <NUM_LIT:1>:<EOL><INDENT>if rtypes[<NUM_LIT:0>].unbounded():<EOL><INDENT>result = self.replylist(rtypes[<NUM_LIT:0>], nodes)<EOL>return (replyroot, result)<EOL><DEDENT>if len(nodes):<EOL><INDENT>unmarshaller = self.unmarshaller()<EOL>resolved = rtypes[<NUM_LIT:0>].resolve(nobuiltin=True)<EOL>result = unmarshaller.process(nodes[<NUM_LIT:0>], resolved)<EOL>return (replyroot, result)<EOL><DEDENT><DEDENT>return (replyroot, None)<EOL>
|
Process the I{reply} for the specified I{method} by sax parsing the
I{reply} and then unmarshalling into python object(s).
@param method: The name of the invoked method.
@type method: str
@param reply: The reply XML received after invoking the specified
method.
@type reply: str
@return: The unmarshalled reply. The returned value is an L{Object}
for a I{list} depending on whether the service returns a single
object or a collection.
@rtype: tuple ( L{Element}, L{Object} )
|
f9696:c0:m7
|
def detect_fault(self, body):
|
fault = body.getChild('<STR_LIT>', envns)<EOL>if fault is None:<EOL><INDENT>return<EOL><DEDENT>unmarshaller = self.unmarshaller(False)<EOL>p = unmarshaller.process(fault)<EOL>if self.options().faults:<EOL><INDENT>raise WebFault(p, fault)<EOL><DEDENT>return self<EOL>
|
Detect I{hidden} soapenv:Fault element in the soap body.
@param body: The soap envelope body.
@type body: L{Element}
@raise WebFault: When found.
|
f9696:c0:m8
|
def replylist(self, rt, nodes):
|
result = []<EOL>resolved = rt.resolve(nobuiltin=True)<EOL>unmarshaller = self.unmarshaller()<EOL>for node in nodes:<EOL><INDENT>sobject = unmarshaller.process(node, resolved)<EOL>result.append(sobject)<EOL><DEDENT>return result<EOL>
|
Construct a I{list} reply. This method is called when it has been
detected
that the reply is a list.
@param rt: The return I{type}.
@type rt: L{suds.xsd.sxbase.SchemaObject}
@param nodes: A collection of XML nodes.
@type nodes: [L{Element},...]
@return: A list of I{unmarshalled} objects.
@rtype: [L{Object},...]
|
f9696:c0:m9
|
def replycomposite(self, rtypes, nodes):
|
dictionary = {}<EOL>for rt in rtypes:<EOL><INDENT>dictionary[rt.name] = rt<EOL><DEDENT>unmarshaller = self.unmarshaller()<EOL>composite = Factory.object('<STR_LIT>')<EOL>for node in nodes:<EOL><INDENT>tag = node.name<EOL>rt = dictionary.get(tag, None)<EOL>if rt is None:<EOL><INDENT>if node.get('<STR_LIT:id>') is None:<EOL><INDENT>raise Exception('<STR_LIT>' % tag)<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>resolved = rt.resolve(nobuiltin=True)<EOL>sobject = unmarshaller.process(node, resolved)<EOL>value = getattr(composite, tag, None)<EOL>if value is None:<EOL><INDENT>if rt.unbounded():<EOL><INDENT>value = []<EOL>setattr(composite, tag, value)<EOL>value.append(sobject)<EOL><DEDENT>else:<EOL><INDENT>setattr(composite, tag, sobject)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not isinstance(value, list):<EOL><INDENT>value = [value, ]<EOL>setattr(composite, tag, value)<EOL><DEDENT>value.append(sobject)<EOL><DEDENT><DEDENT>return composite<EOL>
|
Construct a I{composite} reply. This method is called when it has been
detected that the reply has multiple root nodes.
@param rtypes: A list of known return I{types}.
@type rtypes: [L{suds.xsd.sxbase.SchemaObject},...]
@param nodes: A collection of XML nodes.
@type nodes: [L{Element},...]
@return: The I{unmarshalled} composite object.
@rtype: L{Object},...
|
f9696:c0:m10
|
def get_fault(self, reply):
|
reply = self.replyfilter(reply)<EOL>sax = Parser()<EOL>faultroot = sax.parse(string=reply)<EOL>soapenv = faultroot.getChild('<STR_LIT>')<EOL>soapbody = soapenv.getChild('<STR_LIT>')<EOL>fault = soapbody.getChild('<STR_LIT>')<EOL>unmarshaller = self.unmarshaller(False)<EOL>p = unmarshaller.process(fault)<EOL>if self.options().faults:<EOL><INDENT>raise WebFault(p, faultroot)<EOL><DEDENT>return (faultroot, p.detail)<EOL>
|
Extract the fault from the specified soap reply. If I{faults} is True,
an exception is raised. Otherwise, the I{unmarshalled} fault L{Object}
is returned. This method is called when the server raises a
I{web fault}.
@param reply: A soap reply message.
@type reply: str
@return: A fault object.
@rtype: tuple ( L{Element}, L{Object} )
|
f9696:c0:m11
|
def mkparam(self, method, pdef, object):
|
marshaller = self.marshaller()<EOL>content =Content(tag=pdef[<NUM_LIT:0>],<EOL>value=object,<EOL>type=pdef[<NUM_LIT:1>],<EOL>real=pdef[<NUM_LIT:1>].resolve())<EOL>return marshaller.process(content)<EOL>
|
Builds a parameter for the specified I{method} using the parameter
definition (pdef) and the specified value (object).
@param method: A method name.
@type method: str
@param pdef: A parameter definition.
@type pdef: tuple: (I{name}, L{xsd.sxbase.SchemaObject})
@param object: The parameter value.
@type object: any
@return: The parameter fragment.
@rtype: L{Element}
|
f9696:c0:m12
|
def mkheader(self, method, hdef, object):
|
marshaller = self.marshaller()<EOL>if isinstance(object, (list, tuple)):<EOL><INDENT>tags = []<EOL>for item in object:<EOL><INDENT>tags.append(self.mkheader(method, hdef, item))<EOL><DEDENT>return tags<EOL><DEDENT>content = Content(tag=hdef[<NUM_LIT:0>], value=object, type=hdef[<NUM_LIT:1>])<EOL>return marshaller.process(content)<EOL>
|
Builds a soapheader for the specified I{method} using the header
definition (hdef) and the specified value (object).
@param method: A method name.
@type method: str
@param hdef: A header definition.
@type hdef: tuple: (I{name}, L{xsd.sxbase.SchemaObject})
@param object: The header value.
@type object: any
@return: The parameter fragment.
@rtype: L{Element}
|
f9696:c0:m13
|
def envelope(self, header, body):
|
env = Element('<STR_LIT>', ns=envns)<EOL>env.addPrefix(Namespace.xsins[<NUM_LIT:0>], Namespace.xsins[<NUM_LIT:1>])<EOL>env.append(header)<EOL>env.append(body)<EOL>return env<EOL>
|
Build the B{<Envelope/>} for an soap outbound message.
@param header: The soap message B{header}.
@type header: L{Element}
@param body: The soap message B{body}.
@type body: L{Element}
@return: The soap envelope containing the body and header.
@rtype: L{Element}
|
f9696:c0:m14
|
def header(self, content):
|
header = Element('<STR_LIT>', ns=envns)<EOL>header.append(content)<EOL>return header<EOL>
|
Build the B{<Body/>} for an soap outbound message.
@param content: The header content.
@type content: L{Element}
@return: the soap body fragment.
@rtype: L{Element}
|
f9696:c0:m15
|
def bodycontent(self, method, args, kwargs):
|
raise Exception('<STR_LIT>')<EOL>
|
Get the content for the soap I{body} node.
@param method: A service method.
@type method: I{service.Method}
@param args: method parameter values
@type args: list
@param kwargs: Named (keyword) args for the method invoked.
@type kwargs: dict
@return: The xml content for the <body/>
@rtype: [L{Element},..]
|
f9696:c0:m16
|
def headercontent(self, method):
|
n = <NUM_LIT:0><EOL>content = []<EOL>wsse = self.options().wsse<EOL>if wsse is not None:<EOL><INDENT>content.append(wsse.xml())<EOL><DEDENT>headers = self.options().soapheaders<EOL>if not isinstance(headers, (tuple, list, dict)):<EOL><INDENT>headers = (headers,)<EOL><DEDENT>if len(headers) == <NUM_LIT:0>:<EOL><INDENT>return content<EOL><DEDENT>pts = self.headpart_types(method)<EOL>if isinstance(headers, (tuple, list)):<EOL><INDENT>for header in headers:<EOL><INDENT>if isinstance(header, Element):<EOL><INDENT>content.append(deepcopy(header))<EOL>continue<EOL><DEDENT>if len(pts) == n:<EOL><INDENT>break<EOL><DEDENT>h = self.mkheader(method, pts[n], header)<EOL>ns = pts[n][<NUM_LIT:1>].namespace('<STR_LIT>')<EOL>h.setPrefix(ns[<NUM_LIT:0>], ns[<NUM_LIT:1>])<EOL>content.append(h)<EOL>n += <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>for pt in pts:<EOL><INDENT>header = headers.get(pt[<NUM_LIT:0>])<EOL>if header is None:<EOL><INDENT>continue<EOL><DEDENT>h = self.mkheader(method, pt, header)<EOL>ns = pt[<NUM_LIT:1>].namespace('<STR_LIT>')<EOL>h.setPrefix(ns[<NUM_LIT:0>], ns[<NUM_LIT:1>])<EOL>content.append(h)<EOL><DEDENT><DEDENT>return content<EOL>
|
Get the content for the soap I{Header} node.
@param method: A service method.
@type method: I{service.Method}
@return: The xml content for the <body/>
@rtype: [L{Element},..]
|
f9696:c0:m17
|
def replycontent(self, method, body):
|
raise Exception('<STR_LIT>')<EOL>
|
Get the reply body content.
@param method: A service method.
@type method: I{service.Method}
@param body: The soap body
@type body: L{Element}
@return: the body content
@rtype: [L{Element},...]
|
f9696:c0:m18
|
def body(self, content):
|
body = Element('<STR_LIT>', ns=envns)<EOL>body.append(content)<EOL>return body<EOL>
|
Build the B{<Body/>} for an soap outbound message.
@param content: The body content.
@type content: L{Element}
@return: the soap body fragment.
@rtype: L{Element}
|
f9696:c0:m19
|
def bodypart_types(self, method, input=True):
|
result = []<EOL>if input:<EOL><INDENT>parts = method.soap.input.body.parts<EOL><DEDENT>else:<EOL><INDENT>parts = method.soap.output.body.parts<EOL><DEDENT>for p in parts:<EOL><INDENT>if p.element is not None:<EOL><INDENT>query = ElementQuery(p.element)<EOL><DEDENT>else:<EOL><INDENT>query = TypeQuery(p.type)<EOL><DEDENT>pt = query.execute(self.schema())<EOL>if pt is None:<EOL><INDENT>raise TypeNotFound(query.ref)<EOL><DEDENT>if p.type is not None:<EOL><INDENT>pt = PartElement(p.name, pt)<EOL><DEDENT>if input:<EOL><INDENT>if pt.name is None:<EOL><INDENT>result.append((p.name, pt))<EOL><DEDENT>else:<EOL><INDENT>result.append((pt.name, pt))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result.append(pt)<EOL><DEDENT><DEDENT>return result<EOL>
|
Get a list of I{parameter definitions} (pdef) defined for the specified
method.
Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
@param method: A service method.
@type method: I{service.Method}
@param input: Defines input/output message.
@type input: boolean
@return: A list of parameter definitions
@rtype: [I{pdef},]
|
f9696:c0:m20
|
def headpart_types(self, method, input=True):
|
result = []<EOL>if input:<EOL><INDENT>headers = method.soap.input.headers<EOL><DEDENT>else:<EOL><INDENT>headers = method.soap.output.headers<EOL><DEDENT>for header in headers:<EOL><INDENT>part = header.part<EOL>if part.element is not None:<EOL><INDENT>query = ElementQuery(part.element)<EOL><DEDENT>else:<EOL><INDENT>query = TypeQuery(part.type)<EOL><DEDENT>pt = query.execute(self.schema())<EOL>if pt is None:<EOL><INDENT>raise TypeNotFound(query.ref)<EOL><DEDENT>if part.type is not None:<EOL><INDENT>pt = PartElement(part.name, pt)<EOL><DEDENT>if input:<EOL><INDENT>if pt.name is None:<EOL><INDENT>result.append((part.name, pt))<EOL><DEDENT>else:<EOL><INDENT>result.append((pt.name, pt))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>result.append(pt)<EOL><DEDENT><DEDENT>return result<EOL>
|
Get a list of I{parameter definitions} (pdef) defined for the specified
method.
Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
@param method: A service method.
@type method: I{service.Method}
@param input: Defines input/output message.
@type input: boolean
@return: A list of parameter definitions
@rtype: [I{pdef},]
|
f9696:c0:m21
|
def returned_types(self, method):
|
result = []<EOL>for rt in self.bodypart_types(method, input=False):<EOL><INDENT>result.append(rt)<EOL><DEDENT>return result<EOL>
|
Get the L{xsd.sxbase.SchemaObject} returned by the I{method}.
@param method: A service method.
@type method: I{service.Method}
@return: The name of the type return by the method.
@rtype: [I{rtype},..]
|
f9696:c0:m22
|
def __init__(self, name, resolved):
|
root = Element('<STR_LIT>', ns=Namespace.xsdns)<EOL>SchemaElement.__init__(self, resolved.schema, root)<EOL>self.__resolved = resolved<EOL>self.name = name<EOL>self.form_qualified = False<EOL>
|
@param name: The part name.
@type name: str
@param resolved: The part type.
@type resolved: L{suds.xsd.sxbase.SchemaObject}
|
f9696:c1:m0
|
def document(self, wrapper):
|
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>
|
Get the document root. For I{document/literal}, this is the
name of the wrapper element qualifed by the schema tns.
@param wrapper: The method name.
@type wrapper: L{xsd.sxbase.SchemaObject}
@return: A root element.
@rtype: L{Element}
|
f9697:c0:m2
|
def bychoice(self, ancestry):
|
for x in ancestry:<EOL><INDENT>if x.choice():<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>
|
The ancestry contains a <choice/>
@param ancestry: A list of ancestors.
@type ancestry: list
@return: True if contains <choice/>
@rtype: boolean
|
f9697:c0:m6
|
def method(self, method):
|
ns = method.soap.input.body.namespace<EOL>if ns[<NUM_LIT:0>] is None:<EOL><INDENT>ns = ('<STR_LIT>', ns[<NUM_LIT:1>])<EOL><DEDENT>method = Element(method.name, ns=ns)<EOL>return method<EOL>
|
Get the document root. For I{rpc/(literal|encoded)}, this is the
name of the method qualifed by the schema tns.
@param method: A service method.
@type method: I{service.Method}
@return: A root element.
@rtype: L{Element}
|
f9698:c0:m4
|
def unmarshaller(self, typed=True):
|
if typed:<EOL><INDENT>return UmxEncoded(self.schema())<EOL><DEDENT>else:<EOL><INDENT>return RPC.unmarshaller(self, typed)<EOL><DEDENT>
|
Get the appropriate XML decoder.
@return: Either the (basic|typed) unmarshaller.
@rtype: L{UmxTyped}
|
f9698:c1:m1
|
def process(self, body):
|
self.nodes = []<EOL>self.catalog = {}<EOL>self.build_catalog(body)<EOL>self.update(body)<EOL>body.children = self.nodes<EOL>return body<EOL>
|
Process the specified soap envelope body and replace I{multiref} node
references with the contents of the referenced node.
@param body: A soap envelope body node.
@type body: L{Element}
@return: The processed I{body}
@rtype: L{Element}
|
f9700:c0:m1
|
def update(self, node):
|
self.replace_references(node)<EOL>for c in node.children:<EOL><INDENT>self.update(c)<EOL><DEDENT>return node<EOL>
|
Update the specified I{node} by replacing the I{multiref} references
with the contents of the referenced nodes and remove the I{href}
attribute.
@param node: A node to update.
@type node: L{Element}
@return: The updated node
@rtype: L{Element}
|
f9700:c0:m2
|
def replace_references(self, node):
|
href = node.getAttribute('<STR_LIT>')<EOL>if href is None:<EOL><INDENT>return<EOL><DEDENT>id = href.getValue()<EOL>ref = self.catalog.get(id)<EOL>if ref is None:<EOL><INDENT>log.error('<STR_LIT>', id)<EOL>return<EOL><DEDENT>node.append(ref.children)<EOL>node.setText(ref.getText())<EOL>for a in ref.attributes:<EOL><INDENT>if a.name != '<STR_LIT:id>':<EOL><INDENT>node.append(a)<EOL><DEDENT><DEDENT>node.remove(href)<EOL>
|
Replacing the I{multiref} references with the contents of the
referenced nodes and remove the I{href} attribute. Warning: since
the I{ref} is not cloned,
@param node: A node to update.
@type node: L{Element}
|
f9700:c0:m3
|
def build_catalog(self, body):
|
for child in body.children:<EOL><INDENT>if self.soaproot(child):<EOL><INDENT>self.nodes.append(child)<EOL><DEDENT>id = child.get('<STR_LIT:id>')<EOL>if id is None:<EOL><INDENT>continue<EOL><DEDENT>key = '<STR_LIT>' % id<EOL>self.catalog[key] = child<EOL><DEDENT>
|
Create the I{catalog} of multiref nodes by id and the list of
non-multiref nodes.
@param body: A soap envelope body node.
@type body: L{Element}
|
f9700:c0:m4
|
def soaproot(self, node):
|
root = node.getAttribute('<STR_LIT:root>', ns=soapenc)<EOL>if root is None:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return root.value == '<STR_LIT:1>'<EOL><DEDENT>
|
Get whether the specified I{node} is a soap encoded root.
This is determined by examining @soapenc:root='1'.
The node is considered to be a root when the attribute
is not specified.
@param node: A node to evaluate.
@type node: L{Element}
@return: True if a soap encoded root.
@rtype: bool
|
f9700:c0:m5
|
def __init__(self, root, definitions=None):
|
Object.__init__(self)<EOL>self.root = root<EOL>pmd = Metadata()<EOL>pmd.excludes = ['<STR_LIT:root>']<EOL>pmd.wrappers = dict(qname=repr)<EOL>self.__metadata__.__print__ = pmd<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c0:m0
|
def resolve(self, definitions):
|
pass<EOL>
|
Resolve named references to other WSDL objects.
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c0:m1
|
def __init__(self, root, definitions):
|
WObject.__init__(self, root, definitions)<EOL>self.name = root.get('<STR_LIT:name>')<EOL>self.qname = (self.name, definitions.tns[<NUM_LIT:1>])<EOL>pmd = self.__metadata__.__print__<EOL>pmd.wrappers['<STR_LIT>'] = repr<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c1:m0
|
def __init__(self, url, options):
|
log.debug('<STR_LIT>', url)<EOL>reader = DocumentReader(options)<EOL>d = reader.open(url)<EOL>root = d.root()<EOL>WObject.__init__(self, root)<EOL>self.id = objid(self)<EOL>self.options = options<EOL>self.url = url<EOL>self.tns = self.mktns(root)<EOL>self.types = []<EOL>self.schema = None<EOL>self.children = []<EOL>self.imports = []<EOL>self.messages = {}<EOL>self.port_types = {}<EOL>self.bindings = {}<EOL>self.services = []<EOL>self.add_children(self.root)<EOL>self.children.sort()<EOL>pmd = self.__metadata__.__print__<EOL>pmd.excludes.append('<STR_LIT>')<EOL>pmd.excludes.append('<STR_LIT>')<EOL>pmd.wrappers['<STR_LIT>'] = repr<EOL>self.open_imports()<EOL>self.resolve()<EOL>self.build_schema()<EOL>self.set_wrapped()<EOL>for s in self.services:<EOL><INDENT>self.add_methods(s)<EOL><DEDENT>log.debug("<STR_LIT>", url, self)<EOL>
|
@param url: A URL to the WSDL.
@type url: str
@param options: An options dictionary.
@type options: L{options.Options}
|
f9701:c2:m0
|
def mktns(self, root):
|
tns = root.get('<STR_LIT>')<EOL>prefix = root.findPrefix(tns)<EOL>if prefix is None:<EOL><INDENT>log.debug('<STR_LIT>', tns)<EOL>prefix = '<STR_LIT>'<EOL><DEDENT>return (prefix, tns)<EOL>
|
Get/create the target namespace
|
f9701:c2:m1
|
def add_children(self, root):
|
for c in root.getChildren(ns=wsdlns):<EOL><INDENT>child = Factory.create(c, self)<EOL>if child is None:<EOL><INDENT>continue<EOL><DEDENT>self.children.append(child)<EOL>if isinstance(child, Import):<EOL><INDENT>self.imports.append(child)<EOL>continue<EOL><DEDENT>if isinstance(child, Types):<EOL><INDENT>self.types.append(child)<EOL>continue<EOL><DEDENT>if isinstance(child, Message):<EOL><INDENT>self.messages[child.qname] = child<EOL>continue<EOL><DEDENT>if isinstance(child, PortType):<EOL><INDENT>self.port_types[child.qname] = child<EOL>continue<EOL><DEDENT>if isinstance(child, Binding):<EOL><INDENT>self.bindings[child.qname] = child<EOL>continue<EOL><DEDENT>if isinstance(child, Service):<EOL><INDENT>self.services.append(child)<EOL>continue<EOL><DEDENT><DEDENT>
|
Add child objects using the factory
|
f9701:c2:m2
|
def open_imports(self):
|
for imp in self.imports:<EOL><INDENT>imp.load(self)<EOL><DEDENT>
|
Import the I{imported} WSDLs.
|
f9701:c2:m3
|
def resolve(self):
|
for c in self.children:<EOL><INDENT>c.resolve(self)<EOL><DEDENT>
|
Tell all children to resolve themselves
|
f9701:c2:m4
|
def build_schema(self):
|
container = SchemaCollection(self)<EOL>for t in [t for t in self.types if t.local()]:<EOL><INDENT>for root in t.contents():<EOL><INDENT>schema = Schema(root, self.url, self.options, container)<EOL>container.add(schema)<EOL><DEDENT><DEDENT>if not len(container): <EOL><INDENT>root = Element.buildPath(self.root, '<STR_LIT>')<EOL>schema = Schema(root, self.url, self.options, container)<EOL>container.add(schema)<EOL><DEDENT>self.schema = container.load(self.options)<EOL>for s in [t.schema() for t in self.types if t.imported()]:<EOL><INDENT>self.schema.merge(s)<EOL><DEDENT>return self.schema<EOL>
|
Process L{Types} objects and create the schema collection
|
f9701:c2:m5
|
def add_methods(self, service):
|
bindings = {<EOL>'<STR_LIT>': Document(self),<EOL>'<STR_LIT>': RPC(self),<EOL>'<STR_LIT>': Encoded(self)<EOL>}<EOL>for p in service.ports:<EOL><INDENT>binding = p.binding<EOL>ptype = p.binding.type<EOL>operations = p.binding.type.operations.values()<EOL>for name in [op.name for op in operations]:<EOL><INDENT>m = Facade('<STR_LIT>')<EOL>m.name = name<EOL>m.location = p.location<EOL>m.binding = Facade('<STR_LIT>')<EOL>op = binding.operation(name)<EOL>m.soap = op.soap<EOL>key = '<STR_LIT:/>'.join((op.soap.style, op.soap.input.body.use))<EOL>m.binding.input = bindings.get(key)<EOL>key = '<STR_LIT:/>'.join((op.soap.style, op.soap.output.body.use))<EOL>m.binding.output = bindings.get(key)<EOL>op = ptype.operation(name)<EOL>p.methods[name] = m<EOL><DEDENT><DEDENT>
|
Build method view for service
|
f9701:c2:m6
|
def set_wrapped(self):
|
for b in self.bindings.values():<EOL><INDENT>for op in b.operations.values():<EOL><INDENT>for body in (op.soap.input.body, op.soap.output.body):<EOL><INDENT>body.wrapped = False<EOL>if len(body.parts) != <NUM_LIT:1>:<EOL><INDENT>continue<EOL><DEDENT>for p in body.parts:<EOL><INDENT>if p.element is None:<EOL><INDENT>continue<EOL><DEDENT>query = ElementQuery(p.element)<EOL>pt = query.execute(self.schema)<EOL>if pt is None:<EOL><INDENT>raise TypeNotFound(query.ref)<EOL><DEDENT>resolved = pt.resolve()<EOL>if resolved.builtin():<EOL><INDENT>continue<EOL><DEDENT>body.wrapped = True<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
|
set (wrapped|bare) flag on messages
|
f9701:c2:m7
|
def __init__(self, root, definitions):
|
WObject.__init__(self, root, definitions)<EOL>self.location = root.get('<STR_LIT:location>')<EOL>self.ns = root.get('<STR_LIT>')<EOL>self.imported = None<EOL>pmd = self.__metadata__.__print__<EOL>pmd.wrappers['<STR_LIT>'] = repr<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c3:m0
|
def load(self, definitions):
|
url = self.location<EOL>log.debug('<STR_LIT>', url)<EOL>if '<STR_LIT>' not in url:<EOL><INDENT>url = urljoin(definitions.url, url)<EOL><DEDENT>options = definitions.options<EOL>d = Definitions(url, options)<EOL>if d.root.match(Definitions.Tag, wsdlns):<EOL><INDENT>self.import_definitions(definitions, d)<EOL>return<EOL><DEDENT>if d.root.match(Schema.Tag, Namespace.xsdns):<EOL><INDENT>self.import_schema(definitions, d)<EOL>return<EOL><DEDENT>raise Exception('<STR_LIT>' % url)<EOL>
|
Load the object by opening the URL
|
f9701:c3:m1
|
def import_definitions(self, definitions, d):
|
definitions.types += d.types<EOL>definitions.messages.update(d.messages)<EOL>definitions.port_types.update(d.port_types)<EOL>definitions.bindings.update(d.bindings)<EOL>self.imported = d<EOL>log.debug('<STR_LIT>', d)<EOL>
|
import/merge wsdl definitions
|
f9701:c3:m2
|
def import_schema(self, definitions, d):
|
if not len(definitions.types):<EOL><INDENT>types = Types.create(definitions)<EOL>definitions.types.append(types)<EOL><DEDENT>else:<EOL><INDENT>types = definitions.types[-<NUM_LIT:1>]<EOL><DEDENT>types.root.append(d.root)<EOL>log.debug('<STR_LIT>', d.root)<EOL>
|
import schema as <types/> content
|
f9701:c3:m3
|
def __init__(self, root, definitions):
|
WObject.__init__(self, root, definitions)<EOL>self.definitions = definitions<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c4:m1
|
def __init__(self, root, definitions):
|
NamedObject.__init__(self, root, definitions)<EOL>pmd = Metadata()<EOL>pmd.wrappers = dict(element=repr, type=repr)<EOL>self.__metadata__.__print__ = pmd<EOL>tns = definitions.tns<EOL>self.element = self.__getref('<STR_LIT>', tns)<EOL>self.type = self.__getref('<STR_LIT:type>', tns)<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c5:m0
|
def __getref(self, a, tns):
|
s = self.root.get(a)<EOL>if s is None:<EOL><INDENT>return s<EOL><DEDENT>else:<EOL><INDENT>return qualify(s, self.root, tns)<EOL><DEDENT>
|
Get the qualified value of attribute named 'a'.
|
f9701:c5:m1
|
def __init__(self, root, definitions):
|
NamedObject.__init__(self, root, definitions)<EOL>self.parts = []<EOL>for p in root.getChildren('<STR_LIT>'):<EOL><INDENT>part = Part(p, definitions)<EOL>self.parts.append(part)<EOL><DEDENT>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c6:m0
|
def __init__(self, root, definitions):
|
NamedObject.__init__(self, root, definitions)<EOL>self.operations = {}<EOL>for c in root.getChildren('<STR_LIT>'):<EOL><INDENT>op = Facade('<STR_LIT>')<EOL>op.name = c.get('<STR_LIT:name>')<EOL>op.tns = definitions.tns<EOL>input = c.getChild('<STR_LIT:input>')<EOL>if input is None:<EOL><INDENT>op.input = None<EOL><DEDENT>else:<EOL><INDENT>op.input = input.get('<STR_LIT:message>')<EOL><DEDENT>output = c.getChild('<STR_LIT>')<EOL>if output is None:<EOL><INDENT>op.output = None<EOL><DEDENT>else:<EOL><INDENT>op.output = output.get('<STR_LIT:message>')<EOL><DEDENT>faults = []<EOL>for fault in c.getChildren('<STR_LIT>'):<EOL><INDENT>f = Facade('<STR_LIT>')<EOL>f.name = fault.get('<STR_LIT:name>')<EOL>f.message = fault.get('<STR_LIT:message>')<EOL>faults.append(f)<EOL><DEDENT>op.faults = faults<EOL>self.operations[op.name] = op<EOL><DEDENT>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c7:m0
|
def resolve(self, definitions):
|
for op in self.operations.values():<EOL><INDENT>if op.input is None:<EOL><INDENT>op.input = Message(Element('<STR_LIT>'), definitions)<EOL><DEDENT>else:<EOL><INDENT>qref = qualify(op.input, self.root, definitions.tns)<EOL>msg = definitions.messages.get(qref)<EOL>if msg is None:<EOL><INDENT>raise Exception("<STR_LIT>" % op.input)<EOL><DEDENT>else:<EOL><INDENT>op.input = msg<EOL><DEDENT><DEDENT>if op.output is None:<EOL><INDENT>op.output = Message(Element('<STR_LIT>'), definitions)<EOL><DEDENT>else:<EOL><INDENT>qref = qualify(op.output, self.root, definitions.tns)<EOL>msg = definitions.messages.get(qref)<EOL>if msg is None:<EOL><INDENT>raise Exception("<STR_LIT>" % op.output)<EOL><DEDENT>else:<EOL><INDENT>op.output = msg<EOL><DEDENT><DEDENT>for f in op.faults:<EOL><INDENT>qref = qualify(f.message, self.root, definitions.tns)<EOL>msg = definitions.messages.get(qref)<EOL>if msg is None:<EOL><INDENT>raise Exception("<STR_LIT>" % f.message)<EOL><DEDENT>f.message = msg<EOL><DEDENT><DEDENT>
|
Resolve named references to other WSDL objects.
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c7:m1
|
def operation(self, name):
|
try:<EOL><INDENT>return self.operations[name]<EOL><DEDENT>except Exception:<EOL><INDENT>raise MethodNotFound(name)<EOL><DEDENT>
|
Shortcut used to get a contained operation by name.
@param name: An operation name.
@type name: str
@return: The named operation.
@rtype: Operation
@raise L{MethodNotFound}: When not found.
|
f9701:c7:m2
|
def __init__(self, root, definitions):
|
NamedObject.__init__(self, root, definitions)<EOL>self.operations = {}<EOL>self.type = root.get('<STR_LIT:type>')<EOL>sr = self.soaproot()<EOL>if sr is None:<EOL><INDENT>self.soap = None<EOL>log.debug('<STR_LIT>', self.name)<EOL>return<EOL><DEDENT>soap = Facade('<STR_LIT>')<EOL>self.soap = soap<EOL>self.soap.style = sr.get('<STR_LIT>', default='<STR_LIT>')<EOL>self.add_operations(self.root, definitions)<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c8:m0
|
def soaproot(self):
|
for ns in (soapns, soap12ns):<EOL><INDENT>sr = self.root.getChild('<STR_LIT>', ns=ns)<EOL>if sr is not None:<EOL><INDENT>return sr<EOL><DEDENT><DEDENT>return None<EOL>
|
get the soap:binding
|
f9701:c8:m1
|
def add_operations(self, root, definitions):
|
dsop = Element('<STR_LIT>', ns=soapns)<EOL>for c in root.getChildren('<STR_LIT>'):<EOL><INDENT>op = Facade('<STR_LIT>')<EOL>op.name = c.get('<STR_LIT:name>')<EOL>sop = c.getChild('<STR_LIT>', default=dsop)<EOL>soap = Facade('<STR_LIT>')<EOL>soap.action = '<STR_LIT>' % sop.get('<STR_LIT>', default='<STR_LIT>')<EOL>soap.style = sop.get('<STR_LIT>', default=self.soap.style)<EOL>soap.input = Facade('<STR_LIT>')<EOL>soap.input.body = Facade('<STR_LIT>')<EOL>soap.input.headers = []<EOL>soap.output = Facade('<STR_LIT>')<EOL>soap.output.body = Facade('<STR_LIT>')<EOL>soap.output.headers = []<EOL>op.soap = soap<EOL>input = c.getChild('<STR_LIT:input>')<EOL>if input is None:<EOL><INDENT>input = Element('<STR_LIT:input>', ns=wsdlns)<EOL><DEDENT>body = input.getChild('<STR_LIT:body>')<EOL>self.body(definitions, soap.input.body, body)<EOL>for header in input.getChildren('<STR_LIT>'):<EOL><INDENT>self.header(definitions, soap.input, header)<EOL><DEDENT>output = c.getChild('<STR_LIT>')<EOL>if output is None:<EOL><INDENT>output = Element('<STR_LIT>', ns=wsdlns)<EOL><DEDENT>body = output.getChild('<STR_LIT:body>')<EOL>self.body(definitions, soap.output.body, body)<EOL>for header in output.getChildren('<STR_LIT>'):<EOL><INDENT>self.header(definitions, soap.output, header)<EOL><DEDENT>faults = []<EOL>for fault in c.getChildren('<STR_LIT>'):<EOL><INDENT>sf = fault.getChild('<STR_LIT>')<EOL>if sf is None:<EOL><INDENT>continue<EOL><DEDENT>fn = fault.get('<STR_LIT:name>')<EOL>f = Facade('<STR_LIT>')<EOL>f.name = sf.get('<STR_LIT:name>', default=fn)<EOL>f.use = sf.get('<STR_LIT>', default='<STR_LIT>')<EOL>faults.append(f)<EOL><DEDENT>soap.faults = faults<EOL>self.operations[op.name] = op<EOL><DEDENT>
|
Add <operation/> children
|
f9701:c8:m2
|
def body(self, definitions, body, root):
|
if root is None:<EOL><INDENT>body.use = '<STR_LIT>'<EOL>body.namespace = definitions.tns<EOL>body.parts = ()<EOL>return<EOL><DEDENT>parts = root.get('<STR_LIT>')<EOL>if parts is None:<EOL><INDENT>body.parts = ()<EOL><DEDENT>else:<EOL><INDENT>body.parts = re.split('<STR_LIT>', parts)<EOL><DEDENT>body.use = root.get('<STR_LIT>', default='<STR_LIT>')<EOL>ns = root.get('<STR_LIT>')<EOL>if ns is None:<EOL><INDENT>body.namespace = definitions.tns<EOL><DEDENT>else:<EOL><INDENT>prefix = root.findPrefix(ns, '<STR_LIT>')<EOL>body.namespace = (prefix, ns)<EOL><DEDENT>
|
add the input/output body properties
|
f9701:c8:m3
|
def header(self, definitions, parent, root):
|
if root is None:<EOL><INDENT>return<EOL><DEDENT>header = Facade('<STR_LIT>')<EOL>parent.headers.append(header)<EOL>header.use = root.get('<STR_LIT>', default='<STR_LIT>')<EOL>ns = root.get('<STR_LIT>')<EOL>if ns is None:<EOL><INDENT>header.namespace = definitions.tns<EOL><DEDENT>else:<EOL><INDENT>prefix = root.findPrefix(ns, '<STR_LIT>')<EOL>header.namespace = (prefix, ns)<EOL><DEDENT>msg = root.get('<STR_LIT:message>')<EOL>if msg is not None:<EOL><INDENT>header.message = msg<EOL><DEDENT>part = root.get('<STR_LIT>')<EOL>if part is not None:<EOL><INDENT>header.part = part<EOL><DEDENT>
|
add the input/output header properties
|
f9701:c8:m4
|
def resolve(self, definitions):
|
self.resolveport(definitions)<EOL>for op in self.operations.values():<EOL><INDENT>self.resolvesoapbody(definitions, op)<EOL>self.resolveheaders(definitions, op)<EOL>self.resolvefaults(definitions, op)<EOL><DEDENT>
|
Resolve named references to other WSDL objects. This includes
cross-linking information (from) the portType (to) the I{soap}
protocol information on the binding for each operation.
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c8:m5
|
def resolveport(self, definitions):
|
ref = qualify(self.type, self.root, definitions.tns)<EOL>port_type = definitions.port_types.get(ref)<EOL>if port_type is None:<EOL><INDENT>raise Exception("<STR_LIT>" % self.type)<EOL><DEDENT>else:<EOL><INDENT>self.type = port_type<EOL><DEDENT>
|
Resolve port_type reference.
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c8:m6
|
def resolvesoapbody(self, definitions, op):
|
ptop = self.type.operation(op.name)<EOL>if ptop is None:<EOL><INDENT>raise Exception("<STR_LIT>" % op.name)<EOL><DEDENT>soap = op.soap<EOL>parts = soap.input.body.parts<EOL>if len(parts):<EOL><INDENT>pts = []<EOL>for p in ptop.input.parts:<EOL><INDENT>if p.name in parts:<EOL><INDENT>pts.append(p)<EOL><DEDENT><DEDENT>soap.input.body.parts = pts<EOL><DEDENT>else:<EOL><INDENT>soap.input.body.parts = ptop.input.parts<EOL><DEDENT>parts = soap.output.body.parts<EOL>if len(parts):<EOL><INDENT>pts = []<EOL>for p in ptop.output.parts:<EOL><INDENT>if p.name in parts:<EOL><INDENT>pts.append(p)<EOL><DEDENT><DEDENT>soap.output.body.parts = pts<EOL><DEDENT>else:<EOL><INDENT>soap.output.body.parts = ptop.output.parts<EOL><DEDENT>
|
Resolve soap body I{message} parts by
cross-referencing with operation defined in port type.
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param op: An I{operation} object.
@type op: I{operation}
|
f9701:c8:m7
|
def resolveheaders(self, definitions, op):
|
soap = op.soap<EOL>headers = soap.input.headers + soap.output.headers<EOL>for header in headers:<EOL><INDENT>mn = header.message<EOL>ref = qualify(mn, self.root, definitions.tns)<EOL>message = definitions.messages.get(ref)<EOL>if message is None:<EOL><INDENT>raise Exception("<STR_LIT>" % mn)<EOL><DEDENT>pn = header.part<EOL>for p in message.parts:<EOL><INDENT>if p.name == pn:<EOL><INDENT>header.part = p<EOL>break<EOL><DEDENT><DEDENT>if pn == header.part:<EOL><INDENT>raise Exception("<STR_LIT>" % (ref, pn))<EOL><DEDENT><DEDENT>
|
Resolve soap header I{message} references.
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param op: An I{operation} object.
@type op: I{operation}
|
f9701:c8:m8
|
def resolvefaults(self, definitions, op):
|
ptop = self.type.operation(op.name)<EOL>if ptop is None:<EOL><INDENT>raise Exception("<STR_LIT>" % op.name)<EOL><DEDENT>soap = op.soap<EOL>for fault in soap.faults:<EOL><INDENT>for f in ptop.faults:<EOL><INDENT>if f.name == fault.name:<EOL><INDENT>fault.parts = f.message.parts<EOL>continue<EOL><DEDENT><DEDENT>if hasattr(fault, '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>raise Exception("<STR_LIT>" % (fault.name, self.type.name))<EOL><DEDENT>
|
Resolve soap fault I{message} references by
cross-referencing with operation defined in port type.
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param op: An I{operation} object.
@type op: I{operation}
|
f9701:c8:m9
|
def operation(self, name):
|
try:<EOL><INDENT>return self.operations[name]<EOL><DEDENT>except:<EOL><INDENT>raise MethodNotFound(name)<EOL><DEDENT>
|
Shortcut used to get a contained operation by name.
@param name: An operation name.
@type name: str
@return: The named operation.
@rtype: Operation
@raise L{MethodNotFound}: When not found.
|
f9701:c8:m10
|
def __init__(self, root, definitions, service):
|
NamedObject.__init__(self, root, definitions)<EOL>self.__service = service<EOL>self.binding = root.get('<STR_LIT>')<EOL>address = root.getChild('<STR_LIT:address>')<EOL>if address is None:<EOL><INDENT>self.location = None<EOL><DEDENT>else:<EOL><INDENT>self.location = address.get('<STR_LIT:location>').encode('<STR_LIT:utf-8>')<EOL><DEDENT>self.methods = {}<EOL>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
@param service: A service object.
@type service: L{Service}
|
f9701:c9:m0
|
def method(self, name):
|
return self.methods.get(name)<EOL>
|
Get a method defined in this portType by name.
@param name: A method name.
@type name: str
@return: The requested method object.
@rtype: I{Method}
|
f9701:c9:m1
|
def __init__(self, root, definitions):
|
NamedObject.__init__(self, root, definitions)<EOL>self.ports = []<EOL>for p in root.getChildren('<STR_LIT:port>'):<EOL><INDENT>port = Port(p, definitions, self)<EOL>self.ports.append(port)<EOL><DEDENT>
|
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c10:m0
|
def port(self, name):
|
for p in self.ports:<EOL><INDENT>if p.name == name:<EOL><INDENT>return p<EOL><DEDENT><DEDENT>return None<EOL>
|
Locate a port by name.
@param name: A port name.
@type name: str
@return: The port object.
@rtype: L{Port}
|
f9701:c10:m1
|
def setlocation(self, url, names=None):
|
for p in self.ports:<EOL><INDENT>for m in p.methods.values():<EOL><INDENT>if names is None or m.name in names:<EOL><INDENT>m.location = url<EOL><DEDENT><DEDENT><DEDENT>
|
Override the invocation location (url) for service method.
@param url: A url location.
@type url: A url.
@param names: A list of method names. None=ALL
@type names: [str,..]
|
f9701:c10:m2
|
def resolve(self, definitions):
|
filtered = []<EOL>for p in self.ports:<EOL><INDENT>ref = qualify(p.binding, self.root, definitions.tns)<EOL>binding = definitions.bindings.get(ref)<EOL>if binding is None:<EOL><INDENT>raise Exception("<STR_LIT>" % p.binding)<EOL><DEDENT>if binding.soap is None:<EOL><INDENT>log.debug('<STR_LIT>', binding.name)<EOL>continue<EOL><DEDENT>p.binding = binding<EOL>filtered.append(p)<EOL><DEDENT>self.ports = filtered<EOL>
|
Resolve named references to other WSDL objects.
Ports without soap bindings are discarded.
@param definitions: A definitions object.
@type definitions: L{Definitions}
|
f9701:c10:m3
|
@classmethod<EOL><INDENT>def create(cls, root, definitions):<DEDENT>
|
fn = cls.tags.get(root.name)<EOL>if fn is not None:<EOL><INDENT>return fn(root, definitions)<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
|
Create an object based on the root tag name.
@param root: An XML root element.
@type root: L{Element}
@param definitions: A definitions object.
@type definitions: L{Definitions}
@return: The created object.
@rtype: L{WObject}
|
f9701:c11:m0
|
def __init__(self, options):
|
self.options = options<EOL>self.plugins = PluginContainer(options.plugins)<EOL>
|
@param options: An options object.
@type options: I{Options}
|
f9702:c0:m0
|
def mangle(self, name, x):
|
h = hashlib.md5(name.encode('<STR_LIT:utf8>')).hexdigest()<EOL>return '<STR_LIT>' % (h, x)<EOL>
|
Mangle the name by hashing the I{name} and appending I{x}.
@return: the mangled name.
|
f9702:c0:m1
|
def open(self, url):
|
cache = self.cache()<EOL>id = self.mangle(url, '<STR_LIT>')<EOL>d = cache.get(id)<EOL>if d is None:<EOL><INDENT>d = self.download(url)<EOL>cache.put(id, d)<EOL><DEDENT>self.plugins.document.parsed(url=url, document=d.root())<EOL>return d<EOL>
|
Open an XML document at the specified I{url}.
First, the document attempted to be retrieved from
the I{object cache}. If not found, it is downloaded and
parsed using the SAX parser. The result is added to the
cache for the next open().
@param url: A document url.
@type url: str.
@return: The specified XML document.
@rtype: I{Document}
|
f9702:c1:m0
|
def download(self, url):
|
store = DocumentStore()<EOL>fp = store.open(url)<EOL>if fp is None:<EOL><INDENT>fp = self.options.transport.open(Request(url))<EOL><DEDENT>content = fp.read()<EOL>fp.close()<EOL>ctx = self.plugins.document.loaded(url=url, document=content)<EOL>content = ctx.document<EOL>sax = Parser()<EOL>return sax.parse(string=content)<EOL>
|
Download the docuemnt.
@param url: A document url.
@type url: str.
@return: A file pointer to the docuemnt.
@rtype: file-like
|
f9702:c1:m1
|
def cache(self):
|
if self.options.cachingpolicy == <NUM_LIT:0>:<EOL><INDENT>return self.options.cache<EOL><DEDENT>else:<EOL><INDENT>return NoCache()<EOL><DEDENT>
|
Get the cache.
@return: The I{options} when I{cachingpolicy} = B{0}.
@rtype: L{Cache}
|
f9702:c1:m2
|
def __init__(self, options, fn):
|
Reader.__init__(self, options)<EOL>self.fn = fn<EOL>
|
@param options: An options object.
@type options: I{Options}
@param fn: A factory function (constructor) used to
create the object not found in the cache.
@type fn: I{Constructor}
|
f9702:c2:m0
|
def open(self, url):
|
cache = self.cache()<EOL>id = self.mangle(url, '<STR_LIT>')<EOL>d = cache.get(id)<EOL>if d is None:<EOL><INDENT>d = self.fn(url, self.options)<EOL>cache.put(id, d)<EOL><DEDENT>else:<EOL><INDENT>d.options = self.options<EOL>for imp in d.imports:<EOL><INDENT>imp.imported.options = self.options<EOL><DEDENT><DEDENT>return d<EOL>
|
Open a WSDL at the specified I{url}.
First, the WSDL attempted to be retrieved from
the I{object cache}. After unpickled from the cache, the
I{options} attribute is restored.
If not found, it is downloaded and instantiated using the
I{fn} constructor and added to the cache for the next open().
@param url: A WSDL url.
@type url: str.
@return: The WSDL object.
@rtype: I{Definitions}
|
f9702:c2:m1
|
def cache(self):
|
if self.options.cachingpolicy == <NUM_LIT:1>:<EOL><INDENT>return self.options.cache<EOL><DEDENT>else:<EOL><INDENT>return NoCache()<EOL><DEDENT>
|
Get the cache.
@return: The I{options} when I{cachingpolicy} = B{1}.
@rtype: L{Cache}
|
f9702:c2:m2
|
def parse(self, file=None, string=None):
|
timer = metrics.Timer()<EOL>timer.start()<EOL>sax, handler = self.saxparser()<EOL>if file is not None:<EOL><INDENT>sax.parse(file)<EOL>timer.stop()<EOL>metrics.log.debug('<STR_LIT>', file, timer)<EOL>return handler.nodes[<NUM_LIT:0>]<EOL><DEDENT>if string is not None:<EOL><INDENT>if isinstance(string, str):<EOL><INDENT>string = string.encode()<EOL><DEDENT>parseString(string, handler)<EOL>timer.stop()<EOL>metrics.log.debug('<STR_LIT>', string, timer)<EOL>return handler.nodes[<NUM_LIT:0>]<EOL><DEDENT>
|
SAX parse XML text.
@param file: Parse a python I{file-like} object.
@type file: I{file-like} object.
@param string: Parse string XML.
@type string: str
|
f9704:c1:m1
|
def date_from_match(match_object):
|
year = int(match_object.group('<STR_LIT>'))<EOL>month = int(match_object.group('<STR_LIT>'))<EOL>day = int(match_object.group('<STR_LIT>'))<EOL>return datetime.date(year, month, day)<EOL>
|
Create a date object from a regular expression match.
The regular expression match is expected to be from RE_DATE or RE_DATETIME.
@param match_object: The regular expression match.
@type value: B{re}.I{MatchObject}
@return: A date object.
@rtype: B{datetime}.I{date}
|
f9705:m0
|
def time_from_match(match_object):
|
hour = int(match_object.group('<STR_LIT>'))<EOL>minute = int(match_object.group('<STR_LIT>'))<EOL>second = int(match_object.group('<STR_LIT>'))<EOL>subsecond = match_object.group('<STR_LIT>')<EOL>microsecond = <NUM_LIT:0><EOL>if subsecond is not None:<EOL><INDENT>subsecond_denominator = <NUM_LIT> ** len(subsecond)<EOL>subsecond = int(subsecond)<EOL>microsecond = subsecond * (<NUM_LIT> / subsecond_denominator)<EOL>microsecond = int(round(microsecond))<EOL><DEDENT>return datetime.time(hour, minute, second, microsecond)<EOL>
|
Create a time object from a regular expression match.
The regular expression match is expected to be from RE_TIME or RE_DATETIME.
@param match_object: The regular expression match.
@type value: B{re}.I{MatchObject}
@return: A date object.
@rtype: B{datetime}.I{time}
|
f9705:m1
|
def tzinfo_from_match(match_object):
|
tz_utc = match_object.group('<STR_LIT>')<EOL>tz_sign = match_object.group('<STR_LIT>')<EOL>tz_hour = int(match_object.group('<STR_LIT>') or <NUM_LIT:0>)<EOL>tz_minute = int(match_object.group('<STR_LIT>') or <NUM_LIT:0>)<EOL>tz_second = int(match_object.group('<STR_LIT>') or <NUM_LIT:0>)<EOL>tzinfo = None<EOL>if tz_utc is not None:<EOL><INDENT>tzinfo = UtcTimezone()<EOL><DEDENT>elif tz_sign is not None:<EOL><INDENT>tz_delta = datetime.timedelta(hours=tz_hour,<EOL>minutes=tz_minute,<EOL>seconds=tz_second)<EOL>if tz_delta == datetime.timedelta():<EOL><INDENT>tzinfo = UtcTimezone()<EOL><DEDENT>else:<EOL><INDENT>tz_multiplier = int('<STR_LIT>' % (tz_sign, ))<EOL>tz_delta = tz_multiplier * tz_delta<EOL>tzinfo = FixedOffsetTimezone(tz_delta)<EOL><DEDENT><DEDENT>return tzinfo<EOL>
|
Create a timezone information object from a regular expression match.
The regular expression match is expected to be from RE_DATE, RE_TIME or
RE_DATETIME.
@param match_object: The regular expression match.
@type value: B{re}.I{MatchObject}
@return: A timezone information object.
@rtype: B{datetime}.I{tzinfo}
|
f9705:m2
|
def __init__(self, value):
|
if isinstance(value, datetime.date):<EOL><INDENT>self.value = value<EOL><DEDENT>elif isinstance(value, str):<EOL><INDENT>self.value = self.parse(value)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % (type(value), ))<EOL><DEDENT>
|
Constructor.
@param value: The date value of the object.
@type value: (datetime.date|str)
@raise ValueError: When I{value} is invalid.
|
f9705:c0:m0
|
@staticmethod<EOL><INDENT>def parse(value):<DEDENT>
|
match_result = RE_DATE.match(value)<EOL>if match_result is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % value)<EOL><DEDENT>value = date_from_match(match_result)<EOL>return value<EOL>
|
Parse the string date.
This supports the subset of ISO8601 used by xsd:date, but is lenient
with what is accepted, handling most reasonable syntax.
Any timezone is parsed but ignored because a) it's meaningless without
a time and b) B{datetime}.I{date} does not support a tzinfo property.
@param value: A date string.
@type value: str
@return: A date object.
@rtype: B{datetime}.I{date}
|
f9705:c0:m1
|
def __init__(self, value):
|
if isinstance(value, datetime.time):<EOL><INDENT>self.value = value<EOL><DEDENT>elif isinstance(value, str):<EOL><INDENT>self.value = self.parse(value)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % (type(value), ))<EOL><DEDENT>
|
Constructor.
@param value: The time value of the object.
@type value: (dateime.time|str)
@raise ValueError: When I{value} is invalid.
|
f9705:c1:m0
|
@staticmethod<EOL><INDENT>def parse(value):<DEDENT>
|
match_result = RE_TIME.match(value)<EOL>if match_result is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % (value, ))<EOL><DEDENT>date = time_from_match(match_result)<EOL>tzinfo = tzinfo_from_match(match_result)<EOL>value = date.replace(tzinfo=tzinfo)<EOL>return value<EOL>
|
Parse the string date.
This supports the subset of ISO8601 used by xsd:time, but is lenient
with what is accepted, handling most reasonable syntax.
@param value: A time string.
@type value: str
@return: A time object.
@rtype: B{datetime}.I{time}
|
f9705:c1:m1
|
def __init__(self, value):
|
if isinstance(value, datetime.datetime):<EOL><INDENT>self.value = value<EOL><DEDENT>elif isinstance(value, str):<EOL><INDENT>self.value = self.parse(value)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % type(value))<EOL><DEDENT>
|
Constructor.
@param value: The datetime value of the object.
@type value: (datetime.datetime|str)
@raise ValueError: When I{value} is invalid.
|
f9705:c2:m0
|
@staticmethod<EOL><INDENT>def parse(value):<DEDENT>
|
match_result = RE_DATETIME.match(value)<EOL>if match_result is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % (value, ))<EOL><DEDENT>date = date_from_match(match_result)<EOL>time = time_from_match(match_result)<EOL>tzinfo = tzinfo_from_match(match_result)<EOL>value = datetime.datetime.combine(date, time)<EOL>value = value.replace(tzinfo=tzinfo)<EOL>return value<EOL>
|
Parse the string datetime.
This supports the subset of ISO8601 used by xsd:dateTime, but is
lenient with what is accepted, handling most reasonable syntax.
@param value: A datetime string.
@type value: str
@return: A datetime object.
@rtype: B{datetime}.I{datetime}
|
f9705:c2:m1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.