From f461acbaf28aa79d82cffaf65b886c3d884cc5f4 Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Wed, 11 Jan 2012 18:58:43 +0100 Subject: update author --- djangorestframework/parsers.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c218e5ee..c5eefaec 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -189,11 +189,38 @@ class XMLParser(BaseParser): """ data = {} tree = ET.parse(stream) - for child in tree.getroot().getchildren(): - data[child.tag] = self._type_convert(child.text) - + data = self._xml_convert(tree.getroot()) + return (data, None) + def _xml_convert(self, element): + """ + convert the xml `element` into the corresponding python object + + `data` The python object representation of xml `element`. + """ + + children = element.getchildren() + + if len(children) == 0: + return self._type_convert(element.text) + else: + if element.tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + if children[0].tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + data = {} + for child in children: + data[child.tag] = self._xml_convert(child) + + return data + def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent -- cgit v1.2.3 From ad7d921e86198a81a8db2a991111218c798026b8 Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Wed, 11 Jan 2012 19:29:48 +0100 Subject: Revert "update author" This reverts commit f461acbaf28aa79d82cffaf65b886c3d884cc5f4. --- djangorestframework/parsers.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c5eefaec..c218e5ee 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -189,38 +189,11 @@ class XMLParser(BaseParser): """ data = {} tree = ET.parse(stream) - data = self._xml_convert(tree.getroot()) - + for child in tree.getroot().getchildren(): + data[child.tag] = self._type_convert(child.text) + return (data, None) - def _xml_convert(self, element): - """ - convert the xml `element` into the corresponding python object - - `data` The python object representation of xml `element`. - """ - - children = element.getchildren() - - if len(children) == 0: - return self._type_convert(element.text) - else: - if element.tag == "resource": - data = [] - for child in children: - data.append(self._xml_convert(child)) - else: - if children[0].tag == "resource": - data = [] - for child in children: - data.append(self._xml_convert(child)) - else: - data = {} - for child in children: - data[child.tag] = self._xml_convert(child) - - return data - def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent -- cgit v1.2.3 From ab83a2faaedd9813887af0382f7199702461f60f Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Wed, 11 Jan 2012 19:31:08 +0100 Subject: recursive xml parsing --- djangorestframework/parsers.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c218e5ee..c5eefaec 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -189,11 +189,38 @@ class XMLParser(BaseParser): """ data = {} tree = ET.parse(stream) - for child in tree.getroot().getchildren(): - data[child.tag] = self._type_convert(child.text) - + data = self._xml_convert(tree.getroot()) + return (data, None) + def _xml_convert(self, element): + """ + convert the xml `element` into the corresponding python object + + `data` The python object representation of xml `element`. + """ + + children = element.getchildren() + + if len(children) == 0: + return self._type_convert(element.text) + else: + if element.tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + if children[0].tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + data = {} + for child in children: + data[child.tag] = self._xml_convert(child) + + return data + def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent -- cgit v1.2.3 From 27d22cff6cbdbbebbf92304934e0a1f1be87c1c4 Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Wed, 11 Jan 2012 19:34:08 +0100 Subject: Revert "update author" This reverts commit f461acbaf28aa79d82cffaf65b886c3d884cc5f4. --- djangorestframework/parsers.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c5eefaec..c218e5ee 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -189,38 +189,11 @@ class XMLParser(BaseParser): """ data = {} tree = ET.parse(stream) - data = self._xml_convert(tree.getroot()) - + for child in tree.getroot().getchildren(): + data[child.tag] = self._type_convert(child.text) + return (data, None) - def _xml_convert(self, element): - """ - convert the xml `element` into the corresponding python object - - `data` The python object representation of xml `element`. - """ - - children = element.getchildren() - - if len(children) == 0: - return self._type_convert(element.text) - else: - if element.tag == "resource": - data = [] - for child in children: - data.append(self._xml_convert(child)) - else: - if children[0].tag == "resource": - data = [] - for child in children: - data.append(self._xml_convert(child)) - else: - data = {} - for child in children: - data[child.tag] = self._xml_convert(child) - - return data - def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent -- cgit v1.2.3 From 1664bc7b915578ae8062562656fcc1b931ef095e Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Wed, 11 Jan 2012 19:36:43 +0100 Subject: recursive xml parsing --- djangorestframework/parsers.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c218e5ee..c5eefaec 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -189,11 +189,38 @@ class XMLParser(BaseParser): """ data = {} tree = ET.parse(stream) - for child in tree.getroot().getchildren(): - data[child.tag] = self._type_convert(child.text) - + data = self._xml_convert(tree.getroot()) + return (data, None) + def _xml_convert(self, element): + """ + convert the xml `element` into the corresponding python object + + `data` The python object representation of xml `element`. + """ + + children = element.getchildren() + + if len(children) == 0: + return self._type_convert(element.text) + else: + if element.tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + if children[0].tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + data = {} + for child in children: + data[child.tag] = self._xml_convert(child) + + return data + def _type_convert(self, value): """ Converts the value returned by the XMl parse into the equivalent -- cgit v1.2.3 From 6b3792aef27e045a049d6f3bd86d970cb53ea9f5 Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Wed, 11 Jan 2012 19:37:43 +0100 Subject: recursive xml parsing --- djangorestframework/parsers.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c5eefaec..79e14260 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -196,8 +196,6 @@ class XMLParser(BaseParser): def _xml_convert(self, element): """ convert the xml `element` into the corresponding python object - - `data` The python object representation of xml `element`. """ children = element.getchildren() -- cgit v1.2.3 From 2966c343520147c4027ea48f3fea47913da3ebdb Mon Sep 17 00:00:00 2001 From: Michele Lazzeri Date: Thu, 12 Jan 2012 13:28:32 +0100 Subject: correct complex data xml parsing --- djangorestframework/parsers.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'djangorestframework/parsers.py') diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index 79e14260..b99423a0 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -187,12 +187,11 @@ class XMLParser(BaseParser): `data` will simply be a string representing the body of the request. `files` will always be `None`. """ - data = {} tree = ET.parse(stream) data = self._xml_convert(tree.getroot()) - + return (data, None) - + def _xml_convert(self, element): """ convert the xml `element` into the corresponding python object @@ -203,19 +202,15 @@ class XMLParser(BaseParser): if len(children) == 0: return self._type_convert(element.text) else: - if element.tag == "resource": + # if the fist child tag is list-item means all children are list-item + if children[0].tag == "list-item": data = [] for child in children: - data.append(self._xml_convert(child)) + data.append(self._xml_convert(child)) else: - if children[0].tag == "resource": - data = [] - for child in children: - data.append(self._xml_convert(child)) - else: - data = {} - for child in children: - data[child.tag] = self._xml_convert(child) + data = {} + for child in children: + data[child.tag] = self._xml_convert(child) return data -- cgit v1.2.3