From 889ef3f2e7abbdb412c506c20f91eb355eb63107 2015-03-21 18:45:28 From: Sylvain Corlay Date: 2015-03-21 18:45:28 Subject: [PATCH] inherit from Unicode --- diff --git a/IPython/html/widgets/trait_types.py b/IPython/html/widgets/trait_types.py index cef80db..e09caaa 100644 --- a/IPython/html/widgets/trait_types.py +++ b/IPython/html/widgets/trait_types.py @@ -17,13 +17,12 @@ _color_names = ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'bei _color_re = re.compile(r'#[a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?$') -class Color(traitlets._CoercedString): +class Color(traitlets.Unicode): """A string holding a valid HTML color such as 'blue', '#060482', '#A80'""" info_text = 'a valid HTML color' def validate(self, obj, value): - value = self._coerce_str(obj, value) if value.lower() in _color_names or _color_re.match(value): return value - self.error(obj, value) \ No newline at end of file + self.error(obj, value) diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py index 38a56e4..7d3c5f1 100644 --- a/IPython/utils/traitlets.py +++ b/IPython/utils/traitlets.py @@ -1288,14 +1288,19 @@ class CUnicode(Unicode): self.error(obj, value) -class _CoercedString(TraitType): +class ObjectName(TraitType): + """A string holding a valid object name in this version of Python. + + This does not check that the name exists in any scope.""" + info_text = "a valid object identifier in Python" if py3compat.PY3: # Python 3: - _coerce_str = staticmethod(lambda _,s: s) + coerce_str = staticmethod(lambda _,s: s) + else: # Python 2: - def _coerce_str(self, obj, value): + def coerce_str(self, obj, value): "In Python 2, coerce ascii-only unicode to str" if isinstance(value, unicode): try: @@ -1304,27 +1309,17 @@ class _CoercedString(TraitType): self.error(obj, value) return value - -class ObjectName(_CoercedString): - """A string holding a valid object name in this version of Python. - - This does not check that the name exists in any scope.""" - - info_text = "a valid object identifier in Python" - def validate(self, obj, value): - value = self._coerce_str(obj, value) + value = self.coerce_str(obj, value) if isinstance(value, string_types) and py3compat.isidentifier(value): return value self.error(obj, value) - class DottedObjectName(ObjectName): """A string holding a valid dotted object name in Python, such as A.b3._c""" - def validate(self, obj, value): - value = self._coerce_str(obj, value) + value = self.coerce_str(obj, value) if isinstance(value, string_types) and py3compat.isidentifier(value, dotted=True): return value