ó
Xé?_c           @   s  d  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 m	 Z	 d e	 j
 f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d	 „  ƒ  YZ e i d
 d 6ƒ Z d „  Z d e j f d „  ƒ  YZ e d k rý e j e ƒ n  d S(   s"   Windows service. Requires pywin32.iÿÿÿÿN(   t   wspbust   pluginst   ConsoleCtrlHandlerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s@   A WSPBus plugin for handling Win32 console events (like Ctrl-C).c         C   s    t  |  _ t j j |  | ƒ d  S(   N(   t   Falset   is_setR   t   SimplePlugint   __init__(   t   selft   bus(    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyR      s    	c         C   sŠ   |  j  r# |  j j d d d ƒd  St j |  j d ƒ } | d k rg |  j j d t j ƒ  d d ƒn |  j j d d d ƒt |  _  d  S(   Ns'   Handler for console events already set.t   leveli(   i   i    s*   Could not SetConsoleCtrlHandler (error %r)s   Set handler for console events.(   R   R   t   logt   win32apit   SetConsoleCtrlHandlert   handlet   GetLastErrort   True(   R   t   result(    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   start   s    	c         C   s¨   |  j  s# |  j j d d d ƒd  Sy t j |  j d ƒ } Wn t k
 rU d } n X| d k r… |  j j d t j ƒ  d d ƒn |  j j d d d ƒt |  _  d  S(   Ns'   Handler for console events already off.R	   i(   i    i   s1   Could not remove SetConsoleCtrlHandler (error %r)s#   Removed handler for console events.(	   R   R   R
   R   R   R   t
   ValueErrorR   R   (   R   R   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   stop"   s    	
c         C   su   | t  j t  j t  j t  j t  j f k rq |  j j d | ƒ y |  j ƒ  Wn t	 k
 r_ n X|  j j
 ƒ  d Sd S(   s,   Handle console control events (like Ctrl-C).s#   Console event %s: shutting down busi   i    (   t   win32cont   CTRL_C_EVENTt   CTRL_LOGOFF_EVENTt   CTRL_BREAK_EVENTt   CTRL_SHUTDOWN_EVENTt   CTRL_CLOSE_EVENTR   R
   R   R   t   exit(   R   t   event(    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyR   4   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyR      s
   			t   Win32Busc           B   sP   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e e e ƒ Z d d d „ Z
 RS(   s‚   A Web Site Process Bus implementation for Win32.

    Instead of time.sleep, this bus blocks using native win32event objects.
    c         C   s   i  |  _  t j j |  ƒ d  S(   N(   t   eventsR    t   BusR   (   R   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyR   N   s    	c         C   s`   y |  j  | SWnJ t k
 r[ t j d d d d | j t j ƒ  f ƒ } | |  j  | <| SXd S(   s@   Return a win32event for the given state (creating it if needed).i    s   WSPBus %s Event (pid=%r)N(   R    t   KeyErrort
   win32eventt   CreateEventt   Nonet   namet   ost   getpid(   R   t   stateR   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   _get_state_eventR   s    c         C   s   |  j  S(   N(   t   _state(   R   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt
   _get_state]   s    c         C   s)   | |  _  |  j | ƒ } t j | ƒ d  S(   N(   R+   R*   R#   t
   PulseEvent(   R   t   valueR   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt
   _set_state`   s    	gš™™™™™¹?c         C   s    t  | t t f ƒ rh |  j | k rœ t g  | D] } |  j | ƒ ^ q. ƒ } t j | d t j ƒ qœ n4 |  j | k rœ |  j | ƒ } t j | t j ƒ n  d S(   sª   Wait for the given state(s), KeyboardInterrupt or SystemExit.

        Since this class uses native win32event objects, the interval
        argument is ignored.
        i    N(	   t
   isinstancet   tuplet   listR)   R*   R#   t   WaitForMultipleObjectst   INFINITEt   WaitForSingleObject(   R   R)   t   intervalt   channelt   sR    R   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   waitf   s    (N(   R   R   R   R   R*   R,   R/   t   propertyR)   R%   R9   (    (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyR   G   s   				t   _ControlCodesc           B   s   e  Z d  Z d „  Z RS(   s)  Control codes used to "signal" a service via ControlService.

    User-defined control codes are in the range 128-255. We generally use
    the standard Python value for the Linux signal and add 128. Example:

        >>> signal.SIGUSR1
        10
        control_codes['graceful'] = 128 + 10
    c         C   sA   x* |  j  ƒ  D] \ } } | | k r | Sq Wt d | ƒ ‚ d S(   s2   For the given value, return its corresponding key.s'   The given object could not be found: %rN(   t   itemsR   (   R   t   objt   keyt   val(    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   key_for…   s    (   R   R   R   R@   (    (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyR;   y   s   
iŠ   t   gracefulc         C   sP   | d k r t  j |  ƒ n0 | d k r8 t  j |  ƒ n t  j |  t | ƒ d  S(   NR   t   restart(   t   win32serviceutilt   StopServicet   RestartServicet   ControlServicet   control_codes(   t   servicet   command(    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   signal_child   s
    t   PyWebServicec           B   sM   e  Z d  Z d Z d Z d Z d Z d Z d Z	 d „  Z
 d „  Z d „  Z RS(   s   Python Web Service.s   Python Web Servicet   pywebsvcc         C   s.   d d l  m } | j j ƒ  | j j ƒ  d  S(   Niÿÿÿÿ(   t   process(   t   cherrypyRM   R   R   t   block(   R   RM   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   SvcDoRun¥   s    c         C   s1   d d l  m } |  j t j ƒ | j j ƒ  d  S(   Niÿÿÿÿ(   RM   (   RN   RM   t   ReportServiceStatust   win32servicet   SERVICE_STOP_PENDINGR   R   (   R   RM   (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   SvcStopª   s    c         C   s   t  j j t j | ƒ ƒ d  S(   N(   RM   R   t   publishRG   R@   (   R   t   control(    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   SvcOther¯   s    N(   R   R   R   t
   _svc_name_t   _svc_display_name_R%   t
   _svc_deps_t
   _exe_name_t
   _exe_args_t   _svc_description_RP   RT   RW   (    (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyRK   ˜   s   		t   __main__(   R   R'   R   R   R#   RR   RC   t   cherrypy.processR    R   R   R   R!   R   t   dictR;   RG   RJ   t   ServiceFrameworkRK   R   t   HandleCommandLine(    (    (    s}   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/process/win32.pyt   <module>   s   :2		