Skip to content
Myr

adding unicode_is_ascii utility function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by Nate Prewitt · parent d52e9b8 · Browse files · 1 file+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−1 removed

  • other:+16 added−1 removed

1 file+16 added−1 removed

modified:requests/_internal_utils.py+16 added-1 removed
6 unmodified lines
7Provides utility functions that are consumed internally by Requests8which depend on extremely few external helpers (such as compat)9"""1011from .compat import is_py2, builtin_str11from .compat import is_py2, builtin_str, str121314def to_native_string(string, encoding='ascii'):15 """Given a string object, regardless of type, returns a representation of
8 unmodified lines
24 else:25 out = string.decode(encoding)2627 return out282930def unicode_is_ascii(u_string):31 """Determine if unicode string only contains ASCII characters.3233 :param str u_string: unicode string to check. Must be unicode34 and not Python 2 `str`.35 :rtype: bool36 """37 assert isinstance(u_string, str)38 try:39 u_string.encode('ascii')40 return True41 except UnicodeEncodeError:42 return False