コード例 #1
0
ファイル: exttype.py プロジェクト: Chalmers-IT/AdHoc
    def xsd(self):
        base = self.xsd_complex_type()
        seq = base.new('sequence')

        for (key, sub) in sorted(self.mandatory.items()):
            if isinstance(sub, tuple):
                typ, desc = ExtType.instance(sub[0]), sub[1]
            else:
                typ, desc = ExtType.instance(sub), None

            x = seq.new("element", name=key, type="myxsd:" + typ.xsd_name())
            if desc:
                x.new('annotation').new('documentation').cdata(XMLNode.escape(desc))

        opt = seq.new('element', name='optionals')
        optseq = opt.new('complexType').new('sequence')
        for (key, sub) in sorted(self.optional.items()):
            if isinstance(sub, tuple):
                typ, desc = ExtType.instance(sub[0]), sub[1]
            else:
                typ, desc = ExtType.instance(sub), None

            elemname = self.capsify(key)
            x = optseq.new("element", name=elemname,
                           type="myxsd:" + typ.xsd_name(),
                           maxOccurs="1", minOccurs="0")
            if desc:
                x.new('annotation').new('documentation').cdata(XMLNode.escape(desc))

        return base
コード例 #2
0
ファイル: exttype.py プロジェクト: fredronnv/AdHoc
    def xsd(self):
        base = self.xsd_complex_type()
        seq = base.new('sequence')

        for (key, sub) in sorted(self.mandatory.items()):
            if isinstance(sub, tuple):
                typ, desc = ExtType.instance(sub[0]), sub[1]
            else:
                typ, desc = ExtType.instance(sub), None

            x = seq.new("element", name=key, type="myxsd:" + typ.xsd_name())
            if desc:
                x.new('annotation').new('documentation').cdata(
                    XMLNode.escape(desc))

        opt = seq.new('element', name='optionals')
        optseq = opt.new('complexType').new('sequence')
        for (key, sub) in sorted(self.optional.items()):
            if isinstance(sub, tuple):
                typ, desc = ExtType.instance(sub[0]), sub[1]
            else:
                typ, desc = ExtType.instance(sub), None

            elemname = self.capsify(key)
            x = optseq.new("element",
                           name=elemname,
                           type="myxsd:" + typ.xsd_name(),
                           maxOccurs="1",
                           minOccurs="0")
            if desc:
                x.new('annotation').new('documentation').cdata(
                    XMLNode.escape(desc))

        return base
コード例 #3
0
        def handler (**args):
            ''' Dynamically created handler for a SmugMug API call'''
        
            defaults = {'method': method,
                        'APIKey': self.api_key}

            for key, default_value in defaults.iteritems():
                if key in args:
                    del args[key]

            new_args = {}
            for key in args.iterkeys():
                if args[key] is not None:
                    new_args[key] = args [key]

            # Step one: Encode the params with fixed position
            postdata_fp = self.encode_and_sign ([("method", method), ("APIKey", self.api_key)])
            # Step 2: Encode the params with variable positions
            postdata = self.encode_and_sign(new_args)

            postdata = postdata_fp + '&' + postdata

            LOG.debug ("Calling URL: %s?%s" % (url, postdata))

            f = urllib.urlopen(url, postdata)
            data = f.read()
            f.close()
            LOG.debug ("Server returns ...(see below)... \n%s" % (data, ))
            
            result = XMLNode.parseXML(data, True)
            if self.fail_on_error:
                SmugMugAPI.testFailure(result, True)

            return result
コード例 #4
0
ファイル: __init__.py プロジェクト: nikgarg/PicGuess
    def parse_xmlnode(self, rest_xml):
        '''Parses a REST XML response from Flickr into an XMLNode object.'''

        rsp = XMLNode.parse(rest_xml, store_xml=True)
        if rsp['stat'] == 'ok':
            return rsp
        
        err = rsp.err[0]
        raise FlickrError(u'Error: %(code)s: %(msg)s' % err)
コード例 #5
0
ファイル: exttype.py プロジェクト: Chalmers-IT/AdHoc
 def xsd_complex_type(self):
     node = XMLNode('complexType', name=self.xsd_name())
     if self.desc:
         node.new('annotation').new('documentation').cdata(XMLNode.escape(self.desc))
     return node
