예제 #1
0
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('UsernameToken', ns=wssens)
     u = Element('Username', ns=wssens)
     u.setText(self.username)
     root.append(u)
     p = Element('Password', ns=wssens)
     p.setText(self.password)
     if self.password_digest:
         p.set("Type", wsdigest)
         p.setText(self.password_digest)
     root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=wssens)
         if self.nonce_has_encoding:
             n.set("EncodingType", nonce_encoding_type)
         n.setText(self.nonce)
         root.append(n)
     if self.created is not None:
         n = Element('Created', ns=wsuns)
         n.setText(str(DateTime(self.created)))
         root.append(n)
     return root
예제 #2
0
    def do_resolve(self, definitions):
        """
        Resolve named references to other WSDL objects.

        @param definitions: A definitions object.
        @type definitions: L{Definitions}

        """
        for op in list(self.operations.values()):
            if op.input is None:
                op.input = Message(Element("no-input"), definitions)
            else:
                qref = qualify(op.input, self.root, definitions.tns)
                msg = definitions.messages.get(qref)
                if msg is None:
                    raise Exception("msg '%s', not-found" % (op.input,))
                op.input = msg
            if op.output is None:
                op.output = Message(Element("no-output"), definitions)
            else:
                qref = qualify(op.output, self.root, definitions.tns)
                msg = definitions.messages.get(qref)
                if msg is None:
                    raise Exception("msg '%s', not-found" % (op.output,))
                op.output = msg
            for f in op.faults:
                qref = qualify(f.message, self.root, definitions.tns)
                msg = definitions.messages.get(qref)
                if msg is None:
                    raise Exception("msg '%s', not-found" % (f.message,))
                f.message = msg
예제 #3
0
 def xml(self):
     root = Element("Timestamp", ns=wsuns)
     created = Element('Created', ns=wsuns)
     created.setText(str(DateTime(self.created)))
     expires = Element('Expires', ns=wsuns)
     expires.setText(str(DateTime(self.expires)))
     root.append(created)
     root.append(expires)
     return root
예제 #4
0
    def node(self, content):
        """
        Create an XML node.

        The XML node is namespace qualified as defined by the corresponding
        schema element.

        """
        ns = content.type.namespace()
        if content.type.form_qualified:
            node = Element(content.tag, ns=ns)
            if ns[0]:
                node.addPrefix(ns[0], ns[1])
        else:
            node = Element(content.tag)
        self.encode(node, content)
        log.debug("created - node:\n%s", node)
        return node
예제 #5
0
파일: sxbase.py 프로젝트: aeibagi/virt-who
    def __init__(self, schema, name):
        """
        @param schema: The containing schema.
        @type schema: L{schema.Schema}

        """
        root = Element(name)
        SchemaObject.__init__(self, schema, root)
        self.name = name
        self.nillable = True
예제 #6
0
 def add_operations(self, root, definitions):
     """Add <operation/> children."""
     dsop = Element("operation", ns=soapns)
     for c in root.getChildren("operation"):
         op = Facade("Operation")
         op.name = c.get("name")
         sop = c.getChild("operation", default=dsop)
         soap = Facade("soap")
         soap.action = '"%s"' % (sop.get("soapAction", default=""),)
         soap.style = sop.get("style", default=self.soap.style)
         soap.input = Facade("Input")
         soap.input.body = Facade("Body")
         soap.input.headers = []
         soap.output = Facade("Output")
         soap.output.body = Facade("Body")
         soap.output.headers = []
         op.soap = soap
         input = c.getChild("input")
         if input is None:
             input = Element("input", ns=wsdlns)
         body = input.getChild("body")
         self.body(definitions, soap.input.body, body)
         for header in input.getChildren("header"):
             self.header(definitions, soap.input, header)
         output = c.getChild("output")
         if output is None:
             output = Element("output", ns=wsdlns)
         body = output.getChild("body")
         self.body(definitions, soap.output.body, body)
         for header in output.getChildren("header"):
             self.header(definitions, soap.output, header)
         faults = []
         for fault in c.getChildren("fault"):
             sf = fault.getChild("fault")
             if sf is None:
                 continue
             fn = fault.get("name")
             f = Facade("Fault")
             f.name = sf.get("name", default=fn)
             f.use = sf.get("use", default="literal")
             faults.append(f)
         soap.faults = faults
         self.operations[op.name] = op
예제 #7
0
 def import_schema(self, definitions, d):
     """Import schema as <types/> content."""
     if not definitions.types:
         root = Element("types", ns=wsdlns)
         definitions.root.insert(root)
         types = Types(root, definitions)
         definitions.types.append(types)
     else:
         types = definitions.types[-1]
     types.root.append(d.root)
     log.debug("imported (XSD):\n%s", d.root)
예제 #8
0
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('Security', ns=wssens)
     root.set('mustUnderstand', str(self.mustUnderstand).lower())
     for t in self.tokens:
         root.append(t.xml())
     return root
예제 #9
0
파일: doctor.py 프로젝트: aeibagi/virt-who
 def add(self, root):
     """
     Add an <xs:import/> to the specified schema root.
     @param root: A schema root.
     @type root: L{Element}
     """
     node = Element('import', ns=self.xsdns)
     node.set('namespace', self.ns)
     if self.location is not None:
         node.set('schemaLocation', self.location)
     log.debug('%s inserted', node)
     root.insert(node)
예제 #10
0
파일: binding.py 프로젝트: aeibagi/virt-who
    def body(self, content):
        """
        Build the B{<Body/>} for a SOAP outbound message.

        @param content: The body content.
        @type content: L{Element}
        @return: The SOAP body fragment.
        @rtype: L{Element}

        """
        body = Element("Body", ns=envns)
        body.append(content)
        return body
