Browse Source

Relaive imports because they are awesome; more stuff in SmartList.

tags/v0.1
Ben Kurtovic 12 years ago
parent
commit
3633f31633
15 changed files with 69 additions and 66 deletions
  1. +1
    -1
      mwparserfromhell/__init__.py
  2. +7
    -7
      mwparserfromhell/nodes/__init__.py
  3. +2
    -2
      mwparserfromhell/nodes/extras/__init__.py
  4. +1
    -1
      mwparserfromhell/nodes/extras/attribute.py
  5. +2
    -2
      mwparserfromhell/nodes/extras/parameter.py
  6. +1
    -1
      mwparserfromhell/nodes/heading.py
  7. +1
    -1
      mwparserfromhell/nodes/html_entity.py
  8. +1
    -1
      mwparserfromhell/nodes/tag.py
  9. +3
    -3
      mwparserfromhell/nodes/template.py
  10. +1
    -1
      mwparserfromhell/nodes/text.py
  11. +1
    -1
      mwparserfromhell/parser/__init__.py
  12. +4
    -4
      mwparserfromhell/parser/demo.py
  13. +40
    -37
      mwparserfromhell/smart_list.py
  14. +1
    -1
      mwparserfromhell/utils.py
  15. +3
    -3
      mwparserfromhell/wikicode.py

+ 1
- 1
mwparserfromhell/__init__.py View File

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


from mwparserfromhell import nodes, parser, smart_list, string_mixin, wikicode
from . import nodes, parser, smart_list, string_mixin, wikicode


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

+ 7
- 7
mwparserfromhell/nodes/__init__.py View File

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


from mwparserfromhell.string_mixin import StringMixIn
from ..string_mixin import StringMixIn


__all__ = ["Node"] __all__ = ["Node"]


@@ -35,9 +35,9 @@ class Node(StringMixIn):
write(unicode(self)) write(unicode(self))




from mwparserfromhell.nodes import extras
from mwparserfromhell.nodes.text import Text
from mwparserfromhell.nodes.heading import Heading
from mwparserfromhell.nodes.html_entity import HTMLEntity
from mwparserfromhell.nodes.tag import Tag
from mwparserfromhell.nodes.template import Template
from . import extras
from .text import Text
from .heading import Heading
from .html_entity import HTMLEntity
from .tag import Tag
from .template import Template

+ 2
- 2
mwparserfromhell/nodes/extras/__init__.py View File

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


from mwparserfromhell.nodes.extras.attribute import Attribute
from mwparserfromhell.nodes.extras.parameter import Parameter
from .attribute import Attribute
from .parameter import Parameter

+ 1
- 1
mwparserfromhell/nodes/extras/attribute.py View File

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


from mwparserfromhell.string_mixin import StringMixIn
from ...string_mixin import StringMixIn


__all__ = ["Attribute"] __all__ = ["Attribute"]




+ 2
- 2
mwparserfromhell/nodes/extras/parameter.py View File

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


from mwparserfromhell.string_mixin import StringMixIn
from mwparserfromhell.utils import parse_anything
from ...string_mixin import StringMixIn
from ...utils import parse_anything


__all__ = ["Parameter"] __all__ = ["Parameter"]




+ 1
- 1
mwparserfromhell/nodes/heading.py View File

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


from mwparserfromhell.nodes import Node
from . import Node


__all__ = ["Heading"] __all__ = ["Heading"]




+ 1
- 1
mwparserfromhell/nodes/html_entity.py View File

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


import htmlentitydefs import htmlentitydefs


from mwparserfromhell.nodes import Node
from . import Node


__all__ = ["HTMLEntity"] __all__ = ["HTMLEntity"]




+ 1
- 1
mwparserfromhell/nodes/tag.py View File

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


from mwparserfromhell.nodes import Node, Text
from . import Node, Text


__all__ = ["Tag"] __all__ = ["Tag"]




+ 3
- 3
mwparserfromhell/nodes/template.py View File

@@ -23,9 +23,9 @@
from collections import defaultdict from collections import defaultdict
import re import re


from mwparserfromhell.nodes import HTMLEntity, Node, Text
from mwparserfromhell.nodes.extras import Parameter
from mwparserfromhell.utils import parse_anything
from . import HTMLEntity, Node, Text
from .extras import Parameter
from ..utils import parse_anything


__all__ = ["Template"] __all__ = ["Template"]




+ 1
- 1
mwparserfromhell/nodes/text.py View File

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


from mwparserfromhell.nodes import Node
from . import Node


__all__ = ["Text"] __all__ = ["Text"]




+ 1
- 1
mwparserfromhell/parser/__init__.py View File

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


from mwparserfromhell.parser.demo import DemoParser as Parser
from .demo import DemoParser as Parser

+ 4
- 4
mwparserfromhell/parser/demo.py View File

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


