Ñò ˜â®Ic @ s¶ d Z d d k Z d d k Z d d k l Z d d k l Z l Z d d k l Z d d k l Z d d g Z d e f d „ ƒ YZ d e f d „ ƒ YZ d e f d „ ƒ YZ d S( sÍ Decorators to control access to controllers and controller actions in a Pylons or TurboGears 2 application. All these utilities are also available in the :mod:`repoze.what.plugins.pylonshq` namespace. iÿÿÿÿN( t decorator( t requestt response( t abort( t NotAuthorizedErrort ActionProtectort ControllerProtectort _BaseProtectionDecoratorc B s e Z d Z d d „ Z RS( c C s | | _ | p | i | _ d S( sÄ Make :mod:`repoze.what` verify that the predicate is met. :param predicate: A :mod:`repoze.what` predicate. :param denial_handler: The callable to be run if authorization is denied (overrides :attr:`default_denial_handler` if defined). If called, ``denial_handler`` will be passed a positional argument which represents a message on why authorization was denied. N( t predicatet default_denial_handlert denial_handler( t selfR R ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyt __init__( s N( t __name__t __module__t NoneR R ( ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR $ s c B s e Z d Z d „ Z d „ Z RS( sá Function decorator to set predicate checkers in Pylons/TG2 controller actions. .. attribute:: default_denial_handler = None :type: callable The default denial handler. c C s t | i | ƒ S( sW Return :meth:`wrap_action` as the decorator for ``action_``. ( R t wrap_action( R t action_( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyt __call__F s c O sœ y | i i t i ƒ Wnu t j oi } t | ƒ } t i i d ƒ o d } n d } | i o | t _ | i | ƒ St | d | ƒn X| | | Ž S( s Wrap the controller action ``action_``. :param action_: The controller action to be wrapped. ``args`` and ``kwargs`` are the positional and named arguments which will be passed to ``action_`` when called. It will run ``action_`` if and only if authorization is granted (i.e., the predicate is met). Otherwise, it will set the HTTP status code (to 401 if the user is anonymous or 403 if authenticated) then, if defined, it will run the denial handler (if not, it will abort with :func:`pylons.controllers.util.abort`). It's worth noting that when the status code for the response is 401, that will trigger a :mod:`repoze.who` challenger (e.g., a login form will be displayed). .. note:: If you want to override the default behavior when authorization is denied (most likely), you should define just a denial handler. If you want to override the whole wrapper (very unlikely), it's safe to extend this class and override this method. s repoze.who.identityi“ i‘ t comment( R t check_authorizationR t environR t unicodet getR R t statusR ( R R t argst kwargst et reasont code( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR M s ( R R t __doc__R R ( ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR 9 s c B s8 e Z d Z e Z d „ Z d „ Z d „ Z d „ Z RS( sg Class decorator to set predicate checkers in Pylons/TG2 controllers. .. attribute:: default_denial_handler = None :type: callable or str The default denial handler to be passed to :attr:`protector`. When it's set as a string, the resulting handler will be the attribute of the controller class whose name is represented by ``default_denial_handler``. For example, if ``default_denial_handler`` equals ``"process_errors"`` and the decorated controller is ``NiceController``, the resulting denial handler will be: ``NiceController.process_errors``. .. attribute:: protector = ActionProtector :type: Subclass of :class:`ActionProtector` The action protection decorator to be added to ``Controller.__before__``. c C s/ t i | ƒ o | i | ƒ S| i | ƒ Sd S( s~ Add the :attr:`protector` decorator to the ``__before__`` method of the ``cls`` controller. N( t inspectt isclasst decorate_classt decorate_instance( R t cls( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR – s c C s4 | i } | i | ƒ } t i | | | ƒ | _ | S( s7 Decorate the ``__before__`` method of a class instance.( t __class__t make_wrapped_methodt newt instancemethodt __before__( R t objR# t new_before( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR" ¢ s c C s | i | ƒ | _ | S( s. Decorate the ``__before__`` method of a class.( R% R( ( R R# ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR! © s c C s t | i ƒ p | i d j o | i } n t | | i ƒ } t | d ƒ o | i i } n d „ } d | _ | i | i | ƒ } | | ƒ S( s= Decorate the ``__before__`` method with the defined protectorR( c _ s d S( N( ( R R ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyt old_before¸ s N( t callableR R t getattrt hasattrR( t im_funcR t protectorR ( R R# R R+ R0 ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR% ® s ( R R R R R0 R R" R! R% ( ( ( sK /usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR y s ( R R R&