Ñò ˜â®Ic @s¶dZddkZddkZddklZddklZlZddklZddk l Z ddgZ d e fd „ƒYZ de fd „ƒYZde fd „ƒYZdS( 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(trequesttresponse(tabort(tNotAuthorizedErrortActionProtectortControllerProtectort_BaseProtectionDecoratorcBseZdZdd„ZRS(cCs ||_|p|i|_dS(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 predicatetdefault_denial_handlertdenial_handler(tselfRR ((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyt__init__(s N(t__name__t __module__tNoneR R (((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR$scBs eZdZd„Zd„ZRS(sá Function decorator to set predicate checkers in Pylons/TG2 controller actions. .. attribute:: default_denial_handler = None :type: callable The default denial handler. cCst|i|ƒS(sW Return :meth:`wrap_action` as the decorator for ``action_``. (Rt wrap_action(R taction_((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyt__call__FscOsœy|iitiƒWnutj oi}t|ƒ}tiidƒo d}nd}|io|t_ |i|ƒSt |d|ƒnX|||Ž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. srepoze.who.identityi“i‘tcomment( Rtcheck_authorizationRtenvironRtunicodetgetR RtstatusR(R Rtargstkwargstetreasontcode((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyRMs    (R Rt__doc__RR(((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR9s  cBs8eZdZeZd„Zd„Zd„Zd„ZRS(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__``. cCs/ti|ƒo|i|ƒS|i|ƒSdS(s~ Add the :attr:`protector` decorator to the ``__before__`` method of the ``cls`` controller. N(tinspecttisclasstdecorate_classtdecorate_instance(R tcls((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR–scCs4|i}|i|ƒ}ti|||ƒ|_|S(s7Decorate the ``__before__`` method of a class instance.(t __class__tmake_wrapped_methodtnewtinstancemethodt __before__(R tobjR#t new_before((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR"¢s cCs|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!©scCst|iƒp|idjo |i}nt||iƒ}t|dƒo|ii}nd„}d|_|i|i |ƒ}||ƒS(s=Decorate the ``__before__`` method with the defined protectorR(c_sdS(N((RR((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyt old_before¸sN( tcallableR RtgetattrthasattrR(tim_funcR t protectorR(R R#R R+R0((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyR%®s    ( R RRRR0RR"R!R%(((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyRys   (RRR&RtpylonsRRtpylons.controllers.utilRtrepoze.what.predicatesRt__all__tobjectRRR(((sK/usr/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/protectors.pyts   @