;ò
!qlAc        	   @   sa  d  Z  d k l Z d d d !Z d k Z d k Z d k Z d k Z d k Z d k	 l
 Z
 l Z d k l Z l Z d k l Z l Z l Z d	 k l Z d
 k l Z d k l Z l Z l Z d „  Z d e i f d „  ƒ  YZ d Z d „  Z d „  Z  d „  Z! d Z" d e f d „  ƒ  YZ# d „  Z$ d Z% d Z& d k	 l' Z( d k) l* Z* e( i+ e( i, d d d d ƒ e( i- d d d  d! ƒ e( i, d" e. d# d$ ƒ ƒ Z/ d% e f d& „  ƒ  YZ0 e( i+ e( i, d' d d( d) ƒ e( i- d d d  d* ƒ e( i1 d+ d, d- d d f g d. d/ ƒƒ Z2 d0 k3 l4 Z4 l5 Z5 d1 e f d2 „  ƒ  YZ6 d3 k) l7 Z7 l8 Z8 e i9 e8 i: e e7 i; ƒ d S(4   s¢   Resource protection for Woven. If you wish to use twisted.cred to protect
your Woven application, you are probably most interested in
L{UsernamePasswordWrapper}.
(   s   nested_scopess   $Revision: 1.34 $i   iþÿÿÿN(   s   logs
   components(   s   Resources	   IResource(   s
   redirectTos   Redirects   DeferredResource(   s   addSlash(   s   reactor(   s   Unauthorizeds   LoginFaileds   UnauthorizedLoginc           C   s9   t  i d t t i ƒ  ƒ t t i ƒ  ƒ f ƒ i ƒ  Sd  S(   Ns   %s_%s(   s   md5s   news   strs   randoms   times	   hexdigest(    (    (    s   C:\Python\PL\PL2_guard.pys   _sessionCookie,   s    s   GuardSessionc           B   s   t  Z d  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   A user's session with a system.

    This utility class contains no functionality, but is used to
    represent a session.
    c         C   sa   t  i i |  ƒ | |  _ | |  _ g  |  _ t |  _ |  i	 d ƒ h  |  _
 h  |  _ |  i ƒ  d S(   s@   Initialize a session with a unique ID for that session.
        i<   N(   s
   componentss   Componentizeds   __init__s   selfs   guards   uids   expireCallbackss   Nones   checkExpiredIDs   setLifetimes   servicess   portalss   touch(   s   selfs   guards   uid(    (    s   C:\Python\PL\PL2_guard.pys   __init__5   s     						c         C   s0   |  i ƒ  | t j o |  Sn |  i | ƒ Sd  S(   N(   s   selfs   touchs	   interfaces   Nones   getComponent(   s   selfs	   interface(    (    s   C:\Python\PL\PL2_guard.pys   _getSelfB   s    
c         C   s-   |  i i | ƒ } | o | d Sn | Sd  S(   Ni   (   s   selfs   servicess   gets   services   x(   s   selfs   services   x(    (    s   C:\Python\PL\PL2_guard.pys   clientForServiceK   s    c         C   su   |  i i | ƒ o4 |  i | \ } } } | i | | ƒ |  i | =n' | | | f |  i | <| i | | ƒ | Sd  S(   N(   s   selfs   servicess   has_keys   services   ps   cs   is   detacheds   idents   perspectives   clients   attached(   s   selfs   idents   perspectives   clients   services   cs   is   p(    (    s   C:\Python\PL\PL2_guard.pys   setClientForServiceR   s    c         C   s   |  i i | ƒ Sd  S(   N(   s   selfs   portalss   gets   port(   s   selfs   port(    (    s   C:\Python\PL\PL2_guard.pys   resourceForPortal`   s    c         C   s(   |  i | ƒ | | f |  i | <| Sd  S(   N(   s   selfs   portalLogouts   ports   rsrcs   logouts   portals(   s   selfs   rsrcs   ports   logout(    (    s   C:\Python\PL\PL2_guard.pys   setResourceForPortalc   s    c         C   sV   |  i i | ƒ } | o9 | \ } } y | ƒ  Wn t i ƒ  n X|  i | =n d  S(   N(	   s   selfs   portalss   gets   ports   ps   rs   ls   logs   err(   s   selfs   ports   ls   ps   r(    (    s   C:\Python\PL\PL2_guard.pys   portalLogouth   s      c         C   s   | |  _  d S(   s`  Set the approximate lifetime of this session, in seconds.

        This is highly imprecise, but it allows you to set some general
        parameters about when this session will expire.  A callback will be
        scheduled each 'lifetime' seconds, and if I have not been 'touch()'ed
        in half a lifetime, I will be immediately expired.
        N(   s   lifetimes   self(   s   selfs   lifetime(    (    s   C:\Python\PL\PL2_guard.pys   setLifetimer   s     c         C   s   |  i i | ƒ d S(   sA   Call this callback when the session expires or logs out.
        N(   s   selfs   expireCallbackss   appends   callback(   s   selfs   callback(    (    s   C:\Python\PL\PL2_guard.pys   notifyOnExpire|   s     c         C   sˆ   t  i d |  i ƒ |  i i |  i =x0 |  i D]% } y | ƒ  Wq. t  i ƒ  q. Xq. Wg  |  _ |  i	 o |  i	 i
 ƒ  t |  _	 n d S(   s&   Expire/logout of the session.
        s   expired session %sN(   s   logs   msgs   selfs   uids   guards   sessionss   expireCallbackss   cs   errs   checkExpiredIDs   cancels   None(   s   selfs   c(    (    s   C:\Python\PL\PL2_guard.pys   expire   s     
 	
c         C   s   t  i  ƒ  |  _ d  S(   N(   s   times   selfs   lastModified(   s   self(    (    s   C:\Python\PL\PL2_guard.pys   touch   s    c         C   sœ   t  |  _ t i ƒ  |  i |  i d j o? |  i i i |  i	 ƒ o |  i
 ƒ  q˜ t i d |  i	 ƒ n0 t i d |  i ƒ t i |  i |  i ƒ |  _ d  S(   Ni   s   no session to expire: %ss2   session given the will to live for %s more seconds(   s   Nones   selfs   checkExpiredIDs   times   lastModifieds   lifetimes   guards   sessionss   has_keys   uids   expires   logs   msgs   reactors	   callLaters   checkExpired(   s   self(    (    s   C:\Python\PL\PL2_guard.pys   checkExpired“   s    	!c         C   s2   |  i i ƒ  } | i d ƒ o | d =n | Sd  S(   Ns   checkExpiredID(   s   selfs   __dict__s   copys   ds   has_key(   s   selfs   d(    (    s   C:\Python\PL\PL2_guard.pys   __getstate__Ÿ   s    c         C   s(   |  i i | ƒ |  i ƒ  |  i ƒ  d  S(   N(   s   selfs   __dict__s   updates   ds   touchs   checkExpired(   s   selfs   d(    (    s   C:\Python\PL\PL2_guard.pys   __setstate__¥   s    
(   s   __name__s
   __module__s   __doc__s   __init__s   Nones   _getSelfs   clientForServices   setClientForServices   resourceForPortals   setResourceForPortals   portalLogouts   setLifetimes   notifyOnExpires   expires   touchs   checkExpireds   __getstate__s   __setstate__(    (    (    s   C:\Python\PL\PL2_guard.pys   GuardSession/   s    							
	
					s   session-initc         C   s#   |  i | | _ | i i | _ d  S(   N(   s   wraps   sessionss   cooks   reqs   sessions   _getSelfs
   getSession(   s   wraps   reqs   cook(    (    s   C:\Python\PL\PL2_guard.pys   _setSession¬   s    c         O   s°   |  i i ƒ  } |  i ƒ  } |  i i | ƒ d i | ƒ } | d d j o | | } n | d | } |  i i ƒ  } | i | ƒ | o | d t i | d ƒ 7} n | Sd  S(   Ns   /iÿÿÿÿs   ?i   (   s   requests   prepaths   pops   pps
   prePathURLs   origs   appends   joins   ars   cs   rets   argss   copys   updates   kws   urllibs	   urlencode(   s   requests   ars   kws   pps   argss   cs   rets   orig(    (    s   C:\Python\PL\PL2_guard.pys
   urlToChild°   s    c         C   s5   t  t |  |  i h  | d <Ž ƒ } d | _ | Sd  S(   Ni   (   s   Redirects
   urlToChilds   requests   postpaths   garbages   rds   isLeaf(   s   requests   garbages   rd(    (    s   C:\Python\PL\PL2_guard.pys   redirectToSessionÄ   s    $	s   __session_key__s   SessionWrapperc           B   s,   t  Z d Z e d „ Z d „  Z d „  Z RS(   Ni  c         C   sJ   t  i |  ƒ | |  _ | t j o d t ƒ  } n | |  _ h  |  _ d  S(   Ns   woven_session_(	   s   Resources   __init__s   selfs   rsrcs   resources	   cookieKeys   Nones   _sessionCookies   sessions(   s   selfs   rsrcs	   cookieKey(    (    s   C:\Python\PL\PL2_guard.pys   __init__Ï   s    		c         C   s   t  t | ƒ | ƒ Sd  S(   N(   s
   redirectTos   addSlashs   request(   s   selfs   request(    (    s   C:\Python\PL\PL2_guard.pys   render×   s    c   	         sÊ  | i o t Sn | i |  i ƒ } t | t | g | i
 Œ ‰  ˆ  | _ ‡  d †  | _ | i t ƒ o | t t ƒ } | |  i j o t | d ƒ Sn |  i | i |  i ƒ | | j o t | d ƒ SqÆt |  | | ƒ |  i SnÝ | |  i j o' t |  | | ƒ t |  i | | ƒ Sn¦ | t j ov t ƒ  } | i |  i | d d ƒt |  | ƒ } |  i | <| i ƒ  t t | t | | i
 Œ ƒ } d | _! | Sn# t d „ | _" t |  i | | ƒ Sd  S(   Nc              s
   t  ˆ  ƒ S(   N(   s   Redirects   setupURL(    (   s   setupURL(    s   C:\Python\PL\PL2_guard.pys   <lambda>ã   s    s   __start_session__s   __session_just_started__s   paths   /i   c         C   s   t  S(   N(   s   None(   s	   interface(    (    s   C:\Python\PL\PL2_guard.pys   <lambda>  s    (#   s   requests   prepaths   Nones	   getCookies   selfs	   cookieKeys   cookies
   urlToChilds   INIT_SESSIONs   paths   postpaths   setupURLs   setupSessionURLs   setupSessions
   startswiths   SESSION_KEYs   lens   keys   sessionss   redirectToSessions   setLifetimes   sessionLifetimes   _setSessions   resources   getResources   _sessionCookies	   newCookies	   addCookies   GuardSessions   szs   checkExpireds   Redirects   rds   isLeafs
   getSession(	   s   selfs   paths   requests   szs	   newCookies   setupURLs   cookies   keys   rd(    (   s   setupURLs   C:\Python\PL\PL2_guard.pys   getChildÛ   s8    			
	(   s   __name__s
   __module__s   sessionLifetimes   Nones   __init__s   renders   getChild(    (    (    s   C:\Python\PL\PL2_guard.pys   SessionWrapperË   s   	c         C   sB   |  i o$ | i i d | i i ƒ  ƒ |  Sn |  i | | ƒ Sd  S(   Ni    (	   s   resources   isLeafs   requests   postpaths   inserts   prepaths   pops   getChildWithDefaults   path(   s   resources   paths   request(    (    s   C:\Python\PL\PL2_guard.pys   getResource  s    
s   perspective-inits   perspective-destroy(   s
   formmethod(   s   forms   identitys    s   Identitys    The unique name of your account.s   passwords   Passwords#   The creative name of your password.s   perspectives   PerspectivesH   (Optional) The name of the role within your account you wish to perform.s   PerspectiveWrapperc           B   s#   t  Z d  Z e d „ Z d „  Z RS(   s/  DEPRECATED.
    
    I am a wrapper that will restrict access to Resources based on a
    C{twisted.cred.service.Service}'s 'authorizer' and perspective list.

    Please note that I must be in turn wrapped by a SessionWrapper, since my
    login functionality requires a session to be established.
    c         C   sH   t  i d t d ƒ t i |  ƒ | |  _ | |  _ | |  _ | |  _	 d S(   sš  Create a PerspectiveWrapper.
        
        @type service: C{twisted.cred.service.Service}

        @type noAuthResource: C{Resource}

        @type authResourceFactory: a callable object

        @param authResourceFactory: This should be a function which takes as an
        argument perspective from 'service' and returns a
        C{Resource} instance.

        @param noAuthResource: This parameter is the C{Resource} that is used
        when the user is browsing this site anonymously.  Somewhere accessible
        from this should be a link to 'perspective-init', which will display a
        C{form.FormProcessor} that allows the user to log in.
        s*   Please use UsernamePasswordWrapper insteadi   N(
   s   warningss   warns   DeprecationWarnings   Resources   __init__s   selfs   services   noAuthResources   authResourceFactorys   callback(   s   selfs   services   noAuthResources   authResourceFactorys   callback(    (    s   C:\Python\PL\PL2_guard.pys   __init__:  s     			c            sá   | i ƒ  ‰ ˆ t j o | i ƒ  Sn | t j o5 t ‡  ‡ d † } t i	 t
 i | ƒ d ˆ  i ƒSnu | t j o' ˆ i t t t ˆ  i ƒ t d ƒ SnA ˆ i ˆ  i ƒ } | o t | | | ƒ Sn t ˆ  i | | ƒ Sd  S(   Nc            sL   ˆ i i i |  ƒ } | i ‡ ‡  ‡ d †  ƒ d „  } | i | ƒ | Sd  S(   Nc            s4   ˆ  i ˆ ƒ i ‡ ‡  d †  ƒ i ‡  ‡ ‡ d †  ƒ S(   Nc            s   ˆ i ˆ  i i ƒ S(   N(   s   idents   requestPerspectiveForServices   selfs   services   serviceName(   s   ign(   s   selfs   ident(    s   C:\Python\PL\PL2_guard.pys   <lambda>^  s    c            s"   ˆ i ˆ  |  ˆ i |  ƒ ˆ i ƒ S(   N(   s   ss   setClientForServices   idents   psps   selfs   authResourceFactorys   service(   s   psp(   s   idents   ss   self(    s   C:\Python\PL\PL2_guard.pys   <lambda>`  s   (   s   idents   verifyPlainPasswords   passwords   addCallback(   s   ident(   s   ss   passwords   self(   s   idents   C:\Python\PL\PL2_guard.pys   <lambda>\  s    c         C   s6   |  i t ƒ o t i t |  i ƒ ƒ ‚ n |  ‚ d  S(   N(   s   fs   traps   Unauthorizeds   fms   FormExceptions   strs   value(   s   f(    (    s   C:\Python\PL\PL2_guard.pys   loginFailured  s    (	   s   selfs   services
   authorizers   getIdentityRequests   identitys   idfrs   addCallbacks   loginFailures
   addErrback(   s   identitys   passwords   perspectives   idfrs   loginFailure(   s   selfs   s(   s   passwords   C:\Python\PL\PL2_guard.pys   loginMethodY  s
    		s   callbacks   .(   s   requests
   getSessions   ss   Nones   setupSessions   paths   INIT_PERSPECTIVEs   loginMethods   forms   FormProcessors   loginSignatures   methods   selfs   callbacks   DESTROY_PERSPECTIVEs   setClientForServices   services   Redirects   clientForServices   scs   getResources   noAuthResource(   s   selfs   paths   requests   ss   loginMethods   sc(    (   s   selfs   ss   C:\Python\PL\PL2_guard.pys   getChildS  s    (   s   __name__s
   __module__s   __doc__s   Nones   __init__s   getChild(    (    (    s   C:\Python\PL\PL2_guard.pys   PerspectiveWrapper0  s    s   usernames   Usernames   Your user name.s   Your password.s   submits   choicess   Logins	   allowNonei   (   s   UsernamePasswords	   Anonymouss   UsernamePasswordWrapperc           B   s/   t  Z d  Z e e d „ Z d „  Z d „  Z RS(   s  I bring a C{twisted.cred} Portal to the web. Use me to provide different Resources
    (usually entire pages) based on a user's authentication details.

    A C{UsernamePasswordWrapper} is a
    L{Resource<twisted.web.resource.Resource>}, and is usually wrapped in a
    L{SessionWrapper} before being inserted into the site tree.

    The L{Realm<twisted.cred.portal.IRealm>} associated with your
    L{Portal<twisted.cred.portal.Portal>} should be prepared to accept a
    request for an avatar that implements the L{twisted.web.resource.IResource}
    interface. This avatar should probably be something like a Woven
    L{Page<twisted.web.woven.page.Page>}. That is, it should represent a whole
    web page. Once you return this avatar, requests for it's children do not go
    through guard.

    If you want to determine what unauthenticated users see, make sure your
    L{Portal<twisted.cred.portal.Portal>} has a checker associated that allows
    anonymous access. (See L{twisted.cred.checkers.AllowAnonymousAccess})
    
    c         C   s,   t  i |  ƒ | |  _ | |  _ | |  _ d S(   s¢  Constructs a UsernamePasswordWrapper around the given portal.

        @param portal: A cred portal for your web application. The checkers
            associated with this portal must be able to accept username/password
            credentials.
        @type portal: L{twisted.cred.portal.Portal}
        
        @param callback: Gets called after a successful login attempt.
            A resource that redirects to "." will display the avatar resource.
            If this parameter isn't provided, defaults to a standard Woven
            "Thank You" page.
        @type callback: A callable that accepts a Woven
            L{model<twisted.web.woven.interfaces.IModel>} and returns a
            L{IResource<twisted.web.resource.Resource>}.

        @param errback: Gets called after a failed login attempt.
            If this parameter is not provided, defaults to a the standard Woven
            form error (i.e. The original form on a page of its own, with
            errors noted.)
        @type errback: A callable that accepts a Woven
            L{model<twisted.web.woven.interfaces.IModel>} and returns a
            L{IResource<twisted.web.resource.Resource>}.
        N(   s   Resources   __init__s   selfs   portals   callbacks   errback(   s   selfs   portals   callbacks   errback(    (    s   C:\Python\PL\PL2_guard.pys   __init__—  s
     		c         C   s&   | i t t ƒ t i d d ƒ ‚ d  S(   Ns   passwords9   Login failed, please enter correct username and password.(   s   fs   traps   LoginFaileds   UnauthorizedLogins   fms   FormException(   s   selfs   f(    (    s   C:\Python\PL\PL2_guard.pys	   _ebFilter´  s    c            s  ˆ i ƒ  ‰ ˆ t j o ˆ i ƒ  Sn ˆ t j oM ‡  ‡ d †  ‰ t ‡  ‡ d † } t	 i
 t i | ƒ d ˆ  i d ˆ  i ƒSn” ˆ t j o ˆ i ˆ  i ƒ t d ƒ Sni ˆ i ˆ  i ƒ } | o t | d ˆ ˆ ƒ Sn8 t ˆ  i i t ƒ  t t ƒ i ‡  ‡ ‡ ‡ d †  ƒ ƒ Sd  S(   Nc            s)   |  \ } } } ˆ i | ˆ  i | ƒ d  S(   N(   s   results	   interfaces   avatarAspects   logouts   ss   setResourceForPortals   selfs   portal(   s   results   avatarAspects   logouts	   interface(   s   selfs   s(    s   C:\Python\PL\PL2_guard.pys   loginSuccess½  s    c            s8   ˆ  i i t |  | ƒ t t ƒ i ˆ ƒ i
 ˆ  i ƒ Sd  S(   N(   s   selfs   portals   logins   UsernamePasswords   usernames   passwords   Nones	   IResources   addCallbacks   loginSuccesss
   addErrbacks	   _ebFilter(   s   usernames   passwords   submit(   s   selfs   loginSuccess(    s   C:\Python\PL\PL2_guard.pys   triggerLoginÁ  s    s   callbacks   errbacks   .i    c            s1   |  \ } } } t ˆ i | ˆ  i | ƒ ˆ ˆ ƒ S(   N(
   s	   interfaces   avatarAspects   logouts   getResources   ss   setResourceForPortals   selfs   portals   paths   request(   s   .0s	   interfaces   avatarAspects   logout(   s   selfs   requests   ss   path(    s   C:\Python\PL\PL2_guard.pys   <lambda>ß  s   (   s   requests
   getSessions   ss   Nones   setupSessions   paths   INIT_PERSPECTIVEs   loginSuccesss   triggerLogins   forms   FormProcessors   newLoginSignatures   methods   selfs   callbacks   errbacks   DESTROY_PERSPECTIVEs   portalLogouts   portals   Redirects   resourceForPortals   rs   getResources   DeferredResources   logins	   Anonymouss	   IResources   addCallback(   s   selfs   paths   requests   triggerLogins   ss   rs   loginSuccess(    (   s   selfs   paths   requests   loginSuccesss   ss   C:\Python\PL\PL2_guard.pys   getChild¸  s     	(   s   __name__s
   __module__s   __doc__s   Nones   __init__s	   _ebFilters   getChild(    (    (    s   C:\Python\PL\PL2_guard.pys   UsernamePasswordWrapper  s    	(   s
   interfacess   utils(<   s   __doc__s
   __future__s   nested_scopess   __version__s   randoms   times   md5s   warningss   urllibs   twisted.pythons   logs
   componentss   twisted.web.resources   Resources	   IResources   twisted.web.utils
   redirectTos   Redirects   DeferredResources   twisted.web.statics   addSlashs   twisted.internets   reactors   twisted.cred.errors   Unauthorizeds   LoginFaileds   UnauthorizedLogins   _sessionCookies   Componentizeds   GuardSessions   INIT_SESSIONs   _setSessions
   urlToChilds   redirectToSessions   SESSION_KEYs   SessionWrappers   getResources   INIT_PERSPECTIVEs   DESTROY_PERSPECTIVEs
   formmethods   fms   twisted.web.wovens   forms   MethodSignatures   Strings   Passwords   Nones   loginSignatures   PerspectiveWrappers   Submits   newLoginSignatures   twisted.cred.credentialss   UsernamePasswords	   Anonymouss   UsernamePasswordWrappers
   interfacess   utilss   registerAdapters   WovenLivePages   IWovenLivePage((   s   Redirects   newLoginSignatures   reactors   INIT_SESSIONs   utilss   randoms   forms   DeferredResources   UsernamePasswordWrappers   GuardSessions   INIT_PERSPECTIVEs	   IResources   SESSION_KEYs   logs
   urlToChilds   urllibs	   Anonymouss   __version__s   md5s   DESTROY_PERSPECTIVEs   getResources   Resources   nested_scopess   warningss   loginSignatures
   interfacess   _setSessions   redirectToSessions   _sessionCookies   UsernamePasswords   fms   Unauthorizeds
   redirectTos   PerspectiveWrappers   addSlashs
   componentss   times   UnauthorizedLogins   SessionWrappers   LoginFailed(    (    s   C:\Python\PL\PL2_guard.pys   ?   sT   						{			O			G		*c