Skip to content

Commit

Permalink
Add CountryCodeSource.to_string() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Apr 18, 2023
1 parent c464a74 commit 19b9e52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion python/phonenumbers/phonenumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# 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
from .util import to_long, unicod, rpr, force_unicode, u


class CountryCodeSource(object):
Expand Down Expand Up @@ -48,6 +48,20 @@ class CountryCodeSource(object):
# supplied as France.
FROM_DEFAULT_COUNTRY = 20

@classmethod
def to_string(cls, val):
"""Return a string representation of a CountryCodeSource value"""
if val == CountryCodeSource.UNSPECIFIED:
return u("UNSPECIFIED")
elif val == CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN:
return u("FROM_NUMBER_WITH_PLUS_SIGN")
elif val == CountryCodeSource.FROM_NUMBER_WITH_IDD:
return u("FROM_NUMBER_WITH_IDD")
elif val == CountryCodeSource.FROM_DEFAULT_COUNTRY:
return u("FROM_DEFAULT_COUNTRY")
else:
return u("INVALID (%d)" % val)


class PhoneNumber(UnicodeMixin):
"""Class representing international telephone numbers.
Expand Down
2 changes: 2 additions & 0 deletions python/phonenumbers/phonenumber.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CountryCodeSource:
FROM_NUMBER_WITH_IDD: int
FROM_NUMBER_WITHOUT_PLUS_SIGN: int
FROM_DEFAULT_COUNTRY: int
@classmethod
def to_string(cls, val: int) -> str: ...

class PhoneNumber(UnicodeMixin):
country_code: int | None
Expand Down

0 comments on commit 19b9e52

Please sign in to comment.