o
    NjZ                     @   s   d dl Z G dd dZdS )    Nc                   @   s   e Zd ZdZdddddddd	d
dddddddddddddddddddddddddddddd dd!Zd"d# e D Zed$ed%ed&B fd'd(Z	ed$ed)ed%efd*d+Z
ed$ed%eeef fd,d-Zd&S ).CookieConverteruZ  
    Converts Amazon session cookies between regional variants.

    Amazon uses region-specific suffixes in cookie names (e.g. -acbmx, -main, -acbca)
    and values (currency, locale). This converter rewrites those markers so a session
    obtained from one storefront can be used on another.

    Supported: MX ↔ US, MX ↔ CA, US ↔ CA
    mainUSDen_USz
amazon.com)suffixcurrencylocaledomainacbcaCADen_CAz	amazon.caacbmxMXNes_MXzamazon.com.mxZacbukGBPen_GBzamazon.co.ukZacbfrEURfr_FRz	amazon.frZacbitit_ITz	amazon.itZacbeses_ESz	amazon.esZacbauAUDen_AUzamazon.com.au)USCAMXZUKFRITESAUc                 C   s   h | ]}|d  qS )r    ).0vr   r   4/Users/user/Downloads/amz/amazon/cookie_converter.py	<setcomp>   s    zCookieConverter.<setcomp>cookie_textreturnNc                 C   s2   | j  D ]\}}d|d  |v r|  S qdS )z>Detect the region of a cookie string based on suffix patterns.-r   N)REGIONSitems)clsr$   codeZcfgr   r   r"   detect_region   s
   zCookieConverter.detect_regiontarget_regionc                 C   s   |  }|| jvr|S | |}|r||kr|S | j| }| j| }|}tdt|d  dd|d  |}tdt|d  d|d |}tdt|d  d|d  |}tt|d |d |}|S )z
        Convert cookie_text to the target region.

        If the cookie is already in the target region, returns it unchanged.
        Auto-detects source region from the cookie content.
        r&   r   z\bz(i18n-prefs=)r   z\1r   )upperr'   r+   resubescape)r)   r$   r,   sourcesrcdstoutr   r   r"   convert%   s<   



zCookieConverter.convertc                    s    fdd j D S )z
        Convert a cookie string to all supported regions.

        Returns a dict with all supported regions converted.
        The source region entry will be the original cookie unchanged.
        c                    s   i | ]	}|  |qS r   )r5   )r    r*   r)   r$   r   r"   
<dictcomp>`   s    z/CookieConverter.convert_all.<locals>.<dictcomp>)r'   r6   r   r6   r"   convert_allX   s   zCookieConverter.convert_all)__name__
__module____qualname____doc__r'   valuesZ_ALL_SUFFIXESclassmethodstrr+   r5   dictr8   r   r   r   r"   r      s$    2 r   )r.   r   r   r   r   r"   <module>   s    