actesweb: force iso-8859-15 encoding (#38781)
This commit is contained in:
parent
064e8fd187
commit
e491403605
|
@ -23,8 +23,8 @@ import contextlib
|
|||
|
||||
from django.core.files.storage import default_storage
|
||||
from django.template.loader import get_template
|
||||
from django.utils import six
|
||||
from django.utils.dateparse import parse_date
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -32,14 +32,9 @@ from passerelle.base.models import BaseResource
|
|||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.conversion import ensure_encoding
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def named_tempfile(*args, **kwargs):
|
||||
with tempfile.NamedTemporaryFile(*args, **kwargs) as fp:
|
||||
if six.PY2:
|
||||
import codecs
|
||||
fp = codecs.getwriter('iso-8859-15')(fp)
|
||||
yield fp
|
||||
|
||||
|
||||
|
@ -87,7 +82,7 @@ class ActesWeb(BaseResource):
|
|||
filename = '%s.DEM' % now().strftime('%Y-%m-%d_%H-%M-%S_%f')
|
||||
filepath = os.path.join(self.basepath, filename)
|
||||
with named_tempfile(dir=tmp_dir, suffix='.DEM', delete=False) as tpf:
|
||||
tpf.write(demand_content)
|
||||
tpf.write(force_bytes(demand_content, 'iso-8859-15'))
|
||||
tpf.flush()
|
||||
os.fsync(tpf.file.fileno())
|
||||
tempfile_name = tpf.name
|
||||
|
|
|
@ -69,12 +69,9 @@ def get_demand_filepath(con, demand_id):
|
|||
|
||||
|
||||
def assert_file_content_values(filename, expectations):
|
||||
with io.open(filename, 'rb') as fp:
|
||||
with io.open(filename, 'r', encoding='iso-8859-15') as fp:
|
||||
for line in fp.readlines():
|
||||
if six.PY2:
|
||||
field, value = line.decode('iso-8859-15').split('=')
|
||||
else:
|
||||
field, value = line.split('=')
|
||||
field, value = line.split('=')
|
||||
if field in expectations:
|
||||
assert value.strip() == expectations[field]
|
||||
|
||||
|
|
Loading…
Reference in New Issue