本文整理汇总了Python中suds.sax.element.Element.set方法的典型用法代码示例。如果您正苦于以下问题:Python Element.set方法的具体用法?Python Element.set怎么用?Python Element.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类suds.sax.element.Element
的用法示例。
在下文中一共展示了Element.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
if self.digest and self.password is None:
raise RuntimeError("Cannot generate password digest without the password.")
if self.autosetnonce:
self.setnonce()
if self.autosetcreated:
self.setcreated()
root = Element('UsernameToken', ns=WSSENS)
u = Element('Username', ns=WSSENS)
u.setText(self.username)
root.append(u)
if self.password is not None:
password = self.password
if self.digest:
password = self.get_digest()
p = Element('Password', ns=WSSENS)
p.setText(password)
p.set('Type', DIGEST_TYPE if self.digest else TEXT_TYPE)
root.append(p)
if self.nonce is not None:
n = Element('Nonce', ns=WSSENS)
n.setText(base64.encodestring(self.nonce)[:-1])
n.set('EncodingType', BASE64_ENC_TYPE)
root.append(n)
if self.created:
c = Element('Created', ns=WSUNS)
c.setText(str(UTC(self.created)))
root.append(c)
return root
示例2: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
usernametoken = Element('UsernameToken', ns=wssens)
username = Element('Username', ns=wssens)
username.setText(self.username)
usernametoken.append(username)
password = Element('Password', ns=wssens)
s = hashlib.sha1()
s.update(self.nonce)
s.update(self._print_datetime(self.created).encode('utf-8'))
s.update(self.password.encode('utf-8'))
password.setText(b64encode(s.digest()).decode('utf-8'))
password.set('Type', 'http://docs.oasis-open.org/wss/2004/01/'
'oasis-200401-wss-username-token-profile-1.0'
'#PasswordDigest')
usernametoken.append(password)
nonce = Element('Nonce', ns=wssens)
nonce.setText(b64encode(self.nonce).decode('utf-8'))
nonce.set(
'EncodingType',
'http://docs.oasis-open.org/wss/2004'
'/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'
)
usernametoken.append(nonce)
created = Element('Created', ns=wsuns)
created.setText(self._print_datetime(self.created))
usernametoken.append(created)
return usernametoken
示例3: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
"""
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
"""
root = Element('UsernameToken', ns=wssens)
u = Element('Username', ns=wssens)
u.setText(self.username)
root.append(u)
p = Element('Password', ns=wssens)
p.setText(self.generate_digest())
p.set(wspassd[0], wspassd[1])
root.append(p)
n = Element('Nonce', ns=wssens)
n.setText(base64.encodestring(self.nonce)[:-1])
n.set(wsenctype[0], wsenctype[1])
root.append(n)
n = Element('Created', ns=wsuns)
n.setText(self.created)
root.append(n)
self.reset()
return root
示例4: encryptMessage
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def encryptMessage(self, env, use_encrypted_header=False, second_pass=False):
encrypted_parts = second_pass and self.second_pass_encrypted_parts or self.encrypted_parts
elements_to_encrypt = []
encrypted_headers = []
for elements_to_encrypt_func in encrypted_parts:
addl_elements = elements_to_encrypt_func(env)
if addl_elements[0] is None:
continue
if not isinstance(addl_elements[0], list):
addl_elements = ([addl_elements[0]], addl_elements[1])
for element in addl_elements[0]:
if element not in elements_to_encrypt:
if element[0].parent.match("Header") and use_encrypted_header:
enc_hdr = Element("EncryptedHeader", ns=wsse11ns)
element[0].parent.replaceChild(element[0], enc_hdr)
enc_hdr.append(element[0])
elements_to_encrypt.append((enc_hdr, "Content"))
encrypted_headers.append(enc_hdr)
else:
elements_to_encrypt.append((element, addl_elements[1]))
ref_list = xmlsec.encryptMessage(
self.cert, self.symmetricKey, elements_to_encrypt, "#" + self.keyId, self.keyReference, self.keyTransport
)
for enc_hdr in encrypted_headers:
enc_hdr.set("wsu:Id", enc_hdr[0].get("Id"))
enc_hdr[0].unset("Id")
if self.includeRefList:
self.encryptedKey.append(ref_list)
return self.encryptedKey
else:
return (self.encryptedKey, ref_list)
示例5: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
"""
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
"""
root = Element('UsernameToken', ns=wssens)
root.set('wsu:Id', 'UsernameToken-%i' % hash(self))
u = Element('Username', ns=wssens)
u.setText(self.username)
root.append(u)
p = Element('Password', ns=wssens)
p.setText(self.password)
# The Type attribute defaults to PasswordText, but some endpoints
# seem to want it specified anyway.
p.set('Type', PASSWORD_TYPES['plain'])
root.append(p)
if self.nonce is not None:
n = Element('Nonce', ns=wssens)
n.setText(self.nonce)
root.append(n)
if self.created is not None:
n = Element('Created', ns=wsuns)
n.setText(self.created.isoformat())
root.append(n)
return root
示例6: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
"""
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
"""
root = Element('UsernameToken', ns=wssens)
u = Element('Username', ns=wssens)
u.setText(self.username)
root.append(u)
p = Element('Password', ns=wssens)
p.setText(self.password)
if self.password_digest:
p.set('Type', wsdigest)
p.setText(self.password_digest)
root.append(p)
if self.nonce is not None:
n = Element('Nonce', ns=wssens)
if self.nonce_has_encoding:
n.set('EncodingType', nonce_encoding_type)
n.setText(self.nonce)
root.append(n)
if self.created is not None:
n = Element('Created', ns=wsuns)
n.setText(str(DateTime(self.created)))
root.append(n)
return root
示例7: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
usernametoken = Element("UsernameToken", ns=wssens)
username = Element("Username", ns=wssens)
username.setText(self.username)
usernametoken.append(username)
password = Element("Password", ns=wssens)
s = hashlib.sha1()
s.update(self.nonce)
s.update(self._print_datetime(self.created).encode("utf-8"))
s.update(self.password.encode("utf-8"))
password.setText(b64encode(s.digest()).decode("utf-8"))
password.set(
"Type",
"http://docs.oasis-open.org/wss/2004/01/" "oasis-200401-wss-username-token-profile-1.0" "#PasswordDigest",
)
usernametoken.append(password)
nonce = Element("Nonce", ns=wssens)
nonce.setText(b64encode(self.nonce).decode("utf-8"))
nonce.set(
"EncodingType",
"http://docs.oasis-open.org/wss/2004" "/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary",
)
usernametoken.append(nonce)
created = Element("Created", ns=wsuns)
created.setText(self._print_datetime(self.created))
usernametoken.append(created)
return usernametoken
示例8: to_xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def to_xml(self, factory):
# Dear Docdata: apparently, reusing Vat was not possible..?
#node = factory.create('ns0:totalVatAmount') does not support setting text.
element = Element('ns0:totalVatAmount')
element.setText(str(int(self.value * 100)))
element.set('rate', self.rate)
element.set('currency', self.currency)
return element
示例9: to_xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def to_xml(self, factory):
# make sure the namespace is set to the correct one
metadata = factory.resolver.find('ns0:totalVatAmount')
element = Element("totalVatAmount", ns=metadata.namespace())
element.setText(str(int(self.value * 100)))
element.set('rate', self.rate)
element.set('currency', self.currency)
return element
示例10: _build_mouser_header
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def _build_mouser_header(self):
header_partnerid = Element('PartnerID').setText(self._api_key)
header_accountinfo = Element('AccountInfo')
header_accountinfo.insert(header_partnerid)
header = Element('MouserHeader')
header.insert(header_accountinfo)
header.set('xmlns', 'http://api.mouser.com/service')
return header
示例11: encryptMessage
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def encryptMessage(cert, symmetric_key, elements_to_encrypt, enc_key_uri, reference_type=KEY_REFERENCE_ISSUER_SERIAL, key_transport=KEY_TRANSPORT_RSA_OAEP):
sym_key = symmetric_key.sym_key
iv = symmetric_key.iv
block_encryption = symmetric_key.block_encryption_algorithm
reference_list = Element("ReferenceList", ns=wsencns)
for (element_to_encrypt, type) in elements_to_encrypt:
reference = Element("DataReference", ns=wsencns)
id = "EncDataId-" + str(generate_unique_id())
reference.set("URI", '#' + id)
reference_list.append(reference)
element_content = element_to_encrypt.canonical()
if type == 'Content':
element_content = element_content[element_content.index(">") + 1:element_content.rindex("<")]
enc_data = Element("EncryptedData", ns=wsencns)
enc_data.set("Id", id)
enc_data.set("Type", "http://www.w3.org/2001/04/xmlenc#" + type)
block_encryption_props = blockEncryptionProperties[block_encryption]
enc_method = Element("EncryptionMethod", ns=wsencns)
enc_method.set("Algorithm", block_encryption_props['uri'])
key_info = Element("KeyInfo", ns=dsns)
sec_token_ref = Element("SecurityTokenReference", ns=wssens)
wsse_reference = Element("Reference", ns=wssens)
wsse_reference.set("URI", enc_key_uri)
sec_token_ref.append(wsse_reference)
key_info.append(sec_token_ref)
cipher_data = Element("CipherData", ns=wsencns)
cipher_value = Element("CipherValue", ns=wsencns)
cipher = EVP.Cipher(alg=blockEncryptionProperties[block_encryption]['openssl_cipher'], key=sym_key, iv=iv, op=1, padding=0)
pad_bytes = block_encryption_props['block_size'] - len(element_content) % block_encryption_props['block_size']
element_content = element_content + ' ' * (pad_bytes - 1) + chr(pad_bytes)
enc_content = cipher.update(element_content.encode("utf-8"))
enc_content = enc_content + cipher.final()
enc_content = iv + enc_content
cipher_value.setText(b64encode(enc_content))
cipher_data.append(cipher_value)
enc_data.append(enc_method)
enc_data.append(key_info)
enc_data.append(cipher_data)
if type == 'Element':
element_to_encrypt.parent.replaceChild(element_to_encrypt, enc_data)
elif type == 'Content':
element_to_encrypt.setText('')
for child in element_to_encrypt.children:
element_to_encrypt.remove(child)
element_to_encrypt.append(enc_data)
return reference_list
示例12: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
"""
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
"""
root = Element('Security', ns=wssens)
root.set('mustUnderstand', str(self.mustUnderstand).lower())
for t in self.tokens:
root.append(t.xml())
return root
示例13: add
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def add(self, root):
"""
Add an <xs:import/> to the specified schema root.
@param root: A schema root.
@type root: L{Element}
"""
node = Element('import', ns=self.xsdns)
node.set('namespace', self.ns)
if self.location is not None:
node.set('schemaLocation', self.location)
log.debug('%s inserted', node)
root.insert(node)
示例14: xml
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def xml(self):
"""
Get xml representation of the object.
@return: The root node.
@rtype: L{Element}
"""
root = Element('Security', ns=WSSE_NS)
for p, u in self.nsprefixes.items():
root.addPrefix(p, u)
root.set('SOAP-ENV:mustUnderstand', self.mustUnderstand)
for t in self.tokens:
root.append(t.xml())
return root
示例15: _ensure_service
# 需要导入模块: from suds.sax.element import Element [as 别名]
# 或者: from suds.sax.element.Element import set [as 别名]
def _ensure_service(self):
"""Trying to add service if no one definied explicitly. EWS workaround."""
if (self.services
or not self.bindings
or len(self.bindings) > 1
or not self.bindings.keys()[0][0].startswith('Exchange')):
return
service = Element('service')
service.set('name', 'ExchangeServices')
port = Element('port', service)
port.set('name', 'ExchangeServicePort')
port.set('binding', self.bindings.keys()[0][0])
address = Element('address', port)
address.set('location', urljoin(self.url, 'exchange.asmx'))
port.append(address)
service.append(port)
service = Factory.create(service, self)
service.resolve(self)
self.children.append(service)
self.services.append(service)
log.debug('Auto created service: %s', service)