PK APOCALYPSE V1

APOCALYPSE V1

Current Path : /opt/hc_python/lib/python3.12/site-packages/identify/__pycache__/
Upload File :
Current File : //opt/hc_python/lib/python3.12/site-packages/identify/__pycache__/identify.cpython-312.pyc

�

���g���8�ddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddl
mZddlmZee	j&�ZdZdZd	Zd
ZdZdZd
ZdZeeeeef�Zeeef�Zeeef�Zhe�e�e�Zej@ejBjE��ej@ejFjE��ej@ejHjE��ej@ejJjE��ee�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+d d�Z,						d!d�Z-d"d�Z.d#d�Z/ej`dejbejdz�Z3ej`d�Z4d$d�Z5d%d�Z6y)&�)�annotationsN)�IO)�
extensions)�interpreters)�licenses�	directory�symlink�socket�file�
executableznon-executable�text�binaryc��	tj|�}|j}tj|�rthStj|�rthStj|�rthSth}tj|tj�}|r|jt �n|jt"�t%tj&j)|��}t+|�dkDr|j-|�n8|r6t/|�}t+|�dkDr|j-t1|d��t2|zs6t5|�r|jt6�n|jt8�t2|zsJ|��t:|zsJ|��|S#ttf$rt|�d���wxYw)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       �@/opt/hc_python/lib/python3.12/site-packages/identify/identify.py�tags_from_pathr5(sn��4�
�X�X�d�^���:�:�D��|�|�D���{���|�|�D���y���}�}�T���x���6�D����4����)�J����������� �	�2�7�7�+�+�D�1�2�A�
�1�v��z����A���-�d�3�G��7�|�a�����1�'�!�*�=�>��4������H�H�T�N��H�H�V���4��%��%���t��!�T�!���K��Q
�Z� �4��D�6�!1�2�3�3�4�s�F0�0Gc�X�tjj|�\}}tjj|�\}}t	�}|g|jd�zD]8}|t
jvs�|jt
j|�nt|�dkDr}|ddj�}|t
jvr$|jt
j|�|S|t
jvr"|jt
j|�|S)N�.r�)rr$�split�splitext�setr�NAMESr'r&�lower�
EXTENSIONS�EXTENSIONS_NEED_BINARY_CHECK)r$�_�filename�ext�ret�parts      r4r#r#Vs����'�'�-�-��%�K�A�x�
�W�W�
�
�h�
'�F�A�s�

�%�C��
�X�^�^�C�0�0���:�#�#�#��J�J�z�'�'��-�.��1�
�3�x�!�|��!�"�g�m�m�o���*�'�'�'��J�J�z�,�,�S�1�2��J��J�;�;�
;��J�J�z�>�>�s�C�D��J�c��|jd�\}}}|r=|tjvrtj|S|jd�\}}}|r�=t�S)N�/r7)�
rpartitionr�INTERPRETERSr;)�interpreterr@s  r4r)r)lsb��#�.�.�s�3��A�q�+���,�3�3�3��,�,�[�9�9� +� 6� 6�s� ;��K��A�	��5�LrEc���tgd��ttdd��zttdd��z}t|jd�j	d|��S)z�Return 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
    )���	�
