[python-meh] [PATCH] Handle non-ascii dict keys and values correctly (#883641)

Vratislav Podzimek vpodzime at redhat.com
Thu Dec 6 11:40:30 UTC 2012


On Wed, 2012-12-05 at 10:55 +0100, Vratislav Podzimek wrote:
> Also add such case to the handle_unicode unittest.
> 
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
>  meh/dump.py             | 4 ++++
>  tests/handle_unicode.py | 1 +
>  2 files changed, 5 insertions(+)
> 
> diff --git a/meh/dump.py b/meh/dump.py
> index 6537990..81751d2 100644
> --- a/meh/dump.py
> +++ b/meh/dump.py
> @@ -352,10 +352,14 @@ class ExceptionDump(object):
>                          first = 0
>                      if type(k) == types.StringType:
>                          ret += "'%s': " % (k,)
> +                    elif type(k) == types.UnicodeType:
> +                        ret += "'%s': " % k.encode("utf-8")
>                      else:
>                          ret += "%s: " % (k,)
>  
>                      if __isSimpleType(v):
> +                        if type(v) == types.UnicodeType:
> +                            v = v.encode("utf-8")
>                          ret += "%s" % (v,)
>                      else:
>                          ret += self._dumpClass(v, level + 1, parentkey = curkey, skipList=skipList)
> diff --git a/tests/handle_unicode.py b/tests/handle_unicode.py
> index 6ae67d7..65fc297 100644
> --- a/tests/handle_unicode.py
> +++ b/tests/handle_unicode.py
> @@ -14,6 +14,7 @@ class UnicodeExample(object):
>          self.ascii_str = ASCII_STR
>          self.unicode_str = UNICODE_STR
>          self.encoded_str = self.unicode_str.encode("utf-8")
> +        self.unicode_dict = { "úú" : "áá" }
These should be u"úú" and u"áá". Fixed locally.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list