forked from daviddrysdale/python-phonenumbers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphonenumbers.util.html
More file actions
151 lines (141 loc) · 9.44 KB
/
Copy pathphonenumbers.util.html
File metadata and controls
151 lines (141 loc) · 9.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module phonenumbers.util</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="phonenumbers.html"><font color="#ffffff">phonenumbers</font></a>.util</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/phonenumbers/util.py">phonenumbers/util.py</a></font></td></tr></table>
<p><tt>Python 2.x/3.x compatibility utilities.<br>
<br>
This module defines a collection of functions that allow the same Python<br>
source code to be used in both Python 2.x and Python 3.x.<br>
<br>
- <a href="#-prnt">prnt</a>() prints its arguments to a file, with given separator and ending.<br>
- to_long() creates a (long) integer <a href="builtins.html#object">object</a> from its input parameter.<br>
- u() allows string literals involving non-ASCII characters to be<br>
used in both Python 2.x / 3.x, e.g. u("ā is a-with-macron")<br>
- unicod() forces its argument to a Unicode string.<br>
- <a href="#-rpr">rpr</a>() generates a representation of a string that can be parsed in either<br>
Python 2.x or 3.x, assuming use of the u() function above.<br>
<br>
>>> from .util import prnt, u, rpr<br>
>>> <a href="#-prnt">prnt</a>("hello")<br>
hello<br>
>>> <a href="#-prnt">prnt</a>("hello", "world")<br>
hello world<br>
>>> <a href="#-prnt">prnt</a>("hello", "world", sep=":")<br>
hello:world<br>
>>> <a href="#-prnt">prnt</a>("hello", "world", sep=":", end='!\n')<br>
hello:world!<br>
>>> u('ā') == u('ā')<br>
True<br>
>>> u('ā') == u('ā')<br>
True<br>
>>> a_macron = u('ā')<br>
>>> <a href="#-rpr">rpr</a>(a_macron)<br>
"u('\\u0101')"<br>
>>> <a href="#-rpr">rpr</a>(u('abc')) == "'abc'" # In Python 2, LHS is Unicode but RHS is string<br>
True<br>
>>> <a href="#-rpr">rpr</a>("'")<br>
"'\\''"</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="builtins.html">builtins</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="phonenumbers.util.html#ImmutableMixin">ImmutableMixin</a>
</font></dt><dt><font face="helvetica, arial"><a href="phonenumbers.util.html#UnicodeMixin">UnicodeMixin</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="ImmutableMixin">class <strong>ImmutableMixin</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Mixin class to make objects of subclasses immutable<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="ImmutableMixin-__delattr__"><strong>__delattr__</strong></a>(self, name)</dt><dd><tt>Implement delattr(self, name).</tt></dd></dl>
<dl><dt><a name="ImmutableMixin-__setattr__"><strong>__setattr__</strong></a>(self, name, value)</dt><dd><tt>Implement setattr(self, name, value).</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="UnicodeMixin">class <strong>UnicodeMixin</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Mixin class to define a __str__ method in terms of __unicode__ method<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="UnicodeMixin-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>Return str(self).</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-force_unicode"><strong>force_unicode</strong></a>(s)</dt><dd><tt>Force the argument to be a Unicode string, preserving None</tt></dd></dl>
<dl><dt><a name="-mutating_method"><strong>mutating_method</strong></a>(func)</dt><dd><tt>Decorator for methods that are allowed to modify immutable objects</tt></dd></dl>
<dl><dt><a name="-print3"><strong>print3</strong></a> = print(...)</dt><dd><tt>print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)<br>
<br>
Prints the values to a stream, or to sys.stdout by default.<br>
Optional keyword arguments:<br>
file: a file-like <a href="builtins.html#object">object</a> (stream); defaults to the current sys.stdout.<br>
sep: string inserted between values, default a space.<br>
end: string appended after the last value, default a newline.<br>
flush: whether to forcibly flush the stream.</tt></dd></dl>
<dl><dt><a name="-prnt"><strong>prnt</strong></a>(*args, **kwargs)</dt></dl>
<dl><dt><a name="-rpr"><strong>rpr</strong></a>(s)</dt><dd><tt>Create a representation of a Unicode string that can be used in both<br>
Python 2 and Python 3k, allowing for use of the u() function</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>U_DASH</strong> = '-'<br>
<strong>U_EMPTY_STRING</strong> = ''<br>
<strong>U_PERCENT</strong> = '%'<br>
<strong>U_PLUS</strong> = '+'<br>
<strong>U_SEMICOLON</strong> = ';'<br>
<strong>U_SLASH</strong> = '/'<br>
<strong>U_SPACE</strong> = ' '<br>
<strong>U_STAR</strong> = '*'<br>
<strong>U_TILDE</strong> = '~'<br>
<strong>U_X_LOWER</strong> = 'x'<br>
<strong>U_X_UPPER</strong> = 'X'<br>
<strong>U_ZERO</strong> = '0'</td></tr></table>
</body></html>