##// END OF EJS Templates
Merge pull request #7181 from jhamrick/extension-traitlet...
Min RK -
r19474:7b625264 merge
parent child Browse files
Show More
@@ -8,4 +8,4 b' from .notebook import NotebookExporter'
8 8 from .pdf import PDFExporter
9 9 from .python import PythonExporter
10 10 from .rst import RSTExporter
11 from .exporter import Exporter
11 from .exporter import Exporter, FilenameExtension
@@ -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, Unicode, List, TraitError
18 18 from IPython.utils.importstring import import_item
19 19 from IPython.utils import text, py3compat
20 20
@@ -24,6 +24,24 b' class ResourcesDict(collections.defaultdict):'
24 24 return ''
25 25
26 26
27 class FilenameExtension(Unicode):
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 # cast to proper unicode
35 value = super(FilenameExtension, self).validate(obj, value)
36
37 # check that it starts with a dot
38 if value and not value.startswith('.'):
39 msg = "FileExtension trait '{}' does not begin with a dot: {!r}"
40 raise TraitError(msg.format(self.name, value))
41
42 return value
43
44
27 45 class Exporter(LoggingConfigurable):
28 46 """
29 47 Class containing methods that sequentially run a list of preprocessors on a
@@ -31,7 +49,7 b' class Exporter(LoggingConfigurable):'
31 49 accompanying resources dict.
32 50 """
33 51
34 file_extension = Unicode(
52 file_extension = FilenameExtension(
35 53 '.txt', config=True,
36 54 help="Extension of the file that should be written to disk"
37 55 )
General Comments 0
You need to be logged in to leave comments. Login now