
    qhI                        S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJrJr  SS
KJrJrJr  SSKJrJrJrJrJrJr  SSKJr  \R<                  " \5      r Sr!Sr"Sr#SS/r$Sr%Sr&Sr'Sr( " S S\)5      r* " S S\*5      r+ " S S\)5      r, " S S\)5      r- " S S\-5      r. " S S\*5      r/ " S  S!\*5      r0 " S" S#\)5      r1 " S$ S%\)5      r2 " S& S'\)5      r3 " S( S)\)5      r4 " S* S+\45      r5 " S, S-\)5      r6 " S. S/\)5      r7 " S0 S1\85      r9 " S2 S3\85      r: " S4 S5\85      r; " S6 S7\85      r< " S8 S9\<5      r= " S: S;\95      r> " S< S=\95      r? " S> S?\95      r@g)@a  OpenID server protocol and logic.

Overview
========

    An OpenID server must perform three tasks:

        1. Examine the incoming request to determine its nature and validity.

        2. Make a decision about how to respond to this request.

        3. Format the response according to the protocol.

    The first and last of these tasks may performed by
    the L{decodeRequest<Server.decodeRequest>} and
    L{encodeResponse<Server.encodeResponse>} methods of the
    L{Server} object.  Who gets to do the intermediate task -- deciding
    how to respond to the request -- will depend on what type of request it
    is.

    If it's a request to authenticate a user (a X{C{checkid_setup}} or
    X{C{checkid_immediate}} request), you need to decide if you will assert
    that this user may claim the identity in question.  Exactly how you do
    that is a matter of application policy, but it generally involves making
    sure the user has an account with your system and is logged in, checking
    to see if that identity is hers to claim, and verifying with the user that
    she does consent to releasing that information to the party making the
    request.

    Examine the properties of the L{CheckIDRequest} object, optionally
    check L{CheckIDRequest.returnToVerified}, and and when you've come
    to a decision, form a response by calling L{CheckIDRequest.answer}.

    Other types of requests relate to establishing associations between client
    and server and verifying the authenticity of previous communications.
    L{Server} contains all the logic and data necessary to respond to
    such requests; just pass the request to L{Server.handleRequest}.


OpenID Extensions
=================

    Do you want to provide other information for your users
    in addition to authentication?  Version 2.0 of the OpenID
    protocol allows consumers to add extensions to their requests.
    For example, with sites using the U{Simple Registration
    Extension<http://openid.net/specs/openid-simple-registration-extension-1_0.html>},
    a user can agree to have their nickname and e-mail address sent to a
    site when they sign up.

    Since extensions do not change the way OpenID authentication works,
    code to handle extension requests may be completely separate from the
    L{OpenIDRequest} class here.  But you'll likely want data sent back by
    your extension to be signed.  L{OpenIDResponse} provides methods with
    which you can add data to it which can be signed with the other data in
    the OpenID signature.

    For example::

        # when request is a checkid_* request
        response = request.answer(True)
        # this will a signed 'openid.sreg.timezone' parameter to the response
        # as well as a namespace declaration for the openid.sreg namespace
        response.fields.setArg('http://openid.net/sreg/1.0', 'timezone', 'America/Los_Angeles')

    There are helper modules for a number of extensions, including
    L{Attribute Exchange<openid.extensions.ax>},
    L{PAPE<openid.extensions.pape>}, and
    L{Simple Registration<openid.extensions.sreg>} in the L{openid.extensions}
    package.

Stores
======

    The OpenID server needs to maintain state between requests in order
    to function.  Its mechanism for doing this is called a store.  The
    store interface is defined in C{L{openid.store.interface.OpenIDStore}}.
    Additionally, several concrete store implementations are provided, so that
    most sites won't need to implement a custom store.  For a store backed
    by flat files on disk, see C{L{openid.store.filestore.FileOpenIDStore}}.
    For stores based on MySQL or SQLite, see the C{L{openid.store.sqlstore}}
    module.


Upgrading
=========

From 1.0 to 1.1
---------------

    The keys by which a server looks up associations in its store have changed
    in version 1.2 of this library.  If your store has entries created from
    version 1.0 code, you should empty it.

From 1.1 to 2.0
---------------

    One of the additions to the OpenID protocol was a specified nonce
    format for one-way nonces.  As a result, the nonce table in the store
    has changed.  You'll need to run contrib/upgrade-store-1.1-to-2.0 to
    upgrade your store, or you'll encounter errors about the wrong number
    of columns in the oid_nonces table.

    If you've written your own custom store or code that interacts
    directly with it, you'll need to review the change notes in
    L{openid.store.interface}.

@group Requests: OpenIDRequest, AssociateRequest, CheckIDRequest,
    CheckAuthRequest

@group Responses: OpenIDResponse

@group HTTP Codes: HTTP_OK, HTTP_REDIRECT, HTTP_ERROR

@group Response Encodings: ENCODE_KVFORM, ENCODE_HTML_FORM, ENCODE_URL
    N)deepcopy)	cryptutil)oidutil)kvform)DiffieHellman)mkNonce)	TrustRootverifyReturnTo)Associationdefault_negotiatorgetSecretSize)MessageInvalidOpenIDNamespace	OPENID_NS
OPENID2_NSIDENTIFIER_SELECTOPENID1_URL_LIMIT)urinorm   i.  i  checkid_setupcheckid_immediate)zURL/redirect)z	HTML formc                       \ rS rSrSrSrSrg)OpenIDRequest   zlI represent an incoming OpenID request.

@cvar mode: the C{X{openid.mode}} of this request.
@type mode: str
N )__name__
__module____qualname____firstlineno____doc__mode__static_attributes__r       F/var/www/html/env/lib/python3.13/site-packages/openid/server/server.pyr   r      s    
 Dr#   r   c                   P    \ rS rSrSrSr/ SQrSS jr\\	4S j5       r
S rS	 rS
rg)CheckAuthRequest   a>  A request to verify the validity of a previous response.

@cvar mode: "X{C{check_authentication}}"
@type mode: str

@ivar assoc_handle: The X{association handle} the response was signed with.
@type assoc_handle: str
@ivar signed: The message with the signature which wants checking.
@type signed: L{Message}

@ivar invalidate_handle: An X{association handle} the client is asking
    about the validity of.  Optional, may be C{None}.
@type invalidate_handle: str

@see: U{OpenID Specs, Mode: check_authentication
    <http://openid.net/specs.bml#mode-check_authentication>}
check_authentication)identity	return_toresponse_nonceNc                 >    Xl         X l        X0l        [        U l        g)zConstruct me.

These parameters are assigned directly as class attributes, see
my L{class documentation<CheckAuthRequest>} for their descriptions.

