From cf14b5ef4e02dadcba08083e62ceb800ec9edb6d Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 16 Mar 2013 19:55:25 -0400 Subject: [PATCH] Add some missing methods to StringMixIn. --- mwparserfromhell/string_mixin.py | 30 ++++++++++++++++++++++++++++++ tests/test_string_mixin.py | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mwparserfromhell/string_mixin.py b/mwparserfromhell/string_mixin.py index 2539f74..9e6d551 100644 --- a/mwparserfromhell/string_mixin.py +++ b/mwparserfromhell/string_mixin.py @@ -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) diff --git a/tests/test_string_mixin.py b/tests/test_string_mixin.py index 455f2e6..cff3848 100644 --- a/tests/test_string_mixin.py +++ b/tests/test_string_mixin.py @@ -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: