Bladeren bron

Updating with a more logical project structure.

tags/v0.1
Ben Kurtovic 12 jaren geleden
bovenliggende
commit
e4fd6ef127
11 gewijzigde bestanden met toevoegingen van 81 en 36 verwijderingen
  1. +11
    -7
      README.rst
  2. +2
    -8
      mwparserfromhell/__init__.py
  3. +32
    -0
      mwparserfromhell/nodes/__init__.py
  4. +1
    -4
      mwparserfromhell/nodes/extras/__init__.py
  5. +0
    -0
      mwparserfromhell/nodes/extras/parameter.py
  6. +2
    -3
      mwparserfromhell/nodes/template.py
  7. +2
    -3
      mwparserfromhell/nodes/text.py
  8. +23
    -0
      mwparserfromhell/parser/__init__.py
  9. +4
    -5
      mwparserfromhell/parser/demo.py
  10. +1
    -1
      mwparserfromhell/string_mixin.py
  11. +3
    -5
      mwparserfromhell/wikicode.py

+ 11
- 7
README.rst Bestand weergeven

@@ -26,15 +26,19 @@ Usage
Normal usage is rather straightforward (where ``text`` is page text)::

>>> import mwparserfromhell
>>> parser = mwparserfromhell.Parser()
>>> templates = parser.parse(text)
>>> wikicode = mwparserfromhell.parse(text)

``wikicode`` is a ``mwparserfromhell.Wikicode`` object, which acts like an
ordinary unicode object. It also contains a list of nodes representing the
components of the wikicode, including ordinary text nodes, templates, and
links. For example::

>>> wikicode = mwparserfromhell.parse(u"{{foo|bar|baz|eggs=spam}}")
>>> print wikicode
u"{{foo|bar|baz|eggs=spam}}"
>>>

``templates`` is a list of ``mwparserfromhell.Template`` objects, which contain
a ``name`` attribute, a ``params`` attribute, and a ``render()`` method. Slices
are supported to get parameters. For example::

>>> templates = parser.parse("{{foo|bar|baz|eggs=spam}}")
>>> print templates
[Template(name="foo", params={"1": "bar", "2": "baz", "eggs": "spam"})]
>>> template = templates[0]
>>> print template.name


+ 2
- 8
mwparserfromhell/__init__.py Bestand weergeven

@@ -32,12 +32,6 @@ __license__ = "MIT License"
__version__ = "0.1.dev"
__email__ = "ben.kurtovic@verizon.net"

from mwparserfromhell.node import Node
from mwparserfromhell.parameter import Parameter
from mwparserfromhell.parser import Parser
from mwparserfromhell.string_mixin import StringMixIn
from mwparserfromhell.template import Template
from mwparserfromhell.text import Text
from mwparserfromhell.wikicode import Wikicode
from mwparserfromhell import nodes, parser, string_mixin, wikicode

parse = Parser().parse
parse = lambda text: parser.Parser().parse(text)

+ 32
- 0
mwparserfromhell/nodes/__init__.py Bestand weergeven

@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Ben Kurtovic <ben.kurtovic@verizon.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from mwparserfromhell.string_mixin import StringMixIn

__all__ = ["Node"]

class Node(StringMixIn):
pass

from mwparserfromhell.nodes import extras
from mwparserfromhell.nodes.template import Template
from mwparserfromhell.nodes.text import Text

mwparserfromhell/node.py → mwparserfromhell/nodes/extras/__init__.py Bestand weergeven

@@ -20,7 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

__all__ = ["Node"]

class Node(object):
pass
from mwparserfromhell.nodes.extras.parameter import Parameter

mwparserfromhell/parameter.py → mwparserfromhell/nodes/extras/parameter.py Bestand weergeven


mwparserfromhell/template.py → mwparserfromhell/nodes/template.py Bestand weergeven

@@ -20,12 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from mwparserfromhell.node import Node
from mwparserfromhell.string_mixin import StringMixIn
from mwparserfromhell.nodes import Node

__all__ = ["Template"]

class Template(Node, StringMixIn):
class Template(Node):
def __init__(self, name, params=None):
self._name = name
if params:

mwparserfromhell/text.py → mwparserfromhell/nodes/text.py Bestand weergeven

@@ -20,12 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from mwparserfromhell.node import Node
from mwparserfromhell.string_mixin import StringMixIn
from mwparserfromhell.nodes import Node

__all__ = ["Text"]

class Text(Node, StringMixIn):
class Text(Node):
def __init__(self, value):
self._value = value


+ 23
- 0
mwparserfromhell/parser/__init__.py Bestand weergeven

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Ben Kurtovic <ben.kurtovic@verizon.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from mwparserfromhell.parser.demo import DemoParser as Parser

mwparserfromhell/parser.py → mwparserfromhell/parser/demo.py Bestand weergeven

@@ -20,14 +20,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from mwparserfromhell.parameter import Parameter
from mwparserfromhell.template import Template
from mwparserfromhell.text import Text
from mwparserfromhell.nodes import Template, Text
from mwparserfromhell.nodes.extras import Parameter
from mwparserfromhell.wikicode import Wikicode

__all__ = ["Parser"]
__all__ = ["DemoParser"]

class Parser(object):
class DemoParser(object):
def _tokenize(self, text):
return text


+ 1
- 1
mwparserfromhell/string_mixin.py Bestand weergeven

@@ -22,7 +22,7 @@

__all__ = ["StringMixIn"]

class StringMixIn(object):
class StringMixIn(object): # UnicodeMixIn?
def __str__(self):
return unicode(self).encode("utf8")



+ 3
- 5
mwparserfromhell/wikicode.py Bestand weergeven

@@ -24,10 +24,8 @@ import htmlentitydefs
import re

import mwparserfromhell
from mwparserfromhell.node import Node
from mwparserfromhell.nodes import Node, Template, Text
from mwparserfromhell.string_mixin import StringMixIn
from mwparserfromhell.template import Template
from mwparserfromhell.text import Text

__all__ = ["Wikicode"]

@@ -187,6 +185,6 @@ class Wikicode(StringMixIn):
# Magic with htmlentitydefs if normalize
return normalized(u" ".join(self.ifilter_text()))

def show_tree(self):
def get_tree(self):
marker = object() # Random object we can find with certainty in a list
print "\n".join(self._show_tree(self, [], marker))
return "\n".join(self._show_tree(self, [], marker))

Laden…
Annuleren
Opslaan