
    qhh                     &   S r / SQrSSKJr  SSKJr  SSKJrJr  Sr	Sr
S r " S	 S
\5      r " S S\5      r " S S\R                  5      r " S S\5      rS r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)zTImplements the OpenID Attribute Exchange specification, version 1.0.

@since: 2.1.0
)AttributeRequestFetchRequestFetchResponseStoreRequestStoreResponse    )	extension)	TrustRoot)NamespaceMap	OPENID_NS	unlimited    c                 \    SU ;   a  [        SU < S35      eSU ;   a  [        SU < S35      eg)zl
Check an alias for invalid characters; raise AXError if any are
found.  Return None if the alias is valid.
,zAlias z must not contain comma.z must not contain periodN)AXError)aliass    F/var/www/html/env/lib/python3.13/site-packages/openid/extensions/ax.py
checkAliasr      s3    
 e|5CDD
e|EDEE     c                       \ rS rSrSrSrg)r   '   zMResults from data that does not meet the attribute exchange 1.0
specification N)__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   '   s    r   r   c                   $    \ rS rSrSrS rS rSrg)NotAXMessage,   z?Raised when there is no Attribute Exchange mode in the message.c                 .    U R                   R                  $ N	__class__r   selfs    r   __repr__NotAXMessage.__repr__/       ~~&&&r   c                 .    U R                   R                  $ r#   r$   r&   s    r   __str__NotAXMessage.__str__2   r*   r   r   N)r   r   r   r   r   r(   r,   r   r   r   r   r    r    ,   s    I''r   r    c                   0    \ rS rSrSrSrSrSrS rS r	Sr
g)		AXMessage6   zAbstract class containing common code for attribute exchange messages

@cvar ns_alias: The preferred namespace alias for attribute
    exchange messages

@cvar mode: The type of this attribute exchange message. This must
    be overridden in subclasses.
axzhttp://openid.net/srv/ax/1.0Nc                     UR                  S5      n[        U[        5      (       a
  [        USS9nX R                  :w  a.  U(       d
  [        5       e[        SU R                  < SU< 35      eg)zRaise an exception if the mode in the attribute exchange
arguments does not match what is expected for this class.

@raises NotAXMessage: When there is no mode value in ax_args at all.

@raises AXError: When mode does not match.
modezutf-8)encodingzExpected mode z; got N)get
isinstancebytesstrr3   r    r   )r'   ax_argsr3   s      r   
_checkModeAXMessage._checkModeI   sY     {{6"dE""tg.D99"n$DIItLMM	 r   c                     SU R                   0$ )zReturn a set of attribute exchange arguments containing the
basic information that must be in every attribute exchange
message.
r3   )r3   r&   s    r   _newArgsAXMessage._newArgsZ   s    
 		""r   r   )r   r   r   r   r   ns_aliasns_urir3   r:   r=   r   r   r   r   r/   r/   6   s#     H+FDN"#r   r/   c                   (    \ rS rSrSrSS jrS rSrg)AttrInfob   a1  Represents a single attribute in an attribute exchange
request. This should be added to an AXRequest object in order to
request the attribute.

@ivar required: Whether the attribute will be marked as required
    when presented to the subject of the attribute exchange
    request.
@type required: bool

@ivar count: How many values of this type to request from the
    subject. Defaults to one.
@type count: int

@ivar type_uri: The identifier that determines what the attribute
    represents and how it is serialized. For example, one type URI
    representing dates could represent a Unix timestamp in base 10
    and another could represent a human-readable string.
@type type_uri: str

@ivar alias: The name that should be given to this alias in the
    request. If it is not supplied, a generic name will be
    assigned. For example, if you want to call a Unix timestamp
    value 'tstamp', set its alias to that value. If two attributes
    in the same message request to use the same alias, the request
    will fail to be generated.