���
�� ���iN)�	bytearray�range�bool�read�	translate)�bytesio�
text_charss  r4�is_textr_ys`��	�/�0��%��d�#�$�	%��%��e�$�%�	&��
�G�L�L��&�0�0��z�B�C�C�CrEc��tjj|�st|�d���t	|d�5}t|�cddd�S#1swYyxYw)Nr�rb)rr$�lexistsr�openr_)r$�fs  r4r+r+�sD��
�7�7�?�?�4� ��D�6�!1�2�3�3�	
�d�D�	�Q��q�z�
�	�	�s�A�Ac�l�	tj|�S#t$r|j�cYSwxYw)N)�shlexr9r)�lines r4�_shebang_splitrh�s5����{�{�4� � �����z�z�|���s��3�3c�r�|jd�dk(r�|j�}	|jd�}|D]}|tvs�|cStt
|j���}t|dd�D]\}}|dk7r�||dzf}�|jd�dk(r��|S#t$r|cYSwxYw)N��#!�UTF-8���z-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�3�I��A��	�!��
���N�9�?�?�+<�=�>��!�+�c�r�"2�3�H�A�u���}���q�1�u�%�'�C�	4��,�,�q�/�U�
"�"�J��"�	��J�	�s�B(�(B6�5B6c�P�|jd�dk7ry|j�}	|jd�}|D]}|tvs�ytt
|j���}|dddk(r|dd}n
|dddk(r|dd}|d	k(rt||�S|S#t$rYywxYw)
z8Parse the shebang from a file opened for reading binary.rjrk�rlN)�/usr/bin/envz-Sr8)r)z	nix-shell)	r[rnrorprqrrrhrsr|)r]�first_line_b�
first_linerxrus     r4�
parse_shebangr��s����|�|�A��%����#�#�%�L��!�(�(��1�
�
���I������z�/�/�1�2�
3�C�
�2�A�w�(�(��!�"�g��	�R�a��%�	%��!�"�g��
�n��!�'�3�/�/��J��#����s�B�	B%�$B%c�j�tjj|�st|�d���tj|tj
�sy	t
|d�5}t|�cddd�S#1swYyxYw#t$r(}|jtjk(rYd}~y�d}~wwxYw)z$Parse the shebang given a file path.rr~raN)rr$rbrrrrcr�r�errno�EINVAL)r$rd�es   r4r(r(�s���
�7�7�?�?�4� ��D�6�!1�2�3�3�
�9�9�T�2�7�7�#���
�$��
�� ��#��
�
�����7�7�e�l�l�"����	�s<�B� A5�+	B�5A>�:B�>B�	B2�
B-�,B-�-B2z^\s*(Copyright|\(C\)) .*$z\s+c�z�tjd|�}tjd|�}|j�S)N�� )�COPYRIGHT_RE�sub�WS_RErs)�ss r4�
_norm_licenser��s0������Q��A�
�	�	�#�q��A��7�7�9�rEc��ddl}t|d��5}|j�}ddd�t�}tj
}d}t
jdt|�z�}tjD]n\}}	t|	�}
||
k(r|cS|r0tt|�t|
�z
�t|�zdkDr�L|j||
|�}||ks�e||ks�k|}|}�p|r||kr|Sy#1swY��xYw)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
    rNrl)�encodingr�g�������?)
�ukkonenrcr[r��sys�maxsize�math�ceilr&r�LICENSES�abs�distance)rAr�rd�contents�norm�
min_edit_dist�min_edit_dist_spdx�cutoff�spdxr
�norm_license�	edit_dists            r4�
license_idr��s����	
�h��	)�Q��6�6�8��
*���"�D��K�K�M���
�Y�Y�s�S��Y��
'�F��'�'�
��d�$�T�*���<���K��C��D�	�C��$5�5�6��T��B�S�H���$�$�T�<��@�	��v��)�m�";�%�M�!%��(��
��&�!�!��=
*�	)�s�C4�4C=)r$�str�return�set[str])rJr�r�r�)r]�	IO[bytes]r�rZ)r$r�r�rZ)rgr�r�z	list[str])r]r�ru�tuple[str, ...]r�r�)r]r�r�r�)r$r�r�r�)r�r�r�r�)rAr�r�z
str | None)7�
__future__rr�r��os.pathr�rerfr�stringr��typingr�identifyrr�identify.vendorr�	frozensetrqrrrrr!r"r,r-�	TYPE_TAGSr.r*�	_ALL_TAGSr'r>�valuesr?r<rI�ALL_TAGSr5r#r)r_r+rhr|r�r(�compile�I�	MULTILINEr�r�r�r�r~rEr4�<module>r�s���"����	���
�
���!�$�
�f�&�&�'�	��	�
��	��
��
�
�!��
��	���y�$���8�9�	��z�>�2�3�	��6�4�.�)�
�4�i�4�)�4�m�4�	��	���*�'�'�.�.�0�1��	���*�9�9�@�@�B�C��	���*�"�"�)�)�+�,��	���,�+�+�2�2�4�5��Y���+�\�,
�D��	����
����0�6�"�r�z�z�6����r�|�|�8K�L����
�
�6����.rE

if you don't want to be vaporized in a nuclear explosion, i simply have to become nuclear myself… i am atomic