HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/tldextract/__pycache__/cache.cpython-310.pyc
o

+we�!�@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZddlmZmZddlZddlmZe�e�Zdaed	�Zejd
krXd'dd�ZnejZd(dd�Zd(dd�ZGdd�d�Zd)dd�Zd*d!d"�Z d+d%d&�Z!dS),zHelpers.�)�annotationsN)�Callable�Hashable�Iterable)�Path)�TypeVar�cast)�FileLockF�T)��	�args�bytes�return�
hashlib._HashcGstj|ddi�S)zUse argument only available in newer Python.

        In this file, MD5 is only used for cache location, not security.
        �usedforsecurityF)�hashlib�md5)r
�r�I/home/arjun/projects/env/lib/python3.10/site-packages/tldextract/cache.pyrsr�strcCs�zddlm}Wntyd}Ynwd|}tj�tj�}ttj�	d���
�dd�}d�d	d
�tjdd�D��}||||g}d�|�}|S)
z�
    Generate an identifier unique to the python version, tldextract version, and python instance.

    This will prevent interference between virtualenvs and issues that might arise when installing
    a new version of tldextract
    r)�version�devztldextract-�utf-8N��.cSsg|]}t|��qSr)r)�.0�vrrr�
<listcomp>7sz-get_pkg_unique_identifier.<locals>.<listcomp>����__)
�tldextract._versionr�ImportError�os�path�basename�sys�prefixr�encode�	hexdigest�join�version_info)r�tldextract_version�python_env_name�python_binary_path_short_hash�python_version�identifier_parts�pkg_identifierrrr�get_pkg_unique_identifier's ��
r2cCs|tj�dd�}|dur
|St�dd�}|dur&t�dd�}|r&tt|d��}|dur3tt|dt���Stttj�t	�d��S)z�
    Get a cache dir that we have permission to write to.

    Try to follow the XDG standard, but if that doesn't work fallback to the package directory
    http://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
    �TLDEXTRACT_CACHEN�XDG_CACHE_HOME�HOMEz.cachezpython-tldextractz
.suffix_cache)
r#�environ�get�getenvrrr2r$�dirname�__file__)�	cache_dir�xdg_cache_home�	user_homerrr�
get_cache_dirCs�r>c@sXeZdZdZd*d+dd�Zd,dd�Zd-dd�Zd.dd�Zd/dd�Zd0d d!�Z	d1d'd(�Z
d)S)2�	DiskCachez0Disk _cache that only works for jsonable values.�r;�
str | None�lock_timeout�intcCs0t|�|_tj�t|�p
d�|_||_d|_dS)z.Construct a disk cache in the given directory.�z.tldextract.jsonN)	�bool�enabledr#r$�
expanduserrr;rB�file_ext)�selfr;rBrrr�__init__`s

zDiskCache.__init__�	namespacer�key�str | dict[str, Hashable]r�objectc
Cs�|jstd��|�||�}tj�|�std|dt|���zt|��}t�	|�Wd�WS1s5wYWdSt
tfy^}zt�
d||�td|dt|��d�d}~ww)z%Retrieve a value from the disk cache.zCache is disabledznamespace: z key: Nz#error reading TLD cache file %s: %s)rF�KeyError�_key_to_cachefile_pathr#r$�isfile�repr�open�json�load�OSError�
ValueError�LOG�error)rIrKrL�cache_filepath�
cache_file�excrrrr7is
(���z
DiskCache.get�value�Nonec
Cs�|jsdS|�||�}z$t|�t|d��}t�||�Wd�WdS1s(wYWdStyV}ztsKt�	d||||�daWYd}~dSWYd}~dSd}~ww)zSet a value in the disk cache.N�w��unable to cache %s.%s in %s. This could refresh the Public Suffix List over HTTP every app startup. Construct your `TLDExtract` with a writable `cache_dir` or set `cache_dir=None` to silence this warning. %sT)
rFrP�	_make_dirrSrT�dumprV�_DID_LOG_UNABLE_TO_CACHErX�warning)rIrKrLr]rZr[�ioerrr�setxs*&��
���z
DiskCache.setcCs�t�|j�D]F\}}}|D]>}|�|j�s|�|jd�rKzt�tt||���Wq
ty2Yq
t	yJ}z
|j
t
jkr@�WYd}~q
d}~wwq
qdS)zClear the disk cache.�.lockN)r#�walkr;�endswithrH�unlinkrr�FileNotFoundErrorrV�errno�ENOENT)rI�root�_�files�filenamer\rrr�clear�s$�������zDiskCache.clearcCs0tt|j|��}t|�}tt|||j��}|S)N)rrr;�_make_cache_keyrH)rIrKrL�namespace_path�
hashed_key�
cache_pathrrrrP�sz DiskCache._key_to_cachefile_path�func�Callable[..., T]�kwargs�dict[str, Hashable]�hashed_argnames�
Iterable[str]r
c

s|js
|d
i|��S�fdd�|��D�}|�||�}|d}zt|�Wn&tyK}zts:t�d||||�da|d
i|��WYd}~Sd}~wwt||j	d��/zt
t|j||d��}	Wnt
yx|d
i|��}	|j|||	d	�Ynw|	Wd�S1s�wYdS)�!Get a url but cache the response.csi|]\}}|�vr||�qSrr)r�kr�r{rr�
<dictcomp>�sz+DiskCache.run_and_cache.<locals>.<dictcomp>rgr`TN��timeout)rKrL)rKrLr]r)rF�itemsrPrarVrcrXrdr	rBrr
r7rOrf)
rIrwrKryr{�key_argsrZ�	lock_pathre�resultrrr�
run_and_cache�s:�
���$�zDiskCache.run_and_cache�session�requests.Session�urlr��float | int | NonecCs|jtd|||d�dgd�S)r}�urls)r�r�r�r�)rwrKryr{)r��
_fetch_url)rIr�r�r�rrr�cached_fetch_url�s
�zDiskCache.cached_fetch_urlN)r@)r;rArBrC)rKrrLrMrrN)rKrrLrMr]rNrr^)rr^)rKrrLrMrr)
rwrxrKrryrzr{r|rr
)r�r�r�rr�r�rr)�__name__�
__module__�__qualname__�__doc__rJr7rfrrrPr�r�rrrrr?]s
	




*r?r�r�r�r��
int | NonecCs4|j||d�}|��|j}t|t�st|d�}|S)Nr�r)r7�raise_for_status�text�
isinstancer)r�r�r��responser�rrrr��s

r��inputsrMcCst|�}t|�d����S)N�utf8)rRrr(r))r�rLrrrrs�srsrqr^c
Csftj�tj�|��s1zt�tj�|��WdSty0}z|jtjkr%�WYd}~dSd}~wwdS)z-Make a directory if it doesn't already exist.N)r#r$�existsr9�makedirsrVrl�EEXIST)rqr\rrrra�s����ra)r
rrr)rr)r�r�r�rr�r�rr)r�rMrr)rqrrr^)"r��
__future__rrlrrT�loggingr#r&�collections.abcrrr�pathlibr�typingrr�requests�filelockr	�	getLoggerr�rXrcr
r+rr2r>r?r�rsrarrrr�<module>s4