@type alias: str or NoneType
Nc                 z    X0l         X l        Xl        X@l        U R                  b  [	        U R                  5        g g r#   )requiredcounttype_urir   r   )r'   rG   rF   rE   r   s        r   __init__AttrInfo.__init__   s1     
 
::!tzz" "r   c                 (    U R                   [        :H  $ )a  
When processing a request for this attribute, the OP should
call this method to determine whether all available attribute
values were requested.  If self.count == UNLIMITED_VALUES,
this returns True.  Otherwise this returns False, in which
case self.count is an integer.
)rF   UNLIMITED_VALUESr&   s    r   wantsUnlimitedValuesAttrInfo.wantsUnlimitedValues   s     zz---r   )r   rF   rE   rG   )   FN)r   r   r   r   r   rH   rL   r   r   r   r   rB   rB   b   s    B#.r   rB   c                     / nU(       aL  UR                  S5       H7  nU R                  U5      nUc  [        SU< 35      eUR                  U5        M9     U$ )a  Given a namespace mapping and a string containing a
comma-separated list of namespace aliases, return a list of type
URIs that correspond to those aliases.

@param namespace_map: The mapping from namespace URI to alias
@type namespace_map: openid.message.NamespaceMap

@param alias_list_s: The string containing the comma-separated
    list of aliases. May also be None for convenience.
@type alias_list_s: str or NoneType

@returns: The list of namespace URIs that corresponds to the
    supplied list of aliases. If the string was zero-length or
    None, an empty list will be returned.

@raise KeyError: If an alias is present in the list of aliases but
    is not present in the namespace map.
r   z&No type is defined for attribute name )splitgetNamespaceURIKeyErrorappend)namespace_mapalias_list_surisr   rG   s        r   
toTypeURIsrW      sa    & D!'',E$44U;H % ) * * H% - Kr   c                   j    \ rS rSrSrSrSS jrS rS rS r	S	 r
\" \
5      r
S
 rS rS rS r\rSrg)r      a  An attribute exchange 'fetch_request' message. This message is
sent by a relying party when it wishes to obtain attributes about
the subject of an OpenID authentication request.

@ivar requested_attributes: The attributes that have been
    requested thus far, indexed by the type URI.
@type requested_attributes: {str:AttrInfo}

@ivar update_url: A URL that will accept responses for this
    attribute exchange request, even in the absence of the user
    who made this request.
fetch_requestNc                 H    [         R                  U 5        0 U l        Xl        g r#   )r/   rH   requested_attributes
update_url)r'   r]   s     r   rH   FetchRequest.__init__   s    4 $&!$r   c                     UR                   U R                  ;   a  [        SUR                   < S35      eXR                  UR                   '   g)zAdd an attribute to this attribute exchange request.

@param attribute: The attribute that is being requested
@type attribute: C{L{AttrInfo}}

@returns: None

@raise KeyError: when the requested attribute is already
    present in this fetch request.
zThe attribute z has already been requestedN)rG   r\   rR   )r'   	attributes     r   addFetchRequest.add   sJ     !:!::%..2 3 3 9B!!)"4"45r   c                 4   [        5       n/ n/ nU R                  5       nU R                  R                  5        H  u  pVUR                  c  UR                  U5      nOUR                  XVR                  5      nUR                  (       a  UR                  U5        OUR                  U5        UR                  S:w  a  [        UR                  5      USU-   '   XTSU-   '   M     U(       a  SR                  U5      US'   U(       a  SR                  U5      US'   U$ )zGet the serialized form of this attribute fetch request.

@returns: The fetch request message parameters
@rtype: {unicode:unicode}
rN   count.type.r   rE   if_available)r
   r=   r\   itemsr   ra   addAliasrE   rS   rF   r8   join)r'   aliasesrE   rf   r9   rG   r`   r   s           r   getExtensionArgsFetchRequest.getExtensionArgs   s     .--/#'#<#<#B#B#DH&H-  ((??C!!&##E*!#,/	,@5()'/GeO$7 $E: "%((8"4GJ&)hh|&<GN#r   c                     / nU R                   R                  5        H)  u  p#UR                  (       d  M  UR                  U5        M+     U$ )zGet the type URIs for all attributes that have been marked
as required.

