diff --git a/mwparserfromhell/__init__.py b/mwparserfromhell/__init__.py index cf63afd..a765131 100644 --- a/mwparserfromhell/__init__.py +++ b/mwparserfromhell/__init__.py @@ -32,6 +32,6 @@ __license__ = "MIT License" __version__ = "0.1.dev" __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() diff --git a/mwparserfromhell/nodes/__init__.py b/mwparserfromhell/nodes/__init__.py index b8022d1..f749e71 100644 --- a/mwparserfromhell/nodes/__init__.py +++ b/mwparserfromhell/nodes/__init__.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from mwparserfromhell.string_mixin import StringMixIn +from ..string_mixin import StringMixIn __all__ = ["Node"] @@ -35,9 +35,9 @@ class Node(StringMixIn): 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 diff --git a/mwparserfromhell/nodes/extras/__init__.py b/mwparserfromhell/nodes/extras/__init__.py index 4677456..825d1af 100644 --- a/mwparserfromhell/nodes/extras/__init__.py +++ b/mwparserfromhell/nodes/extras/__init__.py @@ -20,5 +20,5 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from mwparserfromhell.nodes.extras.attribute import Attribute -from mwparserfromhell.nodes.extras.parameter import Parameter +from .attribute import Attribute +from .parameter import Parameter diff --git a/mwparserfromhell/nodes/extras/attribute.py b/mwparserfromhell/nodes/extras/attribute.py index 5e1ea9c..eb88933 100644 --- a/mwparserfromhell/nodes/extras/attribute.py +++ b/mwparserfromhell/nodes/extras/attribute.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from mwparserfromhell.string_mixin import StringMixIn +from ...string_mixin import StringMixIn __all__ = ["Attribute"] diff --git a/mwparserfromhell/nodes/extras/parameter.py b/mwparserfromhell/nodes/extras/parameter.py index 56eb064..ec39e26 100644 --- a/mwparserfromhell/nodes/extras/parameter.py +++ b/mwparserfromhell/nodes/extras/parameter.py @@ -20,8 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # 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"] diff --git a/mwparserfromhell/nodes/heading.py b/mwparserfromhell/nodes/heading.py index f45d6c2..ee10a9f 100644 --- a/mwparserfromhell/nodes/heading.py +++ b/mwparserfromhell/nodes/heading.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from mwparserfromhell.nodes import Node +from . import Node __all__ = ["Heading"] diff --git a/mwparserfromhell/nodes/html_entity.py b/mwparserfromhell/nodes/html_entity.py index 314b709..af046ea 100644 --- a/mwparserfromhell/nodes/html_entity.py +++ b/mwparserfromhell/nodes/html_entity.py @@ -22,7 +22,7 @@ import htmlentitydefs -from mwparserfromhell.nodes import Node +from . import Node __all__ = ["HTMLEntity"] diff --git a/mwparserfromhell/nodes/tag.py b/mwparserfromhell/nodes/tag.py index 0638c52..d80536b 100644 --- a/mwparserfromhell/nodes/tag.py +++ b/mwparserfromhell/nodes/tag.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from mwparserfromhell.nodes import Node, Text +from . import Node, Text __all__ = ["Tag"] diff --git a/mwparserfromhell/nodes/template.py b/mwparserfromhell/nodes/template.py index 84151cf..0b65aa7 100644 --- a/mwparserfromhell/nodes/template.py +++ b/mwparserfromhell/nodes/template.py @@ -23,9 +23,9 @@ from collections import defaultdict 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"] diff --git a/mwparserfromhell/nodes/text.py b/mwparserfromhell/nodes/text.py index bd0a108..c403029 100644 --- a/mwparserfromhell/nodes/text.py +++ b/mwparserfromhell/nodes/text.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from mwparserfromhell.nodes import Node +from . import Node __all__ = ["Text"] diff --git a/mwparserfromhell/parser/__init__.py b/mwparserfromhell/parser/__init__.py index a757dc3..c32a549 100644 --- a/mwparserfromhell/parser/__init__.py +++ b/mwparserfromhell/parser/__init__.py @@ -20,4 +20,4 @@ # 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 +from .demo import DemoParser as Parser diff --git a/mwparserfromhell/parser/demo.py b/mwparserfromhell/parser/demo.py index 5405f62..f8ce479 100644 --- a/mwparserfromhell/parser/demo.py +++ b/mwparserfromhell/parser/demo.py @@ -20,10 +20,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # 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"] diff --git a/mwparserfromhell/smart_list.py b/mwparserfromhell/smart_list.py index baa8dab..d989882 100644 --- a/mwparserfromhell/smart_list.py +++ b/mwparserfromhell/smart_list.py @@ -53,7 +53,16 @@ class SmartList(list): if stop >= key.stop and stop != sys.maxint: 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): return self.__getitem__(slice(start, stop)) @@ -64,17 +73,14 @@ class SmartList(list): def __delslice__(self, 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): super(SmartList, self).append(item) @@ -82,21 +88,21 @@ class SmartList(list): if stop >= len(self) - 1 and stop != sys.maxint: 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): @@ -108,19 +114,19 @@ class _ListProxy(list): def __repr__(self): return repr(self._render()) - __lt__ + #__lt__ - __le__ + #__le__ - __eq__ + #__eq__ - __ne__ + #__ne__ - __gt__ + #__gt__ - __ge__ + #__ge__ - __nonzero__ + #__nonzero__ def __len__(self): return (self._stop - self._start) / self._step @@ -136,7 +142,7 @@ class _ListProxy(list): else: self._parent[self._start + index] = item - __delitem__ + #__delitem__ def __iter__(self): i = self._start @@ -162,17 +168,14 @@ class _ListProxy(list): def __delslice__(self, 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 def _start(self): @@ -208,9 +211,9 @@ class _ListProxy(list): def insert(self, index, item): self._parent.insert(self._start + index, item) - pop + #pop - remove + #remove def reverse(self): item = self._render() diff --git a/mwparserfromhell/utils.py b/mwparserfromhell/utils.py index 9357d45..33084b5 100644 --- a/mwparserfromhell/utils.py +++ b/mwparserfromhell/utils.py @@ -21,7 +21,7 @@ # SOFTWARE. import mwparserfromhell -from mwparserfromhell.nodes import Node +from .nodes import Node def parse_anything(value): wikicode = mwparserfromhell.wikicode.Wikicode diff --git a/mwparserfromhell/wikicode.py b/mwparserfromhell/wikicode.py index 59e9abc..7680e20 100644 --- a/mwparserfromhell/wikicode.py +++ b/mwparserfromhell/wikicode.py @@ -23,9 +23,9 @@ import re 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"]