@type assoc_handle: str
@type signed: L{Message}
@type invalidate_handle: str
N)assoc_handlesignedinvalidate_handler   	namespace)selfr-   r.   r/   s       r$   __init__CheckAuthRequest.__init__   s     )!2#r#   c                    U R                  U 5      nXl        UR                  5       Ul        UR	                  [
        S5      Ul        UR	                  [
        S5      Ul        UR                  b  UR                  c  Sn[        XUR                  U4-  S9eUR	                  [
        S5      Ul
        UR                  5       Ul        UR                  R                  [
        S5      (       a!  UR                  R                  [
        SS5        U$ )zConstruct me from an OpenID Message.

@param message: An OpenID check_authentication Message
@type message: L{openid.message.Message}

@returntype: L{CheckAuthRequest}
r-   sigz5%s request missing required parameter from message %stextr/   r!   id_res)__new__messagegetOpenIDNamespacer0   getArgr   r-   r5   ProtocolErrorr!   r/   copyr.   hasKeysetArg)klassr:   op_endpointr1   fmts        r$   fromMessageCheckAuthRequest.fromMessage   s     }}U# 335#NN9nE>>)U3%)9ICTYY4H.HII!(	;N!Olln
 ;;i00KKy&(;r#   c                    UR                  U R                  U R                  5      nUR                  U R                  SS9  [	        U 5      nU=(       a    S=(       d    SnUR
                  R                  [        SU5        U R                  (       aL  UR                  U R                  SS9nU(       d+  UR
                  R                  [        SU R                  5        U$ )a`  Respond to this request.

Given a L{Signatory}, I can check the validity of the signature and
the X{C{invalidate_handle}}.

@param signatory: The L{Signatory} to use to check the signature.
@type signatory: L{Signatory}

@returns: A response with an X{C{is_valid}} (and, if
   appropriate X{C{invalidate_handle}}) field.
@returntype: L{OpenIDResponse}
Tdumbtruefalseis_validFr/   )
verifyr-   r.   
invalidateOpenIDResponsefieldsr@   r   r/   getAssociation)r1   	signatoryrK   response	valid_strassocs         r$   answerCheckAuthRequest.answer   s     ##D$5$5t{{C 	T..T:!$'(&4W	y*i@!!,,&&U - 4E&&y2E'+'='=?r#   c           
          U R                   (       a  SU R                   < 3nOSnSU R                  R                  < SU R                  < SU R                  < SU R
                  < U< S3
nU$ )Nz invalidate?  <z	 handle: z sig: z
: signed: >)r/   	__class__r   r-   r5   r.   )r1   ihss      r$   __str__CheckAuthRequest.__str__   sT    !!!&*&<&<?BBNN##T%6%6$++ r#   )r-   r/   r:   r0   r5   r.   N)r   r   r   r   r    r!   required_fieldsr2   classmethodUNUSEDrD   rU   r^   r"   r   r#   r$   r&   r&      s9    " "DAO$ 06  <:r#   r&   c                   @    \ rS rSrSrSrSS/rS r\" \5      rS r	Sr
g	)
PlainTextServerSessioni  a  An object that knows how to handle association requests with no
session type.

@cvar session_type: The session_type for this association
    session. There is no type defined for plain-text in the OpenID
    specification, so we use 'no-encryption'.
@type session_type: str

@see: U{OpenID Specs, Mode: associate
    <http://openid.net/specs.bml#mode-associate>}
@see: AssociateRequest
no-encryption	HMAC-SHA1HMAC-SHA256c                     U " 5       $ r`   r   )clsunused_requests     r$   rD   "PlainTextServerSession.fromMessage  s	    ur#   c                 2    S[         R                  " U5      0$ )Nmac_key)r   toBase64)r1   secrets     r$   rU   PlainTextServerSession.answer   s    7++F344r#   r   N)r   r   r   r   r    session_typeallowed_assoc_typesrD   rb   rU   r"   r   r#   r$   re   re     s/     #L&6 k*K5r#   re   c                   h    \ rS rSrSrSr\" \R                  5      r	S/r
S rS r\" \5      rS rSrg	)
DiffieHellmanSHA1ServerSessioni$  a  An object that knows how to handle association requests with the
Diffie-Hellman session type.

@cvar session_type: The session_type for this association
    session.
@type session_type: str

@ivar dh: The Diffie-Hellman algorithm values for this request
@type dh: DiffieHellman

@ivar consumer_pubkey: The public key sent by the consumer in the
    associate request
@type consumer_pubkey: long

@see: U{OpenID Specs, Mode: associate
    <http://openid.net/specs.bml#mode-associate>}
@see: AssociateRequest
DH-SHA1rg   c                     Xl         X l        g r`   )dhconsumer_pubkey)r1   rx   ry   s      r$   r2   'DiffieHellmanSHA1ServerSession.__init__;  s    .r#   c                    UR                  [        S5      nUR                  [        S5      nUc  Uc  Uc  Ub  Uc  SnOSn[        USU< 35      eU(       d  U(       a8  [        R                  " U5      n[        R                  " U5      n[        X#5      nO[
        R                  " 5       nUR                  [        S5      nUc  [        USU< 35      e[        R                  " U5      nU " XV5      $ )z
@param message: The associate request message
@type message: openid.message.Message

@returntype: L{DiffieHellmanSHA1ServerSession}

@raises ProtocolError: When parameters required to establish the
    session are missing.

dh_modulusdh_genmodulus	generatorzPIf non-default modulus or generator is supplied, both must be supplied. Missing dh_consumer_publicz4Public key for DH-SHA1 session not found in message )r<   r   r=   r   base64ToLongr   fromDefaults)rj   r:   r|   r}   missingrx   ry   s          r$   rD   *DiffieHellmanSHA1ServerSession.fromMessage?  s     ^^I|<
	846#5&!#%AHLM M "//
;J++F3Fz2B++-B!..4HI"=D*H I I $00A2''r#   c                     U R                   R                  U R                  UU R                  5      n[        R
                  " U R                   R                  5      [        R                  " U5      S.$ )N)dh_server_publicenc_mac_key)	rx   	xorSecretry   	hash_funcr   longToBase64publicr   ro   )r1   rp   rn   s      r$   rU   %DiffieHellmanSHA1ServerSession.answeri  sW    ''##D$8$8&$(NN4 !* 6 6tww~~ F"++G4
 	
r#   )ry   rx   N)r   r   r   r   r    rr   staticmethodr   sha1r   rs   r2   rD   rb   rU   r"   r   r#   r$   ru   ru   $  s@    $ LY^^,I&-/&(P k*K
r#   ru   c                   B    \ rS rSrSr\" \R                  5      rS/r	Sr
g) DiffieHellmanSHA256ServerSessionir  	DH-SHA256rh   r   N)r   r   r   r   rr   r   r   sha256r   rs   r"   r   r#   r$   r   r   r  s    LY--.I(/r#   r   c                   l   ^  \ rS rSrSrSr\\\S.r	U 4S jr
\4S jr\" \5      rS r  S
S jrS	rU =r$ )AssociateRequestix  a  A request to establish an X{association}.

@cvar mode: "X{C{check_authentication}}"
@type mode: str

@ivar assoc_type: The type of association.  The protocol currently only
    defines one value for this, "X{C{HMAC-SHA1}}".
@type assoc_type: str

@ivar session: An object that knows how to handle association
    requests of a certain type.

@see: U{OpenID Specs, Mode: associate
    <http://openid.net/specs.bml#mode-associate>}
	associate)rf   rv   r   c                 X   > [         [        U ]  5         Xl        X l        [
        U l        g)zConstruct me.

The session is assigned directly as a class attribute. See my
L{class documentation<AssociateRequest>} for its description.
N)superr   r2   session
assoc_typer   r0   )r1   r   r   r[   s      r$   r2   AssociateRequest.__init__  s$     	.0$#r#   c                    UR                  5       (       a<  UR                  [        S5      nUS:X  a  [        R	                  S5        O-U(       d  SnO#UR                  [
        S5      nUc
  [        USS9e U R                  U   n UR                  U5      nUR                  [        S
S5      nXuR                  ;  a  Sn[        XX74-  5      eU " XW5      n	Xl        UR                  5       U	l        U	$ ! [         a    [        USU< 35      ef = f! [         a#  n[        USUR                  < S	U< 35      eSnAff = f)zConstruct me from an OpenID Message.

@param message: The OpenID associate request
@type message: openid.message.Message

@returntype: L{AssociateRequest}
rr   rf   z[Received OpenID 1 request with a no-encryption assocaition session type. Continuing anyway.Nz!session_type missing from requestr6   zUnknown session type zError parsing z
 session: r   rg   z4Session type %s does not support association type %s)	isOpenID1r<   r   loggerwarningr   r=   session_classesKeyErrorrD   
ValueErrorrr   rs   r:   r;   r0   )
rA   r:   rB   rr   session_classr   whyr   rC   r1   s
             r$   rD   AssociateRequest.fromMessage  s[    ">>)^DL.CD ".">>*nEL##"EG G	N!11,?M
	C#//8G
 ^^I|[I
888HC/I)IJJW) 335%  	N=I LN N	N  	C!.!;!;S*B C C	Cs$   6C3 D 3D
D>D99D>c                    [        U 5      nUR                  R                  [        [	        UR
                  5      U R                  UR                  S.5        UR                  R                  [        U R                  R                  UR                  5      5        U R                  R                  S:X  a  U R                  R                  5       (       d5  UR                  R                  [        SU R                  R                  5        U$ )a!  Respond to this request with an X{association}.

@param assoc: The association to send back.
@type assoc: L{openid.association.Association}

@returns: A response with the association information, encrypted
    to the consumer's X{public key} if appropriate.
@returntype: L{OpenIDResponse}
)
expires_inr   r-   rf   rr   )rN   rO   
updateArgsr   str	expiresInr   handler   rU   rp   rr   r:   r   r@   )r1   rT   rR   s      r$   rU   AssociateRequest.answer  s     "$'""9eoo.//!LL/
 	
 	""9#'<<#6#6u||#D	F ))_<&&(( OO""9n#'<<#<#<> r#   c                    U R                   R                  5       (       a  [        U R                   5      e[        U 5      nUR                  R                  [        SS5        UR                  R                  [        SU5        U(       a!  UR                  R                  [        SU5        U(       a!  UR                  R                  [        SU5        U$ )zjRespond to this request indicating that the association
type or association session type is not supported.
error_codezunsupported-typeerrorr   rr   )r:   r   r=   rN   rO   r@   r   )r1   r:   preferred_association_typepreferred_session_typerR   s        r$   answerUnsupported"AssociateRequest.answerUnsupported  s     <<!!##--!$'y,8JKy'7;%OO""9l#=? "OO""9n#9; r#   )r   r:   r0   r   )NN)r   r   r   r   r    r!   re   ru   r   r   r2   rc   rD   rb   rU   r   r"   __classcell__r[   s   @r$   r   r   x  sT      D 015O	$ 17 *X k*K< 6:15 r#   r   c                       \ rS rSrSr     SS jrS r\" \5      rS r	\
" \	5      r	S rS rS	 rSS
 jrS rS rS rSrg)CheckIDRequesti  a:  A request to confirm the identity of a user.

This class handles requests for openid modes X{C{checkid_immediate}}
and X{C{checkid_setup}}.

@cvar mode: "X{C{checkid_immediate}}" or "X{C{checkid_setup}}"
@type mode: str

@ivar immediate: Is this an immediate-mode request?
@type immediate: bool

@ivar identity: The OP-local identifier being checked.
@type identity: str

@ivar claimed_id: The claimed identifier.  Not present in OpenID 1.x
    messages.
@type claimed_id: str

@ivar trust_root: "Are you Frank?" asks the checkid request.  "Who wants
    to know?"  C{trust_root}, that's who.  This URL identifies the party
    making the request, and the user will use that to make her decision
    about what answer she trusts them to have.  Referred to as "realm" in
    OpenID 2.0.
@type trust_root: str

@ivar return_to: The URL to send the user agent back to to reply to this
    request.
@type return_to: str

@ivar assoc_handle: Provided in smart mode requests, a handle for a
    previously established association.  C{None} for dumb mode requests.
@type assoc_handle: str
Nc                    XPl         Xl        U=(       d    UU l        X l        U=(       d    UU l        X`l        U R
                  c   eU(       a  SU l        SU l        OSU l        SU l        U R                  b;  [        R                  " U R                  5      (       d  [        SU R                  5      eU R                  5       (       d!  [        SU R                  U R                  5      eSU l        g)zConstruct me.

These parameters are assigned directly as class attributes, see
my L{class documentation<CheckIDRequest>} for their descriptions.

@raises MalformedReturnURL: When the C{return_to} URL is not a URL.
NTr   Fr   )r-   r)   
claimed_idr*   
trust_rootrB   	immediater!   r	   parseMalformedReturnURLtrustRootValidUntrustedReturnURLr:   )r1   r)   r*   r   r   r-   rB   r   s           r$   r2   CheckIDRequest.__init__!  s     ) $0"$1	&+++!DN+DI"DN'DI>>%??4>>22$T4>>::""$$$T4>>4??KKr#   c                 j    [         R                  " S[        SS9  U R                  R	                  5       $ )NzmThe "namespace" attribute of CheckIDRequest objects is deprecated. Use "message.getOpenIDNamespace()" instead   
stacklevel)warningswarnDeprecationWarningr:   r;   r1   s    r$   _getNamespaceCheckIDRequest._getNamespaceE  s0     	 ||..00r#   c                    U R                  U 5      nXl        X#l        UR                  [        S5      nUS:X  a  SUl        SUl        OSUl        SUl        UR                  [        S5      Ul        UR                  5       (       a   UR                  (       d  Sn[        XU4-  S9eUR                  [        S	5      Ul
        UR                  [        S
5      Ul        UR                  5       (       a  UR                  c  Sn[        XS9eOZUR                  (       a  UR                  (       d  Sn[        XS9eUR                  (       a  UR                  (       d  Sn[        XS9eUR                  5       (       a  SnOSnUR                  [        U5      =(       d    UR                  Ul        UR                  5       (       d,  UR                  UR                  s=L a  c  O  O[        US5      eUR                  [        S5      Ul        UR                  b:  [        R                  " UR                  5      (       d  [!        XR                  5      eUR#                  5       (       d   [%        XR                  UR                  5      eU$ )a  Construct me from an OpenID message.

@raises ProtocolError: When not all required parameters are present
    in the message.

@raises MalformedReturnURL: When the C{return_to} URL is not a URL.

@raises UntrustedReturnURL: When the C{return_to} URL is outside
    the C{trust_root}.

@param message: An OpenID checkid_* request Message
@type message: openid.message.Message

@param op_endpoint: The endpoint URL of the server that this
    message was sent to.
@type op_endpoint: str

@returntype: L{CheckIDRequest}
r!   r   TFr   r*   z*Missing required field 'return_to' from %rr6   r)   r   z0OpenID 1 message did not contain openid.identityz?OpenID 2.0 message contained openid.identity but not claimed_idz?OpenID 2.0 message contained openid.claimed_id but not identityr   realmz2openid.realm required when openid.return_to absentr-   )r9   r:   rB   r<   r   r   r!   r*   r   r=   r)   r   r   r-   r	   r   r   r   r   )rA   r:   rB   r1   r!   rC   r]   trust_root_params           r$   rD   CheckIDRequest.fromMessageP  s
   ( }}U#&~~i0&&!DN+DI"DN'DI 	;?t~~>CWK.?@@y*=!..LA}}$F#G44 % }}T__"#G44 #G44 +&
 #>>)5EF *>> 	   ""~~88#MO O $NN9nE >>%??4>>22$Wnn== ""$$$WnndooNNr#   c                 (    U R                   [        :H  $ )z@Is the identifier to be selected by the IDP?

@returntype: bool
)r)   r   r   s    r$   idSelectCheckIDRequest.idSelect  s     }} 111r#   c                     U R                   (       d  g[        R                  " U R                   5      nUc   [        U R                  U R                   5      eU R
                  b  UR                  U R
                  5      $ g)z8Is my return_to under my trust_root?

@returntype: bool
T)r   r	   r   MalformedTrustRootr:   r*   validateURL)r1   trs     r$   r   CheckIDRequest.trustRootValid  sZ    
 __T__-:$T\\4??CC>>%>>$..11r#   c                 B    [        U R                  U R                  5      $ )ab  Does the relying party publish the return_to URL for this
response under the realm? It is up to the provider to set a
policy for what kinds of realms should be allowed. This
return_to URL verification reduces vulnerability to data-theft
attacks based on open proxies, cross-site-scripting, or open
redirectors.

This check should only be performed after making sure that the
return_to URL matches the realm.

@see: L{trustRootValid}

@raises openid.yadis.discover.DiscoveryFailure: if the realm
    URL does not support Yadis discovery (and so does not
    support the verification process).

@raises openid.fetchers.HTTPFetchingError: if the realm URL
    is not reachable.  When this is the case, the RP may be hosted
    on the user's intranet.

@returntype: bool

@returns: True if the realm publishes a document with the
    return_to URL listed

@since: 2.1.0
)r
   r   r*   r   s    r$   returnToVerifiedCheckIDRequest.returnToVerified  s    8 doot~~>>r#   c           
         U R                   c   eU R                  (       d  [        eU(       dK  U R                   R                  5       (       d   U R                  (       d  [        U < S35      eU R                  nU(       a  SnOLU R                   R                  5       (       a  U R                  (       a  SnOSnOU R                  (       a  SnOSn[        U 5      nU(       aH  U R                   R                  5       (       a)  U R                   R                  5       n[        SU< 35      eU(       Ga  U R                  [        :X  a   U(       d  [        S5      eUnU=(       d    Un	OU R                  (       as  U(       aS  U R                  U:w  aC  [        U R                  5      n
[        U5      nU
U:w  a  [        SU R                  < S	U< 35      eU R                  nU R                  n	OU(       a  [        S
U< 35      eSnU R                   R                  5       (       a  Uc  [        S5      eUR                  R!                  ["        UU R                  [%        5       S.5        U(       a!  UR                  R'                  ["        SU5        Uba  UR                  R'                  ["        SU5        U R                   R)                  5       (       a!  UR                  R'                  ["        SW	5        U$ UR                  R'                  ["        SU5        U R                  (       a  U R                   R                  5       (       a  U(       d  [        S5      eU R+                  U R                  U R                  U R,                  SU R.                  U R                  U R                  S9nU R                   Ul         UR1                  U5      nUR                  R'                  ["        SU5        U$ )a8  Respond to this request.

@param allow: Allow this user to claim this identity, and allow the
    consumer to have this information?
@type allow: bool

@param server_url: DEPRECATED.  Passing C{op_endpoint} to the
    L{Server} constructor makes this optional.

    When an OpenID 1.x immediate mode request does not succeed,
    it gets back a URL where the request may be carried out
    in a not-so-immediate fashion.  Pass my URL in here (the
    fully qualified address of this server's endpoint, i.e.
    C{http://example.com/server}), and I will use it as a base for the
    URL for a new request.

    Optional for requests where C{CheckIDRequest.immediate} is C{False}
    or C{allow} is C{True}.

@type server_url: str

@param identity: The OP-local identifier to answer with.  Only for use
    when the relying party requested identifier selection.
@type identity: str or None

@param claimed_id: The claimed identifier to answer with, for use
    with identifier selection in the case where the claimed identifier
    and the OP-local identifier differ, i.e. when the claimed_id uses
    delegation.

    If C{identity} is provided but this is not, C{claimed_id} will
    default to the value of C{identity}.  When answering requests
    that did not ask for identifier selection, the response
    C{claimed_id} will default to that of the request.

    This parameter is new in OpenID 2.0.
@type claimed_id: str or None

@returntype: L{OpenIDResponse}

@change: Version 2.0 deprecates C{server_url} and adds C{claimed_id}.

@raises NoReturnError: when I do not have a return_to.
NzJ should be constructed with op_endpoint to respond to OpenID 2.0 messages.r8   cancelsetup_neededz6claimed_id is new in OpenID 2.0 and not available for z`This request uses IdP-driven identifier selection.You must supply an identifier in the response.zRequest was for identity z, cannot reply with identity z4This request specified no identity and you supplied zHRequest was an OpenID 1 request, so response must include an identifier.)r!   r*   r+   rB   r)   r   r!   zCsetup_url is required for allow=False in OpenID 1.x immediate mode.F)r   r-   rB   r   user_setup_url)r:   r*   NoReturnToErrorr   rB   RuntimeErrorr   rN   r;   VersionErrorr)   r   r   r   r   rO   r   r   r   r@   	isOpenID2r[   r   r-   encodeToURL)r1   allow
server_urlr)   r   r!   rR   r0   response_identityresponse_claimed_idnormalized_request_identitynormalized_answer_identitysetup_request	setup_urls                 r$   rU   CheckIDRequest.answer  sA   Z ||'''~~!!<<))++D4D4D #$($, - - ))JD\\##%%~~~~%!$'$,,0022779I5> B C C }} 11$IJ J %-!&0&<H#(!:29$--2H/181B.367(26--KL L %)MM!&*oo#$)156 6 %)!||%%'',=,E -. . OO&&y!^^"))3  &&y-L ,&&y*'8:<<))++OO**9l+>@0 + OO""9fd;~~<<))++J$ &E F F !%MMNNOO#!%!2!2 $ 0 0# !/ !0 )-%)55jA	&&y2BINr#   c                     U R                   (       d  [        eU R                  U R                  U R                  U R                   S.nU R
                  (       a>  U R                  R                  5       (       a  U R
                  US'   OU R
                  US'   U R                  (       a  U R                  US'   [        U R                  R                  5       5      nUR                  [        U5        UR                  U5      $ )zEncode this request as a URL to GET.

@param server_url: URL of the OpenID server to make this request of.
@type server_url: str

@returntype: str

@raises NoReturnError: when I do not have a return_to.
)r!   r)   r   r*   r   r   r-   )r*   r   r!   r)   r   r   r:   r   r-   r   r;   r   r   toURL)r1   r   qrR   s       r$   r   CheckIDRequest.encodeToURL  s     ~~!! II//	
 ??||%%''"&//,!__'
 $ 1 1An4<<::<=Iq)~~j))r#   c                    U R                   (       d  [        eU R                  (       a  [        S5      e[	        U R
                  R                  5       5      nUR                  [        SS5        UR                  U R                   5      $ )a  Get the URL to cancel this request.

Useful for creating a "Cancel" button on a web form so that operation
can be carried out directly without another trip through the server.

(Except you probably want to make another trip through the server so
that it knows that the user did make a decision.  Or you could simulate
this method by doing C{.answer(False).encodeToURL()})

@returntype: str
@returns: The return_to URL with openid.mode = cancel.

@raises NoReturnError: when I do not have a return_to.
zACancel is not an appropriate response to immediate mode requests.r!   r   )
r*   r   r   r   r   r:   r;   r@   r   r   r1   rR   s     r$   getCancelURLCheckIDRequest.getCancelURL  sf     ~~!!>> 8 9 9 4<<::<=	684~~dnn--r#   c                     SU R                   R                  < SU R                  < SU R                  < SU R                  < SU R
                  < S3$ )NrY   z id:z im:z tr:z ah:rZ   )r[   r   r)   r   r   r-   r   s    r$   __repr__CheckIDRequest.__repr__  s4    NN##T]]DNNOOT..0 	0r#   )	r-   r   r)   r   r:   r!   rB   r*   r   )NFNNNNNN)r   r   r   r   r    r2   r   propertyr0   rD   rb   r   r   r   rU   r   r   r   r"   r   r#   r$   r   r     si     J ! "! "H1 'I]~ k*K2 ?<Yv!*F.40r#   r   c                   \    \ rS rSrSrS rS rSS jrSS jrS r	S	 r
S
 rS rS rS rSrg)rN   i  a  I am a response to an OpenID request.

@ivar request: The request I respond to.
@type request: L{OpenIDRequest}

@ivar fields: My parameters as a dictionary with each key mapping to
    one value.  Keys are parameter names with no leading "C{openid.}".
    e.g.  "C{identity}" and "C{mac_key}", never "C{openid.identity}".
@type fields: L{openid.message.Message}

@ivar signed: The names of the fields which should be signed.
@type signed: list of str
c                 D    Xl         [        UR                  5      U l        g)zIMake a response to an L{OpenIDRequest}.

@type request: L{OpenIDRequest}
N)requestr   r0   rO   r1   r   s     r$   r2   OpenIDResponse.__init__  s    
 g//0r#   c                     U R                   R                  < SU R                  R                   R                  < SU R                  < 3$ )Nz for : )r[   r   r   rO   r   s    r$   r^   OpenIDResponse.__str__  s4    "&.."9"9"&,,"8"8"A"A4;;P 	Pr#   Nc                 ^    U R                   R                  U R                  R                  US9$ )a1  Returns the form markup for this response.

@param form_tag_attrs: Dictionary of attributes to be added to
    the form tag. 'accept-charset' and 'enctype' have defaults
    that can be overridden. If a value is supplied for
    'action' or 'method', it will be replaced.

@returntype: str

@since: 2.1.0
)form_tag_attrs)rO   toFormMarkupr   r*   r1   r  s     r$   r  OpenIDResponse.toFormMarkup  s1     {{''LL""> ( C 	Cr#   c                 L    [         R                  " U R                  U5      5      $ )zReturns an HTML document that auto-submits the form markup
for this response.

@returntype: str

@see: toFormMarkup

@since: 2.1.?
r   autoSubmitHTMLr  r  s     r$   toHTMLOpenIDResponse.toHTML  s      %%d&7&7&GHHr#   c                 0    U R                  5       [        :H  $ )zReturns True if this response's encoding is
ENCODE_HTML_FORM.  Convenience method for server authors.

@returntype: bool

@since: 2.1.0
)whichEncodingENCODE_HTML_FORMr   s    r$   renderAsFormOpenIDResponse.renderAsForm  s     !!#'777r#   c                 H    U R                   R                  [        S5      S:H  $ )z7Does this response require signing?

@returntype: bool
r!   r8   )rO   r<   r   r   s    r$   needsSigningOpenIDResponse.needsSigning  s     
 {{!!)V4@@r#   c                     U R                   R                  [        ;   aO  U R                  R	                  5       [
        :X  a'  [        U R                  5       5      [        :  a  [        $ [        $ [        $ )zHow should I be encoded?

@returns: one of ENCODE_URL, ENCODE_HTML_FORM, or ENCODE_KVFORM.

@change: 2.1.0 added the ENCODE_HTML_FORM response.
)r   r!   BROWSER_REQUEST_MODESrO   r;   r   lenr   r   r  
ENCODE_URLENCODE_KVFORMr   s    r$   r  OpenIDResponse.whichEncoding  sU     << 55{{--/:=4##%&)::''!!  r#   c                 `    U R                   R                  U R                  R                  5      $ )zEncode a response as a URL for the user agent to GET.

You will generally use this URL with a HTTP redirect.

@returns: A URL to direct the user agent back to.
@returntype: str
)rO   r   r   r*   r   s    r$   r   OpenIDResponse.encodeToURL$  s#     {{  !7!788r#   c                 :    UR                  U R                  5        g)z
Add an extension response to this response message.

@param extension_response: An object that implements the
    extension interface for adding arguments to an OpenID
    message.
@type extension_response: L{openid.extension}

@returntype: None
N)	toMessagerO   )r1   extension_responses     r$   addExtensionOpenIDResponse.addExtension.  s     	$$T[[1r#   c                 6    U R                   R                  5       $ )a,  Encode a response in key-value colon/newline format.

This is a machine-readable format used to respond to messages which
came directly from the consumer and not through the user agent.

@see: OpenID Specs,
   U{Key-Value Colon/Newline format<http://openid.net/specs.bml#keyvalue>}

@returntype: str
)rO   toKVFormr   s    r$   encodeToKVFormOpenIDResponse.encodeToKVForm;  s     {{##%%r#   )rO   r   r`   )r   r   r   r   r    r2   r^   r  r  r  r  r  r   r  r!  r"   r   r#   r$   rN   rN     s=    *1PC
I8A! 92&r#   rN   c                   (    \ rS rSrSr\SS4S jrSrg)WebResponseiI  a^  I am a response to an OpenID request in terms a web server understands.

I generally come from an L{Encoder}, either directly or from
L{Server.encodeResponse}.

@ivar code: The HTTP code of this response.
@type code: int

@ivar headers: Headers to include in this response.
@type headers: dict

@ivar body: The body of this response.
@type body: str
Nr#   c                 |    Xl         Ub  X l        O0 U l        [        U[        5      (       a
  [	        USS9nX0l        g)zConstruct me.

These parameters are assigned directly as class attributes, see
my L{class documentation<WebResponse>} for their descriptions.
Nzutf-8)encoding)codeheaders
isinstancebytesr   body)r1   r'  r(  r+  s       r$   r2   WebResponse.__init__Y  s9     	"LDLdE""tg.D	r#   )r+  r'  r(  )r   r   r   r   r    HTTP_OKr2   r"   r   r#   r$   r$  r$  I  s     $T r#   r$  c                   P    \ rS rSrSrSrSrSrS rS r	S r
SS	 jrSS
 jrS rSrg)	Signatoryii  a)  I sign things.

I also check signatures.

All my state is encapsulated in an
L{OpenIDStore<openid.store.interface.OpenIDStore>}, which means
I'm not generally pickleable but I am easy to reconstruct.

@cvar SECRET_LIFETIME: The number of seconds a secret remains valid.
@type SECRET_LIFETIME: int
i u zhttp://localhost/|normalzhttp://localhost/|dumbc                     Uc   eXl         g)zCreate a new Signatory.

@param store: The back-end where my associations are stored.
@type store: L{openid.store.interface.OpenIDStore}
Nstore)r1   r2  s     r$   r2   Signatory.__init__  s        
r#   c           	         U R                  USS9nU(       d  [        R                  SU< SU< 35        g UR                  U5      nU$ ! [         a+  n[        R                  SU< SU< SU< 35         S	nAgS	nAff = f)
a>  Verify that the signature for some data is valid.

@param assoc_handle: The handle of the association used to sign the
    data.
@type assoc_handle: str

@param message: The signed message to verify
@type message: openid.message.Message

@returns: C{True} if the signature is valid, C{False} if not.
@returntype: bool
TrG   z failed to get assoc with handle z to verify message FzError in verifying z with r   N)rP   r   r   checkMessageSignaturer   	exception)r1   r-   r:   rT   validexs         r$   rL   Signatory.verify  s     ##Lt#<LL*6A B	//8E
 	  	&r3 4	s   A
 

A?!A::A?c                 R   [        U5      nUR                  R                  nU(       a  U R                  USSS9nU(       a  UR                  S::  av  UR
                  R                  [        SU5        U=(       a    UR                  =(       d    SnU(       a   UR                  S::  a  U R                  USS9  U R                  SUS9nOU R                  SS9n UR                  UR
                  5      Ul        U$ ! [        R                   a  n[        U[        U5      S	9eS
nAff = f)aZ  Sign a response.

I take a L{OpenIDResponse}, create a signature for everything
in its L{signed<OpenIDResponse.signed>} list, and return a new
copy of the response object with that signature included.

@param response: A response to sign.
@type response: L{OpenIDResponse}

@returns: A signed copy of the response.
@returntype: L{OpenIDResponse}
F)rH   checkExpirationr   r/   rg   rG   TrH   r   )explanationN)r   r   r-   rP   r   rO   r@   r   r   rM   createAssociationsignMessager   KVFormErrorEncodingErrorr   )r1   rR   signed_responser-   rT   r   errs          r$   signSignatory.sign  s$    #8,''44 ''5% ( AE EOOq0&&--i9L.:<"7u'7'7F;
U__1 OOLuO=..* / 6 ***5E	@%*%6%67M7M%NO"  !! 	@c#h??	@s    C: :D&D!!D&c                    [         R                  " [        U5      5      n[        R                  " [         R                  " S5      5      nSU[        [        R                  " 5       5      U4-  n[        R                  " U R                  XSU5      nU(       a  U R                  nOU R                  nU R                  R                  Xv5        U$ )aA  Make a new association.

@param dumb: Is this association for a dumb-mode transaction?
@type dumb: bool

@param assoc_type: The type of association to create.  Currently
    there is only one type defined, C{HMAC-SHA1}.
@type assoc_type: str

@returns: the new association.
@returntype: L{openid.association.Association}
   z{%s}{%x}{%s})r   getBytesr   r   ro   inttimer   fromExpiresInSECRET_LIFETIME	_dumb_key_normal_keyr2  storeAssociation)r1   rH   r   rp   uniqr   rT   keys           r$   r>  Signatory.createAssociation  s     ##M*$=>	 2 21 56:s499;/?"FF))$*>*>*46 ..C""C

##C/r#   c           	         Uc  [        S5      eU(       a  U R                  nOU R                  nU R                  R	                  XA5      nUbw  UR
                  S::  ag  [        R                  SU(       + =(       a    S=(       d    S< SU< SUR
                  < S	35        U(       a  U R                  R                  XA5        SnU$ )
a  Get the association with the specified handle.

@type assoc_handle: str

@param dumb: Is this association used with dumb mode?
@type dumb: bool

@returns: the association, or None if no valid association with that
    handle was found.
@returntype: L{openid.association.Association}
Nzassoc_handle must not be Noner   z
requested znot-rX   z	dumb key z is expired (by z	 seconds))	r   rM  rN  r2  rP   r   r   inforemoveAssociation)r1   r-   rH   r;  rQ  rT   s         r$   rP   Signatory.getAssociation  s    $ <==..C""C

))#<A!5KK#8/525|//+ , 

,,S?r#   c                 z    U(       a  U R                   nOU R                  nU R                  R                  X15        g)zInvalidates the association with the given handle.

@type assoc_handle: str

@param dumb: Is this association used with dumb mode?
@type dumb: bool
N)rM  rN  r2  rU  )r1   r-   rH   rQ  s       r$   rM   Signatory.invalidate  s-     ..C""C

$$S7r#   r1  N)Trg   )T)r   r   r   r   r    rL  rN  rM  r2   rL   rD  r>  rP   rM   r"   r   r#   r$   r/  r/  i  s:    
 (O -K(I6+Z6!F8r#   r/  c                   "    \ rS rSrSr\rS rSrg)Encoderi  a  I encode responses in to L{WebResponses<WebResponse>}.

If you don't like L{WebResponses<WebResponse>}, you can do
your own handling of L{OpenIDResponses<OpenIDResponse>} with
L{OpenIDResponse.whichEncoding}, L{OpenIDResponse.encodeToURL}, and
L{OpenIDResponse.encodeToKVForm}.
c                    UR                  5       nU[        :X  a?  U R                  UR                  5       S9n[	        U[
        5      (       a  [        Ul        U$ U[        :X  a(  UR                  5       nU R                  [        SU0S9nU$ U[        :X  a$  U R                  [        UR                  5       S9nU$ [        U5      e)zwEncode a response to a L{WebResponse}.

@raises EncodingError: When I can't figure out how to encode this
    message.
)r+  location)r'  r(  )r'  r+  )r  r  responseFactoryr!  r)  	Exception
HTTP_ERRORr'  r  r   HTTP_REDIRECTr  r-  r  rA  )r1   rR   	encode_aswrr\  s        r$   encodeEncoder.encode(  s     **,	%%%8+B+B+D%EB(I..$ 	 *$++-H%%"Z,B & DB 	 **%%79J%KB
 	  ))r#   r   N)	r   r   r   r   r    r$  r]  rc  r"   r   r#   r$   rZ  rZ    s     "Or#   rZ  c                   2   ^  \ rS rSrSrS rU 4S jrSrU =r$ )SigningEncoderi@  zWI encode responses in to L{WebResponses<WebResponse>}, signing them when required.
    c                     Xl         g)z{Create a L{SigningEncoder}.

@param signatory: The L{Signatory} I will make signatures with.
@type signatory: L{Signatory}
NrQ   )r1   rQ   s     r$   r2   SigningEncoder.__init__D  s	     #r#   c                 V  > [        U[        5      (       d  UR                  5       (       al  U R                  (       d  [	        SU< 3U5      eUR
                  R                  [        S5      (       a  [        U5      eU R                  R                  U5      n[        [        U ]3  U5      $ )zEncode a response to a L{WebResponse}, signing it first if appropriate.

@raises EncodingError: When I can't figure out how to encode this
    message.

@raises AlreadySigned: When this response is already signed.

@returntype: L{WebResponse}
z(Must have a store to sign this request: r5   )r)  r^  r  rQ   r   rO   r?   r   AlreadySignedrD  r   rf  rc  )r1   rR   r[   s     r$   rc  SigningEncoder.encodeL  s     8Y//X5J5J5L5L>> "*"./79 9%%i77#H--~~**84H^T1(;;r#   rh  )	r   r   r   r   r    r2   rc  r"   r   r   s   @r$   rf  rf  @  s    #< <r#   rf  c                       \ rS rSrSr\R                  \R                  \R                  \R                  S.r	S r
S rS rSrg)	Decoderib  z?I decode an incoming web request in to a L{OpenIDRequest}.
    )r   r   r(   r   c                     Xl         g)zConstruct a Decoder.

@param server: The server which I am decoding requests for.
    (Necessary because some replies reference their server.)
@type server: L{Server}
Nserver)r1   rq  s     r$   r2   Decoder.__init__m  s	     r#   c                    U(       d  g [         R                  " U5      nUR                  [        S5      nU(       d  Sn[        X%U4-  S9eU R                  R                  X@R                  5      nU" X R                  R                  5      $ ! [         aI  nUR                  5       n[        US'   [         R                  " U5      n[        U[        U5      5      eSnAff = f)ai  I transform query parameters into an L{OpenIDRequest}.

If the query does not seem to be an OpenID request at all, I return
C{None}.

@param query: The query parameters as a dictionary with each
    key mapping to one value.
@type query: dict

@raises ProtocolError: When the query does not seem to be a valid
    OpenID request.

@returntype: L{OpenIDRequest}
Nz	openid.nsr!   zNo mode value in message %sr6   )r   fromPostArgsr   r>   r   r=   r   r<   r   	_handlersgetdefaultDecoderrq  rB   )r1   queryr:   rC  r!   rC   handlers          r$   decodeDecoder.decodev  s     
	3**51G ~~i0/CWK.?@@..$$T+>+>?w 7 788! & 	3
 JJLE!+E+**51GS22	3s   B 
C ACC c                 L    UR                  [        S5      nSn[        XU4-  S9e)zCalled to decode queries when no handler for that mode is found.

@raises ProtocolError: This implementation always raises
    L{ProtocolError}.
r!   zUnrecognized OpenID mode %rr6   )r<   r   r=   )r1   r:   rq  r!   rC   s        r$   rw  Decoder.defaultDecoder  s*     ~~i0+G.99r#   rp  N)r   r   r   r   r    r   rD   r&   r   ru  r2   rz  rw  r"   r   r#   r$   rn  rn  b  sD     (33+77 0 < <%11	I$9L:r#   rn  c                   H    \ rS rSrSrS\\\4S jrS r	S r
S rS rS	 rS
rg)Serveri  a  I handle requests for an OpenID server.

Some types of requests (those which are not C{checkid} requests) may be
handed to my L{handleRequest} method, and I will take care of it and
return a response.

For your convenience, I also provide an interface to L{Decoder.decode}
and L{SigningEncoder.encode} through my methods L{decodeRequest} and
L{encodeResponse}.

All my state is encapsulated in an
L{OpenIDStore<openid.store.interface.OpenIDStore>}, which means
I'm not generally pickleable but I am easy to reconstruct.

Example::

    oserver = Server(FileOpenIDStore(data_path), "http://example.com/op")
    request = oserver.decodeRequest(query)
    if request.mode in ['checkid_immediate', 'checkid_setup']:
        if self.isAuthorized(request.identity, request.trust_root):
            response = request.answer(True)
        elif request.immediate:
            response = request.answer(False)
        else:
            self.showDecidePage(request)
            return
    else:
        response = oserver.handleRequest(request)

    webresponse = oserver.encode(response)

@ivar signatory: I'm using this for associate requests and to sign things.
@type signatory: L{Signatory}

@ivar decoder: I'm using this to decode things.
@type decoder: L{Decoder}

@ivar encoder: I'm using this to encode things.
@type encoder: L{Encoder}

@ivar op_endpoint: My URL.
@type op_endpoint: str

@ivar negotiator: I use this to determine which kinds of
    associations I can make and how.
@type negotiator: L{openid.association.SessionNegotiator}
Nc                 ^   Xl         U" U R                   5      U l        U" U R                  5      U l        U" U 5      U l        [        R
                  " 5       U l        U(       dE  [        R                  " U R                  R                  < SU R                  R                  < S3SS9  X l        g)a  A new L{Server}.

@param store: The back-end where my associations are stored.
@type store: L{openid.store.interface.OpenIDStore}

@param op_endpoint: My URL, the fully qualified address of this
    server's endpoint, i.e. C{http://example.com/server}
@type op_endpoint: str

@change: C{op_endpoint} is new in library version 2.0.  It
    currently defaults to C{None} for compatibility with
    earlier versions of the library, but you must provide it
    if you want to respond to any version 2 OpenID requests.
.zB constructor requires op_endpoint parameter for OpenID 2.0 serversr   r   N)r2  rQ   encoderdecoderr   r>   
negotiatorr   r   r[   r   r   rB   )r1   r2  rB   signatoryClassencoderClassdecoderClasss         r$   r2   Server.__init__  s    ( 
'

3#DNN3#D),113MM **DNN,C,CE 	
 'r#   c                     [        U SUR                  -   S5      nUb  U" U5      $ [        U < SUR                  < S35      e)a  Handle a request.

Give me a request, I will give you a response.  Unless it's a type
of request I cannot handle myself, in which case I will raise
C{NotImplementedError}.  In that case, you can handle it yourself,
or add a method to me for handling that request type.

@raises NotImplementedError: When I do not have a handler defined
    for that type of request.

@returntype: L{OpenIDResponse}
openid_Nz& has no handler for a request of mode r  )getattrr!   NotImplementedError)r1   r   ry  s      r$   handleRequestServer.handleRequest  sG     $	GLL 8$?7##%w||%& &r#   c                 8    UR                  U R                  5      $ )zXHandle and respond to C{check_authentication} requests.

@returntype: L{OpenIDResponse}
)rU   rQ   r   s     r$   openid_check_authentication"Server.openid_check_authentication  s    
 ~~dnn--r#   c                 L   UR                   nUR                  R                  nU R                  R	                  X#5      (       a+  U R
                  R                  SUS9nUR                  U5      $ SU< SU< 3nU R                  R                  5       u  pgUR                  XVU5      $ )zMHandle and respond to C{associate} requests.

@returntype: L{OpenIDResponse}
Fr<  zAssociation type z$ is not supported with session type )
r   r   rr   r  	isAllowedrQ   r>  rU   getAllowedTyper   )r1   r   r   rr   rT   r:   preferred_assoc_typer   s           r$   openid_associateServer.openid_associate  s     ''
33??$$Z>>NN44z 5 3E>>%(( ? -7FG $(??#A#A#C ;!,,W-CE Er#   c                 8    U R                   R                  U5      $ )a  Transform query parameters into an L{OpenIDRequest}.

If the query does not seem to be an OpenID request at all, I return
C{None}.

@param query: The query parameters as a dictionary with each
    key mapping to one value.
@type query: dict

@raises ProtocolError: When the query does not seem to be a valid
    OpenID request.

@returntype: L{OpenIDRequest}

@see: L{Decoder.decode}
)r  rz  )r1   rx  s     r$   decodeRequestServer.decodeRequest*  s    " ||""5))r#   c                 8    U R                   R                  U5      $ )a  Encode a response to a L{WebResponse}, signing it first if appropriate.

@raises EncodingError: When I can't figure out how to encode this
    message.

@raises AlreadySigned: When this response is already signed.

@returntype: L{WebResponse}

@see: L{SigningEncoder.encode}
)r  rc  r   s     r$   encodeResponseServer.encodeResponse=  s     ||""8,,r#   )r  r  r  rB   rQ   r2  )r   r   r   r   r    r/  rf  rn  r2   r  r  r  r  r  r"   r   r#   r$   r  r    s6    .d " ),% 'D&*.E(*&-r#   r  c                   R    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rSrg)r=   iL  zA message did not conform to the OpenID protocol.

@ivar message: The query that is failing to be a valid OpenID request.
@type message: openid.message.Message
Nc                     Xl         X0l        X@l        [        U5      [        [        4;  d   e[
        R                  X5        g)zWhen an error occurs.

@param message: The message that is failing to be a valid
    OpenID request.
@type message: openid.message.Message

@param text: A message about the encountered error.  Set as C{args[0]}.
@type text: str
N)openid_message	referencecontacttyper   r^  r2   )r1   r:   r7   r  r  s        r$   r2   ProtocolError.__init__S  s8     &"G}S#J...4&r#   c                 ^    U R                   c  gU R                   R                  [        S5      $ )zGGet the return_to argument from the request, if any.

@returntype: str
Nr*   )r  r<   r   r   s    r$   getReturnToProtocolError.getReturnToc  s,    
 &&&--iEEr#   c                 &    U R                  5       SL$ )z@Did this request have a return_to parameter?

@returntype: bool
N)r  r   s    r$   hasReturnToProtocolError.hasReturnTom  s    
 !--r#   c                    U R                   R                  5       n[        U5      nUR                  [        SS5        UR                  [        S[        U 5      5        U R                  b*  UR                  [        S[        U R                  5      5        U R                  b*  UR                  [        S[        U R                  5      5        U$ )zLGenerate a Message object for sending to the relying party,
after encoding.
r!   r   r  r  )r  r;   r   r@   r   r   r  r  )r1   r0   replys      r$   r  ProtocolError.toMessaget  s     ''::<		"Y0YT3<<#LLIs4<</@A>>%LLKT^^1DEr#   c                 \    U R                  5       R                  U R                  5       5      $ r`   )r  r   r  r   s    r$   r   ProtocolError.encodeToURL  s#    ~~%%d&6&6&899r#   c                 >    U R                  5       R                  5       $ r`   )r  r   r   s    r$   r!  ProtocolError.encodeToKVForm  s    ~~((**r#   c                 \    U R                  5       R                  U R                  5       5      $ )z4Encode to HTML form markup for POST.

@since: 2.1.0
)r  r  r  r   s    r$   r  ProtocolError.toFormMarkup  s%    
 ~~,,T-=-=-?@@r#   c                 J    [         R                  " U R                  5       5      $ )zmEncode to a full HTML page, wrapping the form markup in a page
that will autosubmit the form.

@since: 2.1.?
r  r   s    r$   r  ProtocolError.toHTML  s     %%d&7&7&9::r#   c                 V   U R                  5       (       aO  U R                  R                  5       [        :X  a'  [	        U R                  5       5      [        :  a  [        $ [        $ U R                  c  gU R                  R                  [        S5      nU(       a  U[        ;  a  [        $ g)zHow should I be encoded?

@returns: one of ENCODE_URL, ENCODE_KVFORM, or None.  If None,
    I cannot be encoded as a protocol message and should be
    displayed to the user.
Nr!   )r  r  r;   r   r  r   r   r  r  r<   r   r  r  )r1   r!   s     r$   r  ProtocolError.whichEncoding  s     ""557:E4##%&)::''!!&"")))V<00$$ r#   )r  r  r  r   )r   r   r   r   r    r2   r  r  r  r   r!  r  r  r  r"   r   r#   r$   r=   r=   L  s6    ' F.&:+A;!r#   r=   c                       \ rS rSrSrSrg)r   i  zcRaised when an operation was attempted that is not compatible with
the protocol version being used.r   Nr   r   r   r   r    r"   r   r#   r$   r   r     s    (r#   r   c                       \ rS rSrSrSrg)r   i  zgRaised when a response to a request cannot be generated because
the request contains no return_to URL.
r   Nr  r   r#   r$   r   r     s     	r#   r   c                   (    \ rS rSrSrSS jrS rSrg)rA  i  zCould not encode this as a protocol message.

You should probably render it and show it to the user.

@ivar response: The response that failed to encode.
@type response: L{OpenIDResponse}
Nc                 F    [         R                  X5        Xl        X l        g r`   )r^  r2   rR   r=  )r1   rR   r=  s      r$   r2   EncodingError.__init__  s    4* &r#   c                     U R                   (       a)  U R                  R                  < SU R                   < 3nU$ U R                  R                  < SU R                  < 3nU$ )Nr   z for Response )r=  r[   r   rR   )r1   r]   s     r$   r^   EncodingError.__str__  sK     NN33T5E5EFA  )-(?(?OAr#   )r=  rR   r`   r   r   r   r   r    r2   r^   r"   r   r#   r$   rA  rA    s    '
r#   rA  c                       \ rS rSrSrSrg)rk  i  z This response is already signed.r   Nr  r   r#   r$   rk  rk    s    *r#   rk  c                   $    \ rS rSrSrS rS rSrg)r   i  z&A return_to is outside the trust_root.c                 F    [         R                  X5        X l        X0l        g r`   )r=   r2   r*   r   )r1   r:   r*   r   s       r$   r2   UntrustedReturnURL.__init__  s    t-"$r#   c                 >    SU R                   < SU R                  < 3$ )Nz
return_to z not under trust_root r*   r   r   s    r$   r^   UntrustedReturnURL.__str__  s    9=9=J 	Jr#   r  Nr  r   r#   r$   r   r     s    0%
Jr#   r   c                       \ rS rSrSrS rSrg)r   i  z0The return_to URL doesn't look like a valid URL.c                 :    X l         [        R                  X5        g r`   )r*   r=   r2   )r1   r  r*   s      r$   r2   MalformedReturnURL.__init__  s    "t4r#   )r*   N)r   r   r   r   r    r2   r"   r   r#   r$   r   r     s
    :5r#   r   c                       \ rS rSrSrSrg)r   i  zThe trust root is not well-formed.

@see: OpenID Specs, U{openid.trust_root<http://openid.net/specs.bml#mode-checkid_immediate>}
r   Nr  r   r#   r$   r   r     s     	r#   r   )Ar    rJ  r   loggingr>   r   openidr   r   r   	openid.dhr   openid.store.noncer   openid.server.trustrootr	   r
   openid.associationr   r   r   openid.messager   r   r   r   r   r   openid.urinormr   	getLoggerr   r   r-  r`  r_  r  r  r  r  rc   objectr   r&   re   ru   r   r   r   rN   r$  r/  rZ  rf  rn  r  r^  r=   r   r   rA  rk  r   r   r   r   r#   r$   <module>r     s  sj        # & = M MA A "			8	$

(*=> 
" 	F i} iX5V 52K
V K
\*'E *C} CLD0] D0NA&V A&H& @q8 q8h f  F<W <DB:f B:Jb-V b-JqI qh(9 (
	i 	I ,+M +
J 
J5 5	 	r#   