
    )Jf                         d Z g dZddlZddlZddlmZ  ej        e          ZddgZ	g dZ
d Zdd
ZddZddZddZd Zd Zd Z G d de          ZdS )zOThis module contains general utility code that is used throughout
the library.
)log
appendArgstoBase64
fromBase64autoSubmitHTML	toUnicode    N)	urlencodezdefusedxml.cElementTreezdefusedxml.ElementTree)zxml.etree.cElementTreezxml.etree.ElementTreecElementTreezelementtree.ElementTreec                 t    t          | t                    r|                     d          S t          |           S )zReturns the given argument as a unicode object.

    @param value: A UTF-8 encoded string or a unicode (coercable) object
    @type message: str or unicode

    @returns: Unicode object representing the input value.
    utf-8)
isinstancebytesdecodestr)values    Q/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/oidutil.pyr   r      s4     % %||G$$$u::    OpenID transaction in progressc                     t          | t                    rt          | d          } t          |t                    rt          |d          }d|d| d}|S )Nr   encodingz
<html>
<head>
  <title>z=</title>
</head>
<body onload="document.forms[0].submit();">
z
<script>
var elements = document.forms[0].elements;
for (var i = 0; i < elements.length; i++) {
  elements[i].style.display = "none";
}
</script>
</body>
</html>
)r   r   r   )formtitlehtmls      r   r   r   ,   sh    $ +4'***% -EG,,,  uudddD  Kr   c                 t    | t           } 	 t          |           S # t          $ r t          d|           w xY w)aj  Find a working ElementTree implementation that is not vulnerable
    to XXE, using `defusedxml`.

    >>> XXESafeElementTree = importSafeElementTree()

    @param module_names: The names of modules to try to use as
        a safe ElementTree. Defaults to C{L{xxe_safe_elementtree_modules}}

    @returns: An ElementTree module that is not vulnerable to XXE.
    NzSUnable to find a ElementTree module that is not vulnerable to XXE. Tried importing )xxe_safe_elementtree_modulesimportElementTreeImportError)module_namess    r   importSafeElementTreer    D   sd     3C ... C C Ck2>,B C C 	CCs    7c                 2   | t           } | D ]z}	 t          |dddg          }	 |                    d           |c S # t          t          t
          f$ r   t                              d|z             Y hxY w# t          $ r Y ww xY wt          d|           )a:  Find a working ElementTree implementation, trying the standard
    places that such a thing might show up.

    >>> ElementTree = importElementTree()

    @param module_names: The names of modules to try to use as
        ElementTree. Defaults to C{L{elementtree_modules}}

    @returns: An ElementTree module
    Nunusedz	<unused/>zRNot using ElementTree library %r because it failed to parse a trivial document: %szKNo ElementTree library found. You may need to install one. Tried importing )	elementtree_modules
__import__XML
SystemExitMemoryErrorAssertionErrorlogger	exceptionr   )r   mod_nameElementTrees      r   r   r   Y   s     *  C C	#$XtTH:FFK
	#,,, #""" ^<   ?  35=>? ? ? ? ?  	 	 	D	 k2>,B C C 	Cs   A7<6A47
BBc                 <    t                               d|            dS )a  Handle a log message from the OpenID library.

    This is a legacy function which redirects to logger.error.
    The logging module should be used instead of this

    @param message: A string containing a debugging message from the
        OpenID library
    @type message: str

    @param level: The severity of the log message. This parameter is
        currently unused, but in the future, the library may indicate
        more important information with a higher level value.
    @type level: int or None

    @returns: Nothing.
    zHThis is a legacy log message, please use the logging module. Message: %sN)r)   error)messagelevels     r   r   r   ~   s,    $ LL 018: : : : :r   c                    t          |d          r"t          |                                          }nt          |          }t	          | t
                    st          | d          } |s| S d| v rd}nd}d}|D ]e\  }}t	          |t                    s|                    d          }t	          |t                    s|                    d          }||f||<   |dz  }f| |t          |          S )a  Append query arguments to a HTTP(s) URL. If the URL already has
    query arguemtns, these arguments will be added, and the existing
    arguments will be preserved. Duplicate arguments will not be
    detected or collapsed (both will appear in the output).

    @param url: The url to which the arguments will be appended
    @type url: str

    @param args: The query arguments to add to the URL. If a
        dictionary is passed, the items will be sorted before
        appending them to the URL. If a sequence of pairs is passed,
        the order of the sequence will be preserved.
    @type args: A dictionary from string to string, or a sequence of
        pairs of strings.

    @returns: The URL with the parameters added
    @rtype: str
    itemsr   r   ?&r      )	hasattrsortedr2   listr   r   r   encoder	   )urlargssepikvs         r   r   r      s   & tW djjll##Dzzc3 )#((( 

czz 	
A  1!U## 	"!!A!U## 	"!!Aa&Q	QsCC411r   c                     t          | t                    r|                     d          } t          j        |           dd         S )z7Represent string / bytes s as base64, omitting newlinesr   N)r   r   r9   binascii
b2a_base64)ss    r   r   r      s?    !S HHWq!!#2#&&r   c                     t          | t                    r|                     d          } 	 t          j        |           S # t          j        $ r!}t          t          |                    d }~ww xY w)Nr   )r   r   r9   rB   
a2b_base64Error
ValueError)rD   whys     r   r   r      sp    !S HHW#"1%%%> # # #S"""#s   A   A0A++A0c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )SymbolzThis class implements an object that compares equal to others
    of the same type that have the same name. These are distict from
    str or unicode objects.
    c                     || _         d S Nname)selfrO   s     r   __init__zSymbol.__init__   s    			r   c                 ^    t          |           t          |          u o| j        |j        k    S rM   )typerO   rP   others     r   __eq__zSymbol.__eq__   s'    DzzT%[[(DTY%*-DDr   c                     | |k     S rM    rT   s     r   __ne__zSymbol.__ne__   s    EM""r   c                 8    t          | j        | j        f          S rM   )hash	__class__rO   rP   s    r   __hash__zSymbol.__hash__   s    T^TY/000r   c                     d| j         dS )Nz<Symbol >rN   r]   s    r   __repr__zSymbol.__repr__   s      $			,,r   N)	__name__
__module____qualname____doc__rQ   rV   rY   r^   ra   rX   r   r   rK   rK      sl         
  E E E# # #1 1 1- - - - -r   rK   )r   rM   )r   )re   __all__rB   loggingurllib.parser	   	getLoggerrb   r)   r   r#   r   r   r    r   r   r   r   r   objectrK   rX   r   r   <module>rk      sF     
   # " " " " "		8	$	$   
   
 
 
   0C C C C*"C "C "C "CJ: : : :,02 02 02f' ' '# # #- - - - -V - - - - -r   