Skip to content

Parse XML files in bytes mode to avoid encoding error - #1322

Merged
peterjc merged 3 commits into
biopython:masterfrom
peterjc:open_bytes
Jul 15, 2017
Merged

peterjc merged 3 commits into
biopython:masterfrom
peterjc:open_bytes

Conversation

@peterjc

@peterjc peterjc commented Jul 13, 2017

Copy link
Copy Markdown
Member

This would resolve #855 and #1319

A similar approach might work for #1320 and #1321

For testing you need to (temporarily) change the locale settings, e.g. with LANG=C, see detailed notes on #855.

peterjc added 3 commits July 13, 2017 15:09
By opening these files in binary mode, the XML parser
itself takes care of dealing with the encoding. This
allows the following to pass:

$ LANG=C python3 test_SeqIO_SeqXML.py

Previously this would fail as the default encoding
'ascii' would break on the non-ASCII characters in
UTF-8 encoded test file SeqXML/rna_example.xml

Closes biopython#1319
By opening these files in binary mode, the XML parser
itself takes care of dealing with the encoding. This
allows the following to pass:

$ LANG=C python3 test_NCBIXML.py

Previously this would fail as the default encoding
'ascii' would break on the non-ASCII characters in
the names in some of the BLAST references.

Closes biopython#855.
@peterjc
peterjc requested review from bow, etal and tiagoantao July 13, 2017 14:32
@codecov

codecov Bot commented Jul 13, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #1322 into master will decrease coverage by <.01%.
The diff coverage is 84.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1322      +/-   ##
==========================================
- Coverage   84.44%   84.44%   -0.01%     
==========================================
  Files         318      318              
  Lines       48772    48779       +7     
==========================================
+ Hits        41187    41192       +5     
- Misses       7585     7587       +2
Impacted Files Coverage Δ
Bio/SeqIO/__init__.py 84.43% <100%> (ø) ⬆️
Bio/Blast/NCBIXML.py 89.49% <83.33%> (+0.27%) ⬆️
Bio/SeqIO/SeqXmlIO.py 86.46% <0%> (-0.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1d1458...34e78d2. Read the comment docs.

@peterjc

peterjc commented Jul 13, 2017

Copy link
Copy Markdown
Member Author

CodeCov is getting quite fussy (they have a moving goal post by default, the more we improve our base coverage, the stricter this check becomes).

It thinks we dropped two lines of coverage dealing with the SAXParseException...

@peterjc

peterjc commented Jul 14, 2017

Copy link
Copy Markdown
Member Author

@smsaladi who helped debug this on #855 says he likes the binary mode idea: #855 (comment)

@peterjc peterjc closed this Jul 14, 2017
@peterjc peterjc reopened this Jul 14, 2017
@peterjc

peterjc commented Jul 14, 2017

Copy link
Copy Markdown
Member Author

(Sorry for the close/open, I clicked the wrong button)

@bow bow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterjc , this looks ok for a merge.

@peterjc
peterjc merged commit aa94ebc into biopython:master Jul 15, 2017
@peterjc

peterjc commented Jul 15, 2017

Copy link
Copy Markdown
Member Author

Thanks Bow

@peterjc
peterjc deleted the open_bytes branch July 15, 2017 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_NCBIXML.py UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3

2 participants