From 0429cbea1262e08d3264a182938e603d70592571 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Sat, 6 Apr 2013 22:49:48 -0400 Subject: [PATCH] Using punycode where we can. --- hy/compiler.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hy/compiler.py b/hy/compiler.py index bb3aaed..247319d 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -29,6 +29,7 @@ from hy.models.dict import HyDict from hy.util import flatten_literal_list +import codecs import ast import sys @@ -44,7 +45,14 @@ def ast_str(foobar): if sys.version_info[0] >= 3: return str(foobar) - return str(foobar.encode("ascii", 'backslashreplace')) + try: + return str(foobar) + except UnicodeEncodeError: + pass + + enc = codecs.getencoder('punycode') + foobar, _ = enc(foobar) + return str(foobar).replace("-", "_") def builds(_type):