U
    hV                     @   s  d Z ddlmZmZmZ ddlmZmZ ddlmZm	Z	 ddlm
Z
 zddlmZmZ W nt ek
r   ddlZddlZejejd d	ksejejd d
kredejd dedfiZdZn Y nX dddgZedZefZdd Zdd Zdd ZedkrddlZe  dS )a  Phone number to time zone mapping functionality

>>> import phonenumbers
>>> from phonenumbers.timezone import time_zones_for_number
>>> ro_number = phonenumbers.parse("+40721234567", "RO")
>>> tzlist = time_zones_for_number(ro_number)
>>> len(tzlist)
1
>>> str(tzlist[0])
'Europe/Bucharest'
>>> dual_number = phonenumbers.parse("+976136234567", "US")
>>> tzlist = time_zones_for_number(dual_number)
>>> len(tzlist)
2
>>> str(tzlist[0])
'Asia/Choibalsan'
>>> str(tzlist[1])
'Asia/Ulaanbaatar'

   )prntuU_PLUS)PhoneNumberTypenumber_type)PhoneNumberFormatformat_number)is_number_type_geographical)TIMEZONE_DATATIMEZONE_LONGEST_PREFIX    Nzbuildmetadatafromxml.pyzbuildprefixdata.pyzAFailed to import generated data (but OK as during autogeneration))fileZ4411zEurope/London   UNKNOWN_TIMEZONE"time_zones_for_geographical_numbertime_zones_for_numberzEtc/Unknownc                 C   sX   t | tj}|tstdttddD ](}|dd|  }|tkr*t|   S q*t	S )aN  Returns a list of time zones to which a phone number belongs.

    This method assumes the validity of the number passed in has already been
    checked, and that the number is geo-localizable. We consider fixed-line
    and mobile numbers possible candidates for geo-localization.

    Arguments:
    numobj -- a valid phone number for which we want to get the time zones
                  to which it belongs
    Returns a list of the corresponding time zones or a single element list
    with the default unknown time zone if no other time zone was found or if
    the number was invalidz"Expect E164 number to start with +r   r   )
r   r   ZE164
startswithr   	Exceptionranger   r
   _UNKNOWN_TIME_ZONE_LIST)numobjZe164_num
prefix_lenprefix r   9/tmp/pip-unpacked-wheel-2dq4jqp8/phonenumbers/timezone.pyr   @   s    
c                 C   s2   t | }|tjkrtS t|| js*t| S t| S )a  As time_zones_for_geographical_number() but explicitly checks the
    validity of the number passed in.

    Arguments:
    numobj -- a valid phone number for which we want to get the time zones to which it belongs
    Returns a list of the corresponding time zones or a single element list with the default
    unknown time zone if no other time zone was found or if the number was invalid)r   r   UNKNOWNr   r	   country_code$_country_level_time_zones_for_numberr   )r   ntyper   r   r   r   Y   s    
c                 C   sD   t | j}ttddD ](}|dd|  }|tkrt|   S qtS )a>  Returns the list of time zones corresponding to the country calling code of a number.
    Arguments:
    numobj -- the phone number to look up
    Returns a list of the corresponding time zones or a single element list with the default
    unknown time zone if no other time zone was found or if the number was invalidr   r   Nr   )strr   r   r   r
   r   )r   ccr   r   r   r   r   r   i   s    
r   __main__)__doc__utilr   r   r   Zphonenumberutilr   r   r   r   r	   Ztzdatar
   r   ImportErrorossyspathbasenameargvstderr__all__r   r   r   r   r   __name__doctesttestmodr   r   r   r   <module>   s2   $

