
P'^c           @@ si  d  Z  d d l 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 m Z d d l m Z d d l m Z d d l 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  m! Z! m" Z" d
 d l# m$ Z$ e d  Z% e d  Z& e d  Z' e d  Z( e d  Z) d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. g Z* e+ e d d  Z, d
 Z- e+ e d d/  Z. e+ e d d0  Z/ e+ e d1 d2  Z0 e
 j1   Z2 e2 d3 k Z3 e2 d4 k Z4 d5 Z5 e j6 e j7 Be j8 BZ9 e j: e j; Bd6 >e j: d7 >Be j: BZ< d8 Z= e d9 d]  Z> e j? j@ d< eA  ZB d= ZC d> ZD d?   ZE d eF f d@     YZG d dA  ZI d eJ f dB     YZK eK ZL dC   ZM dD   ZN dE   ZO eP e dF  r1d dG  ZQ n d dH  ZQ d  eJ f dI     YZR d d d d d d eA dJ  ZS dK   ZT dL   ZU dM   ZV dN   ZW dO   ZX dP   ZY dQ   ZZ d d dR  Z[ dS eJ f dT     YZ\ e\   Z] e] j^ Z_ e] j` Za e] jb Zc e] jd Ze dU   Zf d dV  Zg e j? j@ dW  r5dX   Zh n d d dY  Zh dZ   Zi e d[    Zj d\   Zk d S(^   s   
    celery.platforms
    ~~~~~~~~~~~~~~~~

    Utilities dealing with platform specifics: signals, daemonization,
    users, groups, and so on.

i    (   t   absolute_importt   print_functionN(   t
   namedtuple(   t   current_process(   t   maybe_fileno(   t	   get_errno(   t   safe_str(   t   contextmanageri   (   t
   try_import(   t   itemst   ranget   reraiset   string_tt   zip_longest(   t   uniqt   setproctitlet   resourcet   pwdt   grps   multiprocessing.utilt   EX_OKt
   EX_FAILUREt   EX_UNAVAILABLEt   EX_USAGEt   SYSTEMt   IS_OSXt
   IS_WINDOWSt   pyimplementationt
   LockFailedt	   get_fdmaxt   Pidfilet   create_pidlockt   close_open_fdst   DaemonContextt   detachedt	   parse_uidt	   parse_gidt	   setgroupst
   initgroupst   setgidt   setuidt   maybe_drop_privilegest   signalst   set_process_titlet   set_mp_process_titlet   get_errno_namet   ignore_errnot
   fd_by_pathiE   i@   t   EX_CANTCREATiI   t   Darwint   Windowst   /i   i   sL   ERROR: Pidfile ({0}) already exists.
Seems we're already running? (pid: {1})t   _ranget   startt   stopt   C_FORCE_ROOTs>  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}
s   You are running the worker with superuser privileges, which is
absolutely not recommended!

Please specify a different user using the -u option.

User information: uid={uid} euid={euid} gid={gid} egid={egid}
c          C@ s   t  t d  r t j   St j j d  r6 d t j St  t d  r d j d   t j d  D  }  t j d r |  d d	 j d
   t j d D  7}  n  d |  Sd Sd S(   s<   Return string identifying the current Python implementation.t   python_implementationt   javas   Jython t   pypy_version_infot   .c         s@ s   |  ] } t  |  Vq d  S(   N(   t   str(   t   .0t   p(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>d   s    i   t   -t    c         s@ s   |  ] } t  |  Vq d  S(   N(   R;   (   R<   R=   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>f   s    s   PyPy t   CPythonN(   t   hasattrt	   _platformR7   t   syst   platformt
   startswitht   joinR9   (   t   v(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   ]   s    
 +c           B@ s   e  Z d  Z RS(   s&   Raised if a pidlock can't be acquired.(   t   __name__t
   __module__t   __doc__(    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   l   s   c         C@ sX   y t  j d  SWn n Xt d k r+ |  St j t j  d } | t j k rT |  S| S(   s   Return the maximum number of open file descriptors
    on this system.

    :keyword default: Value returned if there's no file
                      descriptor limit.

    t   SC_OPEN_MAXi   N(   t   ost   sysconfR   t   Nonet	   getrlimitt   RLIMIT_NOFILEt   RLIM_INFINITY(   t   defaultt   fdmax(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   p   s    c           B@ sh   e  Z d  Z d	 Z d   Z d   Z e Z d   Z d   Z	 e	 Z
 d   Z d   Z d   Z d   Z RS(
   s   Pidfile

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

    TIP: Use the :func:`create_pidlock` function instead,
    which is more convenient and also removes stale pidfiles (when
    the process holding the lock is no longer running).

    c         C@ s   t  j j |  |  _ d  S(   N(   RL   t   patht   abspath(   t   selfRT   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   __init__   s    c         C@ sN   y |  j    Wn9 t k
 rI } t t t t |   t j   d  n X|  S(   s   Acquire lock.i   (   t	   write_pidt   OSErrorR   R   R;   RC   t   exc_info(   RV   t   exc(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   acquire   s
    *c         C@ s   t  j j |  j  S(   s#   Return true if the pid lock exists.(   RL   RT   t   exists(   RV   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt	   is_locked   s    c         G@ s   |  j    d S(   s   Release lock.N(   t   remove(   RV   t   args(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   release   s    c         C@ s   t  d   t |  j d  z } | j   } | j   | k rX t d j |     n  y t | j    SWn& t k
 r t d j |     n XWd QXWd QXd S(   s    Read and return the current pid.t   ENOENTt   rs#   Partial or invalid pidfile {0.path}s"   pidfile {0.path} contents invalid.N(   R-   t   openRT   t   readlinet   stript
   ValueErrort   formatt   int(   RV   t   fht   line(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   read_pid   s    c         C@ s0   t  t j t j   t j |  j  Wd QXd S(   s   Remove the lock.N(   R-   t   errnoRb   t   EACCESRL   t   unlinkRT   (   RV   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR_      s    c         C@ s   y |  j    } Wn1 t k
 rC } t d d t j |  j   t SX| sX |  j   t Sy t j | d  WnI t j	 k
 r } | j
 t
 j k r t d d t j |  j   t Sn Xt S(   sU   Remove the lock if the process is not running.
        (does not respond to signals).s"   Broken pidfile found. Removing it.t   filei    s"   Stale pidfile exists. Removing it.(   Rl   Rg   t   printRC   t   stderrR_   t   TrueRL   t   killt   errorRm   t   ESRCHt   False(   RV   t   pidR[   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   remove_if_stale   s"    


c         C@ s   t  j   } d j |  } t  j |  j t t  } t  j | d  } z@ | j |  | j	   y t  j
 |  Wn t k
 r n XWd  | j   Xt |  j  } z% | j   | k r t d   n  Wd  | j   Xd  S(   Ns   {0}
t   ws7   Inconsistency: Pidfile content doesn't match at re-read(   RL   t   getpidRh   Rd   RT   t   PIDFILE_FLAGSt   PIDFILE_MODEt   fdopent   writet   flusht   fsynct   AttributeErrort   closet   readR   (   RV   Rx   t   contentt
   pidfile_fdt   pidfilet   rfh(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyRX      s$    
N(   RH   RI   RJ   RN   RT   RW   R\   t	   __enter__R^   Ra   t   __exit__Rl   R_   Ry   RX   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR      s   								c         C@ s    t  |   } t j | j  | S(   s  Create and verify pidfile.

    If the pidfile already exists the program exits with an error message,
    however if the process it refers to is not 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: :class:`Pidfile`.

    **Example**:

    .. code-block:: python

        pidlock = create_pidlock('/var/run/app.pid')

    (   t   _create_pidlockt   atexitt   registerRa   (   R   t   pidlock(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR      s    c         C@ sg   t  |   } | j   rY | j   rY t t j |  | j    d t j t	 t
   n  | j   | S(   NRp   (   R   R^   Ry   Rq   t	   PIDLOCKEDRh   Rl   RC   Rr   t
   SystemExitR/   R\   (   R   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR     s    %
c         @ s   t      xp |  D]h } y t j | t j  } Wn t k
 rE q n Xz!   j t j |  d d ! Wd t j |  Xq W  f d   } g  t t	 d   D] } | |  r | ^ q S(   sN  Return a list of fds.

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

    :keyword paths: List of file paths go get fd for.

    :returns: :list:.

    **Example**:

    .. code-block:: python

        keep = fd_by_path(['/dev/urandom',
                           '/my/precious/'])
    i   i   Nc         @ s7   y t  j |   d d !  k SWn t k
 r2 t SXd  S(   Ni   i   (   RL   t   fstatRY   Rw   (   t   fd(   t   stats(    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   fd_in_stats*  s    i   (
   t   setRL   Rd   t   O_RDONLYRY   t   addR   R   R
   R   (   t   pathsRT   R   R   t   _fd(    (   R   s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR.     s    	!t
   closerangec         C@ s   t  t t d   t t |  p g   D    }  t d d  } t d g |   t |  | g  } } xD t | |  D]3 \ } } | d | k rw t j	 | d |  qw qw Wd  S(   Nc         s@ s!   |  ] } | d  k	 r | Vq d  S(   N(   RN   (   R<   t   f(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>8  s    RR   i   ii   (
   t   listR   t   sortedt   mapR   R   t   iterR   RL   R   (   t   keept   maxfdt   kLt   kHt   lowt   high(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   5  s    	('c         C@ s   g  |  p g  D]$ } t  |  d  k	 r t  |  ^ q }  xU t t t d d    D]8 } | |  k rS t t j   t j	 |  Wd  QXqS qS Wd  S(   NRR   i   (
   R   RN   t   reversedR
   R   R-   Rm   t   EBADFRL   R   (   R   R   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   B  s    4"c           B@ sY   e  Z e Z d d d e d e d   Z d   Z d   Z e Z	 d   Z
 e
 Z d   Z RS(   c         K@ s   t  | t  r6 t | | j d  r* d n d  } n  | p? t |  _ | |  _ | |  _ | |  _ | |  _	 t
 j t
 j t
 j f |  _ d  S(   Nt   0i   i
   (   t
   isinstanceR   Ri   RE   t   DAEMON_WORKDIRt   workdirt   umaskt   faket   after_chdirt   after_forkersRC   t   stdint   stdoutRr   t   stdfds(   RV   R   R   R   R   R   R   t   kwargs(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyRW   N  s    '				c         C@ s;   | d  k	 r7 t j t j t j  } t j | |  n  d  S(   N(   RN   RL   Rd   t   devnullt   O_RDWRt   dup2(   RV   R   t   dest(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   redirect_to_null[  s    c         C@ s   |  j  s |  j s |  j   n  t j |  j  |  j d  k	 rQ t j |  j  n  |  j rg |  j   n  |  j s t	 |  j
  t d g  } t |  x$ |  j
 D] } |  j t |   q W|  j r t d  k	 r t j   q n  t |  _  n  d  S(   Ns   /dev/urandom(   t   _is_openR   t   _detachRL   t   chdirR   R   RN   R   R   R   R.   R   R   R   R   t   mputilt   _run_after_forkersRs   (   RV   R   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyRd   `  s     				
