404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.12.147.104: ~ $
from __future__ import unicode_literals
from __future__ import absolute_import
from . import util
from . import odict


class State(list):
    """ Track the current and nested state of the parser.

    This utility class is used to track the state of the BlockParser and
    support multiple levels if nesting. It's just a simple API wrapped around
    a list. Each time a state is set, that state is appended to the end of the
    list. Each time a state is reset, that state is removed from the end of
    the list.

    Therefore, each time a state is set for a nested block, that state must be
    reset when we back out of that level of nesting or the state could be
    corrupted.

    While all the methods of a list object are available, only the three
    defined below need be used.

    """

    def set(self, state):
        """ Set a new state. """
        self.append(state)

    def reset(self):
        """ Step back one step in nested state. """
        self.pop()

    def isstate(self, state):
        """ Test that top (current) level is of given state. """
        if len(self):
            return self[-1] == state
        else:
            return False


class BlockParser:
    """ Parse Markdown blocks into an ElementTree object.

    A wrapper class that stitches the various BlockProcessors together,
    looping through them and creating an ElementTree object.
    """

    def __init__(self, markdown):
        self.blockprocessors = odict.OrderedDict()
        self.state = State()
        self.markdown = markdown

    def parseDocument(self, lines):
        """ Parse a markdown document into an ElementTree.

        Given a list of lines, an ElementTree object (not just a parent
        Element) is created and the root element is passed to the parser
        as the parent. The ElementTree object is returned.

        This should only be called on an entire document, not pieces.

        """
        # Create a ElementTree from the lines
        self.root = util.etree.Element(self.markdown.doc_tag)
        self.parseChunk(self.root, '\n'.join(lines))
        return util.etree.ElementTree(self.root)

    def parseChunk(self, parent, text):
        """ Parse a chunk of markdown text and attach to given etree node.

        While the ``text`` argument is generally assumed to contain multiple
        blocks which will be split on blank lines, it could contain only one
        block. Generally, this method would be called by extensions when
        block parsing is required.

        The ``parent`` etree Element passed in is altered in place.
        Nothing is returned.

        """
        self.parseBlocks(parent, text.split('\n\n'))

    def parseBlocks(self, parent, blocks):
        """ Process blocks of markdown text and attach to given etree node.

        Given a list of ``blocks``, each blockprocessor is stepped through
        until there are no blocks left. While an extension could potentially
        call this method directly, it's generally expected to be used
        internally.

        This is a public method as an extension may need to add/alter
        additional BlockProcessors which call this method to recursively
        parse a nested block.

        """
        while blocks:
            for processor in self.blockprocessors.values():
                if processor.test(parent, blocks[0]):
                    if processor.run(parent, blocks) is not False:
                        # run returns True or None
                        break

Filemanager

Name Type Size Permission Actions
extensions Folder 0755
__init__.py File 20.31 KB 0644
__init__.pyc File 16.28 KB 0644
__main__.py File 5.02 KB 0644
__main__.pyc File 4.29 KB 0644
__version__.py File 880 B 0644
__version__.pyc File 941 B 0644
blockparser.py File 3.43 KB 0644
blockparser.pyc File 4.65 KB 0644
blockprocessors.py File 22.47 KB 0644
blockprocessors.pyc File 19.21 KB 0644
inlinepatterns.py File 16.73 KB 0644
inlinepatterns.pyc File 20.04 KB 0644
odict.py File 5.9 KB 0644
odict.pyc File 7.78 KB 0644
postprocessors.py File 3.53 KB 0644
postprocessors.pyc File 5.33 KB 0644
preprocessors.py File 14.3 KB 0644
preprocessors.pyc File 10.9 KB 0644
serializers.py File 9.59 KB 0644
serializers.pyc File 6.99 KB 0644
treeprocessors.py File 12.73 KB 0644
treeprocessors.pyc File 11.54 KB 0644
util.py File 5.51 KB 0644
util.pyc File 5.46 KB 0644