2323from colorama import init
2424init ()
2525from colorama import Fore , Back , Style
26+ from .util import unicode , bytes , basestring
2627
2728try :
2829 import curses
3738# literal non-ascii characters).
3839# todo _ can remove this, this next 10 lines is from
3940# http://www.rfk.id.au/blog/entry/preparing-pyenchant-for-python-3/
40- if not isinstance ('' , type (b'' )):
41- def u (s ):
42- return s
43- bytes_type = bytes
44- unicode_type = str
45- basestring_type = str
46- else :
47- def u (s ):
48- return s .decode ('unicode_escape' )
49- bytes_type = str
50- unicode_type = unicode
51- basestring_type = basestring
52-
53-
54- _UTF8_TYPES = (bytes_type , type (None ))
55- _TO_UNICODE_TYPES = (unicode_type , type (None ))
41+ _UTF8_TYPES = (bytes , type (None ))
42+ _TO_UNICODE_TYPES = (unicode , type (None ))
5643
5744
5845def utf8 (value ):
@@ -63,7 +50,7 @@ def utf8(value):
6350 """
6451 if isinstance (value , _UTF8_TYPES ):
6552 return value
66- assert isinstance (value , unicode_type ), \
53+ assert isinstance (value , unicode ), \
6754 "Expected bytes, unicode, or None; got %r" % type (value )
6855 return value .encode ("utf-8" )
6956
@@ -76,7 +63,7 @@ def to_unicode(value):
7663 """
7764 if isinstance (value , _TO_UNICODE_TYPES ):
7865 return value
79- assert isinstance (value , bytes_type ), \
66+ assert isinstance (value , bytes ), \
8067 "Expected bytes, unicode, or None; got %r" % type (value )
8168 return value .decode ("utf-8" )
8269
@@ -86,7 +73,7 @@ def to_unicode(value):
8673
8774# When dealing with the standard library across python 2 and 3 it is
8875# sometimes useful to have a direct conversion to the native string type
89- if str is unicode_type :
76+ if str is unicode :
9077 native_str = to_unicode
9178else :
9279 native_str = utf8
@@ -181,7 +168,7 @@ def format(self, record):
181168 except Exception as e :
182169 record .message = "Bad message (%r): %r" % (e , record .__dict__ )
183170 assert isinstance (
184- record .message , basestring_type ) # guaranteed by logging
171+ record .message , basestring ) # guaranteed by logging
185172
186173 date_format = '%H:%m:%S'
187174 record .asctime = time .strftime (date_format , self .converter (record .created ))
0 commit comments