• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python parser.Parser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中suds.sax.parser.Parser的典型用法代码示例。如果您正苦于以下问题:Python Parser类的具体用法?Python Parser怎么用?Python Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: get_fault

 def get_fault(self, reply):
     """
     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} )
     """
     reply = self.replyfilter(reply)
     sax = Parser()
     faultroot = sax.parse(string=reply)
     soapenv = faultroot.getChild('Envelope')
     soapbody = soapenv.getChild('Body')
     fault = soapbody.getChild('Fault')
     unmarshaller = self.unmarshaller(False)
     p = unmarshaller.process(fault)
     if self.options().faults:
         raise WebFault(p, faultroot)
     try:
         detail = p.detail
     except AttributeError:
         try:
             detail = p.faultstring
         except AttributeError:
             detail = "Unknown Error"
     return (faultroot, detail)
开发者ID:Techlightenment,项目名称:suds,代码行数:28,代码来源:binding.py


示例2: cdata

def cdata():
    xml = '<a><![CDATA[<b>This is my &amp;&lt;tag&gt;</b>]]></a>'
    p = Parser()
    d = p.parse(string=xml)
    print d
    a = d.root()
    print a.getText()
开发者ID:AbletonAG,项目名称:suds,代码行数:7,代码来源:saxenc.py


示例3: get_reply

 def get_reply(self, method, reply):
     """
     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} )
     """
     reply = self.replyfilter(reply)
     sax = Parser()
     replyroot = sax.parse(string=reply)
     soapenv = replyroot.getChild('Envelope')
     soapenv.promotePrefixes()
     soapbody = soapenv.getChild('Body')
     soapbody = self.multiref.process(soapbody)
     nodes = self.replycontent(method, soapbody)
     rtypes = self.returned_types(method)
     if len(rtypes) > 1:
         result = self.replycomposite(rtypes, nodes)
         return (replyroot, result)
     if len(rtypes) == 1:
         if rtypes[0].unbounded():
             result = self.replylist(rtypes[0], nodes)
             return (replyroot, result)
         if len(nodes):
             unmarshaller = self.unmarshaller()
             resolved = rtypes[0].resolve(nobuiltin=True)
             result = unmarshaller.process(nodes[0], resolved)
             return (replyroot, result)
     return (replyroot, None)
开发者ID:Andersbakken,项目名称:NetflixScripts,代码行数:35,代码来源:binding.py


示例4: get

 def get(self, mangled):
     """Override this to prevent attempted purges."""
     fp = self.getf(mangled)
     if fp is None:
         return None
     p = Parser()
     return p.parse(fp)
开发者ID:jasonthomas,项目名称:solitude,代码行数:7,代码来源:client.py


示例5: get_fault

 def get_fault(self, reply):
     """
     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} )
     """
     _reply = self.replyfilter(reply)
     sax = Parser()
     faultroot = sax.parse(string=_reply)
     soapenv = faultroot.getChild('Envelope')
     soapbody = soapenv.getChild('Body')
     fault = soapbody.getChild('Fault')
     unmarshaller = self.unmarshaller(False)
     if fault:
         p = unmarshaller.process(fault)
         if self.options().faults:
             raise WebFault(p, faultroot)
         return (True, faultroot, p.detail)
     else:
         #p = unmarshaller.process(soapbody)
         #if self.options().faults:
             #raise WebFault(p, faultroot)
         return (False, faultroot, reply)
开发者ID:emergence,项目名称:suds-philpem,代码行数:27,代码来源:binding.py


示例6: get_user

    def get_user(self, user_id):
        """
        Returns data of the user with id == `user_id` as a dict of type:
        {
            'firstname': ...,
            'lastname': ...,
            'internalemailaddress': ...,
            'systemuserid': ...,
        }
        """
        response = self.make_retrieve_soap_request(
            'systemuser', user_id, ['firstname', 'lastname', 'internalemailaddress']
        )

        parser = Parser()
        doc = parser.parse(string=response.content)

        attrs_el = doc.childAtPath('Envelope/Body/RetrieveResponse/RetrieveResult/Attributes')
        data = {}
        for attr_el in attrs_el:
            key = attr_el.getChild('key').text
            value = attr_el.getChild('value').text
            data[key] = value

        return data
开发者ID:UKTradeInvestment,项目名称:data-hub-api,代码行数:25,代码来源:api.py


