Permalink
Browse files

Avoid cElementTree on Python 3.1 due to http://bugs.python.org/issue9257

  • Loading branch information...
1 parent fc24967 commit 52fdd0ed7fa576494005e635b6a6610daab2ab0e @peterjc peterjc committed Dec 5, 2012
Showing with 26 additions and 15 deletions.
  1. +9 −9 Bio/Phylo/PhyloXMLIO.py
  2. +13 −3 Bio/SearchIO/BlastIO/blast_xml.py
  3. +4 −3 Bio/SeqIO/UniprotIO.py
@@ -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
@@ -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("")
@@ -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):
@@ -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

0 comments on commit 52fdd0e

Please sign in to comment.