Bladeren bron

Inherit StringMixIn method documentation from unicode.

Also reorder imports in nodes.__init__ to fix a minor bug.
tags/v0.1
Ben Kurtovic 11 jaren geleden
bovenliggende
commit
064b258141
2 gewijzigde bestanden met toevoegingen van 49 en 1 verwijderingen
  1. +1
    -1
      mwparserfromhell/nodes/__init__.py
  2. +48
    -0
      mwparserfromhell/string_mixin.py

+ 1
- 1
mwparserfromhell/nodes/__init__.py Bestand weergeven

@@ -28,6 +28,6 @@ class Node(StringMixIn):
pass pass


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

+ 48
- 0
mwparserfromhell/string_mixin.py Bestand weergeven

@@ -22,6 +22,11 @@


__all__ = ["StringMixIn"] __all__ = ["StringMixIn"]


def inheritdoc(method):
method.__doc__ = getattr(unicode, method.func_name).__doc__
return method


class StringMixIn(object): class StringMixIn(object):
def __str__(self): def __str__(self):
return unicode(self).encode("utf8") return unicode(self).encode("utf8")
@@ -80,122 +85,165 @@ class StringMixIn(object):
return unicode(item) in unicode(self) return unicode(item) in unicode(self)
return item in unicode(self) return item in unicode(self)


@inheritdoc
def capitalize(self): def capitalize(self):
return unicode(self).capitalize() return unicode(self).capitalize()


@inheritdoc
def center(self, width, fillchar=None): def center(self, width, fillchar=None):
return unicode(self).center(width, fillchar) return unicode(self).center(width, fillchar)


@inheritdoc
def count(self, sub=None, start=None, end=None): def count(self, sub=None, start=None, end=None):
return unicode(self).count(sub, start, end) return unicode(self).count(sub, start, end)


@inheritdoc
def decode(self, encoding=None, errors=None): def decode(self, encoding=None, errors=None):
return unicode(self).decode(encoding, errors) return unicode(self).decode(encoding, errors)


@inheritdoc
def encode(self, encoding=None, errors=None): def encode(self, encoding=None, errors=None):
return unicode(self).encode(encoding, errors) return unicode(self).encode(encoding, errors)


@inheritdoc
def endswith(self, prefix, start=None, end=None): def endswith(self, prefix, start=None, end=None):
return unicode(self).endswith(prefix, start, end) return unicode(self).endswith(prefix, start, end)


@inheritdoc
def expandtabs(self, tabsize=None): def expandtabs(self, tabsize=None):
return unicode(self).expandtabs(tabsize) return unicode(self).expandtabs(tabsize)


@inheritdoc
def find(self, sub=None, start=None, end=None): def find(self, sub=None, start=None, end=None):
return unicode(self).find(sub, start, end) return unicode(self).find(sub, start, end)


@inheritdoc
def format(self, *args, **kwargs): def format(self, *args, **kwargs):
return unicode(self).format(*args, **kwargs) return unicode(self).format(*args, **kwargs)


@inheritdoc
def index(self, sub=None, start=None, end=None): def index(self, sub=None, start=None, end=None):
return unicode(self).index(sub, start, end) return unicode(self).index(sub, start, end)


@inheritdoc
def isalnum(self): def isalnum(self):
return unicode(self).isalnum() return unicode(self).isalnum()


@inheritdoc
def isalpha(self): def isalpha(self):
return unicode(self).isalpha() return unicode(self).isalpha()


@inheritdoc
def isdecimal(self): def isdecimal(self):
return unicode(self).isdecimal() return unicode(self).isdecimal()


@inheritdoc
def isdigit(self): def isdigit(self):
return unicode(self).isdigit() return unicode(self).isdigit()


@inheritdoc
def islower(self): def islower(self):
return unicode(self).islower() return unicode(self).islower()


@inheritdoc
def isnumeric(self): def isnumeric(self):
return unicode(self).isnumeric() return unicode(self).isnumeric()


