当前位置: 首页>>代码示例>>Python>>正文


Python SimpleXMLElement.types方法代码示例

本文整理汇总了Python中simplexml.SimpleXMLElement.types方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleXMLElement.types方法的具体用法?Python SimpleXMLElement.types怎么用?Python SimpleXMLElement.types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simplexml.SimpleXMLElement的用法示例。


在下文中一共展示了SimpleXMLElement.types方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wsdl

# 需要导入模块: from simplexml import SimpleXMLElement [as 别名]
# 或者: from simplexml.SimpleXMLElement import types [as 别名]

#.........这里部分代码省略.........
                    }
                serv['ports'][port['name']] = bindings[binding_name]
             
        for binding in wsdl.binding:
            binding_name = binding['name']
            if debug: print "Processing binding", service_name
            soap_binding = binding('binding', ns=soap_uris.values(), error=False)
            transport = soap_binding and soap_binding['transport'] or None
            port_type_name = get_local_name(binding['type'])
            bindings[binding_name].update({
                'port_type_name': port_type_name,
                'transport': transport, 'operations': {},
                })
            port_type_bindings[port_type_name] = bindings[binding_name]
            for operation in binding.operation:
                op_name = operation['name']
                op = operation('operation',ns=soap_uris.values(), error=False)
                action = op and op['soapAction']
                d = operations.setdefault(op_name, {})
                bindings[binding_name]['operations'][op_name] = d
                d.update({'name': op_name})
                #if action: #TODO: separe operation_binding from operation
                d["action"] = action
        
        def process_element(element_name, children):
            if debug: print "Processing element", element_name
            for tag in children:
                d = OrderedDict()
                for e in tag.children():
                    t = e['type'].split(":")
                    if len(t)>1:
                        ns, type_name = t
                    else:
                        ns, type_name = xsd_ns, t[0]
                    if ns==xsd_ns:
                        # look for the type, None == any
                        fn = REVERSE_TYPE_MAP.get(unicode(type_name), None)
                    else:
                        # complex type, postprocess later
                        fn = elements.setdefault(unicode(type_name), OrderedDict())
                    e_name = unicode(e['name'])
                    d[e_name] = fn
                    if e['maxOccurs']=="unbounded":
                        # it's an array... TODO: compound arrays?
                        d.array = True
                elements.setdefault(element_name, OrderedDict()).update(d)

        for element in wsdl.types("schema", ns=xsd_uri).children():
            if element.get_local_name() in ('element', 'complexType'):
                element_name = unicode(element['name'])
                if debug: print "Parsing Element %s: %s" % (element.get_local_name(),element_name)
                if element.get_local_name() == 'complexType':
                    children = element.children()
                else:
                    children = element.children()
                    if children:
                        children = children.children()
                if children:
                    process_element(element_name, children)

        def postprocess_element(elements):
            for k,v in elements.items():
                if isinstance(v, OrderedDict):
                    if v.array:
                        elements[k] = [v] # convert arrays to python lists
                    if v!=elements: #TODO: fix recursive elements
                        postprocess_element(v)
                    
        postprocess_element(elements)

        for message in wsdl.message:
            if debug: print "Processing message", message['name']
            part = message('part', error=False)
            element = {}
            if part:
                element_name = get_local_name(part['element'])
                element = {element_name: elements.get(element_name)}
            messages[message['name']] = element
        
        for port_type in wsdl.portType:
            port_type_name = port_type['name']
            if debug: print "Processing port type", port_type_name
            binding = port_type_bindings[port_type_name]

            for operation in port_type.operation:
                op_name = operation['name']
                op = operations[op_name] 
                op['documentation'] = unicode(operation('documentation', error=False) or '')
                if binding['soap_ver']: 
                    #TODO: separe operation_binding from operation (non SOAP?)
                    input = get_local_name(operation.input['message'])
                    output = get_local_name(operation.output['message'])
                    op['input'] = messages[input]
                    op['output'] = messages[output]

        if debug:
            import pprint
            pprint.pprint(services)
        
        return services
开发者ID:BlackgateResearch,项目名称:Pip-Target,代码行数:104,代码来源:client.py

示例2: wsdl_parse

# 需要导入模块: from simplexml import SimpleXMLElement [as 别名]
# 或者: from simplexml.SimpleXMLElement import types [as 别名]

