Show More
@@ -14,7 +14,7 b' import datetime' | |||
|
14 | 14 | from IPython.config.configurable import LoggingConfigurable |
|
15 | 15 | from IPython.config import Config |
|
16 | 16 | from IPython import nbformat |
|
17 |
from IPython.utils.traitlets import MetaHasTraits, |
|
|
17 | from IPython.utils.traitlets import MetaHasTraits, Unicode, List, TraitError | |
|
18 | 18 | from IPython.utils.importstring import import_item |
|
19 | 19 | from IPython.utils import text, py3compat |
|
20 | 20 | |
@@ -24,19 +24,22 b' class ResourcesDict(collections.defaultdict):' | |||
|
24 | 24 | return '' |
|
25 | 25 | |
|
26 | 26 | |
|
27 |
class FilenameExtension( |
|
|
27 | class FilenameExtension(Unicode): | |
|
28 | 28 | """A trait for filename extensions.""" |
|
29 | 29 | |
|
30 | 30 | default_value = u'' |
|
31 | 31 | info_text = 'a filename extension, beginning with a dot' |
|
32 | 32 | |
|
33 | 33 | def validate(self, obj, value): |
|
34 | try: | |
|
35 | value = py3compat.cast_unicode_py2(value) | |
|
36 | except UnicodeDecodeError: | |
|
37 | msg = "Could not decode {!r} for FileExtension trait '{}'." | |
|
38 | raise TraitError(msg.format(value, self.name)) | |
|
34 | # cast to proper unicode | |
|
35 | value = super(FilenameExtension, self).validate(obj, value) | |
|
39 | 36 | |
|
37 | # make sure the value is actually unicode | |
|
38 | if not isinstance(value, py3compat.unicode_type): | |
|
39 | msg = "FileExtension trait '{}' is not of type '{}'" | |
|
40 | raise TraitError(msg.format(self.name, py3compat.unicode_type)) | |
|
41 | ||
|
42 | # check that it starts with a dot | |
|
40 | 43 | if not value.startswith('.'): |
|
41 | 44 | msg = "FileExtension trait '{}' does not begin with a dot: {!r}" |
|
42 | 45 | raise TraitError(msg.format(self.name, value)) |
General Comments 0
You need to be logged in to leave comments.
Login now