Sfoglia il codice sorgente

Add some missing methods to StringMixIn.

tags/v0.2
Ben Kurtovic 11 anni fa
parent
commit
cf14b5ef4e
2 ha cambiato i file con 32 aggiunte e 1 eliminazioni
  1. +30
    -0
      mwparserfromhell/string_mixin.py
  2. +2
    -1
      tests/test_string_mixin.py

+ 30
- 0
mwparserfromhell/string_mixin.py Vedi File

@@ -122,6 +122,11 @@ class StringMixIn(object):
def capitalize(self):
return self.__unicode__().capitalize()

if py3k:
@inheritdoc
def casefold(self):
return self.__unicode__().casefold()

@inheritdoc
def center(self, width, fillchar=None):
if fillchar is None:
@@ -167,6 +172,11 @@ class StringMixIn(object):
def format(self, *args, **kwargs):
return self.__unicode__().format(*args, **kwargs)

if py3k:
@inheritdoc
def format_map(self, mapping):
return self.__unicode__().format_map(mapping)

@inheritdoc
def index(self, sub, start=None, end=None):
return self.__unicode__().index(sub, start, end)
@@ -187,6 +197,11 @@ class StringMixIn(object):
def isdigit(self):
return self.__unicode__().isdigit()

if py3k:
@inheritdoc
def isidentifier(self):
return self.__unicode__().isidentifier()

@inheritdoc
def islower(self):
return self.__unicode__().islower()
@@ -195,6 +210,11 @@ class StringMixIn(object):
def isnumeric(self):
return self.__unicode__().isnumeric()

if py3k:
@inheritdoc
def isprintable(self):
return self.__unicode__().isprintable()

@inheritdoc
def isspace(self):
return self.__unicode__().isspace()
@@ -225,6 +245,16 @@ class StringMixIn(object):
def lstrip(self, chars=None):
return self.__unicode__().lstrip(chars)

if py3k:
@inheritdoc
@staticmethod
def maketrans(self, x, y=None, z=None):
if z is None:
if y is None:
return self.__unicode__.maketrans(x)
return self.__unicode__.maketrans(x, y)
return self.__unicode__.maketrans(x, y, z)

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


+ 2
- 1
tests/test_string_mixin.py Vedi File

@@ -48,7 +48,8 @@ class TestStringMixIn(unittest.TestCase):
"rsplit", "rstrip", "split", "splitlines", "startswith", "strip",
"swapcase", "title", "translate", "upper", "zfill"]
if py3k:
methods.extend(["casefold", "format_map", "isidentifier", "isprintable", "maketrans"])
methods.extend(["casefold", "format_map", "isidentifier",
"isprintable", "maketrans"])
else:
methods.append("decode")
for meth in methods:


Caricamento…
Annulla
Salva