From 556fb8877b2bf2b58d258181ea45fa5271a95ab9 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Wed, 27 Mar 2019 10:47:27 -0300 Subject: [PATCH] Conserta erro no autodecode --- sapl/legacy/scripts/exporta_zope/exporta_zope.py | 15 ++++----------- sapl/legacy/scripts/exporta_zope/requirements.txt | 1 + 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/sapl/legacy/scripts/exporta_zope/exporta_zope.py b/sapl/legacy/scripts/exporta_zope/exporta_zope.py index 4ddb1ea85..c3c7c753a 100755 --- a/sapl/legacy/scripts/exporta_zope/exporta_zope.py +++ b/sapl/legacy/scripts/exporta_zope/exporta_zope.py @@ -15,6 +15,7 @@ from contextlib import contextmanager from functools import partial from os.path import exists +import chardet import git import magic import yaml @@ -339,18 +340,10 @@ def find_sapl(app): return sapl -def detectar_encoding(fonte): - desc = magic.from_buffer(fonte) - for termo, enc in [('ISO-8859', 'latin1'), ('UTF-8', 'utf-8')]: - if termo in desc: - return enc - return None - - def autodecode(fonte): - if isinstance(fonte, str): - enc = detectar_encoding(fonte) - return fonte.decode(enc) if enc else fonte + if isinstance(fonte, str) and fonte.strip(): + enc = chardet.detect(fonte)['encoding'] + return fonte.decode(enc) else: return fonte diff --git a/sapl/legacy/scripts/exporta_zope/requirements.txt b/sapl/legacy/scripts/exporta_zope/requirements.txt index 69305576b..7468028a5 100644 --- a/sapl/legacy/scripts/exporta_zope/requirements.txt +++ b/sapl/legacy/scripts/exporta_zope/requirements.txt @@ -6,3 +6,4 @@ GitPython pyaml python-magic ipython +chardet