§
    ¬	ÊjÓ9  ã                  ó  — d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	 ddl
mZ ddlmZ dZd	Z eh d
£¦  «        Zd2d„Zd3d„Zd4d„Zd4d„Zd5d„Zd6d„Zd7d „Zd8d"„Zd8d#„Zd8d$„Zd8d%„Zd8d&„Zd8d'„Zd8d(„Zd8d)„Z d8d*„Z!d9d,„Z"dd-œd:d1„Z#dS );aN  The cookies a persona already has: a decision about the persona, made here.

MOVED FROM THE CONSUMERS IN 36.x. Three byte-identical copies of this logic
lived in `invisible_playwright`, `invisible_selenium` and `invisible_puppeteer`
(`_recaptcha_seed.py`), and each took the Google CONSENT cookie's language
from the raw locale TAG the caller held, while `navigator.language` came from
the language list this package decides. Now the data is built here, as a pure
function of the persona and the session language, and each consumer keeps only
the call that hands the list to its own driver.

Consumes the Bayesian-sampled `browsing_history` from the persona Profile
(see `_fpforge/_sampler.py:derive_browsing_history`). For each visited site it
builds 1-5 realistic cookies whose composition is chosen by the site's
`cookie_profile` tag (analytics-only / consent / bot-defense / etc.). All
values are seeded deterministically from the persona seed, so a given persona
always presents the SAME cookies across sessions.

In addition it always builds 5 cookies on .google.com (NID, CONSENT, SOCS,
_GRECAPTCHA, ENID). It excludes 1P_JAR, which Google deprecated in 2022 -
including it now is an anachronism flag.

No Playwright, no driver objects: the result is a list of plain dicts in the
shape Playwright's `add_cookies` and Juggler's `setCookies` both take.
é    )ÚannotationsN)ÚAnyÚListÚOptionalé   )ÚSessionLocale)Úsub_seedz@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_Ú0123456789abcdef>    ÚATÚBEÚBGÚCHÚCYÚCZÚDEÚDKÚEEÚESÚFIÚFRÚGBÚGRÚHRÚHUÚIEÚISÚITÚLIÚLTÚLUÚLVÚMTÚNLÚNOÚPLÚPTÚROÚSEÚSIÚSKÚlocaler   Úreturnú'tuple[str, str]'c                ó®   — | j                              d¦  «        d                              ¦   «         }| j        t          v r	| j        |fS d| j        r|ndfS )uv  `(region_token, lang)` for the Google CONSENT cookie, from the DECISION.

    â›” THE LANGUAGE IS `primary`'s, NEVER THE REQUESTED TAG'S. Until 36.x this
    took the tag the caller held (as the public `consent_region_lang`), while
    `navigator.language` came from the decided list: the two could name
    different languages, and a page reading both saw them disagree. Reading
    `primary` makes the cookie say the language the page reads.

    THE REGION IS `region`, NOT A PART OF `primary`, and that is deliberate.
    The CONSENT region is WHERE consent was given, which Google takes from the
    visitor's country, not from the language: a French egress decides
    "fr, fr-FR, ..." whose first entry has no region at all, and taking the
    region from `primary` would have turned every French, Czech, Slovak,
    Croatian and Irish session into a non-EU `FX` one. `region` is the region
    of the tag the decision started from (the egress country, for "auto").

    WHY IT IS NOT A TIMEZONE TABLE. This used to live in the wrapper as a
    22-row IANA timezone table (`_TZ_TO_REGION`): a Romanian session resolved
    `ro-RO` for `navigator.language` and fell through to `("FX", "en")` for the
    cookie, because `Europe/Bucharest` was not one of the 22.

    No region known means a non-EU English visitor, the `en+FX` that is also
    what a session with no language asked gets.
    ú-r   ÚFXÚen)ÚprimaryÚsplitÚlowerÚregionÚCONSENT_REGION_COUNTRIES)r+   Úlangs     úGC:\Projects\Muse2API\.venv\Lib\site-packages\invisible_core/_cookies.pyÚ_consent_region_langr9   7   s[   € ð2 Œ>×Ò Ñ$Ô$ QÔ'×-Ò-Ñ/Ô/€DØ„}Õ0Ð0Ð0Ø”˜tÐ$Ð$Ø˜&œ-Ð1�$�$¨TÐ2Ð2ó    ÚtsÚfloatú'datetime.datetime'c                ó`   — t           j                              | t           j        j        ¦  «        S )a¸  UTC datetime for an epoch, without the deprecated constructor.

    `datetime.utcfromtimestamp` has been deprecated since 3.12 and returns a
    NAIVE datetime, which is the reason it is going away: the value carries no
    sign of being UTC, so any later arithmetic silently treats it as local.
    Only `.strftime("%Y%m%d")` is taken from it here, so the two spell the same
    string - the point is that the CI matrix now runs 3.14.
    )ÚdatetimeÚfromtimestampÚtimezoneÚutc©r;   s    r8   Ú	_utc_fromrD   V   s#   € õ Ô×*Ò*¨2­xÔ/@Ô/DÑEÔEÐEr:   Úrngúrandom.RandomÚlengthÚintÚstrc                ó`   ‡ — d                      ˆ fd„t          |¦  «        D ¦   «         ¦  «        S )NÚ c              3  óL   •K  — | ]}‰                      t          ¦  «        V — Œd S ©N)ÚchoiceÚ_B64_ALPHABET©Ú.0Ú_rE   s     €r8   ú	<genexpr>z_b64_rand.<locals>.<genexpr>c   ó/   øè è € ÐDÐD°�3—:’:�mÑ,Ô,ÐDÐDÐDÐDÐDÐDr:   ©ÚjoinÚrange©rE   rG   s   ` r8   Ú	_b64_randrY   b   ó0   ø€ Ø�7Š7ÐDÐDÐDÐDµe¸F±m´mÐDÑDÔDÑDÔDÐDr:   c                ó`   ‡ — d                      ˆ fd„t          |¦  «        D ¦   «         ¦  «        S )NrK   c              3  óL   •K  — | ]}‰                      t          ¦  «        V — Œd S rM   )rN   Ú_HEX_ALPHABETrP   s     €r8   rS   z_hex_rand.<locals>.<genexpr>g   rT   r:   rU   rX   s   ` r8   Ú	_hex_randr^   f   rZ   r:   c                óF   — t          | ¦  «                             d¦  «        S )Nz%Y%m%d)rD   ÚstrftimerC   s    r8   Ú_yyyymmdd_utcra   j   s   € Ý�R‰=Œ=×!Ò! (Ñ+Ô+Ð+r:   Únowú
