Skip to content
Browse files

Fix blast-xml writer to cope with py2.7.4 changes (writes unicode only)

  • Loading branch information...
1 parent 0e4e388 commit 3c9de1510fd1e9da23e96d8f9213a7e86873e3f6 @bow bow committed Apr 8, 2013
Showing with 5 additions and 6 deletions.
  1. +5 −6 Bio/SearchIO/BlastIO/blast_xml.py
View
11 Bio/SearchIO/BlastIO/blast_xml.py
@@ -609,7 +609,7 @@ def __init__(self, out, encoding='utf-8', indent=" ", increment=2):
def startDocument(self):
"""Starts the XML document."""
- self.write('<?xml version="1.0"?>\n'
+ self.write(u'<?xml version="1.0"?>\n'
'<!DOCTYPE BlastOutput PUBLIC "-//NCBI//NCBI BlastOutput/EN" '
'"http://www.ncbi.nlm.nih.gov/dtd/NCBI_BlastOutput.dtd">\n')
@@ -628,7 +628,7 @@ def startElement(self, name, attrs={}, children=False):
def endElement(self, name):
"""Ends and XML element of the given name."""
XMLGenerator.endElement(self, name)
- self.write('\n')
+ self.write(u'\n')
def startParent(self, name, attrs={}):
"""Starts an XML element which has children.
@@ -640,7 +640,7 @@ def startParent(self, name, attrs={}):
"""
self.startElement(name, attrs, children=True)
self._level += self._increment
- self.write('\n')
+ self.write(u'\n')
# append the element name, so we can end it later
self._parent_stack.append(name)
@@ -670,9 +670,8 @@ def simpleElement(self, name, content=None):
self.endElement(name)
def characters(self, content):
- # apply sax's filter first, then ours
- content = escape(content)
- for a, b in (('"', '&quot;'), ("'", '&apos;')):
+ content = escape(unicode(content))
+ for a, b in ((u'"', u'&quot;'), (u"'", u'&apos;')):
content = content.replace(a, b)
self.write(content)

0 comments on commit 3c9de15

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