
iNc           @   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 y d d l Z d d l Z Wn e	 k
 r e
 Z Z n Xy d d l Z Wn e	 k
 r d d l Z n Xd 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 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* y d d l m+ Z+ Wn e	 k
 re
 Z+ n Xy d d l m, Z, Wn e	 k
 re
 Z, n! Xd d l- m. Z. d d l- m/ Z/ y d d l0 Z0 Wn e	 k
 rIe
 Z0 n Xy d d l1 Z1 d d l2 Z1 Wn e	 e3 f k
 re
 Z1 n Xy d d l4 Z4 d d l5 Z5 Wn e	 k
 re
 Z5 n Xe6 e d e
  e
 k rd Z7 n e
 Z7 d   Z8 d e9 f d     YZ: d e j; f d     YZ< d e j= f d     YZ> d e j? f d     YZ@ d  e j? f d!     YZA d" e9 f d#     YZB d$ e jC f d%     YZD d& e j? f d'     YZE d( e j? f d)     YZF d* e j? f d+     YZG d, e j? f d-     YZH d. e9 f d/     YZI d0 e j? f d1     YZJ d2   ZK d3   ZL d4 e j? f d5     YZM d6 e j? f d7     YZN d8 e j? f d9     YZO d S(:   sE   
Tests for L{twisted.application.app} and L{twisted.scripts.twistd}.
iN(   t
   implements(   t   verifyObject(   t   unittest(   t   plugin(   t   IServiceMaker(   t   servicet   appt   reactors(   t   twistd(   t   log(   t
   UsageError(   t   ILogObserver(   t   Version(   t   Componentized(   t   Deferred(   t   UserDatabase(   t   syslog(   t   _twistd_unix(   t   UnixApplicationRunner(   t   UnixAppLoggert   setuids5   Platform does not support --uid/--gid twistd options.c            s   t  j t j    } t j t j      t   } | j | | j	 | | j
 | j | j | j      f d   } |  t  d | j  |  t d |  d S(   su  
    Patch L{pwd.getpwnam} so that it behaves as though only one user exists
    and patch L{grp.getgrnam} so that it behaves as though only one group
    exists.

    @param patch: A function like L{TestCase.patch} which will be used to
        install the fake implementations.

    @type user: C{str}
    @param user: The name of the single user which will exist.

    @type uid: C{int}
    @param uid: The UID of the single user which will exist.

    @type group: C{str}
    @param group: The name of the single user which will exist.

    @type gid: C{int}
    @param gid: The GID of the single group which will exist.
    c            sS   t    }   | | j  j  < | | j  j  <t |  } i |   6|  S(   N(   t   listt   indext   gr_namet   gr_gidt   tuple(   t   namet   result(   t   groupt   grentt   gid(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   getgrnamo   s
    t   getpwnamR   N(   t   pwdt   getpwuidt   ost   getuidt   grpt   getgrgidt   getgidR   t   addUsert	   pw_passwdt   pw_gidt   pw_gecost   pw_dirt   pw_shellR    (   t   patcht   usert   uidR   R   t   pwentt   databaseR   (    (   R   R   R   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   patchUserDatabaseN   s    	t   MockServiceMakerc           B   s   e  Z d  Z d Z d   Z RS(   sO   
    A non-implementation of L{twisted.application.service.IServiceMaker}.
    t   ueoac         C   s   | |  _  t j   |  _ |  j S(   se   
        Take a L{usage.Options} instance and return a
        L{service.IService} provider.
        (   t   optionsR   t   Service(   t   selfR6   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   makeService   s    	(   t   __name__t
   __module__t   __doc__t   tapnameR9   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR4   {   s   t   CrippledAppLoggerc           B   s   e  Z d  Z d   Z RS(   s*   
    @see: CrippledApplicationRunner.
    c         C   s   d  S(   N(    (   R8   t   application(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   start   s    (   R:   R;   R<   R@   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR>      s   t   CrippledApplicationRunnerc           B   s&   e  Z d  Z e Z d   Z d   Z RS(   s   
    An application runner that cripples the platform-specific runner and
    nasty side-effect-having code so that we can use it without actually
    running any environment-affecting code.
    c         C   s   d  S(   N(    (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   preApplication   s    c         C   s   d  S(   N(    (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   postApplication   s    (   R:   R;   R<   R>   t   loggerFactoryRB   RC   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRA      s   	t   ServerOptionsTestc           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e d k r d	 Z e e _ e	 _ e
 _ n  d
   Z d   Z RS(   sT   
    Non-platform-specific tests for the pltaform-specific ServerOptions class.
    c            s,  d t  f d     Y} | d   | d   | d    | d         f d   } t j   }  j | j t j  | | _ | j }      g } x~ t | |  D]m \ } } | \ } }	 }
 }  j | | j	   j |	 d   j |
   | j  f  j | | j  q Wd S(	   sh   
        subCommands is built from IServiceMaker plugins, and is sorted
        alphabetically.
        t
   FakePluginc           B   s   e  Z d    Z d   Z RS(   c         S   s'   | |  _  d | |  _ d | |  _ d  S(   Ns   options for s   description of (   R=   t   _optionst   description(   R8   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   __init__   s    	c         S   s   |  j  S(   N(   RG   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR6      s    (   R:   R;   RI   R6   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRF      s   	t   applet   bananat   coconutt   donutc         3   s(    j  |  t    V V V Vd  S(   N(   t   assertEqualR   (   t	   interface(   RL   RJ   R8   RM   RK   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
   getPlugins   s
    N(   t   objectR   t   ServerOptionsRN   t   _getPluginsR   RP   t   subCommandst   zipR=   t   NoneRG   RH   (   R8   RF   RP   t   configRT   t   expectedOrdert
   subCommandt   expectedCommandR   t   shortcutt   parserClasst   documentation(    (   RL   RJ   R8   RM   RK   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_subCommands   s"    			c            s6  d t  f d     Y} | d   | d   | d    | d        f d   } t j   }  j | j t j  | | _ t j   | _  j	 t
 | j d g  | j j    g   xI      f D]5 }    f d	   } | | j  | | j  q W j  t   d
  f  d S(   sP   
        Reactor names are listed alphabetically by I{--help-reactors}.
        t   FakeReactorInstallerc           B   s   e  Z d    Z RS(   c         S   s   d | |  _  d | |  _ d  S(   Ns   name of s   description of (   t	   shortNameRH   (   R8   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRI      s    (   R:   R;   RI   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR_      s   RJ   RK   RL   RM   c           3   s    V V  V Vd  S(   N(    (    (   RM   RL   RK   RJ   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   getReactorTypes   s    s   --help-reactorsc            s*    j  |      j   j |    d  S(   N(   t   assertInt   appendR   (   t   s(   t
   helpOutputR8   t   indexes(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   getIndex   s    s7   reactor descriptions were not in alphabetical order: %rN(   RQ   R   RR   RN   t   _getReactorTypesR   Ra   t   StringIOt   messageOutputt   assertRaisest
   SystemExitt   parseOptionst   getvalueR`   RH   t   sorted(   R8   R_   Ra   RW   t   reactorRg   (    (   RL   RJ   R8   Re   RM   Rf   RK   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_sortedReactorHelp   s*    	c         C   s7   t  j   } d | _ | j   |  j | d t  d S(   sS   
        postOptions should set no_save to True when a subcommand is used.
        R5   t   no_saveN(   R   RR   RY   t   postOptionsRN   t   True(   R8   RW   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&   test_postOptionsSubCommandCausesNoSave   s    	
c         C   s.   t  j   } | j   |  j | d t  d S(   sR   
        If no sub command is used, postOptions should not touch no_save.
        Rr   N(   R   RR   Rs   RN   t   False(   R8   RW   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt(   test_postOptionsNoSubCommandSavesAsUsual
  s    
c         C   sC   t  j   } t |  } x$ t j j D] } |  j | |  q% Wd S(   sq   
        All the profilers that can be used in L{app.AppProfiler} are listed in
        the help output.
        N(   R   RR   t   strR   t   AppProfilert	   profilersRb   (   R8   RW   Re   t   profiler(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_listAllProfilers  s    c         C   s$   t  j   } |  j | d d  d S(   sG   
        The default value for the C{umask} option is C{None}.
        t   umaskN(   R   RR   RN   RV   (   R8   RW   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_defaultUmask  s    c         C   s^   t  j   } | j d d g  |  j | d d  | j d d g  |  j | d d  d S(   sh   
        The value given for the C{umask} option is parsed as an octal integer
        literal.
        s   --umaskt   123R}   iS   t   0123N(   R   RR   Rm   RN   (   R8   RW   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
   test_umask&  s
    c         C   s,   t  j   } |  j t | j d d g  d S(   s   
        If a value is given for the C{umask} option which cannot be parsed as
        an integer, L{UsageError} is raised by L{ServerOptions.parseOptions}.
        s   --umaskt   abcdefN(   R   RR   Rk   R
   Rm   (   R8   RW   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_invalidUmask2  s    s   twistd unix not availablec         C   sb   t  j   } |  j t | j d d g  } |  j | j d j d   |  j d | j d  d S(   sQ   
        C{--logger} with an unimportable module raises a L{UsageError}.
        s   --loggers   no.such.module.I.hopei    se   Logger 'no.such.module.I.hope' could not be imported: 'no.such.module.I.hope' does not name an objects   
N(	   R   RR   Rk   R
   Rm   t
   assertTruet   argst
   startswitht   assertNotIn(   R8   RW   t   e(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&   test_unimportableConfiguredLogObserver?  s    
c         C   sb   t  j   } |  j t | j d d g  } |  j | j d j d   |  j d | j d  d S(   sP   
        C{--logger} with a non-existent object raises a L{UsageError}.
        s   --loggers   twisted.test.test_twistd.FOOBARi    si   Logger 'twisted.test.test_twistd.FOOBAR' could not be imported: 'module' object has no attribute 'FOOBAR's   
N(	   R   RR   Rk   R
   Rm   R   R   R   R   (   R8   RW   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt*   test_badAttributeWithConfiguredLogObserverL  s    
N(   R:   R;   R<   R^   Rq   Ru   Rw   R|   R~   R   R   R   RV   t   msgt   skipR   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRE      s   	+	*	
							t   TapFileTestc           B   s    e  Z d  Z d   Z d   Z RS(   sM   
    Test twistd-related functionality that requires a tap file on disk.
    c         C   sH   |  j    |  _ t |  j d  } t j t j d  |  | j   d S(   sP   
        Create a trivial Application and put it in a tap file on disk.
        t   wbs   Hi!N(   t   mktempt   tapfilet   filet   picklet   dumpR   t   Applicationt   close(   R8   t   f(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   setUp_  s    c         C   sT   t  j   } | j d |  j g  t |  j   } |  j t j |  j	 d  d S(   s   
        Ensure that the createOrGetApplication call that 'twistd -f foo.tap'
        makes will load the Application out of foo.tap.
        s   -fs   Hi!N(
   R   RR   Rm   R   RA   t   createOrGetApplicationRN   R   t   IServiceR   (   R8   RW   R?   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&   test_createOrGetApplicationWithTapFilei  s    (   R:   R;   R<   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   Z  s   	
t   TestLoggerFactoryc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s8   
    A logger factory for L{TestApplicationRunner}.
    c         C   s   | |  _  d  S(   N(   t   runner(   R8   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRI   z  s    c         C   s/   |  j  j j d  t |  j  d  |  j  _ d S(   sC   
        Save the logging start on the C{runner} instance.
        R	   R?   N(   R   t   orderRc   t   hasattrt   hadApplicationLogObserver(   R8   R?   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR@   ~  s    	c         C   s   d S(   s%   
        Don't log anything.
        N(    (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   stop  s    (   R:   R;   R<   RI   R@   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   u  s   			t   TestApplicationRunnerc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s`   
    An ApplicationRunner which tracks the environment in which its methods are
    called.
    c         C   s/   t  j j |  |  g  |  _ t |   |  _ d  S(   N(   R   t   ApplicationRunnerRI   R   R   t   logger(   R8   R6   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRI     s    	c         C   s&   |  j  j d  t |  d  |  _ d  S(   Nt   preR?   (   R   Rc   R   t   hadApplicationPreApplication(   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRB     s    c         C   s&   |  j  j d  t |  d  |  _ d  S(   Nt   postR?   (   R   Rc   R   t   hadApplicationPostApplication(   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRC     s    (   R:   R;   R<   RI   RB   RC   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s   		t   ApplicationRunnerTestc           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z e e _	 d   Z
 e e
 _	 d   Z RS(   sR   
    Non-platform-specific tests for the platform-specific ApplicationRunner.
    c         C   sM   t  j   } t   |  _ i |  j d 6| _ t   | _ d | _ | |  _ d  S(   Nt   test_command(	   R   RR   R4   t   serviceMakert   loadedPluginsRQ   t
   subOptionsRY   RW   (   R8   RW   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    	c         C   sh   t  |  j  } | j   |  j |  j j |  j j d  |  j |  j j t j | j	  j
 d d  d S(   s   
        Ensure that a twistd plugin gets used in appropriate ways: it
        is passed its Options instance, and the service it returns is
        added to the application.
        sK   ServiceMaker.makeService needs to be passed the correct sub Command object.i    sP   ServiceMaker.makeService's result needs to be set as a child of the Application.N(   RA   RW   t   runt   assertIdenticalR   R6   R   R   R   R?   t   services(   R8   t   arunner(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt,   test_applicationRunnerGetsCorrectApplication  s    
	c         C   si   t  |  j  } | j   |  j | j  |  j | j  |  j | j  |  j | j	 d d d g  d S(   s   
        Test thet preApplication and postApplication methods are
        called by ApplicationRunner.run() when appropriate.
        R   R	   R   N(
   R   RW   R   t   assertFalseR   R   R   R   RN   R   (   R8   Rd   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_preAndPostApplication  s    
c            s   |  j  j |  g    d t j f   f d     Y} d t f   f d     Y} |   } t t j |  t t j |  | |  j   } | j	   | | _
 | j   |  j   d d d t | | f d d	 g  d
 S(   s.  
        Assert that given a particular command line, an application is started
        as a particular UID/GID.

        @param argv: A list of strings giving the options to parse.
        @param uid: An integer giving the expected UID.
        @param gid: An integer giving the expected GID.
        t   FakeUnixApplicationRunnerc              s>   e  Z   f d    Z   f d   Z   f d   Z d   Z RS(   c            s     j  d  d  S(   Nt   environment(   Rc   (   R8   t   chroott   rundirt   nodaemonR}   t   pidfile(   t   events(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   setupEnvironment  s    c            s     j  d | | | f  d  S(   Nt
   privileges(   Rc   (   R8   t   euidR0   R   (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   shedPrivileges  s    c            s     j  d  d  S(   NRp   (   Rc   (   R8   Rp   t	   oldstdoutt	   oldstderr(   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   startReactor  s    c         S   s   d  S(   N(    (   R8   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt	   removePID  s    (   R:   R;   R   R   R   R   (    (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s   t   FakeServicec              so   e  Z e e j e j  d Z d Z d Z	 d    Z
 d   Z d   Z   f d   Z   f d   Z d   Z RS(   c         S   s   d  S(   N(    (   R8   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   setName  s    c         S   s   d  S(   N(    (   R8   t   parent(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   setServiceParent  s    c         S   s   d  S(   N(    (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   disownServiceParent  s    c            s     j  d  d  S(   Nt   privilegedStartService(   Rc   (   R8   (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    c            s     j  d  d  S(   Nt   startService(   Rc   (   R8   (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    c         S   s   d  S(   N(    (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   stopService  s    N(   R:   R;   R    R   R   t   IProcessRV   t   processNameR0   R   R   R   R   R   R   R   (    (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s   			R   R   R   R   Rp   N(   RW   Rm   R   t   _SomeApplicationRunnerRQ   R   R   R   R   RB   R?   RC   RN   Rv   (   R8   t   argvR0   R   R   R   R?   R   (    (   R   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt"   _applicationStartsWithConfiguredID  s    		
	
c         C   s;   d } d } |  j  d t |  d t |  g | |  d S(   s  
        L{postApplication} should change the UID and GID to the values
        specified as numeric strings by the configuration after running
        L{service.IService.privilegedStartService} and before running
        L{service.IService.startService}.
        i  i  s   --uids   --gidN(   R   Rx   (   R8   R0   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt.   test_applicationStartsWithConfiguredNumericIDs  s    c         C   sT   d } d } d } d } t  |  j | | | |  |  j d | d | g | |  d S(   s  
        L{postApplication} should change the UID and GID to the values
        specified as user and group names by the configuration after running
        L{service.IService.privilegedStartService} and before running
        L{service.IService.startService}.
        t   fooi  t   bari  s   --uids   --gidN(   R3   R.   R   (   R8   R/   R0   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt+   test_applicationStartsWithConfiguredNameIDs%  s    c         C   sW   t    } t j i t d 6d d 6t d 6 } | j | d d  |  j | j d  d S(   s7   
        L{startReactor} calls L{reactor.run}.
        t   profileR{   t   debugs'   startReactor did not call reactor.run()N(   t   DummyReactorR   R   Rv   R   RV   R   t   called(   R8   Rp   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_startReactorRunsTheReactor6  s    		(   R:   R;   R<   R   R   R   R   R   t
   setuidSkipR   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s   	
			C				t*   UnixApplicationRunnerSetupEnvironmentTestsc           B   s   e  Z d  Z e d k r! d Z n  e   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z RS(   s  
    Tests for L{UnixApplicationRunner.setupEnvironment}.

    @ivar root: The root of the filesystem, or C{unset} if none has been
        specified with a call to L{os.chroot} (patched for this TestCase with
        L{UnixApplicationRunnerSetupEnvironmentTests.chroot ).

    @ivar cwd: The current working directory of the process, or C{unset} if
        none has been specified with a call to L{os.chdir} (patched for this
        TestCase with L{UnixApplicationRunnerSetupEnvironmentTests.chdir).

    @ivar mask: The current file creation mask of the process, or C{unset} if
        none has been specified with a call to L{os.umask} (patched for this
        TestCase with L{UnixApplicationRunnerSetupEnvironmentTests.umask).

    @ivar daemon: A boolean indicating whether daemonization has been performed
        by a call to L{_twistd_unix.daemonize} (patched for this TestCase with
        L{UnixApplicationRunnerSetupEnvironmentTests.
    s   twistd unix not availablec            s     j    _   j    _   j    _ t   _ t j     _   j	 t d   f d      j	 t d   f d      j	 t d   f d      j	 t
 d   j  t i     _ d  S(   NR   c            s   t    d |   S(   Nt   root(   t   setattr(   t   path(   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   <lambda>d  s    t   chdirc            s   t    d |   S(   Nt   cwd(   R   (   R   (   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   e  s    R}   c            s   t    d |   S(   Nt   mask(   R   (   R   (   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   f  s    t	   daemonize(   t   unsetR   R   R   Rv   t   daemonR#   t   getpidt   pidR.   R   R   R   R   (   R8   (    (   R8   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   ^  s    	c            s)   t    _   j t d   f d    d S(   s   
        Indicate that daemonization has happened and change the PID so that the
        value written to the pidfile can be tested in the daemonization case.
        R   c              s     j  d S(   Ni   (   R   (    (   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   q  s    N(   Rt   R   R.   R#   (   R8   (    (   R8   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   k  s    	c         C   s3   |  j  j d d t d d  |  j |  j d  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} changes the root of the
        filesystem if passed a non-C{None} value for the C{chroot} parameter.
        s   /foo/bart   .N(   R   R   Rt   RV   RN   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_chroott  s    c         C   s6   |  j  j d d t d d  |  j |  j |  j  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} does not change the root of
        the filesystem if passed C{None} for the C{chroot} parameter.
        R   N(   R   R   RV   Rt   R   R   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_noChroot}  s    c         C   s3   |  j  j d d t d d  |  j |  j d  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} changes the working directory
        of the process to the path given for the C{rundir} parameter.
        s   /foo/barN(   R   R   RV   Rt   RN   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_changeWorkingDirectory  s    c         C   s0   |  j  j d d t d d  |  j |  j  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} daemonizes the process if
        C{False} is passed for the C{nodaemon} parameter.
        R   N(   R   R   RV   Rv   R   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_daemonize  s    c         C   s0   |  j  j d d t d d  |  j |  j  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} does not daemonize the
        process if C{True} is passed for the C{nodaemon} parameter.
        R   N(   R   R   RV   Rt   R   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_noDaemonize  s    c         C   sg   |  j    } |  j j d d t d |  t |  } t | j    } | j   |  j	 | |  j
  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} writes the process's PID to
        the file specified by the C{pidfile} parameter.
        R   N(   R   R   R   RV   Rt   R   t   intt   readR   RN   R   (   R8   R   t   fObjR   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_nonDaemonPIDFile  s    
c         C   sk   |  j    } |  j j d d t d |  t |  } t | j    } | j   |  j	 | |  j
 d  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} writes the daemonized
        process's PID to the file specified by the C{pidfile} parameter if
        C{nodaemon} is C{False}.
        R   i   N(   R   R   R   RV   Rv   R   R   R   R   RN   R   (   R8   R   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_daemonPIDFile  s    
c         C   s3   |  j  j d d t d d  |  j |  j d  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} changes the process umask to
        the value specified by the C{umask} parameter.
        R   i{   N(   R   R   RV   Rv   RN   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    c         C   s6   |  j  j d d t d d  |  j |  j |  j  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} doesn't change the process
        umask if C{None} is passed for the C{umask} parameter and C{True} is
        passed for the C{nodaemon} parameter.
        R   N(   R   R   RV   Rt   R   R   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_noDaemonizeNoUmask  s    c         C   s3   |  j  j d d t d d  |  j |  j d  d S(   s   
        L{UnixApplicationRunner.setupEnvironment} changes the process umask to
        C{0077} if C{None} is passed for the C{umask} parameter and C{False} is
        passed for the C{nodaemon} parameter.
        R   i?   N(   R   R   RV   Rv   RN   R   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_daemonizedNoUmask  s    N(   R:   R;   R<   R   RV   R   RQ   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   E  s    																				
t*   UnixApplicationRunnerStartApplicationTestsc           B   s,   e  Z d  Z e d k r! d Z n  d   Z RS(   s>   
    Tests for L{UnixApplicationRunner.startApplication}.
    s   twistd unix not availablec      
      s  t  j   } | j d d d d d d d d d	 g	  t j d
  } t |  |  _ g      f d   } |  j t j	 |  j j
  t j	 |   |  j t d |  |  j t d d    |  j t d d    |  j j |  |  j   d d t d d	 g  d S(   s   
        L{UnixApplicationRunner.startApplication} calls
        L{UnixApplicationRunner.setupEnvironment} with the chroot, rundir,
        nodaemon, umask, and pidfile parameters from the configuration it is
        constructed with.
        s
   --nodaemons   --umaskt   0070s   --chroots   /foo/chroots   --rundirs   /foo/rundirs	   --pidfiles   /foo/pidfilet   test_setupEnvironmentc            s      j  | | | | | f  d  S(   N(   t   extend(   R8   R   R   R   R}   R   (   R   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   fakeSetupEnvironment  s    R   R   c          _   s   d  S(   N(   RV   (   t   at   kw(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    t   startApplicationc          _   s   d  S(   N(   RV   (   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    i8   N(   R   RR   Rm   R   R   R   R   RN   t   inspectt
   getargspecR   R.   R   R   Rt   (   R8   R6   R?   R   (    (   R   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s*    N(   R:   R;   R<   R   RV   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s   	t   UnixApplicationRunnerRemovePIDc           B   s5   e  Z d  Z e d k r! d Z n  d   Z d   Z RS(   s7   
    Tests for L{UnixApplicationRunner.removePID}.
    s   twistd unix not availablec         C   sw   t  i   } |  j   } t j |  t j j | d  } t | d  j   | j |  |  j	 t j j
 |   d S(   sp   
        L{UnixApplicationRunner.removePID} deletes the file the name of
        which is passed to it.
        s   foo.pidt   wN(   R   R   R#   t   makedirsR   t   joinR   R   R   R   t   exists(   R8   R   R   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_removePID  s    c         C   s_   t  i   } | j d  |  j t  } |  j t |  d  |  j | d j j t j  d S(   sr   
        Calling L{UnixApplicationRunner.removePID} with a non-existent filename logs
        an OSError.
        t   fakepidi   i    N(	   R   R   t   flushLoggedErrorst   OSErrorRN   t   lent   valuet   errnot   ENOENT(   R8   R   t   errors(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_removePIDErrors  s
    N(   R:   R;   R<   R   RV   R   R  R  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s
   		R   c           B   s   e  Z d  Z e Z d   Z RS(   s   
    A dummy reactor, only providing a C{run} method and checking that it
    has been called.

    @ivar called: if C{run} has been called or not.
    @type called: C{bool}
    c         C   s%   |  j  r t d   n  t |  _  d S(   sV   
        A fake run method, checking that it's been called one and only time.
        s   Already calledN(   R   t   RuntimeErrorRt   (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   3  s    	(   R:   R;   R<   Rv   R   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   )  s   t   AppProfilingTestCasec           B   sU  e  Z d  Z d   Z e d k r- d e _ n  d   Z d   Z e d k rW d e _ n  d   Z	 d   Z
 e d k r d e
 _ n  d   Z e d k r d e _ n  d	   Z e d k r d e _ n  d
   Z d   Z e d k r d e _ n  d   Z e d k rd e _ n  d   Z e d k r/d e _ n  d   Z d   Z d   Z d   Z RS(   s'   
    Tests for L{app.AppProfiler}.
    c         C   s   t  j   } |  j   | d <d | d <t j |  } t   } | j |  |  j | j  t	 | d  j
   } |  j d |  |  j d |  d S(   s   
        L{app.ProfileRunner.run} should call the C{run} method of the reactor
        and save profile data in the specified file.
        R   R{   s   DummyReactor.runs   function callsN(   R   RR   R   R   Ry   R   R   R   R   R   R   Rb   (   R8   RW   R{   Rp   t   data(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_profileB  s    
	s   profile module not availablec         C   sq   t  j    } |  j t d |  } | |  } | j   | j   | j   } |  j d |  |  j d |  d  S(   Nt   stdouts   function callss   (run)(   Ri   R.   t   syst   print_statst   restoreRn   Rb   (   R8   t
   statsClassR   t   outR  t   statsR  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
   _testStatsX  s    

c         C   s   t  j   } |  j   | d <d | d <t | d <t j |  } t   } | j |  |  j | j	  |  j
 t j | d  d S(   s   
        With the C{savestats} option specified, L{app.ProfileRunner.run}
        should save the raw stats object instead of a summary output.
        R   R{   t	   savestatsN(   R   RR   R   Rt   R   Ry   R   R   R   R   R  t   pstatst   Stats(   R8   RW   R{   Rp   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_profileSaveStatsj  s    

	c         C   s   t  j j   } t j   } d | d <t j |  } d t  j d <z |  j t	 | j
 d  Wd t  j j   t  j j |  Xd S(   s   
        When the C{profile} module is not present, L{app.ProfilerRunner.run}
        should raise a C{SystemExit} exception.
        R   R{   N(   R  t   modulest   copyR   RR   R   Ry   RV   Rk   Rl   R   t   cleart   update(   R8   t   savedModulesRW   R{   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_withoutProfile  s    
c         C   s   d t  j f d     Y} |  j t  d |  t j   } |  j   | d <d | d <t j |  } t   } t	 j
 } |  j t | j |  |  j t	 j
 |  d S(   s   
        When an error happens during the print of the stats, C{sys.stdout}
        should be restored to its initial value.
        t   ErroneousProfilec           B   s   e  Z d    Z RS(   c         S   s   t  d   d  S(   Nt   Boom(   R  (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR    s    (   R:   R;   R  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR#    s   t   ProfileR   R{   N(   R   R%  R.   R   RR   R   R   Ry   R   R  R  Rk   R  R   R   (   R8   R#  RW   R{   Rp   t	   oldStdout(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_profilePrintStatsError  s    
		c         C   s   t  j   } |  j   | d <d | d <t j |  } t   } | j |  |  j | j  t	 | d  j
   } |  j d |  |  j d |  d S(   s   
        L{app.HotshotRunner.run} should call the C{run} method of the reactor
        and save profile data in the specified file.
        R   t   hotshotR{   R   s   function callsN(   R   RR   R   R   Ry   R   R   R   R   R   R   Rb   (   R8   RW   R{   Rp   R  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_hotshot  s    
	s   hotshot module not availablec         C   s   t  j   } |  j   | d <d | d <t | d <t j |  } t   } | j |  |  j | j	  |  j
 t j j | d  d S(   s   
        With the C{savestats} option specified, L{app.HotshotRunner.run} should
        save the raw stats object instead of a summary output.
        R   R(  R{   R  N(   R   RR   R   Rt   R   Ry   R   R   R   R   R  R(  R  t   load(   R8   RW   R{   Rp   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_hotshotSaveStats  s    

	c         C   s   t  j j   } d t  j d <t j   } d | d <t j |  } z |  j t	 | j
 d  Wd t  j j   t  j j |  Xd S(   s   
        When the C{hotshot} module is not present, L{app.HotshotRunner.run}
        should raise a C{SystemExit} exception and log the C{ImportError}.
        R(  R{   N(   R  R  R  RV   R   RR   R   Ry   Rk   Rl   R   R  R   (   R8   R!  RW   R{   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_withoutHotshot  s    
c         C   s   d t  j f d     Y} |  j t  d |  t j   } |  j   | d <d | d <t j |  } t   } t	 j
 } |  j t | j |  |  j t	 j
 |  d S(   s   
        When an error happens while printing the stats, C{sys.stdout}
        should be restored to its initial value.
        t   ErroneousStatsc           B   s   e  Z d    Z RS(   c         S   s   t  d   d  S(   NR$  (   R  (   R8   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR    s    (   R:   R;   R  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR-    s   R  R   R(  R{   N(   R  R  R.   R   RR   R   R   Ry   R   R  R  Rk   R  R   R   (   R8   R-  RW   R{   Rp   R&  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_hotshotPrintStatsError  s    
		c         C   s   t  j   } |  j   | d <d | d <t j |  } t   } | j |  |  j | j  t	 | d  j
   } |  j d |  |  j d |  d S(   s   
        L{app.CProfileRunner.run} should call the C{run} method of the
        reactor and save profile data in the specified file.
        R   t   cProfileR{   R   s   function callsN(   R   RR   R   R   Ry   R   R   R   R   R   R   Rb   (   R8   RW   R{   Rp   R  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_cProfile  s    
	s   cProfile module not availablec         C   s   t  j   } |  j   | d <d | d <t | d <t j |  } t   } | j |  |  j | j	  |  j
 t j | d  d S(   s   
        With the C{savestats} option specified,
        L{app.CProfileRunner.run} should save the raw stats object
        instead of a summary output.
        R   R/  R{   R  N(   R   RR   R   Rt   R   Ry   R   R   R   R   R  R  R  (   R8   RW   R{   Rp   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_cProfileSaveStats  s    

	c         C   s   t  j j   } d t  j d <t j   } d | d <t j |  } z |  j t	 | j
 d  Wd t  j j   t  j j |  Xd S(   s   
        When the C{cProfile} module is not present,
        L{app.CProfileRunner.run} should raise a C{SystemExit}
        exception and log the C{ImportError}.
        R/  R{   N(   R  R  R  RV   R   RR   R   Ry   Rk   Rl   R   R  R   (   R8   R!  RW   R{   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_withoutCProfile+  s    
c         C   sX   t  j   } |  j   | d <d | d <|  j t t j |  } |  j t |  d  d S(   sq   
        Check that L{app.AppProfiler} raises L{SystemExit} when given an
        unknown profiler name.
        R   t   foobarR{   s!   Unsupported profiler name: foobarN(	   R   RR   R   Rk   Rl   R   Ry   RN   Rx   (   R8   RW   t   error(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_unknownProfiler>  s
    
c         C   s&   t  j i   } |  j | j d  d S(   sT   
        L{app.Profiler} defaults to the hotshot profiler if not specified.
        R(  N(   R   Ry   RN   R{   (   R8   R{   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_defaultProfilerK  s    c         C   s-   t  j i d d 6 } |  j | j d  d S(   se   
        The case of the profiler name passed to L{app.AppProfiler} is not
        relevant.
        t   HotShotR{   R(  N(   R   Ry   RN   R{   (   R8   R{   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_profilerNameCaseInsentiveS  s    N(   R:   R;   R<   R  R   RV   R   R  R  R"  R'  R)  R(  R+  R,  R.  R0  R/  R1  R2  R5  R6  R8  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR  =  s@   														c            s5   g   t  j      f d   } |  t  d |   S(   s  
    Patch L{log.FileLogObserver} to record every call and keep a reference to
    the passed log file for tests.

    @param patch: a callback for patching (usually L{unittest.TestCase.patch}).

    @return: the list that keeps track of the log files.
    @rtype: C{list}
    c            s    j  |     |   S(   N(   Rc   (   t   logFile(   t   oldFileLobObservert   logFiles(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   FileLogObserveri  s    R<  (   R	   R<  (   R.   R<  (    (   R:  R;  s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   _patchFileLogObserver]  s
    
	c            s9   g    d t  f   f d     Y} |  j t d |    S(   su   
    Make fake syslog, and return list to which prefix and then log
    messages will be appended if it is used.
    t   fakesyslogobserverc              s&   e  Z   f d    Z   f d   Z RS(   c            s     j  |  d  S(   N(   Rc   (   R8   t   prefix(   t   logMessages(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRI   x  s    c            s     j  |  d  S(   N(   Rc   (   R8   t	   eventDict(   R@  (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   emitz  s    (   R:   R;   RI   RB  (    (   R@  (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR>  w  s   t   SyslogObserver(   RQ   R.   R   (   t   testCaseR>  (    (   R@  s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   _setupSyslogq  s    t   AppLoggerTestCasec           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z i  e j	 d  Z
 d   Z d   Z d	   Z e d k s~ e d k r d
 e _ n  d   Z d   Z d   Z d   Z RS(   s   
    Tests for L{app.AppLogger}.

    @ivar observers: list of observers installed during the tests.
    @type observers: C{list}
    c            s/   g    _    f d   }   j t d |  d S(   sx   
        Override L{log.addObserver} so that we can trace the observers
        installed in C{self.observers}.
        c            s!     j  j |   t j |   d  S(   N(   t	   observersRc   R	   t   addObserver(   t   observer(   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   startLoggingWithObserver  s    RJ  N(   RG  R.   R	   (   R8   RJ  (    (   R8   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    	c         C   s%   x |  j  D] } t j |  q
 Wd S(   s1   
        Remove all installed observers.
        N(   RG  R	   t   removeObserver(   R8   RI  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   tearDown  s    c         C   sU   |  j  |  j | j g  |  j d | d d d  |  j d | d d d  d S(   s   
        Ensure that initial C{twistd} logs are written to the given list.

        @type logs: C{list}
        @param logs: The list whose C{append} method was specified as the
            initial log observer.
        s   starting upi    t   messages   reactor classi   N(   RN   RG  Rc   Rb   (   R8   t   logs(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   _checkObserver  s    c            sH   t  j i   } g      f d   | _ | j t    |  j    d S(   s   
        L{app.AppLogger.start} calls L{log.addObserver}, and then writes some
        messages about twistd and the reactor.
        c              s     j  S(   N(   Rc   (    (   RI  (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    N(   R   t	   AppLoggert   _getLogObserverR@   R   RO  (   R8   R   (    (   RI  s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
   test_start  s
    c         C   sO   t    } g  } | j t | j  t j i   } | j |  |  j |  d S(   s   
        When the L{ILogObserver} component is available on the application,
        that object will be used as the log observer instead of constructing a
        new one.
        N(   R   t   setComponentR   Rc   R   RP  R@   RO  (   R8   R?   RN  R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt$   test_startUsesApplicationLogObserver  s    	c            sF   g    i   f d   d 6} | j  |  | |  } | j |    S(   s  
        Set up an AppLogger which exercises the C{logger} configuration option.

        @type application: L{Componentized}
        @param application: The L{Application} object to pass to
            L{app.AppLogger.start}.
        @type extraLogArgs: C{dict}
        @param extraLogArgs: extra values to pass to AppLogger.
        @type appLogger: L{AppLogger} class, or a subclass
        @param appLogger: factory for L{AppLogger} instances.

        @rtype: C{list}
        @return: The logs accumulated by the log observer.
        c              s     j  S(   N(   Rc   (    (   RN  (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR     s    R   (   R   R@   (   R8   R?   t   extraLogArgst	   appLoggert   logArgsR   (    (   RN  s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   _setupConfiguredLogger  s    c         C   s#   t    } |  j |  j |   d S(   s  
        When the C{logger} key is specified in the configuration dictionary
        (i.e., when C{--logger} is passed to twistd), the initial log observer
        will be the log observer returned from the callable which the value
        refers to in FQPN form.
        N(   R   RO  RX  (   R8   R?   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt#   test_startUsesConfiguredLogObserver  s    	c         C   sL   g  } t    } | j t | j  |  j |  j |   |  j | g   d S(   sh   
        C{--logger} takes precedence over a ILogObserver component set on
        Application.
        N(   R   RS  R   Rc   RO  RX  RN   (   R8   t   nonlogsR?   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt(   test_configuredLogObserverBeatsComponent  s
    	c         C   sL   t  |   } t   } |  j |  j | i t d 6t   |  j | g   d S(   s`   
        C{--logger} takes precedence over a C{--syslog} command line
        argument.
        R   N(   RE  R   RO  RX  Rt   R   RN   (   R8   RN  R?   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt%   test_configuredLogObserverBeatsSyslog  s    	

s&   Not on POSIX, or syslog not available.c         C   sR   t    } |  j   } |  j |  j | i d d 6  |  j t j j |   d S(   sa   
        C{--logger} takes precedence over a C{--logfile} command line
        argument.
        R   t   logfileN(   R   R   RO  RX  R   R#   R   R  (   R8   R?   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt&   test_configuredLogObserverBeatsLogfile  s
    	c         C   s   t  j i d d 6 } t |  j  } | j   } |  j t |  d  |  j | d t j	  t  j i d d 6 } | j   } |  j t |  d  |  j | d t j	  d S(   s   
        When logfile is empty or set to C{-}, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at C{sys.stdout}.
        t   -R]  i   i    t    i   N(
   R   RP  R=  R.   RQ  RN   R  R   R  R  (   R8   R   R;  RI  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_getLogObserverStdout  s    c         C   sz   t  |  j  } |  j   } t j i | d 6 } | j   } |  j t |  d  |  j | d j t	 j j
 |   d S(   s   
        When passing the C{logfile} option, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at the specified path.
        R]  i   i    N(   R=  R.   R   R   RP  RQ  RN   R  R   R#   t   abspath(   R8   R;  t   filenameR   RI  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_getLogObserverFile#  s    c            s   g    t    }   f d   } |  j t d |  t j i   } | | _ | j   |  j   | g  | j   |  j   | g  |  j | j d  d S(   s   
        L{app.AppLogger.stop} removes the observer created in C{start}, and
        reinitialize its C{_observer} so that if C{stop} is called several
        times it doesn't break.
        c            s     j  |   d  S(   N(   Rc   (   RI  (   t   removed(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   remove;  s    RK  N(
   RQ   R.   R	   R   RP  t	   _observerR   RN   R   RV   (   R8   RI  Rf  R   (    (   Re  s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt	   test_stop3  s    		

N(   R:   R;   R<   R   RL  RO  RR  RT  R   RP  RX  RY  R[  R\  R   RV   R   R   R^  Ra  Rd  Rh  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRF    s"   											t   UnixAppLoggerTestCasec           B   sz   e  Z d  Z e d
 k r! d Z n  d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z e d
 k rx d	 e _ n  RS(   sw   
    Tests for L{UnixAppLogger}.

    @ivar signals: list of signal handlers installed.
    @type signals: C{list}
    s   twistd unix not availablec            s/   g    _    f d   }   j t d |  d S(   ss   
        Fake C{signal.signal} for not installing the handlers but saving them
        in C{self.signals}.
        c            s     j  j |  | f  d  S(   N(   t   signalsRc   (   t   sigR   (   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt
   fakeSignalX  s    t   signalN(   Rj  R.   Rm  (   R8   Rl  (    (   R8   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyR   R  s    	c         C   s   t  |  j  } t i d d 6t d 6 } | j   } |  j t |  d  |  j | d t j	  t i d d 6t d 6 } | j   } |  j t |  d  |  j | d t j	  d S(	   s   
        When non-daemonized and C{logfile} is empty or set to C{-},
        L{UnixAppLogger._getLogObserver} returns a log observer pointing at
        C{sys.stdout}.
        R_  R]  R   i   i    R`  i   N(
   R=  R.   R   Rt   RQ  RN   R  R   R  R  (   R8   R;  R   RI  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRa  ]  s    c         C   sI   t  i d d 6t d 6 } |  j t | j  } |  j t |  d  d S(   s   
        When daemonized and C{logfile} is set to C{-},
        L{UnixAppLogger._getLogObserver} raises C{SystemExit}.
        R_  R]  R   s&   Daemons cannot log to stdout, exiting!N(   R   Rv   Rk   Rl   RQ  RN   Rx   (   R8   R   R4  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_getLogObserverStdoutDaemonp  s    c            s   t  |  j  } |  j   } t i | d 6 } | j   } |  j t |  d  |  j | d j t j j	 |   |  j t |  j
  d  |  j |  j
 d d t j  t       f d   } | | d _ |  j
 d d } | d d    S(   s   
        When C{logfile} contains a file name, L{app.AppLogger._getLogObserver}
        returns a log observer pointing at the specified path, and a signal
        handler rotating the log is installed.
        R]  i   i    c              s     j  d   d  S(   N(   t   callbackRV   (    (   t   d(    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   rotate  s    N(   R=  R.   R   R   RQ  RN   R  R   R#   Rb  Rj  Rm  t   SIGUSR1R   Rq  RV   (   R8   R;  Rc  R   RI  Rq  t	   rotateLog(    (   Rp  s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRd  z  s    	c            sd     f d   }   j  t d |    j   } t i | d 6 } | j   }   j   j g   d S(   sy   
        If a signal handler is already installed,
        L{UnixAppLogger._getLogObserver} doesn't override it.
        c            s     j  |  t j  t   S(   N(   RN   Rm  Rr  RQ   (   Rk  (   R8   (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   fakeGetSignal  s    t	   getsignalR]  N(   R.   Rm  R   R   RQ  RN   Rj  (   R8   Rt  Rc  R   RI  (    (   R8   s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt,   test_getLogObserverDontOverrideSignalHandler  s    c         C   sr   t  |  j  } t i d d 6t d 6 } | j   } |  j t |  d  |  j | d j t j j	 d   d S(   s   
        When daemonized and C{logfile} is empty, the observer returned by
        L{UnixAppLogger._getLogObserver} points at C{twistd.log} in the current
        directory.
        R`  R]  R   i   i    s
   twistd.logN(
   R=  R.   R   Rv   RQ  RN   R  R   R#   Rb  (   R8   R;  R   RI  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_getLogObserverDefaultFile  s    c         C   sw   t  |   } t i t d 6d d 6 } | j   } |  j | d g  | i d d 6 |  j | d i d d 6g  d S(   s   
        If C{syslog} is set to C{True}, L{UnixAppLogger._getLogObserver} starts
        a L{syslog.SyslogObserver} with given C{prefix}.
        R   s   test-prefixR?  t   bR   N(   RE  R   Rt   RQ  RN   (   R8   RN  R   RI  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_getLogObserverSyslog  s    s   Syslog not availableN(   R:   R;   R<   R   RV   R   R   Ra  Rn  Rd  Rv  Rw  Ry  R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRi  H  s   				
				t   DeprecationTestsc           B   s   e  Z d  Z d   Z RS(   s(   
    Tests for deprecated features.
    c         C   s   g  } t  j | j  |  j t  j | j  |  j t d d d d  t j  |  j	 t
 |  d  |  j d | d d d  |  j d | d d d  d	 S(
   s2   
        L{app.initialLog} is deprecated.
        t   Twistedi   i   i    s   starting upRM  s   reactor classi   N(   R	   RH  Rc   t
   addCleanupRK  t   callDeprecatedR   R   t
   initialLogRN   R  Rb   (   R8   RN  (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   test_initialLog  s    "(   R:   R;   R<   R  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyRz    s   (P   R<   Rm  R   R	  R#   R  Ri   R!   R%   t   ImportErrorRV   t   cPickleR   t   zope.interfaceR    t   zope.interface.verifyR   t   twisted.trialR   t   twistedR   t   twisted.application.serviceR   t   twisted.applicationR   R   R   t   twisted.scriptsR   t   twisted.pythonR	   t   twisted.python.usageR
   t   twisted.python.logR   t   twisted.python.versionsR   t   twisted.python.componentsR   t   twisted.internet.deferR   t   twisted.python.fakepwdR   R   R   t   twisted.scripts._twistd_unixR   R   R   R(  t   hotshot.statsRl   R  R/  t   getattrR   R3   RQ   R4   RP  R>   R   RA   t   TestCaseRE   R   R   R   R   R   R   R   R   R   R  R=  RE  RF  Ri  Rz  (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_twistd.pyt   <module>   s   $$




		-
,# !		