Ñò »Ic @ s³ d Z d d k l Z l Z d d d d d d d d d d d d d d d g Z 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 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# S($ s¥ Built-in predicate checkers. This is module provides the predicate checkers that were present in the original "identity" framework of TurboGears 1, plus others. iÿÿÿÿ( t parse_formvarst parse_dict_querystringt Predicatet CompoundPredicatet Allt Anyt has_all_permissionst has_any_permissiont has_permissiont in_all_groupst in_any_groupt in_groupt is_usert is_anonymoust not_anonymoust PredicateErrort NotAuthorizedErrorc B s\ e Z d Z d d „ Z d „ Z d „ Z d „ Z d d „ Z d „ Z d „ Z d „ Z RS( s– Generic predicate checker. This is the base predicate class. It won't do anything useful for you, unless you subclass it. c C s | o | | _ n d S( sB Create a predicate and use ``msg`` as the error message if it fails. :param msg: The error message, if you want to override the default one defined by the predicate. :type msg: str You may use the ``msg`` keyword argument with any predicate. N( t message( t selft msg( ( s: /usr/lib/python2.6/site-packages/repoze/what/predicates.pyt __init__/ s c C s | i | ƒ d S( sò Raise an exception if the predicate is not met. :param environ: The WSGI environment. :type environ: dict :param credentials: The :mod:`repoze.what` ``credentials`` dictionary as a short-cut. :type credentials: dict :raise NotImplementedError: When the predicate doesn't define this method. :raises NotAuthorizedError: If the predicate is not met (use :meth:`unmet` to raise it). This is the method that must be overridden by any predicate checker. For example, if your predicate is "The current month is the specified one", you may define the following predicate checker:: from datetime import date from repoze.what.predicates import Predicate class is_month(Predicate): message = 'The current month must be %(right_month)s' def __init__(self, right_month, **kwargs): self.right_month = right_month super(is_month, self).__init__(**kwargs) def evaluate(self, environ, credentials): today = date.today() if today.month != self.right_month: # Raise an exception because the predicate is not met. self.unmet() .. versionadded:: 1.0.2 .. attention:: Do not evaluate predicates by yourself using this method. See :meth:`check_authorization` and :meth:`is_met`. .. warning:: To make your predicates thread-safe, keep in mind that they may be instantiated at module-level and then shared among many threads, so avoid predicates from being modified after their evaluation. This is, the ``evaluate()`` method should not add, modify or delete any attribute of the predicate. N( t eval_with_environ( R t environt credentials( ( s: /usr/lib/python2.6/site-packages/repoze/what/predicates.pyt evaluate= s 2c C s t ‚ d S( s Check whether the predicate is met. :param environ: The WSGI environment. :type environ: dict :return: Whether the predicate is met or not. :rtype: bool :raise NotImplementedError: This must be defined by the predicate itself. .. deprecated:: 1.0.2 Only :meth:`evaluate` will be used as of :mod:`repoze.what` v2. N( t NotImplementedError( R R ( ( s: /usr/lib/python2.6/site-packages/repoze/what/predicates.pyt _eval_with_environq s c C sK d d k l } d } | | t d d ƒ| i | ƒ p | i ƒ n d S( sç Make sure this predicate is met. :param environ: The WSGI environment. :raises NotAuthorizedError: If the predicate is not met. .. versionchanged:: 1.0.1 In :mod:`repoze.what`<1.0.1, this method returned a ``bool`` and set the ``error`` instance attribute of the predicate to the predicate message. .. deprecated:: 1.0.2 Define :meth:`evaluate` instead. iÿÿÿÿ( t warnsš Predicate._eval_with_environ(environ) is deprecated for forward compatibility with repoze.what v2; define Predicate.evaluate(environ, credentials) insteadt stackleveli N( t warningsR t DeprecationWarningR t unmet( R R R R ( ( s: /usr/lib/python2.6/site-packages/repoze/what/predicates.pyR ‚ s c K sV | o | } n | i } t | ƒ } | i i ƒ } | i | ƒ t | | ƒ ‚ d S( s 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. For example, if you have a predicate that checks that the current month is the specified one, where the predicate message is defined with two placeholders as in:: The current month must be %(right_month)s and it is %(this_month)s and the predicate has an attribute called ``right_month`` which represents the expected month, then you can use this method as in:: self.unmet(this_month=this_month) Then :meth:`unmet` will build the message using the ``this_month`` keyword argument and the ``right_month`` attribute as the placeholders for ``this_month`` and ``right_month``, respectively. So, if ``this_month`` equals ``3`` and ``right_month`` equals ``5``, the message for the exception to be raised will be:: The current month must be 5 and it is 3 If you have a context-sensitive predicate checker and thus you want to change the error message on evaluation, you can call :meth:`unmet` as:: self.unmet('%(this_month)s is not a good month', this_month=this_month) The exception raised would contain the following message:: 3 is not a good month .. versionadded:: 1.0.2 .. versionchanged:: 1.0.4 Introduced the ``msg`` argument. .. attention:: This method should only be called from :meth:`evaluate`. N( R t unicodet __dict__t copyt updateR ( R R t placeholdersR t all_placeholders( ( s: /usr/lib/python2.6/site-packages/repoze/what/predicates.pyR š s 5 c C s€ | i d ƒ } | i d h ƒ } y | i | | ƒ Wn0 t j o$ } | o | i d | ƒ ‚ n X| o | i d ƒ d S( sÈ 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. Example:: >>> from repoze.what.predicates import is_user >>> environ = gimme_the_environ() >>> p = is_user('gustavo') >>> p.check_authorization(environ) # ... repoze.what.predicates.NotAuthorizedError: The current user must be "gustavo" .. versionadded:: 1.0.4 Backported from :mod:`repoze.what` v2; deprecates :func:`repoze.what.authorize.check_authorization`. s repoze.who.loggers repoze.what.credentialsu Authorization denied: %ss Authorization grantedN( t getR R t info( R R t loggerR t error( ( s: /usr/lib/python2.6/site-packages/repoze/what/predicates.pyt check_authorizationÛ s c C sG | i d h ƒ } y | i | | ƒ t SWn t j o } t SXd S( s Find whether the predicate is met or not. :param environ: The WSGI environment. :return: Whether the predicate is met or not. :rtype: bool Example:: >>> from repoze.what.predicates import is_user >>> environ = gimme_the_environ() >>> p = is_user('gustavo') >>> p.is_met(environ) False .. versionadded:: 1.0.4 Backported from :mod:`repoze.what` v2. s repoze.what.credentialsN( R&