Skip to content

Commit

Permalink
UTF encode unicode objects
Browse files Browse the repository at this point in the history
  • Loading branch information
reubano committed Feb 24, 2015
1 parent 5cb3678 commit d253cf0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pipe2py/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
memoize = cache.memoize
timeout = 60 * 60 * 1

encode = lambda w: w.encode('utf-8') if isinstance(w, unicode) else w

class Objectify:
def __init__(self, **entries):
Expand Down Expand Up @@ -189,8 +190,8 @@ def get_value(field, item=None, force=False, **kwargs):
OPS = {
'number': {'default': 0.0, 'func': float},
'integer': {'default': 0, 'func': int},
'text': {'default': ''},
'unicode': {'default': '', 'func': unicode},
'text': {'default': '', 'func': lambda i: str(encode(i))},
'unicode': {'default': u'', 'func': unicode},
'bool': {'default': False, 'func': lambda i: bool(int(i))},
}

Expand Down Expand Up @@ -312,10 +313,8 @@ def get_input(context, conf):
value = context.inputs.get(name, default)
elif not context.test:
# we skip user interaction during tests
value = raw_input(
"%s (default=%s) " % (
prompt.encode('utf-8'), default.encode('utf-8'))
) or default
raw = raw_input("%s (default=%s) " % (encode(prompt), encode(default)))
value = raw or default
else:
value = default

Expand Down Expand Up @@ -345,7 +344,7 @@ def get_word(item):
except TypeError:
word = None

return str(word.encode('utf-8')) if isinstance(word, unicode) else word
return str(encode(word) or '')


def get_num(item):
Expand Down Expand Up @@ -380,7 +379,7 @@ def url_quote(url):
try:
return quote(url, safe=URL_SAFE)
except KeyError:
return quote(url.encode('utf-8'), safe=URL_SAFE)
return quote(encode(url), safe=URL_SAFE)


def listize(item):
Expand Down

0 comments on commit d253cf0

Please sign in to comment.