List[dict]c                ó>  — |                       dd¦  «        dz  }t          |¦  «        \  }}d|                       dd¦  «        › dt          | d¦  «        › �d	d
|dz   ddddœddt          ||z
  ¦  «        › d|                       dd¦  «        d›d|                       dd¦  «        › d|› d|› d|                       dd¦  «        › �d	d
|dz   dddœddt          | d ¦  «        › �d	d
|dz   dddœd!t          | d"¦  «        d	d
|dz   dddœd#t          | d$¦  «        d	d
|dz   ddddœgS )%Né<   iÐ  é€Q ÚNIDéd   i  ú=é²   z.google.comú/i Ní TÚNone)ÚnameÚvalueÚdomainÚpathÚexpiresÚhttpOnlyÚsecureÚsameSiteÚCONSENTzYES+cb.r/   é
   é   Ú02dz-pr   é	   ú.ú+iç  é€ÀÚLax©rm   rn   ro   rp   rq   rs   rt   ÚSOCSÚCAESé8   Ú_GRECAPTCHAé|   ÚENIDéü   )Úrandintr9   rY   ra   )rE   rb   r+   Úconsent_ager5   r7   s         r8   Ú_google_cookiesrˆ   r   sÄ  € à—+’+˜b #Ñ&Ô&¨Ñ.€KÝ'¨Ñ/Ô/�L€FˆDð Ø—[’[  cÑ*Ô*ÐBÐB­Y°s¸CÑ-@Ô-@ÐBÐBØ ¨#Ø˜+Ñ%Ø T°vð		?ð 	?ð
 ð=�M¨#°Ñ*;Ñ<Ô<ð =ð =Ø—[’[  RÑ(Ô(ÐDð=ð =Ø03·²¸A¸qÑ0AÔ0Að=ð =àð=ð =à"ð=ð =à%(§[¢[°°cÑ%:Ô%:ð=ð =ð !¨#Ø˜+Ñ%Ø Uð	,ð 	,ð Ø-� 3¨Ñ+Ô+Ð-Ð-Ø ¨#Ø˜+Ñ%Ø Uð		,ð 	,ð
 Ý˜C Ñ%Ô%Ø ¨#Ø˜+Ñ%Ø Vð		-ð 	-ð
 Ý˜C Ñ%Ô%Ø ¨#Ø˜+Ñ%Ø T°uð		>ð 	>ð3ð r:   ro   c                ó:   — |                       d¦  «        r| nd| z   S )Nrz   )Ú
