
    qhE                     v   S r SSKJrJr  SSKJr  SSKr\R                  " \5      r	 \
  / SQrSSSS	S
SSSSS.	rS rSrSr\r \" \S5        S r " S S\5      rS r " S S\5      r " S S\5      rg! \ a    \
\
4r
 NWf = f! \ a-  r\	R'                  S\< SS< S\
" \5      < 35         SrCNfSrCff = f)a  Simple registration request and response parsing and object representation

This module contains objects representing simple registration requests
and responses that can be used with both OpenID relying parties and
OpenID providers.

  1. The relying party creates a request object and adds it to the
     C{L{AuthRequest<openid.consumer.consumer.AuthRequest>}} object
     before making the C{checkid_} request to the OpenID provider::

      auth_request.addExtension(SRegRequest(required=['email']))

  2. The OpenID provider extracts the simple registration request from
     the OpenID request using C{L{SRegRequest.fromOpenIDRequest}},
     gets the user's approval and data, creates a C{L{SRegResponse}}
     object and adds it to the C{id_res} response::

      sreg_req = SRegRequest.fromOpenIDRequest(checkid_request)
      # [ get the user's approval and data, informing the user that
      #   the fields in sreg_response were requested ]
      sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
      sreg_resp.toMessage(openid_response.fields)

  3. The relying party uses C{L{SRegResponse.fromSuccessResponse}} to
     extract the data from the OpenID response::

      sreg_resp = SRegResponse.fromSuccessResponse(success_response)

@since: 2.0

@var sreg_data_fields: The names of the data fields that are listed in
    the sreg spec, and a description of them in English

@var sreg_uri: The preferred URI to use for the simple registration
    namespace and XRD Type value
    )registerNamespaceAliasNamespaceAliasRegistrationError)	ExtensionN)SRegRequestSRegResponsedata_fieldsns_uri
ns_uri_1_0
ns_uri_1_1supportsSRegz	Full NameNicknamezDate of BirthzE-mail AddressGenderzPostal CodeCountryLanguagez	Time Zone)	fullnamenicknamedobemailgenderpostcodecountrylanguagetimezonec                 6    U [         ;  a  [        U < S35      eg)zCheck to see that the given value is a valid simple
registration data field name.

@raise ValueError: if the field name is not a valid simple
    registration data field name
z+ is not a defined simple registration fieldN)r   
ValueError)
field_names    H/var/www/html/env/lib/python3.13/site-packages/openid/extensions/sreg.pycheckFieldNamer   K   s&     $$( ) 	) %    zhttp://openid.net/sreg/1.0z%http://openid.net/extensions/sreg/1.1sregzregisterNamespaceAlias(z, z
) failed: c                 d    U R                  [        5      =(       d    U R                  [        5      $ )a  Does the given endpoint advertise support for simple
registration?

@param endpoint: The endpoint object as returned by OpenID discovery
@type endpoint: openid.consumer.discover.OpenIDEndpoint

@returns: Whether an sreg type was advertised by the endpoint
@rtype: bool
)usesExtensionr   r
   )endpoints    r   r   r   j   s*     "":. /"":.0r   c                       \ rS rSrSrSrg)SRegNamespaceErrorx   a  The simple registration namespace was not found and could not
be created using the expected name (there's another extension
using the name 'sreg')

This is not I{illegal}, for OpenID 2, although it probably
indicates a problem, since it's not expected that other extensions
will re-use the alias that is in use for OpenID 1.

If this is an OpenID 1 request, then there is no recourse. This
should not happen unless some code has modified the namespaces for
the message that is being processed.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r'   r   r   r%   r%   x   s    r   r%   c                     [         [        4 H$  nU R                  R                  U5      nUc  M#    U$    [         n U R                  R	                  [         S5        U$ ! [
         a  n[        U5      eSnAff = f)a  Extract the simple registration namespace URI from the given
OpenID message. Handles OpenID 1 and 2, as well as both sreg
namespace URIs found in the wild, as well as missing namespace
definitions (for OpenID 1)

