
b]c           @   s  d  Z  d d l m 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	 Z	 d d l
 Z
 d d l Z d d l m Z d d l m Z d d l m Z d	   Z d
 e f d     YZ d   Z d   Z d   Z d   Z d   Z d   Z d   Z d e f d     YZ d   Z d d  Z d   Z e e d  Z  e! d  Z" e! d  Z# d   Z$ d   Z% dX d dY d  Z& d e f d     YZ' d    Z( d!   Z) d d d" d d#  Z* d$   Z+ d d d d%  Z, d& e f d'     YZ- d(   Z. d) e f d*     YZ/ d+ e f d,     YZ0 e d-  Z1 d. e f d/     YZ2 d0   Z3 d1   Z4 d2   Z5 e! d d3  Z6 d4   Z7 d5   Z8 d d6  Z9 d7   Z: d8   Z; d9 e< f d:     YZ= d; e f d<     YZ> d= e f d>     YZ? d? e@ f d@     YZA dA eA _B dA e f dB     YZC d aD dC   ZE dD   ZF dE dF  ZG dG e jH f dH     YZI dI   ZJ dJ   ZK dK   ZL e jM dL  ZN e jM dM  ZO eO eN dN  ZP eQ d  ZR dO   ZS dP eQ f dQ     YZT dR   ZU dS   ZV dT   ZW dU   ZX dV   ZY dW   ZZ d S(Z   s   Routines to help with the creation, loading and introspection of
modules, classes, hierarchies, attributes, functions, and methods.

