+
    }i+                        ^ RI Hu Ht ^ RIHt ^ RIHtHtH	t	H
t
HtHtHtHtHt ^ RIt^ RIHt ^ RIHtHtHtHt ^ RIHt ^RIHtHtHtHtH t H!t! ^RI"H#t#  ^ RI$t%R	t& ] ! R R4      4       t(]! R	R7       ! R R4      4       t) R R lt*R R lt+R,R R llt,R R lt-R R lt. ]R,          t/Rt0 ! R R]4      t1R R lt2R  R! lt3R" R# lt4R$ R% lt5 R& R' lt6R( R) lt7 ! R* R+4      t8]8! 4       t9R#   ]' d    R
t& Li ; i)-    N)	dataclass)	AnyDictIterableListOptionalSetTupleUnioncast)tags)
LOCAL_DATAGitHubDownloaderrprintwebdl)LeakWarning)InvalidLocaleMissingReleaseNotInstalledGeoIPExtraUnknownIPLocationUnknownLanguageUnknownTerritory)validate_ipTFc                   f   a  ] tR t^"t o RtRtRt]V 3R lR l4       tV 3R lR lt	V 3R lt
RtV tR# )	Localez0
Stores locale, region, and script information.
Nc                    < V ^8  d   QhRS[ /#    returnstr)format__classdict__s   "a/Users/ahmad/.openclaw/workspace/my-crawler/.venv/lib/python3.14/site-packages/camoufox/locale.py__annotate__Locale.__annotate__-   s      3     c                t    V P                   '       d   V P                   R V P                    2# V P                  # )-)regionlanguageselfs   &r$   	as_stringLocale.as_string,   s.    ;;;mm_Adkk]33}}r'   c                6   < V ^8  d   QhRS[ S[S[3,          /# r   )r   r!   )r"   r#   s   "r$   r%   r&   2   s      4S> r'   c                    V P                   '       g   Q hRV P                   RV P                  /pV P                  '       d   V P                  VR&   V# )z2
Converts the locale to a intl config dictionary.
zlocale:regionzlocale:languagezlocale:script)r*   r+   scriptr-   datas   & r$   	as_configLocale.as_config2   sI     {{{{T[[t}}
 ;;;$(KKD!r'   c                ^   < V ^8  d   Qh/ S[ ;R&   S[S[ ,          ;R&   S[S[ ,          ;R&   # )r   r+   r*   r2   )r!   r   )r"   r#   s   "r$   r%   r&   "   s3      M  SM   SM  r'    )__name__
__module____qualname____firstlineno____doc__r*   r2   propertyr.   r5   __annotate_func____static_attributes____classdictcell__r#   s   @r$   r   r   "   s9     
 !F F 
 !  r'   r   )frozenc                   F   a  ] tR t^@t o RtRtV 3R lR ltV 3R ltRtV t	R# )Geolocationz!
Stores geolocation information.
Nc                6   < V ^8  d   QhRS[ S[S[3,          /# r   )r   r!   r   )r"   r#   s   "r$   r%   Geolocation.__annotate__L   s      4S> r'   c                    RV P                   RV P                  RV P                  /V P                  P	                  4       CpV P
                  '       d   V P
                  VR&   V# )z2
Converts the geolocation to a config dictionary.
zgeolocation:longitudezgeolocation:latitudetimezonezgeolocation:accuracy)	longitudelatituderI   localer5   accuracyr3   s   & r$   r5   Geolocation.as_configL   s\    
 $T^^"DMM
 kk##%	
 ===+/==D'(r'   c                f   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[S[,          ;R&   # )r   rL   rJ   rK   rI   rM   )r   floatr!   r   )r"   r#   s   "r$   r%   rG   @   sG      N    O  M  uo$ r'   r8   )
r9   r:   r;   r<   r=   rM   r5   r?   r@   rA   rB   s   @r$   rE   rE   @   s"      !%H   r'   rE   c                (    V ^8  d   QhR\         RR/# )r   locr   Nr    )r"   s   "r$   r%   r%   `   s     + +s +t +r'   c                j    \         P                  ! V 4      '       d   R# \        P                  ! V 4      h)zL
Verifies that a locale is valid.
Takes either language-region or language.
N)r   checkr   invalid_input)rR   s   &r$   verify_localerV   `   s%    
 zz#

%
%c
**r'   c                0    V ^8  d   QhR\         R\        /# )r   rL   r   r!   r   )r"   s   "r$   r%   r%   j   s      S V r'   c                Z   \        V 4       \        P                  ! V 4      pVP                  '       g   \        P
                  ! V 4      hVP                  P                  R,          p\        VR,          VP                  P                  R,          R,          VP                  R4      R7      # )z)
Normalizes and validates a locale code.
recordSubtagzSuppress-Script)r+   r*   r2   )
rV   r   tagr*   r   rU   r+   r4   r   get)rL   parserrZ   s   &  r$   normalize_localer_   j   s     & XXfF===))&11__!!(+F !}}!!(+H5zz+, r'   c                <    V ^8  d   QhR\         R\        R\        /# )r   rL   ignore_regionr   )r!   boolr   )r"   s   "r$   r%   r%      s!     . .# .d .v .r'   c                n   \        V 4      ^8  d   \        V 4      #  \        P                  V 4      #   \         d     Mi ; iT'       d   \        T 4       \        T R7      #  \        P                  T 4      p\        P                  ! R4       T#   \         d     Mi ; i\        P                  ! T 4      h)z6
Handles a locale input, normalizing it if necessary.
)r+   	no_region)lenr_   SELECTORfrom_regionr   rV   r   from_languager   warnr   r   rU   )rL   ra   r+   s   && r$   handle_localerj      s    
 6{Q''##F++  fv&&))&1 	%	   
%
%f
--s    2 A A #B BBc                    V ^8  d   QhR\         \        \        \        ,          3,          R\        \        \        3,          RR/# )r   localesconfigr   N)r   r!   r   r   r   )r"   s   "r$   r%   r%      s6      E#tCy.1 4S> d r'   c                F   \        V \        4      '       d.   V P                  R4       Uu. uF  q"P                  4       NK  	  p p\	        V ^ ,          4      pVP                  VP                  4       4       \        V 4      ^8  d   R# \        R V  4       4      VR&   R# u upi )z
Handles a list of locales.
,Nc              3   P   "   T F  p\        VR R7      P                  x  K  	  R# 5i)T)ra   N)rj   r.   ).0rL   s   & r$   	<genexpr>!handle_locales.<locals>.<genexpr>   s       (JQfD1;;'s   $&z
locale:all)	
isinstancer!   splitstriprj   updater5   re   _join_unique)rl   rm   rR   intl_locales   &&  r$   handle_localesrz      s     '3*1--*<=*<399;*<=  
+K
MM+'')*
7|a ( (JQ( F< >s   Bc                F    V ^8  d   QhR\         \        ,          R\        /# )r   seqr   )r   r!   )r"   s   "r$   r%   r%      s"     G Ghsm G Gr'   c                N   a \        4       oRP                  V3R lV  4       4      # )z0
Joins a sequence of strings without duplicates
z, c              3   j   <"   T F(  qS9   d   K  SP                  V4      '       d   K$  Vx  K*  	  R # 5iN)add)rq   xseens   & r$   rr   _join_unique.<locals>.<genexpr>   s#     F1IQ!QQs   33
3)setjoin)r|   r   s   &@r$   rx   rx      s!     UD99FFFFr'   zGeoLite2-City.mmdbzP3TERX/GeoLite.mmdbc                   H   a  ] tR t^t o RtV 3R lR ltV 3R lR ltRtV tR# )MaxMindDownloaderz7
MaxMind database downloader from a GitHub repository.
c                6   < V ^8  d   QhRS[ RS[S[,          /# )r   assetr   )r   r   r!   )r"   r#   s   "r$   r%   MaxMindDownloader.__annotate__   s       (3- r'   c                T    VR ,          P                  R4      '       d
   VR,          # R# )namez
-City.mmdbbrowser_download_urlN)endswith)r-   r   s   &&r$   check_assetMaxMindDownloader.check_asset   s&    =!!,///00r'   c                   < V ^8  d   QhRR/# r   r   Nr8   )r"   r#   s   "r$   r%   r      s     L LT Lr'   c                    \        R 4      h)z+Failed to find GeoIP database release asset)r   r,   s   &r$   missing_asset_error%MaxMindDownloader.missing_asset_error   s    JKKr'   r8   N)	r9   r:   r;   r<   r=   r   r   r@   rA   rB   s   @r$   r   r      s       L Lr'   r   c                    V ^8  d   QhRR/# r   r8   )r"   s   "r$   r%   r%      s     
 
t 
r'   c                 4    \         '       g   \        R4      hR# )z+
Checks if the geoip2 module is available.
zOPlease install the geoip extra to use this feature: pip install camoufox[geoip]N)ALLOW_GEOIPr   r8   r'   r$   geoip_allowedr      s     ;$]
 	
 r'   c                    V ^8  d   QhRR/# r   r8   )r"   s   "r$   r%   r%      s     
 
t 
r'   c                     \        4        \        \        4      P                  4       p \	        \
        R4      ;_uu_ 4       p\        V RVR7       RRR4       R#   + '       g   i     R# ; i)z(
Downloads the MaxMind GeoIP2 database.
wbzDownloading GeoIP database)descbufferN)r   r   	MMDB_REPO	get_assetopen	MMDB_FILEr   )	asset_urlfs     r$   download_mmdbr      sK     O!),668I	i		!-	
 
			s    AA*	c                    V ^8  d   QhRR/# r   r8   )r"   s   "r$   r%   r%      s     	& 	&T 	&r'   c                     \         P                  4       '       g   \        R4       R# \         P                  4        \        R4       R# )z&
Removes the MaxMind GeoIP2 database.
zGeoIP database not found.NzGeoIP database removed.)r   existsr   unlinkr8   r'   r$   remove_mmdbr      s4     *+
$%r'   c                0    V ^8  d   QhR\         R\        /# )r   ipr   )r!   rE   )r"   s   "r$   r%   r%      s     
 
 
 
r'   c                V  a \         P                  4       '       g   \        4        \        V 4       \        P
                  P                  \        \         4      4      ;_uu_ 4       pVP                  V 4      p\        \        VP                  P                  4      P                  4       pVP                  o\        ;QJ d    V3R lR 4       F  '       g   K   RM	  RM! V3R lR 4       4      '       d   \        RV  24      h\         P#                  V4      p\%        V\        \&        VP                  P(                  4      \        \&        VP                  P*                  4      \        \        VP                  P,                  4      R7      uuRRR4       #   + '       g   i     R# ; i)z)
Gets the geolocation for an IP address.
c              3   F   <"   T F  p\        SV4      '       * x  K  	  R # 5ir   )getattr)rq   attrlocations   & r$   rr   "get_geolocation.<locals>.<genexpr>
  s      ^7]t78T***7]s   !TFzUnknown IP location: )rL   rJ   rK   rI   N)rJ   rK   	time_zone)r   r   r   r   geoip2databaseReaderr!   cityr   registered_countryiso_codeupperr   anyr   rf   rg   rE   rP   rJ   rK   r   )r   readerrespr   rL   r   s   &    @r$   get_geolocationr      s   
  O			I	/	/6{{2T44==>DDF== 3^7]^333^7]^^^#&;B4$@AA %%h/5$--"9"9:%!7!78#t}}667	
 
0	/	/	/s   %A/FF5BFF(	c                8    V ^8  d   QhR\         P                  /# r   )ETElement)r"   s   "r$   r%   r%     s      "** r'   c                     \        \        R,          R4      ;_uu_ 4       p \        P                  ! V P	                  4       4      pRRR4       Xf   Q R4       hV#   + '       g   i     L; i)z
Fetches supplemental data from the territoryInfo.xml file.
Source: https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/supplementalData.xml
zterritoryInfo.xmlrbNz Failed to load territoryInfo.xml)r   r   r   XMLread)r   r4   s     r$   get_unicode_infor     sR    
 
j..	5	5vvaffh 
6???K 
6	5s   %AA*	c                P    V ^8  d   QhR\         P                  R\        R\        /# )r   elementr   r   )r   r   r!   rP   )r"   s   "r$   r%   r%   (  s%     ' 'rzz ' ' 'r'   c                8    \        V P                  V^ 4      4      # )z#
Converts an attribute to a float.
)rP   r]   )r   r   s   &&r$   	_as_floatr   (  s     T1%&&r'   c                      a  ] tR tRt o RtR tV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
RtV tR# )StatisticalLocaleSelectori/  z
Selects a random locale based on statistical data.
Takes either a territory code or a language code, and generates a Locale object.
c                $    \        4       V n        R # r   )r   rootr,   s   &r$   __init__"StatisticalLocaleSelector.__init__5  s    $&	r'   c                d   < V ^8  d   QhRS[ RS[S[P                  S[P                  3,          /# )r   r   r   r!   r
   npndarray)r"   r#   s   "r$   r%   &StatisticalLocaleSelector.__annotate__8  s1     D DS DU2::rzz;Q5R Dr'   c           	        V P                   P                  RV R24      pVf   \        RV 24      hVP                  R4      pV'       g   \	        RV 24      h\
        P                  ! V Uu. uF  qDP                  R4      NK  	  up4      p\
        P                  ! V Uu. uF  p\        VR4      NK  	  up4      pV P                  WV4      # u upi u upi )z
Calculates a random language based on the territory code,
based on the probability that a person speaks the language in the territory.
zterritory[@type='z']zUnknown territory: languagePopulationz#No language data found for region: typepopulationPercent)
r   findr   findall
ValueErrorr   arrayr]   r   normalize_probabilities)r-   r   	territorylang_populationslang	languagespercentagess   &&     r$   _load_territory_data.StatisticalLocaleSelector._load_territory_data8  s    
 IINN%6xj#CD	"%8
#CDD$,,-ABB8*MNNHH;KL;K4hhv.;KLM	hhQabQa	$0C DQabc++ICC Mbs   -C!Cc                d   < V ^8  d   QhRS[ RS[S[P                  S[P                  3,          /# r   r+   r   r   )r"   r#   s   "r$   r%   r   J  s1      V  VC  VE"**bjj:P4Q  Vr'   c                4   V P                   P                  RV R24      pV'       g   \        RV 24      h. p. pV F  pVP                  R4      pVf   K  VP	                  RV R24      pVf   K5  VP                  V4       VP                  \        VR4      \        VR4      ,          R	,          \        VR
4      ,          4       K  	  V'       g   \        RV 24      hV P                  \        P                  ! V4      \        P                  ! V4      4      # )zg
Calculates a random region for a language
based on the total speakers of the language in that region.
z'.//territory/languagePopulation[@type="z"]/..z#No region data found for language: r   zlanguagePopulation[@type="z"]r   literacyPercenti'  
populationz)No valid region data found for language: )r   r   r   r]   r   appendr   r   r   r   r   )r-   r+   territoriesregionsr   terrr*   lang_pops   &&      r$   _load_language_data-StatisticalLocaleSelector._load_language_dataJ  s   
 ii''*QRZQ[[`(ab!$Gz"RSSDXXf%F~yy#=hZr!JKHNN6"($78D"345 D,/0  " H
STT++BHHW,=rxx?TUUr'   c                   < V ^8  d   QhRS[ P                  RS[ P                  RS[S[ P                  S[ P                  3,          /# )r   r   freqr   )r   r   r
   )r"   r#   s   "r$   r%   r   l  s?     ' ''+-::'	rzz2::%	&'r'   c                B    \         P                  ! V4      pWV,          3# )z
Normalize probabilities.
)r   sum)r-   r   r   totals   &&& r$   r   1StatisticalLocaleSelector.normalize_probabilitiesl  s     t,&&r'   c                &   < V ^8  d   QhRS[ RS[/# )r   r*   r   rX   )r"   r#   s   "r$   r%   r   u  s     8 8# 8& 8r'   c                    V P                  V4      w  r#\        P                  P                  W#R7      P	                  RR4      p\        V RV 24      # )zR
Get a random locale based on the territory ISO code.
Returns as a Locale object.
p_r)   )r   r   randomchoicereplacer_   )r-   r*   r   probabilitiesr+   s   &&   r$   rg   %StatisticalLocaleSelector.from_regionu  sQ    
 $(#<#<V#D 	99##I#?GGSQ8*AfX 677r'   c                &   < V ^8  d   QhRS[ RS[/# r   rX   )r"   r#   s   "r$   r%   r   ~  s     8 8c 8f 8r'   c                    V P                  V4      w  r#\        P                  P                  W#R7      p\	        V RV 24      # )zH
Get a random locale based on the language.
Returns as a Locale object.
r   r)   )r   r   r   r   r_   )r-   r+   r   r   r*   s   &&   r$   rh   'StatisticalLocaleSelector.from_language~  sD    
 "&!9!9(!C!!'!;8*AfX 677r'   )r   N)r9   r:   r;   r<   r=   r   r   r   r   rg   rh   r@   rA   rB   s   @r$   r   r   /  sF     
'D D$ V  VD' '8 88 8r'   r   )F):xml.etree.ElementTreeetreeElementTreer   dataclassesr   typingr   r   r   r   r   r	   r
   r   r   numpyr   language_tagsr   camoufox.pkgmanr   r   r   r   camoufox.warningsr   
exceptionsr   r   r   r   r   r   r   r   geoip2.databaser   r   ImportErrorr   rE   rV   r_   rj   rz   rx   r   r   r   r   r   r   r   r   r   r   rf   r8   r'   r$   <module>r     s   " " ! O O O   G G )   K
   : $  4
+*.@*G --	!	L( L

 	&
>
'V8 V8r %&c  Ks   C5 5	D D