%PDF- %PDF-
Direktori : /opt/alt/python27/lib/python2.7/site-packages/paste/auth/ |
Current File : //opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyo |
� a�Nc @ s] d Z d e f d � � YZ e Z d g Z d e k rY d d l Z e j d e j � n d S( sh Authentication via Multiple Methods In some environments, the choice of authentication method to be used depends upon the environment and is not "fixed". This middleware allows N authentication methods to be registered along with a goodness function which determines which method should be used. The following example demonstrates how to use both form and digest authentication in a server stack; by default it uses form-based authentication unless ``*authmeth=digest`` is specified as a query argument. >>> from paste.auth import form, cookie, digest, multi >>> from paste.wsgilib import dump_environ >>> from paste.httpserver import serve >>> >>> multi = multi.MultiHandler(dump_environ) >>> def authfunc(environ, realm, user): ... return digest.digest_password(realm, user, user) >>> multi.add_method('digest', digest.middleware, "Test Realm", authfunc) >>> multi.set_query_argument('digest') >>> >>> def authfunc(environ, username, password): ... return username == password >>> multi.add_method('form', form.middleware, authfunc) >>> multi.set_default('form') >>> serve(cookie.middleware(multi)) serving on... t MultiHandlerc B sJ e Z d Z d � Z d � Z d � Z d � Z d d d � Z d � Z RS( s� Multiple Authentication Handler This middleware provides two othogonal facilities: - a manner to register any number of authentication middlewares - a mechanism to register predicates which cause one of the registered middlewares to be used depending upon the request If none of the predicates returns True, then the application is invoked directly without middleware c C s( | | _ | | _ i | _ g | _ d S( N( t applicationt defaultt bindingt predicate( t selfR ( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt __init__1 s c O s | | j | | � | j | <d S( N( R R ( R t namet factoryt argst kwargs( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt add_method6 s c C s! | j j | | j | f � d S( N( R t appendR ( R R t checker( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt add_predicate8 s c C s | j | | _ d S( s# set default authentication method N( R R ( R R ( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt set_default: s s *authmethc s3 d | | p | f � | j | � f d � � d S( s8 choose authentication method based on a query argument s %s=%sc s � | j d d � k S( Nt QUERY_STRINGt ( t get( t environ( t lookfor( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt <lambda>A s N( R ( R R t keyt value( ( R sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt set_query_argument= s c C sC x0 | j D]% \ } } | | � r | | | � Sq W| j | | � S( N( R R ( R R t start_responseR R ( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt __call__B s N( t __name__t __module__t __doc__R R R R t NoneR R ( ( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyR # s t __main__i����Nt optionflags( R t objectR t middlewaret __all__R t doctestt testmodt ELLIPSIS( ( ( sA /opt/alt/python27/lib/python2.7/site-packages/paste/auth/multi.pyt <module>! s %