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