from mwparserfromhell.nodes import Template, Text
from mwparserfromhell.nodes.extras import Parameter
from mwparserfromhell.smart_list import SmartList
from mwparserfromhell.wikicode import Wikicode
from ..nodes import Template, Text
from ..nodes.extras import Parameter
from ..smart_list import SmartList
from ..wikicode import Wikicode


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




+ 40
- 37
mwparserfromhell/smart_list.py View File

@@ -53,7 +53,16 @@ class SmartList(list):
if stop >= key.stop and stop != sys.maxint: if stop >= key.stop and stop != sys.maxint:
self._children[id(child)][1][1] += diff self._children[id(child)][1][1] += diff


__delitem__
def __delitem__(self, key):
super(SmartList, self).__delitem__(key)
if not isinstance(key, slice):
key = slice(key, key + 1)
diff = key.stop - key.start
for child, (start, stop, step) in self._children.itervalues():
if start > key.start:
self._children[id(child)][1][0] -= diff
if stop >= key.stop:
self._children[id(child)][1][1] -= diff


def __getslice__(self, start, stop): def __getslice__(self, start, stop):
return self.__getitem__(slice(start, stop)) return self.__getitem__(slice(start, stop))
@@ -64,17 +73,14 @@ class SmartList(list):
def __delslice__(self, start, stop): def __delslice__(self, start, stop):
self.__delitem__(slice(start, stop)) self.__delitem__(slice(start, stop))


__add__

__radd__

__iadd__
def __add__(self, other):
return SmartList(list(self) + other)


__mul__
def __radd__(self, other):
return SmartList(other + list(self))


__rmul__

__imul__
def __iadd__(self, other):
self.extend(other)


def append(self, item): def append(self, item):
super(SmartList, self).append(item) super(SmartList, self).append(item)
@@ -82,21 +88,21 @@ class SmartList(list):
if stop >= len(self) - 1 and stop != sys.maxint: if stop >= len(self) - 1 and stop != sys.maxint:
self._children[id(child)][1][1] += 1 self._children[id(child)][1][1] += 1


count
#count


index
#index


extend
#extend


insert
#insert


pop
#pop


remove
#remove


reverse
#reverse


sort
#sort




class _ListProxy(list): class _ListProxy(list):
@@ -108,19 +114,19 @@ class _ListProxy(list):
def __repr__(self): def __repr__(self):
return repr(self._render()) return repr(self._render())


__lt__
#__lt__


__le__
#__le__


__eq__
#__eq__


__ne__
#__ne__


__gt__
#__gt__


__ge__
#__ge__


__nonzero__
#__nonzero__


def __len__(self): def __len__(self):
return (self._stop - self._start) / self._step return (self._stop - self._start) / self._step
@@ -136,7 +142,7 @@ class _ListProxy(list):
else: else:
self._parent[self._start + index] = item self._parent[self._start + index] = item


__delitem__
#__delitem__


def __iter__(self): def __iter__(self):
i = self._start i = self._start
@@ -162,17 +168,14 @@ class _ListProxy(list):
def __delslice__(self, start, stop): def __delslice__(self, start, stop):
self.__delitem__(slice(start, stop)) self.__delitem__(slice(start, stop))


__add__

__radd__

__iadd__

__mul__
def __add__(self, other):
return SmartList(list(self) + other)


__rmul__
def __radd__(self, other):
return SmartList(other + list(self))


__imul__
def __iadd__(self, other):
self.extend(other)


@property @property
def _start(self): def _start(self):
@@ -208,9 +211,9 @@ class _ListProxy(list):
def insert(self, index, item): def insert(self, index, item):
self._parent.insert(self._start + index, item) self._parent.insert(self._start + index, item)


pop
#pop


remove
#remove


def reverse(self): def reverse(self):
item = self._render() item = self._render()


+ 1
- 1
mwparserfromhell/utils.py View File

@@ -21,7 +21,7 @@
# SOFTWARE. # SOFTWARE.


import mwparserfromhell import mwparserfromhell
from mwparserfromhell.nodes import Node
from .nodes import Node


def parse_anything(value): def parse_anything(value):
wikicode = mwparserfromhell.wikicode.Wikicode wikicode = mwparserfromhell.wikicode.Wikicode


+ 3
- 3
mwparserfromhell/wikicode.py View File

@@ -23,9 +23,9 @@
import re import re
import sys import sys


from mwparserfromhell.nodes import Heading, Node, Tag, Template, Text
from mwparserfromhell.string_mixin import StringMixIn
from mwparserfromhell.utils import parse_anything
from .nodes import Heading, Node, Tag, Template, Text
from .string_mixin import StringMixIn
from .utils import parse_anything


__all__ = ["Wikicode"] __all__ = ["Wikicode"]




Loading…
Cancel
Save