Browse Source

Conserta erro no autodecode

migracao
Marcio Mazza 6 years ago
parent
commit
556fb8877b
  1. 15
      sapl/legacy/scripts/exporta_zope/exporta_zope.py
  2. 1
      sapl/legacy/scripts/exporta_zope/requirements.txt

15
sapl/legacy/scripts/exporta_zope/exporta_zope.py

@ -15,6 +15,7 @@ from contextlib import contextmanager
from functools import partial from functools import partial
from os.path import exists from os.path import exists
import chardet
import git import git
import magic import magic
import yaml import yaml
@ -339,18 +340,10 @@ def find_sapl(app):
return sapl 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): def autodecode(fonte):
if isinstance(fonte, str): if isinstance(fonte, str) and fonte.strip():
enc = detectar_encoding(fonte) enc = chardet.detect(fonte)['encoding']
return fonte.decode(enc) if enc else fonte return fonte.decode(enc)
else: else:
return fonte return fonte

1
sapl/legacy/scripts/exporta_zope/requirements.txt

@ -6,3 +6,4 @@ GitPython
pyaml pyaml
python-magic python-magic
ipython ipython
chardet

Loading…
Cancel
Save