o
    wvXjÊa  ã                   @   s|  d Z ddlmZmZmZ ddlZddlZddlZddlZddl	Z	ddl
ZddlZddlZddlZddlZddlmZ ddlmZ ddlmZmZ ddlmZ ddlmZ d	d
lmZ d	dlmZm Z m!Z! d	dl"m#Z# zddl$m%Z% W n e&y}   dZ%Y nw e#dƒZ'e#dƒZ(e#dƒZ)e#dƒZ*e#dƒZ+dZ,e-e	ddƒZ.d	Z/e-e	ddƒZ0e-e	ddƒZ1e-e	ddƒZ2e 3¡ Z4e4dkZ5e4dkZ6dZ7e	j8e	j9B e	j:B Z;e	j<e	j=B d> e	j<d> B e	j<B Z>d Z?ed!d"ƒZ@e	jA Bd#d$¡ZCd%ZDd&ZEd'd(„ eFeƒD ƒZGd)d*„ eGD ƒZHd+d,„ ZId-d.„ ZJG d/d0„ d0eKƒZLG d1d2„ d2eMƒZNeNZOd3d4„ ZPd5d6„ ZQd7d8„ ZRG d9d:„ d:eMƒZS		$ddd;d<„ZTd=d>„ ZUd?d@„ ZVdAdB„ ZWdCdD„ ZXdEdF„ ZYdGdH„ ZZdIdJ„ Z[dedKdL„Z\dMdN„ Z]G dOdP„ dPeMƒZ^e^ƒ Z_e_j`Zae_jbZce_jdZee_jfZgdQdR„ ZhdSdT„ ZidfdUdV„Zje	jA BdW¡�r�dXdY„ ZkndedZdY„Zkd[d\„ Zled]d^„ ƒZmd_d`„ Znejodak �r³ddlpZpdbdc„ ZqeqejrƒZreqejsƒZseqejtƒZtdS ejrZrejsZsejtZtdS )gziPlatforms.

Utilities dealing with platform specifics: signals, daemonization,
users, groups, and so on.
é    )Úabsolute_importÚprint_functionÚunicode_literalsN)Ú
namedtuple)Úcontextmanager)Úclose_open_fdsÚ	get_fdmax)Úmaybe_fileno)Úsafe_stré   )ÚSecurityError)ÚitemsÚreraiseÚstring_t)Ú
try_import)Úcurrent_processÚsetproctitleÚresourceÚpwdÚgrpzmultiprocessing.util)ÚEX_OKÚ
EX_FAILUREÚEX_UNAVAILABLEÚEX_USAGEÚSYSTEMÚIS_macOSÚ
IS_WINDOWSÚSIGMAPÚpyimplementationÚ
LockFailedr   ÚPidfileÚcreate_pidlockr   ÚDaemonContextÚdetachedÚ	parse_uidÚ	parse_gidÚ	setgroupsÚ
initgroupsÚsetgidÚsetuidÚmaybe_drop_privilegesÚsignalsÚsignal_nameÚset_process_titleÚset_mp_process_titleÚget_errno_nameÚignore_errnoÚ
fd_by_pathÚisattyr   r   éE   r   é@   ÚEX_CANTCREATéI   ÚDarwinÚWindowsú/é   é   zLERROR: Pidfile ({0}) already exists.
Seems we're already running? (pid: {1})Ú_range)ÚstartÚstopÚC_FORCE_ROOTFa>  Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!

If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).

User information: uid={uid} euid={euid} gid={gid} egid={egid}
zÑYou're running the worker with superuser privileges: this is
absolutely not recommended!

Please specify a different user using the --uid option.

User information: uid={uid} euid={euid} gid={gid} egid={egid}
c                 C   s"   h | ]}|  d ¡rd|vr|’qS )ÚSIGÚ_)Ú
startswith©Ú.0Úsig© rF   úM/var/www/html/myproject/venv/lib/python3.10/site-packages/celery/platforms.pyÚ	<setcomp>^   s    þÿrH   c                 C   s   i | ]}t t|ƒ|“qS rF   )ÚgetattrÚ_signal)rD   ÚnamerF   rF   rG   Ú
<dictcomp>b   ó    rL   c                 C   s    z|   ¡ W S  ty   Y dS w )z6Return true if the process has a controlling terminal.N)r2   ÚAttributeError)ÚfhrF   rF   rG   r2   e   s
   
