From 70827fe06b8f4ec606d47519def1658890c489ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 9 Feb 2016 22:45:44 +0100 Subject: [PATCH] XML files must be open in binary mode for sax parser The sax parser expect a byte stream, so we must open the file with the binary mode. Also file_open should have a default encoding to None because encoding should not be set in binary mode. issue5313 --- trytond/modules/__init__.py | 2 +- trytond/tools/misc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index 718a441e6f..c8a43af86b 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -244,7 +244,7 @@ def load_module_graph(graph, pool, update=None, lang=None): filename = filename.replace('/', os.sep) logger.info('%s:loading %s', module, filename) # Feed the parser with xml content: - with tools.file_open(OPJ(module, filename)) as fp: + with tools.file_open(OPJ(module, filename), 'rb') as fp: tryton_parser.parse_xmlstream(fp) modules_todo.append((module, list(tryton_parser.to_delete))) diff --git a/trytond/tools/misc.py b/trytond/tools/misc.py index f9dfb87e0c..a41c8822be 100644 --- a/trytond/tools/misc.py +++ b/trytond/tools/misc.py @@ -51,7 +51,7 @@ def exec_command_pipe(name, *args, **kwargs): stdout=subprocess.PIPE, env=child_env) -def file_open(name, mode="r", subdir='modules', encoding='utf-8'): +def file_open(name, mode="r", subdir='modules', encoding=None): """Open a file from the root dir, using a subdir folder.""" from trytond.modules import EGG_MODULES if sys.version_info < (3,):