Update __init__.py
Copied the description about errors-argument from Pyh-Doc (https://docs.python.org/3/howto/unicode.html). Im not sure how to create the HTML-Doc out of this file. So, I could not test the doc-output.
This commit is contained in:
1 parent
2b603b6f60
commit
43fe5cd8be
1 file changed
+25
-2
@@ -41,7 +41,19 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
|
||||
# type: (Union[unicode, bytes], str, str) -> bytes
|
||||
"""Make sure ``s_or_u`` is a bytestring."""
|
||||
"""
|
||||
Make sure ``s_or_u`` is a bytestring.
|
||||
|
||||
Arguments:
|
||||
s_or_u (string or unicode): The value to convert
|
||||
encoding (string): default 'utf-8'
|
||||
errors (string): The errors argument is the same as the argument of the decode() method but supports a few more possible handlers.
|
||||
As well as 'strict', 'ignore', and 'replace' (which in this case inserts a question mark instead of the unencodable character),
|
||||
there is also 'xmlcharrefreplace' (inserts an XML character reference), backslashreplace (inserts a \uNNNN escape sequence)
|
||||
and namereplace (inserts a \N{...} escape sequence).
|
||||
Returns:
|
||||
bytes: converted bytes.
|
||||
"""
|
||||
if s_or_u is None:
|
||||
return s_or_u
|
||||
|
||||
@@ -56,7 +68,18 @@ def to_bytes(s_or_u, encoding="utf-8", errors="strict"):
|
||||
|
||||
def to_unicode(s_or_u, encoding="utf-8", errors="strict"):
|
||||
# type: (Union[unicode, bytes], str, str) -> unicode
|
||||
"""Make sure ``s_or_u`` is a unicode string."""
|
||||
"""
|
||||
Make sure ``s_or_u`` is a unicode string.
|
||||
|
||||
Arguments:
|
||||
s_or_u (string or unicode): The value to convert
|
||||
encoding (string): default 'utf-8'
|
||||
errors (string): The errors argument specifies the response when the input string can’t be converted according to the encoding’s rules.
|
||||
Legal values for this argument are 'strict' (raise a UnicodeDecodeError exception), 'replace' (use U+FFFD, REPLACEMENT CHARACTER),
|
||||
'ignore' (just leave the character out of the Unicode result), or 'backslashreplace' (inserts a \xNN escape sequence).
|
||||
Returns:
|
||||
string: converted string.
|
||||
"""
|
||||
if s_or_u is None:
|
||||
return s_or_u
|
||||
|
||||
|
||||
Reference in new issue
Block a user