From 80e27d286b61ea873ec0caa615ecfbae0f5fe8a3 Mon Sep 17 00:00:00 2001 From: Florent Gallaire Date: Tue, 6 Sep 2016 01:36:36 +0200 Subject: [PATCH] Add Python 3 support --- cjkwrap.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cjkwrap.py b/cjkwrap.py index 0b2698e..5fdfb90 100644 --- a/cjkwrap.py +++ b/cjkwrap.py @@ -27,6 +27,14 @@ import textwrap import unicodedata +import sys + +PY3 = sys.version[0] == '3' + +if PY3: + text_type = str +else: + text_type = unicode def cjklen(text): @@ -35,7 +43,7 @@ def cjklen(text): Return the real width of a text. Fullwidth and Wide CJK chars are double-width. """ - if not isinstance(text, unicode): + if not isinstance(text, text_type): return len(text) l = 0 for char in text: @@ -51,7 +59,7 @@ def cjkslices(text, index): Return the two slices of a text cut to the index. """ - if not isinstance(text, unicode): + if not isinstance(text, text_type): return text[:index], text[index:] if cjklen(text) <= index: return text, u''