³ò
Ae|Mc           @   sü  d  Z  y d d k Z d d k Z Wn+ e j
 o d d k Z d d k Z n Xd d k l Z l	 Z	 d d k
 Z
 d d k Z d d k Z d d k Z d d k Z d d k Z e e d e ƒ p e i d j Z e i d  j  Z e i i d	 ƒ Z e p e o d d k Z n d d k Z d d
 k l Z d d k l Z d d d d d d g Z d „  Z d „  Z  d e! f d „  ƒ  YZ" d e! f d „  ƒ  YZ# d e# f d „  ƒ  YZ$ d a& d d e' d „ Z( d „  Z) d „  Z* d „  Z+ d „  Z, e' d „ Z- d „  Z. d S(!   s   Beaker utilitiesiÿÿÿÿN(   t   datetimet	   timedeltat   py3kwarningi   i    i   i   t   java(   t   asbool(   t   localt   ThreadLocalt   Registryt   WeakValuedRegistryt   SyncDictt   encoded_patht   verify_directoryc         C   sa   d } xT t  i |  t  i ƒ p= y | d 7} t  i |  ƒ Wq	 | d j o ‚  qX q	 Xq	 Wd S(   sc   verifies and creates a directory.  tries to
    ignore collisions with other threads and processes.i    i   i   N(   t   ost   accesst   F_OKt   makedirs(   t   dirt   tries(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR   #   s     
c            s   ‡  f d †  } | S(   Nc            s8   ‡ ‡  f d †  } ˆ  i  | _  d ˆ ˆ  i f | _ | S(   Nc             s    t  i ˆ  t d ƒ ˆ |  | Ž  S(   Ni   (   t   warningst   warnt   DeprecationWarning(   t   argst   kargs(   t   messaget   fn(    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   deprecated_method3   s    s   %s

%s(   t   __name__t   __doc__(   R   R   (   R   (   R   sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   wrapper2   s    (    (   R   R   (    (   R   sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt
   deprecated1   s    c           B   sD   e  Z d  Z d Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 RS(   s$   stores a value on a per-thread basist   _tlocalc         C   s   t  ƒ  |  _  d  S(   N(   R   (   t   self(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   __init__A   s    c         C   s   | |  i  _ d  S(   N(   R   t   value(   R   R!   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   putD   s    c         C   s   t  |  i d ƒ S(   NR!   (   t   hasattrR   (   R   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   hasG   s    c         C   s   t  |  i d | ƒ S(   NR!   (   t   getattrR   (   R   t   default(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   getJ   s    c         C   s   |  i  ` d  S(   N(   R   R!   (   R   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   removeM   s    N(
   R   t
   __module__R   t	   __slots__R    R"   R$   t   NoneR'   R(   (    (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR   <   s   			c           B   sh   e  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Þ  
    An efficient/threadsafe singleton map algorithm, a.k.a.
    "get a value based on this key, and create if not found or not
    valid" paradigm:
    
        exists && isvalid ? get : create

    Designed to work with weakref dictionaries to expect items
    to asynchronously disappear from the dictionary.  

    Use python 2.3.3 or greater !  a major bug was just fixed in Nov.
    2003 that was driving me nuts with garbage collection/weakrefs in
    this section.

    c         C   s   t  i ƒ  |  _ h  |  _ d  S(   N(   t   _threadt   allocate_lockt   mutext   dict(   R   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR    `   s    c         O   si   y9 |  i  | ƒ o |  i | Sn |  i | | | | Ž SWn) t j
 o |  i | | | | Ž Sn Xd  S(   N(   t   has_keyR/   t   sync_gett   KeyError(   R   t   keyt
   createfuncR   t   kwargs(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR'   d   s    c         O   s‹   |  i  i ƒ  zi y9 |  i | ƒ o |  i | Sn |  i | | | | Ž SWn) t j
 o |  i | | | | Ž Sn XWd  |  i  i ƒ  Xd  S(   N(   R.   t   acquireR0   R/   t   _createR2   t   release(   R   R3   R4   R   R5   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR1   m   s    c         O   s   | | | Ž  |  | <} | S(   N(    (   R   R3   R4   R   R5   t   obj(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR7   z   s    c         C   s   |  i  i | ƒ S(   N(   R/   R0   (   R   R3   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR0   ~   s    c         C   s   |  i  i | ƒ S(   N(   R/   t   __contains__(   R   R3   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR:      s    c         C   s   |  i  i | ƒ S(   N(   R/   t   __getitem__(   R   R3   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR;   ƒ   s    c         C   s   |  i  i | | ƒ d  S(   N(   R/   t   __setitem__(   R   R3   R!   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR<   …   s    c         C   s   |  i  i | ƒ S(   N(   R/   t   __delitem__(   R   R3   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR=   ‡   s    c         C   s   |  i  i ƒ  d  S(   N(   R/   t   clear(   R   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR>   ‰   s    (   R   R)   R   R    R'   R1   R7   R0   R:   R;   R<   R=   R>   (    (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR	   P   s   										c           B   s   e  Z d  „  Z RS(   c         C   s"   t  i ƒ  |  _ t i ƒ  |  _ d  S(   N(   t
   _threadingt   RLockR.   t   weakreft   WeakValueDictionaryR/   (   R   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR    Ž   s    (   R   R)   R    (    (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR      s   s   .encc   	      C   sï   d i  | ƒ } t d j o d d k l a n | o< t o t | i d ƒ ƒ i ƒ  } qs t | ƒ i ƒ  } n t i i	 | ƒ } g  } x+ t
 d | ƒ D] } | i | d | !ƒ q› Wt i i  |  | Œ } t | ƒ t i i  | | | ƒ S(   ss   Generate a unique file-accessible path from the given list of
    identifiers starting at the given root directory.t   _iÿÿÿÿ(   t   sha1s   utf-8i   i    N(   t   joinRD   R+   t   beaker.cryptot   py3kt   encodet	   hexdigestR   t   patht   basenamet   ranget   appendR   (	   t   roott   identifierst	   extensiont   deptht   digest_filenamest   identt   tokenst   dR   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyR
   “   s     
c         C   s  t  |  | ƒ pÙ t  | t ƒ p | f } n t } x˜ | D] } yt | t t f j o4 g  } |  i d ƒ D] } | | i ƒ  qj ~ }  n$ | t j o
 t } n | |  ƒ }  t } Wn n X| o Pq: q: W| p t	 | ƒ ‚ qn3 t  |  t
 ƒ o" |  i ƒ  o t	 d | ƒ ‚ n |  S(   Nt   ,s!   Empty strings are invalid for: %s(   t
   isinstancet   tuplet   Falset   listt   splitt   stript   boolR   t   Truet	   Exceptiont   str(   t   optt   typest   errort   coercedt   typt   _[1]t   x(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   verify_options°   s,     4

	c         C   sI   xB | D]: \ } } } | |  j o t  |  | | | ƒ |  | <q q W|  S(   N(   Rh   (   t   paramst   rulesetR3   Rb   R   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   verify_rulesÉ   s
     "c         C   s  d t  t i f d f d t  t i f d f d t  t i f d f d t t t f d f d	 t  t i f d
 f d t  f d f d t  f d f d t  t i f d f d t  t i f d f d t  t i f d f d t t i f d f d t t i f d f d t t i f d f g } t |  | ƒ S(   Nt   data_dirs3   data_dir must be a string referring to a directory.t   lock_dirs3   lock_dir must be a string referring to a directory.t   types   Session type must be a string.t   cookie_expiressB   Cookie expires was not a boolean, datetime, or timedelta instance.t   cookie_domains   Cookie domain must be a string.t   ids   Session id must be a string.R3   s   Session key must be a string.t   secrets    Session secret must be a string.t   validate_keys%   Session encrypt_key must be a string.t   encrypt_keys&   Session validate_key must be a string.t   secures!   Session secure must be a boolean.t   timeouts#   Session timeout must be an integer.t   autos   Session is created if accessed.(   R`   Rb   t   NoneTypeR]   R    R   t   intRk   (   Ri   t   rules(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   coerce_session_paramsÐ   s    c      	   C   sŽ   d t  t i f d f d t  t i f d f d t  f d f d t t i f d f d	 t t i f d
 f d t t t i f d f g } t |  | ƒ S(   NRl   s3   data_dir must be a string referring to a directory.Rm   s3   lock_dir must be a string referring to a directory.Rn   s   Cache type must be a string.t   enableds&   enabled must be true/false if present.t   expiresN   expire must be an integer representing how many seconds the cache is valid fort   regionss7   Regions must be a comma seperated list of valid regions(   R`   Rb   Rx   R]   Ry   RZ   RX   Rk   (   Ri   Rz   (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   coerce_cache_paramsê   s    c   
      C   s³  | o% t  d d d d d d d d ƒ } n h  } x^ |  i ƒ  D]P \ } } | i d ƒ o | | | d <n | i d ƒ o | | | d	 <q? q? Wt | ƒ d
 | j o t | d
 <n | i d d ƒ } | oÞ h  } xÇ | D]¿ } t  d | i d ƒ d | i d ƒ d | i d ƒ d
 | d
 d | i d ƒ ƒ } t | ƒ d }	 xC | i	 ƒ  D]5 } | i d | ƒ o | i | ƒ | | |	 <qPqPWt | ƒ | | | <qÞ W| | d <n | S(   sJ   Parse configuration options and validate for use with the
    CacheManagerRn   t   memoryRl   R}   t   log_files   beaker.cache.i   s   cache.i   R|   R~   Rm   i   s   %s.t   cache_regionsN(
   R/   R+   t	   iteritemst
   startswithR   R^   t   popR'   t   lent   keys(
   t   configt   include_defaultst   optionsR3   t   valR~   t   region_configst   regiont   region_optionst
   region_len(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   parse_cache_config_optionsû   s@     
 
 
c         C   sc   d } t |  d ƒ o |  i } |  i }  n | o d | i | i f Sn d |  i |  i f Sd S(   s+   Generates a unique namespace for a functiont   im_funcs   %s.%sN(   R+   R#   t   im_classR‘   R)   R   (   t   funct   kls(    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pyt   func_namespace$  s    	(   i   i    (   i   i   (/   R   t   threadR,   t	   threadingR?   t   ImportErrort   dummy_threadt   dummy_threadingR    R   R   t   stringRb   RA   R   t   sysR%   RY   t   version_infoRG   t   py24t   platformR„   t   jythont   picklet   cPicklet   beaker.convertersR   R   R   t   __all__R   R   t   objectR   R	   R   R+   RD   R^   R
   Rh   Rk   R{   R   R   R•   (    (    (    sd   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/util.pys   <module>   sJ   "		=				)