
    Mi                    N   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKJr  S SKJr  S SKJr  S SKJr  \" \	R&                  5      rSrSrS	rS
rSrSrSrSr\" \\\\45      r\" \\45      r\" \\45      r1 \k\k\kr\R@                  " \RB                  RE                  5       6   \R@                  " \RF                  RE                  5       6   \R@                  " \RH                  RE                  5       6   \R@                  " \RJ                  RE                  5       6   \" \5      r&SS jr'SS jr(SS jr)SS jr*SS jr+S S jr,      S!S jr-S"S jr.S#S jr/\R`                  " S\Rb                  \Rd                  -  5      r3\R`                  " S5      r4S$S jr5S%S jr6g)&    )annotationsN)IO)
extensions)interpreters)licenses	directorysymlinksocketfile
executableznon-executabletextbinaryc                    [         R                  " U 5      nUR                  n[
        R                  " U5      (       a  [        1$ [
        R                  " U5      (       a  [        1$ [
        R                  " U5      (       a  [        1$ [        1n[         R                  " U [         R                  5      nU(       a  UR                  [         5        OUR                  ["        5        [%        [         R&                  R)                  U 5      5      n[+        U5      S:  a  UR-                  U5        O>U(       a7  [/        U 5      n[+        U5      S:  a  UR-                  [1        US   5      5        [2        U-  (       d;  [5        U 5      (       a  UR                  [6        5        OUR                  [8        5        [2        U-  (       d   U5       e[:        U-  (       d   U5       eU$ ! [        [        4 a    [        U  S35      ef = f)N does not exist.r   )oslstatOSError
ValueErrorst_modestatS_ISDIR	DIRECTORYS_ISLNKSYMLINKS_ISSOCKSOCKETFILEaccessX_OKadd
EXECUTABLENON_EXECUTABLEtags_from_filenamepathbasenamelenupdateparse_shebang_from_filetags_from_interpreterENCODING_TAGSfile_is_textTEXTBINARY	MODE_TAGS)r$   srmodetagsr   tshebangs          k/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/identify/identify.pytags_from_pathr5   (   sz   4XXd^ ::D||D{||Dy}}Tx6D4)J  	277++D12A
1vzA-d3G7|a1'!*=> 4HHTNHHV4%%t!T!KQ Z  4D6!12334s   G$ $Hc                f   [         R                  R                  U 5      u  p[         R                  R                  U5      u  p[	        5       nU/UR                  S5      -    H;  nU[
        R                  ;   d  M  UR                  [
        R                  U   5          O   [        U5      S:  a  USS  R                  5       nU[
        R                  ;   a$  UR                  [
        R                  U   5        U$ U[
        R                  ;   a"  UR                  [
        R                  U   5        U$ )N.r      )r   r$   splitsplitextsetr   NAMESr'   r&   lower
EXTENSIONSEXTENSIONS_NEED_BINARY_CHECK)r$   _filenameextretparts         r4   r#   r#   V   s    ''--%KAWWh'FA
%C 
X^^C00:###JJz''-. 1
 3x!|!"gmmo*'''JJz,,S12 J J;;;JJz>>sCDJ    c                    U R                  S5      u    pU (       aE  U [        R                  ;   a  [        R                  U    $ U R                  S5      u  n   nU (       a  ME  [        5       $ )N/r7   )
rpartitionr   INTERPRETERSr;   )interpreterr@   s     r4   r)   r)   l   sb    #..s3Aq ,333,,[99 + 6 6s ;KA	 + 5LrE   c                    [        / SQ5      [        [        SS5      5      -   [        [        SS5      5      -   n[        U R                  S5      R	                  SU5      5      (       + $ )zReturn whether the first KB of contents seems to be binary.

This is roughly based on libmagic's binary/text detection:
https://github.com/file/file/blob/df74b09b9027676088c797528edcaae5a9ce9ad0/src/encoding.c#L203-L228
)      	   
                            i   N)	bytearrayrangeboolread	translate)bytesio