c         G@ s   |  j  r t |  _  n  d  S(   N(   R   Rw   (   RV   R`   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   y  s    	c         C@ sR   t  j   d k rA t  j   t  j   d k rN t  j d  qN n t  j d  |  S(   Ni    (   RL   t   forkt   setsidt   _exit(   RV   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   ~  s    
N(   RH   RI   Rw   R   RN   Rs   RW   R   Rd   R   R   R   R   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR    K  s   				c   	   	   @ s   t  s t d   n  | d
 k r- t j   n | } t j d  t d | d |     f d   } t d | d | d | d	 |  S(   so  Detach the current process in the background (daemonize).

    :keyword logfile: Optional log file.  The ability to write to this file
       will be verified before the process is detached.
    :keyword pidfile: Optional pidfile.  The pidfile will not 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.
    :keyword uid: Optional user id or user name to change
      effective privileges to.
    :keyword gid: Optional group id or group name to change effective
      privileges to.
    :keyword umask: Optional umask that will be effective in the child process.
    :keyword workdir: Optional new working directory.
    :keyword fake: Don't actually detach, intented for debugging purposes.
    :keyword \*\*opts: Ignored.

    **Example**:

    .. code-block:: python

        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 is not locked.
            pidlock = create_pidlock('/var/run/app.pid')

            # Run the program
            program.run(logfile='/var/log/app.log')

    s&   This platform does not support detach.t   SIGCLDt   uidt   gidc           @ s6     o t    d  j    r2 t   j   n  d  S(   Nt   a(   Rd   R   R   Ra   (    (   t   logfileR   (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   after_chdir_do  s    R   R   R   R   N(	   R   t   RuntimeErrorRN   RL   t   getcwdR)   t   resetR(   R    (	   R   R   R   R   R   R   R   t   optsR   (    (   R   R   s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR!     s    $c         C@ si   y t  |   SWnT t k
 rd y t j |   j SWqe t t f k
 r` t d j |     qe Xn Xd S(   s   Parse user id.

    uid can be an integer (uid) or a string (user name), if a user name
    the uid is taken from the system user registry.

    s   User does not exist: {0}N(   Ri   Rg   R   t   getpwnamt   pw_uidR   t   KeyErrorRh   (   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR"     s    c         C@ si   y t  |   SWnT t k
 rd y t j |   j SWqe t t f k
 r` t d j |     qe Xn Xd S(   s   Parse group id.

    gid can be an integer (gid) or a string (group name), if a group name
    the gid is taken from the system group registry.

    s   Group does not exist: {0}N(   Ri   Rg   R   t   getgrnamt   gr_gidR   R   Rh   (   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR#     s    c         C@ s   |  }  x y t  j |   SWq
 t k
 rQ t |   d k rC   n  |  d  |  (q
 t k
 r } | j t j k s t |   d k r   n  |  d  |  (q
 Xq
 Wd S(   s   :fun:`setgroups` may have a platform-dependent limit,
    and it is not always possible to know in advance what this limit
    is, so we use this ugly hack stolen from glibc.i   iN(   RL   R$   Rg   t   lenRY   Rm   t   EINVAL(   t   groupsR[   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   _setgroups_hack  s    $c         @ s   d } y t j d  } Wn t k
 r, n Xy t   |   SWnS t k
 r } | j t j k ri   n  t   f d   t j	   D  r   q n Xd S(   s+   Set active groups from a list of group ids.t   SC_NGROUPS_MAXc         3@ s   |  ] } |   k Vq d  S(   N(    (   R<   t   group(   R   (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>  s    N(
   RN   RL   RM   t	   ExceptionR   RY   Rm   t   EPERMt   anyt	   getgroups(   R   t
   max_groupsR[   (    (   R   s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR$     s    "c         C@ s{   t  s
 d St  j |   d } t t d  r< t j | |  Sg  t j   D] } | | j k rI | j ^ qI } t	 |  d S(   sP   Compat version of :func:`os.initgroups` which was first
    added to Python 2.7.Ni    R%   (
   R   t   getpwuidRA   RL   R%   R   t   getgrallt   gr_memR   R$   (   R   R   t   usernamet   grR   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR%     s    c         C@ s   t  j t |    d S(   s4   Version of :func:`os.setgid` supporting group names.N(   RL   R&   R#   (   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR&     s    c         C@ s   t  j t |    d S(   s2   Version of :func:`os.setuid` supporting usernames.N(   RL   R'   R"   (   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR'     s    c         C@ sj  t  j d k r d St j   r= t j   s= t d   q= n  |  oL t |   }  | o^ t |  } |  r | r t r t j	 |   j
 } n  t |  t |  |  t |   y t d  Wn. t k
 r } t |  t j k r   q qXt d   n | ot |  |  r7t j   r7t j   r7t d   n  | rft j   rft j   rft d   n  d S(   s   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.

    t   win32Ns   contact supporti    s6   non-root user able to restore privileges after setuid.s%   Still root uid after drop privileges!s%   Still root gid after drop privileges!(   RC   RD   RL   t   geteuidt   getuidt   AssertionErrorR"   R#   R   R   t   pw_gidR&   R%   R'   RY   R   Rm   R   R   t   getgidt   getegid(   R   R   R[   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR(     s4    

  t   Signalsc           B@ s   e  Z d  Z e j Z e j Z e e d  r9 d   Z	 n: y d d l
 m Z Wn e k
 ri d   Z	 n
 Xd   Z	 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d d  Z RS(   si  Convenience interface to :mod:`signals`.

    If the requested signal is not supported on the current platform,
    the operation will be ignored.

    **Examples**:

    .. code-block:: python

        >>> 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)

    t	   setitimerc         C@ s   t  j t  j |  d  S(   N(   t   _signalR   t   ITIMER_REAL(   RV   t   seconds(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt	   arm_alarm}  s    i    (   t   alarmc         C@ s   t  j t j |   d  S(   N(   R   R   t   matht   ceil(   RV   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR     s    c         C@ s
   t  |  S(   N(   t   _itimer_alarm(   RV   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR     s    c         C@ s   t  j d  S(   Ni    (   R   R   (   RV   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   reset_alarm  s    c         C@ s)   y |  j  |  SWn t k
 r$ n Xd S(   s=   Return true value if ``signal_name`` exists on this platform.N(   t   signumR   (   RV   t   signal_name(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt	   supported  s    c         C@ sk   t  | t j  r | St  | t  s3 | j   rB t d   n  | j d  s^ d | } n  t t |  S(   s#   Get signal number from signal name.s%   signal name must be uppercase string.t   SIG(	   R   t   numberst   IntegralR   t   isuppert	   TypeErrorRE   t   getattrR   (   RV   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR     s    c         @ s!     j    f d   | D  d S(   s   Reset signals to the default signal handler.

        Does nothing if the platform doesn't support signals,
        or the specified signal in particular.

        c         3@ s   |  ] } |   j  f Vq d  S(   N(   RR   (   R<   t   sig(   RV   (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>  s    N(   t   update(   RV   t   signal_names(    (   RV   s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR     s    c         @ s!     j    f d   | D  d S(   s   Ignore signal using :const:`SIG_IGN`.

        Does nothing if the platform doesn't support signals,
        or the specified signal in particular.

        c         3@ s   |  ] } |   j  f Vq d  S(   N(   t   ignored(   R<   R   (   RV   (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>  s    N(   R   (   RV   R   (    (   RV   s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   ignore  s    c         C@ s   t  j |  j |   S(   N(   R   t	   getsignalR   (   RV   R   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   __getitem__  s    c         C@ s;   y t  j |  j |  |  Wn t t f k
 r6 n Xd S(   s   Install signal handler.

        Does nothing if the current platform doesn't support signals,
        or the specified signal in particular.

        N(   R   t   signalR   R   Rg   (   RV   R   t   handler(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   __setitem__  s    c         K@ s:   x3 t  t | p i  |   D] \ } } | |  | <q Wd S(   s#   Set signal handlers from a mapping.N(   R	   t   dict(   RV   t   _d_t   sigmapR   R  (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR     s    (N(   RH   RI   RJ   R   t   SIG_IGNR   t   SIG_DFLRR   RA   R   t   itimerR   R   t   ImportErrorR   R   R   R   R   R  R  RN   R   (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR   Q  s$   %												c         C@ sC   d |  d k r d n d } t  |   | k r? d j |  |  Sd S(   Nt   managei    i   i   t    R?   (   R   RF   (   t   argvt	   arg_start(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   strargv  s    c         C@ sM   d j  |   } | r' d j  | |  n | } t rI t j t |   n  | S(   sm   Set the ps name for the currently running process.

    Only works if :mod:`setproctitle` is installed.

    s   [{0}]s   {0} {1}(   Rh   t   _setproctitleR   R   (   t   prognamet   infot	   proctitle(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR*     s
    t   NOSETPSc          O@ s   d  S(   N(    (   R   t   k(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR+     s    c         C@ s=   | r d j  |  |  }  n  t d j  |  t   j  d | S(   sz   Set the ps name using the multiprocessing process name.

        Only works if :mod:`setproctitle` is installed.

        s   {0}: {1}s   {0}:{1}R  (   Rh   R*   R   t   name(   R  R  t   hostname(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR+     s    c         C@ s    t  |  t  r t t |   S|  S(   s&   Get errno for string, e.g. ``ENOENT``.(   R   R   R   Rm   (   t   n(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR,     s    c          o@ s   | j  d  p t f } g  |  D] } t |  ^ q }  y	 d VWn= | k
 r } t | d  sg   n  | j |  k r   q n Xd S(   s  Context manager to ignore specific POSIX error codes.

    Takes a list of error codes to ignore, which 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

    :keyword types: A tuple of exceptions to ignore (when the errno matches),
                    defaults to :exc:`Exception`.
    t   typesNRm   (   t   getR   R,   RA   Rm   (   t   errnosR   R  Rm   R[   (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyR-     s    	c         C@ s  t  t d  r t j   n d } t  t d  r< t j   n d } t  t d  r] t j   n d } t  t d  r~ t j   n d } t  t d  r t d   d d d d g D  s t d   q n  | s | s | s | rd	 |  k s d
 |  k rMt sMz5 t	 t
 j d | d | d | d |  d t j Wd  t j d  XqMn  t j t t j d | d | d | d |    n  d  S(   NR   i  R   R   R   t   fchownc         s@ s   |  ] } t  t |  Vq d  S(   N(   RA   RL   (   R<   t   attr(    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pys	   <genexpr>  s   s$   suspicious platform, contact supportt   pickles   application/x-python-serializeR   t   euidR   t   egidRp   i   (   RA   RL   R   R   R   R   t   allR   R6   Rq   t   ROOT_DISALLOWEDRh   RC   Rr   R   t   warningst   warnt   RuntimeWarningt   ROOT_DISCOURAGED(   t   accept_contentR   R   R   R!  (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   check_privileges  s&    !!!!	(   R4   R5   (l   RJ   t
   __future__R    R   R   Rm   R   R   RL   RD   RB   R  R   RC   R$  t   collectionsR   t   billiardR   t   kombu.utilsR   t   kombu.utils.compatR   t   kombu.utils.encodingR   t
   contextlibR   t   localR   t   fiveR	   R
   R   R   R   t   utils.functionalR   R  R   R   R   R   t   __all__R   R   R   R   R   R/   t   systemR   R   R   R   t   O_CREATt   O_EXCLt   O_WRONLYR|   t   R_OKt   W_OKR}   R   R3   t   environR  Rw   R6   R#  R'  R   R   R   RN   R   t   objectR   t   PIDFileR   R   R.   RA   R   R    R!   R"   R#   R   R$   R%   R&   R'   R(   R   R)   R   t
   get_signalR  t   install_signal_handlerR   t   reset_signalR   t   ignore_signalR  R*   R+   R,   R-   R)  (    (    (    s2   /tmp/pip-unpacked-wheel-gV1wwp/celery/platforms.pyt   <module>	   s   (				&
		e				%	=7							6u							