ÿr2   c                  C   s�   t tdƒr	t ¡ S tj d¡rdtj S t tdƒrFd dd„ tjdd	… D ƒ¡} tjd	d… rB| d
d dd„ tjd	d… D ƒ¡ 7 } d|  S dS )z<Return string identifying the current Python implementation.Úpython_implementationÚjavazJython Úpypy_version_infoÚ.c                 s   ó   � | ]}t |ƒV  qd S ©N©Ústr©rD   ÚprF   rF   rG   Ú	<genexpr>t   ó   € z#pyimplementation.<locals>.<genexpr>Nr;   ú-Ú c                 s   rT   rU   rV   rX   rF   rF   rG   rZ   v   r[   zPyPy ÚCPython)ÚhasattrÚ	_platformrP   ÚsysÚplatformrB   ÚjoinrR   )ÚvrF   rF   rG   r   m   s   


&r   c                   @   s   e Zd ZdZdS )r   z'Raised if a PID lock can't be acquired.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rF   rF   rF   rG   r   |   s    r   c                   @   s\   e Zd ZdZdZdd„ Zdd„ ZeZdd„ Zd	d
„ Z	e	Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )r    aF  Pidfile.

    This is the type returned by :func:`create_pidlock`.

    See Also:
        Best practice is to not use this directly but rather use
        the :func:`create_pidlock` function instead:
        more convenient and also removes stale pidfiles (when
        the process holding the lock is no longer running).
    Nc                 C   s   t j |¡| _d S rU   )ÚosÚpathÚabspath)Úselfrj   rF   rF   rG   Ú__init__�   ó   zPidfile.__init__c              
   C   sR   z|   ¡  W | S  ty( } ztttt|ƒƒt ¡ d ƒ W Y d}~| S d}~ww )zAcquire lock.é   N)Ú	write_pidÚOSErrorr   r   rW   ra   Úexc_info)rl   ÚexcrF   rF   rG   Úacquire’   s   
þ&€þzPidfile.acquirec                 C   s   t j | j¡S )z#Return true if the pid lock exists.)ri   rj   Úexists©rl   rF   rF   rG   Ú	is_locked›   s   zPidfile.is_lockedc                 G   s   |   ¡  dS )zRelease lock.N)Úremove©rl   ÚargsrF   rF   rG   ÚreleaseŸ   s   zPidfile.releasec              
   C   s¶   t dƒ�M t| jdƒ�6}| ¡ }| ¡ |krtd | ¡ƒ‚zt| ¡ ƒW W  d  ƒ W  d  ƒ S  ty@   td | ¡ƒ‚w 1 sDw   Y  W d  ƒ dS 1 sTw   Y  dS )z Read and return the current pid.ÚENOENTÚrz#Partial or invalid pidfile {0.path}Nz"pidfile {0.path} contents invalid.)r0   Úopenrj   ÚreadlineÚstripÚ
ValueErrorÚformatÚint)rl   rO   ÚlinerF   rF   rG   Úread_pid¤   s$   
ÿùÿ	ÿÿø"ÿzPidfile.read_pidc                 C   s@   t tjtjƒ� t | j¡ W d  ƒ dS 1 sw   Y  dS )zRemove the lock.N)r0   Úerrnor|   ÚEACCESri   Úunlinkrj   rv   rF   rF   rG   rx   ³   s   "ÿzPidfile.removec              
   C   sè   z|   ¡ }W n ty   tdtjd� |  ¡  Y dS w |s$|  ¡  dS z	t |d¡ W dS  tjy_ } z%|j	t	j
ksB|j	t	jkrTtdtjd� |  ¡  W Y d}~dS W Y d}~dS d}~w tys   tdtjd� |  ¡  Y dS w )zhRemove the lock if the process isn't running.

        I.e. process does not respons to signal.
        z#Broken pidfile found - Removing it.©ÚfileTr   z#Stale pidfile exists - Removing it.NF)r…   r�   Úprintra   Ústderrrx   ri   ÚkillÚerrorr†   ÚESRCHÚEPERMÚSystemError)rl   Úpidrs   rF   rF   rG   Úremove_if_stale¸   s4   ý
