Format: application/x-python-code
1 o
2
3 2'h�/ � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZ d dl
4 mZ d dlm
5 Z
6 d dlmZ d dlmZ d dlmZ d dlmZ dd ed
7 e jfdd�ZG d
8 d� de�ZdS )� N)�contextmanager)�Path)�sleep)�time)� BaseCache)�FileSystemSerializer� �string�returnc C s
9 t �| �S )z�Don't access ``hashlib.md5`` until runtime. FIPS builds may not include
10 md5, in which case the import and use as a default would fail before the
11 developer can configure something else.
12 )�hashlib�md5)r � r
13 �CC:\Users\shubh\Videos\agent\nova\Lib\site-packages\cachelib/file.py� _lazy_md5 s
14 r c @ s e Zd ZdZdZdZee�Ze � Z
15 dAdeded ed
16 e
17 je de
18 jf
19 dd
20 �Zdefdd�Zedefdd��Z dBde
21 je de
22 je ddfdd�Zde
23 je defdd�Zdedefdd�Zde
24 jeddf fdd�Zdefdd �Zd!eddfd"d#�Zdefd$d%�ZdCd&d'�Zdefd(d)�Zd*edefd+d,�Z d*ede
25 jfd-d.�Z!dDd*ede
26 jde
27 je defd/d0�Z" 1dEd*ede
28 jde
29 je d2edef
30 d3d4�Z#dFd*ed2edefd5d6�Z$d*edefd7d8�Z%d9e
31 j&d:e
32 jd;e
33 jde
34 jfd<d=�Z'e(d>ed
35 ede
36 jfd?d@��Z)dS )G�FileSystemCachea1 A cache that stores the items on the file system. This cache depends
37 on being the only user of the `cache_dir`. Make absolutely sure that
38 nobody but this cache stores files there or otherwise the cache will
39 randomly delete files therein.
40
41 :param cache_dir: the directory where cache files are stored.
42 :param threshold: the maximum number of items the cache stores before
43 it starts deleting some. A threshold value of 0
44 indicates no threshold.
45 :param default_timeout: the default timeout that is used if no timeout is
46 specified on :meth:`~BaseCache.set`. A timeout of
47 0 indicates that the cache never expires.
48 :param mode: the file mode wanted for the cache files, default 0600
49 :param hash_method: Default hashlib.md5. The hash method used to
50 generate the filename for cached results.
51 Default is lazy loaded and can be overriden by
52 seeting `_default_hash_method`
53 z.__wz_cacheZ__wz_cache_count�� �, N� cache_dir� threshold�default_timeout�mode�hash_methodc
54 C s� t �| |� || _|| _| j| _|d ur|| _|| _| jd u r$| �� | _zt� | j� W n t
55 yE } z
56 |jtjkr;� W Y d }~nd }~ww | jdkrY| j
57 tt| �� ��d� d S d S )Nr ��value)r �__init__�_path�
58 _threshold�_default_hash_method�_hash_method�_mode�_get_compatible_platform_mode�os�makedirs�OSError�errno�EEXIST�
59 _update_count�len�list� _list_dir)�selfr r r r r �exr
60 r
61 r r 8 s(
62
63 ���
64 �zFileSystemCache.__init__r
65 c C s d}t �� dkrtj}|S )Ni� �Windows)�platform�system�stat�S_IWRITE)r* r r
66 r
67 r r Z s z-FileSystemCache._get_compatible_platform_modec C s | � | j�pdS �Nr )�get�_fs_count_file�r* r
68 r
69 r �_file_count` s zFileSystemCache._file_count�deltar c C s<