コード例 #6
0
ファイル: exttype.py プロジェクト: Chalmers-IT/AdHoc
    print ExtPerson().output(0, p)

    try:
        print ExtPerson().output(0, "apa")
    except ExtOutputError as e:
        pass

    print ExtPersonData().xsd().xml()

    try:
        pd = ExtPersonData().parse(0, dict(person=u"viktor", friends=[u"mort", u"niklas"], name=u"Viktor Fougstedt"))
    except ExtRegexpMismatchError:
        pass

    pd = ExtPersonData().parse(
        0, dict(person=u"person-viktor", friends=[u"person-mort", u"person-niklas"], name=u"Viktor Fougstedt"))

    print pd

    resp = XMLNode("response")
    ExtPersonData().to_xml(resp, ExtPersonData().output(0, pd))
    soap = resp.xml()
    print soap

    import xml.dom.minidom
    dom = xml.dom.minidom.parseString(soap)

    tmp = ExtPersonData().from_xml(dom.documentElement)
    print tmp
    print ExtPersonData().parse(0, tmp)
コード例 #7
0
ファイル: exttype.py プロジェクト: fredronnv/AdHoc
 def xsd_complex_type(self):
     node = XMLNode('complexType', name=self.xsd_name())
     if self.desc:
         node.new('annotation').new('documentation').cdata(
             XMLNode.escape(self.desc))
     return node
コード例 #8
0
ファイル: exttype.py プロジェクト: fredronnv/AdHoc
    print ExtPersonData().xsd().xml()

    try:
        pd = ExtPersonData().parse(
            0,
            dict(person=u"viktor",
                 friends=[u"mort", u"niklas"],
                 name=u"Viktor Fougstedt"))
    except ExtRegexpMismatchError:
        pass

    pd = ExtPersonData().parse(
        0,
        dict(person=u"person-viktor",
             friends=[u"person-mort", u"person-niklas"],
             name=u"Viktor Fougstedt"))

    print pd

    resp = XMLNode("response")
    ExtPersonData().to_xml(resp, ExtPersonData().output(0, pd))
    soap = resp.xml()
    print soap

    import xml.dom.minidom
    dom = xml.dom.minidom.parseString(soap)

    tmp = ExtPersonData().from_xml(dom.documentElement)
    print tmp
    print ExtPersonData().parse(0, tmp)