÷
ý€üýzPidfile.remove_if_stalec                 C   s²   t  ¡ }d |¡}t  | jtt¡}t  |d¡}z | |¡ | 	¡  zt  
|¡ W n	 ty1   Y nw W | ¡  n| ¡  w t| jƒ}z| ¡ |krMtdƒ‚W | ¡  d S | ¡  w )Nz{0}
Úwz7Inconsistency: Pidfile content doesn't match at re-read)ri   Úgetpidr‚   r~   rj   ÚPIDFILE_FLAGSÚPIDFILE_MODEÚfdopenÚwriteÚflushÚfsyncrN   ÚcloseÚreadr   )rl   r’   ÚcontentÚ
pidfile_fdÚpidfileÚrfhrF   rF   rG   rp   Ô   s,   

ÿ€
ÿÿzPidfile.write_pid)re   rf   rg   rh   rj   rm   rt   Ú	__enter__rw   r{   Ú__exit__r…   rx   r“   rp   rF   rF   rF   rG   r    €   s    r    c                 C   s   t | ƒ}t |j¡ |S )a  Create and verify pidfile.

    If the pidfile already exists the program exits with an error message,
    however if the process it refers to isn't running anymore, the pidfile
    is deleted and the program continues.

    This function will automatically install an :mod:`atexit` handler
    to release the lock at exit, you can skip this by calling
    :func:`_create_pidlock` instead.

    Returns:
       Pidfile: used to manage the lock.

    Example:
        >>> pidlock = create_pidlock('/var/run/app.pid')
    )Ú_create_pidlockÚatexitÚregisterr{   ©r    ÚpidlockrF   rF   rG   r!   ñ   s   r!   c                 C   sF   t | ƒ}| ¡ r| ¡ stt | | ¡ ¡tjd� t	t
ƒ‚| ¡  |S )Nr‰   )r    rw   r“   r‹   Ú	PIDLOCKEDr‚   r…   ra   rŒ   Ú
SystemExitr5   rt   r§   rF   rF   rG   r¤     s   r¤   c              
      sŽ   t ƒ ‰| D ].}z	t |tj¡}W n	 ty   Y qw zˆ t |¡dd… ¡ W t |¡ qt |¡ w ‡fdd„‰ ‡ fdd„tt	dƒƒD ƒS )a[  Return a list of file descriptors.

    This method returns list of file descriptors corresponding to
    file paths passed in paths variable.

    Arguments:
        paths: List[str]: List of file paths.

    Returns:
        List[int]: List of file descriptors.

    Example:
        >>> keep = fd_by_path(['/dev/urandom', '/my/precious/'])
    r   r;   c                    s.   zt  | ¡dd… ˆ v W S  ty   Y dS w )Nr   r;   F)ri   Úfstatrq   )Úfd)ÚstatsrF   rG   Úfd_in_stats*  s
   ÿzfd_by_path.<locals>.fd_in_statsc                    s   g | ]}ˆ |ƒr|‘qS rF   rF   )rD   Ú_fd)r®   rF   rG   Ú
<listcomp>0  rM   zfd_by_path.<locals>.<listcomp>i   )
Úsetri   r~   ÚO_RDONLYrq   Úaddr«   rœ   Úranger   )Úpathsrj   r¬   rF   )r®   r­   rG   r1     s   ÿr1   c                   @   sJ   e Zd ZdZdZ		ddd„Zdd„ Zd	d
„ ZeZdd„ Z	e	Z
dd„ ZdS )r"   z(Context manager daemonizing the process.FNTc                 K   sZ   t |tƒrt|| d¡rdndƒ}|pt| _|| _|| _|| _|| _	t
jt
jt
jf| _d S )NÚ0é   é
   )Ú
isinstancer   rƒ   rB   ÚDAEMON_WORKDIRÚworkdirÚumaskÚfakeÚafter_chdirÚafter_forkersra   ÚstdinÚstdoutrŒ   Ústdfds)rl   r    r»   r¼   r½   r¾   r¿   ÚkwargsrF   rF   rG   rm   8  s   

zDaemonContext.__init__c                 C   s,   |d urt  t jt j¡}t  ||¡ d S d S rU   )ri   r~   ÚdevnullÚO_RDWRÚdup2)rl   r¬   ÚdestrF   rF   rG   Úredirect_to_nullE  s   þzDaemonContext.redirect_to_nullc                 C   s¤   | j sP| js
|  ¡  t | j¡ | jd urt | j¡ | jr"|  ¡  | jsKt| j	ƒt
dgƒ }t|ƒ | j	D ]	}|  t|ƒ¡ q6| jrKtd urKt ¡  d| _ d S d S )Nz/dev/urandomT)Ú_is_openr½   Ú_detachri   Úchdirr»   r¼   r¾   ÚlistrÂ   r1   r   rÈ   r	   r¿   ÚmputilÚ_run_after_forkers)rl   Úkeepr¬   rF   rF   rG   r~   J  s"   


ëzDaemonContext.openc                 G   s   | j rd| _ d S d S )NF)rÉ   ry   rF   rF   rG   rœ   c  s   
ÿzDaemonContext.closec                 C   s<   t  ¡ dkrt  ¡  t  ¡ dkrt  d¡ | S t  d¡ | S ©Nr   )ri   ÚforkÚsetsidÚ_exitrv   rF   rF   rG   rÊ   h  s   

ÿzDaemonContext._detach)NNNFNT)re   rf   rg   rh   rÉ   rm   rÈ   r~   r¢   rœ   r£   rÊ   rF   rF   rF   rG   r"   3  s    
ÿr"   c           	         sT   t stdƒ‚|du rt ¡ n|}t d¡ t||d� ‡ ‡fdd„}t||||d�S )aë  Detach the current process in the background (daemonize).

    Arguments:
        logfile (str): Optional log file.
            The ability to write to this file
            will be verified before the process is detached.
        pidfile (str): Optional pid file.
            The pidfile won't be created,
            as this is the responsibility of the child.  But the process will
            exit if the pid lock exists and the pid written is still running.
        uid (int, str): Optional user id or user name to change
            effective privileges to.
        gid (int, str): Optional group id or group name to change
            effective privileges to.
        umask (str, int): Optional umask that'll be effective in
            the child process.
        workdir (str): Optional new working directory.
        fake (bool): Don't actually detach, intended for debugging purposes.
        **opts (Any): Ignored.

    Example:
        >>> from celery.platforms import detached, create_pidlock
        >>> with detached(
        ...           logfile='/var/log/app.log',
        ...           pidfile='/var/run/app.pid',
        ...           uid='nobody'):
        ... # Now in detached child process with effective user set to nobody,
        ... # and we know that our logfile can be written to, and that
        ... # the pidfile isn't locked.
        ... pidlock = create_pidlock('/var/run/app.pid')
        ...
        ... # Run the program
        ... program.run(logfile='/var/log/app.log')
    z&This platform does not support detach.NÚSIGCLD©ÚuidÚgidc                      s*   ˆ ot ˆ dƒ ¡  ˆrtˆƒ ¡  d S d S )NÚa)r~   rœ   r¤   r{   rF   ©Úlogfiler    rF   rG   Úafter_chdir_dož  s
   €ÿz detached.<locals>.after_chdir_do)r¼   r»   r½   r¾   )r   ÚRuntimeErrorri   Úgetcwdr+   Úresetr*   r"   )	rÚ   r    rÖ   r×   r¼   r»   r½   ÚoptsrÛ   rF   rÙ   rG   r#   s  s   $
ÿr#   c                 C   óN   zt | ƒW S  ty&   z	t | ¡jW  Y S  ttfy%   td | ¡ƒ‚w w )zŒParse user id.

    Arguments:
        uid (str, int): Actual uid, or the username of a user.
    Returns:
        int: The actual uid.
    zUser does not exist: {0})rƒ   r�   r   ÚgetpwnamÚpw_uidrN   ÚKeyErrorr‚   ©rÖ   rF   rF   rG   r$   «  ó   
ÿýr$   c                 C   rà   )z—Parse group id.

    Arguments:
        gid (str, int): Actual gid, or the name of a group.
    Returns:
        int: The actual gid of the group.
    zGroup does not exist: {0})rƒ   r�   r   ÚgetgrnamÚgr_gidrN   rã   r‚   ©r×   rF   rF   rG   r%   ¼  rå   r%   c              
   C   s¢   | d d … } 	 zt  | ¡W S  ty'   t| ƒdkr‚ | d d… | d d …< Y n) tyO } z|jtjks:t| ƒdkr;‚ | d d… | d d …< W Y d }~nd }~ww q)Nr   éÿÿÿÿ)ri   r&   r�   Úlenrq   r†   ÚEINVAL)Úgroupsrs   rF   rF   rG   Ú_setgroups_hackÍ  s    €ýùrí   c              
      sŠ   d}zt  d¡}W n	 ty   Y nw z	tˆ d|… ƒW S  tyD } z|jtjkr+‚ t‡ fdd„t  ¡ D ƒƒr9‚ W Y d}~dS d}~ww )z+Set active groups from a list of group ids.NÚSC_NGROUPS_MAXc                 3   s   � | ]}|ˆ vV  qd S rU   rF   )rD   Úgroup©rì   rF   rG   rZ   ì  r[   zsetgroups.<locals>.<genexpr>)	ri   ÚsysconfÚ	Exceptionrí   rq   r†   r�   ÚanyÚ	getgroups)rì   Ú
