
    ?g                     ^    d Z ddlZddlZddlmZmZ ddlmZ d Zd Z	d Z
d Zd	 Zd
 Zd Zy)zp
oauthlib.utils
~~~~~~~~~~~~~~

This module contains utility methods used by various parts of the OAuth 2 spec.
    N)quoteurlparse)	urldecodec                     t        | t              s| | S t        | t        t        t        f      r(dj                  | D cg c]  }t        |       c}      S t        d| z        c c}w )z5Convert a list of scopes to a space separated string. z8Invalid scope (%s), must be string, tuple, set, or list.)
isinstancestrsettuplelistjoin
ValueErrorscopess     R/var/www/openai/venv/lib/python3.12/site-packages/oauthlib/oauth2/rfc6749/utils.pylist_to_scoper      s_    %	EC-	.xx/AQ/00SV[[\\ 0s   A&c                     t        | t        t        t        f      r| D cg c]  }t	        |       c}S | y| j                         j                  d      S c c}w )z5Convert a space separated string to a list of scopes.Nr   )r   r   r   r
   r	   stripsplitr   s     r   scope_to_listr      sP    %%s+, %&1A&&	{{}""3''	 's   Ac                 ~    t        t        t        |       j                              }d|v rt	        |d         |d<   |S )Nr   )dictr   r   queryr   )uriparamss     r   params_from_urir   "   s:    )HSM//01F&'w8wM    c                     ddd}t        |       \  }}}}}}d|v r|j                  dd      \  }}||fS |j                  |j                               }||fS )zuExtract hostname and port from URI.

    Will use default port for HTTP and HTTPS if none is present in the URI.
    80443)HTTPHTTPS:   )r   r   getupper)	r   default_portsschnetlocpathparr   fraports	            r   host_from_urir/   )   sr     M
 *2#&CsE3
f}||C+ 4<   -4<r   c                 p    t        | t              st        d      t        | j	                  d      d      S )ztEscape a string in an OAuth-compatible fashion.

    TODO: verify whether this can in fact be used for OAuth 2

    z#Only unicode objects are escapable.zutf-8   ~)safe)r   r	   r   r   encode)us    r   escaper5   <   s0     a>??'"..r   c                     t         j                   j                         | z
  }|j                  |j                  |j                  dz  dz  z   dz  z   dz  }t        |      S )z9Generate a age parameter for MAC authentication draft 00.   i  i@B )datetimenowmicrosecondssecondsdaysr	   )
issue_timetdages      r   generate_ager@   G   sZ    						 :	-B??bjj277R<$+>>  Cs8Or   c                     t         j                  j                  d      ry| j                         j	                  d      S )zCheck if the uri is over ssl.OAUTHLIB_INSECURE_TRANSPORTTzhttps://)osenvironr&   lower
startswith)r   s    r   is_secure_transportrG   O   s-    	zz~~3499;!!*--r   )__doc__r8   rC   urllib.parser   r   oauthlib.commonr   r   r   r   r/   r5   r@   rG    r   r   <module>rL      s<     	 ( %](&/.r   