
    !}gk                       d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
Z
ddlmZ ddlmZ  ej        d	          Z ej        d
ej        ej        z            ZdZ G d de          Z	 	 d d!dZd"dZ	 d#d$dZ	 d#d$dZdS )%z=tldextract helpers for testing and fetching remote resources.    )annotationsN)Sequence)cast)FileAdapter   )	DiskCache
tldextractz^(?P<suffix>[.*!]*\w[\S]*)z// ===BEGIN PRIVATE DOMAINS===c                      e Zd ZdZdS )SuffixListNotFoundzA recoverable error while looking up a suffix list.

    Recoverable because you can specify backups, or use this library's bundled
    snapshot.
    N)__name__
__module____qualname____doc__     V/var/www/py-google-trends/myenv/lib/python3.11/site-packages/tldextract/suffix_list.pyr   r      s           r   r   cacher   urlsSequence[str]cache_fetch_timeoutfloat | int | Nonesessionrequests.Session | Nonereturnstrc                   d}|7t          j                    }|                    dt                                 d}	 |D ]j}	 |                     |||          c |r|                                 S S # t           j        j        $ r  t          	                    d|d           Y gw xY w	 |r|                                 n# |r|                                 w w xY wt          d          )	zQDecode the first successfully fetched URL, from UTF-8 encoding to Python unicode.FNzfile://T)r   urltimeoutz+Exception reading Public Suffix List url %s)exc_infozNo remote Public Suffix List found. Consider using a mirror, or avoid this fetch by constructing your TLDExtract with `suffix_list_urls=()`.)requestsSessionmountr   cached_fetch_urlclose
exceptionsRequestExceptionLOGwarningr   )r   r   r   r   session_createdr   s         r   find_first_responser*      sC    O"$$i/// 	 	C--#6I .      	MMOOOO	 &7   A3QU      	  	MMOOO  	MMOOOO	 	M  s/   C A3C 31B'$C &B''C Csuffix_list_texttuple[list[str], list[str]]c                    |                      t                    \  }}}d t                              |          D             }d t                              |          D             }||fS )zJParse the raw suffix list text for its different designations of suffixes.c                8    g | ]}|                     d           S suffixgroup.0ms     r   
<listcomp>z1extract_tlds_from_suffix_list.<locals>.<listcomp>F   s$    UUU1778$$UUUr   c                8    g | ]}|                     d           S r/   r1   r3   s     r   r6   z1extract_tlds_from_suffix_list.<locals>.<listcomp>G   s$    WWW!AGGH%%WWWr   )	partitionPUBLIC_PRIVATE_SUFFIX_SEPARATORPUBLIC_SUFFIX_REfinditer)r+   public_text_private_textpublic_tldsprivate_tldss         r   extract_tlds_from_suffix_listrA   @   ss    #3#=#='$ $ KL VU.>.G.G.T.TUUUKWW/?/H/H/V/VWWWL$$r   fallback_to_snapshotboolc           
     N    |                      t          d| ||||dddg          S ))Fetch, parse, and cache the suffix lists.zpublicsuffix.org-tldsr   r   r   rB   r   r   rB   )func	namespacekwargshashed_argnames)run_and_cache_get_suffix_listsrF   s        r   get_suffix_listsrM   K   sK     )#6$8
 
  !78    r   c                   	 t          | |||          }n[# t          $ rN}|r@t          j        dd          }t	          t
          |          }|                    d          }n|Y d}~nd}~ww xY wt          |          \  }	}
|	|
fS )rE   )r   r   r	   z.tld_set_snapshotzutf-8N)r*   r   pkgutilget_datar   bytesdecoderA   )r   r   r   rB   r   textexcmaybe_pkg_datapkg_datar?   r@   s              r   rL   rL   a   s    "4-@'
 
 
     	$-l<OPPNE>22H??7++DDI DDDD !>d C CK$$s    
A.AA))A.)NN)
r   r   r   r   r   r   r   r   r   r   )r+   r   r   r,   )N)r   r   r   r   r   r   rB   rC   r   r   r   r,   )r   
__future__r   loggingrO   recollections.abcr   typingr   r    requests_filer   r   r   	getLoggerr'   compileUNICODE	MULTILINEr:   r9   LookupErrorr   r*   rA   rM   rL   r   r   r   <module>rb      se   C C " " " " " "   				 $ $ $ $ $ $        % % % % % %      g%%2:;RZ",=VWW "B         /3'+	    D% % % %  (,    6 (,% % % % % % %r   