示例7: extract_auth_tokens_on_premise

    def extract_auth_tokens_on_premise(self, resp_content):
        fix_suds()
        from suds.sax.parser import Parser
        p = Parser()
        doc = p.parse(string=resp_content)

        created = (self.now - timedelta(minutes=1)).isoformat()
        expires = (self.now + timedelta(minutes=60)).isoformat()
        rst_resp = doc.childAtPath('Envelope/Body/RequestSecurityTokenResponseCollection/RequestSecurityTokenResponse')
        key_ident = rst_resp.childAtPath('RequestedAttachedReference/SecurityTokenReference/KeyIdentifier').text
        binary_secret = rst_resp.childAtPath('RequestedProofToken/BinarySecret').text
        signature, signature_digest = self.generate_hmac_signature(binary_secret, created, expires)

        enc_data = rst_resp.childAtPath('RequestedSecurityToken/EncryptedData')
        key_ciphertext = enc_data.childAtPath('KeyInfo/EncryptedKey/CipherData/CipherValue').text
        token_ciphertext = enc_data.childAtPath('CipherData/CipherValue').text
        x509_info = enc_data.childAtPath('KeyInfo/EncryptedKey/KeyInfo/SecurityTokenReference/X509Data/X509IssuerSerial')
        issuer_name_x509 = x509_info.childAtPath('X509IssuerName').text
        serial_number_x509 = x509_info.childAtPath('X509SerialNumber').text

        context = {
            'key_ciphertext': key_ciphertext,
            'token_ciphertext': token_ciphertext,
            'key_ident': key_ident,
            'created': created,
            'expires': expires,
            'issuer_name_x509': issuer_name_x509,
            'serial_number_x509': serial_number_x509,
            'signature_digest': signature_digest,
            'signature': signature,
        }
        return context
开发者ID:jlattimer,项目名称:python-dynamics,代码行数:32,代码来源:dynamics.py


示例8: get_fault

 def get_fault(self, reply):
     """
     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} )
     """
     reply = self.replyfilter(reply)
     sax = Parser()
     faultroot = sax.parse(string=reply)
     soapenv = faultroot.getChild('Envelope')
     if soapenv is None:
         # If there isn't an <Envelope>, then we probably got a regular 500 error page (HTML) back. Not sure what to do
         # in this case, let's throw a generic exception (non-WebFault) for now.
         raise ServerErrorMissingSoapEnvelope(faultroot)
     soapbody = soapenv.getChild('Body')
     fault = soapbody.getChild('Fault')
     unmarshaller = self.unmarshaller(False)
     p = unmarshaller.process(fault)
     if self.options().faults:
         raise WebFault(p, faultroot)
     return (faultroot, p.detail)
开发者ID:CashStar,项目名称:suds-gzip,代码行数:25,代码来源:binding.py


示例9: get

 def get(self, id):
     try:
         fp = FileCache.getf(self, id)
         if fp is None:
             return None
         p = Parser()
         return p.parse(fp)
     except Exception:
         FileCache.purge(self, id)
开发者ID:IvarsKarpics,项目名称:edna-mx,代码行数:9,代码来源:cache.py


示例10: extract_adfs_url

    def extract_adfs_url(self, resp_content):
        fix_suds()
        from suds.sax.parser import Parser
        p = Parser()
        doc = p.parse(string=resp_content)

        all_policies = doc.childAtPath('definitions/Policy/ExactlyOne/All')
        url = all_policies.childAtPath('AuthenticationPolicy/SecureTokenService/Identifier').text
        return url.replace('http:', 'https:')
开发者ID:jlattimer,项目名称:python-dynamics,代码行数:9,代码来源:dynamics.py


示例11: get

 def get(self, id):
     try:
         fp = self.getf(id)
         if fp is None:
             return None
         p = Parser()
         return p.parse(fp)
     except Exception:
         self.purge(id)
开发者ID:BhallaLab,项目名称:moose-gui,代码行数:9,代码来源:cache.py


示例12: marshall_response

def marshall_response(vim, response):
    from suds.sax.parser import Parser
    from suds.bindings.document import Document
    parser = Parser()
    document = parser.parse(string=response)
    obj = document.getChildren()[0]
    binding = Document(vim.client.wsdl)
    unmarshaller = binding.unmarshaller()
    marshalled_obj = unmarshaller.process(obj, None)
    return vim._parse_object_content(marshalled_obj)
开发者ID:MiguelMoll,项目名称:vFense,代码行数:10,代码来源:__init__.py


示例13: sending

    def sending(self, context):
        '''Signs XML before sending'''

        signature_template = '''
            <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
              <SignedInfo>
              <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
              <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
              <Reference URI="#%(REFERENCE_ID)s">
                <Transforms>
                  <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
                  <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                </Transforms>
                <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                <DigestValue></DigestValue>
              </Reference>
              </SignedInfo>
              <SignatureValue />
              <KeyInfo>
                <X509Data>
                  <X509Certificate />
                </X509Data>
              </KeyInfo>
            </Signature>
        '''

        envelope_element = Parser().parse(string=context.envelope).root()
        envelope_element.refitPrefixes()

        body = envelope_element.getChild('Body')
        payload = body[0]

        qname = payload.qname()
        if 'Echo' in qname:
            return

        reference_id = "refId:%s" % uuid4()
        payload.set('Id', reference_id)
        signature_template %= {'REFERENCE_ID': reference_id}

        signature_element = Parser().parse(string=signature_template).root()
        payload.append(signature_element)

        envelope = self.DTD_TEST_ID % qname
        envelope += envelope_element.str()
        envelope = envelope.encode('utf-8')

        signer = XMLDSIG()
        signer.load_key(self.key_path,
                        password=self.key_passphrase,
                        cert_path=self.cert_path)
        context.envelope = signer.sign(envelope)
        context.envelope = self.RE_DTD_TEST.sub('', context.envelope)