@returns: A list of the type URIs for attributes that have
    been marked as required.
@rtype: [str]
)r\   rg   rE   rS   )r'   rE   rG   r`   s       r   getRequiredAttrsFetchRequest.getRequiredAttrs  sE     #'#<#<#B#B#DH!!!) $E r   c                    UR                   nUR                  U R                  5      nU " 5       n UR                  U5        UR
                  (       a  UR                  [        SUR                  [        S5      5      nU(       d  [        SUR
                  < S35      e[        R                  " U5      nUR                  UR
                  5      (       d  [        SUR
                  < SU< 35      eU$ ! [         a
  n SnAgSnAff = f)a  Extract a FetchRequest from an OpenID message

@param openid_request: The OpenID authentication request
    containing the attribute fetch request
@type openid_request: C{L{openid.server.server.CheckIDRequest}}

@rtype: C{L{FetchRequest}} or C{None}
@returns: The FetchRequest extracted from the message or None, if
    the message contained no AX extension.

@raises KeyError: if the AuthRequest is not consistent in its use
    of namespace aliases.

@raises AXError: When parseExtensionArgs would raise same.

@see: L{parseExtensionArgs}
Nrealm	return_tozCannot validate update_url z against absent realmzUpdate URL z! failed validation against realm )messagegetArgsr@   parseExtensionArgsr    r]   getArgr   r   r	   parsevalidateURL)clsopenid_requestrs   r9   r'   errrq   trs           r   fromOpenIDRequestFetchRequest.fromOpenIDRequest  s    $ !((//#**-u	##G, ?? NN9g#*>>)[#IKE *+ + 'B>>$//22__e/0 0 )  		s   C3 3
DDc           	         U R                  U5        [        5       nUR                  5        H  u  p4UR                  S5      (       d  M  USS nUnUR	                  Xe5        SU-   nUR                  U5      nU(       a&   [        U5      n	U	S::  a  [        SU< SU< 35      eOS
n	U R                  [        XeU	S95        M     [        X!R                  S5      5      n
U
 H  nSU R                  U   l        M     [        X!R                  S5      5      nX-   nUR                  5        H  nXl;  d  M
  [        SU< S35      e   UR                  S5      U l        g! [         a"    U[        :w  a  [        SU< S	U< 35      eUn	 Nf = f)aS  Given attribute exchange arguments, populate this FetchRequest.

@param ax_args: Attribute Exchange arguments from the request.
    As returned from L{Message.getArgs<openid.message.Message.getArgs>}.
@type ax_args: dict

@raises KeyError: if the message is not consistent in its use
    of namespace aliases.

@raises NotAXMessage: If ax_args does not include an Attribute Exchange
    mode.

@raises AXError: If the data to be parsed does not follow the
    attribute exchange specification. At least when
    'if_available' or 'required' is not specified for a
    particular attribute type.
re      Nrd   r   zCount z  must be greater than zero, got zInvalid count value for z: rN   )r   rF   rE   Trf   z	Type URI zC was in the request but not present in "required" or "if_available"r]   )r:   r
   rg   
startswithrh   r5   intr   
ValueErrorrK   ra   rB   rW   r\   rE   iterNamespaceURIsr]   )r'   r9   rj   keyvaluer   rG   	count_keycount_srF   rE   rf   all_type_uriss                r   ru   FetchRequest.parseExtensionArgsN  s   & 	 .!--/JC~~g&&AB   1$u,	!++i0
( #G A:")!*G!7#8 8 & E(uEF/ *2 g{{:'>? H;?D%%h/8 ! "';;~+FG /113H,'+ , , 4 "++l33 & ("&66")+4g+A #B B '	(s   ?$E)FFc                 H    [        U R                  R                  5       5      $ )zLIterate over the AttrInfo objects that are
contained in this fetch_request.
)iterr\   valuesr&   s    r   	iterAttrsFetchRequest.iterAttrs  s     D--44677r   c                 ,    [        U R                  5      $ )zCIterate over the attribute type URIs in this fetch_request
        )r   r\   r&   s    r   __iter__FetchRequest.__iter__  s     D--..r   c                     XR                   ;   $ )z=Is the given type URI present in this fetch_request?
        )r\   r'   rG   s     r   has_keyFetchRequest.has_key  s     4444r   )r\   r]   r#   )r   r   r   r   r   r3   rH   ra   rk   rn   r}   classmethodru   r   r   r   __contains__r   r   r   r   r   r      sT     D%
B"0d+Z $$56?4B8/
5
 Lr   r   c                   P    \ rS rSrSrS rS rS rSS jrS r	SS	 jr
S
 rS rSrg)AXKeyValueMessagei  zAn abstract class that implements a message that has attribute
keys and values. It contains the common code between
fetch_response and store_request.
c                 <    [         R                  U 5        0 U l        g r#   )r/   rH   datar&   s    r   rH   AXKeyValueMessage.__init__  s    4 	r   c                      U R                   U   nUR                  U5        g! [         a    / =o0R                   U'    N.f = f)ag  Add a single value for the given attribute type to the
message. If there are already values specified for this type,
this value will be sent in addition to the values already
specified.

@param type_uri: The URI for the attribute

@param value: The value to add to the response to the relying
    party for this attribute
@type value: unicode

@returns: None
N)r   rR   rS   )r'   rG   r   r   s       r   addValueAXKeyValueMessage.addValue  sE    	.YYx(F 	e  	.+--FYYx(	.s   # A A c                      X R                   U'   g)zSet the values for the given attribute type. This replaces
any values that have already been set for this attribute.

@param type_uri: The URI for the attribute

@param values: A list of values to send for this attribute.
@type values: [unicode]
Nr   )r'   rG   r   s      r   	setValuesAXKeyValueMessage.setValues  s     %		(r   Nc                    Uc
  [        5       n0 nU R                  R                  5        HX  u  p4UR                  U5      nX2SU-   '   [	        [        U5      5      USU-   '   [        U5       H  u  pgSXVS-   4-  nXrU'   M     MZ     U$ )zGet the extension arguments for the key/value pairs
contained in this message.

@param aliases: An alias mapping. Set to None if you don't
    care about the aliases for this request.
re   rd   value.%s.%drN   )r
   r   rg   ra   r8   len	enumerate)	r'   rj   r9   rG   r   r   ir   r   s	            r   _getExtensionKVArgs%AXKeyValueMessage._getExtensionKVArgs  s     ?"nG $		 1HKK)E'/GeO$(+CK(8GHu$%%f-#u!en4$ . !2 r   c                    U R                  U5        [        5       nUR                  5        H@  u  p4UR                  S5      (       d  M  UnUSS n[	        U5        UR                  XV5        MB     UR                  5        HZ  u  pV USU-      n[        U5      n/ n	[        SUS-   5       H  n
SXj4-  nX   nU	R                  U5        M      XR                  U'   M\     g! [         a    USU-      nUS:X  a  / n	 N/U/n	 N4f = f)	av  Parse attribute exchange key/value arguments into this
object.

@param ax_args: The attribute exchange fetch_response
    arguments, with namespacing removed.
@type ax_args: {unicode:unicode}

@returns: None

@raises ValueError: If the message has bad values for
    particular fields

@raises KeyError: If the namespace mapping is bad or required
    arguments are missing
re   r   Nrd   rN   r   zvalue. )r:   r
   rg   r   r   rh   r   rangerS   rR   r   )r'   r9   rj   r   r   rG   r   r   rF   r   r   	value_keys               r   ru   $AXKeyValueMessage.parseExtensionArgs  s     	 .!--/JC~~g&& AB5!  1 *  '}}OH)!(U"23 Gq%!),A -
 :I#.EMM%( -
 #)IIh%  /  %5 01B;F#WF%s   CD;D Dc                     U R                   R                  U5      nU(       d  U$ [        U5      S:X  a  US   $ [        SU< 35      e)az  Get a single value for an attribute. If no value was sent
for this attribute, use the supplied default. If there is more
than one value for this attribute, this method will fail.

@type type_uri: str
@param type_uri: The URI for the attribute

@param default: The value to return if the attribute was not
    sent in the fetch_response.

@returns: The value of the attribute in the fetch_response
    message, or the default supplied
@rtype: unicode or NoneType

@raises ValueError: If there is more than one value for this
    parameter in the fetch_response message.
@raises KeyError: If the attribute was not sent in this response
rN   r   z More than one value present for )r   r5   r   r   )r'   rG   defaultr   s       r   	getSingleAXKeyValueMessage.getSingle  sB    & x(N[A!9(MNNr   c                      U R                   U   $ )a4  Get the list of values for this attribute in the
fetch_response.

