Skip to content

Commit

Permalink
Python 2.6 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Dec 13, 2011
1 parent fdc4998 commit 1dd2a00
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cairosvg/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import os
from xml.etree import ElementTree
from xml.parsers import expat

ParseError = getattr(ElementTree, 'ParseError', expat.ExpatError)


class Node(dict):
Expand Down Expand Up @@ -88,7 +91,7 @@ def __init__(self, text_or_url, parent=None):
try:
tree = ElementTree.fromstring(text_or_url)
self.filename = None
except ElementTree.ParseError:
except ParseError:
if "#" in text_or_url:
filename, element_id = text_or_url.split("#")
else:
Expand All @@ -102,7 +105,9 @@ def __init__(self, text_or_url, parent=None):
with open(filename) as file_descriptor:
tree = ElementTree.fromstring(file_descriptor.read())
if element_id:
for element in tree.iter():
iterator = (tree.iter() if hasattr(tree, 'iter')
else tree.getiterator())
for element in iterator:
if element.get("id") == element_id:
tree = element
break
Expand Down

0 comments on commit 1dd2a00

Please sign in to comment.