本文整理汇总了Python中suds.sax.parser.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.parse方法的具体用法?Python Parser.parse怎么用?Python Parser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类suds.sax.parser.Parser
的用法示例。
在下文中一共展示了Parser.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_reply
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例2: get_fault
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例3: get_fault
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例4: extract_auth_tokens_on_premise
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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
示例5: cdata
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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()
示例6: get_fault
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例7: get_user
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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
示例8: get
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例9: get
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例10: get
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例11: extract_adfs_url
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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:')
示例12: marshall_response
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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: get_whoami
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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
示例14: download
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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)
示例15: download
# 需要导入模块: from suds.sax.parser import Parser [as 别名]
# 或者: from suds.sax.parser.Parser import parse [as 别名]
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