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/lib64/python3.10/site-packages/tweepy/__pycache__/cache.cpython-310.pyc
o

+we�1�@s�ddlZddlZddlZddlZddlZddlZddlZzddlZWn	ey+Ynwe�	e
�ZGdd�d�ZGdd�de�Z
Gdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZdS)�Nc@�DeZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
�Zdd�Z	dS)�Cache�Cache interface�<cCs
||_dS)z[Initialize the cache
            timeout: number of seconds to keep a cached entry
        N)�timeout��selfr�r	�E/home/arjun/projects/env/lib/python3.10/site-packages/tweepy/cache.py�__init__s
zCache.__init__cC�t�)�\Add new record to cache
            key: entry key
            value: data of entry
        ��NotImplementedError�r�key�valuer	r	r
�store �zCache.storeNcCr)z�Get cached entry if exists and not expired
            key: which entry to get
            timeout: override timeout with this value [optional]
        r�rrrr	r	r
�get'rz	Cache.getcCr)z.Get count of entries currently stored in cacher�rr	r	r
�count.�zCache.countcCr)z$Delete any expired entries in cache.rrr	r	r
�cleanup2rz
Cache.cleanupcCr)zDelete all cached entriesrrr	r	r
�flush6rzCache.flush�r�N�
�__name__�
__module__�__qualname__�__doc__rrrrrrr	r	r	r
rs

rc@s\eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�Zdd�Zd
S)�MemoryCachezIn-memory cachercCs t�||�i|_t��|_dSr)rr�_entries�	threading�Lock�lockrr	r	r
r>szMemoryCache.__init__cCs|j|jd�S)N)�entriesr)r$rrr	r	r
�__getstate__CszMemoryCache.__getstate__cCs"t��|_|d|_|d|_dS)Nr(r)r%r&r'r$r)r�stater	r	r
�__setstate__Gs

zMemoryCache.__setstate__cC�|dko
t��|d|kS�Nr��time�r�entryrr	r	r
�_is_expiredMszMemoryCache._is_expiredcCs*|j��t��|f|j|<|j��dSr)r'�acquirer/r$�releaserr	r	r
rPs
zMemoryCache.storeNcCs~|j��z3|j�|�}|sW|j��dS|dur|j}|�||�r/|j|=W|j��dS|dW|j��S|j��w)N�)r'r3r$rr4rr2)rrrr1r	r	r
rUs
��zMemoryCache.getcCs
t|j�Sr)�lenr$rr	r	r
rns
zMemoryCache.countcCsV|j��zt|j���D]\}}|�||j�r|j|=q
W|j��dS|j��wr)r'r3�dictr$�itemsr2rr4)r�k�vr	r	r
rqs
��zMemoryCache.cleanupcCs"|j��|j��|j��dSr)r'r3r$�clearr4rr	r	r
rzs

zMemoryCache.flushrr)
rr r!r"rr)r+r2rrrrrr	r	r	r
r#;s

	r#c@s�eZdZdZiZd#dd�Zdd�Zd$dd	�Zd
d�Zd$dd
�Z	dd�Z
d$dd�Zdd�Zdd�Z
dd�Zd%dd�Zdd�Zdd�Zdd �Zd!d"�ZdS)&�	FileCachezFile-based cachercCs�t�||�tj�|�durt�|�||_|tjvr"tj||_	nt
��|_	|j	tj|<tjdkr<|j
|_|j|_dStjdkrK|j|_|j|_dSt�d�|j|_|j|_dS)NF�posix�ntz/FileCache locking not supported on this system!)rr�os�path�exists�mkdir�	cache_dirr<�cache_locksr'r%r&�name�_lock_file_posix�
_lock_file�_unlock_file_posix�_unlock_file�_lock_file_win32�_unlock_file_win32�log�warning�_lock_file_dummy�_unlock_file_dummy)rrCrr	r	r
r�s"





zFileCache.__init__cCs,t��}|�|�d��tj�|j|���S)Nzutf-8)	�hashlib�md5�update�encoder?r@�joinrC�	hexdigest)rrrQr	r	r
�	_get_path�szFileCache._get_pathTcC�dSrr	�rr@�	exclusiver	r	r
rN��zFileCache._lock_file_dummycCrWrr	�rr'r	r	r
rO�rZzFileCache._unlock_file_dummycCsb|d}|durt|d�}t�|tj�nt|d�}t�|tj�tj�|�dur/|��dS|S)N�.lockT�w�rF)	�open�fcntl�lockf�LOCK_EX�LOCK_SHr?r@rA�close)rr@rY�	lock_path�f_lockr	r	r
rF�s

zFileCache._lock_file_posixcCs|��dSr)rdr[r	r	r
rH�szFileCache._unlock_file_posixcCrWrr	rXr	r	r
rJ�rzFileCache._lock_file_win32cCrWrr	r[r	r	r
rK�rzFileCache._unlock_file_win32cCs0t�|�tj�|d�rt�|d�dSdS�Nr\)r?�remover@rA)rr@r	r	r
�_delete_file�s
�zFileCache._delete_filecCsl|�|�}|j��z%|�|�}t|d�}t�t��|f|�|��|�	|�W|j�
�dS|j�
�w)N�wb)rVr'r3rGr_�pickle�dumpr/rdrIr4)rrrr@rf�datafiler	r	r
r�s



