This file is indexed.

/usr/lib/python3/dist-packages/phonenumbers/phonenumber.py is in python3-phonenumbers 8.8.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
"""PhoneNumber object definition"""

# Based on original Java code and protocol buffer:
#     resources/phonenumber.proto
#     java/src/com/google/i18n/phonenumbers/Phonenumber.java
#   Copyright (C) 2010-2011 The Libphonenumber Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .util import UnicodeMixin, ImmutableMixin, mutating_method
from .util import to_long, unicod, rpr, force_unicode


class CountryCodeSource(object):
    """The source from which a country code is derived."""
    # Default value returned if this is not set, because the phone number was
    # created using parse(keep_raw_input=False).
    UNSPECIFIED = 0

    # The country_code is derived based on a phone number with a leading "+",
    # e.g. the French number "+33 1 42 68 53 00".
    FROM_NUMBER_WITH_PLUS_SIGN = 1

    # The country_code is derived based on a phone number with a leading IDD,
    # e.g. the French number "011 33 1 42 68 53 00", as it is dialled
    # from US.
    FROM_NUMBER_WITH_IDD = 5

    # The country_code is derived based on a phone number without a leading
    # "+", e.g. the French number "33 1 42 68 53 00" when default_country is
    # supplied as France.
    FROM_NUMBER_WITHOUT_PLUS_SIGN = 10

    # The country_code is derived NOT based on the phone number itself, but
    # from the default_country parameter provided in the parsing function by
    # the clients. This happens mostly for numbers written in the national
    # format (without country code). For example, this would be set when
    # parsing the French number "01 42 68 53 00", when default_country is
    # supplied as France.
    FROM_DEFAULT_COUNTRY = 20


class PhoneNumber(UnicodeMixin):
    """Class representing international telephone numbers.

    This class is hand-created based on phonenumber.proto. Please refer
    to that file for detailed descriptions of the meaning of each field.
    """

    def __init__(self,
                 country_code=None,
                 national_number=None,
                 extension=None,
                 italian_leading_zero=None,
                 number_of_leading_zeros=None,
                 raw_input=None,
                 country_code_source=CountryCodeSource.UNSPECIFIED,
                 preferred_domestic_carrier_code=None):
        # The country calling code for this number, as defined by the
        # International Telecommunication Union (ITU). For example, this would
        # be 1 for NANPA countries, and 33 for France.
        #
        # None if not set, of type int otherwise.
        if country_code is None:
            self.country_code = None
        else:
            self.country_code = int(country_code)

        # Number does not contain National(trunk) prefix.
        # National (significant) Number is defined in International
        # Telecommunication Union (ITU) Recommendation E.164. It is a
        # language/country-neutral representation of a phone number at a
        # country level. For countries which have the concept of an "area
        # code" or "national destination code", this is included in the
        # National (significant) Number. Although the ITU says the maximum
        # length should be 15, we have found longer numbers in some countries
        # e.g. Germany.  Note that the National (significant) Number does not
        # contain the National(trunk) prefix.
        #
        # None if not set, of type long otherwise (and so it will never
        # contain any formatting (hypens, spaces, parentheses), nor any
        # alphanumeric spellings).

        if national_number is None:
            self.national_number = None
        else:
            self.national_number = to_long(national_number)

        # Extension is not standardized in ITU recommendations, except for
        # being defined as a series of numbers with a maximum length of 40
        # digits.
        #
        # When present, it is a Unicode string to accommodate for the
        # possible use of a leading zero in the extension (organizations
        # have complete freedom to do so, as there is no standard defined).
        # However, only ASCII digits should be stored here.
        self.extension = force_unicode(extension)  # None or Unicode '[0-9]+'

        # In some countries, the national (significant) number starts with one
        # or more "0"s without this being a national prefix or trunk code of
        # some kind. For example, the leading zero in the national
        # (significant) number of an Italian phone number indicates the number
        # is a fixed-line number.  There have been plans to migrate fixed-line
        # numbers to start with the digit two since December 2000, but it has
        # not happened yet. See http://en.wikipedia.org/wiki/%2B39 for more
        # details.
        #
        # These fields can be safely ignored (there is no need to set them)
        # for most countries. Some limited number of countries behave like
        # Italy - for these cases, if the leading zero(s) of a number would be
        # retained even when dialling internationally, set this flag to true,
        # and also set the number of leading zeros.
        #
        # Clients who use the parsing functionality of the i18n phone number
        # libraries will have these fields set if necessary automatically.
        #
        # None if not set, of type bool otherwise:
        if italian_leading_zero is None:
            self.italian_leading_zero = None
        else:
            self.italian_leading_zero = bool(italian_leading_zero)

        # None if not set, of type int otherwise.
        if number_of_leading_zeros is None:
            self.number_of_leading_zeros = None
        else:
            self.number_of_leading_zeros = int(number_of_leading_zeros)

        # The next few fields are non-essential fields for a phone number.
        # They retain extra information about the form the phone number was
        # in when it was provided to us to parse. They can be safely
        # ignored by most clients.

        # This field is used to store the raw input string containing phone
        # numbers before it was canonicalized by the library. For example, it
        # could be used to store alphanumerical numbers such as
        # "1-800-GOOG-411".
        self.raw_input = force_unicode(raw_input)  # None or Unicode string

        # The source from which the country_code is derived. This is not set
        # in the general parsing method, but in the method that parses and
        # keeps raw_input. New fields could be added upon request.
        self.country_code_source = country_code_source  # CountryCodeSource.VALUE
        if self.country_code_source is None:  # pragma no cover
            self.country_code_source = CountryCodeSource.UNSPECIFIED

        # The carrier selection code that is preferred when calling this
        # phone number domestically. This also includes codes that need to
        # be dialed in some countries when calling from landlines to mobiles
        # or vice versa. For example, in Columbia, a "3" needs to be dialed
        # before the phone number itself when calling from a mobile phone to
        # a domestic landline phone and vice versa.
        #
        # Note this is the "preferred" code, which means other codes may work
        # as well.
        self.preferred_domestic_carrier_code = force_unicode(preferred_domestic_carrier_code)
        # None or Unicode string

    def clear(self):
        """Erase the contents of the object"""
        self.country_code = None
        self.national_number = None
        self.extension = None
        self.italian_leading_zero = None
        self.number_of_leading_zeros = None
        self.raw_input = None
        self.country_code_source = CountryCodeSource.UNSPECIFIED
        self.preferred_domestic_carrier_code = None

    def merge_from(self, other):
        """Merge information from another PhoneNumber object into this one."""
        if other.country_code is not None:
            self.country_code = other.country_code
        if other.national_number is not None:
            self.national_number = other.national_number
        if other.extension is not None:
            self.extension = other.extension
        if other.italian_leading_zero is not None:
            self.italian_leading_zero = other.italian_leading_zero
        if other.number_of_leading_zeros is not None:
            self.number_of_leading_zeros = other.number_of_leading_zeros
        if other.raw_input is not None:
            self.raw_input = other.raw_input
        if other.country_code_source is not CountryCodeSource.UNSPECIFIED:
            self.country_code_source = other.country_code_source
        if other.preferred_domestic_carrier_code is not None:
            self.preferred_domestic_carrier_code = other.preferred_domestic_carrier_code

    def __eq__(self, other):
        if not isinstance(other, PhoneNumber):
            return False
        return (self.country_code == other.country_code and
                self.national_number == other.national_number and
                self.extension == other.extension and
                bool(self.italian_leading_zero) == bool(other.italian_leading_zero) and
                self.number_of_leading_zeros == other.number_of_leading_zeros and
                self.raw_input == other.raw_input and
                self.country_code_source == other.country_code_source and
                self.preferred_domestic_carrier_code == other.preferred_domestic_carrier_code)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __repr__(self):
        return (unicod("PhoneNumber(country_code=%s, national_number=%s, extension=%s, " +
                       "italian_leading_zero=%s, number_of_leading_zeros=%s, " +
                       "country_code_source=%s, preferred_domestic_carrier_code=%s)") %
                (self.country_code,
                 self.national_number,
                 rpr(self.extension),
                 self.italian_leading_zero,
                 self.number_of_leading_zeros,
                 self.country_code_source,
                 rpr(self.preferred_domestic_carrier_code)))

    def __unicode__(self):
        result = (unicod("Country Code: %s National Number: %s") %
                  (self.country_code, self.national_number))
        if self.italian_leading_zero is not None:
            result += unicod(" Leading Zero(s): %s") % self.italian_leading_zero
        if self.number_of_leading_zeros is not None:
            result += unicod(" Number of leading zeros: %d") % self.number_of_leading_zeros
        if self.extension is not None:
            result += unicod(" Extension: %s") % self.extension
        if self.country_code_source is not CountryCodeSource.UNSPECIFIED:
            result += unicod(" Country Code Source: %s") % self.country_code_source
        if self.preferred_domestic_carrier_code is not None:
            result += (unicod(" Preferred Domestic Carrier Code: %s") %
                       self.preferred_domestic_carrier_code)
        return result


class FrozenPhoneNumber(PhoneNumber, ImmutableMixin):
    """Immutable version of PhoneNumber"""
    def __hash__(self):
        return hash((self.country_code,
                     self.national_number,
                     self.extension,
                     bool(self.italian_leading_zero),
                     self.number_of_leading_zeros,
                     self.raw_input,
                     self.country_code_source,
                     self.preferred_domestic_carrier_code))

    @mutating_method
    def __init__(self, *args, **kwargs):
        if len(kwargs) == 0 and len(args) == 1 and isinstance(args[0], PhoneNumber):
            # Copy constructor
            super(FrozenPhoneNumber, self).__init__(**args[0].__dict__)
        else:
            super(FrozenPhoneNumber, self).__init__(*args, **kwargs)