Skip to content

Commit 8f66a94

Browse files
committed
Flake8 cleanup (mostly whitespace).
Got all but a couple files in the tests (ran out of time today). Apparently I have been using some bad form for years (although a few things seemed to look better before the update). Anyway, conformant now.
1 parent 0c21438 commit 8f66a94

34 files changed

+955
-708
lines changed

markdown/__init__.py

Lines changed: 111 additions & 76 deletions
Large diffs are not rendered by default.

markdown/__main__.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
import sys
99
import optparse
1010
import codecs
11-
try:
11+
try:
1212
import yaml
13-
except ImportError: #pragma: no cover
13+
except ImportError: # pragma: no cover
1414
import json as yaml
1515

1616
import logging
1717
from logging import DEBUG, INFO, CRITICAL
1818

19-
logger = logging.getLogger('MARKDOWN')
19+
logger = logging.getLogger('MARKDOWN')
20+
2021

2122
def parse_options(args=None, values=None):
2223
"""
@@ -27,7 +28,7 @@ def parse_options(args=None, values=None):
2728
desc = "A Python implementation of John Gruber's Markdown. " \
2829
"https://pythonhosted.org/Markdown/"
2930
ver = "%%prog %s" % markdown.version
30-
31+
3132
parser = optparse.OptionParser(usage=usage, description=desc, version=ver)
3233
parser.add_option("-f", "--file", dest="filename", default=None,
3334
help="Write output to OUTPUT_FILE. Defaults to STDOUT.",
@@ -36,24 +37,28 @@ def parse_options(args=None, values=None):
3637
help="Encoding for input and output files.",)
3738
parser.add_option("-s", "--safe", dest="safe", default=False,
3839
metavar="SAFE_MODE",
39-
help="Deprecated! 'replace', 'remove' or 'escape' HTML tags in input")
40-
parser.add_option("-o", "--output_format", dest="output_format",
40+
help="Deprecated! 'replace', 'remove' or 'escape' HTML "
41+
"tags in input")
42+
parser.add_option("-o", "--output_format", dest="output_format",
4143
default='xhtml1', metavar="OUTPUT_FORMAT",
4244
help="'xhtml1' (default), 'html4' or 'html5'.")
43-
parser.add_option("-n", "--no_lazy_ol", dest="lazy_ol",
45+
parser.add_option("-n", "--no_lazy_ol", dest="lazy_ol",
4446
action='store_false', default=True,
4547
help="Observe number of first item of ordered lists.")
4648
parser.add_option("-x", "--extension", action="append", dest="extensions",
47-
help = "Load extension EXTENSION.", metavar="EXTENSION")
48-
parser.add_option("-c", "--extension_configs", dest="configfile", default=None,
49+
help="Load extension EXTENSION.", metavar="EXTENSION")
50+
parser.add_option("-c", "--extension_configs",
51+
dest="configfile", default=None,
4952
help="Read extension configurations from CONFIG_FILE. "
50-
"CONFIG_FILE must be of JSON or YAML format. YAML format requires "
51-
"that a python YAML library be installed. The parsed JSON or YAML "
52-
"must result in a python dictionary which would be accepted by the "
53-
"'extension_configs' keyword on the markdown.Markdown class. "
54-
"The extensions must also be loaded with the `--extension` option.",
53+
"CONFIG_FILE must be of JSON or YAML format. YAML"
54+
"format requires that a python YAML library be "
55+
"installed. The parsed JSON or YAML must result in a "
56+
"python dictionary which would be accepted by the "
57+
"'extension_configs' keyword on the markdown.Markdown "
58+
"class. The extensions must also be loaded with the "
59+
"`--extension` option.",
5560
metavar="CONFIG_FILE")
56-
parser.add_option("-q", "--quiet", default = CRITICAL,
61+
parser.add_option("-q", "--quiet", default=CRITICAL,
5762
action="store_const", const=CRITICAL+10, dest="verbose",
5863
help="Suppress all warnings.")
5964
parser.add_option("-v", "--verbose",
@@ -75,11 +80,14 @@ def parse_options(args=None, values=None):
7580

7681
extension_configs = {}
7782
if options.configfile:
78-
with codecs.open(options.configfile, mode="r", encoding=options.encoding) as fp:
83+
with codecs.open(
84+
options.configfile, mode="r", encoding=options.encoding
85+
) as fp:
7986
try:
8087
extension_configs = yaml.load(fp)
8188
except Exception as e:
82-
message = "Failed parsing extension config file: %s" % options.configfile
89+
message = "Failed parsing extension config file: %s" % \
90+
options.configfile
8391
e.args = (message,) + e.args[1:]
8492
raise
8593

@@ -92,20 +100,23 @@ def parse_options(args=None, values=None):
92100
'output_format': options.output_format,
93101
'lazy_ol': options.lazy_ol}, options.verbose
94102

95-
def run(): #pragma: no cover
103+
104+
def run(): # pragma: no cover
96105
"""Run Markdown from the command line."""
97106

98107
# Parse options and adjust logging level if necessary
99108
options, logging_level = parse_options()
100-
if not options: sys.exit(2)
109+
if not options:
110+
sys.exit(2)
101111
logger.setLevel(logging_level)
102112
logger.addHandler(logging.StreamHandler())
103113

104114
# Run
105115
markdown.markdownFromFile(**options)
106116

107-
if __name__ == '__main__': #pragma: no cover
108-
# Support running module as a commandline command.
117+
118+
if __name__ == '__main__': # pragma: no cover
119+
# Support running module as a commandline command.
109120
# Python 2.5 & 2.6 do: `python -m markdown.__main__ [options] [args]`.
110121
# Python 2.7 & 3.x do: `python -m markdown [options] [args]`.
111122
run()

markdown/__version__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#
22
# markdown/__version__.py
33
#
4-
# version_info should conform to PEP 386
4+
# version_info should conform to PEP 386
55
# (major, minor, micro, alpha/beta/rc/final, #)
66
# (1, 1, 2, 'alpha', 0) => "1.1.2.dev"
77
# (1, 2, 0, 'beta', 2) => "1.2b2"
88
version_info = (2, 5, 2, 'final', 0)
99

10+
1011
def _get_version():
1112
" Returns a PEP 386-compliant version number from version_info. "
1213
assert len(version_info) == 5

markdown/blockparser.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from . import util
44
from . import odict
55

6+
67
class State(list):
7-
""" Track the current and nested state of the parser.
8-
9-
This utility class is used to track the state of the BlockParser and
8+
""" Track the current and nested state of the parser.
9+
10+
This utility class is used to track the state of the BlockParser and
1011
support multiple levels if nesting. It's just a simple API wrapped around
1112
a list. Each time a state is set, that state is appended to the end of the
1213
list. Each time a state is reset, that state is removed from the end of
1314
the list.
1415
15-
Therefore, each time a state is set for a nested block, that state must be
16+
Therefore, each time a state is set for a nested block, that state must be
1617
reset when we back out of that level of nesting or the state could be
1718
corrupted.
1819
@@ -36,9 +37,10 @@ def isstate(self, state):
3637
else:
3738
return False
3839

40+
3941
class BlockParser:
40-
""" Parse Markdown blocks into an ElementTree object.
41-
42+
""" Parse Markdown blocks into an ElementTree object.
43+
4244
A wrapper class that stitches the various BlockProcessors together,
4345
looping through them and creating an ElementTree object.
4446
"""
@@ -49,12 +51,12 @@ def __init__(self, markdown):
4951
self.markdown = markdown
5052

