|
116 | 116 | truncate_too_long_number,) |
117 | 117 | from .shortnumberutil import connects_to_emergency_number, is_emergency_number |
118 | 118 | from .phonenumbermatcher import PhoneNumberMatch, PhoneNumberMatcher, Leniency |
119 | | -from .geocoder import (area_description_for_number, country_name_for_number, |
120 | | - description_for_number, description_for_valid_number) |
| 119 | + |
| 120 | + |
| 121 | +# The geodata occupies a lot of space, so only perform the import on first use |
| 122 | +# of geocoder functionality. |
| 123 | +def area_description_for_number(*args, **kwargs): |
| 124 | + """Return a text description of the area of a PhoneNumber for the given language. |
| 125 | +
|
| 126 | + Arguments: |
| 127 | + numobj -- The PhoneNumber object for which we want to get a text description. |
| 128 | + lang -- A 2-letter lowercase ISO 639-1 language code for the language in |
| 129 | + which the description should be returned (e.g. "en") |
| 130 | + script -- A 4-letter titlecase (first letter uppercase, rest lowercase) |
| 131 | + ISO script code as defined in ISO 15924, separated by an |
| 132 | + underscore (e.g. "Hant") |
| 133 | + region -- A 2-letter uppercase ISO 3166-1 country code (e.g. "GB") |
| 134 | +
|
| 135 | + Returns a text description in the given language code, for the given phone |
| 136 | + number's area, or an empty string if no description is available.""" |
| 137 | + from .geocoder import area_description_for_number as real_fn |
| 138 | + return real_fn(*args, **kwargs) |
| 139 | + |
| 140 | + |
| 141 | +def country_name_for_number(*args, **kwargs): |
| 142 | + """Return the given PhoneNumber object's country name in the given language. |
| 143 | +
|
| 144 | + Arguments: |
| 145 | + numobj -- The PhoneNumber object for which we want to get a text description. |
| 146 | + lang -- A 2-letter lowercase ISO 639-1 language code for the language in |
| 147 | + which the description should be returned (e.g. "en") |
| 148 | + script -- A 4-letter titlecase (first letter uppercase, rest lowercase) |
| 149 | + ISO script code as defined in ISO 15924, separated by an |
| 150 | + underscore (e.g. "Hant") |
| 151 | + region -- A 2-letter uppercase ISO 3166-1 country code (e.g. "GB") |
| 152 | +
|
| 153 | + The script and region parameters are currently ignored. |
| 154 | +
|
| 155 | + Returns a text description in the given language code, for the given phone |
| 156 | + number's region, or an empty string if no description is available.""" |
| 157 | + from .geocoder import country_name_for_number as real_fn |
| 158 | + return real_fn(*args, **kwargs) |
| 159 | + |
| 160 | + |
| 161 | +def description_for_number(*args, **kwargs): |
| 162 | + """Return a text description of a PhoneNumber object for the given language. |
| 163 | +
|
| 164 | + The description might consist of the name of the country where the phone |
| 165 | + number is from and/or the name of the geographical area the phone number |
| 166 | + is from. This function explicitly checks the validity of the number passed in |
| 167 | +
|
| 168 | + Arguments: |
| 169 | + numobj -- The PhoneNumber object for which we want to get a text description. |
| 170 | + lang -- A 2-letter lowercase ISO 639-1 language code for the language in |
| 171 | + which the description should be returned (e.g. "en") |
| 172 | + script -- A 4-letter titlecase (first letter uppercase, rest lowercase) |
| 173 | + ISO script code as defined in ISO 15924, separated by an |
| 174 | + underscore (e.g. "Hant") |
| 175 | + region -- A 2-letter uppercase ISO 3166-1 country code (e.g. "GB") |
| 176 | +
|
| 177 | + Returns a text description in the given language code, for the given phone |
| 178 | + number, or an empty string if no description is available.""" |
| 179 | + from .geocoder import description_for_number as real_fn |
| 180 | + return real_fn(*args, **kwargs) |
| 181 | + |
| 182 | + |
| 183 | +def description_for_valid_number(*args, **kwargs): |
| 184 | + """Return a text description of a PhoneNumber object, in the language |
| 185 | + provided. |
| 186 | +
|
| 187 | + The description might consist of the name of the country where the phone |
| 188 | + number is from and/or the name of the geographical area the phone number |
| 189 | + is from if more detailed information is available. |
| 190 | +
|
| 191 | + If the phone number is from the same region as the user, only a |
| 192 | + lower-level description will be returned, if one exists. Otherwise, the |
| 193 | + phone number's region will be returned, with optionally some more detailed |
| 194 | + information. |
| 195 | +
|
| 196 | + For example, for a user from the region "US" (United States), we would |
| 197 | + show "Mountain View, CA" for a particular number, omitting the United |
| 198 | + States from the description. For a user from the United Kingdom (region |
| 199 | + "GB"), for the same number we may show "Mountain View, CA, United States" |
| 200 | + or even just "United States". |
| 201 | +
|
| 202 | + This function assumes the validity of the number passed in has already |
| 203 | + been checked, and that the number is suitable for geocoding. We consider |
| 204 | + fixed-line and mobile numbers possible candidates for geocoding. |
| 205 | +
|
| 206 | + Arguments: |
| 207 | + numobj -- A valid PhoneNumber object for which we want to get a text |
| 208 | + description. |
| 209 | + lang -- A 2-letter lowercase ISO 639-1 language code for the language in |
| 210 | + which the description should be returned (e.g. "en") |
| 211 | + script -- A 4-letter titlecase (first letter uppercase, rest lowercase) |
| 212 | + ISO script code as defined in ISO 15924, separated by an |
| 213 | + underscore (e.g. "Hant") |
| 214 | + region -- The region code for a given user. This region will be omitted |
| 215 | + from the description if the phone number comes from this |
| 216 | + region. It is a two-letter uppercase ISO country code as |
| 217 | + defined by ISO 3166-1. |
| 218 | +
|
| 219 | + Returns a text description in the given language code, for the given phone |
| 220 | + number, or an empty string if no description is available.""" |
| 221 | + from .geocoder import description_for_valid_number as real_fn |
| 222 | + return real_fn(*args, **kwargs) |
121 | 223 |
|
122 | 224 |
|
123 | 225 | # Version number is taken from the upstream libphonenumber version |
124 | 226 | # together with an indication of the version of the Python-specific code. |
125 | | -__version__ = "5.2b1" |
| 227 | +__version__ = "5.3b1" |
126 | 228 |
|
127 | 229 | __all__ = ['PhoneNumber', 'CountryCodeSource', 'FrozenPhoneNumber', |
128 | 230 | 'REGION_CODE_FOR_NON_GEO_ENTITY', 'NumberFormat', 'PhoneNumberDesc', 'PhoneMetadata', |
|
0 commit comments