max_groupsrs   rF   rð   rG   r&   à  s    ÿþ€ýr&   c                    sN   t sdS t  | ¡d ‰ ttdƒrt ˆ |¡S ‡ fdd„t ¡ D ƒ}t|ƒ dS )zyInit process group permissions.

    Compat version of :func:`os.initgroups` that was first
    added to Python 2.7.
    Nr   r'   c                    s   g | ]
}ˆ |j v r|j‘qS rF   )Úgr_memrç   )rD   Úgr©ÚusernamerF   rG   r°   ü  s    
ÿzinitgroups.<locals>.<listcomp>)r   Úgetpwuidr_   ri   r'   r   Úgetgrallr&   )rÖ   r×   rì   rF   rø   rG   r'   ñ  s   
r'   c                 C   ó   t  t| ƒ¡ dS )z4Version of :func:`os.setgid` supporting group names.N)ri   r(   r%   rè   rF   rF   rG   r(     ó   r(   c                 C   rü   )z2Version of :func:`os.setuid` supporting usernames.N)ri   r)   r$   rä   rF   rF   rG   r)     rý   r)   c                 C   sž   t jdkrdS t ¡ rt ¡ stdƒ‚| ot| ƒ} |ot|ƒ}| r't| |ƒ n|o,t	|ƒ | r;t ¡ s;t ¡ s;tdƒ‚|rIt 
¡ sKt ¡ sMtdƒ‚dS dS dS )a  Change process privileges to new user/group.

    If UID and GID is specified, the real user/group is changed.

    If only UID is specified, the real user is changed, and the group is
    changed to the users primary group.

    If only GID is specified, only the group is changed.
    Úwin32Nzcontact supportz%Still root uid after drop privileges!z%Still root gid after drop privileges!)ra   rb   ri   ÚgeteuidÚgetuidr   r$   r%   Ú_setuidr(   ÚgetgidÚgetegidrÕ   rF   rF   rG   r*     s    


€ÿr*   c              
   C   sv   |s
t r
t  | ¡j}t|ƒ t| |ƒ t| ƒ z	tdƒ W t	dƒ‚ ty: } z|jtjkr/‚ W Y d }~d S d }~ww )Nr   z6non-root user able to restore privileges after setuid.)
r   rú   Úpw_gidr(   r'   r)   rq   r†   r�   r   )rÖ   r×   rs   rF   rF   rG   r  )  s    

ÿúÿ€ÿr  c                   @   s¦   e Zd ZdZejZejZe	edƒrdd„ Z
nzddlmZ W n ey+   dd„ Z
Y nw dd„ Z
d	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„ZdS )ÚSignalsaE  Convenience interface to :mod:`signals`.

    If the requested signal isn't supported on the current platform,
    the operation will be ignored.

    Example:
        >>> from celery.platforms import signals

        >>> from proj.handlers import my_handler
        >>> signals['INT'] = my_handler

        >>> signals['INT']
        my_handler

        >>> signals.supported('INT')
        True

        >>> signals.signum('INT')
        2

        >>> signals.ignore('USR1')
        >>> signals['USR1'] == signals.ignored
        True

        >>> signals.reset('USR1')
        >>> signals['USR1'] == signals.default
        True

        >>> from proj.handlers import exit_handler, hup_handler
        >>> signals.update(INT=exit_handler,
        ...                TERM=exit_handler,
        ...                HUP=hup_handler)
    Ú	setitimerc                 C   s   t  t j|¡ d S rU   )rJ   r  ÚITIMER_REAL©rl   ÚsecondsrF   rF   rG   Ú	arm_alarmm  rn   zSignals.arm_alarmr   )Úalarmc                 C   s   t  t |¡¡ d S rU   )rJ   r  ÚmathÚceilr  rF   rF   rG   r
  t  s   c                 C   s   t |ƒS rU   )Ú_itimer_alarmr  rF   rF   rG   r
  x  s   c                 C   s
   t  d¡S rÐ   )rJ   r  rv   rF   rF   rG   Úreset_alarm{  s   
zSignals.reset_alarmc                 C   s&   z|   |¡ W dS  ty   Y dS w )z@Return true value if signal by ``name`` exists on this platform.FT)ÚsignumrN   ©rl   rK   rF   rF   rG   Ú	supported~  s   ýÿzSignals.supportedc                 C   sF   t |tjƒr|S t |tƒr| ¡ stdƒ‚| d¡sd| }tt|ƒS )zGet signal number by name.z%signal name must be uppercase string.r@   )	r¹   ÚnumbersÚIntegralr   ÚisupperÚ	TypeErrorrB   rI   rJ   r  rF   rF   rG   r  ‡  s   
ÿ