开发者ID:vvojvoda,项目名称:fiscal-hr-python,代码行数:53,代码来源:fiscal.py


示例14: get_whoami

    def get_whoami(self, resp_content):
        fix_suds()
        from suds.sax.parser import Parser
        p = Parser()
        doc = p.parse(string=resp_content)

        id = ''
        results = doc.childAtPath('Envelope/Body/ExecuteResponse/ExecuteResult/Results')
        for result in results.children:
            if result.childAtPath('key').text == 'UserId':
                id = result.childAtPath('value').text

        return id
开发者ID:jlattimer,项目名称:python-dynamics,代码行数:13,代码来源:dynamics.py


示例15: download

 def download(self):
     """ download the schema """
     url = self.location
     try:
         if '://' not in url:
             url = urljoin(self.schema.baseurl, url)
         transport = self.schema.options.transport
         root = Parser(transport).parse(url=url).root()
         root.set('url', url)
         return self.schema.instance(root, url)
     except TransportError:
         msg = 'imported schema (%s) at (%s), failed' % (self.ns[1], url)
         log.error('%s, %s', self.id, msg, exc_info=True)
         raise Exception(msg)
开发者ID:bigbang4u2,项目名称:mywork,代码行数:14,代码来源:sxbasic.py


示例16: download

 def download(self, url):
     """
     Download the docuemnt.
     @param url: A document url.
     @type url: str.
     @return: A file pointer to the docuemnt.
     @rtype: file-like
     """
     store = DocumentStore()
     fp = store.open(url)
     if fp is None:
         fp = self.options.transport.open(Request(url))
     sax = Parser()
     return sax.parse(file=fp)
开发者ID:dreamindustries,项目名称:suds,代码行数:14,代码来源:reader.py


示例17: download

 def download(self, url):
     """
     Download the docuemnt.
     @param url: A document url.
     @type url: str.
     @return: A file pointer to the docuemnt.
     @rtype: file-like
     """
     store = DocumentStore()
     if url.startswith('http') or url.startswith('suds'):
         fp = store.open(url)
         if fp is None:
             fp = self.options.transport.open(Request(url))
     else:
         fp = open(url, 'r')
     sax = Parser()
     return sax.parse(file=fp)
开发者ID:ortsed,项目名称:suds,代码行数:17,代码来源:reader.py


示例18: download

def download(reader, url):
    company = None
    info =  url.split('/')
    filename = 'mocks/%s.xml' % info[-1].lower()

    # If the url contains the company name, take it and append it to response
    if len(info) == 3:
        company = info[0]
    with open(os.path.join(os.path.dirname(__file__), filename), 'r') as f:
        response = f.read()
        sax = Parser()
        result = sax.parse(string=response)
        if company:
            element = result.children[0].children[-1].children[0].children[0]
            location = element.get('location')
            element.set('location', '%s/%s' %(company, location))
        return result
开发者ID:ctxis,项目名称:lather,代码行数:17,代码来源:conftest.py


示例19: download

 def download(self, url):
     """
     Download the docuemnt.
     @param url: A document url.
     @type url: str.
     @return: A file pointer to the docuemnt.
     @rtype: file-like
     """
     store = DocumentStore()
     fp = store.open(url)
     if fp is None:
         fp = self.options.transport.open(Request(url))
     content = fp.read()
     fp.close()
     ctx = self.plugins.document.loaded(url=url, document=content)
     content = ctx.document
     sax = Parser()
     return sax.parse(string=content)
开发者ID:EquipmentShare,项目名称:suds-py3,代码行数:18,代码来源:reader.py


示例20: suds_unmarshall

def suds_unmarshall(data):
    try:
        from suds.sax.parser import Parser
        from suds.umx.basic import Basic
    except ImportError:
        print "ERROR:  Could not import SUDS."
        print "You must install SUDS for the '-t' option to work"
        print "https://fedorahosted.org/suds/"
        return None

    p = Parser()
    obj = None
    try:
        root = p.parse(string=data).root()
        umx = Basic()
        obj = umx.process(root)
    except Exception, e:
        print "SAX Excpetion:", e
开发者ID:cfrantz,项目名称:python-locfg,代码行数:18,代码来源:locfg.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sudsobject.asdict函数代码示例发布时间:2022-05-27
下一篇:
Python element.Element类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap