ó
ZËTc           @  sî  d  Z  d d l m Z d d l m Z d d l m Z d d d d d	 d
 d d d d d d d d g Z y& d d l m	 Z	 m
 Z
 d „  e
 _ Wn= e k
 rË d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 n Xd e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ d! e
 f d" „  ƒ  YZ d# e
 f d$ „  ƒ  YZ d% e f d& „  ƒ  YZ d' e f d( „  ƒ  YZ d) e
 f d* „  ƒ  YZ d+ e
 f d, „  ƒ  YZ d- e
 f d. „  ƒ  YZ d/ e f d0 „  ƒ  YZ d1 e f d2 „  ƒ  YZ d3 S(4   uÕ   
Built-in predicate checkers.

This is mostly took from repoze.what.precidates

This is module provides the predicate checkers that were present in the
original "identity" framework of TurboGears 1, plus others.

iÿÿÿÿ(   t   unicode_literals(   t   request(   t   unicode_textu	   Predicateu   CompoundPredicateu   Allu   Anyu   has_all_permissionsu   has_any_permissionu   has_permissionu   in_all_groupsu   in_any_groupu   in_groupu   is_useru   is_anonymousu   not_anonymousu   NotAuthorizedError(   t   NotAuthorizedErrort	   Predicatec         C  s   |  j  t j ƒ S(   N(   t   is_metR   t   environ(   t   self(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   <lambda>   s    R   c           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR      s   R   c           B  sJ   e  Z d d  „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z e Z	 RS(   c         C  s   | r | |  _  n  d  S(   N(   t   message(   R   t   msg(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   __init__    s    c         C  s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   R   t   credentials(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   evaluate$   s    c         K  sT   | r | } n	 |  j  } t | ƒ } |  j j ƒ  } | j | ƒ t | | ƒ ‚ d S(   uö  
            Raise an exception because this predicate is not met.

            :param msg: The error message to be used; overrides the predicate's
                default one.
            :type msg: str
            :raises NotAuthorizedError: If the predicate is not met.

            ``placeholders`` represent the placeholders for the predicate message.
            The predicate's attributes will also be taken into account while
            creating the message with its placeholders.
            N(   R   R   t   __dict__t   copyt   updateR   (   R   R   t   placeholdersR   t   all_placeholders(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   unmet'   s    		c         C  sA   | j  d i  ƒ } y |  j | | ƒ Wn t k
 r< ‚  n Xd S(   uÒ   
            Evaluate the predicate and raise an exception if it's not met.

            :param environ: The WSGI environment.
            :raise NotAuthorizedError: If it the predicate is not met.
            u   repoze.what.credentialsN(   t   getR   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   check_authorizationB   s
    c         C  sC   | j  d i  ƒ } y |  j | | ƒ t SWn t k
 r> t SXd S(   uÉ   
            Find whether the predicate is met or not.

            :param environ: The WSGI environment.
            :return: Whether the predicate is met or not.
            :rtype: bool
            u   repoze.what.credentialsN(   R   R   t   TrueR   t   False(   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   O   s    c         C  s   |  j  t j ƒ S(   N(   R   R   R   (   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   __nonzero__^   s    N(
   R	   R
   t   NoneR   R   R   R   R   R   t   __bool__(    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR      s   				t   CompoundPredicatec           B  s   e  Z d  Z d „  Z RS(   u)   A predicate composed of other predicates.c         O  s#   t  t |  ƒ j |   | |  _ d  S(   N(   t   superR   R   t
   predicates(   R   R    t   kwargs(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   e   s    (   R	   R
   t   __doc__R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   b   s   t   Notc           B  s&   e  Z d  Z d Z d „  Z d „  Z RS(   u·   
    Negate the specified predicate.

    :param predicate: The predicate to be negated.

    Example::

        # The user *must* be anonymous:
        p = Not(not_anonymous())

    u   The condition must not be metc         K  s#   t  t |  ƒ j |   | |  _ d  S(   N(   R   R#   R   t	   predicate(   R   R$   R!   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   x   s    c         C  s:   y |  j  j | | ƒ Wn t k
 r+ d  SX|  j ƒ  d  S(   N(   R$   R   R   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   |   s
    (   R	   R
   R"   R   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR#   j   s   	t   Allc           B  s   e  Z d  Z d „  Z RS(   u,  
    Check that all of the specified predicates are met.

    :param predicates: All of the predicates that must be met.

    Example::

        # Grant access if the current month is July and the user belongs to
        # the human resources group.
        p = All(is_month(7), in_group('hr'))

    c         C  s(   x! |  j  D] } | j | | ƒ q
 Wd S(   u÷   
        Evaluate all the predicates it contains.

        :param environ: The WSGI environment.
        :param credentials: The :mod:`repoze.what` ``credentials``.
        :raises NotAuthorizedError: If one of the predicates is not met.

        N(   R    R   (   R   R   R   t   p(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   ’   s    	(   R	   R
   R"   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR%   „   s   t   Anyc           B  s   e  Z d  Z d Z d „  Z RS(   u$  
    Check that at least one of the specified predicates is met.

    :param predicates: Any of the predicates that must be met.

    Example::

        # Grant access if the currest user is Richard Stallman or Linus
        # Torvalds.
        p = Any(is_user('rms'), is_user('linus'))

    uK   At least one of the following predicates must be met: %(failed_predicates)sc         C  s~   g  } xR |  j  D]G } y | j | | ƒ d SWq t k
 rV } | j t | ƒ ƒ q Xq Wd j | ƒ } |  j d | ƒ d S(   uô   
        Evaluate all the predicates it contains.

        :param environ: The WSGI environment.
        :param credentials: The :mod:`repoze.what` ``credentials``.
        :raises NotAuthorizedError: If none of the predicates is met.

        Nu   , t   failed_predicates(   R    R   R   t   appendR   t   joinR   (   R   R   R   t   errorsR&   t   excR(   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   ®   s    	(   R	   R
   R"   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR'   Ÿ   s   t   is_userc           B  s&   e  Z d  Z d Z d „  Z d „  Z RS(   uÂ   
    Check that the authenticated user's username is the specified one.

    :param user_name: The required user name.
    :type user_name: str

    Example::

        p = is_user('linus')

    u(   The current user must be "%(user_name)s"c         K  s#   t  t |  ƒ j |   | |  _ d  S(   N(   R   R-   R   t	   user_name(   R   R.   R!   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   Ñ   s    c         C  s0   | r" |  j  | j d ƒ k r" d  S|  j ƒ  d  S(   Nu   repoze.what.userid(   R.   R   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   Õ   s    (   R	   R
   R"   R   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR-   Â   s   	t   in_groupc           B  s&   e  Z d  Z d Z d „  Z d „  Z RS(   u×   
    Check that the user belongs to the specified group.

    :param group_name: The name of the group to which the user must belong.
    :type group_name: str

    Example::

        p = in_group('customers')

    u:   The current user must belong to the group "%(group_name)s"c         K  s#   t  t |  ƒ j |   | |  _ d  S(   N(   R   R/   R   t
   group_name(   R   R0   R!   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   ë   s    c         C  s0   | r" |  j  | j d ƒ k r" d  S|  j ƒ  d  S(   Nu   groups(   R0   R   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   ï   s    (   R	   R
   R"   R   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR/   Ü   s   	t   in_all_groupsc           B  s   e  Z d  Z d „  Z RS(   uÓ   
    Check that the user belongs to all of the specified groups.

    :param groups: The name of all the groups the user must belong to.

    Example::

        p = in_all_groups('developers', 'designers')

    c         O  s<   g  | D] } t  | ƒ ^ q } t t |  ƒ j | | Ž  d  S(   N(   R/   R   R1   R   (   R   t   groupsR!   t   gt   group_predicates(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR     s    (   R	   R
   R"   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR1   õ   s   
t   in_any_groupc           B  s   e  Z d  Z d Z d „  Z RS(   uÕ   
    Check that the user belongs to at least one of the specified groups.

    :param groups: The name of any of the groups the user may belong to.

    Example::

        p = in_any_group('directors', 'hr')

    uN   The member must belong to at least one of the following groups: %(group_list)sc         O  sN   d j  | ƒ |  _ g  | D] } t | ƒ ^ q } t t |  ƒ j | | Ž  d  S(   Nu   , (   R*   t
   group_listR/   R   R5   R   (   R   R2   R!   R3   R4   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR     s    (   R	   R
   R"   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR5     s   
t   is_anonymousc           B  s   e  Z d  Z d Z d „  Z RS(   u¢   
    Check that the current user is anonymous.

    Example::

        # The user must be anonymous!
        p = is_anonymous()

    .. versionadded:: 1.0.7

    u"   The current user must be anonymousc         C  s   | r |  j  ƒ  n  d  S(   N(   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   *  s    (   R	   R
   R"   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR7     s   t   not_anonymousc           B  s   e  Z d  Z d Z d „  Z RS(   u›   
    Check that the current user has been authenticated.

    Example::

        # The user must have been authenticated!
        p = not_anonymous()

    u-   The current user must have been authenticatedc         C  s   | s |  j  ƒ  n  d  S(   N(   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   <  s    (   R	   R
   R"   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR8   /  s   	t   has_permissionc           B  s&   e  Z d  Z d Z d „  Z d „  Z RS(   uÙ   
    Check that the current user has the specified permission.

    :param permission_name: The name of the permission that must be granted to
        the user.

    Example::

        p = has_permission('hire')

    u7   The user must have the "%(permission_name)s" permissionc         K  s#   t  t |  ƒ j |   | |  _ d  S(   N(   R   R9   R   t   permission_name(   R   R:   R!   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   O  s    c         C  s0   | r" |  j  | j d ƒ k r" d  S|  j ƒ  d  S(   Nu   permissions(   R:   R   R   (   R   R   R   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   S  s    (   R	   R
   R"   R   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR9   A  s   	t   has_all_permissionsc           B  s   e  Z d  Z d „  Z RS(   u  
    Check that the current user has been granted all of the specified
    permissions.

    :param permissions: The names of all the permissions that must be
        granted to the user.

    Example::

        p = has_all_permissions('view-users', 'edit-users')

    c         O  s<   g  | D] } t  | ƒ ^ q } t t |  ƒ j | | Ž  d  S(   N(   R9   R   R;   R   (   R   t   permissionsR!   R&   t   permission_predicates(    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   h  s    (   R	   R
   R"   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR;   Z  s   t   has_any_permissionc           B  s   e  Z d  Z d Z d „  Z RS(   u  
    Check that the user has at least one of the specified permissions.

    :param permissions: The names of any of the permissions that have to be
        granted to the user.

    Example::

        p = has_any_permission('manage-users', 'edit-users')

    uQ   The user must have at least one of the following permissions: %(permission_list)sc         O  sN   d j  | ƒ |  _ g  | D] } t | ƒ ^ q } t t |  ƒ j | | Ž  d  S(   Nu   , (   R*   t   permission_listR9   R   R>   R   (   R   R<   R!   R&   R=   (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR   }  s    (   R	   R
   R"   R   R   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyR>   n  s   N(   R"   t
   __future__R    t   tgR   t
   tg._compatR   t   __all__t   repoze.what.predicatesR   R   R   t   ImportErrort	   Exceptiont   objectR   R#   R%   R'   R-   R/   R1   R5   R7   R8   R9   R;   R>   (    (    (    sk   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/predicates.pyt   <module>
   s4   	C#