zFileCache.storeNcCs|�|�|�|�Sr)�_getrVrr	r	r
r�sz
FileCache.getcCs�tj�|�dur
dS|j��z=|�|d�}t|d�}t�|�\}}|�	�|dur-|j
}|dkr@t��||kr@d}|�|�|�
|�|W|j��S|j��w)NF�rbr)r?r@rAr'r3rGr_rk�loadrdrr/rirIr4)rr@rrfrm�created_timerr	r	r
rn�s"



zFileCache._getcCs.d}t�|j�D]}|�d�rq|d7}q|S)Nrr\r5)r?�listdirrC�endswith)r�cr1r	r	r
r�s

zFileCache.countcCs:t�|j�D]}|�d�rq|�tj�|j|�d�qdSrg)r?rrrCrsrnr@rT�rr1r	r	r
r�s

�zFileCache.cleanupcCs8t�|j�D]}|�d�rq|�tj�|j|��qdSrg)r?rrrCrsrir@rTrur	r	r
rs

�zFileCache.flushr)Tr)rr r!r"rDrrVrNrOrFrHrJrKrirrrnrrrr	r	r	r
r<�s$




r<c@r)�
MemCacheCacherrcCs||_||_dS)z�Initialize the cache
            client: The memcache client
            timeout: number of seconds to keep a cached entry
        N)�clientr)rrwrr	r	r
r
s
zMemCacheCache.__init__cCs|jj|||jd�dS)r
r.N)rw�setrrr	r	r
rszMemCacheCache.storeNcCs|j�|�S)z�Get cached entry if exists and not expired
            key: which entry to get
            timeout: override timeout with this value [optional].
            DOES NOT WORK HERE
        )rwrrr	r	r
rszMemCacheCache.getcCr)z8Get count of entries currently stored in cache. RETURN 0rrr	r	r
r$rzMemCacheCache.countcCr)z*Delete any expired entries in cache. NO-OPrrr	r	r
r(rzMemCacheCache.cleanupcCr)z Delete all cached entries. NO-OPrrr	r	r
r,rzMemCacheCache.flushrrrr	r	r	r
rv
s

rvc@sZeZdZdZ			ddd�Zdd�Zd	d
�Zddd
�Zdd�Zdd�Z	dd�Z
dd�ZdS)�
RedisCachezCache running in a redis serverr�tweepy:keys�tweepy:cCs"t�||�||_||_||_dSr)rrrw�keys_container�pre_identifier)rrwrr|r}r	r	r
r4s
zRedisCache.__init__cCr,r-r.r0r	r	r
r2=szRedisCache._is_expiredcCsV|j|}|j��}|�|t�t��|f��|�||j�|�	|j
|�|��dS)z-Store the key, value pair in our redis serverN)r}rw�pipelinerxrk�dumpsr/�expirer�saddr|�execute)rrr�piper	r	r
rAs

zRedisCache.storeNcCsX|j|}|j�|�}|sdSt�|�}|dur|j}|�||�r(|�|�dS|dS)z4Given a key, returns an element from the redis tableNr5)r}rwrrk�loadsrr2�delete_entry)rrr�unpickled_entryr1r	r	r
rQs


zRedisCache.getcCst|j�|j��S)z�Note: This is not very efficient,
        since it retrieves all the keys from the redis
        server to know how many keys we have)r6rw�smembersr|rr	r	r
rhszRedisCache.countcCs.|j��}|�|j|�|�|�|��dS)z%Delete an object from the redis tableN)rwr~�sremr|�deleter�)rrr�r	r	r
r�ns

zRedisCache.delete_entrycCsN|j�|j�}|D]}|j�|�}|r$t�|�}|�||j�r$|�|�q	dS)zCleanup all the expired keysN)	rwr�r|rrkr�r2rr�)r�keysrr1r	r	r
rus

��zRedisCache.cleanupcCs&|j�|j�}|D]}|�|�q	dS)z!Delete all entries from the cacheN)rwr�r|r�)rr�rr	r	r
rs�zRedisCache.flush)rrzr{r)rr r!r"rr2rrrr�rrr	r	r	r
ry1s
�	

ryc@sLeZdZdZddd�Zdd�Zdd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dS)�MongodbCachez+A simple pickle-based MongoDB cache system.��tweepy_cachecCs0t�||�||_|||_|jjd|d�dS)z0Should receive a "database" cursor from pymongo.�created��expireAfterSecondsN)rrr�col�create_index)r�dbr�
collectionr	r	r
r�s
zMongodbCache.__init__cCs<ddlm}tj��}|t�|��}|j�|||d��dS)Nr)�Binary)r��_idr)�bson.binaryr��datetime�utcnowrkrr��insert)rrrr��now�blobr	r	r
r�s
zMongodbCache.storeNcCs.|rt�|j�d|i�}|rt�|d�SdS)Nr�r)rr��find_onerkr�)rrr�objr	r	r
r�s�zMongodbCache.getcCs|j�i���Sr)r��findrrr	r	r
r��zMongodbCache.countcCs|j�d|i�S)Nr�)r�rh)rrr	r	r
r��r�zMongodbCache.delete_entrycCsdS)z.MongoDB will automatically clear expired keys.Nr	rr	r	r
r�rzMongodbCache.cleanupcCs |j��|jjd|jd�dS)Nr�r�)r��dropr�rrr	r	r
r�s
zMongodbCache.flush)r�r�r)rr r!r"rrrrr�rrr	r	r	r
r��s

r�)r�rP�loggingrkr%r/r?r`�ImportError�	getLoggerrrLrr#r<rvryr�r	r	r	r
�<module>s(�
$E'U