
     +h<                     "   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ d dlmZmZ d dlZd dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ  eej                   ed          k    rd dlmZ 	 	 d dlmZ n# e $ r	 d dl!mZ Y nw xY wd dl"m#Z# 	 d dl$m%Z% n# e $ r d dl&m'Z' 	 	 	 	 	 ddZ%Y nw xY wn3# e $ r+ 	 d dlm%Z% d dl(mZ d dl)m#Z# n# e $ r  ed          w xY wY nw xY w	 d dl*Z*dZ+n# e $ r dZ+Y nw xY w G d de          Z,dS )    N)LooseVersion)urlparse)	HTTPError)Requesturlopen)ServerProxyFault)sleep)BaseCommandCommandError)color_style)signalcommand)InstallRequirementz19.0)install_req_from_line)
PipSession)parse_requirements)get_installed_distributions)castTFc                     ddl m j                            |                              | |||          }fd|D             S )zReturn a list of installed Distribution objects.
            Left for compatibility until direct pkg_resources uses are refactored out.
            r   )pkg_resources)
local_onlyinclude_editableseditables_only	user_onlyc                 D    g | ]}t          j        |          j        S  )r   Distribution_dist).0distr   s     t/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/django_extensions/management/commands/pipchecker.py
<listcomp>z/get_installed_distributions.<locals>.<listcomp>3   s)    SSSTD3T::@SSS    )pip._internal.metadatar   Environment
from_pathsiter_installed_distributions)r   r   r   r   pathsdistsr   s         @r!   r   r       sl     =<<<<<!-88??\\%"3-#	 ]  E TSSSUSSSSr#   z#Pip version 6 or higher is requiredc                   ^     e Zd ZdZ fdZed             ZddZd Zd Z	d Z
d	 Zd
 Z xZS )Commandz4Scan pip requirement files for out-of-date packages.c           	          t                                          |           |                    ddddd           |                    ddd	d
g dd          f |                    ddddd           d S )Nz-tz--github-api-tokenstoregithub_api_tokenz"A github api authentication token.)actiondesthelpz-rz--requirementappendrequirementsFILENAMEzeCheck all the packages listed in the given requirements file. This option can be used multiple times.)r/   r0   defaultmetavarr1   z-nz--newer
store_true
show_newerz9Also show when newer version then available is installed.)superadd_argumentsadd_argument)selfparser	__class__s     r!   r:   zCommand.add_argumentsG   s    f%%%&w#*N 	 	
 	
 	
 	/(
A 	 	
 	
 	 	 	)L|L 	 	
 	
 	
 	
 	
r#   c                 (   t                      | _        || _        |d         r	|d         }nt          j                            d          rdg}nt          j                            d          rd t          j        d          D             }nUt          j                            d          rdg}n2t          j                            d          rdg}nt          d          i | _        t                      5 }|D ]}t          ||          D ]}t          |t                    st          |j                  }|j        r|j        n|j        j        }t%          t&          j                  t%          d          k    r||j        d	| j        |<   ||j        d	| j        |<   	 d d d            n# 1 swxY w Y   |d
         r|d
         | _        nKt          j                            d          r%t          j                            d          | _        nd | _        |                                  t4          r|                                  n2| j                            | j                            d                     |                                  d S )Nr3   zrequirements.txtc                     g | ]{}t           j                            t           j                            d |                    ?|                                                    d          fd                    |          |S )r3   z.txtzrequirements/{0})ospathisfilejoinlowerendswithformat)r   fs     r!   r"   z"Command.handle.<locals>.<listcomp>b   sy       127>>"',,~q"A"ABBGHwwyyGYGYZ`GaGa"))!,,  r#   zrequirements-dev.txtzrequirements-prod.txtzRequirements file(s) not found)sessionz6.0.8)pip_requrlr.   GITHUB_API_TOKENzYCannot check github urls. The requests library is not installed. ( pip install requests )) r   styleoptionsrA   rB   existslistdirr   reqsr   r   
