Python: module phonenumbers.util

phonenumbers.util | index phonenumbers/util.py

`Python 2.x/3.x compatibility utilities.
This module defines a collection of functions that allow the same Python
source code to be used in both Python 2.x and Python 3.x.
- prnt() prints its arguments to a file, with given separator and ending.
- to_long() creates a (long) integer object from its input parameter.
- u() allows string literals involving non-ASCII characters to be
used in both Python 2.x / 3.x, e.g. u("ā is a-with-macron")
- unicod() forces its argument to a Unicode string.
- rpr() generates a representation of a string that can be parsed in either
Python 2.x or 3.x, assuming use of the u() function above.
>>> from .util import prnt, u, rpr
>>> prnt("hello")
hello
>>> prnt("hello", "world")
hello world
>>> prnt("hello", "world", sep=":")
hello:world
>>> prnt("hello", "world", sep=":", end='!\n')
hello:world!
>>> u('ā') == u('ā')
True
>>> u('ā') == u('ā')
True
>>> a_macron = u('ā')
>>> rpr(a_macron)
"u('\\u0101')"
>>> rpr(u('abc')) == "'abc'" # In Python 2, LHS is Unicode but RHS is string
True
>>> rpr("'")
"'\\''"`

Modules
`` |  |
builtins | sys |  |

Classes
`` |  | builtins.object ImmutableMixin UnicodeMixin
class ImmutableMixin(builtins.object)
`` | `Mixin class to make objects of subclasses immutable`
| Methods defined here: __delattr__(self, name) `Implement delattr(self, name).` __setattr__(self, name, value) `Implement setattr(self, name, value).` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class UnicodeMixin(builtins.object)
`` | `Mixin class to define a __str__ method in terms of __unicode__ method`
| Methods defined here: __str__(self) `Return str(self).` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`

Functions
`` |  | force_unicode(s) `Force the argument to be a Unicode string, preserving None` mutating_method(func) `Decorator for methods that are allowed to modify immutable objects` print3 = print(...) `print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.` prnt(*args, **kwargs) rpr(s) `Create a representation of a Unicode string that can be used in both Python 2 and Python 3k, allowing for use of the u() function`

Data
`` |  | U_DASH = '-' U_EMPTY_STRING = '' U_PERCENT = '%' U_PLUS = '+' U_SEMICOLON = ';' U_SLASH = '/' U_SPACE = ' ' U_STAR = '*' U_TILDE = '~' U_X_LOWER = 'x' U_X_UPPER = 'X' U_ZERO = '0'