##// END OF EJS Templates
Arrange Str and Bytes traitlets to simplify automatic conversion to Python 3.
Thomas Kluyver -
Show More
@@ -952,24 +952,24 b' class CComplex(Complex):'
952 952 self.error(obj, value)
953 953
954 954
955 class Str(TraitType):
955 class Bytes(TraitType):
956 956 """A trait for strings."""
957 957
958 958 default_value = ''
959 959 info_text = 'a string'
960 960
961 961 def validate(self, obj, value):
962 if isinstance(value, str):
962 if isinstance(value, bytes):
963 963 return value
964 964 self.error(obj, value)
965 965
966 966
967 class CStr(Str):
967 class CBytes(Bytes):
968 968 """A casting version of the string trait."""
969 969
970 970 def validate(self, obj, value):
971 971 try:
972 return str(value)
972 return bytes(value)
973 973 except:
974 974 try:
975 975 return unicode(value)
@@ -986,7 +986,7 b' class Unicode(TraitType):'
986 986 def validate(self, obj, value):
987 987 if isinstance(value, unicode):
988 988 return value
989 if isinstance(value, str):
989 if isinstance(value, bytes):
990 990 return unicode(value)
991 991 self.error(obj, value)
992 992
@@ -999,6 +999,11 b' class CUnicode(Unicode):'
999 999 return unicode(value)
1000 1000 except:
1001 1001 self.error(obj, value)
1002
1003 if sys.version_info[0] < 3:
1004 Str, CStr = Bytes, CBytes
1005 else:
1006 Str, CStr = Unicode, CUnicode
1002 1007
1003 1008
1004 1009 class Bool(TraitType):
General Comments 0
You need to be logged in to leave comments. Login now