
[XMc           @   sv  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 m	 Z	 m
 Z
 m Z m Z 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 d  d	 l m Z d  d
 l m Z d  d l m  Z  d  d l m! Z! d e" f d     YZ# d e# f d     YZ$ d e# f d     YZ% d e# f d     YZ& d e" f d     YZ' d e" f d     YZ( d   Z) d d d  Z+ d   Z, d   Z- d e" f d     YZ. d   Z/ d    Z0 d! d- d"     YZ1 d# e
 j2 e1 f d$     YZ3 d%   Z4 d&   Z5 e e d' d( d) d*   e5  Z5 d+   Z6 d,   Z7 d S(.   iN(   t   runtimet   logt   usaget   failuret   utilt   logfile(   t   Version(   t   qual(   t
   deprecated(   t   ILogObserver(   t   sob(   t   servicet   reactors(   t   defer(   t	   copyright(   t   installReactor(   t   NoSuchReactort   _BasicProfilerc           B   s    e  Z d  Z d   Z d   Z RS(   s   
    @ivar saveStats: if C{True}, save the stats information instead of the
        human readable format
    @type saveStats: C{bool}

    @ivar profileOutput: the name of the file use to print profile data.
    @type profileOutput: C{str}
    c         C   s   | |  _  | |  _ d  S(   N(   t   profileOutputt	   saveStats(   t   selfR   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   __init__!   s    	c         C   s*   d | | f } | d 7} t  |   d S(   s   
        Helper method to report an import error with a profile module. This
        has to be explicit because some of these modules are removed by
        distributions due to them being non-free.
        s   Failed to import module %s: %ss   
This is most likely caused by your operating system not including
the module due to it being non-free. Either do not use the option
--profile, or install the module; your operating system vendor
may provide it in a separate package.
N(   t
   SystemExit(   R   t   modulet   et   s(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   _reportImportError&   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR      s   	t   ProfileRunnerc           B   s   e  Z d  Z d   Z RS(   s1   
    Runner for the standard profile module.
    c         C   s   y d d l  } Wn# t k
 r5 } |  j d |  n X| j   } | j | j  |  j rn | j |  j  nN t	 j
 t |  j d  } t	 _
 z | j   Wd | t	 j
 t	 _
 } | j   Xd S(   s:   
        Run reactor under the standard profiler.
        iNt   profilet   a(   R   t   ImportErrorR   t   Profilet   runcallt   runR   t
   dump_statsR   t   syst   stdoutt   opent   print_statst   close(   R   t   reactorR   R   t   pt   tmp(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR$   <   s    	(   R   R   R   R$   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR   7   s   t   HotshotRunnerc           B   s   e  Z d  Z d   Z RS(   s0   
    Runner for the hotshot profile module.
    c         C   s0  y d d l  } Wn) t t f k
 r; } |  j d |  n X| j |  j  } | j | j  |  j rk d S| j	 j
 |  j  } | j   | j d  t | d d  d k	 r t |  j d  | _ | j   | j j   nN t j t |  j d  } t _ z | j   Wd | t j t _ } | j   Xd S(   s9   
        Run reactor under the hotshot profiler.
        iNt   hotshott   streamt   w(   t   hotshot.statsR!   R   R   R"   R   R#   R$   R   t   statst   loadt
   strip_dirst
   sort_statst   getattrt   NoneR(   R0   R)   R*   R&   R'   (   R   R+   R/   R   R,   R   R-   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR$   X   s(    	

(   R   R   R   R$   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR.   S   s   t   CProfileRunnerc           B   s   e  Z d  Z d   Z RS(   s)   
    Runner for the cProfile module.
    c         C   s   y d d l  } d d l } Wn# t k
 rA } |  j d |  n X| j   } | j | j  |  j rz | j |  j	  nR t
 |  j	 d  } | j | d | } | j   | j d  | j   | j   d S(   s:   
        Run reactor under the cProfile profiler.
        iNt   cProfileR1   R0   (   R:   t   pstatsR!   R   R"   R#   R$   R   R%   R   R(   t   StatsR5   R6   R)   R*   (   R   R+   R:   R;   R   R,   R0   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR$      s    	

(   R   R   R   R$   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR9      s   t   AppProfilerc           B   s2   e  Z d  Z i e d 6e d 6e d 6Z d   Z RS(   s   
    Class which selects a specific profile runner based on configuration
    options.

    @ivar profiler: the name of the selected profiler.
    @type profiler: C{str}
    R   R/   t   cprofilec         C   s   | j  d t  } | j  d d   } | j  d d  j   |  _ |  j |  j k ry |  j |  j | |  } | j |  _ n t d |  j f   d  S(   Nt	   savestatsR   t   profilerR/   s   Unsupported profiler name: %s(   t   gett   FalseR8   t   lowerR@   t	   profilersR$   R   (   R   t   optionsR   R   R@   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR      s    (   R   R   R   R   R.   R9   RD   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR=      s   
t	   AppLoggerc           B   sA   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z	 RS(   s+  
    Class managing logging faciliy of the application.

    @ivar _logfilename: The name of the file to which to log, if other than the
        default.
    @type _logfilename: C{str}

    @ivar _observer: log observer added at C{start} and removed at C{stop}.
    @type _observer: C{callable}
    c         C   s   | j  d d  |  _ d  S(   NR   t    (   RA   t   _logfilename(   R   RE   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR      s    c         C   sT   | j  t d  } | d k r- |  j   } n  | |  _ t j |  j  |  j   d S(   sc  
        Initialize the logging system.

        If an L{ILogObserver} component has been set on C{application}, then
        it will be used as the log observer.  Otherwise a log observer will be
        created based on the command-line options.

        @param application: The application on which to check for an
            L{ILogObserver}.
        N(   t   getComponentR	   R8   t   _getLogObservert	   _observerR   t   startLoggingWithObservert   _initialLog(   R   t   applicationt   observer(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   start   s    	c         C   sW   d d l  m } t j d t j t j t j	   f  t j d t
 | j  f  d S(   s1   
        Print twistd start log message.
        i(   R+   s   twistd %s (%s %s) starting up.s   reactor class: %s.N(   t   twisted.internetR+   R   t   msgR   t   versionR&   t
   executableR    t   shortPythonVersionR   t	   __class__(   R   R+   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyRM      s
    c         C   sJ   |  j  d k s |  j  r% t j } n t j j |  j   } t j |  j S(   sr   
        Create a log observer to be added to the logging system before running
        this application.
        t   -(	   RH   R&   R'   R   t   LogFilet   fromFullPathR   t   FileLogObservert   emit(   R   t   logFile(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyRJ      s    c         C   s<   t  j d  |  j d k	 r8 t  j |  j  d |  _ n  d S(   s0   
        Print twistd stop log message.
        s   Server Shut Down.N(   R   RR   RK   R8   t   removeObserver(   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   stop   s    N(
   R   R   R   R8   RK   R   RP   RM   RJ   R^   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyRF      s   
				c          C   sC   d   }  d   } d   } | t  j _ |  t  j _ | t  j _ d  S(   Nc         S   s;   |  j    |  j   d d l m } | j d | j  d S(   Ni(   R+   i    i   (   t   clear_all_breakst   set_continueRQ   R+   t	   callLaterR^   (   R   t   argR+   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   do_stop  s
    

c         S   s	   d GHd  S(   NsE   stop - Continue execution, then cleanly shutdown the twisted reactor.(    (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt	   help_stop	  s    c         S   s   t  j d  d  S(   Ni    (   t   ost   _exit(   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   set_quit  s    (   t   pdbt   PdbRg   Rc   Rd   (   Rc   Rd   Rg   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   fixPdb   s    			c         C   s  | d k r d d l m } n  y |  d rK | d k	 r | j |  q n~ |  d r | t _ | t _ t j d k r t	 j	 t	 j
 d    t	 j	 t	 j d    n  t   t j | j  n
 | j   WnC |  d r | } n t d	 d
  } t j d |  | j   n Xd S(   sN  
    Start the reactor, using profiling if specified by the configuration, and
    log any error happening in the process.

    @param config: configuration of the twistd application.
    @type config: L{ServerOptions}

    @param oldstdout: initial value of C{sys.stdout}.
    @type oldstdout: C{file}

    @param oldstderr: initial value of C{sys.stderr}.
    @type oldstderr: C{file}

    @param profiler: object used to run the reactor with profiling.
    @type profiler: L{AppProfiler}

    @param reactor: The reactor to use.  If C{None}, the global reactor will
        be used.
    i(   R+   R   t   debugt   posixc          W   s
   t  j   S(   N(   Rh   t	   set_trace(   t   args(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   <lambda>4  s    c          W   s
   t  j   S(   N(   Rh   Rm   (   Rn   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyRo   5  s    t   nodaemons   TWISTD-CRASH.logR    t   fileN(   R8   RQ   R+   R$   R&   R'   t   stderrR    t   platformTypet   signalt   SIGUSR2t   SIGINTRj   Rh   R#   R(   t	   tracebackt	   print_exct   flush(   t   configt	   oldstdoutt	   oldstderrR@   R+   Rq   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   runReactorWithLogging  s*    

		
	c         C   s   |  r t  j  d  Sd  Sd  S(   Ns   Passphrase: (   t   getpassR8   (   t   needed(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   getPassphraseD  s    c         C   s    |  r t  j d  } n d  Sd  S(   Ns   Encryption passphrase: (   R   t   getPasswordR8   (   R   t
   passphrase(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   getSavePassphraseL  s    t   ApplicationRunnerc           B   sP   e  Z d  Z e Z e Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z RS(   s  
    An object which helps running an application based on a config object.

    Subclass me and implement preApplication and postApplication
    methods. postApplication generally will want to run the reactor
    after starting the application.

    @ivar config: The config object, which provides a dict-like interface.

    @ivar application: Available in postApplication, but not
       preApplication. This is the application object.

    @ivar profilerFactory: Factory for creating a profiler object, able to
        profile the application if options are set accordingly.

    @ivar profiler: Instance provided by C{profilerFactory}.

    @ivar loggerFactory: Factory for creating object responsible for logging.

    @ivar logger: Instance provided by C{loggerFactory}.
    c         C   s1   | |  _  |  j |  |  _ |  j |  |  _ d  S(   N(   Rz   t   profilerFactoryR@   t   loggerFactoryt   logger(   R   Rz   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR   m  s    	c         C   sG   |  j    |  j   |  _ |  j j |  j  |  j   |  j j   d S(   s&   
        Run the application.
        N(   t   preApplicationt   createOrGetApplicationRN   R   RP   t   postApplicationR^   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR$   s  s
    

c         C   s    t  |  j | | |  j |  d S(   s   
        Run the reactor with the given configuration.  Subclasses should
        probably call this from C{postApplication}.

        @see: L{runReactorWithLogging}
        N(   R}   Rz   R@   (   R   R+   R{   R|   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   startReactor  s    c         C   s   t     d S(   s   
        Override in subclass.

        This should set up any state necessary before loading and
        running the Application.
        N(   t   NotImplementedError(   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR     s    c         C   s   t     d S(   s   
        Override in subclass.

        This will be called after the application has been loaded (so
        the C{application} attribute will be set). Generally this
        should start the application and run the reactor.
        N(   R   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR     s    c         C   s   |  j  j rY |  j  j |  j  j } | j |  j  j  } t j | j  } | j |  n% t	 |  j  d  } t
 |  j  |  } | S(   s  
        Create or load an Application based on the parameters found in the
        given L{ServerOptions} instance.

        If a subcommand was used, the L{service.IServiceMaker} that it
        represents will be used to construct a service to be added to
        a newly-created Application.

        Otherwise, an application will be loaded based on parameters in
        the config.
        t	   encrypted(   Rz   t
   subCommandt   loadedPluginst   makeServicet
   subOptionsR   t   Applicationt   tapnamet   setServiceParentR   t   getApplication(   R   t   plgt   serRN   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR     s    (   R   R   R   R=   R   RF   R   R   R$   R   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR   T  s   				
	c         C   s/  g  d d d g D]  } |  | r |  | | f ^ q d } | d i d d 6j  | d | d  } } y7 t j d |  t j | | |  } t j d  Wn t k
 r*} d	 | } t | t  r | j d d
 k r | d 7} n  t	 j
 d t j  t j |  t j   t j d | d  n X| S(   Nt   pythont   sourceRq   i    t   picklei   s   Loading %s...s   Loaded.s   Failed to load application: %sRN   sN  
Could not find 'application' in the file. To use 'twistd -y', your .tac
file must create a suitable object (e.g., by calling service.Application())
and store it in a variable named 'application'. twistd loads your .tac file
and scans the global variables for one of this name.

Please read the 'Using Application' HOWTO for details.
s   
(   RA   R   RR   R   t   loadApplicationt	   Exceptiont
   isinstancet   KeyErrorRn   Rw   Rx   R   t   deferrR&   t   exit(   Rz   R   t   tR   t   filenamet   styleRN   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR     s"    7,
"

c          C   s-   d d j  g  t j   D] }  |  j ^ q  S(   Ns   (%s)t    (   t   joinR   t   getReactorTypest	   shortName(   t   r(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   _reactorZshAction  s    t   ReactorSelectionMixinc           B   s<   e  Z d  Z i e d 6Z e j Z d   Z d   Z	 e	 Z
 RS(   s   
    Provides options for selecting a reactor to install.

    If a reactor is installed, the short name which was used to locate it is
    saved as the value for the C{"reactor"} key.
    R+   c         C   sG   x4 t  j   D]& } |  j j d | j | j f  q Wt d   d S(   sE   
        Display a list of possibly available reactor names.
        s       %-4s	%s
i    N(   R   R   t   messageOutputt   writeR   t   descriptionR   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   opt_help_reactors  s    c         C   sz   y t  |  Wn[ t k
 r= d | f } t j |   n9 t k
 rk } d | f } t j |   n X| |  d <d S(   sX   
        Which reactor to use (see --help-reactors for a list of possibilities)
        sc   The specified reactor does not exist: '%s'.
See the list of available reactors with --help-reactorsst   The specified reactor cannot be used, failed with error: %s.
See the list of available reactors with --help-reactorsR+   N(   R   R   R   t
   UsageErrorR   (   R   R   RR   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   opt_reactor  s    	

(   R   R   R   R   t   zsh_actionsR&   R'   R   R   R   t   opt_r(    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR     s   		
	t   ServerOptionsc        
   B   s-  e  Z d  Z d d+ d g d d d g d d d g g Z d	 d
 d+ d g d d d+ d g d d+ d d d j e j  g d d d d g d d d+ d g d d d+ d g d d d d  g g Z d, g Z	 i d! d 6d" d 6d# d 6d$ d 6Z
 d%   Z d&   Z e Z d'   Z d+ d(  Z d)   Z d*   Z e e  Z RS(-   sQ   twistd reads a twisted.application.service.Application out of a file and runs it.R?   sB   save the Stats object rather than the text output of the profiler.t   no_savet   os   do not save state on shutdownR   R   s(   The specified tap/aos file is encrypted.R   t   ls%   log to a specified file, - for stdoutR   R,   s6   Run in profile mode, dumping results to specified fileR@   R/   s!   Name of the profiler to use (%s).s   , Rq   t   fs
   twistd.taps   read the given .tap fileR   t   ys:   read an application from within a Python file (implies -o)R   R   s2   Read an application from a .tas file (AOT format).t   rundirt   dt   .s-   Change to a supplied directory before runnings   _files -g "*.tap"s   _files -g "*.(tac|py)"s   _files -g "*.tas"t   _dirsc         O   s$   t  |  d <t j j |  | |  d  S(   NRk   (   RB   R   t   OptionsR   (   R   R    t   kw(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR   4  s    
c         C   s%   t  j t  t j   t |  d <d S(   s   
        Run the application in the Python Debugger (implies nodaemon),
        sending SIGUSR2 will drop into debugger
        Rk   N(   R   t   setDebuggingt   TrueR   t   startDebugMode(   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt	   opt_debug9  s    
c         C   sI   t  j t j  y d d l } Wn t k
 r4 d SX| j t j  d S(   s   
        Print an insanely verbose log of everything that happens.
        Useful when debugging freezes or locks in complex code.iN(   R&   t   settraceR   t   spewert	   threadingR!   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   opt_spewD  s    c         C   s<   | d  k r% t j d p d g } n  t j j |  |  d  S(   Ni   s   --help(   R8   R&   t   argvR   R   t   parseOptions(   R   RE   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR   P  s    c         C   s$   |  j  s |  d r  t |  d <n  d  S(   NR   R   (   R   R   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   postOptionsV  s    c         #   sp   d d l  m } | j t j  } i  |  _ x> | D]6     |  j   j <  j d    f d     j f Vq2 Wd  S(   Ni(   t   pluginc              s
     j    S(   N(   RE   (    (   t   plug(    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyRo   a  s    (	   t   twistedR   t
   getPluginsR   t   IServiceMakerR   R   R8   R   (   R   R   t   plugins(    (   R   s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   subCommands[  s    	N(   s   files   pythons   source(   R   R   t   longdescR8   t   optFlagsR   R=   RD   t   optParameterst   zsh_mutuallyExclusiveR   R   R   t   opt_bR   R   R   R   t   property(    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR     sD   								

					c         C   sY   |   } y | j    Wn1 t j k
 rJ } | GHd t j d | f GHn X|  |  d  S(   Ns   %s: %si    (   R   R   t   errorR&   R   (   t   runAppR   Rz   t   ue(    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyR$   f  s    	c           C   s   t  i   j   d  S(   N(   RF   RM   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt
   initialLogr  s    t   Twistedi   i   i    c         C   si   t  j |  | |  } t j |  j |  t |  } | rF d  } n  t j |  j d | d |  d  S(   NR   R   (   R   R   R
   t   IPersistablet   setStyleR   R8   t   save(   t   fileint   typeinR   t   fileoutt   typeoutt   encryptRN   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   convertStylex  s    	c         C   sw   d d l  m } t j |   j   | rT t j |   } | j d d | j d  n  | j d d t j |   j	  d  S(   Ni(   R+   t   aftert   shutdownt   before(
   RQ   R+   R   t   IServicet   startServiceR
   R   t   addSystemEventTriggerR   t   stopService(   RN   R   R+   R,   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   startApplication  s    (    (8   R&   Re   Rh   R~   Rw   Rt   t   warningst   twisted.pythonR    R   R   R   R   R   t   twisted.python.versionsR   t   twisted.python.reflectR   t   twisted.python.deprecateR   t   twisted.python.logR	   t   twisted.persistedR
   t   twisted.applicationR   R   RQ   R   R   R   t   twisted.application.reactorsR   R   t   objectR   R   R.   R9   R=   RF   Rj   R8   R}   R   R   R   R   R   R   R   R   R$   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/application/app.pyt   <module>   s>   T. 3G	.		j		1X		!	