isinstancer   r   requirementnamelinkfilenamer   pip__version__rK   r.   environget
check_pypiHAS_REQUESTScheck_githubstdoutwriteERRORcheck_other)r<   argsrN   	req_filesrI   rV   reqrT   s           r!   handlezCommand.handleX   s    ]]
>" 	A/IIW^^.// 	A+,IIW^^N++ 
	A 68j6P6P  II W^^233 	A/0IIW^^344 	A01II?@@@	\\ 	W%  -hHHH  C%c+=>> E3CODD'*xF388SX5FD $CO44|G7L7LLL'*#&8+ +	$ (+#&7+ +	$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	& %& 	)$+,>$?D!!Z^^.// 	)$&JNN3E$F$FD!!$(D! 	MKdj..  0K  L  L  M  M  Ms   7B,F00F47F4Nc                     t          ||          }t          j        t          |                                                    S )z#Shorcut for return contents as jsonheaders)r   jsonloadsr   read)r<   rK   rh   rd   s       r!   _urlopen_as_jsonzCommand._urlopen_as_json   s6    c7+++z'#,,++--...r#   c                 H    t          j        dt          |                     S )Nz([ab]|rc|dev)\d+$)researchstr)r<   versions     r!   
_is_stablezCommand._is_stable   s    913w<<@@@@r#   c                                            |          r% fd|D             }|rt          |d                   S |rt          |d                   nd S )Nc                 X    g | ]&}                     t          |                    $|'S r   rr   r   )r   vr<   s     r!   r"   z.Command._available_version.<locals>.<listcomp>   s0    OOOAdool1oo.N.NOaOOOr#   r   ru   )r<   dist_version	availablestables   `   r!   _available_versionzCommand._available_version   sf    ??<(( 	/OOOOOOOF /#F1I...-6@|IaL)))D@r#   c                 6   t                      D ]4}|j        }|| j                                        v r|| j        |         d<   5t	          d          }t          | j                                                  D ]\  }}|d         rd|v r|d         }t          |j                  }d}d}|r	 |	                    |d         j
        d          p4|	                    |d         j
                            dd          d          }d	}t          d
           n_# t          $ rR}| j                            |j                   | j                            d           t          d           Y d}~nd}~ww xY w||                     ||          }	|	s| j                            d          }
n| j        d         r4||	k    r.| j                            d                    |	                    }
n@|	|k    r.| j                            d                    |	                    }
nd}
| j        |= | j                            d                    |                    }nd}
|}| j                            d                    ||
                     | j        |=  dS )z>If the requirement is frozen to pypi, check for a new version.r    zhttps://pypi.python.org/pypirK   TNrJ   -_F   zRetrying in 60 seconds!<   zFrelease is not on pypi (check capitalization and/or --extra-index-url)r8   z{0} available (newer installed)z{0} available
