Show More
@@ -8,4 +8,4 b' from .notebook import NotebookExporter' | |||||
8 | from .pdf import PDFExporter |
|
8 | from .pdf import PDFExporter | |
9 | from .python import PythonExporter |
|
9 | from .python import PythonExporter | |
10 | from .rst import RSTExporter |
|
10 | from .rst import RSTExporter | |
11 | from .exporter import Exporter |
|
11 | from .exporter import Exporter, FilenameExtension |
@@ -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, Unicode, List |
|
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,6 +24,24 b' class ResourcesDict(collections.defaultdict):' | |||||
24 | return '' |
|
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 | class Exporter(LoggingConfigurable): |
|
45 | class Exporter(LoggingConfigurable): | |
28 | """ |
|
46 | """ | |
29 | Class containing methods that sequentially run a list of preprocessors on a |
|
47 | Class containing methods that sequentially run a list of preprocessors on a | |
@@ -31,7 +49,7 b' class Exporter(LoggingConfigurable):' | |||||
31 | accompanying resources dict. |
|
49 | accompanying resources dict. | |
32 | """ |
|
50 | """ | |
33 |
|
51 | |||
34 |
file_extension = |
|
52 | file_extension = FilenameExtension( | |
35 | '.txt', config=True, |
|
53 | '.txt', config=True, | |
36 | help="Extension of the file that should be written to disk" |
|
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