Various fixes to markdown found by the automatic python checker

This commit is contained in:
Kovid Goyal 2011-09-03 14:42:04 -06:00
parent 33d6ae3486
commit c7bf67e6c3
10 changed files with 53 additions and 54 deletions

View File

@ -63,10 +63,10 @@ class Check(Command):
for f in x[-1]: for f in x[-1]:
y = self.j(x[0], f) y = self.j(x[0], f)
mtime = os.stat(y).st_mtime mtime = os.stat(y).st_mtime
if f.endswith('.py') and f not in ('ptempfile.py', 'feedparser.py', if (f.endswith('.py') and f not in ('ptempfile.py', 'feedparser.py',
'pyparsing.py', 'markdown.py') and \ 'pyparsing.py', 'markdown.py') and
'genshi' not in y and cache.get(y, 0) != mtime and \ 'genshi' not in y and cache.get(y, 0) != mtime and
'prs500/driver.py' not in y: 'prs500/driver.py' not in y):
yield y, mtime yield y, mtime
for x in os.walk(self.j(self.d(self.SRC), 'recipes')): for x in os.walk(self.j(self.d(self.SRC), 'recipes')):

View File

@ -355,7 +355,7 @@ class HashHeaderProcessor(BlockProcessor):
blocks.insert(0, after) blocks.insert(0, after)
else: else:
# This should never happen, but just in case... # This should never happen, but just in case...
message(CRITICAL, "We've got a problem header!") print("We've got a problem header!")
class SetextHeaderProcessor(BlockProcessor): class SetextHeaderProcessor(BlockProcessor):
@ -407,7 +407,7 @@ class HRProcessor(BlockProcessor):
# Recursively parse lines before hr so they get parsed first. # Recursively parse lines before hr so they get parsed first.
self.parser.parseBlocks(parent, ['\n'.join(prelines)]) self.parser.parseBlocks(parent, ['\n'.join(prelines)])
# create hr # create hr
hr = markdown.etree.SubElement(parent, 'hr') markdown.etree.SubElement(parent, 'hr')
# check for lines in block after hr. # check for lines in block after hr.
lines = lines[len(prelines)+1:] lines = lines[len(prelines)+1:]
if len(lines): if len(lines):

View File

@ -9,7 +9,7 @@ Markdown is called from the command line.
import markdown import markdown
import sys import sys
import logging import logging
from logging import DEBUG, INFO, WARN, ERROR, CRITICAL from logging import DEBUG, INFO, CRITICAL
EXECUTABLE_NAME_FOR_USAGE = "python markdown.py" EXECUTABLE_NAME_FOR_USAGE = "python markdown.py"
""" The name used in the usage statement displayed for python versions < 2.3. """ The name used in the usage statement displayed for python versions < 2.3.

View File

@ -8,9 +8,11 @@ def importETree():
etree_in_c = None etree_in_c = None
try: # Is it Python 2.5+ with C implemenation of ElementTree installed? try: # Is it Python 2.5+ with C implemenation of ElementTree installed?
import xml.etree.cElementTree as etree_in_c import xml.etree.cElementTree as etree_in_c
etree_in_c
except ImportError: except ImportError:
try: # Is it Python 2.5+ with Python implementation of ElementTree? try: # Is it Python 2.5+ with Python implementation of ElementTree?
import xml.etree.ElementTree as etree import xml.etree.ElementTree as etree
etree
except ImportError: except ImportError:
try: # An earlier version of Python with cElementTree installed? try: # An earlier version of Python with cElementTree installed?
import cElementTree as etree_in_c import cElementTree as etree_in_c

View File

@ -80,7 +80,7 @@ class DefListIndentProcessor(markdown.blockprocessors.ListIndentProcessor):
ITEM_TYPES = ['dd'] ITEM_TYPES = ['dd']
LIST_TYPES = ['dl'] LIST_TYPES = ['dl']
def create_item(parent, block): def create_item(self, parent, block):
""" Create a new dd and parse the block with it as the parent. """ """ Create a new dd and parse the block with it as the parent. """
dd = markdown.etree.SubElement(parent, 'dd') dd = markdown.etree.SubElement(parent, 'dd')
self.parser.parseBlocks(dd, [block]) self.parser.parseBlocks(dd, [block])