XXX: what to do if the values are not present? default
parameter? this is funny because it's always supposed to
return a list, so the default may break that, though it's
provided by the user's code, so it might be okay. If no
default is supplied, should the return be None or []?

@param type_uri: The URI of the attribute

@returns: The list of values for this attribute in the
    response. May be an empty list.
@rtype: [unicode]

@raises KeyError: If the attribute was not sent in the response
r   r   s     r   r5   AXKeyValueMessage.get4  s    $ yy""r   c                 6    [        U R                  U5      5      $ )aB  Get the number of responses for a particular attribute in
this fetch_response message.

@param type_uri: The URI of the attribute

@returns: The number of values sent for this attribute

@raises KeyError: If the attribute was not sent in the
    response. KeyError will not be raised if the number of
    values was zero.
)r   r5   r   s     r   rF   AXKeyValueMessage.countH  s     488H%&&r   r   r#   )r   r   r   r   r   rH   r   r   r   ru   r   r5   rF   r   r   r   r   r   r     s1    *
%0-)^O6#('r   r   c                   Z   ^  \ rS rSrSrSrS	S jrS rU 4S jrS
S jr	\
" \	5      r	SrU =r$ )r   iW  z0A fetch_response attribute exchange message
    fetch_responsec                 F    [         R                  U 5        X l        Xl        g)a  
