
    j
                     d    d dl mZ ddlmZ ddlmZ ee G d d                                  ZdS )    )total_ordering   )i18n)str_coerciblec                   h    e Zd ZdZd Zed             Zed             Zd Z	d Z
d Zd Zd	 Zd
 ZdS )Countrya  
    Country class wraps a 2 to 3 letter country code. It provides various
    convenience properties and methods.

    ::

        from babel import Locale
        from sqlalchemy_utils import Country, i18n


        # First lets add a locale getter for testing purposes
        i18n.get_locale = lambda: Locale('en')


        Country('FI').name  # Finland
        Country('FI').code  # FI

        Country(Country('FI')).code  # 'FI'

    Country always validates the given code if you use at least the optional
    dependency list 'babel', otherwise no validation are performed.

    ::

        Country(None)  # raises TypeError

        Country('UnknownCode')  # raises ValueError


    Country supports equality operators.

    ::

        Country('FI') == Country('FI')
        Country('FI') != Country('US')


    Country objects are hashable.


    ::

        assert hash(Country('FI')) == hash('FI')

    c                    t          |t                    r|j        | _        d S t          |t                    r|                     |           || _        d S t          d                    t          |          j                            )Nz:Country() argument must be a string or a country, not '{}')	
isinstancer   codestrvalidate	TypeErrorformattype__name__)selfcode_or_countrys     m/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/sqlalchemy_utils/primitives/country.py__init__zCountry.__init__7   s    ow// 	',DIII-- 		MM/***'DIIIL))2       c                 H    t          j                    j        | j                 S N)r   
get_localeterritoriesr   r   s    r   namezCountry.nameE   s      ,TY77r   c                     	 t           j                            d          j        |          d S # t          $ r t          d|           t          $ r Y d S w xY w)Nenz*Could not convert string to country code: )r   babelLocaler   KeyError
ValueErrorAttributeError)r   r   s     r   r   zCountry.validateI   s~    	Jd##/5555 	 	 	CTCC    	 	 	DD	s   *. %AAc                     t          |t                    r| j        |j        k    S t          |t                    r| j        |k    S t          S r   r
   r   r   r   NotImplementedr   others     r   __eq__zCountry.__eq__U   sH    eW%% 	"9
**s## 	"9%%!!r   c                 *    t          | j                  S r   )hashr   r   s    r   __hash__zCountry.__hash__]   s    DIr   c                     | |k     S r    r'   s     r   __ne__zCountry.__ne__`   s    EM""r   c                     t          |t                    r| j        |j        k     S t          |t                    r| j        |k     S t          S r   r%   r'   s     r   __lt__zCountry.__lt__c   sH    eW%% 	%9uz))s## 	%9u$$r   c                 0    | j         j         d| j        dS )N())	__class__r   r   r   s    r   __repr__zCountry.__repr__j   s     .)::DI::::r   c                     | j         S r   )r   r   s    r   __unicode__zCountry.__unicode__m   s
    yr   N)r   
__module____qualname____doc__r   propertyr   classmethodr   r)   r,   r/   r1   r6   r8   r.   r   r   r   r      s        , ,Z   8 8 X8 	 	 [	" " "  # # #  ; ; ;    r   r   N)	functoolsr    r   utilsr   r   r.   r   r   <module>rA      s    $ $ $ $ $ $       ! ! ! ! ! ! e e e e e e e  e e er   