startswith)ro   s    r8   Ú_norm_domainr‹   �   s#   € Ø×&Ò& sÑ+Ô+Ð=ˆ6ˆ6°°v±Ð=r:   Údictc                óˆ   — |                       dd¦  «        dz  }dd|                       dd¦  «        › d||z
  › �|d	|d
z   dddœS )Né   i‹  rf   Ú_gaúGA1.2.é áõéÿÉš;rz   rk   r|   Tr}   r~   ©r†   )rE   rb   ro   Ú	first_ages       r8   Ú
_ga_cookier•   ¡   sc   € Ø—’˜A˜sÑ#Ô# eÑ+€IØØS˜cŸkšk¨)°YÑ?Ô?ÐSÐSÀ#È	Á/ÐSÐSØ cØ˜[Ñ(Ø¨ð	/ð /ð /r:   c           	     ó~   — dd|                       dd¦  «        › d||                       dd¦  «        z
  › �|d|dz   d	d
dœS )NÚ_gidr�   r‘   r’   rz   re   rf   rk   Tr}   r~   r“   ©rE   rb   ro   s      r8   Ú_gid_cookier™   ª   s[   € ØØ`˜cŸkšk¨)°YÑ?Ô?Ð`Ð`À#ÈÏÊÐTVÐX]ÑH^ÔH^ÑB^Ð`Ð`Ø cØ˜U‘{Ø¨ð	/ð /ð /r:   c                ól   — dt          | d¦  «        › d|                      d|¦  «        › d�|d|dz   dd	d
œS )NÚ__cf_bmé+   rz   i ñSez-1-1-1-1rk   é  Trl   r~   )rY   r†   r˜   s      r8   Ú_cf_bm_cookierž   ²   sQ   € ØÝ! # rÑ*Ô*ÐSÐS¨S¯[ª[¸ÀSÑ-IÔ-IÐSÐSÐSØ cØ˜T‘zØ¨ð	0ð 0ð 0r:   c                ó˜   — |                       dd¦  «        }t          ||dz  z
  ¦  «                             d¦  «        }d||d|dz   dd	d
œS )NrŽ   im  rf   z%Y-%m-%dT%H:%M:%S.000ZÚOptanonAlertBoxClosedrk   r|   Tr}   r~   )r†   rD   r`   )rE   rb   ro   Úage_dÚisos        r8   Ú_onetrust_cookier£   º   sg   € Ø�KŠK˜˜3ÑÔ€EÝ
�C˜% %™-Ñ'Ñ
(Ô
(×
1Ò
1Ø ñô €Cð ,ØØ cØ˜[Ñ(Ø¨ð	/ð /ð /r:   c                óD   — ddt          | d¦  «        z   dz   |d|dz   ddd	œS )
Nzcookieyes-consentz
consentid:é   zB,consent:yes,action:yes,necessary:yes,functional:yes,analytics:yesrk   r|   Tr}   r~   )rY   r˜   s      r8   Ú_cookieyes_cookier¦   Æ   sA   € Ø'Ø!¥I¨c°2Ñ$6Ô$6Ñ6ØYñZà cØ˜[Ñ(Ø¨ð/ð /ð /r:   c           
     ó¤   — dt          | d¦  «        › d|                      dd¦  «        › d||                      dd¦  «        d	z  z
  › �|d
|dz   dddœS )NÚ_clcké   z|2|frv   éc   z|0|re   é´   rf   rk   i€3áTr}   r~   )r^   r†   r˜   s      r8   Ú_clarity_cookier¬   Ï   s|   € ØÝ! # qÑ)Ô)ð =ð =¨s¯{ª{¸2¸rÑ/BÔ/Bð =ð =Ø˜cŸkšk¨"¨cÑ2Ô2°UÑ:Ñ:ð=ð =à cØ˜[Ñ(Ø¨ð/ð /ð /r:   c                ó„   — dd||                       dd¦  «        z
  dz  › d|                       dd¦  «        › �|d	|d
