Repository navigation
Closed
Description
Spin out from #855 which was specifically for test_NCBIXML.py but has the same root cause.
One of the test XML files contains non-ASCII accented characters (etc):
SeqXML/rna_example.xml: <description>åÅüöÖ߸䢣$€香肠</description>
Note that this XML file does define an encoding:
<?xml version="1.0" encoding="UTF-8"?>Testing with Biopython 1.70 with my default locale, everything is fine as a UTF8 encoding is the default. However, under some systems (including the multibuild systems for compiling wheels), you can get a default encoding of ascii.
The failure can be recreated under Python 3 as follows, here on Mac OS X using Python 3.6:
$ LANG=C python3 test_SeqIO_SeqXML.py
test_duplicated_dbxref (__main__.TestDetailedRead)
Read multiple cross references to a single source ... ERROR
test_duplicated_property (__main__.TestDetailedRead)
Read property with multiple values ... ERROR
test_empty_description (__main__.TestDetailedRead)
Check empty description. ... ERROR
test_full_characters_set_read (__main__.TestDetailedRead)
Read full characters set for each type ... ERROR
test_global_species (__main__.TestDetailedRead)
Check global species. ... ERROR
test_local_source_definition (__main__.TestDetailedRead)
Check local source. ... ERROR
test_local_species (__main__.TestDetailedRead)
Check local species. ... ERROR
test_read_minimal_required (__main__.TestDetailedRead)
Check minimal record. ... ERROR
test_special_characters_desc (__main__.TestDetailedRead)
Read special XML characters in description. ... ERROR
test_unicode_characters_desc (__main__.TestDetailedRead)
Test special unicode characters in the description. ... ERROR
test_read_write_dna (__main__.TestReadAndWrite)
Read and write DNA. ... ok
test_read_write_globalSpecies (__main__.TestReadAndWrite)
Read and write global species. ... ok
test_read_write_protein (__main__.TestReadAndWrite)
Read and write protein. ... ok
test_read_write_rna (__main__.TestReadAndWrite)
Read and write RNA. ... ERROR
test_write_species (__main__.TestReadAndWrite)
Test writing species from annotation tags. ... ok
test_for_errors (__main__.TestReadCorruptFiles)
Handling of corrupt files. ... ok
test_check_SeqIO (__main__.TestSimpleRead)
Files readable using parser via SeqIO. ... ERROR
======================================================================
ERROR: test_duplicated_dbxref (__main__.TestDetailedRead)
Read multiple cross references to a single source
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_duplicated_property (__main__.TestDetailedRead)
Read property with multiple values
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_empty_description (__main__.TestDetailedRead)
Check empty description.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_full_characters_set_read (__main__.TestDetailedRead)
Read full characters set for each type
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_global_species (__main__.TestDetailedRead)
Check global species.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_local_source_definition (__main__.TestDetailedRead)
Check local source.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_local_species (__main__.TestDetailedRead)
Check local species.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_read_minimal_required (__main__.TestDetailedRead)
Check minimal record.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_special_characters_desc (__main__.TestDetailedRead)
Read special XML characters in description.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_unicode_characters_desc (__main__.TestDetailedRead)
Test special unicode characters in the description.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 50, in setUp
self.records[key] = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_read_write_rna (__main__.TestReadAndWrite)
Read and write RNA.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 115, in test_read_write_rna
read1_records = list(SeqIO.parse(test_files["rna"][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
======================================================================
ERROR: test_check_SeqIO (__main__.TestSimpleRead)
Files readable using parser via SeqIO.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_SeqIO_SeqXML.py", line 40, in test_check_SeqIO
records = list(SeqIO.parse(test_files[key][0], "seqxml"))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 611, in parse
for r in i:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Bio/SeqIO/SeqXmlIO.py", line 58, in __iter__
for event, node in self._events:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 226, in __next__
rc = self.getEvent()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/dom/pulldom.py", line 255, in getEvent
buf = self.stream.read(self.bufsize)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 797: ordinal not in range(128)
----------------------------------------------------------------------
Ran 17 tests in 0.028s
FAILED (errors=12)
Metadata
Metadata
Assignees
Labels
No labels
Activity
Treat SeqXML files as binary (encoding)
peterjc commentedon Jul 13, 2017
Right now when given a filename
Bio.SeqIOfor text files, it will open the file using the default encoding (which depends on the locale).One simple fix seems to be to class
seqxmlas a binary file format, which means opening it in bytes mode, and let the XML parser take care of the encoding. That seems to work perfectly.Alternatively we might make
Bio.SeqIOdefault to opening text files usingencoding='utf-8'but that might have side effects...Treat SeqXML files as binary (encoding)