5153
def parseDocument(self, lines):
52-
""" Parse a markdown document into an ElementTree.
53-
54-
Given a list of lines, an ElementTree object (not just a parent Element)
55-
is created and the root element is passed to the parser as the parent.
56-
The ElementTree object is returned.
57-
54+
""" Parse a markdown document into an ElementTree.
55+
56+
Given a list of lines, an ElementTree object (not just a parent
57+
Element) is created and the root element is passed to the parser
58+
as the parent. The ElementTree object is returned.
59+
5860
This should only be called on an entire document, not pieces.
5961
6062
"""
@@ -64,29 +66,30 @@ def parseDocument(self, lines):
6466
return util.etree.ElementTree(self.root)
6567

6668
def parseChunk(self, parent, text):
67-
""" Parse a chunk of markdown text and attach to given etree node.
68-
69+
""" Parse a chunk of markdown text and attach to given etree node.
70+
6971
While the ``text`` argument is generally assumed to contain multiple
7072
blocks which will be split on blank lines, it could contain only one
7173
block. Generally, this method would be called by extensions when
72-
block parsing is required.
73-
74-
The ``parent`` etree Element passed in is altered in place.
74+
block parsing is required.
75+
76+
The ``parent`` etree Element passed in is altered in place.
7577
Nothing is returned.
7678
7779
"""
7880
self.parseBlocks(parent, text.split('\n\n'))
7981

8082
def parseBlocks(self, parent, blocks):
81-
""" Process blocks of markdown text and attach to given etree node.
82-
83+
""" Process blocks of markdown text and attach to given etree node.
84+
8385
Given a list of ``blocks``, each blockprocessor is stepped through
8486
until there are no blocks left. While an extension could potentially
85-
call this method directly, it's generally expected to be used internally.
87+
call this method directly, it's generally expected to be used
88+
internally.
8689
87-
This is a public method as an extension may need to add/alter additional
88-
BlockProcessors which call this method to recursively parse a nested
89-
block.
90+
This is a public method as an extension may need to add/alter
91+
additional BlockProcessors which call this method to recursively
92+
parse a nested block.
9093
9194
"""
9295
while blocks:
@@ -95,5 +98,3 @@ def parseBlocks(self, parent, blocks):
9598
if processor.run(parent, blocks) is not False:
9699
# run returns True or None
97100
break
98-
99-

0 commit comments

Comments
 (0)