コード例 #9
0
    def get_wsdl(self, path):
        """If incoming path matches .get_wsdl_url(True), output a WSDL
        which is bug-compatible with the Microsoft svcutil toolchain,
        accomplished by renaming all input parameters to <name> + '_in'.
        The WSDL/SOAP URI:s reflect the compatability mode
        (/SOAP_mscompat rather than /SOAP for example).
        """

        #self.types = {}
        #self.generate_soap_fundefs()

        # Start by creating the base elements for the respective
        # components. That way we can add specific subelements as we
        # go.

        if path == self.get_wsdl_path(True):
            mssuffix = "_mscompat"
            mscompat = True
        elif path == self.get_wsdl_path(False):
            mssuffix = ""
            mscompat = False
        else:
            self.logger.error("VOLVO")
            raise ExtInternalError()

        wsdl_ns = self.get_wsdl_url(mscompat)
        schema_ns = self.get_schema_url(mscompat)

        defattrs = {
            'xmlns:self': wsdl_ns,
            'xmlns:myxsd': schema_ns,
            'xmlns:soap': "http://schemas.xmlsoap.org/wsdl/soap/",
            'xmlns': "http://schemas.xmlsoap.org/wsdl/",
        }

        name_attr = self.server.service_name
        if self.version > 0:
            name_attr += "-" + self.get_version_string(with_dashes=False)

        wsdl_root = XMLNode('definitions',
                            name=name_attr,
                            targetNamespace=wsdl_ns,
                            _other_attributes=defattrs,
                            _space_children=True)

        t = wsdl_root.new('types')
        wsdl_schema_root = t.new('schema',
                                 targetNamespace=schema_ns,
                                 xmlns="http://www.w3.org/2001/XMLSchema",
                                 elementFormDefault="qualified",
                                 _space_children=True)

        # Note that the dashes in the version will be removed by
        # capsification later
        p = self.server.service_name
        p += self.get_version_string(with_dashes=True)
        p += mssuffix
        ptname = ExtType.capsify(p + '-port-type')
        srvname = ExtType.capsify(p + 'service')
        bndname = ExtType.capsify(p + '-soap-binding')

        # PortType, Binding and Service are added to the WSDL XML element
        # last, since the <message> elements should come before them, but
        # we want to generate the contents of these three nodes at the
        # same time as the <message> elements.

        wsdl_porttype_root = XMLNode('portType',
                                     name=ptname,
                                     _space_children=True)

        wsdl_binding_root = XMLNode('binding',
                                    name=bndname,
                                    type="self:" + ptname,
                                    _space_children=True)

        wsdl_binding_root.new('soap:binding',
                              style='document',
                              transport="http://schemas.xmlsoap.org/soap/http")

        wsdl_service_root = XMLNode('service', name=srvname)
        prt = wsdl_service_root.new('port',
                                    name=srvname + 'Port',
                                    binding="self:" + bndname)
        prt.new('soap:address', location=self.server.get_server_url() + 'SOAP')

        # TODO ###
        #faultdef = RPCSOAPTypeDefFactory(self).typedef(SOAPFaultDetailType()._docdict())
        #faultmsg = wsdl_root.new("message", name="msgFaultDetail")
        #faultmsg.new("part", name="fault", element="myxsd:soapFaultDetail")

        def add_type(schemaelem, already_added, typething):
            typ = ExtType.instance(typething)
            if typ._name() in already_added:
                return

            already_added.add(typ._name())
            schemaelem.add(typ.xsd())

            for (_key, subtyp) in typ._subtypes():
                add_type(schemaelem, already_added, subtyp)

        added_types = set()

        for funcls in self.get_visible_functions():
            wsdl_schema_root.add(funcls.xsd_request(mscompat))
            wsdl_schema_root.add(funcls.xsd_response())

            for (_name, typ, _desc) in funcls.get_parameters():
                add_type(wsdl_schema_root, added_types, typ)

            (typ, _desc) = funcls._returns()
            add_type(wsdl_schema_root, added_types, typ)

            # Doc/lit-wrap input message
            msg = wsdl_root.new('message', name=funcls.input_message_name())
            msg.new('part',
                    name='parameters',
                    element="myxsd:" + funcls.request_element_name())

            # Doc/lit-wrap output message
            msg = wsdl_root.new('message', name=funcls.output_message_name())
            msg.new('part',
                    name='parameters',
                    element="myxsd:" + funcls.response_element_name())

            # PortType operation
            op = wsdl_porttype_root.new('operation', name=funcls.soap_name())
            op.new('input', message="self:" + funcls.input_message_name())
            op.new('output', message="self:" + funcls.output_message_name())
            op.new('fault',
                   message="self:msgFaultDetail",
                   name="soapFaultDetail")

            # SOAP operation
            soapaction = self.server.get_server_url(
            ) + "SOAP" + "/" + funcls.soap_name()
            _soapns = self.server.get_server_url() + "WSDL" + mssuffix

            op2 = wsdl_binding_root.new('operation', name=funcls.soap_name())
            op2.new('soap:operation', soapAction=soapaction)
            op2.new('input').new('soap:body', use='literal')
            op2.new('output').new('soap:body', use='literal')
            op2.new('fault',
                    name="soapFaultDetail").new('soap:fault',
                                                use='literal',
                                                name="soapFaultDetail")

        # Added here to come after all <message>:s
        wsdl_root.add(wsdl_porttype_root)
        wsdl_root.add(wsdl_binding_root)
        wsdl_root.add(wsdl_service_root)

        return wsdl_root.xml()