z   dddœS )zAFacebook Pixel _fbp = fb.<subdomain_index>.<unix_ms>.<random_int>Ú_fbpzfb.1.re   i �' iè  rz   r‘   l   ÿc(	 rk   i §v Tr}   r~   r“   r˜   s      r8   Ú_fbp_cookier¯   Ø   sj   € àð=˜c C§K¢K°°HÑ$=Ô$=Ñ=ÀÑEð =ð =ØŸš I¨zÑ:Ô:ð=ð =à cØ˜ZÑ'Ø¨ð/ð /ð /r:   c                ó‚   — d|                       dd¦  «        › d|                       dd¦  «        › �}d|› �d|d	|d
z   dddœS )z<_dc_gtm_<container_id>=1 - Google Tag Manager throttle flag.zUA-i€–˜ iÿàõr/   r   ry   Ú_dc_gtm_Ú1rk   re   Tr}   r~   r“   )rE   rb   ro   Ú	containers       r8   Ú_gtm_cookier´   â   sa   € àK�c—k’k (¨HÑ5Ô5ÐKÐK¸¿ºÀAÀqÑ8IÔ8IÐKÐK€IØ*˜yÐ*Ð*ØØ cØ˜R‘xØ¨ð	/ð /ð /r:   c                ó^   — dt          |                      dd¦  «        ¦  «        |d|dz   dddœS )	z"HubSpot referrer flag - small int.Ú__hssrcr   é   rk   r�   Tr}   r~   )rI   r†   r˜   s      r8   Ú_hssrc_cookier¸   ì   s>   € àÝ˜Ÿš Q¨Ñ*Ô*Ñ+Ô+Ø cØ˜T‘zØ¨ð	/ð /ð /r:   Úprofilec                ón  — t          |¦  «        }| dk    rt          |||¦  «        gS | dk    r`t          |||¦  «        t          |||¦  «        g}|                     ¦   «         dk     r$|                     t          |||¦  «        ¦  «         |S | dk    r"t          |||¦  «        t          |||¦  «        gS | dk    r­t          |||¦  «        t          |||¦  «        g}|                     |                     ¦   «         dk     rt          |||¦  «        nt          |||¦  «        ¦  «         |                     ¦   «         dk     r$|                     t          |||¦  «        ¦  «         |S | dk    �r5t          |||¦  «        t          |||¦  «        t          |||¦  «        g}|                     |                     ¦   «         dk     rt          |||¦  «        nt          |||¦  «        ¦  «         |                     ¦   «         dk     r$|                     t          |||¦  «        ¦  «         |                     ¦   «         dk     r$|                     t          |||¦  «        ¦  «         |                     ¦   «         d	k     r$|                     t          |||¦  «        ¦  «         |S t          |||¦  «        gS )
a$  Map a cookie_profile tag (from browsing_pool.json) to concrete cookies.

    Each recipe is a realistic combination observed on real production sites
    in that category. Cookie age and sub-recipe variance (e.g., OneTrust vs
    CookieYes for consent banner) are deterministic from rng.
    ÚminimalÚga_onlyg333333Ó?Úga_cfÚ
ga_consentg      à?gš™™™™™Ù?Úga_consent_clarityg      Ð?)r‹   r•   r™   ÚrandomÚappendr´   rž   r£   r¦   r¬   r¯   r¸   )r¹   rE   rb   ro   Úouts        r8   Ú_cookies_for_profilerÃ   õ   s£  € õ ˜&Ñ!Ô!€FØ�)ÒÐÝ˜3  VÑ,Ô,Ð-Ð-Ø�)ÒÐÝ˜#˜s FÑ+Ô+­[¸¸cÀ6Ñ-JÔ-JÐKˆà�:Š:‰<Œ<˜#ÒÐØ�JŠJ•{ 3¨¨VÑ4Ô4Ñ5Ô5Ð5Øˆ
Ø�'ÒÐÝ˜3  VÑ,Ô,­m¸CÀÀfÑ.MÔ.MÐNÐNØ�,ÒÐÝ˜#˜s FÑ+Ô+­[¸¸cÀ6Ñ-JÔ-JÐKˆØ�
Š
¸¿º¹¼ÈÒ9KÐ9KÕ# C¨¨fÑ5Ô5Ð5Ý)¨#¨s°FÑ;Ô;ñ	=ô 	=ð 	=à�:Š:‰<Œ<˜#ÒÐØ�JŠJ•{ 3¨¨VÑ4Ô4Ñ5Ô5Ð5Øˆ
ØÐ&Ò&Ñ&å˜#˜s FÑ+Ô+­[¸¸cÀ6Ñ-JÔ-JÝ˜s C¨Ñ0Ô0ð2ˆà�
Š
¸¿º¹¼ÈÒ9KÐ9KÕ# C¨¨fÑ5Ô5Ð5Ý)¨#¨s°FÑ;Ô;ñ	=ô 	=ð 	=à�:Š:‰<Œ<˜#ÒÐØ�JŠJ•{ 3¨¨VÑ4Ô4Ñ5Ô5Ð5Ø�:Š:‰<Œ<˜#ÒÐØ�JŠJ•{ 3¨¨VÑ4Ô4Ñ5Ô5Ð5Ø�:Š:‰<Œ<˜$ÒÐØ�JŠJ•} S¨#¨vÑ6Ô6Ñ7Ô7Ð7Øˆ
å�s˜C Ñ(Ô(Ð)Ð)r:   )rb   r   ú'SessionLocale | str | None'úOptional[int]c          
     ó^  — t          j        |¦  «        }t          t          | d¦  «        ¦  «        }t	          t          | dd¦  «        pg ¦  «        }|�|nt          t          j        ¦   «         ¦  «        }g }t          j        t          |d¦  «        ¦  «        }| 	                    t          |||¦  «        ¦  «         |D ]l}	t          j        t          |d|	d         › �¦  «        ¦  «        }
