ó
ÐH/\c           @   sa  d  d l  j Z d  d l m Z d  d l m Z e j ƒ  d  d l m Z d  d l m	 Z	 y d  d l
 m Z Wn! e k
 r d  d l m Z n Xd e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ g  Z g  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ y d  d l m Z Wn e k
 rÂe Z n Xe j  e e k d ƒ d e j f d  „  ƒ  Yƒ Z! e j" d! ƒ d" e j f d# „  ƒ  Yƒ Z# e j$ d$ ƒ d% e j f d& „  ƒ  Yƒ Z% e& d' k r]e j' ƒ  n  d S((   iÿÿÿÿN(   t   copy(   t   monkey(   t   local(   t   Thread(   t   Mappingt   ReadPropertyc           B   s   e  Z d  Z d „  Z RS(   s!   A property that can be overriddenc         C   s   | d  k	 r d S|  S(   Ni*   (   t   None(   t   selft   instt   klass(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   __get__   s    (   t   __name__t
   __module__t   __doc__R
   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR      s   t   Ac           B   s2   e  Z d  d g Z d Z d Z e ƒ  Z d „  Z RS(   t   initializedt   objt    t   MyPathc         C   s;   t  t |  ƒ j ƒ  t |  d ƒ s. | |  _ n  d |  _ d  S(   NR   R   (   t   superR   t   __init__t   hasattrR   t   path(   R   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR   !   s    (   R   R   t	   __slots__R   t	   type_pathR   t   read_propertyR   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR      s
   	t   Objc           B   s   e  Z RS(    (   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR   (   s   t   Sentinelc           B   s   e  Z d  „  Z RS(   c         C   s   t  j t |  ƒ ƒ d  S(   N(   t   deleted_sentinelst   appendt   id(   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   __del__0   s    (   R   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR   /   s   t   MyLocalc           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   i*   c         C   s3   t  j |  ƒ t ƒ  |  _ t j t |  j ƒ ƒ d  S(   N(   R   R   R   t   sentinelt   created_sentinelsR   R   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR   8   s    c         C   s   |  S(   N(    (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   desc=   s    (   R   R   t
   CLASS_PROPR   t   propertyR#   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR    4   s   	t   MyLocalSubclassc           B   s   e  Z RS(    (   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR&   A   s   t   WithGetattrc           B   s   e  Z d  „  Z RS(   c         C   s&   | d k r d St  t |  ƒ j | ƒ S(   Nt   fooi*   (   R   R'   t   __getattr__(   R   t   name(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR)   F   s    (   R   R   R)   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR'   D   s   t   LocalWithABCc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   |  j  | S(   N(   t   d(   R   R*   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   __getitem__M   s    c         C   s   t  |  j ƒ S(   N(   t   iterR,   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   __iter__P   s    c         C   s   t  |  j ƒ S(   N(   t   lenR,   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   __len__S   s    (   R   R   R-   R/   R1   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR+   K   s   		t   LocalWithStaticMethodc           B   s   e  Z e d  „  ƒ Z RS(   c           C   s   d S(   Ni*   (    (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   a_staticmethodX   s    (   R   R   t   staticmethodR3   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR2   V   s   t   LocalWithClassMethodc           B   s   e  Z e d  „  ƒ Z RS(   c         C   s   |  S(   N(    (   t   cls(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   a_classmethod^   s    (   R   R   t   classmethodR7   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR5   \   s   t   TestGeventLocalc           B   sÔ   e  Z d  „  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z e d „ Z d „  Z d „  Z e j d ƒ d „  ƒ Z e j d „  ƒ Z d „  Z d „  Z d „  Z RS(   c         C   s   t  2t 2d  S(   N(   R   R"   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   setUph   s    c         C   sM   |  j  t d ƒ  t d ƒ Wd  QX|  j  t d ƒ  t d d ƒ Wd  QXd  S(   Ns*   Initialization arguments are not supportedR(   t   kw(   t   assertRaisesRegext	   TypeErrorR   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt$   test_create_local_subclass_init_argsn   s    	
	
c         C   s)   t  ƒ  } d | _ |  j | j d ƒ d  S(   Ni   (   R   t   attrt   assertEqual(   R   t   l(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_local_opts_not_subclassedx   s    		c         C   sH   t  ƒ  } |  j t ƒ  d | _ Wd  QX|  j t ƒ  | ` Wd  QXd  S(   Ni   (   R   t   assertRaisest   AttributeErrort   __dict__(   R   RA   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_cannot_set_delete_dict}   s
    	c            se   t  ƒ  ‰  ˆ j t ƒ  t ˆ  d ƒ Wd  QX‡  ‡ f d †  } t d | ƒ } | j ƒ  | j ƒ  d  S(   Nt   thingc              s'   ˆ j  t ƒ  t ˆ  d ƒ Wd  QXd  S(   NRG   (   RC   RD   t   delattr(    (   RA   R   (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt	   del_localŠ   s    t   target(   R   RC   RD   RH   R   t   startt   join(   R   RI   t   t(    (   RA   R   s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_delete_with_no_dict…   s    	
c            s’  t  t ƒ  ƒ ‰  d ˆ  _ ˆ j ˆ  j d ƒ ‡  ‡ f d †  } t d | ƒ } | j ƒ  | j ƒ  ˆ j ˆ  j d ƒ d ˆ  j d <ˆ j ˆ  j d ƒ ˆ  ` ˆ j t	 ˆ  d ƒ ƒ ˆ j
 d ˆ  j ƒ ˆ  ` ˆ j ˆ  j d ƒ ˆ j t ƒ  ˆ  ` Wd  QXˆ j ˆ  j d ƒ d ˆ  _ ˆ j ˆ  j d ƒ ˆ j t  j t ƒ ˆ j ˆ  j d ƒ ˆ j d	 ˆ  j ƒ d
 ˆ  _ ˆ j ˆ  j d
 ƒ ˆ j
 d	 ˆ  j ƒ d  S(   Ni   c              s    ˆ j  ˆ  j d ƒ d ˆ  _ d  S(   Ni   i   (   R@   R   (    (   t   aR   (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   demonstrate_slots_shared˜   s    RJ   i   i*   R   R   R   R   t   Local(   R   R   R   R@   R   RK   RL   RE   t   assertFalseR   t   assertInR   RC   RD   R   t   assertIsInstanceR   R   t   assertNotIn(   R   RP   t   greenlet(    (   RO   R   s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_slot_and_type_attributes’   s4    	

		c            s‹   t  t ƒ  ƒ ‰  |  j t ƒ  t ˆ  d ƒ Wd  QX‡  f d †  } t d | ƒ } | j ƒ  | j ƒ  |  j t ƒ  t ˆ  d ƒ Wd  QXd  S(   Nt	   fizz_buzzc              s   d ˆ  _  d  S(   Ni   (   RX   (    (   RO   (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   set_fizz_buzzÈ   s    RJ   (   R   R   RC   RD   t   getattrR   RK   RL   (   R   RY   RV   (    (   RO   s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_attribute_errorÂ   s    

c         C   s<   t  ƒ  } |  j d | j ƒ d | _ |  j d | j ƒ d  S(   Ni*   t   baz(   R'   R@   R(   (   R   t   getter(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_getattr_calledÒ   s    		c         C   s­   t  t ƒ  ƒ } d | _ d | j _ t | ƒ } |  j | j | j d ƒ |  j | j | j d ƒ d | _ |  j | j | j d ƒ d | j _ |  j | j | j d ƒ d  S(   Nt   123t   tests+   The values in the two objects must be equals   The values must be equalt   321s/   The values in the two objects must be differentt   works(   R   R   R   R   t   echoR    R@   t   assertNotEqual(   R   RO   t   b(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt	   test_copyÙ   s    		c         C   sR   t  ƒ  } t | d d ƒ t | ƒ } |  j | j d ƒ |  j | j | j ƒ d  S(   NRG   i*   (   R   t   setattrR    R@   RG   t   assertIsNotRE   (   R   RO   Re   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_copy_no_subclassí   s
    	c         C   sp   t  i  ƒ } d | _ t  i d d 6ƒ } d | _ |  j | j | j d ƒ d | _ |  j | j | j d ƒ d  S(   NR_   i   t   ones+   The values in the two objects must be equalRa   s/   The values in the two objects must be different(   R   R   R@   Rd   (   R   RO   Re   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_objectsõ   s    			c         C   s   | ƒ  } |  j  d | j ƒ d | _ |  j  d | j ƒ |  j  | j d d ƒ | ` |  j  d | j ƒ |  j | | j ƒ d  S(   Ni*   i   R$   (   R@   R$   RE   t   assertIsR#   (   R   t   kindt   mylocal(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_class_attr  s    		c         C   s   |  j  d t ƒ d  S(   NRm   (   Ro   R&   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_class_attr_subclass  s    c            s   d d  l  } t ƒ  ‰  d  ˆ  _ t j ƒ  t 2t 2‡  f d †  } g  t d ƒ D] } t	 d | ƒ ^ qL } x | D] } | j
 ƒ  qn W| j ƒ  |  j t t ƒ t | ƒ ƒ x! | D] } | j ƒ  s¯ t ‚ q¯ W| j ƒ  t j ƒ  |  j t t ƒ t | ƒ ƒ d  S(   Niÿÿÿÿc              s   t  ˆ  d ƒ d  S(   NR!   (   RZ   (    (   t   my_local(    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   demonstrate_my_local  s    i   RJ   (   t   geventR    R   R!   t	   greentestt   gc_collect_if_neededR"   R   t   rangeR   RK   t   sleepR@   R0   t   is_alivet   AssertionError(   R   Rs   Rr   t   _t	   greenletsRM   t   g(    (   Rq   s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt=   test_locals_collected_when_greenlet_dead_but_still_referenced  s"    		
(


s6   GC makes this non-deterministic, especially on Windowsc            sƒ   d d  l  } d d  l ‰ ˆ j ƒ  d ‰  d  ‰ ‡  ‡ ‡ ‡ f d †  } | j | ƒ ‰ | j ƒ  ˆ j ƒ  ˆ j ˆ  t t	 ƒ ƒ d  S(   Niÿÿÿÿiè  c             s   x3 t  d ƒ D]% }  t ƒ  } ˆ j | j ƒ d  } q Wˆ j ƒ  ˆ j ƒ  ˆ j ˆ  t t ƒ ƒ ˆ j ˆ  t t	 ƒ ƒ ˆ j
 ˆ j ƒ  ƒ d  S(   Niè  (   Rv   R    t   assertIsNotNoneR!   R   t   collectR@   R0   R"   R   RR   t	   has_links(   Rz   t   x(   t   countt   gct   running_greenletR   (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyRr   >  s    	


(
   Rs   Rƒ   R   R   t   spawnRw   RL   R@   R0   R   (   R   Rs   Rr   (    (   R‚   Rƒ   R„   R   s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt@   test_locals_collected_when_unreferenced_even_in_running_greenlet1  s    


c            s›   d d  l  } d d l m ‰  d | j f ‡  f d †  ƒ  Y} | ƒ  } | j ƒ  | j ƒ  |  j | j | ƒ |  j | j	 t
 | j f i d d 6f g ƒ d  S(   Niÿÿÿÿ(   t   all_local_dicts_for_greenlett
   MyGreenletc              s#   e  Z d Z d Z ‡  f d  †  Z RS(   c            s4   t  ƒ  } d | _ t | ƒ |  _ ˆ  |  ƒ |  _ d  S(   Ni*   (   R   R(   R   t   id_xt   results(   R   R   (   R‡   (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   _run^  s    		N(   R   R   R   RŠ   R‰   R‹   (    (   R‡   (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyRˆ   [  s   i*   R(   (   Rs   t   gevent.localR‡   t   GreenletRK   RL   t
   assertTruet
   successfulR@   RŠ   R   R‰   (   R   Rs   Rˆ   R|   (    (   R‡   s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_local_dicts_for_greenletV  s    		

c         C   si   t  ƒ  } i d d 6| _ |  j i d d 6| j ƒ |  j d | j ƒ |  j d g t | j ƒ  ƒ ƒ d  S(   Ni   RO   (   R+   R,   R@   RS   t   listt   keys(   R   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_local_with_abck  s
    	c         C   s#   t  ƒ  } |  j d | j ƒ  ƒ d  S(   Ni*   (   R2   R@   R3   (   R   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_local_with_staticmethodv  s    	c         C   s#   t  ƒ  } |  j t  | j ƒ  ƒ d  S(   N(   R5   Rl   R7   (   R   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_local_with_classmethodz  s    	(   R   R   R:   t   tearDownR>   RB   RF   RN   RW   R[   R^   Rf   Ri   Rk   R    Ro   Rp   R}   Rt   t   skipOnLibuvOnPyPyOnWinR†   t   ignores_leakcheckR   R“   R”   R•   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR9   e   s(   		
				0							%		(   t	   interfaces   Needs zope.interfacet   TestLocalInterfacec           B   s    e  Z d Z e j d  „  ƒ Z RS(   c         C   sŒ   d t  j f d „  ƒ  Y} t  j | ƒ d t f d „  ƒ  Yƒ } d | t f d „  ƒ  Y} | ƒ  } t t  j | ƒ ƒ } |  j | g | ƒ d  S(   Nt   IFooc           B   s   e  Z RS(    (   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR›   Œ  s   t   Basec           B   s   e  Z RS(    (   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyRœ     s   t   Derivedc           B   s   e  Z RS(    (   R   R   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR   “  s   (   R™   t	   Interfacet   implementert   objectR   R‘   t
   providedByR@   (   R   R›   Rœ   R   R,   t   p(    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_provides‡  s    	N(   R   R   R   t   __timeout__Rt   R˜   R£   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyRš   ƒ  s   s   Needs C extensiont   TestCExtc           B   s   e  Z d  „  Z RS(   c         C   s   |  j  t j d ƒ d  S(   Ns   gevent._local(   R@   R   R   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_c_extensionŸ  s    (   R   R   R¦   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR¥   œ  s   s   Needs pure-pythont   TestPurec           B   s   e  Z d  „  Z RS(   c         C   s   |  j  t j d ƒ d  S(   Ns   gevent.local(   R@   R   R   (   R   (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   test_extension¦  s    (   R   R   R¨   (    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyR§   £  s   t   __main__((   t   gevent.testingt   testingRt   R    Rs   R   t	   patch_allt	   threadingR   R   t   collections.abcR   t   ImportErrort   collectionsR    R   R   R   R   R"   R   R    R&   R'   R+   R2   R5   t   TestCaseR9   t   zopeR™   R   t   skipIfRš   t   skipOnPurePythonR¥   t   skipWithCExtensionsR§   R   t   main(    (    (    s7   lib/python2.7/site-packages/gevent/tests/test__local.pyt   <module>   sF    
		ÿ 