up to date"{dist.project_name} {dist.version}r    znot installed{pkg_info:40} {msg}pkg_infomsg)r   project_namerQ   keysr   listitemsr   rq   package_releasesrT   replacer
   r	   r^   r_   faultStringrz   rM   WARNrN   INFOrG   BOLD)r<   r    rT   pypird   rw   retryrx   erravailable_versionr   r   s               r!   r[   zCommand.check_pypi   s   /11 	/ 	/D$Dty~~''''*.	$'9::dioo//00 #	  #	 ID#5z   36{+DL99 	 ""$($9$9#i.:Mt$T$T  %[X\XmXmnqr{n|  oB  oJ  oJ  KN  PS  oT  oT  VZ  Y[  Y[	 %a  " " "))#/:::))*CDDDb								"  " %)$;$;L)$T$T!( 	*//*rssCC\,/ LCT4T4T*//*K*R*RSd*e*effCC&55*///*@*@AR*S*STTCC&C	$:??+O+V+V\`+V+a+abb%K3::HRU:VVWWW	$G#	  #	 s   0A'D
E4"AE//E4c                 
   t          | j                                                  D ]\  }}|d         }|st          |          }|                    d          rd|vr:|                    d          rPddi}| j        rd                    | j                  |d<   	 t          |          j	        
                    d	d
          d                             d                              d          
                    d          }t          |          dk    r|\  }}nhd|v rD|dd         \  }}|d|d                             dd                              dd          z   z  }n | j                            d|d           anX# t"          t$          f$ rD}| j                            | j                            d|d|d                     Y d}~d}~ww xY w	 t+          j        d|                                          }	nC# t0          $ r6}| j                            dt          |          z             Y d}~ dS d}~ww xY wd|	v rA|	d         dk    r5| j                            | j                            d                      dS d|	v rP|	d                             d          r5| j                            | j                            d                      dS d}
d |v r8|
                    d           \  }}|                    d          r
|d
d         }
nd|v r|
                    d          \  }}
|
| j                            d!          }|
r.d"                    ||          }t+          j        ||                                          }d#                    |||
          }t+          j        ||                                          }d|v rC|d         d$k    r7| j                            d%                    |
dd&         |                    }nj|d'         d( |D             v r| j                            d)          }n;| j                            d*                    |d'         dd&                             }d+|v rd,                    |d+         -          }n#|
|}nd.                    ||
dd&                   }| j                            d/                    ||0                     | j        |= dS )1a  
        If the requirement is frozen to a github url, check for new commits.

        API Tokens
        ----------
        For more than 50 github api calls per hour, pipchecker requires
        authentication with the github api by settings the environemnt
        variable ``GITHUB_API_TOKEN`` or setting the command flag
        --github-api-token='mytoken'``.

        To create a github api token for use at the command line::
             curl -u 'rizumu' -d '{"scopes":["repo"], "note":"pipchecker"}' https://api.github.com/authorizations

        For more info on github api tokens:
            https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
            https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps

        Requirement Format
        ------------------
        Pipchecker gets the sha of frozen repo and checks if it is
        found at the head of any branches. If it is not found then
        the requirement is considered to be out of date.

        Therefore, freezing at the commit hash will provide the expected
        results, but if freezing at a branch or tag name, pipchecker will
        not be able to determine with certainty if the repo is out of date.

        Freeze at the commit hash (sha)::
            git+git://github.com/django/django.git@393c268e725f5b229ecb554f3fac02cfc250d2df#egg=Django
            https://github.com/django/django/archive/393c268e725f5b229ecb554f3fac02cfc250d2df.tar.gz#egg=Django
            https://github.com/django/django/archive/393c268e725f5b229ecb554f3fac02cfc250d2df.zip#egg=Django

        Freeze with a branch name::
            git+git://github.com/django/django.git@master#egg=Django
            https://github.com/django/django/archive/master.tar.gz#egg=Django
            https://github.com/django/django/archive/master.zip#egg=Django

        Freeze with a tag::
            git+git://github.com/django/django.git@1.5b2#egg=Django
            https://github.com/django/django/archive/1.5b2.tar.gz#egg=Django
            https://github.com/django/django/archive/1.5b2.zip#egg=Django

        Do not freeze::
            git+git://github.com/django/django.git#egg=Django

        rK   gitzgithub.com/).tar.gzz.tar.bz2.zipzcontent-typezapplication/jsonz	token {0}Authorization#r~   r   /   archiveN@r    r   z
Failed to parse 
z: zhttps://api.github.com/django/rg   z
%s
messagezBad credentialsz(
Github API: Bad credentials. Aborting!
zAPI Rate Limit Exceededz,
Github API: Rate Limit Exceeded. Aborting!
z.gitzrepo is not frozenz-https://api.github.com/repos/{0}/{1}/branchesz0https://api.github.com/repos/{0}/{1}/commits/{2}z	Not Foundz*{0} not found in {1}. Repo may be private.
   shac                 *    g | ]}|d          d         S )commitr   r   )r   branchs     r!   r"   z(Command.check_github.<locals>.<listcomp>A  s"    2e2e2ev6(3CE3J2e2e2er#   r   z!{0} is not the head of any branchr    r   r   z{0} {1}r   r   )r   rQ   r   rp   
startswithrF   r.   rG   r   rB   splitstriprstriplenr   rM   r`   
ValueError
IndexErrorr^   r_   requestsrZ   ri   r   r   r   )r<   rT   rd   req_urlrh   
path_partsuserrepoe	test_authfrozen_commit_sha	repo_namefrozen_commit_fullr   
branch_urlbranch_datafrozen_commit_urlfrozen_commit_datar   s                      r!   r]   zCommand.check_github   s   ^ dioo//00 R	  R	 ID#%jG 'llG!!%(( ]'-I-I ?@@   2G $ U+6+=+=d>S+T+T(%g..399#qAA!DJJ3OOVVWZ[[aabeff
z??a''!+JD$$*,, ",BQBJD$C*R."8"8B"G"G"O"OPVXZ"["[[[DD J$$$%KLLL
+   !!$*"2"2"2SZSZSZ\]\]\]3^"_"_```$L)ISZ[[[``bb		   !!(SVV"3444 I%%)I*>BS*S*S!!$*"2"23_"`"`aaai''Ii,@,K,KLe,f,f'!!$*"2"23c"d"deee $~~04

60B0B-	-%0055 ?(:122(>%/3zz#,	, (j&&';<<  vLSSTXZcdd
&l:wGGGLLNN$V$]$])%6% %! &.\2CW%U%U%U%Z%Z%\%\" 2227I)7TXc7c7c***+W+^+^_pqtrtqt_uw{+|+|}}CC'.2e2eYd2e2e2eee*//,77CC*//*M*T*TUghmUnorprorUs*t*tuuC}}?FFCPVKFXX"*$++D2CCRC2HIIK3::HRU:VVWWW	$eR	  R	 s1    C&F		G9GG"(H
I*IIc                    | j         r| j                            | j                            d                     | j                                         D ]\  }}d|v rd                    |d                   }n#d|v rd                    |d                   }nd}| j                            | j                            d	                    |
                               dS dS )z
        If the requirement is frozen somewhere other than pypi or github, skip.

        If you have a private pypi or use --extra-index-url, consider contributing
        support here.
        z7
Only pypi and github based requirements are supported:r    r   r   rK   z{url})rK   zunknown packagez1{pkg_info:40} is not a pypi or github requirement)r   N)rQ   r^   r_   rM   r`   r   rG   r   )r<   rT   rd   r   s       r!   ra   zCommand.check_otherO  s
    9 		BKdj../ijjkkk!Y__.. B B	cS==CJJPSTZP[J\\HHc\\&~~#e*~==HH0H!!$*//2e2l2lv~2l22  #A  #A  B  B  B  B		B 		BB Br#   )N)__name__
__module____qualname__r1   r:   r   re   rl   rr   rz   r[   r]   ra   __classcell__)r>   s   @r!   r+   r+   D   s        AD
 
 
 
 
" 4 4 ]4l/ / / /
A A AA A A+  +  + ZA  A  A FB B B B B B Br#   r+   )TTFFN)-ri   rA   rn   distutils.versionr   urllib.parser   urllib.errorr   urllib.requestr   r   xmlrpc.clientr   r	   rW   timer
   django.core.management.baser   r   "django_extensions.management.colorr   "django_extensions.management.utilsr   pip._internal.reqr   rX   pip._internal.req.constructorsr   pip._internal.network.sessionr   ImportErrorpip._internal.downloadpip._internal.req.req_filer   pip._internal.utils.miscr   typingr   pip.downloadpip.reqr   r\   r+   r   r#   r!   <module>r      s"    				 				 * * * * * * ! ! ! ! ! ! " " " " " " + + + + + + + + , , , , , , , , 



       A A A A A A A A : : : : : : < < < < < < 0 0 0 0 0 0<  LL$8$888DDDDDD&B6<<<<<<< 6 6 6555555556======THHHHHHH T T T " 	T 	T 	T 	T 	T 	TT.  B B BB333333++++++....... B B Bl@AAAB 	/.BOOOLL   LLL[B [B [B [B [Bk [B [B [B [B [Bs~   8A? >B9 ?B
B9 B	B9 B B9 B52B9 4B55B9 9C)?CC)C##C)(C)-C4 4C>=C>