View File

@ -106,7 +106,7 @@ class FootnoteExtension(markdown.Extension):
div = etree.Element("div") div = etree.Element("div")
div.set('class', 'footnote') div.set('class', 'footnote')
hr = etree.SubElement(div, "hr") etree.SubElement(div, "hr")
ol = etree.SubElement(div, "ol") ol = etree.SubElement(div, "ol")
for id in self.footnotes.keys(): for id in self.footnotes.keys():
@ -199,7 +199,6 @@ class FootnotePreprocessor(markdown.preprocessors.Preprocessor):
""" """
items = [] items = []
item = -1
i = 0 # to keep track of where we are i = 0 # to keep track of where we are
def detab(line): def detab(line):
@ -277,7 +276,6 @@ class FootnoteTreeprocessor(markdown.treeprocessors.Treeprocessor):
ind = element.getchildren().find(child) ind = element.getchildren().find(child)
element.getchildren().insert(ind + 1, footnotesDiv) element.getchildren().insert(ind + 1, footnotesDiv)
child.tail = None child.tail = None
fnPlaceholder.parent.replaceChild(fnPlaceholder, footnotesDiv)
else: else:
root.append(footnotesDiv) root.append(footnotesDiv)

View File

@ -66,7 +66,6 @@ Dependencies:
""" """
import calibre.ebooks.markdown.markdown as markdown import calibre.ebooks.markdown.markdown as markdown
from calibre.ebooks.markdown.markdown import etree
import re import re
from string import ascii_lowercase, digits, punctuation from string import ascii_lowercase, digits, punctuation
@ -119,7 +118,7 @@ class HeaderIdProcessor(markdown.blockprocessors.BlockProcessor):
blocks.insert(0, after) blocks.insert(0, after)
else: else:
# This should never happen, but just in case... # This should never happen, but just in case...
message(CRITICAL, "We've got a problem header!") print ("We've got a problem header!")
def _get_meta(self): def _get_meta(self):
""" Return meta data suported by this ext as a tuple """ """ Return meta data suported by this ext as a tuple """

View File

@ -47,6 +47,7 @@ from urlparse import urlparse, urlunparse
import sys import sys
if sys.version >= "3.0": if sys.version >= "3.0":
from html import entities as htmlentitydefs from html import entities as htmlentitydefs
htmlentitydefs
else: else:
import htmlentitydefs import htmlentitydefs
@ -215,7 +216,6 @@ class HtmlPattern (Pattern):
""" Store raw inline html and return a placeholder. """ """ Store raw inline html and return a placeholder. """
def handleMatch (self, m): def handleMatch (self, m):
rawhtml = m.group(2) rawhtml = m.group(2)
inline = True
place_holder = self.markdown.htmlStash.store(rawhtml) place_holder = self.markdown.htmlStash.store(rawhtml)
return place_holder return place_holder

View File

@ -156,7 +156,7 @@ class OrderedDict(dict):
self.keyOrder.insert(i, key) self.keyOrder.insert(i, key)
else: else:
self.keyOrder.append(key) self.keyOrder.append(key)
except Error: except Exception as e:
# restore to prevent data loss and reraise # restore to prevent data loss and reraise
self.keyOrder.insert(n, key) self.keyOrder.insert(n, key)
raise Error raise e

View File

@ -185,7 +185,7 @@ class InlineProcessor(Treeprocessor):
result.append(node) result.append(node)
else: # wrong placeholder else: # wrong placeholder
end = index + len(prefix) end = index + len(self.__placeholder_prefix)
linkText(data[strartIndex:end]) linkText(data[strartIndex:end])
strartIndex = end strartIndex = end
else: else: