diff options
author | Waylan Limberg <waylan@gmail.com> | 2014-01-08 22:37:22 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2014-01-08 22:37:22 -0500 |
commit | 88f75ee760bb92e51fc64c3805a73b8be896e641 (patch) | |
tree | a66a466a31e6153cab0871d7047dbbf675e7ea4e | |
parent | 809195fb900c8e8bd3ff65a2e69de78075224096 (diff) | |
download | markdown-88f75ee760bb92e51fc64c3805a73b8be896e641.tar.gz markdown-88f75ee760bb92e51fc64c3805a73b8be896e641.tar.bz2 markdown-88f75ee760bb92e51fc64c3805a73b8be896e641.zip |
Address various depreciated APIs in Python
This mostly revolves around old APIs for ElementTree, but includes a few
others as well. Fixes #254. Thanks for the report.
-rw-r--r-- | markdown/__init__.py | 2 | ||||
-rw-r--r-- | markdown/blockprocessors.py | 10 | ||||
-rw-r--r-- | markdown/treeprocessors.py | 12 | ||||
-rw-r--r-- | tests/util.py | 8 |
4 files changed, 16 insertions, 16 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index 0219dc3..4943388 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -293,7 +293,7 @@ class Markdown(object): # Run the tree-processors for treeprocessor in self.treeprocessors.values(): newRoot = treeprocessor.run(root) - if newRoot: + if newRoot is not None: root = newRoot # Serialize _properly_. Strip top-level tags. diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 61977b4..147ff0f 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -211,7 +211,7 @@ class ListIndentProcessor(BlockProcessor): # Step through children of tree to find matching indent level. while indent_level > level: child = self.lastChild(parent) - if child and (child.tag in self.LIST_TYPES or child.tag in self.ITEM_TYPES): + if child is not None and (child.tag in self.LIST_TYPES or child.tag in self.ITEM_TYPES): if child.tag in self.LIST_TYPES: level += 1 parent = child @@ -232,7 +232,7 @@ class CodeBlockProcessor(BlockProcessor): sibling = self.lastChild(parent) block = blocks.pop(0) theRest = '' - if sibling and sibling.tag == "pre" and len(sibling) \ + if sibling is not None and sibling.tag == "pre" and len(sibling) \ and sibling[0].tag == "code": # The previous block was a code block. As blank lines do not start # new code blocks, append this block to the previous, adding back @@ -271,7 +271,7 @@ class BlockQuoteProcessor(BlockProcessor): block = '\n'.join([self.clean(line) for line in block[m.start():].split('\n')]) sibling = self.lastChild(parent) - if sibling and sibling.tag == "blockquote": + if sibling is not None and sibling.tag == "blockquote": # Previous block was a blockquote so set that as this blocks parent quote = sibling else: @@ -319,7 +319,7 @@ class OListProcessor(BlockProcessor): items = self.get_items(blocks.pop(0)) sibling = self.lastChild(parent) - if sibling and sibling.tag in self.SIBLING_TAGS: + if sibling is not None and sibling.tag in self.SIBLING_TAGS: # Previous block was a list item, so set that as parent lst = sibling # make sure previous item is in a p- if the item has text, then it @@ -515,7 +515,7 @@ class EmptyBlockProcessor(BlockProcessor): # Add remaining lines to master blocks for later. blocks.insert(0, theRest) sibling = self.lastChild(parent) - if sibling and sibling.tag == 'pre' and len(sibling) and sibling[0].tag == 'code': + if sibling is not None and sibling.tag == 'pre' and len(sibling) and sibling[0].tag == 'code': # Last block is a codeblock. Append to preserve whitespace. sibling[0].text = util.AtomicString('%s%s' % (sibling[0].text, filler)) diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index e6d3dc9..ef0a2aa 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -131,7 +131,7 @@ class InlineProcessor(Treeprocessor): childResult = self.__processPlaceholders(text, subnode) if not isText and node is not subnode: - pos = node.getchildren().index(subnode) + pos = list(node).index(subnode) node.remove(subnode) else: pos = 0 @@ -179,7 +179,7 @@ class InlineProcessor(Treeprocessor): linkText(text) if not isString(node): # it's Element - for child in [node] + node.getchildren(): + for child in [node] + list(node): if child.tail: if child.tail.strip(): self.__processElementText(node, child,False) @@ -237,7 +237,7 @@ class InlineProcessor(Treeprocessor): if not isString(node): if not isinstance(node.text, util.AtomicString): # We need to process current node too - for child in [node] + node.getchildren(): + for child in [node] + list(node): if not isString(node): if child.text: child.text = self.__handleInline(child.text, @@ -276,7 +276,7 @@ class InlineProcessor(Treeprocessor): while stack: currElement = stack.pop() insertQueue = [] - for child in currElement.getchildren(): + for child in currElement: if child.text and not isinstance(child.text, util.AtomicString): text = child.text child.text = None @@ -292,11 +292,11 @@ class InlineProcessor(Treeprocessor): child.tail = dumby.text else: child.tail = None - pos = currElement.getchildren().index(child) + 1 + pos = list(currElement).index(child) + 1 tailResult.reverse() for newChild in tailResult: currElement.insert(pos, newChild) - if child.getchildren(): + if len(child): stack.append(child) for element, lst in insertQueue: diff --git a/tests/util.py b/tests/util.py index bbf7aea..0f416fb 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,16 +1,16 @@ import sys if sys.version_info[0] == 3: - from configparser import SafeConfigParser + from configparser import ConfigParser else: - from ConfigParser import SafeConfigParser + from ConfigParser import SafeConfigParser as ConfigParser class MarkdownSyntaxError(Exception): pass -class CustomConfigParser(SafeConfigParser): +class CustomConfigParser(ConfigParser): def get(self, section, option): - value = SafeConfigParser.get(self, section, option) + value = ConfigParser.get(self, section, option) if option == 'extensions': if len(value.strip()): return value.split(',') |