Преглед на файлове

Add some missing methods to StringMixIn.

tags/v0.2
Ben Kurtovic преди 11 години
родител
ревизия
cf14b5ef4e
променени са 2 файла, в които са добавени 32 реда и са изтрити 1 реда
  1. +30
    -0
      mwparserfromhell/string_mixin.py
  2. +2
    -1
      tests/test_string_mixin.py

+ 30
- 0
mwparserfromhell/string_mixin.py Целия файл

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


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

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


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

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


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

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


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

@inheritdoc @inheritdoc
def isspace(self): def isspace(self):
return self.__unicode__().isspace() return self.__unicode__().isspace()
@@ -225,6 +245,16 @@ class StringMixIn(object):
def lstrip(self, chars=None): def lstrip(self, chars=None):
return self.__unicode__().lstrip(chars) 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 @inheritdoc
def partition(self, sep): def partition(self, sep):
return self.__unicode__().partition(sep) return self.__unicode__().partition(sep)


+ 2
- 1
tests/test_string_mixin.py Целия файл

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


Зареждане…
Отказ
Запис