@param message: The OpenID message from which to parse simple
    registration fields. This may be a request or response message.
@type message: C{L{openid.message.Message}}

@returns: the sreg namespace URI for the supplied message. The
    message may be modified to define a simple registration
    namespace.
@rtype: C{str}

@raise ValueError: when using OpenID 1 if the message defines
    the 'sreg' alias to be something other than a simple
    registration type.
Nr    )r   r
   
namespacesgetAliasaddAliasKeyErrorr%   )messagesreg_ns_urialiaswhys       r   	getSRegNSr7      s    * #J/""++K8 # 0 !	*''
F;   	* %S))	*s    A 
A8(A33A8c                       \ rS rSrSrSrSSS\4S jr\" \	5      r
S r\" \5      rSS jrS rS	 rS
 rSS jrSS jrS rSrg)r      a  An object to hold the state of a simple registration request.

@ivar required: A list of the required fields in this simple
    registration request
@type required: [str]

@ivar optional: A list of the optional fields in this simple
    registration request
@type optional: [str]

@ivar policy_url: The policy URL that was provided with the request
@type policy_url: str or NoneType

@group Consumer: requestField, requestFields, getExtensionArgs, addToOpenIDRequest
@group Server: fromOpenIDRequest, parseExtensionArgs
r    Nc                     [         R                  " U 5        / U l        / U l        X0l        X@l        U(       a  U R                  USSS9  U(       a  U R                  USSS9  gg)z/Initialize an empty simple registration requestT)requiredstrictFN)r   __init__r;   optional
policy_urlr	   requestFields)selfr;   r>   r?   r4   s        r   r=   SRegRequest.__init__   s_     	4 $!x$tDx%E r   c                     U " 5       nUR                   R                  5       nUR                  U5      Ul        UR	                  UR                  5      nUR                  U5        U$ )a$  Create a simple registration request that contains the
fields that were requested in the OpenID request with the
given arguments

@param request: The OpenID request
@type request: openid.server.CheckIDRequest

@returns: The newly created simple registration request
@rtype: C{L{SRegRequest}}
)r3   copy
_getSRegNSr	   getArgsparseExtensionArgs)clsrequestrA   r3   argss        r   fromOpenIDRequestSRegRequest.fromOpenIDRequest   sT     u //&&(oog.t{{+%r   c                    S HM  nUS:H  nUR                  U5      nU(       d  M"  UR                  S5       H  n U R                  XdU5        M     MO     UR                  S5      U l        g! [         a    U(       a  e  MJ  f = f)a  Parse the unqualified simple registration request
parameters and add them to this object.

This method is essentially the inverse of
C{L{getExtensionArgs}}. This method restores the serialized simple
registration request fields.

If you are extracting arguments from a standard OpenID
checkid_* request, you probably want to use C{L{fromOpenIDRequest}},
which will extract the sreg namespace and arguments from the
OpenID request. This method is intended for cases where the
OpenID server needs more control over how the arguments are
parsed than that method provides.

>>> args = message.getArgs(ns_uri)
>>> request.parseExtensionArgs(args)

@param args: The unqualified simple registration arguments
@type args: {str:str}

@param strict: Whether requests with fields that are not
    defined in the simple registration specification should be
    tolerated (and ignored)
@type strict: bool

@returns: None; updates this object
r;   r>   r;   ,r?   N)getsplitrequestFieldr   r?   )rA   rJ   r<   	list_namer;   itemsr   s          r   rG   SRegRequest.parseExtensionArgs   s    8 2I!Z/HHHY'Eu"'++c"2J"))*G #3	 2 ((<0	 & "!! ""s   A++B Bc                 4    U R                   U R                  -   $ )z|A list of all of the simple registration fields that were
requested, whether they were required or optional.

@rtype: [str]
rN   rA   s    r   allRequestedFieldsSRegRequest.allRequestedFields  s     }}t}},,r   c                 4    [        U R                  5       5      $ )zBHave any simple registration fields been requested?

