Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Using Python built-in ElementTree rather than lxml
  • Loading branch information
steadicat authored and Luke Sneeringer committed May 25, 2010
1 parent 9983754 commit 976d210
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions __init__.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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."

Expand Down Expand Up @@ -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:
Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.