zSignals.signumc                    ó   ˆ   ‡ fdd„|D ƒ¡ dS )z¦Reset signals to the default signal handler.

        Does nothing if the platform has no support for signals,
        or the specified signal in particular.
        c                 3   ó   � | ]}|ˆ j fV  qd S rU   )ÚdefaultrC   rv   rF   rG   rZ   ˜  ó   € z Signals.reset.<locals>.<genexpr>N©Úupdate)rl   Úsignal_namesrF   rv   rG   rÞ   ’  ó   zSignals.resetc                    r  )zŸIgnore signal using :const:`SIG_IGN`.

        Does nothing if the platform has no support for signals,
        or the specified signal in particular.
        c                 3   r  rU   )ÚignoredrC   rv   rF   rG   rZ      r  z!Signals.ignore.<locals>.<genexpr>Nr  )rl   ÚnamesrF   rv   rG   Úignoreš  r  zSignals.ignorec                 C   s   t  |  |¡¡S rU   )rJ   Ú	getsignalr  r  rF   rF   rG   Ú__getitem__¢  s   zSignals.__getitem__c              	   C   s2   zt  |  |¡|¡ W dS  ttfy   Y dS w )z™Install signal handler.

        Does nothing if the current platform has no support for signals,
        or the specified signal in particular.
        N)rJ   Úsignalr  rN   r�   )rl   rK   ÚhandlerrF   rF   rG   Ú__setitem__¥  s
   ÿzSignals.__setitem__Nc                 K   s.   t t|pi fi |¤ŽƒD ]\}}|| |< qdS )z#Set signal handlers from a mapping.N)r   Údict)rl   Ú_d_ÚsigmaprK   r%  rF   rF   rG   r  °  s    
ÿzSignals.updaterU   )re   rf   rg   rh   rJ   ÚSIG_IGNr  ÚSIG_DFLr  r_   r
  Úitimerr  r  ÚImportErrorr  r  r  rÞ   r!  r#  r&  r  rF   rF   rF   rG   r  E  s(    "

þ	r  c                 C   s   t |  dd… S )z)Return name of signal from signal number.r;   N)r   )r  rF   rF   rG   r,   ½  s   r,   c                 C   s6   d| d v rdnd}t | ƒ|krd | |d … ¡S dS )NÚmanager   ro   r   ú r]   )rê   rc   )ÚargvÚ	arg_startrF   rF   rG   ÚstrargvÂ  s   r2  c                 C   s4   d  | ¡}|rd  ||¡n|}trt t|ƒ¡ |S )zxSet the :command:`ps` name for the currently running process.

    Only works if :pypi:`setproctitle` is installed.
    z[{0}]z{0} {1})r‚   Ú_setproctitler   r
   )ÚprognameÚinfoÚ	proctitlerF   rF   rG   r-   É  s
   
r-   ÚNOSETPSc                  O   s   dS )zDisabled feature.NrF   )rØ   ÚkrF   rF   rG   r.   ×  s    r.   c                 C   s4   |rd  | |¡} trtƒ jnd}td  | |¡|d�S )z|Set the :command:`ps` name from the current process name.

        Only works if :pypi:`setproctitle` is installed.
        z{0}: {1}ÚMainProcessz{0}:{1})r5  )r‚   r   rK   r-   )r4  r5  ÚhostnamerK   rF   rF   rG   r.   Û  s   c                 C   s   t | tƒr
