
    _Og=(                     N   S r SSKJr  SSKrSSKJr  SSKJr  SSK	r
SSKrSSKJr  SSKJr  0 r\" \5      rS r " S	 S
\R(                  R*                  5      r " S S\R(                  R.                  5      r " S S\R2                  5      rS r " S S\5      r " S S\5      rg)z)Module containing session and auth logic.    N)contextmanager)	getLogger   )__version__)
exceptionsc                 l    U R                   S:X  a$  SU R                  ;   a  SU R                  S   ;   a  gg)zDDetermine whether a response requires us to prompt the user for 2FA.i  X-GitHub-OTPrequiredTF)status_codeheaders)responses    T/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/github3/session.pyrequires_2far      s9     	#h...(**>::    c                       \ rS rSrSrS rSrg)	BasicAuth   z2Sub-class requests's class so we have a nice repr.c                      SU R                    3$ )z'Use the username as the representation.zbasic )usernameselfs    r   __repr__BasicAuth.__repr__   s    ''r    N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s
    <(r   r   c                   :    \ rS rSrSrSrS rS rS rS r	S r
S	rg
)	TokenAuth$   z&Auth class that handles simple tokens.ztoken {}c                     Xl         g)zStore our token.Ntokenr   r&   s     r   __init__TokenAuth.__init__)   s    
r   c                 (    SU R                   SS  S3$ )'Return a nice view of the token in use.ztoken N   z...r%   r   s    r   r   TokenAuth.__repr__-   s    

2A's++r   c                     X:X  + $ )'Test for equality, or the lack thereof.r   r   others     r   __ne__TokenAuth.__ne__1   s      r   c                 6    U R                   [        USS5      :H  $ )r/   r&   N)r&   getattrr0   s     r   __eq__TokenAuth.__eq__5   s    zzWUGT:::r   c                 j    U R                   R                  U R                  5      UR                  S'   U$ )+Add the authorization header and format it.Authorization)header_format_strformatr&   r   )r   requests     r   __call__TokenAuth.__call__9   s/    +/+A+A+H+HJJ,
( r   r%   N)r   r   r   r   r   r;   r(   r   r2   r6   r>   r    r   r   r   r"   r"   $   s$    0",!;r   r"   c                      ^  \ rS rSrSrSr\R                  R                  / SQ-   rSU 4S jjr	\
S 5       rS rS rU 4S	 jrS
 rS rU 4S jrS rS rS rS rS r\S 5       r\S 5       rSrU =r$ )GitHubSessionA   a  Our slightly specialized Session object.

Normally this is created automatically by
:class:`~github3.github.GitHub`.  To use alternate values for
network timeouts, this class can be instantiated directly and
passed to the GitHub object.  For example:

.. code-block:: python

   gh = github.GitHub(session=session.GitHubSession(
       default_connect_timeout=T, default_read_timeout=N))

:param default_connect_timeout:
   the number of seconds to wait when establishing a connection to
   GitHub
:type default_connect_timeout:
   float
:param default_read_timeout:
   the number of seconds to wait for a response from GitHub
:type default_read_timeout:
   float
N)base_urltwo_factor_auth_cbdefault_connect_timeoutdefault_read_timeoutrequest_counterc                    > [         TU ]  5         Xl        X l        U R                  R                  SSSS[         3S.5        SU l        SU l        SU l	        g)	z.Slightly modify how we initialize our session.z#application/vnd.github.v3.full+jsonzutf-8zapplication/jsonzgithub3.py/)AcceptzAccept-CharsetzContent-Typez
User-Agentzhttps://api.github.comNr   )
superr(   rE   rF   r   updater   rC   rD   rG   )r   rE   rF   	__class__s      r   r(   GitHubSession.__init__b   s`    '>$$8! @") 2 +K=9		
 1"& r   c                 2    U R                   U R                  4$ )z0Return the timeout tuple as expected by Requests)rE   rF   r   s    r   timeoutGitHubSession.timeoutw   s     ,,d.G.GHHr   c                 B    U(       a  U(       d  g[        X5      U l        g)zSet the Basic Auth credentials on this Session.

:param str username: Your GitHub username
:param str password: Your GitHub password
N)r   auth)r   r   passwords      r   
basic_authGitHubSession.basic_auth|   s     Xh1	r   c                 p   UR                  S5      =(       d    U R                  /nUR                  U5        U Vs/ s H  n[        U5      PM     nn[	        U5      n[
        R                  SU5        U[        ;  a-  [
        R                  S5        SR                  U5      [        U'   [        U   $ s  snf )z!Build a new API url from scratch.rC   zBuilding a url from %sz!Missed the cache building the url/)	getrC   extendstrtuple__logs__info__url_cache__join)r   argskwargspartspkeys         r   	build_urlGitHubSession.build_url   s    J'84==9T!&'AQ'El.4m#MM=>!$%M#S!! (s   B3c                    > UR                  S0 5      nUR                  S[        U R                  5       5      05        UR                  US9  [        TU ]  " U0 UD6$ )z,Handler for when the user has 2FA turned on.r   r	   )r   )poprK   rZ   rD   rJ   r=   )r   r`   ra   r   rL   s       r   handle_two_factor_auth$GitHubSession.handle_two_factor_auth   sT    **Y+D,C,C,E(FGHg&w///r   c                 ^    U R                   =(       d    U R                  R                  S5      $ )z@Check for whether or not the user has authentication configured.r:   )rR   r   rX   r   s    r   has_authGitHubSession.has_auth   s     yy=DLL,,_==r   c                     [        S5      e)zUse OAuth2 for authentication.

It is suggested you install requests-oauthlib to use this.

:param str client_id: Client ID retrieved from GitHub
:param str client_secret: Client secret retrieved from GitHub
z&These features are not implemented yet)NotImplementedErrorr   	client_idclient_secrets      r   oauth2_authGitHubSession.oauth2_auth   s     ""JKKr   c                 (  > UR                  SU R                  5        [        TU ]  " U0 UD6nU =R                  S-  sl        [        U5      (       a?  U R                  (       a.  U R                  X5      nUR                  R                  U5        UnU$ )z6Make a request, count it, and handle 2FA if necessary.rO   r   )

setdefaultrO   rJ   r=   rG   r   rD   ri   historyappend)r   r`   ra   r   new_responserL   s        r   r=   GitHubSession.request   s~    )T\\27?D3F3!!!d&=&=  66tDL  ''1#Hr   c                 t    U R                   R                  S5      nU R                   R                  S5      nX4$ )zJReturn the client credentials.

:returns: tuple(client_id, client_secret)
rq   rr   )paramsrX   rp   s      r   retrieve_client_credentials)GitHubSession.retrieve_client_credentials   s1    
 KKOOK0	8))r   c                 t    U(       d  g[        U[        R                  5      (       d  [        S5      eXl        g)z0Register our 2FA callback specified by the user.Nz Your callback should be callable)
isinstanceabc_collectionsCallable
ValueErrorrD   )r   callbacks     r   two_factor_auth_callback&GitHubSession.two_factor_auth_callback   s-    (O$<$<==?@@"*r   c                 4    U(       d  g[        U5      U l        g)zUse an application token for authentication.

:param str token: Application token retrieved from GitHub's
    /authorizations endpoint
N)r"   rR   r'   s     r   
token_authGitHubSession.token_auth   s     e$	r   c                 4    U(       d  g[        X5      U l        g)z7Authenticate as an App to be able to view its metadata.N)AppBearerTokenAuthrR   )r   r   	expire_ins      r   app_bearer_token_auth#GitHubSession.app_bearer_token_auth   s    &w:	r   c                 B    U(       d  g[        US   US   5      U l        g)z7Use an access token generated by an App's installation.Nr&   
expires_at)AppInstallationTokenAuthrR   )r   jsons     r   app_installation_token_auth)GitHubSession.app_installation_token_auth   s"    ,M4-
	r   c              '      #    U R                   nU R                  R                  S5      nU R                  " U6   Sv   X l         U(       a  X0R                  S'   gg7f)z8Allow us to temporarily swap out basic auth credentials.r:   N)rR   r   rX   rT   )r   rR   old_basic_authold_token_auths       r   temporary_basic_auth"GitHubSession.temporary_basic_auth   sL      ))/:"	,:LL) s   AAc              #      #    U R                   Ssol         U R                  R                  SS5      nSv   Xl         U(       a  X R                  S'   gg7f)z6Unset authentication temporarily as a context manager.Nr:   )rR   r   rh   )r   r   r   s      r   no_authGitHubSession.no_auth   sI      %)IIt!	))/4@"	,:LL) s   AA)rR   rC   rE   rF   rG   rD   )r,   
   )r   r   r   r   r   rR   requestsSession	__attrs__r(   propertyrO   rT   re   ri   rl   rs   r=   r}   r   r   r   r   r   r   r   r    __classcell__rL   s   @r   rA   rA   A   s    . D  ** . I!* I I	2
"0>L*+	%;
 
; 
; 	; 	;r   rA   c                  p    [         R                   R                  [        R                  R                  5      $ )N)datetimenowdateutiltzUTCr   r   r   _utcnowr      s!      11r   c                   N   ^  \ rS rSrSrU 4S jrS r\S 5       rU 4S jr	Sr
U =r$ )r   i  z>Use token authentication but throw an exception on expiration.c                 x   > [         TU ]  U5        X l        [        R                  R                  U5      U l        g)"Set-up our authentication handler.N)rJ   r(   expires_at_strr   parserparser   )r   r&   r   rL   s      r   r(   !AppInstallationTokenAuth.__init__  s,    ("////
;r   c                 T    SR                  U R                  SS U R                  5      $ )r+   z+app installation token {}... expiring at {}Nr,   )r<   r&   r   r   s    r   r   !AppInstallationTokenAuth.__repr__
  s*    <CCJJrND//
 	
r   c                 2    [        5       nXR                  :  $ z-Indicate whether our token is expired or not.r   r   r   r   s     r   expired AppInstallationTokenAuth.expired       i__$$r   c                    > U R                   (       a/  [        R                  " SR                  U R                  5      5      e[
        TU ]  U5      $ )r9   z)Your app installation token expired at {})r   excAppInstallationTokenExpiredr<   r   rJ   r>   r   r=   rL   s     r   r>   !AppInstallationTokenAuth.__call__  sF    <<11;BB'' 
 w((r   )r   r   )r   r   r   r   r   r(   r   r   r   r>   r    r   r   s   @r   r   r     s.    H<
 % %
) )r   r   c                   R   ^  \ rS rSrSrSrU 4S jrS r\S 5       r	U 4S jr
SrU =r$ )	r   i!  z<Use JWT authentication but throw an exception on expiration.z	Bearer {}c                 p   > [         TU ]  U5        [        R                  " US9n[	        5       U-   U l        g)r   )secondsN)rJ   r(   r   	timedeltar   r   )r   r&   r   rL   s      r   r(   AppBearerTokenAuth.__init__&  s.    &&y9	!)i/r   c                 f    SR                  U R                  SS [        U R                  5      5      $ )z#Return a helpful view of the token.z"app bearer token {} expiring at {}Nr,   )r<   r&   rZ   r   r   s    r   r   AppBearerTokenAuth.__repr__,  s-    3::JJrNC0
 	
r   c                 2    [        5       nXR                  :  $ r   r   r   s     r   r   AppBearerTokenAuth.expired2  r   r   c                    > U R                   (       a,  [        R                  " S[        U R                  5       35      e[
        TU ]  U5      $ )r9   zYour app token expired at )r   r   AppTokenExpiredrZ   r   rJ   r>   r   s     r   r>   AppBearerTokenAuth.__call__8  sC    <<%%,S-A,BC  w((r   )r   )r   r   r   r   r   r;   r(   r   r   r   r>   r    r   r   s   @r   r   r   !  s4    F#0
 % %
) )r   r   )r   collections.abcabcr   r   
contextlibr   loggingr   dateutil.parserr   r    r   r   r   r^   __package__r\   r   rR   HTTPBasicAuthr   AuthBaser"   r   rA   r   r   r   r   r   r   <module>r      s    / )  %     [!(++ (&& :y;H$$ y;x2)y )@) )r   