#.........这里部分代码省略.........
                location = address and address['location'] or None
                soap_uri = address and soap_uris.get(address.get_prefix())
                soap_ver = soap_uri and soap_ns.get(soap_uri)
                bindings[binding_name] = {'service_name': service_name,
                    'location': location,
                    'soap_uri': soap_uri, 'soap_ver': soap_ver,
                    }
                serv['ports'][port['name']] = bindings[binding_name]
             
        for binding in wsdl.binding:
            binding_name = binding['name']
            if debug: print "Processing binding", service_name
            soap_binding = binding('binding', ns=soap_uris.values(), error=False)
            transport = soap_binding and soap_binding['transport'] or None
            port_type_name = get_local_name(binding['type'])
            bindings[binding_name].update({
                'port_type_name': port_type_name,
                'transport': transport, 'operations': {},
                })
            port_type_bindings[port_type_name] = bindings[binding_name]
            for operation in binding.operation:
                op_name = operation['name']
                op = operation('operation',ns=soap_uris.values(), error=False)
                action = op and op['soapAction']
                d = operations.setdefault(op_name, {})
                bindings[binding_name]['operations'][op_name] = d
                d.update({'name': op_name})
                #if action: #TODO: separe operation_binding from operation
                if action:
                    d["action"] = action
        
        #TODO: cleanup element/schema/types parsing:
        def process_element(element_name, node):
            "Parse and define simple element types"
            if debug: print "Processing element", element_name
            for tag in node:
                if tag.get_local_name() in ("annotation", "documentation"):
                    continue
                elif tag.get_local_name() in ('element', 'restriction'):
                    if debug: print element_name,"has not children!",tag
                    children = tag # element "alias"?
                    alias = True
                elif tag.children():
                    children = tag.children()
                    alias = False
                else:
                    if debug: print element_name,"has not children!",tag
                    continue #TODO: abstract?
                d = OrderedDict()                    
                for e in children:
                    t = e['type']
                    if not t:
                        t = e['base'] # complexContent (extension)!
                    if not t:
                        t = 'anyType' # no type given!
                    t = t.split(":")
                    if len(t)>1:
                        ns, type_name = t
                    else:
                        ns, type_name = None, t[0]
                    if element_name == type_name:
                        continue # prevent infinite recursion
                    uri = ns and e.get_namespace_uri(ns) or xsd_uri
                    if uri==xsd_uri:
                        # look for the type, None == any
                        fn = REVERSE_TYPE_MAP.get(unicode(type_name), None)
开发者ID:AndresVillan,项目名称:pyafipws.web2py-app,代码行数:70,代码来源:client.py

示例3: wsdl_parse

# 需要导入模块: from simplexml import SimpleXMLElement [as 别名]
# 或者: from simplexml.SimpleXMLElement import types [as 别名]

#.........这里部分代码省略.........

        for binding in wsdl.binding:
            binding_name = binding["name"]
            soap_binding = binding("binding", ns=soap_uris.values(), error=False)
            transport = soap_binding and soap_binding["transport"] or None
            port_type_name = get_local_name(binding["type"])
            bindings[binding_name].update({"port_type_name": port_type_name, "transport": transport, "operations": {}})
            if port_type_name not in port_type_bindings:
                port_type_bindings[port_type_name] = []
            port_type_bindings[port_type_name].append(bindings[binding_name])
            for operation in binding.operation:
                op_name = operation["name"]
                op = operation("operation", ns=soap_uris.values(), error=False)
                action = op and op["soapAction"]
                d = operations[binding_name].setdefault(op_name, {})
                bindings[binding_name]["operations"][op_name] = d
                d.update({"name": op_name})
                d["parts"] = {}
                # input and/or ouput can be not present!
                input = operation("input", error=False)
                body = input and input("body", ns=soap_uris.values(), error=False)
                d["parts"]["input_body"] = body and body["parts"] or None
                output = operation("output", error=False)
                body = output and output("body", ns=soap_uris.values(), error=False)
                d["parts"]["output_body"] = body and body["parts"] or None
                header = input and input("header", ns=soap_uris.values(), error=False)
                d["parts"]["input_header"] = header and {"message": header["message"], "part": header["part"]} or None
                header = output and output("header", ns=soap_uris.values(), error=False)
                d["parts"]["output_header"] = header and {"message": header["message"], "part": header["part"]} or None
                if action:
                    d["action"] = action

        # check axis2 namespace at schema types attributes
        self.namespace = dict(wsdl.types("schema", ns=xsd_uri)[:]).get("targetNamespace", self.namespace)

        imported_schemas = {}

        # process current wsdl schema:
        for schema in wsdl.types("schema", ns=xsd_uri):
            preprocess_schema(
                schema,
                imported_schemas,
                elements,
                xsd_uri,
                self.__soap_server,
                self.http,
                cache,
                force_download,
                self.wsdl_basedir,
            )

        postprocess_element(elements)

        for message in wsdl.message:
            log.debug("Processing message %s" % message["name"])
            for part in message("part", error=False) or []:
                element = {}
                element_name = part["element"]
                if not element_name:
                    # some implementations (axis) uses type instead
                    element_name = part["type"]
                type_ns = get_namespace_prefix(element_name)
                type_uri = wsdl.get_namespace_uri(type_ns)
                if type_uri == xsd_uri:
                    element_name = get_local_name(element_name)
                    fn = REVERSE_TYPE_MAP.get(unicode(element_name), None)
开发者ID:yashodhank,项目名称:digital-signage-server,代码行数:70,代码来源:client.py


注:本文中的simplexml.SimpleXMLElement.types方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。