@inheritdoc
def isspace(self): def isspace(self):
return unicode(self).isspace() return unicode(self).isspace()


@inheritdoc
def istitle(self): def istitle(self):
return unicode(self).istitle() return unicode(self).istitle()


@inheritdoc
def isupper(self): def isupper(self):
return unicode(self).isupper() return unicode(self).isupper()


@inheritdoc
def join(self, iterable): def join(self, iterable):
return unicode(self).join(iterable) return unicode(self).join(iterable)


@inheritdoc
def ljust(self, width, fillchar=None): def ljust(self, width, fillchar=None):
return unicode(self).ljust(width, fillchar) return unicode(self).ljust(width, fillchar)


@inheritdoc
def lower(self): def lower(self):
return unicode(self).lower() return unicode(self).lower()


@inheritdoc
def lstrip(self, chars=None): def lstrip(self, chars=None):
return unicode(self).lstrip(chars) return unicode(self).lstrip(chars)


@inheritdoc
def partition(self, sep): def partition(self, sep):
return unicode(self).partition(sep) return unicode(self).partition(sep)


@inheritdoc
def replace(self, old, new, count): def replace(self, old, new, count):
return unicode(self).replace(old, new, count) return unicode(self).replace(old, new, count)


@inheritdoc
def rfind(self, sub=None, start=None, end=None): def rfind(self, sub=None, start=None, end=None):
return unicode(self).rfind(sub, start, end) return unicode(self).rfind(sub, start, end)


@inheritdoc
def rindex(self, sub=None, start=None, end=None): def rindex(self, sub=None, start=None, end=None):
return unicode(self).rindex(sub, start, end) return unicode(self).rindex(sub, start, end)


@inheritdoc
def rjust(self, width, fillchar=None): def rjust(self, width, fillchar=None):
return unicode(self).rjust(width, fillchar) return unicode(self).rjust(width, fillchar)


@inheritdoc
def rpartition(self, sep): def rpartition(self, sep):
return unicode(self).rpartition(sep) return unicode(self).rpartition(sep)


@inheritdoc
def rsplit(self, sep=None, maxsplit=None): def rsplit(self, sep=None, maxsplit=None):
return unicode(self).rsplit(sep, maxsplit) return unicode(self).rsplit(sep, maxsplit)


@inheritdoc
def rstrip(self, chars=None): def rstrip(self, chars=None):
return unicode(self).rstrip(chars) return unicode(self).rstrip(chars)


@inheritdoc
def split(self, sep=None, maxsplit=None): def split(self, sep=None, maxsplit=None):
return unicode(self).split(sep, maxsplit) return unicode(self).split(sep, maxsplit)


@inheritdoc
def splitlines(self, keepends=None): def splitlines(self, keepends=None):
return unicode(self).splitlines(keepends) return unicode(self).splitlines(keepends)


@inheritdoc
def startswith(self, prefix, start=None, end=None): def startswith(self, prefix, start=None, end=None):
return unicode(self).startswith(prefix, start, end) return unicode(self).startswith(prefix, start, end)


@inheritdoc
def strip(self, chars=None): def strip(self, chars=None):
return unicode(self).strip(chars) return unicode(self).strip(chars)


@inheritdoc
def swapcase(self): def swapcase(self):
return unicode(self).swapcase() return unicode(self).swapcase()


@inheritdoc
def title(self): def title(self):
return unicode(self).title() return unicode(self).title()


@inheritdoc
def translate(self, table, deletechars=None): def translate(self, table, deletechars=None):
return unicode(self).translate(table, deletechars) return unicode(self).translate(table, deletechars)


@inheritdoc
def upper(self): def upper(self):
return unicode(self).upper() return unicode(self).upper()


@inheritdoc
def zfill(self, width): def zfill(self, width):
return unicode(self).zfill(width) return unicode(self).zfill(width)


del inheritdoc

Laden…
Annuleren
Opslaan