def main(): sample_dict = { 'searchFilter': { 'categoryId': { '#text': 222, '@attrs': { 'site': 'US' } } }, 'paginationInput': { 'pageNumber': '1', 'pageSize': '25' }, 'itemFilter': [ { 'name': 'Condition', 'value': 'Used' }, { 'name': 'LocatedIn', 'value': 'GB' }, ], 'sortOrder': 'StartTimeNewest' } xml = dict2xml(sample_dict)
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" xml += "<{verb}Request>".format(verb=verb) xml += dict2xml(data) xml += "</{verb}Request>".format(verb=verb) return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">" xml += dict2xml(data) xml += "</" + verb + "Request>" return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<{verb}Request xmlns=\"http://www.ebay.com/marketplace/selling\">".format(verb=verb) xml += dict2xml(data, self.escape_xml) xml += "</{verb}Request>".format(verb=verb) return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<" + verb + "Request xmlns=\"http://www.ebay.com/marketplace/search/v1/services\">" xml += dict2xml(data, self.escape_xml) xml += "</" + verb + "Request>" return xml
def test_motors_compat_request_xml(self): print( '----------------------------------------------------------------------' ) print('Testing ebay: general') motors_dict = { 'Item': { 'Category': '101', 'Title': 'My Title', 'ItemCompatibilityList': { 'Compatibility': [ { 'CompatibilityNotes': 'Fits for all trims and engines.', 'NameValueList': [{ 'Name': 'Year', 'Value': '2001' }, { 'Name': 'Make', 'Value': 'Honda' }, { 'Name': 'Model', 'Value': 'Accord' }] }, ] } } } motors_xml = """<Item> <Category>101</Category> <ItemCompatibilityList> <Compatibility> <CompatibilityNotes>Fits for all trims and engines.</CompatibilityNotes> <NameValueList> <Name>Year</Name><Value>2001</Value> </NameValueList> <NameValueList> <Name>Make</Name><Value>Honda</Value> </NameValueList> <NameValueList> <Name>Model</Name><Value>Accord</Value> </NameValueList> </Compatibility> </ItemCompatibilityList> <Title>My Title</Title> </Item>""" motors_xml = re.sub(r'>\s+<', '><', motors_xml) motors_xml = re.sub(r'\s+$', '', motors_xml) self.assertEqual(dict2xml(motors_dict), motors_xml) print('All tests passed ✅') print( '----------------------------------------------------------------------' )
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<{verb}Request xmlns=\"http://www.ebay.com/marketplace/selling\">".format( verb=verb) xml += dict2xml(data, self.escape_xml) xml += "</{verb}Request>".format(verb=verb) return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<" + verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">" xml += dict2xml(data, self.escape_xml) xml += "</" + verb + "Request>" return xml
def _to_xml(self, data): "Converts a list or dictionary to XML and returns it." xml = '' if type(data) == dict: xml = dict2xml(data) elif type(data) == list: xml = list2xml(data) else: xml = data return xml
def build_request_data(self, verb, data, verb_attrs): xml = '<?xml version="1.0" encoding="utf-8"?>' xml += '<soap:Envelope' xml += ' xmlns:soap="http://www.w3.org/2003/05/soap-envelope"' xml += ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' xml += ' xmlns:ser="%s" >' % self.config.get('soap_env_str') xml += '<soap:Body>' xml += '<ser:%sRequest>' % verb xml += dict2xml(self.soapify(data)) xml += '</ser:%sRequest>' % verb xml += '</soap:Body>' xml += '</soap:Envelope>' return xml
def build_request_data(self, verb, data, verb_attrs): xml = '<?xml version="1.0" encoding="utf-8"?>' xml += '<soap:Envelope' xml += ' xmlns:soap="http://www.w3.org/2003/05/soap-envelope"' xml += ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' xml += ' xmlns:ser="%s" >' % self.config.get('soap_env_str') xml += '<soap:Body>' xml += '<ser:%sRequest>' % verb xml += dict2xml(self.soapify(data), self.escape_xml) xml += '</ser:%sRequest>' % verb xml += '</soap:Body>' xml += '</soap:Envelope>' return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<" + self.verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">" if not self.config.get('iaf_token', None): xml += "<RequesterCredentials>" if self.config.get('token', None): xml += "<eBayAuthToken>%s</eBayAuthToken>" % self.config.get('token') elif self.config.get('username', None): xml += "<Username>%s</Username>" % self.config.get('username', '') if self.config.get('password', None): xml += "<Password>%s</Password>" % self.config.get('password', '') xml += "</RequesterCredentials>" xml += dict2xml(data) xml += "</" + self.verb + "Request>" return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<{verb}Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">".format(verb=self.verb) if not self.config.get('iaf_token', None): xml += "<RequesterCredentials>" if self.config.get('token', None): xml += "<eBayAuthToken>{token}</eBayAuthToken>".format(token=self.config.get('token')) elif self.config.get('username', None): xml += "<Username>{username}</Username>".format(username=self.config.get('username', '')) if self.config.get('password', None): xml += "<Password>{password}</Password>".format(password=self.config.get('password', None)) xml += "</RequesterCredentials>" xml += dict2xml(data, self.escape_xml) xml += "</{verb}Request>".format(verb=self.verb) return xml
def main(): sample_dict = { 'searchFilter': {'categoryId': {'#text': 222, '@attrs': {'site': 'US'}}}, 'paginationInput': { 'pageNumber': '1', 'pageSize': '25' }, 'itemFilter': [ {'name': 'Condition', 'value': 'Used'}, {'name': 'LocatedIn', 'value': 'GB'}, ], 'sortOrder': 'StartTimeNewest' } xml = dict2xml(sample_dict)
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<" + self.verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">" if not self.config.get('iaf_token', None): xml += "<RequesterCredentials>" if self.config.get('token', None): xml += "<eBayAuthToken>%s</eBayAuthToken>" % self.config.get( 'token') elif self.config.get('username', None): xml += "<Username>%s</Username>" % self.config.get( 'username', '') if self.config.get('password', None): xml += "<Password>%s</Password>" % self.config.get( 'password', '') xml += "</RequesterCredentials>" xml += dict2xml(data) xml += "</" + self.verb + "Request>" return xml
def build_request_data(self, verb, data, verb_attrs): xml = "<?xml version='1.0' encoding='utf-8'?>" xml += "<{verb}Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">".format( verb=self.verb) if not self.config.get('iaf_token', None): xml += "<RequesterCredentials>" if self.config.get('token', None): xml += "<eBayAuthToken>{token}</eBayAuthToken>".format( token=self.config.get('token')) elif self.config.get('username', None): xml += "<Username>{username}</Username>".format( username=self.config.get('username', '')) if self.config.get('password', None): xml += "<Password>{password}</Password>".format( password=self.config.get('password', None)) xml += "</RequesterCredentials>" xml += dict2xml(data, self.escape_xml) xml += "</{verb}Request>".format(verb=self.verb) return xml
import os import sys sys.path.insert(0, '%s/../' % os.path.dirname(__file__)) from ebaysdk.utils import dict2xml dict1 = {'a': 'b'} assert(dict2xml(dict1) == '<a>b</a>') ''' dict2 XML Output <tag attr2="attr2value" site="US">222</tag> ''' dict2 = { 'tag': { '#text': 222, '@attrs': {'site': 'US', 'attr2': 'attr2value'} } } assert(dict2xml(dict2) == '<tag attr2="attr2value" site="US">222</tag>') ''' dict3 XML Output <itemFilter> <name>Condition</name> <value>Used</value> </itemFilter> <itemFilter> <name>LocatedIn</name>
import os import sys sys.path.insert(0, '%s/../' % os.path.dirname(__file__)) from ebaysdk.utils import dict2xml dict1 = {'a': 'b'} assert(dict2xml(dict1)=='<a>b</a>') ''' dict2 XML Output <tag attr2="attr2value" site="US">222</tag> ''' dict2 = { 'tag': { '#text': 222, '@attrs': {'site': 'US', 'attr2': 'attr2value'} } } assert(dict2xml(dict2)=='<tag attr2="attr2value" site="US">222</tag>') ''' dict3 XML Output <itemFilter> <name>Condition</name> <value>Used</value> </itemFilter> <itemFilter> <name>LocatedIn</name>
import os import sys sys.path.insert(0, '%s/../' % os.path.dirname(__file__)) from ebaysdk.utils import dict2xml dict1 = {'a': 'b'} assert (dict2xml(dict1) == '<a>b</a>') ''' dict2 XML Output <tag attr2="attr2value" site="US">222</tag> ''' dict2 = { 'tag': { '#text': 222, '@attrs': { 'site': 'US', 'attr2': 'attr2value' } } } assert (dict2xml(dict2) == '<tag attr2="attr2value" site="US">222</tag>') ''' dict3 XML Output <itemFilter> <name>Condition</name> <value>Used</value> </itemFilter> <itemFilter>