
    D6i
                     P    d dl mZ ddlmZ ddlmZ ee G d d                    Zy)    )total_ordering   )i18n)str_coerciblec                   Z    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y)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                  | _        y t        |t              r| j	                  |       || _        y t        dj                  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     f/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/sqlalchemy_utils/primitives/country.py__init__zCountry.__init__8   s_    ow/',,DI-MM/*'DILSS)22     c                 X    t        j                         j                  | j                     S N)r   
get_localeterritoriesr   r   s    r   namezCountry.nameE   s     ,,TYY77r   c                     	 t         j                  j                  d      j                  |    y # t        $ r t        d|       t        $ r Y y 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   sR    	JJd#//5 	RI$PQQ 		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__S   s>    eW%99

**s#99%%!!r   c                 ,    t        | j                        S r   )hashr   r   s    r   __hash__zCountry.__hash__[   s    DII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__a   s>    eW%99uzz))s#99u$$r   c                 N    | j                   j                   d| j                  dS )N())	__class__r   r   r   s    r   __repr__zCountry.__repr__h   s$    ..))*!DII=::r   c                     | j                   S r   )r   r   s    r   __unicode__zCountry.__unicode__k   s    yyr   N)r   
__module____qualname____doc__r   propertyr   classmethodr   r)   r,   r/   r1   r6   r8   r.   r   r   r   r      sS    ,\ 8 8  "#;r   r   N)	functoolsr    r   utilsr   r   r.   r   r   <module>rA      s2    $  ! c c  cr   