diff --git a/src/urdf_parser_py/display_urdf.py b/src/urdf_parser_py/display_urdf.py index 0ff7acf..5bb113a 100644 --- a/src/urdf_parser_py/display_urdf.py +++ b/src/urdf_parser_py/display_urdf.py @@ -6,7 +6,7 @@ def main(): parser = argparse.ArgumentParser(usage='Load an URDF file') - parser.add_argument('file', type=argparse.FileType('r'), + parser.add_argument('file', type=argparse.FileType('rb'), help='File to load. Use - for stdin') parser.add_argument('-o', '--output', type=argparse.FileType('w'), default=None, help='Dump file to XML') diff --git a/src/urdf_parser_py/xml_reflection/core.py b/src/urdf_parser_py/xml_reflection/core.py index 0ab1948..b46df35 100644 --- a/src/urdf_parser_py/xml_reflection/core.py +++ b/src/urdf_parser_py/xml_reflection/core.py @@ -613,7 +613,7 @@ def from_xml_string(cls, xml_string): @classmethod def from_xml_file(cls, file_path): - xml_string = open(file_path, 'r').read() + xml_string = open(file_path, 'rb').read() return cls.from_xml_string(xml_string) # Confusing distinction between loading code in object and reflection diff --git a/test/test_urdf.py b/test/test_urdf.py index 40c5c9b..b78432d 100644 --- a/test/test_urdf.py +++ b/test/test_urdf.py @@ -289,6 +289,21 @@ def test_robot_link_defaults_xyz_set(self): self.assertEqual(origin.xyz, [1, 2, 3]) self.assertEqual(origin.rpy, [0, 0, 0]) + def test_xml_with_UTF8_encoding(self): + xml = b''' + + + + + + + +''' + robot = self.parse(xml) + origin = robot.links[0].inertial.origin + self.assertEqual(origin.xyz, [1, 2, 3]) + self.assertEqual(origin.rpy, [0, 0, 0]) + class LinkMultiVisualsAndCollisionsTest(unittest.TestCase):