@@ -24,24 +24,24 @@ class CountryCodeSource(object):
2424 """The source from which a country code is derived."""
2525
2626 # The country_code is derived based on a phone number with a leading "+",
27- # e.g. the French number "+33 (0) 1 42 68 53 00".
27+ # e.g. the French number "+33 1 42 68 53 00".
2828 FROM_NUMBER_WITH_PLUS_SIGN = 1
2929
3030 # The country_code is derived based on a phone number with a leading IDD,
31- # e.g. the French number "011 33 (0) 1 42 68 53 00", as it is dialled
31+ # e.g. the French number "011 33 1 42 68 53 00", as it is dialled
3232 # from US.
3333 FROM_NUMBER_WITH_IDD = 5
3434
3535 # The country_code is derived based on a phone number without a leading
36- # "+", e.g. the French number "33 (0) 1 42 68 53 00" when default_country is
36+ # "+", e.g. the French number "33 1 42 68 53 00" when default_country is
3737 # supplied as France.
3838 FROM_NUMBER_WITHOUT_PLUS_SIGN = 10
3939
4040 # The country_code is derived NOT based on the phone number itself, but
4141 # from the default_country parameter provided in the parsing function by
4242 # the clients. This happens mostly for numbers written in the national
4343 # format (without country code). For example, this would be set when
44- # parsing the French number "(0)1 42 68 53 00", when default_country is
44+ # parsing the French number "01 42 68 53 00", when default_country is
4545 # supplied as France.
4646 FROM_DEFAULT_COUNTRY = 20
4747
@@ -58,6 +58,7 @@ def __init__(self,
5858 national_number = None ,
5959 extension = None ,
6060 italian_leading_zero = False ,
61+ number_of_leading_zeros = None ,
6162 raw_input = None ,
6263 country_code_source = None ,
6364 preferred_domestic_carrier_code = None ):
@@ -71,18 +72,21 @@ def __init__(self,
7172 else :
7273 self .country_code = int (country_code )
7374
75+ # Number does not contain National(trunk) prefix.
7476 # National (significant) Number is defined in International
75- # Telecommunication Union Recommendation E.164. It is a
77+ # Telecommunication Union (ITU) Recommendation E.164. It is a
7678 # language/country-neutral representation of a phone number at a
77- # country level. For countries which have the concept of Area Code, the
78- # National (significant) Number contains the area code. It contains a
79- # maximum number of digits which equal to 15 - n, where n is the number
80- # of digits of the country code. Take note that National (significant)
81- # Number does not contain National(trunk) prefix.
79+ # country level. For countries which have the concept of Area Code,
80+ # the National (significant) Number contains the area code. It
81+ # contains a maximum number of digits which equal to 15 - n, where n
82+ # is the number of digits of the country code. Take note that National
83+ # (significant) Number does not contain National(trunk)
84+ # prefix.
8285 #
8386 # None if not set, of type long otherwise (and so it will never
8487 # contain any formatting (hypens, spaces, parentheses), nor any
8588 # alphanumeric spellings).
89+
8690 if national_number is None :
8791 self .national_number = None
8892 else :
@@ -98,23 +102,25 @@ def __init__(self,
98102 # However, only ASCII digits should be stored here.
99103 self .extension = force_unicode (extension ) # None or Unicode '[0-9]+'
100104
101- # In some countries, the national (significant) number starts with
102- # a "0" without this being a national prefix or trunk code of some
103- # kind. For example, the leading zero in the national (significant)
104- # number of an Italian phone number indicates the number is a
105- # fixed-line number. There have been plans to migrate fixed-line
105+ # In some countries, the national (significant) number starts with one
106+ # or more "0"s without this being a national prefix or trunk code of
107+ # some kind. For example, the leading zero in the national
108+ # (significant) number of an Italian phone number indicates the number
109+ # is a fixed-line number. There have been plans to migrate fixed-line
106110 # numbers to start with the digit two since December 2000, but it has
107111 # not happened yet. See http://en.wikipedia.org/wiki/%2B39 for more
108112 # details.
109113 #
110- # This field can be safely ignored (there is no need to set it) for
111- # most countries. Some limited amount of countries behave like Italy;
112- # for these cases, if the leading zero of a number would be
113- # retained even when dialling internationally, set this flag to true.
114+ # These fields can be safely ignored (there is no need to set them)
115+ # for most countries. Some limited number of countries behave like
116+ # Italy - for these cases, if the leading zero(s) of a number would be
117+ # retained even when dialling internationally, set this flag to true,
118+ # and also set the number of leading zeros.
114119 #
115- # Clients who use the parsing functionality of the phonenumbers
116- # library will have this field set if necessary automatically.
120+ # Clients who use the parsing functionality of the i18n phone number
121+ # libraries will have these fields set if necessary automatically.
117122 self .italian_leading_zero = bool (italian_leading_zero )
123+ self .number_of_leading_zeros = number_of_leading_zeros # None or int
118124
119125 # The next few fields are non-essential fields for a phone number.
120126 # They retain extra information about the form the phone number was
@@ -151,6 +157,7 @@ def clear(self):
151157 self .national_number = None
152158 self .extension = None
153159 self .italian_leading_zero = False
160+ self .number_of_leading_zeros = None
154161 self .raw_input = None
155162 self .country_code_source = None
156163 self .preferred_domestic_carrier_code = None
@@ -165,6 +172,8 @@ def merge_from(self, other):
165172 self .extension = other .extension
166173 if other .italian_leading_zero is not None :
167174 self .italian_leading_zero = other .italian_leading_zero
175+ if other .number_of_leading_zeros is not None :
176+ self .number_of_leading_zeros = other .number_of_leading_zeros
168177 if other .raw_input is not None :
169178 self .raw_input = other .raw_input
170179 if other .country_code_source is not None :
@@ -179,6 +188,7 @@ def __eq__(self, other):
179188 self .national_number == other .national_number and
180189 self .extension == other .extension and
181190 self .italian_leading_zero == other .italian_leading_zero and
191+ self .number_of_leading_zeros == other .number_of_leading_zeros and
182192 self .raw_input == other .raw_input and
183193 self .country_code_source == other .country_code_source and
184194 self .preferred_domestic_carrier_code == other .preferred_domestic_carrier_code )
@@ -188,19 +198,23 @@ def __ne__(self, other):
188198
189199 def __repr__ (self ):
190200 return (unicod ("PhoneNumber(country_code=%s, national_number=%s, extension=%s, " +
191- "italian_leading_zero=%s, country_code_source=%s, preferred_domestic_carrier_code=%s)" ) %
201+ "italian_leading_zero=%s, number_of_leading_zeros=%s, " +
202+ "country_code_source=%s, preferred_domestic_carrier_code=%s)" ) %
192203 (self .country_code ,
193204 self .national_number ,
194205 rpr (self .extension ),
195206 self .italian_leading_zero ,
207+ self .number_of_leading_zeros ,
196208 self .country_code_source ,
197209 rpr (self .preferred_domestic_carrier_code )))
198210
199211 def __unicode__ (self ):
200212 result = (unicod ("Country Code: %s National Number: %s" ) %
201213 (self .country_code , self .national_number ))
202214 if self .italian_leading_zero is not None :
203- result += unicod (" Leading Zero: %s" ) % self .italian_leading_zero
215+ result += unicod (" Leading Zero(s): %s" ) % self .italian_leading_zero
216+ if self .number_of_leading_zeros is not None :
217+ result += unicod (" Number of leading zeros: %d" ) % self .number_of_leading_zeros
204218 if self .extension is not None :
205219 result += unicod (" Extension: %s" ) % self .extension
206220 if self .country_code_source is not None :
@@ -218,6 +232,7 @@ def __hash__(self):
218232 self .national_number ,
219233 self .extension ,
220234 self .italian_leading_zero ,
235+ self .number_of_leading_zeros ,
221236 self .raw_input ,
222237 self .country_code_source ,
223238 self .preferred_domestic_carrier_code ))
0 commit comments