misc: adapt de/encoding in import zip (#36515)
This commit is contained in:
parent
4322fe9f64
commit
48118f8781
|
@ -14,7 +14,8 @@ from django.core.management import call_command
|
|||
from django.core.management.base import CommandError
|
||||
from django.http import Http404
|
||||
from django.test import override_settings
|
||||
from django.utils.six import StringIO
|
||||
from django.utils import six
|
||||
from django.utils.six import BytesIO, StringIO
|
||||
from quixote import cleanup
|
||||
from wcs.qommon import get_publisher_class
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
|
@ -147,7 +148,7 @@ def test_import_config_zip():
|
|||
pub.cfg['sp'] = {'what': 'ever'}
|
||||
pub.write_cfg()
|
||||
|
||||
c = StringIO()
|
||||
c = BytesIO()
|
||||
z = zipfile.ZipFile(c, 'w')
|
||||
z.writestr('config.pck', pickle.dumps(
|
||||
{'language': {'language': 'fr'},
|
||||
|
@ -160,7 +161,7 @@ def test_import_config_zip():
|
|||
assert pub.cfg['whatever'] == ['a', 'b', 'c']
|
||||
assert pub.cfg['sp'] == {'what': 'ever'}
|
||||
|
||||
c = StringIO()
|
||||
c = BytesIO()
|
||||
z = zipfile.ZipFile(c, 'w')
|
||||
z.writestr('config.json', json.dumps(
|
||||
{'language': {'language': 'en'},
|
||||
|
@ -171,8 +172,9 @@ def test_import_config_zip():
|
|||
pub.import_zip(c)
|
||||
assert pub.cfg['language'] == {'language': 'en'}
|
||||
assert pub.cfg['sp'] == {'what': 'ever'}
|
||||
assert not isinstance(pub.cfg['language'], unicode)
|
||||
assert not isinstance(pub.cfg['whatever2'][-1]['c'], unicode)
|
||||
if six.PY2:
|
||||
assert not isinstance(pub.cfg['language'], unicode)
|
||||
assert not isinstance(pub.cfg['whatever2'][-1]['c'], unicode)
|
||||
|
||||
def test_cron_command():
|
||||
pub = create_temporary_pub()
|
||||
|
|
|
@ -21,6 +21,7 @@ import sys
|
|||
import traceback
|
||||
import zipfile
|
||||
|
||||
from django.utils import six
|
||||
from django.utils.six.moves import cPickle
|
||||
|
||||
from .Defaults import *
|
||||
|
@ -30,6 +31,7 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
from wcs.qommon import force_str
|
||||
from .qommon.publisher import set_publisher_class, QommonPublisher, get_request
|
||||
|
||||
# this is terribly ugly but import RootDirectory will import a bunch of things,
|
||||
|
@ -160,8 +162,8 @@ class WcsPublisher(StubWcsPublisher):
|
|||
def _decode_list(data):
|
||||
rv = []
|
||||
for item in data:
|
||||
if isinstance(item, unicode):
|
||||
item = item.encode(self.site_charset)
|
||||
if isinstance(item, six.string_types):
|
||||
item = force_str(item)
|
||||
elif isinstance(item, list):
|
||||
item = _decode_list(item)
|
||||
elif isinstance(item, dict):
|
||||
|
@ -172,10 +174,9 @@ class WcsPublisher(StubWcsPublisher):
|
|||
def _decode_dict(data):
|
||||
rv = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(key, unicode):
|
||||
key = key.encode(self.site_charset)
|
||||
if isinstance(value, unicode):
|
||||
value = value.encode(self.site_charset)
|
||||
key = force_str(key)
|
||||
if isinstance(value, six.string_types):
|
||||
value = force_str(value)
|
||||
elif isinstance(value, list):
|
||||
value = _decode_list(value)
|
||||
elif isinstance(value, dict):
|
||||
|
|
Loading…
Reference in New Issue