本文整理汇总了Python中suds.sax.parser.Parser类的典型用法代码示例。如果您正苦于以下问题:Python Parser类的具体用法?Python Parser怎么用?Python Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例2: cdata
def cdata():
xml = '<a><![CDATA[<b>This is my &<tag></b>]]></a>'
p = Parser()
d = p.parse(string=xml)
print d
a = d.root()
print a.getText()
示例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)
示例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)
示例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)
示例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
示例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
示例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)
示例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)
示例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:')
示例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)
示例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)
示例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)
示例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
示例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)