コード例 #10
0
ファイル: api.py プロジェクト: Chalmers-IT/AdHoc
    def get_wsdl(self, path):
        """If incoming path matches .get_wsdl_url(True), output a WSDL
        which is bug-compatible with the Microsoft svcutil toolchain,
        accomplished by renaming all input parameters to <name> + '_in'.
        The WSDL/SOAP URI:s reflect the compatability mode
        (/SOAP_mscompat rather than /SOAP for example).
        """

        #self.types = {}
        #self.generate_soap_fundefs()

        # Start by creating the base elements for the respective
        # components. That way we can add specific subelements as we
        # go.

        if path == self.get_wsdl_path(True):
            mssuffix = "_mscompat"
            mscompat = True
        elif path == self.get_wsdl_path(False):
            mssuffix = ""
            mscompat = False
        else:
            self.logger.error("VOLVO")
            raise ExtInternalError()

        wsdl_ns = self.get_wsdl_url(mscompat)
        schema_ns = self.get_schema_url(mscompat)

        defattrs = {
            'xmlns:self': wsdl_ns,
            'xmlns:myxsd': schema_ns,
            'xmlns:soap': "http://schemas.xmlsoap.org/wsdl/soap/",
            'xmlns': "http://schemas.xmlsoap.org/wsdl/",
        }

        name_attr = self.server.service_name
        if self.version > 0:
            name_attr += "-" + self.get_version_string(with_dashes=False)

        wsdl_root = XMLNode('definitions',
                            name=name_attr,
                            targetNamespace=wsdl_ns,
                            _other_attributes=defattrs,
                            _space_children=True)

        t = wsdl_root.new('types')
        wsdl_schema_root = t.new('schema',
                                 targetNamespace=schema_ns,
                                 xmlns="http://www.w3.org/2001/XMLSchema",
                                 elementFormDefault="qualified",
                                 _space_children=True)

        # Note that the dashes in the version will be removed by
        # capsification later
        p = self.server.service_name
        p += self.get_version_string(with_dashes=True)
        p += mssuffix
        ptname = ExtType.capsify(p + '-port-type')
        srvname = ExtType.capsify(p + 'service')
        bndname = ExtType.capsify(p + '-soap-binding')

        # PortType, Binding and Service are added to the WSDL XML element
        # last, since the <message> elements should come before them, but
        # we want to generate the contents of these three nodes at the
        # same time as the <message> elements.

        wsdl_porttype_root = XMLNode('portType', name=ptname,
                                     _space_children=True)

        wsdl_binding_root = XMLNode('binding', name=bndname,
                                    type="self:" + ptname,
                                    _space_children=True)

        wsdl_binding_root.new('soap:binding', style='document',
                              transport="http://schemas.xmlsoap.org/soap/http")

        wsdl_service_root = XMLNode('service', name=srvname)
        prt = wsdl_service_root.new('port', name=srvname + 'Port',
                                    binding="self:" + bndname)
        prt.new('soap:address', location=self.server.get_server_url() + 'SOAP')

        # TODO ###
        #faultdef = RPCSOAPTypeDefFactory(self).typedef(SOAPFaultDetailType()._docdict())
        #faultmsg = wsdl_root.new("message", name="msgFaultDetail")
        #faultmsg.new("part", name="fault", element="myxsd:soapFaultDetail")

        def add_type(schemaelem, already_added, typething):
            typ = ExtType.instance(typething)
            if typ._name() in already_added:
                return

            already_added.add(typ._name())
            schemaelem.add(typ.xsd())

            for (_key, subtyp) in typ._subtypes():
                add_type(schemaelem, already_added, subtyp)

        added_types = set()

        for funcls in self.get_visible_functions():
            wsdl_schema_root.add(funcls.xsd_request(mscompat))
            wsdl_schema_root.add(funcls.xsd_response())

            for (_name, typ, _desc) in funcls.get_parameters():
                add_type(wsdl_schema_root, added_types, typ)

            (typ, _desc) = funcls._returns()
            add_type(wsdl_schema_root, added_types, typ)

            # Doc/lit-wrap input message
            msg = wsdl_root.new('message', name=funcls.input_message_name())
            msg.new('part', name='parameters', element="myxsd:" + funcls.request_element_name())

            # Doc/lit-wrap output message
            msg = wsdl_root.new('message', name=funcls.output_message_name())
            msg.new('part', name='parameters', element="myxsd:" + funcls.response_element_name())

            # PortType operation
            op = wsdl_porttype_root.new('operation', name=funcls.soap_name())
            op.new('input', message="self:" + funcls.input_message_name())
            op.new('output', message="self:" + funcls.output_message_name())
            op.new('fault', message="self:msgFaultDetail", name="soapFaultDetail")

            # SOAP operation
            soapaction = self.server.get_server_url() + "SOAP" + "/" + funcls.soap_name()
            _soapns = self.server.get_server_url() + "WSDL" + mssuffix

            op2 = wsdl_binding_root.new('operation', name=funcls.soap_name())
            op2.new('soap:operation', soapAction=soapaction)
            op2.new('input').new('soap:body', use='literal')
            op2.new('output').new('soap:body', use='literal')
            op2.new('fault', name="soapFaultDetail").new('soap:fault', use='literal', name="soapFaultDetail")

        # Added here to come after all <message>:s
        wsdl_root.add(wsdl_porttype_root)
        wsdl_root.add(wsdl_binding_root)
        wsdl_root.add(wsdl_service_root)

        return wsdl_root.xml()