Show More
@@ -952,24 +952,24 b' class CComplex(Complex):' | |||||
952 | self.error(obj, value) |
|
952 | self.error(obj, value) | |
953 |
|
953 | |||
954 |
|
954 | |||
955 |
class |
|
955 | class Bytes(TraitType): | |
956 | """A trait for strings.""" |
|
956 | """A trait for strings.""" | |
957 |
|
957 | |||
958 | default_value = '' |
|
958 | default_value = '' | |
959 | info_text = 'a string' |
|
959 | info_text = 'a string' | |
960 |
|
960 | |||
961 | def validate(self, obj, value): |
|
961 | def validate(self, obj, value): | |
962 |
if isinstance(value, |
|
962 | if isinstance(value, bytes): | |
963 | return value |
|
963 | return value | |
964 | self.error(obj, value) |
|
964 | self.error(obj, value) | |
965 |
|
965 | |||
966 |
|
966 | |||
967 |
class C |
|
967 | class CBytes(Bytes): | |
968 | """A casting version of the string trait.""" |
|
968 | """A casting version of the string trait.""" | |
969 |
|
969 | |||
970 | def validate(self, obj, value): |
|
970 | def validate(self, obj, value): | |
971 | try: |
|
971 | try: | |
972 |
return |
|
972 | return bytes(value) | |
973 | except: |
|
973 | except: | |
974 | try: |
|
974 | try: | |
975 | return unicode(value) |
|
975 | return unicode(value) | |
@@ -986,7 +986,7 b' class Unicode(TraitType):' | |||||
986 | def validate(self, obj, value): |
|
986 | def validate(self, obj, value): | |
987 | if isinstance(value, unicode): |
|
987 | if isinstance(value, unicode): | |
988 | return value |
|
988 | return value | |
989 |
if isinstance(value, |
|
989 | if isinstance(value, bytes): | |
990 | return unicode(value) |
|
990 | return unicode(value) | |
991 | self.error(obj, value) |
|
991 | self.error(obj, value) | |
992 |
|
992 | |||
@@ -999,6 +999,11 b' class CUnicode(Unicode):' | |||||
999 | return unicode(value) |
|
999 | return unicode(value) | |
1000 | except: |
|
1000 | except: | |
1001 | self.error(obj, value) |
|
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 | class Bool(TraitType): |
|
1009 | class Bool(TraitType): |
General Comments 0
You need to be logged in to leave comments.
Login now