소스 검색

Support `.encode()` keyword arguments for Python 2.6.

tags/v0.3.3
Marcio Faustino 10 년 전
부모
커밋
9650cd6276
1개의 변경된 파일21개의 추가작업 그리고 0개의 파일을 삭제
  1. +21
    -0
      mwparserfromhell/string_mixin.py

+ 21
- 0
mwparserfromhell/string_mixin.py 파일 보기

@@ -32,6 +32,15 @@ from .compat import bytes, py3k, str

__all__ = ["StringMixIn"]

def inheritdoc(method):
"""Set __doc__ of *method* to __doc__ of *method* in its parent class.

Since this is used on :py:class:`~.StringMixIn`, the "parent class" used is
``str``. This function can be used as a decorator.
"""
method.__doc__ = getattr(str, method.__name__).__doc__
return method

class StringMixIn(object):
"""Implement the interface for ``unicode``/``str`` in a dynamic manner.

@@ -99,8 +108,20 @@ class StringMixIn(object):
def __contains__(self, item):
return str(item) in self.__unicode__()

@inheritdoc
def encode(self, encoding=None, errors=None):
if encoding is None:
encoding = getdefaultencoding()
args = [encoding]
if errors is not None:
args.append(errors)
return self.__unicode__().encode(*args)

def __getattr__(self, attr):
return getattr(self.__unicode__(), attr)

if py3k:
maketrans = str.maketrans # Static method can't rely on __getattr__


del inheritdoc

불러오는 중...
취소
저장