Skip to content

Commit

Permalink
Avoid cElementTree on Python 3.1 due to http://bugs.python.org/issue9257
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Dec 5, 2012
1 parent fc24967 commit 52fdd0e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
18 changes: 9 additions & 9 deletions Bio/Phylo/PhyloXMLIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

from Bio.Phylo import PhyloXML as PX

if (3, 0, 0) <= sys.version_info[:3] <= (3, 1, 3):
# Workaround for cElementTree regression in python 3.0--3.1.3
# See http://bugs.python.org/issue9257
from xml.etree import ElementTree
else:
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
# Alternative Python implementation, perhaps?
#For speed try to use cElementTree rather than ElementTree
try:
if (3, 0) <= sys.version_info[:2] <= (3, 1):
# Workaround for bug in python 3.0 and 3.1,
# see http://bugs.python.org/issue9257
from xml.etree import ElementTree as ElementTree
else:
from xml.etree import cElementTree as ElementTree
except ImportError:
from xml.etree import ElementTree as ElementTree

# Recognize the phyloXML namespace when parsing
# See http://effbot.org/zone/element-namespaces.htm
Expand Down
16 changes: 13 additions & 3 deletions Bio/SearchIO/BlastIO/blast_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
"""Bio.SearchIO parser for BLAST+ XML output formats."""
# for more info: http://www.ncbi.nlm.nih.gov/dtd/NCBI_BlastOutput.mod.dtd

import sys
import re
from itertools import chain
from xml.sax.saxutils import XMLGenerator, escape


#For speed try to use cElementTree rather than ElementTree
try:
from xml.etree import cElementTree as ET
if (3, 0) <= sys.version_info[:2] <= (3, 1):
# Workaround for bug in python 3.0 and 3.1,
# see http://bugs.python.org/issue9257
from xml.etree import ElementTree as ElementTree
else:
from xml.etree import cElementTree as ElementTree
except ImportError:
from xml.etree import ElementTree as ET
from xml.etree import ElementTree as ElementTree


from Bio._py3k import _as_bytes, _bytes_to_string
_empty_bytes_string = _as_bytes("")
Expand Down Expand Up @@ -176,7 +186,7 @@ class BlastXmlParser(object):
"""Parser for the BLAST XML format"""

def __init__(self, handle):
self.xml_iter = iter(ET.iterparse(handle, events=('start', 'end')))
self.xml_iter = iter(ElementTree.iterparse(handle, events=('start', 'end')))
self._meta, self._fallback = self._parse_preamble()

def __iter__(self):
Expand Down
7 changes: 4 additions & 3 deletions Bio/SeqIO/UniprotIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
except ImportError:
from StringIO import StringIO

#For speed try to use cElementTree rather than ElemenTree
#For speed try to use cElementTree rather than ElementTree
try:
if (3, 0, 0) <= sys.version_info[:3] <= (3, 1, 3):
#workaround for bug in python 3 to 3.1.3 see http://bugs.python.org/issue9257
if (3, 0) <= sys.version_info[:2] <= (3, 1):
# Workaround for bug in python 3.0 and 3.1,
# see http://bugs.python.org/issue9257
from xml.etree import ElementTree as ElementTree
else:
from xml.etree import cElementTree as ElementTree
Expand Down

0 comments on commit 52fdd0e

Please sign in to comment.