
    NjZ                          d dl Z  G d d      Zy)    Nc                   *   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ej                         D  ch c]  }|d"   	 c}} Zed#ed$ed%z  fd&       Z	ed#ed'ed$efd(       Z
ed#ed$eeef   fd)       Zy%c c}} w )*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.mxacbukGBPen_GBzamazon.co.ukacbfrEURfr_FRz	amazon.fracbitit_ITz	amazon.itacbeses_ESz	amazon.esacbauAUDen_AUzamazon.com.au)USCAMXUKFRITESAUr   cookie_textreturnNc                 d    | j                   j                         D ]  \  }}d|d    |v s|c S  y)z>Detect the region of a cookie string based on suffix patterns.-r   N)REGIONSitems)clsr'   codecfgs       >C:\Users\Sxnti\OneDrive\Desktop\amz\amazon\cookie_converter.pydetect_regionzCookieConverter.detect_region   s<     **,ID#3x=/"k1 -     target_regionc                 \   |j                         }|| j                  vr|S | j                  |      }|r||k(  r|S | j                  |   }| j                  |   }|}t        j                  dt        j
                  |d          dd|d    |      }t        j                  dt        j
                  |d          d|d   |      }t        j                  dt        j
                  |d          d|d    |      }t        j                  t        j
                  |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+   r1   resubescape)r-   r'   r3   sourcesrcdstouts          r0   convertzCookieConverter.convert%   s?    &++-+"";/=0kk&!kk-( ff3x=)*"-H
 ff"))CM*+2.M
 ffRYYs:789#j/"#
 ffIIc(m$M
 
r2   c                 b    | j                   D ci c]  }|| j                  ||       c}S c c}w )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.
        )r+   r=   )r-   r'   r.   s      r0   convert_allzCookieConverter.convert_allX   s2     BEMckk+t44MMMs   ,)__name__
__module____qualname____doc__r+   values_ALL_SUFFIXESclassmethodstrr1   r=   dictr?   ).0vs   00r0   r   r      s     ewR^_ ewR]^ ewRab ewR`a ewR]^ ewR]^ ewR]^ ewRab	G +2..*:;*:QQx[*:;M d
   0# 0c 0c 0 0d Nc Nd38n N N} <s   Br   )r6   r    r2   r0   <module>rL      s    	\N \Nr2   