tt| ƒS | S )z(Get errno for string (e.g., ``ENOENT``).)r¹   r   rI   r†   )ÚnrF   rF   rG   r/   æ  s   

r/   c               
   o   sl   � |  d¡ptf}dd„ | D ƒ} zdV  W dS  |y5 } zt|dƒs$‚ |j| vr*‚ W Y d}~dS d}~ww )a  Context manager to ignore specific POSIX error codes.

    Takes a list of error codes to ignore: this can be either
    the name of the code, or the code integer itself::

        >>> with ignore_errno('ENOENT'):
        ...     with open('foo', 'r') as fh:
        ...         return fh.read()

        >>> with ignore_errno(errno.ENOENT, errno.EPERM):
        ...    pass

    Arguments:
        types (Tuple[Exception]): A tuple of exceptions to ignore
            (when the errno matches).  Defaults to :exc:`Exception`.
    Útypesc                 S   s   g | ]}t |ƒ‘qS rF   )r/   )rD   r†   rF   rF   rG   r°      s    z ignore_errno.<locals>.<listcomp>Nr†   )Úgetrò   r_   r†   )ÚerrnosrÃ   r<  rs   rF   rF   rG   r0   í  s   €

ÿ€ýr0   c              	   C   s  t tdƒr	t ¡ nd}t tdƒrt ¡ nd}t tdƒrt ¡ nd}t tdƒr*t ¡ nd}t tdƒr>tdd„ d	D ƒƒs>td
ƒ‚|rF|rF|rF|s†d| v sNd| v rvtsvzt	t
j||||d�tjd� W tj ¡  t d¡ ntj ¡  t d¡ w t ttj||||d�ƒ¡ d S d S )Nr   iÿÿ  r  rÿ   r  Úfchownc                 s   s   � | ]}t t|ƒV  qd S rU   )r_   ri   )rD   ÚattrrF   rF   rG   rZ     s   € ÿz#check_privileges.<locals>.<genexpr>)r   r  rÿ   r  z$suspicious platform, contact supportÚpicklezapplication/x-python-serialize)rÖ   Úeuidr×   Úegidr‰   r   )r_   ri   r   r  rÿ   r  Úallr   r?   r‹   ÚROOT_DISALLOWEDr‚   ra   rŒ   rš   rÓ   ÚwarningsÚwarnÚRuntimeWarningÚROOT_DISCOURAGED)Úaccept_contentrÖ   r×   rB  rC  rF   rF   rG   Úcheck_privileges
  s6   
ÿÿþ

ÿ
ÿõrK  )ro   é   rL  c                    s   t  ˆ ¡‡ fdd„ƒ}|S )Nc                    s   ˆ |   ¡ g|¢R i |¤ŽS rU   )Úencode)Úsrz   rÃ   ©ÚfunrF   rG   Ú_inner)  s   z_to_bytes_arg.<locals>._inner)Ú	functoolsÚwraps)rP  rQ  rF   rO  rG   Ú_to_bytes_arg(  s   rT  )NNNNr   NF)NNrU   )urh   Ú
__future__r   r   r   r¥   r†   r  r  ri   rb   r`   r$  rJ   Ústructra   rF  Úcollectionsr   Ú
contextlibr   Úbilliard.compatr   r   Úkombu.utils.compatr	   Úkombu.utils.encodingr
   Ú
exceptionsr   Úfiver   r   r   Úlocalr   Úbilliard.processr   r-  r3  r   r   r   rÍ   Ú__all__rI   r   r   r   r   r5   Úsystemr   r   r   rº   ÚO_CREATÚO_EXCLÚO_WRONLYr–   ÚR_OKÚW_OKr—   r©   r<   Úenvironr=  r?   rE  rI  ÚdirÚSIGNAMESr   r2   r   rò   r   Úobjectr    ÚPIDFiler!   r¤   r1   r"   r#   r$   r%   rí   r&   r'   r(   r)   r*   r  r  r+   r  Ú
get_signalr&  Úinstall_signal_handlerrÞ   Úreset_signalr!  Úignore_signalr,   r2  r-   r.   r/   r0   rK  Úversion_inforR  rT  ÚpackÚunpackÚunpack_fromrF   rF   rF   rG   Ú<module>   sÂ   ÿ 

	ÿn	#@
ÿ8
q






