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) else: p.set("Type", wstext) 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
def build_soap_client(self): if self.soap_endpoint is None or not self.soap_endpoint: self.soap_endpoint = self.get_soap_endpoint() self.soap_client = suds.client.Client(self.wsdl_file_url, faults=False, cachingpolicy=1) self.soap_client.set_options(location=self.soap_endpoint) self.soap_client.set_options( headers={"user-agent": "FuelSDK-Python-v1.3.0"}) if self.use_oAuth2_authentication == "True": element_oAuth = Element("fueloauth", ns=("etns", "http://exacttarget.com")) element_oAuth.setText(self.authToken) self.soap_client.set_options(soapheaders=(element_oAuth)) else: element_oAuth = Element("oAuth", ns=("etns", "http://exacttarget.com")) element_oAuthToken = Element("oAuthToken").setText( self.internalAuthToken) element_oAuth.append(element_oAuthToken) self.soap_client.set_options(soapheaders=(element_oAuth)) security = suds.wsse.Security() token = suds.wsse.UsernameToken("*", "*") security.tokens.append(token) self.soap_client.set_options(wsse=security)
def build_soap_client(self): if self.soap_endpoint is None or not self.soap_endpoint: self.soap_endpoint = self.get_soap_endpoint() self.soap_client = suds.client.Client(self.wsdl_file_url, faults=False, cachingpolicy=1) self.soap_client.set_options(location=self.soap_endpoint) self.soap_client.set_options( headers={'user-agent': 'FuelSDK-Python-v1.2.0'}) if self.use_oAuth2_authentication == 'True': element_oAuth = Element('fueloauth', ns=('etns', 'http://exacttarget.com')) element_oAuth.setText(self.authToken) self.soap_client.set_options(soapheaders=(element_oAuth)) else: element_oAuth = Element('oAuth', ns=('etns', 'http://exacttarget.com')) element_oAuthToken = Element('oAuthToken').setText( self.internalAuthToken) element_oAuth.append(element_oAuthToken) self.soap_client.set_options(soapheaders=(element_oAuth)) security = suds.wsse.Security() token = suds.wsse.UsernameToken('*', '*') security.tokens.append(token) self.soap_client.set_options(wsse=security)
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
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) p.set( 'Type', 'http://docs.oasis-open.org/wss/2004/01/' 'oasis-200401-wss-username-token-profile-1.0#' + ('PasswordDigest' if self.digest else 'PasswordText')) root.append(p) if self.nonce is not None: n = Element('Nonce', ns=wssens) if self.digest: n.set( 'EncodingType', 'http://docs.oasis-open.org/wss/2004' '/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary' ) n.setText(b64encode(self.nonce)) else: n.setText(self.nonce) root.append(n) if self.created is not None: n = Element('Created', ns=wsuns) n.setText(str(UTC(self.created))) root.append(n) return root
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
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
def _setupNationalRailClient(self): logging.info('Setting up national rail client') token = Element('AccessToken', ns=DARWIN_WEBSERVICE_NAMESPACE) val = Element('TokenValue', ns=DARWIN_WEBSERVICE_NAMESPACE) val.setText(DARWIN_TOKEN) token.append(val) client = Client(LDBWS_URL) client.set_options(soapheaders=token) self.nationalRailClient = client
def xml(self): root = Element("Timestamp", ns=wsuns) created = Element('Created', ns=wsuns) created.setText(str(UTC(self.created))) expires = Element('Expires', ns=wsuns) expires.setText(str(UTC(self.expires))) root.append(created) root.append(expires) return root
def xml(self): root = Element("Timestamp", ns=wsuns) created = Element('Created', ns=wsuns) created.setText(str(DateTime(self.created))) expires = Element('Expires', ns=wsuns) expires.setText(str(DateTime(self.expires))) root.append(created) root.append(expires) return root
def xml(self): root = Element("Timestamp", ns=wsuns) # xsd:datetime format does not have fractional seconds created = Element("Created", ns=wsuns) created.setText(str(UTC(self.created - timedelta(microseconds=self.created.microsecond)))) expires = Element("Expires", ns=wsuns) expires.setText(str(UTC(self.expires - timedelta(microseconds=self.expires.microsecond)))) root.append(created) root.append(expires) return root
def to_xml(self, factory): # Needs to be an xsd:int with an attribute # Can't do that with factory.create('ns0:quantity') #metadata = factory.resolver.find('ns0:quantity') #ns = metadata.namespace() element = Element('ns0:quantity') element.setText(str(self.value)) element.set('unitOfMeasure', self.unit) return element
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
def xml(self): self.created = Token.utc() root = Element("Timestamp", ns=WSUNS) created = Element('Created', ns=WSUNS) created.setText(self._trim_to_ms(str(UTC(self.created)))) root.append(created) if self.validity is not None: self.expires = self.created + timedelta(seconds=self.validity) expires = Element('Expires', ns=WSUNS) expires.setText(self._trim_to_ms(str(UTC(self.expires)))) root.append(expires) return root
def xml(self): self.created = datetime.utcnow() root = Element("Timestamp", ns=WSUNS) created = Element('Created', ns=WSUNS) created.setText(iso_utc(self.created)) root.append(created) if self.validity is not None: self.expires = self.created + timedelta(seconds=self.validity) expires = Element('Expires', ns=WSUNS) expires.setText(iso_utc(self.expires)) root.append(expires) return root
def connect(self): from .client import SmsClient from suds.sax.element import Element self.client = SmsClient(self._vim.server_fqdn) session = eval(list(self._vim.client.client.options.transport.cookiejar)[0].value) cookie = Element("vcSessionCookie") cookie.setText(session) self.client.wsdl.options.__pts__.set("soapheaders", cookie) ref = Property('ServiceInstance') ref._type = 'ServiceInstance' self.service_instance = SmsServiceInstance(self, name='ServiceInstance', ref=ref) self.connected = True
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) 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( str( UTC(self.created - timedelta(microseconds=self.created.microsecond)))) root.append(n) return root
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
def xml(self): """ Get xml representation of the object. @return: The root node. @rtype: L{Element} """ root = Element('UsernameToken', ns=WSSE_NS) for p, u in self.nsprefixes.items(): root.addPrefix(p, u) root.append(Attribute('wsu:Id', 'UsernameToken-9')) root.append(Attribute('xmlns:wsu', WSU_URI)) u = Element('Username', ns=WSSE_NS) u.setText(self.username) root.append(u) p = Element('Password', ns=WSSE_NS) p.setText(self.password) p.append(Attribute('Type', WSU_UN_URI)) root.append(p) if self.nonce is not None: n = Element('Nonce', ns=WSSE_NS) n.setText(self.nonce) root.append(n) if self.created is not None: n = Element('Created', ns=WSU_NS) n.setText(str(UTC(self.created))) root.append(n) return root
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
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
def _create_wsse_header(self, username, password): username_element = Element('wsse:Username') username_element.setText(username) password_element = Element('wsse:Password') password_element.set('Type', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText') password_element.setText(sha256(password.encode()).hexdigest()) nonce = Element('wsse:Nonce') nonce.set('EncodingType', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary') nonce.setText(base64.b64encode(os.urandom(64))) bogota_tz = pytz.timezone('America/Bogota') created = Element('wsu:Created') created.setText(pytz.utc.localize(datetime.now()).astimezone(bogota_tz).strftime('%Y-%m-%dT%H:%M:%S.000-05:00')) username_token = Element('wsse:UsernameToken') username_token.set('wsu:Id', 'UsernameToken-1') username_token.append(username_element) username_token.append(password_element) username_token.append(nonce) username_token.append(created) header = Element('wsse:Security').append(username_token) return header
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(iso_utc(self.created)) root.append(c) return root
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
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) 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) #txt=str(DateTime(self.created)) #txt=txt.replace('Z', '') #n.setText(txt) root.append(n) return root
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) nonce_bytes = self.nonce if not isinstance(self.nonce, bytes): nonce_bytes = self.nonce.encode('utf-8') n.setText(base64.encodebytes(nonce_bytes)[:-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
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
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
def to_xml(self, factory): # Needs to be an xsd:int with an attribute. Suds is not # responding nicely with basic types combined with attributes, so # we can't do that with factory.create('ns0:quantity') # # See also: # https://stackoverflow.com/questions/13103023/how-can-i-assign-a-value-to-a-factory-created-simpletype-object-with-python-suds # make sure the namespace is set to the correct one metadata = factory.resolver.find('ns0:quantity') element = Element("quantity", ns=metadata.namespace()) element.setText(str(self.value)) element.set('unitOfMeasure', self.unit) return element
def connect(self): from .client import SmsClient from suds.sax.element import Element self.client = SmsClient("{0}:8443".format(self._vim.server_fqdn)) session = eval( list(self._vim.client.client.options.transport.cookiejar)[0].value) cookie = Element("vcSessionCookie") cookie.setText(session) self.client.wsdl.options.__pts__.set("soapheaders", cookie) ref = Property('ServiceInstance') ref._type = 'ServiceInstance' self.service_instance = SmsServiceInstance(self, name='ServiceInstance', ref=ref) self.connected = True
def xml(self): root = Element("Timestamp", ns=wsuns) # xsd:datetime format does not have fractional seconds created = Element('Created', ns=wsuns) created.setText( str( UTC(self.created - timedelta(microseconds=self.created.microsecond)))) expires = Element('Expires', ns=wsuns) expires.setText( str( UTC(self.expires - timedelta(microseconds=self.expires.microsecond)))) root.append(created) root.append(expires) return root
def xml(self): """ Get xml representation of the object. @return: The root node. @rtype: L{Element} """ root = Element('Timestamp', ns=wsuns) root.set('wsu:Id', 'Timestamp-%i' % hash(self)) c = Element('Created', ns=wsuns) c.setText(self.created.isoformat()) root.append(c) if self.expires: e = Element('Expires', ns=wsuns) e.setText(self.expires.isoformat()) root.append(e) return root
def build_soap_header(self, el, data): """Set up a SOAP object for our headers""" ## make our first element for name in data: if type(data[name]) is dict: ## append to the current element nel = Element(name) el.children.append(nel) self.build_soap_header(nel, data[name]) else: opt = Element(name) opt.setText(data[name]) el.children.append(opt) # print "{name} - {data}".format(name=name,data=data[name]) return el
def __init__(self, key): """ input - 'key' - your unique access token. """ self.key = key self.url = 'https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2017-10-01' self.namespace = ('ns2', 'http://thalesgroup.com/RTTI/2013-11-28/Token/types') self.header = Element('AccessToken', ns=self.namespace) header_val = Element('TokenValue', ns=self.namespace, parent=self.header) header_val.setText(key) self.header.append(header_val) self.__client = Client(self.url) self.__client.set_options(soapheaders=self.header)
def describe_vehicle_failure2(vin): """This fails because there is a bug related when prettyxml is False https://fedorahosted.org/suds/ticket/432 """ client = Client(CHROME_URL) account_info = client.factory.create('AccountInfo') account_info._number = CHROME_ACCOUNT_NUMBER account_info._secret = CHROME_ACCOUNT_SECRET account_info._country = 'US' account_info._language = 'en' vin_element = Element('vin', ns=('ns1', 'urn:description7a.services.chrome.com')) vin_element.setText(vin) result = client.service.describeVehicle(account_info, vin_element) print result
def create_element(self, name, ns=None, prefix=None, attrs=None, text=None): """Создание нового элемента""" new_element = Element(name, ns=ns) if prefix: new_element.setPrefix(prefix) if attrs: for k, v in attrs.items(): new_element.set(k, v) if text: new_element.setText(text) return new_element
def describe_vehicle_success_with_never_unwrap_output_patch(vin): """This uses a patched version of suds which never tries to unwrap the output message """ # NOTE: prettyxml must be set to True in order to add `vin_element` below # https://fedorahosted.org/suds/ticket/432 client = Client(CHROME_URL, prettyxml=True, never_unwrap_output=True) account_info = client.factory.create('AccountInfo') account_info._number = CHROME_ACCOUNT_NUMBER account_info._secret = CHROME_ACCOUNT_SECRET account_info._country = 'US' account_info._language = 'en' vin_element = Element('vin', ns=('ns1', 'urn:description7a.services.chrome.com')) vin_element.setText(vin) result = client.service.describeVehicle(account_info, vin_element) print str(result)[:1000] print result._bestMakeName
def create_version(): el = Element('Version') el.setPrefix('ns0') major_release = Element('majorRelease') major_release.setPrefix('ns0') major_release.setText('1') el.append(major_release) minor_release = Element('minorRelease') minor_release.setPrefix('ns0') minor_release.setText('18') el.append(minor_release) return { 'majorRelease': '1', 'minorRelease': '0', } return el
def describe_vehicle_failure3(vin): """This fails becuase attributes on the root of the response element, such as bestMakeName, are not available """ # NOTE: prettyxml must be set to True in order to add `vin_element` below # https://fedorahosted.org/suds/ticket/432 client = Client(CHROME_URL, prettyxml=True) account_info = client.factory.create('AccountInfo') account_info._number = CHROME_ACCOUNT_NUMBER account_info._secret = CHROME_ACCOUNT_SECRET account_info._country = 'US' account_info._language = 'en' vin_element = Element('vin', ns=('ns1', 'urn:description7a.services.chrome.com')) vin_element.setText(vin) result = client.service.describeVehicle(account_info, vin_element) print str(result)[:1000] print result._bestMakeName
def __init__(self, internal_oauth_token, url=None): self.client = Client(settings.EXACTTARGET_SOAP_WSDL_URL) # Make easy the access to the types self.valid_types = [] for valid_type in self.client.sd[0].types: self.valid_types.append(valid_type[0].name) if url: self.client.set_options(location=url) # Add the default Security in the header security = Security() token = UsernameToken('*', '*') security.tokens.append(token) self.client.set_options(wsse=security) # Add oAuth token to SOAP header. ns = (None, constants.OAUTH_HEADER_URL) oauth_header = Element("oAuth", ns=ns) oauth_element = Element("oAuthToken") oauth_element.setText(internal_oauth_token) oauth_header.append(oauth_element) self.client.set_options(soapheaders=oauth_header)
def marshalled(self, context): """Add an authenticator token to the document before it is sent. :param context: The current message context. """ body = context.envelope.getChild("Body") operation = body[0] if operation.name in ("AuthenticateUser", "RegisterAccount"): pass elif self.authenticator: namespace = operation.namespace() element = Element("Authenticator", ns=namespace) element.setText(self.authenticator) operation.insert(element) else: document = Document(self.client.wsdl) method = self.client.service.AuthenticateUser.method parameter = document.param_defs(method)[0] element = document.mkparam(method, parameter, self.credentials) operation.insert(element)
def __init__(self, wsdl=None, api_key=None, timeout=5): """ Constructor Keyword arguments: wsdl -- the URL of the Darwin LDB WSDL document. Will fall back to using the DARWIN_WEBSERVICE_WSDL environment variable if not supplied api_key -- a valid API key for the Darwin LDB webservice. Will fall back to the DARWIN_WEBSERVICE_API_KEY if not supplied timeout -- a timeout in seconds for calls to the LDB Webservice (default 5) """ if not wsdl: wsdl = os.environ['DARWIN_WEBSERVICE_WSDL'] if not api_key: api_key = os.environ['DARWIN_WEBSERVICE_API_KEY'] self._soap_client = Client(wsdl) self._soap_client.set_options(timeout=timeout) #build soap headers token3 = Element('AccessToken', ns=DARWIN_WEBSERVICE_NAMESPACE) token_value = Element('TokenValue', ns=DARWIN_WEBSERVICE_NAMESPACE) token_value.setText(api_key) token3.append(token_value) self._soap_client.set_options(soapheaders=(token3))
def basic(): xml = "<a>Me && <b>my</b> shadow's <i>dog</i> love to 'play' and sing "la,la,la";</a>" p = Parser() d = p.parse(string=xml) a = d.root() print 'A(parsed)=\n%s' % a assert str(a) == xml b = Element('a') b.setText('Me && <b>my</b> shadow\'s <i>dog</i> love to \'play\' and sing "la,la,la";') print 'B(encoded)=\n%s' % b assert str(b) == xml print 'A(text-decoded)=\n%s' % a.getText() print 'B(text-decoded)=\n%s' % b.getText() assert a.getText() == b.getText() print 'test pruning' j = Element('A') j.set('n', 1) j.append(Element('B')) print j j.prune() print j
def describe_vehicle_failure(vin): """This fails because an extra accountInfo element is added in the request xml """ client = Client(CHROME_URL) account_info = client.factory.create('AccountInfo') account_info._number = CHROME_ACCOUNT_NUMBER account_info._secret = CHROME_ACCOUNT_SECRET account_info._country = 'US' account_info._language = 'en' vin_element = Element('vin', ns=('ns1', 'urn:description7a.services.chrome.com')) vin_element.setText(vin) vehicle_description_request = client.factory.create('VehicleDescriptionRequest') vehicle_description_request.accountInfo = account_info vehicle_description_request.switch.append(vin_element) print vehicle_description_request result = client.service.describeVehicle(vehicle_description_request) print result
def basic(): xml = "<a>Me && <b>my</b> shadow's <i>dog</i> love to 'play' and sing "la,la,la";</a>" p = Parser() d = p.parse(string=xml) a = d.root() print 'A(parsed)=\n%s' % a assert str(a) == xml b = Element('a') b.setText('Me && <b>my</b> shadow\'s <i>dog</i> love to \'play\' and sing "la,la,la";') print 'B(encoded)=\n%s' % b assert str(b) == xml print 'A(text-decoded)=\n%s' % a.getText() print 'B(text-decoded)=\n%s' % b.getText() assert a.getText() == b.getText() print 'test pruning' j = Element('A') j.set('n', 1) j.append(Element('B')) print j j.prune() print j
def build_soap_client(self): if self.soap_endpoint is None or not self.soap_endpoint: self.soap_endpoint = self.get_soap_endpoint() self.soap_client = suds.client.Client(self.wsdl_file_url, faults=False, cachingpolicy=1) self.soap_client.set_options(location=self.soap_endpoint) self.soap_client.set_options(headers={'user-agent' : 'FuelSDK-Python-v1.2.0'}) if self.use_oAuth2_authentication == 'True': element_oAuth = Element('fueloauth', ns=('etns', 'http://exacttarget.com')) element_oAuth.setText(self.authToken); self.soap_client.set_options(soapheaders=(element_oAuth)) else: element_oAuth = Element('oAuth', ns=('etns', 'http://exacttarget.com')) element_oAuthToken = Element('oAuthToken').setText(self.internalAuthToken) element_oAuth.append(element_oAuthToken) self.soap_client.set_options(soapheaders=(element_oAuth)) security = suds.wsse.Security() token = suds.wsse.UsernameToken('*', '*') security.tokens.append(token) self.soap_client.set_options(wsse=security)
def buildEncryptedKey(key_id, cert, sym_key, reference_type=KEY_REFERENCE_ISSUER_SERIAL, block_encryption=BLOCK_ENCRYPTION_AES128_CBC, key_transport=KEY_TRANSPORT_RSA_OAEP): enc_key = Element("EncryptedKey", ns=wsencns) enc_key.set("Id", key_id) enc_method = Element("EncryptionMethod", ns=wsencns) enc_method.set("Algorithm", keyTransportProperties[key_transport]['uri']) key_info = build_key_info(cert, reference_type) cipher_data = Element("CipherData", ns=wsencns) cipher_value = Element("CipherValue", ns=wsencns) block_encryption_props = blockEncryptionProperties[block_encryption] pub_key = cert.getRsaPublicKey() enc_sym_key = pub_key.public_encrypt(sym_key, keyTransportProperties[key_transport]['padding']) cipher_value.setText(b64encode(enc_sym_key)) cipher_data.append(cipher_value) sha1 = EVP.MessageDigest('sha1') sha1.update(enc_sym_key) cipher_value_sha1 = sha1.final() enc_key.append(enc_method) enc_key.append(key_info) enc_key.append(cipher_data) return (enc_key, cipher_value_sha1)