Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

code reformatting to conform to pep8

  • Loading branch information...
commit 5e736fd0cb5b071a6c2be2fdce5711587c9b8eb1 1 parent ee8a8b8
@n1k0 n1k0 authored
View
2  docs/index.rst
@@ -11,7 +11,7 @@ Landslide requires Python_ v2.5 minimum and these dependencies installed:
* The Jinja2_ template engine
* Pygments_ for code syntax highlighting
-One of the syntax handlers above :
+One of the syntax handlers above:
* The Markdown_ python library if you intend to write your slides contents using the Markdown_ syntax
* or the docutils_ package if you rather prefer using reStructuredText_.
View
6 src/landslide/generator.py
@@ -50,7 +50,7 @@ class Generator(object):
def __init__(self, source, destination_file='presentation.html',
theme='default', direct=False, debug=False, verbose=True,
embed=False, encoding='utf8', logger=None):
- """Configures this generator from its properties."""
+ """Configures the generator."""
self.debug = debug
self.direct = direct
self.encoding = encoding
@@ -78,8 +78,8 @@ def __init__(self, source, destination_file='presentation.html',
config.read(source)
except Exception, e:
raise RuntimeError(u"Invalid configuration file: %s" % e)
- self.source = (config.get('landslide', 'source')
- .replace('\r', '').split('\n'))
+ self.source = config.get('landslide', 'source')\
+ .replace('\r', '').split('\n')
if config.has_option('landslide', 'theme'):
theme = config.get('landslide', 'theme')
self.log(u"Using configured theme %s" % theme)
View
5 src/landslide/macro.py
@@ -47,8 +47,7 @@ class CodeHighlightingMacro(Macro):
"""
code_blocks_re = re.compile(
r'(<pre.+?>(<code>)?\s?!(\w+?)\n(.*?)(</code>)?</pre>)',
- re.UNICODE | re.MULTILINE | re.DOTALL
- )
+ re.UNICODE | re.MULTILINE | re.DOTALL)
html_entity_re = re.compile('&(\w+?);')
@@ -94,7 +93,7 @@ def process(self, content, source=None):
re.DOTALL | re.UNICODE)
if not images:
- return content, []
+ return content, classes
for image_url in images:
if not image_url or image_url.startswith('data:'):
View
27 src/landslide/main.py
@@ -33,16 +33,14 @@ def _parse_options():
description="Generates an HTML5 or PDF "
"slideshow from Markdown or other formats",
epilog="Note: PDF export requires the `prince` program: "
- "http://princexml.com/"
- )
+ "http://princexml.com/")
parser.add_option(
"-b", "--debug",
action="store_true",
dest="debug",
help="Will display any exception trace to stdin",
- default=False
- )
+ default=False)
parser.add_option(
"-d", "--destination",
@@ -50,16 +48,14 @@ def _parse_options():
help="The path to the to the destination file: .html or "
".pdf extensions allowed (default: presentation.html)",
metavar="FILE",
- default="presentation.html"
- )
+ default="presentation.html")
parser.add_option(
"-e", "--encoding",
dest="encoding",
help="The encoding of your files (defaults to utf8)",
metavar="ENCODING",
- default="utf8"
- )
+ default="utf8")
parser.add_option(
"-i", "--embed",
@@ -68,15 +64,13 @@ def _parse_options():
help="Embed stylesheet and javascript contents, "
"base64-encoded images in presentation to make a "
"standalone document",
- default=False
- )
+ default=False)
parser.add_option(
"-t", "--theme",
dest="theme",
help="A theme name, or path to a landlside theme directory",
- default='default'
- )
+ default='default')
parser.add_option(
"-o", "--direct-ouput",
@@ -84,16 +78,14 @@ def _parse_options():
dest="direct",
help="Prints the generated HTML code to stdin; won't work "
"with PDF export",
- default=False
- )
+ default=False)
parser.add_option(
"-q", "--quiet",
action="store_false",
dest="verbose",
help="Won't write anything to stdin (silent mode)",
- default=False
- )
+ default=False)
parser.add_option(
"-v", "--verbose",
@@ -101,8 +93,7 @@ def _parse_options():
dest="verbose",
help="Write informational messages to stdin (enabled by "
"default)",
- default=True
- )
+ default=True)
(options, args) = parser.parse_args()
View
37 src/landslide/tests.py
@@ -14,17 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import macro
import os
import re
import unittest
import codecs
from generator import Generator
-from macro import *
from parser import Parser
-from pprint import pprint
-
SAMPLES_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'samples')
if (not os.path.exists(SAMPLES_DIR)):
@@ -77,18 +75,22 @@ def test_unicode(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example3', 'slides.rst'))
g.execute()
s = g.render()
- self.assertTrue(s.find('<pre>')!=-1)
+ self.assertTrue(s.find('<pre>') != -1)
self.assertEqual(len(re.findall('<pre><span', s)), 3)
def test_inputencoding(self):
- g = Generator(os.path.join(SAMPLES_DIR, 'example3', 'slides.koi8_r.rst'), encoding='koi8_r')
+ g = Generator(os.path.join(SAMPLES_DIR, 'example3',
+ 'slides.koi8_r.rst'), encoding='koi8_r')
content = g.render()
# check that the string is utf_8
- self.assertTrue(re.findall(u'русский',content, flags=re.UNICODE))
+ self.assertTrue(re.findall(u'русский', content,
+ flags=re.UNICODE))
g.execute()
- file_contents = codecs.open(g.destination_file, encoding='utf_8').read()
+ file_contents = codecs.open(g.destination_file, encoding='utf_8')\
+ .read()
# check that the file was properly encoded in utf_8
- self.assertTrue(re.findall(u'русский',file_contents, flags=re.UNICODE))
+ self.assertTrue(re.findall(u'русский', file_contents,
+ flags=re.UNICODE))
def test_get_template_vars(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example1', 'slides.md'))
@@ -98,7 +100,6 @@ def test_get_template_vars(self):
])
self.assertEqual(svars['head_title'], 'slide1')
-
def test_process_macros(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example1', 'slides.md'))
# Notes
@@ -115,7 +116,7 @@ def test_process_macros(self):
def test_register_macro(self):
g = Generator(os.path.join(SAMPLES_DIR, 'example1', 'slides.md'))
- class SampleMacro(Macro):
+ class SampleMacro(macro.Macro):
pass
g.register_macro(SampleMacro)
@@ -153,7 +154,7 @@ def foo():
<p>End here.</p>'''
def test_parsing_code_blocks(self):
- m = CodeHighlightingMacro(self.logtest)
+ m = macro.CodeHighlightingMacro(self.logtest)
blocks = m.code_blocks_re.findall(self.sample_html)
self.assertEquals(len(blocks), 3)
self.assertEquals(blocks[0][2], 'python')
@@ -164,7 +165,7 @@ def test_parsing_code_blocks(self):
self.assertTrue(blocks[2][3].startswith('<foo>'))
def test_descape(self):
- m = CodeHighlightingMacro(self.logtest)
+ m = macro.CodeHighlightingMacro(self.logtest)
self.assertEqual(m.descape('foo'), 'foo')
self.assertEqual(m.descape('&gt;'), '>')
self.assertEqual(m.descape('&lt;'), '<')
@@ -173,7 +174,7 @@ def test_descape(self):
self.assertEqual(m.descape('&lt;spam&amp;eggs&gt;'), '<spam&eggs>')
def test_process(self):
- m = CodeHighlightingMacro(self.logtest)
+ m = macro.CodeHighlightingMacro(self.logtest)
hl = m.process("<pre><code>!php\n$foo;</code></pre>")
self.assertTrue(hl[0].startswith('<div class="highlight"><pre'))
self.assertEquals(hl[1][0], u'has_code')
@@ -182,7 +183,7 @@ def test_process(self):
self.assertEqual(m.process(input)[1], [])
def test_process_rst_code_blocks(self):
- m = CodeHighlightingMacro(self.logtest)
+ m = macro.CodeHighlightingMacro(self.logtest)
hl = m.process(self.sample_html)
self.assertTrue(hl[0].startswith('<p>Let me give you this'))
self.assertTrue(hl[0].find('<p>Then this one') > 0)
@@ -194,7 +195,7 @@ def test_process_rst_code_blocks(self):
class EmbedImagesMacroTest(BaseTestCase):
def test_process(self):
base_dir = os.path.join(SAMPLES_DIR, 'example1', 'slides.md')
- m = EmbedImagesMacro(self.logtest, True)
+ m = macro.EmbedImagesMacro(self.logtest, True)
self.assertRaises(WarningMessage, m.process,
'<img src="toto.jpg"/>', '.')
content, classes = m.process('<img src="monkey.jpg"/>', base_dir)
@@ -205,7 +206,7 @@ def test_process(self):
class FixImagePathsMacroTest(BaseTestCase):
def test_process(self):
base_dir = os.path.join(SAMPLES_DIR, 'example1', 'slides.md')
- m = FixImagePathsMacro(self.logtest, False)
+ m = macro.FixImagePathsMacro(self.logtest, False)
content, classes = m.process('<img src="monkey.jpg"/>', base_dir)
self.assertTrue(re.match(r'<img src="file://.*?/monkey.jpg" />',
content))
@@ -213,7 +214,7 @@ def test_process(self):
class FxMacroTest(BaseTestCase):
def test_process(self):
- m = FxMacro(self.logtest)
+ m = macro.FxMacro(self.logtest)
content = '<p>foo</p>\n<p>.fx: blah blob</p>\n<p>baz</p>'
r = m.process(content)
self.assertEqual(r[0], '<p>foo</p>\n<p>baz</p>')
@@ -223,7 +224,7 @@ def test_process(self):
class NotesMacroTest(BaseTestCase):
def test_process(self):
- m = NotesMacro(self.logtest)
+ m = macro.NotesMacro(self.logtest)
r = m.process('<p>foo</p>\n<p>.notes: bar</p>\n<p>baz</p>')
self.assertEqual(r[0].find('<p class="notes">bar</p>'), 11)
self.assertEqual(r[1], [u'has_notes'])
Please sign in to comment.
Something went wrong with that request. Please try again.