##// END OF EJS Templates
Add extension traitlet to force dotted names
Jessica B. Hamrick -
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, Unicode, List
17 from IPython.utils.traitlets import MetaHasTraits, TraitType, List, TraitError
18 18 from IPython.utils.importstring import import_item
19 19 from IPython.utils import text, py3compat
20 20
@@ -24,6 +24,27 b' class ResourcesDict(collections.defaultdict):'
24 24 return ''
25 25
26 26
27 class Extension(TraitType):
28 """A trait for filename extensions."""
29
30 default_value = u''
31 info_text = 'a filename extension, beginning with a dot'
32
33 def validate(self, obj, value):
34 if isinstance(value, bytes):
35 try:
36 value = value.decode('ascii', 'strict')
37 except UnicodeDecodeError:
38 msg = "Could not decode {!r} for extension trait '{}'."
39 raise TraitError(msg.format(value, self.name))
40
41 if not value.startswith('.'):
42 msg = "Extension trait '{}' does not begin with a dot: {!r}"
43 raise TraitError(msg.format(self.name, value))
44
45 return value
46
47
27 48 class Exporter(LoggingConfigurable):
28 49 """
29 50 Class containing methods that sequentially run a list of preprocessors on a
@@ -31,7 +52,7 b' class Exporter(LoggingConfigurable):'
31 52 accompanying resources dict.
32 53 """
33 54
34 file_extension = Unicode(
55 file_extension = Extension(
35 56 '.txt', config=True,
36 57 help="Extension of the file that should be written to disk"
37 58 )
General Comments 0
You need to be logged in to leave comments. Login now