예제 #11
0
파일: binding.py 프로젝트: aeibagi/virt-who
    def __init__(self, name, resolved):
        """
        @param name: The part name.
        @type name: str
        @param resolved: The part type.
        @type resolved: L{suds.xsd.sxbase.SchemaObject}

        """
        root = Element("element", ns=Namespace.xsdns)
        SchemaElement.__init__(self, resolved.schema, root)
        self.__resolved = resolved
        self.name = name
        self.form_qualified = False
예제 #12
0
파일: parser.py 프로젝트: aeibagi/virt-who
 def startElement(self, name, attrs):
     top = self.top()
     node = Element(str(name))
     for a in attrs.getNames():
         n = str(a)
         v = str(attrs.getValue(a))
         attribute = Attribute(n, v)
         if self.mapPrefix(node, attribute):
             continue
         node.append(attribute)
     node.charbuffer = []
     top.append(node)
     self.push(node)
예제 #13
0
 def append(self, node):
     """
     Append (set) the document root.
     @param node: A root L{Element} or name used to build
         the document root element.
     @type node: (L{Element}|str|None)
     """
     if isinstance(node, str):
         self.__root = Element(node)
         return
     if isinstance(node, Element):
         self.__root = node
         return
예제 #14
0
파일: binding.py 프로젝트: aeibagi/virt-who
    def header(self, content):
        """
        Build the B{<Body/>} for a SOAP outbound message.

        @param content: The header content.
        @type content: L{Element}
        @return: The SOAP body fragment.
        @rtype: L{Element}

        """
        header = Element("Header", ns=envns)
        header.append(content)
        return header
예제 #15
0
파일: saxenc.py 프로젝트: aeibagi/virt-who
def basic():
    xml = "<a>Me &amp;&amp; &lt;b&gt;my&lt;/b&gt; shadow&apos;s &lt;i&gt;dog&lt;/i&gt; love to &apos;play&apos; and sing &quot;la,la,la&quot;;</a>"
    p = Parser()
    d = p.parse(string=xml)
    a = d.root()
    print 'A(parsed)=\n%s' % a
    assert str(a) == xml
    b = Element('a')
    b.setText(
        'Me &&amp; &lt;b>my</b> shadow\'s <i>dog</i> love to \'play\' and sing "la,la,la";'
    )
    print 'B(encoded)=\n%s' % b
    assert str(b) == xml
    print 'A(text-decoded)=\n%s' % a.getText()
    print 'B(text-decoded)=\n%s' % b.getText()
    assert a.getText() == b.getText()
    print 'test pruning'
    j = Element('A')
    j.set('n', 1)
    j.append(Element('B'))
    print j
    j.prune()
    print j
예제 #16
0
파일: rpc.py 프로젝트: aeibagi/virt-who
    def method(self, method):
        """
        Get the document root. For I{rpc/(literal|encoded)}, this is the name
        of the method qualified by the schema tns.

        @param method: A service method.
        @type method: I{service.Method}
        @return: A root element.
        @rtype: L{Element}

        """
        ns = method.soap.input.body.namespace
        if ns[0] is None:
            ns = ('ns0', ns[1])
        return Element(method.name, ns=ns)
예제 #17
0
    def __create_single_branch(*args):
        """
        Construct a single branch element tree with given element names.

        Returns a list of constructed Element nodes from root to leaf.

        """
        result = []
        parent = None
        for name in args:
            e = Element(name)
            result.append(e)
            if parent is not None:
                parent.append(e)
            parent = e
        return result
예제 #18
0
파일: binding.py 프로젝트: aeibagi/virt-who
    def envelope(self, header, body):
        """
        Build the B{<Envelope/>} for a 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}

        """
        env = Element("Envelope", ns=envns)
        env.addPrefix(Namespace.xsins[0], Namespace.xsins[1])
        env.append(header)
        env.append(body)
        return env
예제 #19
0
파일: doctor.py 프로젝트: aeibagi/virt-who
 def apply(self, root):
     """
     Apply the import (rule) to the specified schema.
     If the schema does not already contain an import for the
     I{namespace} specified here, it is added.
     @param root: A schema root.
     @type root: L{Element}
     """
     if not self.filter.match(root, self.ns):
         return
     if self.exists(root):
         return
     node = Element('import', ns=self.xsdns)
     node.set('namespace', self.ns)
     if self.location is not None:
         node.set('schemaLocation', self.location)
     log.debug('inserting: %s', node)
     root.insert(node)
예제 #20
0
파일: schema.py 프로젝트: aeibagi/virt-who
    def autoblend(self):
        """
        Ensure that all schemas within the collection import each other which
        has a blending effect.

        @return: self
        @rtype: L{SchemaCollection}

        """
        namespaces = list(self.namespaces.keys())
        for s in self.children:
            for ns in namespaces:
                tns = s.root.get("targetNamespace")
                if tns == ns:
                    continue
                for imp in s.root.getChildren("import"):
                    if imp.get("namespace") == ns:
                        continue
                imp = Element("import", ns=Namespace.xsdns)
                imp.set("namespace", ns)
                s.root.append(imp)
        return self
예제 #21
0
 def test_backslash_in_name(self):
     root, a, _, _ = self.__create_single_branch("root", "a", "b", "c")
     b_c = Element("b\\c")
     a.append(b_c)
     result = root.childAtPath("a/b\\c")
     assert result is b_c
예제 #22
0
 def test_missing(self):
     root = Element("root")
     result = root.childAtPath("an invalid path")
     assert result is None
예제 #23
0
def test_init_name(name, expected_prefix, expected_name):
    e = Element(name)
    assert e.prefix == expected_prefix
    assert e.name == expected_name