text_charss     r4   is_textr_   y   s`     	/0%d#$	%%e$%	& 
 GLL&00zBCCCrE   c                    [         R                  R                  U 5      (       d  [        U  S35      e[	        U S5       n[        U5      sS S S 5        $ ! , (       d  f       g = f)Nr   rb)r   r$   lexistsr   openr_   )r$   fs     r4   r+   r+      sG    77??4  D6!1233	dD	Qqz 
		s   A
A"c                p     [         R                  " U 5      $ ! [         a    U R                  5       s $ f = f)N)shlexr9   r   )lines    r4   _shebang_splitrh      s5     {{4    zz|s    55c                   U R                  S5      S:X  a  U R                  5       n UR                  S5      nU H  nU[        ;  d  M  Us  $    [        [        UR                  5       5      5      n[        US S 5       H  u  pgUS:w  a  M  XVS-      4nM     U R                  S5      S:X  a  M  U$ ! [         a    Us $ f = f)N      #!UTF-8z-ir8   )	r[   readlinedecodeUnicodeDecodeError	printabletuplerh   strip	enumerate)r]   cmdnext_line_b	next_linecline_tokensitokens           r4   _parse_nix_shebangr|      s     ,,q/U
"&&(	#**73I A	!
  N9??+<=>!+cr"23HA}1u%'C	 4 ,,q/U
"" J " 	J	s   B1 1C ?C c                `   U R                  S5      S:w  a  gU R                  5       n UR                  S5      nU H  nU[        ;  d  M    g   [        [        UR                  5       5      5      nUSS S:X  a  USS nOUSS S:X  a  USS nUS	:X  a  [        X5      $ U$ ! [         a     gf = f)
z8Parse the shebang from a file opened for reading binary.rj   rk    rl   N)/usr/bin/envz-Sr8   )r   )z	nix-shell)	r[   rn   ro   rp   rq   rr   rh   rs   r|   )r]   first_line_b
first_linerx   ru   s        r4   parse_shebangr      s    ||A%##%L!((1

 I  z//12
3C
2Aw((!"g	Ra%	%!"g
n!'//J#  s   B   
B-,B-c                   [         R                  R                  U 5      (       d  [        U  S35      e[         R                  " U [         R
                  5      (       d  g [        U S5       n[        U5      sSSS5        $ ! , (       d  f       g= f! [         a)  nUR                  [        R                  :X  a   SnAge SnAff = f)z$Parse the shebang given a file path.r   r~   ra   N)r   r$   rb   r   r   r   rc   r   r   errnoEINVAL)r$   rd   es      r4   r(   r(      s    77??4  D6!123399T277##$ #  77ell"	s<   B +B 6	B  
B
B B 
CB?>B??Cz^\s*(Copyright|\(C\)) .*$z\s+c                z    [         R                  SU 5      n [        R                  SU 5      n U R                  5       $ )N  )COPYRIGHT_REsubWS_RErs   )ss    r4   _norm_licenser      s0    QA		#qA779rE   c                "   SSK n[        U SS9 nUR                  5       nSSS5        [        W5      n[        R
                  nSn[        R                  " S[        U5      -  5      n[        R                   Hv  u  p[        U	5      n
XJ:X  a  Us  $ U(       a2  [        [        U5      [        U
5      -
  5      [        U5      -  S:  a  MR  UR                  XJU5      nX:  d  Mk  X:  d  Mr  UnUnMx     U(       a  XW:  a  U$ g! , (       d  f       N= f)a  Return the spdx id for the license contained in `filename`.  If no
license is detected, returns `None`.

spdx: https://spdx.org/licenses/
licenses from choosealicense.com: https://github.com/choosealicense.com

Approximate algorithm:

1. strip copyright line
2. normalize whitespace (replace all whitespace with a single space)
3. check exact text match with existing licenses
4. failing that use edit distance
r   Nrl   )encodingr   g?)ukkonenrc   r[   r   sysmaxsizemathceilr&   r   LICENSESabsdistance)rA   r   rd   contentsnormmin_edit_distmin_edit_dist_spdxcutoffspdxr   norm_license	edit_dists               r4   
license_idr      s     	h	)Q668 
* "DKKMYYsSY'F ''
$T*K CD	C$556TBSH$$T@	)";%M!% ( &!! = 
*	)s   D  
D)r$   strreturnset[str])rJ   r   r   r   )r]   	IO[bytes]r   rZ   )r$   r   r   rZ   )rg   r   r   z	list[str])r]   r   ru   tuple[str, ...]r   r   )r]   r   r   r   )r$   r   r   r   )r   r   r   r   )rA   r   r   z
str | None)7
__future__r   r   r   os.pathr   rerf   r   stringr   typingr   identifyr   r   identify.vendorr   	frozensetrq   r   r   r   r   r!   r"   r,   r-   	TYPE_TAGSr.   r*   	_ALL_TAGSr'   r>   valuesr?   r<   rI   ALL_TAGSr5   r#   r)   r_   r+   rh   r|   r   r(   compileI	MULTILINEr   r   r   r   r~   rE   r4   <module>r      s   "    	    
   ! $ f&&'		
	
!	y$89	z>23	64.)4i4)4m4	 	  *''..0 1 	  *99@@B C 	  *""))+ , 	  ,++224 5Y+\,
D	 06" zz6r||8KL


6.rE   