@param request: When supplied, I will use namespace aliases
    that match those in this request.  I will also check to
    make sure I do not respond with attributes that were not
    requested.

@type request: L{FetchRequest}

@param update_url: By default, C{update_url} is taken from the
    request.  But if you do not supply the request, you may set
    the C{update_url} here.

@type update_url: str
N)r   rH   r]   request)r'   r   r]   s      r   rH   FetchResponse.__init__\  s     	""4($r   c                    [        5       n/ nU R                  Gb  U R                   H!  nX0R                  ;  d  M  [        SU< 35      e   U R                  R	                  5        H  nUR
                  c  UR                  UR                  5        O&UR                  UR                  UR
                  5         U R                  UR                     nUR                  [        :w  d  M  UR                  [        U5      :  d  M  [        SUR                  < 35      e   U R                  U5      nU R                  5       nU H8  nUR!                  UR                  5      nUR                  USU-   '   SUSU-   '   M:     U R                  =(       a    U R                  R"                  =(       d    U R"                  n	U	(       a  XS'   UR%                  U5        U$ ! [         a    / nUR                  U5         GN%f = f)zSerialize this object into arguments in the attribute
exchange namespace

@returns: The dictionary of unqualified attribute exchange
    arguments that represent this fetch_response.
@rtype: {unicode;unicode}
z+Response attribute not present in request: z<More than the number of requested values were specified for re   0rd   r]   )r
   r   r   rR   r   r   ra   rG   rh   rS   rF   rK   r   r   r   r=   getAliasr]   update)
r'   rj   zero_value_typesrG   	attr_infor   kv_argsr9   r   r]   s
             r   rk   FetchResponse.getExtensionArgso  s    .<<# !II<</"!%& & & "\\335	 ??*KK	 2 23$$Y%7%7I7!YYy'9'9:F
 OO'77!#f+5!.7.@.@DE E! 6( **73 --/ *I$$Y%7%78E'0'9'9GGeO$(+GHu$% *
 ||?(?(? &oo 	 $.L!w?   7F$++I67s   9GG87G8c                 X   > [         [        U ]  U5        UR                  S5      U l        g)zS@see: {Extension.parseExtensionArgs<openid.extension.Extension.parseExtensionArgs>}r]   N)superr   ru   r5   r]   )r'   r9   r%   s     r   ru    FetchResponse.parseExtensionArgs  s"    mT5g>!++l3r   c                     U " 5       nUR                  UR                  U5      n UR                  U5        U$ ! [         a
  n SnAgSnAff = f)a0  Construct a FetchResponse object from an OpenID library
