From 555827d8ebd373c131154160ab49ca83135a5a9e Mon Sep 17 00:00:00 2001 From: Prodesire Date: Sat, 14 Oct 2017 23:46:43 +0800 Subject: [PATCH] add doc for safestr --- docs/index.rst | 34 +++++++++++++++++++++++---------- tests/utils/test_str_unicode.py | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 782efc3..fdba4b1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -164,6 +164,30 @@ Dict String ------ +.. function:: pydu.utils.safeunicode(obj, encoding='utf-8') + + Converts any given object to unicode string. + + >>> safeunicode('hello') + u'hello' + >>> safeunicode(2) + u'2' + >>> safeunicode('\xe4\xb8\xad\xe6\x96\x87') + u'中文' + + +.. function:: pydu.utils.safestr(obj, encoding='utf-8') + + Converts any given object to utf-8 encoded string. + + >>> safestr('hello') + 'hello' + >>> safestr(2) + '2' + >>> safestr(u'中文') + '中文' + + .. function:: pydu.utils.lstrips(text, remove) Removes the string `remove` from the left of `text`. @@ -192,13 +216,3 @@ String 'bar' -.. function:: pydu.utils.safeunicode(obj, encoding='utf-8') - - Converts any given object to unicode string. - - >>> safeunicode('hello') - u'hello' - >>> safeunicode(2) - u'2' - >>> safeunicode('\xe4\xb8\xad\xe6\x96\x87') - u'中文' diff --git a/tests/utils/test_str_unicode.py b/tests/utils/test_str_unicode.py index a866cdd..b0d0ceb 100644 --- a/tests/utils/test_str_unicode.py +++ b/tests/utils/test_str_unicode.py @@ -6,6 +6,7 @@ def test_safestr(): assert safestr('hello') == 'hello' assert safestr(1) == '1' assert list(safestr([1, 'a'])) == ['1', 'a'] + assert safestr(u'中文') == '中文' def test_safeunicode():