Class representing the description of a set of phone numbers.
| 148 | |
| 149 | |
| 150 | class PhoneNumberDesc(UnicodeMixin, ImmutableMixin): |
| 151 | """Class representing the description of a set of phone numbers.""" |
| 152 | @mutating_method |
| 153 | def __init__(self, |
| 154 | national_number_pattern=None, |
| 155 | example_number=None, |
| 156 | possible_length=None, |
| 157 | possible_length_local_only=None): |
| 158 | # The national_number_pattern is the pattern that a valid national |
| 159 | # significant number would match. This specifies information such as |
| 160 | # its total length and leading digits. |
| 161 | self.national_number_pattern = force_unicode(national_number_pattern) # None or Unicode string holding regexp |
| 162 | |
| 163 | # An example national significant number for the specific type. It |
| 164 | # should not contain any formatting information. |
| 165 | self.example_number = force_unicode(example_number) # None or Unicode string |
| 166 | |
| 167 | # These represent the lengths a phone number from this region can be. They |
| 168 | # will be sorted from smallest to biggest. Note that these lengths are for |
| 169 | # the full number, without country calling code or national prefix. For |
| 170 | # example, for the Swiss number +41789270000, in local format 0789270000, |
| 171 | # this would be 9. |
| 172 | # This could be used to highlight tokens in a text that may be a phone |
| 173 | # number, or to quickly prune numbers that could not possibly be a phone |
| 174 | # number for this locale. |
| 175 | if possible_length is None: |
| 176 | possible_length = () |
| 177 | self.possible_length = possible_length # sequence of int |
| 178 | |
| 179 | # These represent the lengths that only local phone numbers (without an area |
| 180 | # code) from this region can be. They will be sorted from smallest to |
| 181 | # biggest. For example, since the American number 456-1234 may be locally |
| 182 | # diallable, although not diallable from outside the area, 7 could be a |
| 183 | # possible value. |
| 184 | # This could be used to highlight tokens in a text that may be a phone |
| 185 | # number. |
| 186 | # To our knowledge, area codes are usually only relevant for some fixed-line |
| 187 | # and mobile numbers, so this field should only be set for those types of |
| 188 | # numbers (and the general description) - however there are exceptions for |
| 189 | # NANPA countries. |
| 190 | if possible_length_local_only is None: |
| 191 | possible_length_local_only = () |
| 192 | self.possible_length_local_only = possible_length_local_only # sequence of int |
| 193 | |
| 194 | def merge_from(self, other): |
| 195 | """Merge information from another PhoneNumberDesc object into this one.""" |
| 196 | if other.national_number_pattern is not None: |
| 197 | self.national_number_pattern = other.national_number_pattern |
| 198 | if other.example_number is not None: |
| 199 | self.example_number = other.example_number |
| 200 | |
| 201 | def __eq__(self, other): |
| 202 | if not isinstance(other, PhoneNumberDesc): |
| 203 | return False |
| 204 | return (repr(self) == repr(other)) |
| 205 | |
| 206 | def __ne__(self, other): |
| 207 | return not self.__eq__(other) |
no outgoing calls