o
    [Þh	  ã                   @   s*   d dl Z d dlZd dlZG dd„ dƒZdS )é    Nc                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚPidfilezž    Manage a PID file. If a specific name is provided
    it and '"%s.oldpid" % name' will be used. Otherwise
    we create a temp file using os.mkstemp.
    c                 C   s   || _ d | _d S ©N)ÚfnameÚpid)Úselfr   © r   úP/var/www/html/premium_crap/venv/lib/python3.10/site-packages/gunicorn/pidfile.pyÚ__init__   s   
zPidfile.__init__c                 C   sÂ   |   ¡ }|r|t ¡ krd S d}t||| jf ƒ‚|| _tj | j¡}|r1tj |¡s1td| ƒ‚t	j
|d�\}}t |d| j  d¡¡ | jrPt || j¡ n|| _t |¡ t | jd¡ d S )Nz5Already running on PID %s (or pid file '%s' is stale)z'%s doesn't exist. Can't create pidfile.)Údirz%s
zutf-8i¤  )ÚvalidateÚosÚgetpidÚRuntimeErrorr   r   ÚpathÚdirnameÚisdirÚtempfileÚmkstempÚwriteÚencodeÚrenameÚcloseÚchmod)r   r   ÚoldpidÚmsgÚfdirÚfdr   r   r   r   Úcreate   s"   
zPidfile.createc                 C   s   |   ¡  || _|  | j¡ d S r   )Úunlinkr   r   r   )r   r   r   r   r   r   .   s   zPidfile.renamec                 C   sr   z.t | jƒ�}t| ¡ pdƒ}W d  ƒ n1 sw   Y  || jkr,t | j¡ W dS W dS  ty8   Y dS w )z delete pidfiler   N)Úopenr   ÚintÚreadr   r   r   Ú	Exception)r   ÚfÚpid1r   r   r   r   3   s   ÿ
ÿÿzPidfile.unlinkc                 C   s4  | j sdS zxt| j ƒ�h}zt| ¡ ƒ}W n ty%   Y W d  ƒ W dS w zt |d¡ |W W  d  ƒ W S  tyr } z/|jd t	j
krW|W  Y d}~W  d  ƒ W S |jd t	jkrmW Y d}~W d  ƒ W dS ‚ d}~ww 1 svw   Y  W dS  ty™ } z|jd t	jkr”W Y d}~dS ‚ d}~ww )z- Validate pidfile and make it stale if neededNr   )r   r   r    r!   Ú
ValueErrorr   ÚkillÚOSErrorÚargsÚerrnoÚEPERMÚESRCHÚENOENT)r   r#   ÚwpidÚer   r   r   r   >   s>   üø	õ
ó€û÷€ýzPidfile.validateN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r   r   r   
   s    r   )r)   r   r   r   r   r   r   r   Ú<module>   s   