Skip to content
Browse files

Using Python built-in ElementTree rather than lxml

  • Loading branch information...
1 parent 9983754 commit 976d210da0c5f5febfc075491836b9485bdb0a66 @steadicat steadicat committed with lukesneeringer May 25, 2010
Showing with 11 additions and 11 deletions.
  1. +11 −11 __init__.py
View
22 __init__.py
@@ -5,7 +5,7 @@
import sys
from exceptions import *
from utils import *
-from lxml import etree
+from xml.etree import ElementTree
from urllib import urlencode
VERSION = '0.9.3'
@@ -101,7 +101,7 @@ def request(cls, path, code = None, item_code = None, product_code = None, pass_
# parse the XML
try:
- content = etree.fromstring(content)
+ content = ElementTree.fromstring(content)
except:
raise UnexpectedResponse, "The server sent back something that wasn't valid XML."
@@ -295,7 +295,7 @@ def _load_data_from_xml(self, xml, clean = True):
('subscription', 'plans'),
)
- for child in xml.iterchildren():
+ for child in xml.getchildren():
# is this an element with children? if so, it's an object
# relationship, not just an attribute
if len(child.getchildren()) > 0:
@@ -317,7 +317,7 @@ def _load_data_from_xml(self, xml, clean = True):
# okay, it's not a single relationship -- follow my normal
# process for a many to many
setattr(self, child.tag, [])
- for indiv_xml in child.iterchildren():
+ for indiv_xml in child.getchildren():
# get the class that this item is
try:
klass = getattr(sys.modules[__name__], indiv_xml.tag.capitalize())
@@ -390,7 +390,7 @@ def all(cls):
xml = CheddarGetter.request('/plans/get/')
# make a list of Plan objects and return it
- for plan_xml in xml.iterchildren(tag = 'plan'):
+ for plan_xml in xml.getiterator(tag = 'plan'):
plans.append(Plan.from_xml(plan_xml))
return plans
@@ -407,7 +407,7 @@ def get(cls, code):
xml = CheddarGetter.request('/plans/get/', code = code)
# return a plan object
- for plan_xml in xml.iterchildren(tag = 'plan'):
+ for plan_xml in xml.getiterator(tag = 'plan'):
return Plan.from_xml(plan_xml)
@@ -480,7 +480,7 @@ def search(cls, **kwargs):
try:
customers = []
xml = CheddarGetter.request('/customers/get/', **kwargs)
- for customer_xml in xml.iterchildren('customer'):
+ for customer_xml in xml.getiterator(tag='customer'):
customers.append(Customer.from_xml(customer_xml))
return customers
@@ -497,7 +497,7 @@ def get(cls, code):
in CheddarGetter."""
xml = CheddarGetter.request('/customers/get/', code = code)
- for customer_xml in xml.iterchildren('customer'):
+ for customer_xml in xml.getiterator(tag='customer'):
return Customer.from_xml(customer_xml)
@@ -557,7 +557,7 @@ def save(self):
# either way, I should get a well-formed customer XML response
# that can now be loaded into this object
- for customer_xml in xml.iterchildren('customer'):
+ for customer_xml in xml.getiterator(tag='customer'):
self._load_data_from_xml(customer_xml)
break
@@ -703,7 +703,7 @@ def save(self):
# either way, I should get a well-formed customer XML response
# that can now be loaded into this object
- for subscription_xml in xml.iterchildren('subscription'):
+ for subscription_xml in xml.getiterator(tag='subscription'):
self._load_data_from_xml(subscription_xml)
break
@@ -802,4 +802,4 @@ class Charge(CheddarObject):
if hasattr(settings, 'CHEDDARGETTER_PRODUCT_CODE'):
CheddarGetter.set_product_code(settings.CHEDDARGETTER_PRODUCT_CODE)
except ImportError:
- pass
+ pass

0 comments on commit 976d210

Please sign in to comment.
Something went wrong with that request. Please try again.