##// END OF EJS Templates
PEP8-ify several files
David Warde-Farley -
Show More
@@ -18,9 +18,11 b' from IPython.nbformat import current as nbformat'
18 # Class declarations
18 # Class declarations
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20
20
21
21 class ConversionException(Exception):
22 class ConversionException(Exception):
22 pass
23 pass
23
24
25
24 class DocStringInheritor(type):
26 class DocStringInheritor(type):
25 """
27 """
26 This metaclass will walk the list of bases until the desired
28 This metaclass will walk the list of bases until the desired
@@ -50,6 +52,7 b' class DocStringInheritor(type):'
50 newClassDict[attributeName] = attribute
52 newClassDict[attributeName] = attribute
51 return type.__new__(meta, classname, bases, newClassDict)
53 return type.__new__(meta, classname, bases, newClassDict)
52
54
55
53 class Converter(object):
56 class Converter(object):
54 __metaclass__ = DocStringInheritor
57 __metaclass__ = DocStringInheritor
55 default_encoding = 'utf-8'
58 default_encoding = 'utf-8'
@@ -85,9 +88,12 b' class Converter(object):'
85 return getattr(self, 'render_' + cell_type, self.render_unknown)
88 return getattr(self, 'render_' + cell_type, self.render_unknown)
86
89
87 def dispatch_display_format(self, format):
90 def dispatch_display_format(self, format):
88 """return output_type dependent render method, for example render_output_text
89 """
91 """
90 return getattr(self, 'render_display_format_' + format, self.render_unknown_display)
92 return output_type dependent render method, for example
93 render_output_text
94 """
95 return getattr(self, 'render_display_format_' + format,
96 self.render_unknown_display)
91
97
92 def convert(self, cell_separator='\n'):
98 def convert(self, cell_separator='\n'):
93 """
99 """
@@ -178,7 +184,8 b' class Converter(object):'
178 data = data.decode('base64')
184 data = data.decode('base64')
179 fopen = lambda fname: open(fname, 'wb')
185 fopen = lambda fname: open(fname, 'wb')
180 else:
186 else:
181 fopen = lambda fname: codecs.open(fname, 'wb', self.default_encoding)
187 fopen = lambda fname: codecs.open(fname, 'wb',
188 self.default_encoding)
182
189
183 with fopen(fullname) as f:
190 with fopen(fullname) as f:
184 f.write(data)
191 f.write(data)
@@ -267,7 +274,6 b' class Converter(object):'
267 Returns list."""
274 Returns list."""
268 raise NotImplementedError
275 raise NotImplementedError
269
276
270
271 def render_pyerr(self, output):
277 def render_pyerr(self, output):
272 """convert pyerr part of a code cell
278 """convert pyerr part of a code cell
273
279
@@ -320,4 +326,3 b' class Converter(object):'
320 Returns list.
326 Returns list.
321 """
327 """
322 raise NotImplementedError
328 raise NotImplementedError
323
@@ -1,6 +1,7 b''
1 from converters.html import ConverterHTML
1 from converters.html import ConverterHTML
2 import io
2 import io
3
3
4
4 class ConverterBloggerHTML(ConverterHTML):
5 class ConverterBloggerHTML(ConverterHTML):
5 """Convert a notebook to html suitable for easy pasting into Blogger.
6 """Convert a notebook to html suitable for easy pasting into Blogger.
6
7
@@ -18,4 +19,3 b' class ConverterBloggerHTML(ConverterHTML):'
18
19
19 def optional_footer(self):
20 def optional_footer(self):
20 return []
21 return []
21
@@ -2,6 +2,7 b' from converters.base import Converter'
2 from converters.utils import markdown2rst, rst_directive, remove_ansi
2 from converters.utils import markdown2rst, rst_directive, remove_ansi
3 from IPython.utils.text import indent
3 from IPython.utils.text import indent
4
4
5
5 class ConverterRST(Converter):
6 class ConverterRST(Converter):
6 extension = 'rst'
7 extension = 'rst'
7 heading_level = {1: '=', 2: '-', 3: '`', 4: '\'', 5: '.', 6: '~'}
8 heading_level = {1: '=', 2: '-', 3: '`', 4: '\'', 5: '.', 6: '~'}
@@ -67,7 +68,5 b' class ConverterRST(Converter):'
67 def render_display_format_json(self, output):
68 def render_display_format_json(self, output):
68 return rst_directive('.. raw:: json', output.json)
69 return rst_directive('.. raw:: json', output.json)
69
70
70
71 def render_display_format_javascript(self, output):
71 def render_display_format_javascript(self, output):
72 return rst_directive('.. raw:: javascript', output.javascript)
72 return rst_directive('.. raw:: javascript', output.javascript)
73
@@ -12,11 +12,13 b' from IPython.utils.text import indent'
12 from IPython.utils import path, py3compat
12 from IPython.utils import path, py3compat
13 from IPython.nbformat.v3.nbjson import BytesEncoder
13 from IPython.nbformat.v3.nbjson import BytesEncoder
14
14
15
15 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
16 # Utility functions
17 # Utility functions
17 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
18 def highlight(src, lang='ipython'):
19 def highlight(src, lang='ipython'):
19 """Return a syntax-highlighted version of the input source.
20 """
21 Return a syntax-highlighted version of the input source.
20 """
22 """
21 from pygments import highlight
23 from pygments import highlight
22 from pygments.lexers import get_lexer_by_name
24 from pygments.lexers import get_lexer_by_name
@@ -29,6 +31,7 b" def highlight(src, lang='ipython'):"
29
31
30 return highlight(src, lexer, HtmlFormatter())
32 return highlight(src, lexer, HtmlFormatter())
31
33
34
32 def output_container(f):
35 def output_container(f):
33 """add a prompt-area next to an output"""
36 """add a prompt-area next to an output"""
34 def wrapped(self, output):
37 def wrapped(self, output):
@@ -53,6 +56,7 b' def output_container(f):'
53
56
54 return wrapped
57 return wrapped
55
58
59
56 def text_cell(f):
60 def text_cell(f):
57 """wrap text cells in appropriate divs"""
61 """wrap text cells in appropriate divs"""
58 def wrapped(self, cell):
62 def wrapped(self, cell):
@@ -133,7 +137,9 b' def ansi2html(txt):'
133 while m:
137 while m:
134 cmds = m.groups()[0].split(';')
138 cmds = m.groups()[0].split(';')
135 closer = '</span>' if opened else ''
139 closer = '</span>' if opened else ''
136 opened = len(cmds) > 1 or cmds[0] != '0'*len(cmds[0]);
140 # True if there is there more than one element in cmds, *or*
141 # if there is only one but it is not equal to a string of zeroes.
142 opened = len(cmds) > 1 or cmds[0] != '0' * len(cmds[0])
137 classes = []
143 classes = []
138 for cmd in cmds:
144 for cmd in cmds:
139 if cmd in ansi_colormap:
145 if cmd in ansi_colormap:
@@ -270,8 +276,8 b' def rst2simplehtml(infile):'
270 walker = iter(html.splitlines())
276 walker = iter(html.splitlines())
271
277
272 # Find start of main text, break out to then print until we find end /div.
278 # Find start of main text, break out to then print until we find end /div.
273 # This may only work if there's a real title defined so we get a 'div class'
279 # This may only work if there's a real title defined so we get a 'div
274 # tag, I haven't really tried.
280 # class' tag, I haven't really tried.
275 for line in walker:
281 for line in walker:
276 if line.startswith('<body>'):
282 if line.startswith('<body>'):
277 break
283 break
@@ -286,6 +292,7 b' def rst2simplehtml(infile):'
286
292
287 return newfname
293 return newfname
288
294
295
289 #-----------------------------------------------------------------------------
296 #-----------------------------------------------------------------------------
290 # Cell-level functions -- similar to IPython.nbformat.v3.rwbase functions
297 # Cell-level functions -- similar to IPython.nbformat.v3.rwbase functions
291 # but at cell level instead of whole notebook level
298 # but at cell level instead of whole notebook level
General Comments 0
You need to be logged in to leave comments. Login now