@rtype: bool
)boolrX   rW   s    r   wereFieldsRequestedSRegRequest.wereFieldsRequested$  s    
 D++-..r   c                 H    XR                   ;   =(       d    XR                  ;   $ )zWas this field in the request?rN   rA   r   s     r   __contains__SRegRequest.__contains__+  s    mm+Jz]]/JKr   c                 ~   [        U5        U(       a*  XR                  ;   d  XR                  ;   a  [        S5      eOCXR                  ;   a  gXR                  ;   a$  U(       a  U R                  R	                  U5        OgU(       a  U R                  R                  U5        gU R                  R                  U5        g)a  Request the specified field from the OpenID user

@param field_name: the unqualified simple registration field name
@type field_name: str

@param required: whether the given field should be presented
    to the user as being a required to successfully complete
    the request

@param strict: whether to raise an exception when a field is
    added to a request more than once

@raise ValueError: when the field requested is not a simple
    registration field or strict is set and the field was
    requested more than once
z%That field has already been requestedN)r   r;   r>   r   removeappend)rA   r   r;   r<   s       r   rR   SRegRequest.requestField/  s    " 	z"]]*jMM.I !HII /J ]]*]]*MM((4MM  ,MM  ,r   c                     [        U[        5      (       a  [        S[        U5      < S35      eU H  nU R	                  XBUS9  M     g)a  Add the given list of fields to the request

@param field_names: The simple registration data fields to request
@type field_names: [str]

@param required: Whether these values should be presented to
    the user as required

@param strict: whether to raise an exception when a field is
    added to a request more than once

@raise ValueError: when a field requested is not a simple
    registration field or strict is set and a field was
    requested more than once
z2Fields should be passed as a list of strings (not ))r<   N)
isinstancestr	TypeErrortyperR   )rA   field_namesr;   r<   r   s        r   r@   SRegRequest.requestFieldsT  sM      k3''26{2CG H H &Jj6B &r   c                    0 nU R                   (       a  SR                  U R                   5      US'   U R                  (       a  SR                  U R                  5      US'   U R                  (       a  U R                  US'   U$ )zGet a dictionary of unqualified simple registration
arguments representing this request.

This method is essentially the inverse of
C{L{parseExtensionArgs}}. This method serializes the simple
registration request fields.

@rtype: {str:str}
rO   r;   r>   r?   )r;   joinr>   r?   )rA   rJ   s     r   getExtensionArgsSRegRequest.getExtensionArgsk  s_     =="xx6D=="xx6D??!%Dr   )r	   r>   r?   r;   )F)FF)r(   r)   r*   r+   r,   ns_aliasr	   r=   staticmethodr7   rE   rK   classmethodrG   rX   r\   r`   rR   r@   rp   r-   r'   r   r   r   r      sh    " H  #	F( i(J. $$56'1R-/L#-JC.r   r   c                       \ rS rSrSrSrS\4S jrS r\	" \5      r\
" \5      rSS jr\	" \5      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Srg)r   i  a  Represents the data returned in a simple registration response
inside of an OpenID C{id_res} response. This object will be
created by the OpenID server, added to the C{id_res} response
object, and then extracted from the C{id_res} message by the
Consumer.

@ivar data: The simple registration data, keyed by the unqualified
    simple registration name of the field (i.e. nickname is keyed
    by C{'nickname'})

@ivar ns_uri: The URI under which the simple registration data was
    stored in the response message.

@group Server: extractResponse
@group Consumer: fromSuccessResponse
@group Read-only dictionary interface: keys, iterkeys, items, iteritems,
    __iter__, get, __getitem__, keys, has_key
r    Nc                 ^    [         R                  " U 5        Uc  0 U l        OXl        X l        g N)r   r=   datar	   )rA   rx   r4   s      r   r=   SRegResponse.__init__  s&    4 <DII!r   c                     U " 5       nUR                   Ul         UR                  5        H'  nUR                  U5      nUc  M  XSR                  U'   M)     U$ )a#  Take a C{L{SRegRequest}} and a dictionary of simple
registration values and create a C{L{SRegResponse}}
object containing that data.

@param request: The simple registration request object
@type request: SRegRequest

@param data: The simple registration data for this
    response, as a dictionary from unqualified simple
    registration field name to string (unicode) value. For
    instance, the nickname should be stored under the key
    'nickname'.
@type data: {str:str}

@returns: a simple registration response object
@rtype: SRegResponse
)r	   rX   rP   rx   )rH   rI   rx   rA   fieldvalues         r   extractResponseSRegResponse.extractResponse  sO    $ unn//1EHHUOE #(		%  2 r   c                 >   U " 5       nUR                  UR                  5      Ul        U(       a  UR                  UR                  5      nO%UR                  R	                  UR                  5      nU(       d  g[
         H  nXT;   d  M
  XE   UR                  U'   M     U$ )a&  Create a C{L{SRegResponse}} object from a successful OpenID
library response
(C{L{openid.consumer.consumer.SuccessResponse}}) response
message

@param success_response: A SuccessResponse from consumer.complete()
@type success_response: C{L{openid.consumer.consumer.SuccessResponse}}

@param signed_only: Whether to process only data that was
    signed in the id_res message from the server.
@type signed_only: bool

@rtype: SRegResponse
@returns: A simple registration response containing the data
    that was supplied with the C{id_res} response.
N)rE   r3   r	   getSignedNSrF   r   rx   )rH   success_responsesigned_onlyrA   rJ   r   s         r   fromSuccessResponse SRegResponse.fromSuccessResponse  s    " uoo&6&>&>?#//<D#++33DKK@D%J!(,(8		*% & r   c                     U R                   $ )zzGet the fields to put in the simple registration namespace
when adding them to an id_res message.

@see: openid.extension
)rx   rW   s    r   rp   SRegResponse.getExtensionArgs  s     yyr   c                 N    [        U5        U R                  R                  X5      $ )zlLike dict.get, except that it checks that the field name is
defined by the simple registration specification)r   rx   rP   )rA   r   defaults      r   rP   SRegResponse.get  s     	z"yy}}Z11r   c                 H    [        U R                  R                  5       5      $ )zDAll of the data values in this simple registration response
        )listrx   rT   rW   s    r   rT   SRegResponse.items  s     DIIOO%&&r   c                 H    [        U R                  R                  5       5      $ rw   )iterrx   rT   rW   s    r   	iteritemsSRegResponse.iteritems  s    DIIOO%&&r   c                 H    [        U R                  R                  5       5      $ rw   )r   rx   keysrW   s    r   r   SRegResponse.keys      DIINN$%%r   c                 H    [        U R                  R                  5       5      $ rw   )r   rx   r   rW   s    r   iterkeysSRegResponse.iterkeys  r   r   c                 
    X;   $ rw   r'   )rA   keys     r   has_keySRegResponse.has_key  s
    {r   c                 4    [        U5        XR                  ;   $ rw   r   rx   r_   s     r   r`   SRegResponse.__contains__  s    z"YY&&r   c                 ,    [        U R                  5      $ rw   )r   rx   rW   s    r   __iter__SRegResponse.__iter__	      DIIr   c                 6    [        U5        U R                  U   $ rw   r   r_   s     r   __getitem__SRegResponse.__getitem__  s    z"yy$$r   c                 ,    [        U R                  5      $ rw   )r[   rx   rW   s    r   __bool__SRegResponse.__bool__  r   r   )rx   r	   )Trw   )r(   r)   r*   r+   r,   rr   r	   r=   r}   rt   rs   r7   rE   r   rp   rP   rT   r   r   r   r   r`   r   r   r   r-   r'   r   r   r   r     s    & H f "4 "/2O i(JB &&9:2'
'&&'%r   r   )r,   openid.messager   r   openid.extensionr   logging	getLoggerr(   loggerri   	NameError__all__r   r   r
   r   r	   e	exceptionr   r   r%   r7   r   r   r'   r   r   <module>r      s  #J% & 			8	$
 
	) *
 5
 
6:v.0 &RP) PfN9 Ni
  *Cl ' 6
!63q65 6 66s)   A5 	B 5
BBB8#B33B8