##// END OF EJS Templates
inherit from Unicode
Sylvain Corlay -
Show More
@@ -17,13 +17,12 b" _color_names = ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'bei"
17 17 _color_re = re.compile(r'#[a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?$')
18 18
19 19
20 class Color(traitlets._CoercedString):
20 class Color(traitlets.Unicode):
21 21 """A string holding a valid HTML color such as 'blue', '#060482', '#A80'"""
22 22
23 23 info_text = 'a valid HTML color'
24 24
25 25 def validate(self, obj, value):
26 value = self._coerce_str(obj, value)
27 26 if value.lower() in _color_names or _color_re.match(value):
28 27 return value
29 self.error(obj, value) No newline at end of file
28 self.error(obj, value)
@@ -1288,14 +1288,19 b' class CUnicode(Unicode):'
1288 1288 self.error(obj, value)
1289 1289
1290 1290
1291 class _CoercedString(TraitType):
1291 class ObjectName(TraitType):
1292 """A string holding a valid object name in this version of Python.
1293
1294 This does not check that the name exists in any scope."""
1295 info_text = "a valid object identifier in Python"
1292 1296
1293 1297 if py3compat.PY3:
1294 1298 # Python 3:
1295 _coerce_str = staticmethod(lambda _,s: s)
1299 coerce_str = staticmethod(lambda _,s: s)
1300
1296 1301 else:
1297 1302 # Python 2:
1298 def _coerce_str(self, obj, value):
1303 def coerce_str(self, obj, value):
1299 1304 "In Python 2, coerce ascii-only unicode to str"
1300 1305 if isinstance(value, unicode):
1301 1306 try:
@@ -1304,27 +1309,17 b' class _CoercedString(TraitType):'
1304 1309 self.error(obj, value)
1305 1310 return value
1306 1311
1307
1308 class ObjectName(_CoercedString):
1309 """A string holding a valid object name in this version of Python.
1310
1311 This does not check that the name exists in any scope."""
1312
1313 info_text = "a valid object identifier in Python"
1314
1315 1312 def validate(self, obj, value):
1316 value = self._coerce_str(obj, value)
1313 value = self.coerce_str(obj, value)
1317 1314
1318 1315 if isinstance(value, string_types) and py3compat.isidentifier(value):
1319 1316 return value
1320 1317 self.error(obj, value)
1321 1318
1322
1323 1319 class DottedObjectName(ObjectName):
1324 1320 """A string holding a valid dotted object name in Python, such as A.b3._c"""
1325
1326 1321 def validate(self, obj, value):
1327 value = self._coerce_str(obj, value)
1322 value = self.coerce_str(obj, value)
1328 1323
1329 1324 if isinstance(value, string_types) and py3compat.isidentifier(value, dotted=True):
1330 1325 return value
General Comments 0
You need to be logged in to leave comments. Login now