Replace unicode with str, duck type encode
This commit is contained in:
parent
ba7109a6b9
commit
426095634c
@ -1,6 +1,11 @@
|
||||
import json
|
||||
import yaml
|
||||
|
||||
try:
|
||||
str = unicode
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
from dataset.util import FreezeException
|
||||
|
||||
|
||||
@ -35,7 +40,7 @@ class Configuration(object):
|
||||
raise FreezeException("Invalid freeze file: %s" % ve)
|
||||
fh.close()
|
||||
except IOError as ioe:
|
||||
raise FreezeException(unicode(ioe))
|
||||
raise FreezeException(str(ioe))
|
||||
|
||||
@property
|
||||
def exports(self):
|
||||
@ -59,7 +64,7 @@ class Export(object):
|
||||
def get_normalized(self, name, default=None):
|
||||
value = self.get(name, default=default)
|
||||
if not value in [None, default]:
|
||||
value = unicode(value).lower().strip()
|
||||
value = str(value).lower().strip()
|
||||
return value
|
||||
|
||||
def get_bool(self, name, default=False):
|
||||
|
||||
@ -3,6 +3,11 @@ import logging
|
||||
import re
|
||||
import locale
|
||||
|
||||
try:
|
||||
str = unicode
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
from dataset.util import FreezeException
|
||||
from slugify import slugify
|
||||
|
||||
@ -11,7 +16,7 @@ TMPL_KEY = re.compile("{{([^}]*)}}")
|
||||
|
||||
OPERATIONS = {
|
||||
'identity': lambda x: x,
|
||||
'lower': lambda x: unicode(x).lower(),
|
||||
'lower': lambda x: str(x).lower(),
|
||||
'slug': slugify
|
||||
}
|
||||
|
||||
@ -39,7 +44,7 @@ class Serializer(object):
|
||||
op, key = 'identity', m.group(1)
|
||||
if ':' in key:
|
||||
op, key = key.split(':', 1)
|
||||
return unicode(OPERATIONS.get(op)(data.get(key, '')))
|
||||
return str(OPERATIONS.get(op)(data.get(key, '')))
|
||||
path = TMPL_KEY.sub(repl, self._basepath)
|
||||
enc = locale.getpreferredencoding()
|
||||
return os.path.realpath(path.encode(enc, 'replace'))
|
||||
@ -74,8 +79,6 @@ class Serializer(object):
|
||||
|
||||
for field, operation in transforms.items():
|
||||
row[field] = OPERATIONS.get(operation)(row.get(field))
|
||||
|
||||
|
||||
self.write(self.file_name(row), row)
|
||||
self.close()
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ from dataset.freeze.format.common import Serializer
|
||||
def value_to_str(value):
|
||||
if isinstance(value, datetime):
|
||||
return value.isoformat()
|
||||
if isinstance(value, unicode):
|
||||
if hasattr(value, 'encode'):
|
||||
return value.encode('utf-8')
|
||||
if value is None:
|
||||
return ''
|
||||
|
||||
Loading…
Reference in New Issue
Block a user