| 	                    t          |	                     dd¦  «        |
||	d         ¦  «        ¦  «         Œm|S )	aP  The full cookie list a persona arrives with, as plain dicts.

    Args:
        profile: the persona, a ``Profile`` from ``generate_profile`` (or any
            object with ``seed`` and ``browsing_history``). The seed drives
            every value; the history, a list of ``{name, category,
            cookie_profile}`` dicts, adds the per-site cookies. An empty
            history gives only the 5 .google.com cookies.
        locale: the session language, the ``SessionLocale`` a launch decided
            (``prepare_session_geo(...).locale``). A tag is accepted and
            decided through ``decide_session_locale``, the same derivation;
            "auto" is refused. The CONSENT cookie's ``lang+region`` token reads
            its ``primary`` language and its region ("it-IT" -> "it+IT",
            "en-US" -> "en+FX").
        now: unix-seconds timestamp; defaults to the current time. Pin it for
            tests.

    Deterministic: the same seed, history, locale and ``now`` give the same
    list. Handing it to a browser is the consumer's part, and the only part
    it keeps.
    ÚseedÚbrowsing_historyNÚgooglezdom:rm   Úcookie_profiler»   )r   ÚofrH   ÚgetattrÚlistÚtimerÀ   ÚRandomr	   Úextendrˆ   rÃ   Úget)r¹   r+   rb   Úsession_localerÇ   Úhistoryr;   ÚcookiesÚrng_gÚsiteÚrng_ds              r8   Úpersona_cookiesrØ   $  s%  € õ2 #Ô% fÑ-Ô-€NÝ�w�w Ñ'Ô'Ñ(Ô(€DÝ•7˜7Ð$6¸Ñ=Ô=ÐCÀÑDÔD€GØ�ˆˆ¥S­¬©¬Ñ%5Ô%5€BØ€Gõ ŒM�( 4¨Ñ2Ô2Ñ3Ô3€EØ‡N‚N•? 5¨"¨nÑ=Ô=Ñ>Ô>Ð>ð ð ð ˆÝ”�h tÐ-B°D¸´LÐ-BÐ-BÑCÔCÑDÔDˆØ�ŠÕ+Ø�HŠHÐ% yÑ1Ô1°5¸"¸dÀ6¼lñ
ô 
ñ 	ô 	ð 	ð 	ð €Nr:   )r+   r   r,   r-   )r;   r<   r,   r=   )rE   rF   rG   rH   r,   rI   )r;   rH   r,   rI   )rE   rF   rb   rH   r+   r   r,   rc   )ro   rI   r,   rI   )rE   rF   rb   rH   ro   rI   r,   rŒ   )
r¹   rI   rE   rF   rb   rH   ro   rI   r,   rc   )r¹   r   r+   rÄ   rb   rÅ   r,   rc   )$Ú__doc__Ú
__future__r   r?   rÀ   rÎ   Útypingr   r   r   Ú_localer   Úseedmixr	   rO   r]   Ú	frozensetr6   r9   rD   rY   r^   ra   rˆ   r‹   r•   r™   rž   r£   r¦   r¬   r¯   r´   r¸   rÃ   rØ   © r:   r8   ú<module>rà      s?  ððð ð0 #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø €€€Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð ð S€Ø"€ð %˜9ð &ð &ð &ñ ô Ð ð3ð 3ð 3ð 3ð>	Fð 	Fð 	Fð 	FðEð Eð Eð EðEð Eð Eð Eð,ð ,ð ,ð ,ð$ð $ð $ð $ðV>ð >ð >ð >ð/ð /ð /ð /ð/ð /ð /ð /ð0ð 0ð 0ð 0ð	/ð 	/ð 	/ð 	/ð/ð /ð /ð /ð/ð /ð /ð /ð/ð /ð /ð /ð/ð /ð /ð /ð/ð /ð /ð /ð(*ð (*ð (*ð (*ðd *.ð)ð )ð )ð )ð )ð )ð )ð )r:   