SuccessResponse object.

@param success_response: A successful id_res response object
@type success_response: openid.consumer.consumer.SuccessResponse

@param signed: Whether non-signed args should be
    processsed. If True (the default), only signed arguments
    will be processsed.
@type signed: bool

@returns: A FetchResponse containing the data from the OpenID
    message, or None if the SuccessResponse did not contain AX
    extension data.

@raises AXError: when the AX data cannot be parsed.
N)extensionResponser@   ru   r    )ry   success_responsesignedr'   r9   r{   s         r   fromSuccessResponse!FetchResponse.fromSuccessResponse  sP    $ u"44T[[&I	##G, K  		s   8 
AA)r   r]   )NN)T)r   r   r   r   r   r3   rH   rk   ru   r   r   r   __classcell__r%   s   @r   r   r   W  s1    D&BH4
8 &&9:r   r   c                   :   ^  \ rS rSrSrSrSU 4S jjrS rSrU =r	$ )r   i  z>A store request attribute exchange message representation
    store_requestc                 6   > [         [        U ]  5         Xl        g)zr
@param aliases: The namespace aliases to use when making this
    store request.  Leave as None to use defaults.
N)r   r   rH   rj   )r'   rj   r%   s     r   rH   StoreRequest.__init__  s    
 	lD*,r   c                 ~    U R                  5       nU R                  U R                  5      nUR                  U5        U$ )zR
@see: L{Extension.getExtensionArgs<openid.extension.Extension.getExtensionArgs>}
)r=   r   rj   r   )r'   r9   r   s      r   rk   StoreRequest.getExtensionArgs  s4     --/**4<<8wr   )rj   r#   )
r   r   r   r   r   r3   rH   rk   r   r   r   s   @r   r   r     s    D r   r   c                   6    \ rS rSrSrSrSrS
S jrS rS r	S	r
g)r   i  zWAn indication that the store request was processed along with
this OpenID transaction.
store_response_successstore_response_failureNc                     [         R                  U 5        U(       a  Ub  [        S5      eU(       a  U R                  U l        OU R
                  U l        X l        g )NzAAn error message may only be included in a failing fetch response)r/   rH   r   SUCCESS_MODEr3   FAILURE_MODEerror_message)r'   	succeededr   s      r   rH   StoreResponse.__init__  sM    4 2 3 4 4))DI))DI*r   c                 4    U R                   U R                  :H  $ )z%Was this response a success response?)r3   r   r&   s    r   r   StoreResponse.succeeded  s    yyD----r   c                     U R                  5       nU R                  5       (       d   U R                  (       a  U R                  US'   U$ )zO@see: {Extension.getExtensionArgs<openid.extension.Extension.getExtensionArgs>}error)r=   r   r   )r'   r9   s     r   rk   StoreResponse.getExtensionArgs  s7    --/~~D$6$6#11GGr   )r   r3   )TN)r   r   r   r   r   r   r   rH   r   rk   r   r   r   r   r   r     s"     ,L+L+.r   r   N)r   __all__openidr   openid.server.trustrootr	   openid.messager
   r   rK   MINIMUM_SUPPORTED_ALIAS_LENGTHr   r   r   r    	Extensionr/   objectrB   rW   r   r   r   r   r   r   r   r   <module>r      s   
  - 2   "$ Fj 
'7 ')#	## )#X3.v 3.lBf9 fRr'	 r'j};% };@$ .I r   