Permalink
Browse files

Fixing some Python3 compatibility issues.

  • Loading branch information...
1 parent 2a0f9e7 commit c51c4c03b005a4f8f3e695c822b361779b8d9a92 @bendmorris bendmorris committed with etal Feb 15, 2013
Showing with 7 additions and 3 deletions.
  1. +5 −1 Bio/Phylo/NeXMLIO.py
  2. +2 −2 Tests/test_Phylo_NeXML.py
View
6 Bio/Phylo/NeXMLIO.py
@@ -251,7 +251,11 @@ def write(self, handle, cdao_to_obo=True, **kwargs):
# use xml.dom.minodom for pretty printing
rough_string = ElementTree.tostring(root_node, 'utf-8')
reparsed = minidom.parseString(rough_string)
- handle.write(reparsed.toprettyxml(indent=" "))
+ try:
+ handle.write(reparsed.toprettyxml(indent=" "))
+ except TypeError:
+ # for compatibility with Python 3
+ handle.write(bytes(reparsed.toprettyxml(indent=" "), 'utf8'))
return count
View
4 Tests/test_Phylo_NeXML.py
@@ -87,8 +87,8 @@ def test_write(self):
t2 = NeXMLIO.Parser(open(DUMMY, 'rb')).parse().next()
def assert_property(prop_name):
- p1 = sorted([getattr(n, prop_name) for n in t1.get_terminals()])
- p2 = sorted([getattr(n, prop_name) for n in t2.get_terminals()])
+ p1 = sorted([getattr(n, prop_name) for n in t1.get_terminals() if getattr(n, prop_name)])
+ p2 = sorted([getattr(n, prop_name) for n in t2.get_terminals() if getattr(n, prop_name)])
self.assertEqual(p1,p2)
for prop_name in ('name', 'branch_length', 'confidence'):

0 comments on commit c51c4c0

Please sign in to comment.