i(   t   update_wrapperNi   (   t   _collections(   t   compati   (   t   excc         C   s>   t  j r |  j d  }  n  t j   } | j |   | j   S(   Ns   utf-8(   R   t   py3kt   encodet   hashlibt   md5t   updatet	   hexdigest(   t   xt   m(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   md5_hex   s
    	t   safe_reraisec           B   s2   e  Z d  Z d Z e d  Z d   Z d   Z RS(   sK  Reraise an exception after invoking some
    handler code.

    Stores the existing exception info before
    invoking so that it is maintained across a potential
    coroutine context switch.

    e.g.::

        try:
            sess.commit()
        except:
            with safe_reraise():
                sess.rollback()

    t	   warn_onlyt	   _exc_infoc         C   s   | |  _  d  S(   N(   R   (   t   selfR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __init__8   s    c         C   s   t  j   |  _ d  S(   N(   t   syst   exc_infoR   (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt	   __enter__;   s    c         C   s   | d  k rI |  j \ } } } d  |  _ |  j s t j | | |  q na t j r |  j r |  j d r t d |  j d |  j d f  n  d  |  _ t j | | |  d  S(   Ni   sf   An exception has occurred during handling of a previous exception.  The previous exception is:
 %s %s
i    (   t   NoneR   R   R   t   reraiseR   t   warn(   R   t   type_t   valuet	   tracebackt   exc_typet	   exc_valuet   exc_tb(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __exit__>   s    		 	(   R   R   (   t   __name__t
   __module__t   __doc__t	   __slots__t   FalseR   R   R   (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   $   s
   	c         C   s&   d j  d   t j d |  j  D  S(   Nt    c         s   s   |  ] } | j    Vq d  S(   N(   t   lower(   t   .0t   n(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>T   s    s   ([A-Z][a-z]+)(   t   joint   ret   findallR   (   t   cls(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   clsname_as_plain_nameR   s    c         C   s^   g  } xK |  j  |  j |  j f D]1 } t | d  rC | j   } n  | j |  q Wt |  S(   sr   decode a slice object as sent to __getitem__.

    takes into account the 2.5 __index__() method, basically.

    t	   __index__(   t   startt   stopt   stept   hasattrR-   t   appendt   tuple(   t   slct   retR
   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   decode_sliceX   s    c         '   s   t  |   }  x | D]y   t j   f t j   f d   t d    } x@ | D]( } | |  k rP |  j |  | VPqP qP Wt d     q Wd  S(   Nc            s     t  |   S(   N(   t   str(   t   i(   t   base(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   <lambda>k   t    i  s&   exhausted namespace for symbol base %s(   t   sett	   itertoolst   chainR   t   itertools_imapt   ranget   addt	   NameError(   t   usedt   basest   poolt   sym(    (   R9   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   _unique_symbolsf   s    $c         c   s5   x. | r0 | | d @} |  |  V| | N} q Wd S(   s6   Call the given function given each nonzero bit from n.i   N(    (   t   fnR'   t   b(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   map_bitsv   s    	c            s     f d   } t  |    S(   s'   A signature-matching decorator factory.c            s  t  j |   r/ t  j |   r/ t d   n  t j |   } t | d  | d d !|  j f } t | d d  \ } } t	 d | d |  } | j
 t | d t  |  j | d <d	 | } t | i   | 6|  | 6|  j  } t |  d
 |   j | _ |  | _ t | |   S(   Ns   not a decoratable functioni    i   i   t   targetRH   t   groupedt   namesD   def %(name)s(%(args)s):
    return %(target)s(%(fn)s, %(apply_kw)s)
t   im_func(   t   inspectt
   isfunctiont   ismethodt	   ExceptionR   t   inspect_getfullargspecR3   R   RG   t   dictR   t   format_argspec_plusR#   t   _exec_code_in_envt   getattrt   __defaults__t   __wrapped__R    (   RH   t   spect   namest	   targ_namet   fn_namet   metadatat   codet	   decorated(   RK   (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   decorate   s     % 	(   R    (   RK   Ra   (    (   RK   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt	   decorator   s    c         B   s   |  | U| | S(   N(    (   R_   t   envR]   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRV      s    c         B   s  e  |  e  r4 |  j } |  } d |  j | f } n |  } } d | } | j d  d } e j |  } | d d =e | d e } | | d <d | } i | d	 6e	 d
 6}	 | |	 U|	 | }
 | j
 |
 _
 d | j d d  d |
 _ e j se | d  r| | j _
 n	 | | _
 |
 S(   s   Produce a wrapping function for the given cls or classmethod.

    Rationale here is so that the __init__ method of the
    class can serve as documentation for the function.

    s   Construct a new :class:`.%s` object. 

This constructor is mirrored as a public API function; see :func:`~%s` for a full usage and argument description.sJ   This function is mirrored; see :func:`~%s` for a description of arguments.t   .ii    RL   RM   s5   def %(name)s(%(args)s):
    return cls(%(apply_kw)s)
R+   t   symbolt
   sqlalchemyi   t   __func__(   t
   isinstancet   typeR   R   t   splitR   RS   RU   R#   Re   R!   t   rsplitR    t   py2kR1   Rg   (   RK   t   locationRH   t	   callable_t   doct   location_nameRZ   R^   R_   Rc   R`   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   public_factory   s0    	


	t   PluginLoaderc           B   s/   e  Z d d   Z d   Z d   Z d   Z RS(   c         C   s   | |  _  i  |  _ | |  _ d  S(   N(   t   groupt   implst   auto_fn(   R   Rs   Ru   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR      s    		c         C   s   |  j  j   d  S(   N(   Rt   t   clear(   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRv      s    c         C   s   | |  j  k r |  j  |   S|  j rR |  j |  } | rR | |  j  | <|   Sn  y d d  l } Wn t k
 ru n8 Xx4 | j |  j |  D] } | j |  j  | <| j   SWt j d |  j | f   d  S(   Nis   Can't load plugin: %s:%s(	   Rt   Ru   t   pkg_resourcest   ImportErrort   iter_entry_pointsRs   t   loadR   t   NoSuchModuleError(   R   RM   t   loaderRw   t   impl(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRz      s     	
c            s#      f d   } | |  j  | <d  S(   Nc             sI   t  j    }  x*   j d  d D] } t |  |  }  q# Wt |    S(   NRd   i   (   R   t   import_Rj   RW   (   t   modt   token(   t
   modulepatht   objname(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRz      s    (   Rt   (   R   RM   R   R   Rz   (    (   R   R   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   register   s    N(   R   R    R   R   Rv   Rz   R   (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRr      s   		c         C   s   y t  j } Wn5 t k
 rD t j |   } | d t | d  f SX|  j } | j } t | j	 |   t | j
 | @ f Sd  S(   Ni    i   (   RO   t   CO_VARKEYWORDSt   AttributeErrorR   RS   t   boolt   __code__t   co_argcountt   listt   co_varnamest   co_flags(   RH   t   co_varkeywordsRZ   t   cot   nargs(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   _inspect_func_args   s    		c         C   s   | d k } | r t   } n  |  j j d t  } | o] t | t j  o] t | j t j	  } | r t
 |  \ } } | j |  | r | r d Sn  | s | r x- |  j D] } t | |  d k r Pq q Wn  | j d  | S(   se  Return the full set of inherited kwargs for the given `cls`.

    Probes a class's __init__ method, collecting all named arguments.  If the
    __init__ defines a \**kwargs catch-all, then the constructor is presumed
    to pass along unrecognized keywords to its base classes, and the
    collection process is repeated recursively on each of the bases.

    Uses a subset of inspect.getfullargspec() to cut down on method overhead,
    as this is used within the Core typing system to create copies of type
    objects which is a performance-sensitive operation.

    No anonymous tuple arguments please !

    R   R   N(   R   R<   t   __dict__t   getR#   Rh   t   typest   FunctionTypeR   t   CodeTypeR   R   t	   __bases__t   get_cls_kwargst   discard(   R+   t   _sett   toplevelt   ctrt   has_initR[   t   has_kwt   c(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s$    c         C   s   t  j |   d S(   s   Return the set of legal kwargs for the given `func`.

    Uses getargspec so is safe to call for methods, functions,
    etc.

    i    (   R   RS   (   t   func(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   get_func_kwargs<  s    c         C   s  t  j |   r" t d |    nt  j |   r | r | r t j |   } t j | j d | j | j	 | j
 | j | j | j  St j |   Snt  j |   r| r| s |  j rt j |  j  } t j | j d | j | j	 | j
 | j | j | j  St j |  j  Sn t  j |   r=t |  j d | d t St |  d  r\t j |  j  St |  d  rt  j |  j  rt |  j d | St d |    n t d |    d S(	   s   Return the argument signature for any callable.

    All pure-Python callables are accepted, including
    functions, methods, classes, objects with __call__;
    builtins and other edge cases like functools.partial() objects
    raise a TypeError.

    s   Can't inspect builtin: %si   t   no_selft   _is_initRg   t   __call__s   Can't inspect callable: %sN(   RO   t	   isbuiltint	   TypeErrorRP   R   RS   t   FullArgSpect   argst   varargst   varkwt   defaultst
   kwonlyargst   kwonlydefaultst   annotationsRQ   t   __self__Rg   t   isclasst   get_callable_argspecR   t   TrueR1   R   (   RH   R   R   RZ   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   G  sH    	



c   
      C   s  t  j |   r! t  j |   } n |  } t  j |   } | d rQ | d d } n! | d rl d | d } n d } t  j | d | d | d d | d  } d } | d r | t | d  7} n  | d r | t | d  7} n  | d | d } | r| d | } n d } t  j | | d | d | d d   }	 | rbt d	 | d
 | d | d |	  St d	 | d d !d
 | d | d d !d |	 d d ! Sd S(   s  Returns a dictionary of formatted, introspected function arguments.

    A enhanced variant of inspect.formatargspec to support code generation.

    fn
       An inspectable callable or tuple of inspect getargspec() results.
    grouped
      Defaults to True; include (parens, around, argument) lists

    Returns:

    args
      Full inspect.formatargspec for fn
    self_arg
      The name of the first positional argument, varargs[0], or None
      if the function defines no positional arguments.
    apply_pos
      args, re-written in calling rather than receiving syntax.  Arguments are
      passed positionally.
    apply_kw
      Like apply_pos, except keyword-ish args are passed as keywords.

    Example::

      >>> format_argspec_plus(lambda self, a, b, c=3, **d: 123)
      {'args': '(self, a, b, c=3, **d)',
       'self_arg': 'self',
       'apply_kw': '(self, a, b, c=c, **d)',
       'apply_pos': '(self, a, b, c, **d)'}

    i    i   s   %s[0]i   i   i   t   formatvaluec         S   s   d |  S(   Nt   =(    (   R
   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR:     R;   R   t   self_argt	   apply_post   apply_kwiN(    (   R   t   callableRS   t   inspect_formatargspecR   t   lenRT   (
   RH   RL   RZ   R   R   R   t   num_defaultst	   name_argst   defaulted_valsR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRU   }  sJ     

%

c      	   C   s}   |  t  j k r$ | r d p d } n: y t |  d | SWn# t k
 r] | rT d pW d } n Xt d d d | d | d	 |  S(
   s  format_argspec_plus with considerations for typical __init__ methods

    Wraps format_argspec_plus with error handling strategies for typical
    __init__ cases::

      object.__init__ -> (self)
      other unreflectable (usually C) -> (self, *args, **kwargs)

    s   (self)R   RL   s   (self, *args, **kwargs)s   self, *args, **kwargsR   R   R   R   (   t   objectR   RU   R   RT   (   t   methodRL   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   format_argspec_init  s    

c         C   s^   y t  j |   SWnF t k
 rY |  t j k rC d g d d d f Sd g d d d f Sn Xd S(   s   inspect.getargspec with considerations for typical __init__ methods

    Wraps inspect.getargspec with error handling for typical __init__ cases::

      object.__init__ -> (self)
      other unreflectable (usually C) -> (self, *args, **kwargs)

    R   R   t   kwargsN(   R   RS   R   R   R   R   (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   getargspec_init  s    	c         C   s+   t  |  t j  r# |  j r# |  j S|  Sd S(   sS   Adjust the incoming callable such that a 'self' argument is not
    required.

    N(   Rh   R   t
   MethodTypeR   Rg   (   t   func_or_cls(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   unbound_method_to_callable  s    c            s  | d k r   g } n t j |  } t   } g  } t j   } d } x8t |  D]*\ } }	 y t j |	 j  }
 Wn t	 k
 r qU qU X|
 j
 r t |
 j
  p d } | d k r|
 j r |
 j } n  | r | j |
 j d | ! q6| j |
 j d  n1 | j g  |
 j d | !D] } | | f ^ q | rU | j g  t |
 j | |
 j
  D] \ } } | | f ^ q] qU qU Wg  } | j   f d   | D  | d k	 rt   |  r| j g  t   |  D] } t |  ^ q n  x | j   D]z \ } } | | k rq n  yH t   | |  } | | k	 re| | k re| j d | | f  n  Wq t k
 ryq Xq W| rxs | D]h \ } } yH t   | |  } | | k	 r| | k r| j d | | f  n  Wqt k
 rqXqWn  d   j j d j |  f S(   s}   Produce a __repr__() based on direct association of the __init__()
    specification vs. same-named attributes present.

    i    i   c         3   s'   |  ] } t  t   | d    Vq d  S(   N(   t   reprRW   R   (   R&   t   arg(   t   obj(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>3  s    s   %s=%rs   %s(%s)s   , N(   R   R   t   to_listR   t   OrderedDictt	   enumerateR   RS   R   R   R   R   R   t   extendR   R   t   zipR1   RW   R   t   itemsR2   RR   t	   __class__R   R(   (   R   t   additional_kwt
   to_inspectt
   omit_kwargt   missingt   pos_argst   kw_argst   vargsR8   t   inspRZ   t   default_lenR   t   defaultt   outputt   valt   defval(    (   R   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   generic_repr  s`    		+;2t   portable_instancemethodc           B   s;   e  Z d  Z d	 Z d   Z d   Z d
 d  Z d   Z RS(   s_   Turn an instancemethod into a (parent, name) pair
    to produce a serializable callable.

    RK   RM   R   t   __weakref__c         C   s"   i |  j  d 6|  j d 6|  j d 6S(   NRK   RM   R   (   RK   RM   R   (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __getstate__V  s    

c         C   s3   | d |  _  | d |  _ | j d d  |  _ d  S(   NRK   RM   R   (    (   RK   RM   R   R   (   R   t   state(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __setstate__]  s    c         C   s%   | j  |  _ | j |  _ | |  _ d  S(   N(   R   RK   R   RM   R   (   R   t   methR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   b  s    c         O   s,   | j  |  j  t |  j |  j  | |   S(   N(   R   R   RW   RK   RM   (   R   R   t   kw(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   g  s    (   RK   RM   R   R   (    (   R   R    R!   R"   R   R   R   R   (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   N  s   		c            s  t  j r% t |  t j  r% t   Sn  |  h   t |  j  } x=| r|| j   } t  j r t | t j  rs q@ n    f d   | j D } n   f d   | j D } x( | D]  } | j	 |    j
 |  q Wt  j r| j d k s@ t | d  r)q@ q)n% | j d k s@ t | d  r)q@ n  xM g  | j   D] } |   k r9| ^ q9D]  } | j	 |    j
 |  qUWq@ Wt    S(   s  Return an unordered sequence of all classes related to cls.

    Traverses diamond hierarchies.

    Fibs slightly: subclasses of builtin types are not returned.  Thus
    class_hierarchy(class A(object)) returns (A, object), not A plus every
    class systemwide that derives from object.

    Old-style classes are discarded and hierarchies rooted on them
    will not be descended.

    c         3   s4   |  ]* } |   k r t  | t j  r | Vq d  S(   N(   Rh   R   t	   ClassType(   R&   t   _(   t   hier(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>  s   c         3   s!   |  ] } |   k r | Vq d  S(   N(    (   R&   R   (   R   (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>  s    t   builtinst   __subclasses__t   __builtin__(   R   Rl   Rh   R   R   R   t   __mro__t   popR   R2   RA   R   R    R1   R   (   R+   t   processR   RD   RI   R   t   s(    (   R   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   class_hierarchyl  s4    	
					2c         c   sZ   t  |   } xG | D]? } x6 |  j D]+ } | | j k r# | | j | f VPq# q# Wq Wd S(   s   iterate all the keys and attributes associated
       with a class, without using getattr().

       Does not use getattr() so that class-sensitive
       descriptors (i.e. property.__get__()) are not called.

    N(   t   dirR   R   (   R+   t   keyst   keyR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   iterate_attributes  s    s
   self.proxyc         C   s  | r | } nn | d k r$ d } n  g  t |  D]F } | j d  r1 | j d  r1 t |  |  r1 | | k r1 | ^ q1 } x4| D],} y: t | |  }	 t |	 d  s w n  t |	 d	 |	  }	 Wn t k
 r q n Xy= t j |	  }
 t j	 |
 d
  } t j	 |
 d
 d  } Wn t
 k
 r7d } d } n Xd t   } | d k	 r^i | | 6pai  } t j | |  y |	 j | | _ Wn t k
 rn Xt |  | | |  q Wd S(   s9   Automates delegation of __specials__ for a proxying type.R"   t   __del__t   __getattribute__t   __metaclass__R   R   t   __R   RN   i    i   s   (self, *args, **kw)s   (*args, **kw)s?   def %(method)s%(fn_args)s: return %(name)s.%(method)s%(d_args)sN(   R"   R   R   R   R   R   (   R   R   t
   startswitht   endswithR1   RW   R   R   RS   R   R   t   localst   exec_RX   t   setattr(   t   into_clst   from_clst   skipt   onlyRM   t   from_instancet   dundersR   R   RH   RZ   t   fn_argst   d_argst   pyRc   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   monkeypatch_proxied_specials  sN    
	     	

c         C   s"   t  |  d |   t  | d |  k S(   s;   Return True if the two methods are the same implementation.Rg   (   RW   (   t   meth1t   meth2(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   methods_equivalent  s    c         C   s1  | r | r t  d   n  t | t  r? t |  |  r? |  St | ps g  t |  D] } | j d  sU | ^ qU  } t t |    } t j } t | t  r | } n' | s t   } t j } n t |  } | | j	 |  |  r |  St |  t
  s>| t j k rd pd } t  d |  | d j |  f   n  d t f d     Y}	 | rmd	 | j |	 _ n  t   }
 x t |   D]v \ } } | | k rt  d
 |   n  t j |  st  d | | f   n  t |	 | t |   |
 j |  qW| |
 |  r|	 St  d d j | |
    d S(   s  Ensure basic interface compliance for an instance or dict of callables.

    Checks that ``obj`` implements public methods of ``cls`` or has members
    listed in ``methods``. If ``required`` is not supplied, implementing at
    least one interface method is sufficient. Methods present on ``obj`` that
    are not in the interface are ignored.

    If ``obj`` is a dict and ``dict`` does not meet the interface
    requirements, the keys of the dictionary are inspected. Keys present in
    ``obj`` that are not in the interface will raise TypeErrors.

    Raises TypeError if ``obj`` does not meet the interface criteria.

    In all passing cases, an object with callable members is returned.  In the
    simple case, ``obj`` is returned as-is; if dict processing kicks in then
    an anonymous class is returned.

    obj
      A type, instance, or dictionary of callables.
    cls
      Optional, a type.  All public methods of cls are considered the
      interface.  An ``obj`` instance of cls will always pass, ignoring
      ``required``..
    methods
      Optional, a sequence of method names to consider as the interface.
    required
      Optional, a sequence of mandatory implementations. If omitted, an
      ``obj`` that provides at least one interface method is considered
      sufficient.  As a convenience, required may be a type, in which case
      all public methods of the type are required.

    s2   a class or collection of method names are requiredR   s   any ofs   all ofs   %r does not implement %s: %ss   , t   AnonymousInterfacec           B   s   e  Z d  Z RS(   s   A callable-holding shell.(   R   R    R!   (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR  4  s   t	   Anonymouss   %r: unknown in this interfaces   %r=%r is not callables,   dictionary does not contain required keys %sN(   R   Rh   Ri   R<   R   R   t   operatort   get   gtt   intersectionRT   R(   R   R   t   dictlike_iteritemsR   R   R   t   staticmethodRA   (   R   R+   t   methodst   requiredR   t	   interfacet   implementedt   compliest	   qualifierR  t   foundR   R}   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   as_interface  sH    !:				t   memoized_propertyc           B   s;   e  Z d  Z d d  Z d   Z d   Z e d    Z RS(   s2   A read-only @property that is only evaluated once.c         C   s+   | |  _  | p | j |  _ | j |  _ d  S(   N(   t   fgetR!   R   (   R   R  Ro   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   O  s    	c         C   s1   | d  k r |  S|  j |  | j |  j <} | S(   N(   R   R  R   R   (   R   R   R+   t   result(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __get__T  s    c         C   s   t  j | |  j  d  S(   N(   R  t   resetR   (   R   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   _resetZ  s    c         C   s   | j  j | d   d  S(   N(   R   R   R   (   R+   R   RM   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR  ]  s    N(	   R   R    R!   R   R   R  R  t   classmethodR  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR  L  s
   		c            s     f d   } t  |    S(   s   Decorate a method memoize its return value.

    Best applied to no-arg methods: memoization is not sensitive to
    argument values, and will always return the same value even when
    called with different arguments.

    c            sM    |  | |      f d   }  j  | _   j | _ | |  j  j  <  S(   Nc             s     S(   N(    (   t   aR   (   R  (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   memon  s    (   R   R!   R   (   R   R   R   R   (   RH   (   R  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   oneshotk  s    (   R    (   RH   R!  (    (   RH   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   memoized_instancemethodb  s    	t!   group_expirable_memoized_propertyc           B   s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   s?   A family of @memoized_properties that can be expired in tandem.c         C   s&   g  |  _  | r" |  j  j |  n  d  S(   N(   t
   attributesR   (   R   R$  (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR   |  s    	c         C   s1   | j  } x! |  j D] } | j | d  q Wd S(   s.   Expire all memoized properties for *instance*.N(   R   R$  R   R   (   R   t   instancet   stasht	   attribute(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   expire_instance  s    	c         C   s   |  j  j | j  t |  S(   N(   R$  R2   R   R  (   R   RH   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    c         C   s   |  j  j | j  t |  S(   N(   R$  R2   R   R"  (   R   RH   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    (    (   R   R    R!   R   R(  R   R   (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR#  y  s
   		t   MemoizedSlotsc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s   Apply memoized items to an object using a __getattr__ scheme.

    This allows the functionality of memoized_property and
    memoized_instancemethod to be available to a class using __slots__.

    c         C   s   t  |   d  S(   N(   R   (   R   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   _fallback_getattr  s    c            s    j  d  r t    n t  d   r[ t  d     } t   |  | St  d   r t  d         f d   }   j | _ | S j   Sd  S(   Nt	   _memoizeds   _memoized_attr_%ss   _memoized_method_%sc             sJ    |  |       f d   }  j  | _   j | _ t   |    S(   Nc             s     S(   N(    (   R  R   (   R  (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    (   R   R!   R   (   R   R   R   (   RH   R   R   (   R  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR!    s    (   R   R   R1   RW   R   R!   R*  (   R   R   R   R!  (    (   RH   R   R   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __getattr__  s    (    (   R   R    R!   R"   R*  R,  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR)    s   	c            s      f d   } | S(   Nc            s    j  d  } t j d j | d d ! t   t   | d g  } t | | d  } t | |  j |     r t	 | d  r | j
 j |  j  n  |  S(   NRd   i    it   __all__(   Rj   R   R~   R(   t   globalsR   RW   R   R   R1   R-  R2   (   R   t   tokensR   (   t
   add_to_allt
   modulename(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRa     s    /(    (   R1  R0  Ra   (    (   R0  R1  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   dependency_for  s    t   dependenciesc           B   sT   e  Z d  Z d   Z d   Z e d    Z e   Z i  Z	 d e
 f d     YZ RS(   s  Apply imported dependencies as arguments to a function.

    E.g.::

        @util.dependencies(
            "sqlalchemy.sql.widget",
            "sqlalchemy.engine.default"
        );
        def some_func(self, widget, default, arg1, arg2, **kw):
            # ...

    Rationale is so that the impact of a dependency cycle can be
    associated directly with the few functions that cause the cycle,
    and not pollute the module-level namespace.

    c         G   s]   g  |  _  xM | D]E } | j d  } |  j  j t j d j | d d ! | d   q Wd  S(   NRd   i    i(   t   import_depsRj   R2   R3  t   _importlaterR(   (   R   t   depst   depR/  (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s
    		c         C   s!  |  j  } t j |  } t | d  } | d d k } x< t t |   D]( } d | | d | | rn d n d <qK Wt | d t } x! | D] } | | r d n d =q W| | d (t | d t }	 d i |	 d d 6| d	 d	 6}
 t |
 t	    } t
 | d
 |  j | _ t | |  S(   Ni    R   R+   s   import_deps[%r]i   RL   s!   lambda %(args)s: fn(%(apply_kw)s)R   R   RN   (   R   R+   (   R4  R   RS   R   R@   R   RU   R#   t   evalR   RW   RX   R    (   R   RH   R4  RZ   t	   spec_zerot   hasselfR8   t
   inner_spect   impnamet
   outer_specR_   R`   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s"    	&c         C   s=   x6 t  t j  D]% } | j j |  r | j   q q Wd  S(   N(   R   R3  t   _unresolvedt
   _full_pathR   t   _resolve(   R+   t   pathR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   resolve_all  s    R5  c           B   sY   e  Z e   Z i  Z d    Z d   Z e d    Z e	 d    Z
 d   Z d   Z RS(   c         C   sJ   | d | } | t  j k r( t  j | St j |   t  j | <} | Sd  S(   NRd   (   R3  t   _by_keyR   t   __new__(   R+   RA  t   addtlR   t   imp(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRD  
  s
    c         C   s&   | |  _  | |  _ t j j |   d  S(   N(   t   _il_patht	   _il_addtlR3  R>  RA   (   R   RA  RE  (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    		c         C   s   |  j  d |  j S(   NRd   (   RG  RH  (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR?    s    c         C   sA   |  t  j k r. t d |  j |  j f   n  t |  j |  j  S(   Ns<   importlater.resolve_all() hasn't been called (this is %s %s)(   R3  R>  Rx   RG  RH  RW   t   _initial_import(   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   module  s
    c         C   s>   t  j j |   t j |  j t   t   |  j g  |  _	 d  S(   N(
   R3  R>  R   R   R~   RG  R.  R   RH  RI  (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR@  &  s    c         C   sv   | d k r" t  d |  j   n  y t |  j |  } Wn* t k
 rd t d |  j | f   n X| |  j | <| S(   NRJ  s   Could not resolve module %ss   Module %s has no attribute '%s'(   Rx   R?  RW   RJ  R   R   (   R   R   t   attr(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR,  ,  s    (   R   R    R<   R>  RC  RD  R   t   propertyR?  R  RJ  R@  R,  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR5    s   				(   R   R    R!   R   R   R  RB  R<   R>  RC  R   R5  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR3    s   			c         C   sa   t  |  t j  rW |  j   j   }  |  d k r4 t S|  d k rD t St d |    n  t |   S(   Nt   truet   yest   ont   yt   tt   1t   falset   not   offR'   t   ft   0s   String is not true/false: %r(   RM  RN  RO  RP  RQ  RR  (   RS  RT  RU  R'   RV  RW  (	   Rh   R   t   string_typest   stripR%   R   R#   t
   ValueErrorR   (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   asbool<  s    c             s     f d   } | S(   sq   Return a callable that will evaluate a string as
    boolean, or one of a set of "alternate" string values.

    c            s   |    k r |  St  |   Sd  S(   N(   R[  (   R   (   t   text(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   bool_or_valueN  s    (    (   R\  R]  (    (   R\  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   bool_or_strH  s    c         C   s   |  d k r |  St |   S(   s   Coerce to integer.N(   R   t   int(   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   asintW  s    c         C   s   | d k r |  } n  | |  k r t | t  sE t |  | |  r |  | d k	 r | t k r~ | r~ t |  |  | | <q | |  |  | | <n  d S(   s   If 'key' is present in dict 'kw', coerce its value to type 'type\_' if
    necessary.  If 'flexi_bool' is True, the string '0' is considered false
    when coercing to boolean.
    N(   R   Rh   Ri   R   R[  (   R   R   R   t
   flexi_boolt   dest(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   coerce_kw_type_  s    	$c            s?   t  |  } | j   f d   | j |  D  | | |   S(   s   Instantiate cls using the __dict__ of obj as constructor arguments.

    Uses inspect to match the named arguments of ``cls``.

    c         3   s1   |  ]' } |   j  k r |   j  | f Vq d  S(   N(   R   (   R&   t   k(   R   (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>|  s    (   R   R   t
   difference(   R   R+   R   R   R[   (    (   R   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   constructor_copys  s     c             s4   t  j j    t j d       f d   }  |  S(   s%   Return a threadsafe counter function.i   c              s*    j    z t    SWd   j   Xd  S(   N(   t   acquiret   nextt   release(    (   t   countert   lock(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   _next  s    
(   R   t	   threadingt   LockR=   t   count(   Rl  (    (   Rj  Rk  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRj    s    c         C   s   t  |  d  r> |  j d k	 r4 t |  j t  r4 t S|  j Sn  t |  t  rS t pV t } | |  t  rl t S| |  t  r t S| |  t  r t St  |  d  r t St  |  d  r t St  |  d  r t S| Sd S(   s   Given an instance or class, guess if it is or is acting as one of
    the basic collection types: list, set and dict.  If the __emulates__
    property is present, return that preferentially.
    t   __emulates__R2   RA   R<   N(	   R1   Rp  R   t
   issubclassR<   Rh   Ri   R   RT   (   t   specimenR   t   isa(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   duck_type_collection  s&    
c         C   s   t  |  |  r |  St  | t  rZ t j d | d j d   | D  t |   f   n" t j d | | t |   f   d  S(   Ns8   Argument '%s' is expected to be one of type %s, got '%s's    or c         s   s   |  ] } d  | Vq d S(   s   '%s'N(    (   R&   R  (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>  s    s6   Argument '%s' is expected to be of type '%s', got '%s'(   Rh   R3   R   t   ArgumentErrorR(   Ri   (   R   t   argtypeRM   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   assert_arg_type  s    /c            s  t  j r+ t   d  rc t   j    Sn8 t   d  rD   j   St   d  rc t   j    St   d t   d d
     d
 k r t	 d     n  t   d  r    f d   } |   St   d  r t  f d	     j
   D  St	 d     d
 S(   s?   Return a (key, value) iterator for almost any dict-like object.R   t	   iteritemst   __getitem__R   s   Object '%r' is not dict-liket   iterkeysc          3   s,   x%   j    D] }  |   |   f Vq Wd  S(   N(   Rz  (   R   (   t   dictliket   getter(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   iterator  s    R   c         3   s!   |  ] } |   |  f Vq d  S(   N(    (   R&   R   (   R|  (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys	   <genexpr>  s    N(   R   R   R1   R   R   Rx  t   iterRW   R   R   R   (   R{  R}  (    (   R{  R|  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s     	
 t   classpropertyc           B   s    e  Z d  Z d   Z d   Z RS(   sA  A decorator that behaves like @property except that operates
    on classes rather than instances.

    The decorator is currently special when using the declarative
    module, but note that the
    :class:`~.sqlalchemy.ext.declarative.declared_attr`
    decorator should be used for this purpose with declarative.

    c         O   s,   t  t |   j | | |  | j |  _ d  S(   N(   t   superR  R   R!   (   R   R  R   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    c         C   s   |  j  |  S(   N(   R  (   t   descR   R+   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s    (   R   R    R!   R   R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s   		t   hybridpropertyc           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    c         C   s?   | d  k r. |  j |  } |  j j | _ | S|  j |  Sd  S(   N(   R   R   R!   (   R   R%  t   ownert   clsval(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s
    (   R   R    R   R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s   	t   hybridmethodc           B   s    e  Z d  Z d   Z d   Z RS(   s/   Decorate a function as cls- or instance- level.c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    c         C   s9   | d  k r" |  j j | | j  S|  j j | |  Sd  S(   N(   R   R   R  R   (   R   R%  R  (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s    (   R   R    R!   R   R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s   	t   _symbolc           B   s2   e  Z d d d   Z d   Z d   Z d   Z RS(   c         C   sd   t  | t j  s t  | d k r3 t |  } n  t j t |  } | | _	 | r` | | _
 n  | S(   s   Construct a new named symbol.N(   Rh   R   RX  t   AssertionErrorR   t   hashR_  RD  R  RM   R!   (   R   RM   Ro   t	   canonicalt   v(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRD    s    	c         C   s   t  |  j d t |   f f S(   NR
   (   Re   RM   R_  (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt
   __reduce__  s    c         C   s
   t  |   S(   N(   R   (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __str__  s    c         C   s   d |  j  S(   Ns
   symbol(%r)(   RM   (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __repr__  s    N(   R   R    R   RD  R  R  R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s   		Re   c           B   sD   e  Z d  Z i  Z e j j   Z d d d  Z	 e
 e d   Z RS(   s  A constant symbol.

    >>> symbol('foo') is symbol('foo')
    True
    >>> symbol('foo')
    <symbol 'foo>

    A slight refinement of the MAGICCOOKIE=object() pattern.  The primary
    advantage of symbol() is its repr().  They are also singletons.

    Repeated calls of symbol('name') will all return the same instance.

    The optional ``doc`` argument assigns to ``__doc__``.  This
    is strictly so that Sphinx autoattr picks up the docstring we want
    (it doesn't appear to pick up the in-module docstring if the datamember
    is in a different module - autoattribute also blows up completely).
    If Sphinx fixes/improves this then we would no longer need
    ``doc`` here.

    c         C   sh   |  j  j   zF |  j j |  } | d  k rN t | | |  |  j | <} n  | SWd  t j  j   Xd  S(   N(   t   _lockRg  t   symbolsR   R   R  Re   Ri  (   R+   RM   Ro   R  RF   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRD  ?  s     c         C   s   xS | j    D]E \ } } | | k r) | S| rB | | j k rB | S| | k r | Sq W| d k rf d St j d | | f   d S(   s  Given a user parameter, parse the parameter into a chosen symbol.

        The user argument can be a string name that matches the name of a
        symbol, or the symbol object itself, or any number of alternate choices
        such as True/False/ None etc.

        :param arg: the user argument.
        :param choices: dictionary of symbol object to list of possible
         entries.
        :param name: name of the argument.   Used in an :class:`.ArgumentError`
         that is raised if the parameter doesn't match any available argument.
        :param resolve_symbol_names: include the name of each symbol as a valid
         entry.

        s   Invalid value for '%s': %rN(   R   RM   R   R   Ru  (   R+   R   t   choicesRM   t   resolve_symbol_namesRF   t   choice(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   parse_user_argumentI  s    N(   R   R    R!   R  R   Rm  Rn  R  R   RD  R  R#   R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRe   &  s   
c         C   s   t  |  _  t  d 7a  d S(   s   Assign a '_creation_order' sequence to the given instance.

    This allows multiple instances to be sorted in order of creation
    (typically within a single thread; the counter is not particularly
    threadsafe).

    i   N(   t   _creation_order(   R%  (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   set_creation_orderp  s    		c         O   sD   y |  | |   SWn, t  k
 r? t d t j   d d ! n Xd S(   sX   executes the given function, catches all exceptions and converts to
    a warning.

    s   %s('%s') ignoredi    i   N(   RR   R   R   R   (   R   R   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   warn_exception}  s    i   c         C   sB   y) t  |   | k r$ d |  d | !S|  SWn t k
 r= |  SXd  S(   Ns   %s...i    (   R   R   (   R   t   len_(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   ellipses_string  s    t   _hash_limit_stringc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s/  A string subclass that can only be hashed on a maximum amount
    of unique values.

    This is used for warnings so that we can send out parameterized warnings
    without the __warningregistry__ of the module,  or the non-overridable
    "once" registry within warnings.py, overloading memory,


    c         C   sT   | | d | } t  t |   j |  |  } t d | t |  | f  | _ | S(   Ns6    (this warning may be suppressed after %d occurrences)s   %s_%d(   R  R  RD  R  t   _hash(   R+   R   t   numR   t   interpolatedR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRD    s
    #c         C   s   |  j  S(   N(   R  (   R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __hash__  s    c         C   s   t  |   t  |  k S(   N(   R  (   R   t   other(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   __eq__  s    (   R   R    R!   RD  R  R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s   			c         C   s   t  j |  t j d d d S(   sd   Issue a warning.

    If msg is a string, :class:`.exc.SAWarning` is used as
    the category.

    t
   stackleveli   N(   t   warningsR   R   t	   SAWarning(   t   msg(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR     s    c         C   s8   | r t  |  d |  }  n  t j |  t j d d d S(   s\   Issue a warning with a parameterized string, limiting the number
    of registrations.

    i
   R  i   N(   R  R  R   R   R  (   R  R   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   warn_limited  s    c            s"     g      f d   } | S(   sN   Decorate the given function to be a no-op after it is called exactly
    once.c             sV     }  rR  j    } y | |  |   SWqR  rH  j d |  n    qR Xn  d  S(   Ni    (   R   t   insert(   R   R   t	   strong_fnt   once_fn(   RH   t   oncet   retry_on_exception(    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   go  s    (    (   RH   R  R  (    (   RH   R  R  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt	   only_once  s    	s%   sqlalchemy/([a-z_]+/){0,2}[a-z_]+\.pys   unit(?:2|test2?/)c         C   s   d } t  |   d } x- | | k rE | j |  |  rE | d 7} q Wx- | | k ru | j |  |  ru | d 8} qI W|  | | d !S(   st  Chop extraneous lines off beginning and end of a traceback.

    :param tb:
      a list of traceback lines as returned by ``traceback.format_stack()``

    :param exclude_prefix:
      a regular expression object matching lines to skip at beginning of
      ``tb``

    :param exclude_suffix:
      a regular expression object matching lines to skip at end of ``tb``
    i    i   (   R   t   search(   t   tbt   exclude_prefixt   exclude_suffixR.   t   end(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   chop_traceback  s    ""c         B   s)   d |  } e    j   } | | U| d S(   Ns&   def set(obj, value):    obj.%s = valueR<   (   R   t   copy(   t   attrnameR_   Rc   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt
   attrsetter  s    
t   EnsureKWArgTypec           B   s    e  Z d  Z d   Z d   Z RS(   sY   Apply translation of functions to accept \**kw arguments if they
    don't already.

    c   
      C   s   |  j  } | r xx | D]m } t j | |  } | r | | } t j |  } | j s |  j |  | | <}	 t |  | |	  q q q Wn  t t	 |   j
 | | |  d  S(   N(   t   ensure_kwargR)   t   matchR   RS   R   t
   _wrap_w_kwR   R  R  R   (
   R+   t   clsnameRD   t   clsdictt   fn_regR   R   RH   RZ   t   wrapped(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR      s    	
	c            s     f d   } t  |    S(   Nc             s
     |    S(   N(    (   R   R   (   RH   (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   wrap  s    (   R    (   R   RH   R  (    (   RH   s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s    (   R   R    R!   R   R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    s   	c         C   s   t  | d  r t |  |  S|  } | j j | _ t  | d  rO | j | _ n  t  | j d  r | j j r | j j | _ n | j r | j | _ n  | Sd S(   s   Augment functools.update_wrapper() to work with objects with
    a ``__call__()`` method.

    :param fn:
      object with __call__ method

    R   R    R!   N(   R1   R    R   R   R    R   R!   (   t   wrapperRH   t   _f(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   wrap_callable  s    	c         C   s!  d |  k r |  j  d  Sd } g  g } d } t |   } x | | k  r |  | } | d k r | d k r | | d k  r |  | d d k r | d j d  | d 7} q | d N} n9 | d k r | d k r | j g   n | d j |  | d 7} q= Wg  | D] } d j |  ^ qS(   s  Parse a dotted identifier with accommodation for quoted names.

    Includes support for SQL-style double quotes as a literal character.

    E.g.::

        >>> quoted_token_parser("name")
        ["name"]
        >>> quoted_token_parser("schema.name")
        ["schema", "name"]
        >>> quoted_token_parser('"Schema"."Name"')
        ['Schema', 'Name']
        >>> quoted_token_parser('"Schema"."Name""Foo"')
        ['Schema', 'Name""Foo']

    t   "Rd   i    i   iR;   (   Rj   R   R2   R(   (   R   R   R  t   idxt   lvt   charR   (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   quoted_token_parser,  s$    	
0c            s%   t  j         f d   } | S(   Nc            sS   |  j  d  k	 r |  j  p d } | rF t |  f d     D  } n  | |  _  |  S(   NR;   c            s   i  |  ] }   |  q S(    (    (   R&   t   param(   R\  (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pys
   <dictcomp>^  s   	 (   R!   R   t   inject_param_text(   RH   Ro   (   t   paramsR\  (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyRa   [  s
    "	(   R   R   (   R  R\  Ra   (    (   R  R\  s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   add_parameter_textX  s    c         C   si   |  j  d d  } t |  d k r( |  S| \ } } | j d  sX | d t j |  St j |   Sd  S(   Ns   
i   R$   (   Rj   R   R   t   textwrapt   dedent(   R\  t
   split_textt	   firstlinet	   remaining(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   _dedent_docstringe  s    c   	      C   s   t  |  p d  }  |  j d  } t j |  j d  } | d rV | j d d  n  g  t |  D] \ } } | j   sc | ^ qc } | j d d  | t | t |  d  } | d | !| | | } d j	 |  S(   NR;   s   
i    i   (
   R  Rj   R  R  R  R   RY  t   minR   R(   (	   t   doctextt
   injecttextt   post   linest   injectlinesR  t   linet   blankst
   inject_pos(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   inject_docstring_textq  s    
1c   
      C   s  |  j    } g  } d  } x| r| j d  } | d  k r t j d |  } | r| j d  } | | k r d t | j d   d } | r t j d | d  }	 |	 r d t |	 j d   } q n  | | | } q qn | j   j d  r)| j	 d  | j	 |  | j	 d  d  } nt | j
   se| j	 |  | j	 |  | j	 d  d  } n8 | j d	  r| j	 |  | j	 | j d   q n  | j	 |  q Wd j |  S(
   Ni    s   (\s+):param (?:\\\*\*?)?(.+?):i   R$   i   s   (\s+)\Ss   :param s   
s   ::(   t
   splitlinesR   R   R)   R  Rs   R   t   lstripR   R2   t   rstripR   R(   (
   R  t   inject_paramst   doclinesR  t	   to_injectR  R   R  t   indentt   m2(    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyR    sB    			(    (    ([   R!   t	   functoolsR    R   RO   R=   R
  R)   R   R  R   R  R;   R   R   R   R   R   R   R,   R6   RG   RJ   Rb   RV   Rq   Rr   R   R   R   R   R#   R   R   RU   R   R   R   R   R   R   R   R  R  R  R  R"  R#  R)  R2  R3  R[  R^  R`  Rc  Rf  Rj  Rt  Rw  R  RL  R  R  R  R_  R  R   Re   R  R  R  R  t	   text_typeR  R   R  R  t   compilet   _SQLA_REt   _UNITTEST_RER  Ri   t   NoneTypeR  R  R  R  R  R  R  R  (    (    (    s:   lib/python2.7/site-packages/sqlalchemy/util/langhelpers.pyt   <module>   s   	.								0*	+	6S		H	3	9	V	(u					!			G		
	
	
				,			