HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/setroubleshoot/__pycache__/util.cpython-39.opt-1.pyc
a

U+eӈ�@s�ddlmZddlmZgd�ZddlZddlZddlZddlm	Z	ddl
Z
ddlmZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlTddlZddlmZdd	lmZmZdd
lmZddlTdd�Z d
d�Z!dZ"dZ#dZ$e�%d��rdZ$ne�%d��r&dZ$dZ&e�'�Z(e�)d�Z*e�)d�Z+e�)d�Z,e�)d�Z-e�)d�Z.e�)d�Z/da0ej1a2ej3ej4ej1ej5ej6d�Z7dd�Z8dd�Z9dd �Z:d!d"�Z;d#d$�Z<d%d&�Z=d'd(�Z>d)d*�Z?dd+d,�Z@d-d.�ZAd�d1d2�ZBd�d3d4�ZCd�d6d7�ZDd8d9�ZEd:d;�ZFd<d=�ZGd>d?�ZHdeH_Id@dA�ZJdBdC�ZKdDdE�ZLieL_MdFdG�ZNieN_MzddHlOmPZPeP�ZQWngZQYn0dIdJ�ZRdKdL�ZSdMdN�ZTdOdP�ZUd�dRdS�ZVdTdU�ZWdVdW�ZXdXdY�ZYdZd[�ZZd\d]�Z[d�d^d_�Z\d`da�Z]d�dbdc�Z^ddde�Z_d�dfdg�Z`dhdi�Zad�djdk�Zbdldm�Zcdndo�Zddpdq�Zedrds�Zfejgejhdt�Ziejj�rXejgejkdt�ZlneiZleleiZme�gd�Znejgdudv�ZoGdwdx�dxejp�ZqGdydz�dzejp�ZrGd{d|�d|�ZsGd}d~�d~ej�Zte�uet�dS)��)�absolute_import)�range),�audit_msg_decode�merge_lists�preextend_list�fmt_obj�format_elapsed_time�format_2_column_name_value�	wrap_text�
format_msg�remove_linebreaks�default_text�default_date_text�is_standard_directory�get_standard_directories�get_rpm_nvr_from_header�get_package_nvr_by_name�get_package_nvr_by_file_path�get_rpm_nvr_by_type�get_rpm_nvr_by_scontext�get_rpm_source_package�is_hex�
split_rpm_nvr�
file_types�get_user_home_dir�get_plugin_names�load_plugins�get_os_environment�find_program�get_identity�get_hostname�make_database_filepath�valid_email_address�launch_web_browser_on_url�abstract�	log_debug�get_error_from_socket_exception�!assure_file_ownership_permissions�parse_datetime_offset�DATABASE_MAJOR_VERSION�DATABASE_MINOR_VERSION�database_version_compatible�syslog_trace�	TimeStamp�Retry�PACKAGE_MANAGERN)�SystemMessageBus)�GObject)�*)�
cmp_to_key)�FunctionType�
MethodType)�
get_configcCs||k||kS�N���x�yr8r8�7/usr/lib/python3.9/site-packages/setroubleshoot/util.py�<lambda>^�r=cCs.zt|t�WSty(t|t�YS0dSr7)�
isinstanceZTypeType�	NameError�type��objr8r8r<�is_typeasrD��rpm�dpkg�debz/etc/redhat-releasez	\s*\n+\s*z^[A-Fa-f0-9]+$z<a\s*href="([^"]+)"[^<]*</a>z^([^\s@]+)@([^\s@]+)$z^\s*"([^"]+)"\s*$z\s*\(\s*type\s+([\w-]+)\s*\)\s*)ZCRITICALZERRORZWARNING�INFO�DEBUGcCs&t�t|d����atdur"tjadS)N�level)�
log_levels�getr6�upper�	log_level�syslog�LOG_WARNING)�sectionr8r8r<�log_init�srScCsttjkrt�tj|�dSr7)rOrP�	LOG_DEBUG)�msgr8r8r<r%�s
r%cCs*|�d�}|D]}t|�rt�|�qdS)N�
)�split�lenrP)ZtraceZ	log_lines�liner8r8r<r,�s
r,cCszd}}|�d�}t|�dkr*t|d�}t|�dkrBt|d�}|tkr`td|ttf�dStd|ttf�dSdS)	N�.�r�z=database version %s not compatible with current %d.%d versionFz9database version %s compatible with current %d.%d versionT)rWrX�intr)r%r*)�version�major�minor�
componentsr8r8r<r+�s
r+cCs�|durdSddl}|�|�\}}t|�}|d}||d}|d}||d}|d}||d}|r~d|||||fS|r�d||||fS|r�d|||fSd||S)	Nri�Qi�<z%dd:%dh:%dm:%.3fsz
%dh:%dm:%.3fsz	%dm:%.3fsz%.3fs)�mathZmodfr])Zelapsed_timercZfractionZwhole�days�hours�minutes�secondsr8r8r<r�s$rcCst�|�rdSdSdS�NTF)�hex_re�match��strr8r8r<r�s
rcCsj|durdSt�|�}|r&|�d�}n@z.tjddkrB|�d�}nt�|��d�}Wn|}Yn0|S)Nr[rrE�hexzutf-8)�audit_decode_re�search�group�sys�version_info�decode�	bytearray�fromhex)rUrjZdecodedr8r8r<r�s

rcCsH|s|S|s|Si}|D]}d||<q|D]}d||<q*t|���}|S)z2return a list containing the unique members of a+bN)�list�keys)�a�b�d�i�mr8r8r<r�s

rcs^|durg}t|�}||}|dkrZt��rJ|��fdd�t|�D��n|��g|�|S)Nrcsg|]
}���qSr8r8��.0r:��defaultr8r<�
<listcomp>�r>z"preextend_list.<locals>.<listcomp>)rXrD�extendr)Zrequested_lengthZ_listr�Z
cur_lengthZdeltar8rr<r�srcs�t�tj�r�St�ttf�r:dd�dd��D��dSt�t�rxt����}|��dd��fdd�|D��dSt	��SdS)	N�[� cSsg|]}dt|��qS)z%s�rr}r8r8r<r�r>zfmt_obj.<locals>.<listcomp>�]�{cs$g|]}dt|�t�|�f�qS)z%s=%sr�)r~�keyrBr8r<r�	r>�})
r?�six�string_typesrv�tuple�join�dictrw�sortrl)rCrwr8rBr<rs
 r��PcCsvt|�|kr"|d|d�d}n|d|t|�}|rB|��rN||dS|t_d|t_|t_t�|�dSdS)Nrr[r�rV)rX�isspace�text_wrapper�initial_indent�subsequent_indent�width�fill)�name�valueZvalue_indentZ
page_widthr�r8r8r<r	s
r	cCs(d|}|t_|t_|t_t�|�dS)Nr�rV)r�r�r�r�r�)�sr��indent�prefixr8r8r<r
s
r
�cCsD|durd}|��}d|}|t_|t_dt_|dt�|�dS)N�r�r�rVz

)�stripr�r�r�r�r�)�titlerUr�ZindentStringr8r8r<r%srcCs$t�d|���}|durdS|SdS)Nr�r�)�fix_newline_re�subr�)rlZnew_strr8r8r<r0srcCs |durdtd�d}t|�S)N�<ZUnknown�>)�_rl)�valr8r8r<r
8sr
cCs|durt|�S|��Sr7)r
�format)�dater8r8r<r>srcCsL|durdStj�|�}|r(tj�|�s,dStjdurBtt��t_|tjvS)z�
    Check whether given path is a standard directory.

    >>> is_standard_directory('/etc')
    True

    >>> is_standard_directory('/etc/systemd/')
    False

    >>> is_standard_directory('/usr/bin/cat')
    False
    NF)�os�path�normpath�isabsr�data�setr)r�r8r8r<rDs
rc
Cs�g}zTtdkr.tjgd�dtjd����d�}tdkrVtjgd�dtjd����d�}Wn>tjy�}z$t�tjd�	t|j
��WYd	}~n
d	}~00|S)
zH
>>> get_standard_directories() # doctest: +ELLIPSIS
[...'/bin'...]
    rF)rFz-qlZ
filesystemT��universal_newlines�stderrrVrH)rGz-Lz
base-fileszfailed to get list from {}: {}N)r/�
subprocess�check_output�PIPE�rstriprW�CalledProcessErrorrP�LOG_ERRr�r�)Zlst�er8r8r<rbs $.rcCs&|d}|d}|d}d|||fS)z6Given an RPM header return the package NVR as a stringr�r^�releasez%s-%s-%sr8)Zhdrr�r^r�r8r8r<rtsrc
Cs�|durdS|tjvr tj|Sd}zNtdkrJtjdd|gdtjd���}tdkrptjddd	|gdtjd���}Wn@tjy�}z&t�tj	d
t||j
f�WYd}~n
d}~00|tj|<|S)z?
>>> get_package_nvr_by_name("coreutils")[0:9]
'coreutils'
    NrF�-qTr�rH�
dpkg-queryz(-f=${Package}-${Version}:${Architecture}z-Wz,failed to retrieve %s info for name '%s': %s)r�cacher/r�r�r�r�r�rPr�r�)r��nvrr�r8r8r<r}s 

�0
rc
Cs�|durdStj�|�sdStj�|�}tj�|�s8dS|tjvrLtj|Sd}z�tdkrvtj	dd|gdtj
d���}tdk�r<ztj	dd|gtj
d	���}WnLtj
y�}z2|jd
kr�dtj|<WYd}~WdS�WYd}~n
d}~00|�d�}|D]@}|�d��rq�|jd
d
d�djdd
d�d}t|�}�q<q�WnBtj
�y�}z&t�tjdt||jf�WYd}~n
d}~00|tj|<|S)zB
>>> get_package_nvr_by_file_path("/bin/ls")[0:9]
'coreutils'
    NrFz-qfTr�rHr�z-S)r�r[rVz
diversion by z: )�maxsplitrz, z,failed to retrieve %s info for path '%s': %s)r�r�r�r��existsrr�r/r�r�r�r�rsr��
returncoderW�
startswithrrPr�r�)r�r��queryZcperYZpackage_namer�r8r8r<r�s@





 0
r)�get_all_file_typescCs6|�d�}|d}|d}d�|dd��}|||fS)N�-������)rWr�)r�rar�r^r�r8r8r<r�s

rcCs�tdurt�tdurdSt�|d�}|dur2dSt|�}|dur||�d�d}d|d}t|�}|dur||d7}t|�}|S)a�
Finds an SELinux module which defines given SELinux type

##### arguments

* `selinux_type(s)`: an SELinux type

##### return values

* `nvr(s)`: nvr of rpm which ships module where `selinux_type` is defined

##### usage

>>> get_rpm_nvr_by_type("sshd_t")[0:14]
'selinux-policy'

>>> get_rpm_nvr_by_type("mysqld_log_t")[0:13]
'mysql-selinux'

>>> get_rpm_nvr_by_type("spc_t")[0:17]
'container-selinux'

    N�/r�z/usr/share/selinux/packages/z.ppz.bz2)�module_type_cache�build_module_type_cacherMrrW)Zselinux_typer��package�module_namer8r8r<r�s rcCs"zt|�WdSYdS0dSrh�r]rkr8r8r<�__str_is_ints
r�c	Cst��\}}|dkrdSt�}g}t�d�|���*}tdd�|D�dd�d�}Wd�n1sb0Y|D]�}t�d	�||��D]�\}}}d
|vr�zfztj	d�|�dd
�}	Wnt	d�|��}	Yn0|	D] }
t
�|
�}|r�|||�d�<q�|	�
�Wq�Yq�0q�qp|adS)z�
Creates a dictionary with all types defined in the module store as keys
and corresponding module paths as values.
The dictionary is stored in "module_type_cache" to be used by
"get_rpm_nvr_by_type"

>>> build_module_type_cache()

    rNz"/var/lib/selinux/{}/active/modulescSs$g|]}|��rt|j�r|j�qSr8)�is_dirr�r�r}r8r8r<r�6r>z+build_module_type_cache.<locals>.<listcomp>cSst|�Sr7r�)r:r8r8r<r=6r>z)build_module_type_cache.<locals>.<lambda>�r�z%/var/lib/selinux/{}/active/modules/{}Zcilz{}/cilZrt)�moder[)�selinuxZselinux_getpolicytyper�r��scandirr��sorted�walk�bz2�open�typedef_regexprjrp�closer�)ZretvalZ
policytypeZmodule_type_dictZ
prioritiesZmodule_store�dir�dirpath�dirnames�	filenames�frY�resultr8r8r<r�!s.
8

r�FcCsL|r(t�}|�dd�}t|�t|���St�t|��}ttt�|���SdS)a
Finds an SELinux module which defines given SELinux context

##### arguments

* `scontext(s)`: an SELinux context

##### return values

* `nvr(s)`: nvr of rpm which ships module where SELinux type used in `scontext` is defined

##### usage

>>> get_rpm_nvr_by_scontext("system_u:system_r:syslogd_t:s0")[0:14]
'selinux-policy'

>>> get_rpm_nvr_by_scontext("system_u:system_r:mysqld_log_t:s0")[0:13]
'mysql-selinux'

>>> get_rpm_nvr_by_scontext("system_u:system_r:timedatex_t:s0", use_dbus=True)[0:14]
'selinux-policy'

    z*org.fedoraproject.SetroubleshootPrivilegedz+/org/fedoraproject/SetroubleshootPrivilegedN)r0Z	get_proxyrlrr�Zcontext_newrZcontext_type_get)ZscontextZuse_dbusZbusZ
remote_object�contextr8r8r<rTs�rcCsd|durdSd}z0ddl}|jdddd|gdd��d	d
�d}Wnt�tjd|�Yn0|S)a;
    Find a source package for `name` rpm
    
    >>> get_rpm_source_package("policycoreutils-python-utils")
    'policycoreutils'

    >>> get_rpm_source_package("selinux-policy-targeted")
    'selinux-policy'

    >>> get_rpm_source_package("selinux-policy-targeted-35.8-1.fc35.noarch")
    'selinux-policy'
    NrrFr�z--qfz%{SOURCERPM}T)r�r�r\z"failed to retrieve rpm info for %s)r�r��rsplitrPr�)r��srcr�r8r8r<rws
(rcCs6t��}zt�|�}Wnty*YdS0|j}|Sr7)r��getuid�pwd�getpwuid�KeyError�pw_dir)�uidZpwZhome_dirr8r8r<r�srcCst�|�}|rdSdSdSrh)�name_at_domain_rero)Zaddressrjr8r8r<r"�s
r"cCs tdd�}t�tj|||�dS)NZhelper_apps�web_browser_launcher)r6r��spawnl�P_NOWAIT)�urlr�r8r8r<r#�s
r#cCs6t|dd�}|r"|d}|d}nt}t|�}||fS)N�argsrr[)�getattrZERR_SOCKET_ERRORZget_strerror)r�r��errno�strerrorr8r8r<r&�s
r&c
Cs�d}tj�|�shzt|d�}|��Wn@tyf}z(d}t�tjd||jf�WYd}~n
d}~00zt�	||�WnBt
y�}z*d}t�tjd|||jf�WYd}~n
d}~00zbt|t�r�|}nt
�|�d}|dur�|}t|t�r�|}nddl}	|	�|�d}t�|||�Wnbt
�y�}zHd}ddl}	t�tjd|t
�|�d|	�|�d|jf�WYd}~n
d}~00|S)	NT�wFzcannot create file %s [%s]zcannot chmod %s to %o [%s]r\rzcannot chown %s to %s:%s [%s])r�r�r�r�r��	ExceptionrPr�r��chmod�OSErrorr?r]r��getpwnam�grp�getgrnam�chownr��getgrgid)
�filepathr��ownerrpr�r�r�r��gidr�r8r8r<r'�s:
.0

Fr'cCs<ddl}|�|���dd}|jj}td|||f��dS)Nrr[rEz=%s must be implemented in subclass %s or ancestor class of %s)�inspectZgetouterframesZcurrentframe�	__class__�__name__�NotImplementedError)rCr��method�subclassr8r8r<r$�s�r$cCs�|durd}nt�dd|�}tdd�}g}t�tj�||d��D]<}tj�|�}|dvr\qBtj�tj�|��d}|�	|�qB|S)	Nr2z.py$r��plugins�
plugin_dir�.py)z__init__.pyr)
�rer�r6�globr�r�r��basename�splitext�append)�filter_globr�plugin_names�p�plugin_namer8r8r<r�s
rcCs|��|��Sr7)Zget_priorityr9r8r8r<�sort_plugins�src
Csztdd�}tj�|�s&td|�gStj�|�}g}t|�}td|�|}|tjvr�z.t	j
�||d�}t	j
�|�}|j
�|�WnBty�}z*t�tjd|t|�f�gWYd}~Sd}~00|D]�}	d||	f}zDt	j
�||d|	d	�}t	j
�|�}|j
�|�|�|���Wq�t�yb}z&t�tjd
|	t|�f�WYd}~q�d}~00q�|jtt�d�|S)Nrrz4plugin directory %s does not exist, no plugin loadedzload_plugins() names=%sz/__init__.pyz&failed to initialize plugins in %s: %sz%s.%sr�rzfailed to load %s plugin: %sr�)r6r�r��isdirr%rrrq�modules�	importlib�util�spec_from_file_location�module_from_spec�loader�exec_moduler�rPr�rlr
Zpluginr�r3r)
rrZplugin_baserrr��mod_spec�modr�rr8r8r<r�s8

2rc	Cs~ztt���d��}Wn8zddl}d�|���}Wnd}Yn0Yn0t��}|d}|d}d||f}||fS)Nrr��unknownr\r�z%s %s)	r��redhat_release_path�	readlinesr��distror�Zlinux_distributionr��uname)Z
myplatformrrZkernel_releaseZcpuZos_descr8r8r<rsrcCs@|durt��}zt�|�}Wnty2YdS0|d}|S�Nr)r�r�r�r�r�)r�Z	pwd_entry�usernamer8r8r<r2src
CsTzddl}|��}|WStyN}z t�tjd|�WYd}~dSd}~00dS)Nrzcannot lookup hostname: %s)ZsocketZgethostnamer�rPr�)ZSocket�hostnamer�r8r8r<r >sr cCs\tj�|�r|Stj�|�}tdd��d�}|D]&}tj�||�}tj�|�r0|Sq0dS)NZfix_commandZprog_search_path�:)r�r�r�rr6rWr�r�)�progr�search_pathrzr�r8r8r<rHs
rcCs2tdd�}t�dd|�}|d}tj�||�}|S)NZdatabase�database_dirz\.xml$r�z
_database.xml)r6rr�r�r�r�)r�r%�filenamer�r8r8r<r!Ts

r!cCs t�d�}d}d}d}d}d}|��}|�|�D]�}|r0d}t|�d��}|�d�}	|	dur0|	dkrp||d	7}|	d
kr�||d7}|	dkr�||d
7}|	dkr�||7}|	dkr�||7}|	dkr�||7}|	dkr0||7}q0|�rtj||||d�}
td||
f�|
St	�	t	j
d|�dSdS)z�The time offset may be specified as a sequence of integer unit pairs.
       Units may be one of year,month,week,day,hour,minute,second and may optionally be plural.
       Example: '2 weeks 1 day' sets the threshold at 15 days.
       z0(\d+)\s*(year|month|week|day|hour|minute|second)FrTr[r\N�yearim�month�Zweek��day�hour�minute�second�rdrerfrgz)parse_datetime_offset(%s) = time delta %sz$could not parse datetime offset (%s))r�compile�lower�finditerr]rp�datetime�	timedeltar%rPr�)�textZdatetime_offset_re�foundrdrerfrgrjZquantityZunitZtdr8r8r<r(]sB


r()rgr[)rec@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
LocalTimezonecCs|�|�rtStSdSr7)�_isdst�	DSTOFFSET�	STDOFFSET��self�dtr8r8r<�	utcoffset�s
zLocalTimezone.utcoffsetcCs|�|�rtStSdSr7)r8�DSTDIFF�ZEROr;r8r8r<�dst�s
zLocalTimezone.dstcCstj|�|�Sr7)�time�tznamer8r;r8r8r<rC�szLocalTimezone.tznamec	CsD|j|j|j|j|j|j|��ddf	}t�|�}t�	|�}|j
dkS)Nrr�)r'r(r+r,r-r.�weekdayrB�mktime�	localtime�tm_isdst)r<r=�ttZstampr8r8r<r8�s
�

zLocalTimezone._isdstN)r��
__module__�__qualname__r>rArCr8r8r8r8r<r7�sr7c@s(eZdZdZdd�Zdd�Zdd�ZdS)�UTCcCs
t�d�Sr�r3r4r;r8r8r<r>�sz
UTC.utcoffsetcCsdS)NrKr8r;r8r8r<rC�sz
UTC.tznamecCs
t�d�SrrLr;r8r8r<rA�szUTC.dstN)r�rIrJ�__doc__r>rCrAr8r8r8r<rK�srKc@s�eZdZe�Ze�ZdZdZd#dd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zd$dd�Zdd�Zdd�Zdd�Zd%dd�Zdd�Zdd�Zd&d!d"�ZdS)'r-z%Y-%m-%dT%H:%M:%SZz%cNcCs�|dur|jdd�|_nft|tj�r0|�|�nNt|t�rNtj�||j	�|_n0t|tj�rb||_nt|t
�rv|j|_ntd��dS)NF��localz-must be string, float, datetime, or TimeStamp)�now�_dtr?r�r��parse�floatr3Z
fromtimestamp�utc_tzr-�	TypeError)r<�tr8r8r<�__init__�s


zTimeStamp.__init__cCs$t|t�r|j|jkS|j|kSdSr7�r?r-rQ�r<�otherr8r8r<�__lt__�s
zTimeStamp.__lt__cCs$t|t�r|j|jS|j|SdSr7rXrYr8r8r<�__add__�s
zTimeStamp.__add__cCs.t|t�r|j|j7_n|j|7_|Sr7rXrYr8r8r<�__iadd__�s
zTimeStamp.__iadd__cCs$t|t�r|j|jS|j|SdSr7rXrYr8r8r<�__sub__�s
zTimeStamp.__sub__cCs.t|t�r|j|j8_n|j|8_|Sr7rXrYr8r8r<�__isub__�s
zTimeStamp.__isub__FcCs$|rtj�|j�Stj�|j�SdSr7)r3rP�local_tzrT)r<rOr8r8r<rP�sz
TimeStamp.nowcCs|j�|j�Sr7)rQZ
astimezoner`�r<r8r8r<rO�szTimeStamp.localcCs|j|jdd�S)NFrN)r��iso8601_fmtrar8r8r<�__str__�szTimeStamp.__str__c
CsBt�||j�\	}}}}}}}}	}
t�||||||d|j�|_|jSr)rB�strptimerbr3rTrQ)r<rlr'r(r+r,r-r.rDZyeardayrAr8r8r<rRs��zTimeStamp.parsercCs |jtj||||d�7_dS)Nr/)rQr3r4)r<rdrerfrgr8r8r<�adds�z
TimeStamp.addcCs|��}||jkrdSdSdSrh�rPrQ�r<rPr8r8r<�	in_futures
zTimeStamp.in_futurecCs|��}||jkrdSdSdSrhrfrgr8r8r<�in_pasts
zTimeStamp.in_pastTcCs0|dur|j}|r |���|�S|j�|�SdSr7)�
locale_fmtrO�strftimerQ)r<ZfmtrOr8r8r<r�s
zTimeStamp.format)N)F)rrrr)NT)r�rIrJrKrTr7r`rbrjrWr[r\r]r^r_rPrOrcrRrerhrir�r8r8r8r<r-�s$


r-c@sheZdZdZdejjdejejffiZ	ddd�Z
dd�Zddd	�Zddd�Z
d
d�Zdd�Zdd�ZdS)r.al
    A class which schedules attempts until one succeeds.

    Intervals are expressed as floating point seconds.

    The retry attempt will be scheduled in the future based on the
    retry_interval which may be either a number of seconds or a
    callable object returning the number of seconds. The callable
    form of the retry_interval is useful when the interval should be
    adjusted based on prior history or other external factors,
    e.g. backing off the frequency of the retry attempts if initial
    attempts fail.

    The retry callback should return False if the attempt fails, in
    which case it will be scheduled again in the future based on the
    current value obtained from the retry_interval. If the retry
    callback returns True it indicates the retry attempt succeeded and
    no more attempts will be made.

    Retry's are started with the start() method and continues until
    the retry callback returns True or the stop() method is called. It
    is always safe to call stop() even if a retry is not pending.

    The retry callback, user_data and notify_interval may be specified
    in either the class init() or in the start() method for convenience.

    If notify_interval is set a 'pending_retry' signal will be emitted
    every time the notification interval elapses, this provides a
    countdown till the next retry attempt.

    The signature of the retry callback is: callback(retry_obj, user_data)

    The signature of the pending_retry signal handler is: callback(retry_obj, seconds_pending, user_data)

    The signature of the retry interval function is: interval(retry_obj, user_data)
    �
pending_retryNcCs:tj�|�||_||_||_d|_||_d|_d|_dSr)	r1rW�callback�retry_interval�	user_data�failed_attempts�notify_interval�trigger_time�
timeout_id)r<rmrnrorqr8r8r<rWOszRetry.__init__cCs |jdurt�|j�d|_dSr7)rsZGLibZ
source_removerar8r8r<�stopYs
z
Retry.stopcCsF|dur||_|dur||_|dur*||_|��d|_|�d�dS)NrT)rnrorqrtrp�_schedule_alarm)r<rnrorqr8r8r<�start^szRetry.startFcCsht��}|r||��|_|j|}|jrH|�d||j�t|j|�}n|}t�t	|d�|j
�|_dS)Nrli�)rB�_get_retry_intervalrrrq�emitro�minr1Ztimeout_addr]�_alarm_callbackrs)r<Z	new_retryrP�seconds_pendingZ
alarm_timer8r8r<rujs
zRetry._schedule_alarmcCs6d|_t��}|j|}|dkr*|��n|��dS)Ng{�G�zt?F)rsrBrr�_attempt_retryru)r<rPr{r8r8r<rzvs

zRetry._alarm_callbackcCs4|�||j�r|��n|jd7_|�d�dS)Nr[T)rmrortrprurar8r8r<r|�s
zRetry._attempt_retrycCs"ttttf�r|�||j�S|jSr7)r?Z
interval_typer5r4rnrorar8r8r<rw�szRetry._get_retry_interval)NN)NNN)F)r�rIrJrMr1ZSignalFlagsZRUN_LASTZ
TYPE_FLOATZ
TYPE_PYOBJECTZ__gsignals__rWrtrvrurzr|rwr8r8r8r<r.%s%�



r.)NN)r�r�)r�r)r�)F)N)N)N)N)vZ
__future__rZ	six.movesr�__all__r�r�r3Zdasbus.connectionr0rZ
gi.repositoryr1rr�r�r�shutilr�r�rq�textwraprB�typesrP�	functoolsr3r4r5Zsetroubleshoot.configr6Zsetroubleshoot.errcode�cmprDr)r*r/�whichrZTextWrapperr�r0r�riZhref_rer�rnr�r�rQrOZLOG_CRITr�ZLOG_INFOrTrLrSr%r,r+rrrrrrr	r
rrr
rrr�rrrr�rZsepolicyr�rrrr�r�rrrr"r#r&r'r$rrrrrr rr!r(r4�timezoner:�daylight�altzoner9r?r@ZHOURZtzinfor7rKr-r.Z
type_registerr8r8r8r<�<module>s�0





�	




	;

23
#

*


$

	/

fq