403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.206
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/xdg/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/xdg/__pycache__/Mime.cpython-310.pyc
o

'8�_�f�@s�dZddlZddlZddlZddlZddlZddlmZddlZddl	m
Z
mZddlm
Z
dZiZdZdadZdaejddkZdd	�ZdCd
d�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�d�ZGdd�de�ZGdd�d�Z Gdd�de�Z!edd�Z"edd�Z#edd�Z$edd �Z%edd!�Z&edd"�Z'edd#�Z(edd$�Z)edd%�Z*edd&�Z+d'a,d(d)�Z-d*d+�Z.d,d-�Z/dDd/d0�Z0dDd1d2�Z1d3d4�Z2dEd6d7�Z3dFd8d9�Z4d:d;�Z5er�d<d=�Z6nd>d=�Z6da7d'a8d?d@�Z9dAdB�Z:dS)Ga�
This module is based on a rox module (LGPL):

http://cvs.sourceforge.net/viewcvs.py/rox/ROX-Lib2/python/rox/mime.py?rev=1.21&view=log

This module provides access to the shared MIME database.

types is a dictionary of all known MIME types, indexed by the type name, e.g.
types['application/x-python']

Applications can install information about MIME types by storing an
XML file as <MIME>/packages/<application>.xml and running the
update-mime-database command, which is provided by the freedesktop.org
shared mime database package.

See http://www.freedesktop.org/standards/shared-mime-info-spec/ for
information about the format of these files.

(based on version 0.13)
�N)�
BaseDirectory)�minidom�
XML_NAMESPACE)�defaultdictz5http://www.freedesktop.org/standards/shared-mime-info�cCsd�dd�|jD����S)zGet text of XML node�cSsg|]}|j�qS�)�	nodeValue)�.0�nrr�*/usr/lib/python3/dist-packages/xdg/Mime.py�
<listcomp>/sz"_get_node_data.<locals>.<listcomp>)�join�
childNodes�strip)�noderrr�_get_node_data-srcCs
t||�S)z�Get the MIMEtype object for the given type.
    
    This remains for backwards compatibility; calling MIMEtype now does
    the same thing.
    
    The name can either be passed as one part ('text/plain'), or as two
    ('text', 'plain').
    )�MIMEtype��media�subtyperrr�lookup1s
	rcsbeZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Z�Z
S)rz�Class holding data about a MIME type.
    
    Calling the class will return a cached instance, so there is only one 
    instance for each MIME type. The name can either be passed as one part
    ('text/plain'), or as two ('text', 'plain').
    Ncs�|durd|vr|�dd�\}}d|vsJ�|��}|��}zt||fWStyDtt|��|�}|�||�|t||f<|YSw)N�/�)�split�lower�types�KeyError�superr�__new__�_init)�clsrr�mtype��	__class__rrrCs�zMIMEtype.__new__cCs||_||_d|_dS�N)rr�_comment)�selfrrrrrr Us
zMIMEtype._initcCs�tj�d|j|jd�}t�|�D]<}t�|�}|durq|j	�
td�D](}|�t
d�p-d}d|tjjv}||jdkrD|t|�f|_|d	krLdSq$qdS)
z>Loads comment for current language. Use get_comment() instead.�mime�.xmlN�comment�lang�enrr�)�os�pathrrrr�load_data_pathsr�parse�documentElement�getElementsByTagNameNS�FREE_NS�getAttributeNSr�xdg�Locale�langsr&r)r'�resourcer/�docr*r+�goodnessrrr�_loadZs
��zMIMEtype._loadcCs*|jdurdt|�f|_|��|jdS)z;Returns comment for current language, loading it if needed.Nrr)r&�strr<�r'rrr�get_commentis

zMIMEtype.get_commentcCs&t�t|�}|tvrtt|�S|S)z:Returns the canonical MimeType object if this is an alias.)�update_cacher=�aliasesr)r'�srrr�	canonicalqs
zMIMEtype.canonicalcCs t�tdd�tt|�D��S)z5Returns a set of Mime types which this inherits from.css�|]}t|�VqdSr%)r)r
�trrr�	<genexpr>|��z)MIMEtype.inherits_from.<locals>.<genexpr>)r@�set�inheritancer=r>rrr�
inherits_fromyszMIMEtype.inherits_fromcCs|jd|jS)Nrrr>rrr�__str__~�zMIMEtype.__str__cCsd|j|jfS)NzMIMEtype(%r, %r)rr>rrr�__repr__�rKzMIMEtype.__repr__cCst|j�t|j�ASr%)�hashrrr>rrr�__hash__��zMIMEtype.__hash__r%)�__name__�
__module__�__qualname__�__doc__rr r<r?rCrIrJrLrN�
__classcell__rrr#rr<src@seZdZdS)�UnknownMagicRuleFormatN)rPrQrRrrrrrU�srUc@seZdZdZdS)�DiscardMagicRuleszGRaised when __NOMAGIC__ is found, and caught to discard previous rules.N)rPrQrRrSrrrrrV�srVc@sNeZdZdZdd�Ze�d�Zedd��Z	dd�Z
d	d
�Zdd�Zd
d�Z
dS)�	MagicRuleNcCs"||_||_||_||_||_dSr%��start�value�mask�word�range)r'rYrZr[r\r]rrr�__init__�s

zMagicRule.__init__s(?:~(\d+))?(?:\+(\d+))?\n$cCs�|��}|�dd�\}}|rt|�nd}|�dd�\}}t|�}|dkr&t�tjddkr9tj|dd�d	d
�}nt|d�d>t|d�}|dd�}t|�|kr_||��7}t|�|ksS|d|�||d�}}|�	d�r�t|�|kr�||��7}t|�|ksw|d|d�||dd�}}nd}|j
�|�}|s�tt
|���|��\}	}
|	dur�t|	�nd}	|
dur�t|
�nd}
||||||	|
�fS)
zjRead a rule from the binary magics file. Returns a 2-tuple of
        the nesting depth and the MagicRule.�>rr�=s__NOMAGIC__
rNr-�big)�	byteorder��&)�readliner�intrV�sys�version_info�
from_bytes�ord�len�
startswith�rule_ending_re�matchrU�repr�groups)r!�f�line�
nest_depthrY�lenvaluerZr[�endingr\r]rrr�	from_file�s8�
�$zMagicRule.from_filecCs0|jt|j�|j}|jrt||j���S|Sr%)rYrkrZr]�also�max�maxlen)r'�lrrrry�szMagicRule.maxlencCs$|�|�r|jr|j�|�SdSdS)NT)�match0rwrn�r'�bufferrrrrn�s

�zMagicRule.matchc
Cs�t|�}t|j�}t|j�D]P}|j|}||}||kr dS|jrPd}t|�D]%}tr9||||j|@}	nt|||�t|j|�@}	|t|	�7}q)n|||�}||jkr^dSqdS)NFrT)rkrZr]rYr[�PY3rj�chr)
r'r}rzrt�orB�e�test�i�crrrr{�s(

�
��zMagicRule.match0cCsd|j|j|j|j|jfS)Nz9MagicRule(start=%r, value=%r, mask=%r, word=%r, range=%r)rXr>rrrrL�s�zMagicRule.__repr__)rPrQrRrwr^�re�compilerm�classmethodrvryrnr{rLrrrrrW�s

4rWc@s@eZdZdZdd�Zdd�Zdd�Zedd	��Zed
d��Z	dS)
�
MagicMatchAnyz�Match any of a set of magic rules.
    
    This has a similar interface to MagicRule objects (i.e. its match() and
    maxlen() methods), to allow for duck typing.
    cCs
||_dSr%)�rules)r'r�rrrr^s
zMagicMatchAny.__init__cst�fdd�|jD��S)Nc3s�|]}|���VqdSr%)rn�r
�r�r}rrrEs�z&MagicMatchAny.match.<locals>.<genexpr>)�anyr�r|rr�rrnszMagicMatchAny.matchcCstdd�|jD��S)Ncss�|]}|��VqdSr%)ryr�rrrrErFz'MagicMatchAny.maxlen.<locals>.<genexpr>)rxr�r>rrrryrOzMagicMatchAny.maxlenc	Cs�|�d�}|�dd�g}|r:|dkr:z
|�t�|��Wn	ty&Ynw|�d�}|r4|�dd�|r:|dksg}d|i}|D]\}}g}||�||f�|||d<qB|�|�S)z/Read a set of rules from the binary magic file.r����[r)�read�seek�appendrWrvrU�from_rule_tree)	r!rqr��depths_rules�tree�
insert_points�depth�rule�subrulesrrrrv	s(
�
�
zMagicMatchAny.from_filecCsXg}|D]\}}|r|�|�|_|�|�qt|�dkrdSt|�dkr(|dS||�S)aFrom a nested list of (rule, subrules) pairs, build a MagicMatchAny
        instance, recursing down the tree.
        
        Where there's only one top-level rule, this is returned directly,
        to simplify the nested structure. Returns None if no rules were read.
        rNr)r�rwr�rk)r!r�r�r�r�rrrr�#szMagicMatchAny.from_rule_treeN)
rPrQrRrSr^rnryr�rvr�rrrrr��s
r�c@s@eZdZdd�Zdd�Zdd�Zdd
d�Zddd
�Zdd�Zd	S)�MagicDBcCstt�|_dSr%)r�list�bytyper>rrrr^8�zMagicDB.__init__c		Cst|d��s}|��}|dkrtd��	|���d�}|snS|ddks+|dd	�d
kr0td|��|dd��d
�\}}t|�}t|�}zt�	|�}Wnt
y_|j�|d	�t�	|�}Ynw|d	ureq|j|�
||f�qWd	�d	S1s{wYd	S)z<Read a magic binary file, and add its rules to this MagicDB.�rbsMIME-Magic
zNot a MIME magic fileT�asciir�[���Nz]
zMalformed section headingr�:)�openre�IOError�decode�
ValueErrorrrfrr�rvrVr��popr�)	r'�fnamerqrr�shead�pri�tnamer"r�rrr�
merge_file;s2
��"�zMagicDB.merge_filecCsjd}g|_|j��D]\}}|D]\}}|j�|||f�t||���}qq
||_|jjdd�dd�dS)z{Prepare the MagicDB for matching.
        
        This should be called after all rules have been merged into it.
        rcS�|dS�Nrr��xrrr�<lambda>f�z"MagicDB.finalise.<locals>.<lambda>T��key�reverseN)�alltypesr��itemsr�rxry�sort)r'ryr"r�r�r�rrr�finaliseXs�zMagicDB.finalise�drNcCs�|dur&g}|D]}|j|D]\}}|�|||f�qq|jdd�d�n|j}|D]\}	}
}|	|kr5q+|	|kr<dS|�|�rE|
Sq+dS)a]Do magic sniffing on some bytes.
        
        max_pri & min_pri can be used to specify the maximum & minimum priority
        rules to look for. possible can be a list of mimetypes to check, or None
        (the default) to check all mimetypes until one matches.
        
        Returns the MIMEtype found, or None if no entries match.
        NcSr�r�rr�rrrr�vr�z$MagicDB.match_data.<locals>.<lambda>)r�)r�r�r�r�rn)r'�data�max_pri�min_pri�possibler�mtr�r��priority�mimetyperrr�
match_datahs"	�
��zMagicDB.match_datacCsFt|d��}|�|j�}Wd�n1swY|�||||�S)a�Read data from the file and do magic sniffing on it.
        
        max_pri & min_pri can be used to specify the maximum & minimum priority
        rules to look for. possible can be a list of mimetypes to check, or None
        (the default) to check all mimetypes until one matches.
        
        Returns the MIMEtype found, or None if no entries match. Raises IOError
        if the file can't be opened.
        r�N)r�r�ryr�)r'r/r�r�r�rq�bufrrrrn�s
�z
MagicDB.matchcCsdt|j�S)Nz<MagicDB (%d types)>)rkr�r>rrrrL�r�zMagicDB.__repr__)r�rN)	rPrQrRr^r�r�r�rnrLrrrrr�7s

r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�GlobDBcCstt�|_dS)z�Prepare the GlobDB. It can't actually be used until .finalise() is
        called, but merge_file() can be used to add data before that.
        N)rrG�allglobsr>rrrr^�szGlobDB.__init__cCs�|j}t|��U}|D]I}|�d�rq
|dd��d�}|dd�\}}}t|�}t|�}	t|�dkr:|d�d�}
nd}
|dkrG|�|	d�q
||	�||t	|
�f�q
Wd�dS1s_wYdS)	z3Loads name matching information from a globs2 file.�#Nr�r�r�,r�__NOGLOBS__)
r�r�rlrrfrrkr��add�tuple)r'r/r�rqrr�fields�weight�	type_name�patternr"�flagsrrrr��s"
�"�zGlobDB.merge_filec	CsHtt�|_tt�|_g|_i|_i|_|j��D]\}}|�	�}|D]t\}}}d|v}|�
d�r\|dd�}d|vs\d|vs\d|vs\|rO|j|�||f�n|j|���||f�q"d|vshd|vshd|vr�|rldnt
j}t
jt�|�|d	�}|j�|||f�q"|r�||f|j|<q"||f|j|��<q"q|jjd
dd�d
�dS)zzPrepare the GlobDB for matching.
        
        This should be called after all files have been merged into it.
        �csz*.r-N�*r��?r)r�TcSs|dt|dj�fS)Nr-r)rkr�r�rrrr��sz!GlobDB.finalise.<locals>.<lambda>)r�r�)rr��exts�
cased_exts�globs�literals�cased_literalsr�r�rCrlr�rr��Ir��fnmatch�	translater�)	r'r"r�r�r�r��cased�rest�re_flagsrrrr��s2


�zGlobDB.finalisecCs*z
t|�|��dWStyYdSw)zTReturn the first match found for a given path, or None if no match
        is found.rN)�next�_match_path�
StopIteration�r'r/rrr�first_match�s
�zGlobDB.first_matchcCst|�|��S)z<Return a list of (MIMEtype, glob weight) pairs for the path.)r�r�r�rrr�all_matches�szGlobDB.all_matchesc
cs�tj�|�}||jvr|j|V|��}||jvr!|j|V|}	|�d�}|dkr.n||dd�}||jvrF|j|D]}|Vq@q$|}	|�d�}|dkrTn||dd�}||jvrl|j|D]}|VqfqJ|j	D]\}}}	|�
|�r||	fVqpdS)z(Yields pairs of (mimetype, glob weight).r�.rN)r.r/�basenamer�rr��findr�r�r�rn)
r'r/�leaf�lleaf�ext�p�res�regex�	mime_typer�rrrr��s<�




�


�	

��zGlobDB._match_pathN)	rPrQrRr^r�r�r�r�r�rrrrr��s*r��text�plain�applicationzoctet-stream�inode�blockdevice�
chardevice�	directory�fifo�socket�symlink�door�
executableFc	CsRdaiatt�at�tj�	dd��D]*}t
|d��}|D]}|���dd�\}}|t|<qWd�n1s7wYqt
�at�tj�	dd��D]}t�|�qJt��t�at�tj�	dd��D]}t�|�qct��t�tj�	dd��D]-}t
|d��}|D]}|���dd�\}}t|�|�q�Wd�n1s�wYqydS)	NTr(rAr�r�globs2�magic�
subclasses)�_cache_uptodaterArrGrHrr0r.r/rr�rrr�r�r�r�r�r�r�)r/rqrr�aliasrC�sub�parentrrr�_cache_databases8
�������rcCstst�dSdSr%)r�rrrrrr@=s
�r@cCst�t�|�S)z6Returns type of file by its name, or None if not known)r@r�r�)r/rrr�get_type_by_nameAs
rr�cC�t�t�|||�S)z:Returns type of file by its contents, or None if not known)r@r�rn)r/r�r�rrr�get_type_by_contentsF�rcCr)z0Returns type of the data, which should be bytes.)r@r�r�)r�r�r�rrr�get_type_by_dataLrrcCsXt�|�rtSt�|�rtSt�|�rtSt�|�rtSt�	|�r#t
St�|�r*tSt
S)z.Match special filesystem objects to Mimetypes.)�stat�S_ISDIR�	inode_dir�S_ISCHR�
inode_char�S_ISBLK�inode_block�S_ISFIFO�
inode_fifo�S_ISLNK�
inode_symlink�S_ISSOCK�inode_socket�
inode_door)�st_moderrr�_get_type_by_statRsrTcCs�t�z|rt�|�}nt�|�}Wn
t|�}|ptYSt�|j�rLt||d�}|s2t|�}|s:t||d�}|durJt�	|j�d@rHt
StS|St|j�S)a�Returns type of file indicated by path.
    
    This function is *deprecated* - :func:`get_type2` is more accurate.
    
    :param path: pathname to check (need not exist)
    :param follow: when reading file, follow symbolic links
    :param name_pri: Priority to do name matches. 100=override magic
    
    This tries to use the contents of the file, and falls back to the name. It
    can also handle special filesystem objects like directories and sockets.
    )r�)r�N�I)r@r.r�lstatrr��S_ISREGrr�S_IMODE�app_exer)r/�follow�name_pri�strDrrr�get_type\s&
�
rc
CsLt�z|rt�|�nt�|�}Wnty t|�ptYSwt�|j�s,t	|j�St
t�|�dd�dd�}|rq|dd}d}|dd�D]\}}||krRn|d7}qH|d|�}t
|�dkri|ddSdd	�|D�}nd}z	tj||d
�}	Wnty�d}	Ynw|	r�|	S|r�|ddSt�|j�d@r�tSt|�r�tStS)a�Find the MIMEtype of a file using the XDG recommended checking order.
    
    This first checks the filename, then uses file contents if the name doesn't
    give an unambiguous MIMEtype. It can also handle special filesystem objects
    like directories and sockets.
    
    :param path: file path to examine (need not exist)
    :param follow: whether to follow symlinks
    
    :rtype: :class:`MIMEtype`
    
    .. versionadded:: 1.0
    cSr�)Nrrr�rrrr��r�zget_type2.<locals>.<lambda>Tr�rrNcSsg|]\}}|�qSrr)r
r��wrrrr
�szget_type2.<locals>.<listcomp>)r�r)r@r.rr�OSErrorr�octet_streamrrr�sortedr�r�rkr�rnr�rr�is_text_filer�)
r/rr�mtypes�
max_weightr�r�r r�rDrrr�	get_type2�sB�

�r'cCsZzt|d�}Wn
tyYdSw|�t|�d��Wd�S1s&wYdS)z�Guess whether a file contains text or binary data.
    
    Heuristic: binary if the first 32 bytes include ASCII control characters.
    This rule may change in future versions.
    
    .. versionadded:: 1.0
    r�F� N)r�r��_is_textr�)r/rqrrrr$�s�$�r$cC�tdd�|D��S)Ncs�8�|]}|dkpd|kodknp|dkVqdS)rc�r(�Nr�r
�brrrrE�s�6�_is_text.<locals>.<genexpr>�r��r�rrrr)�rOr)cCr*)Ncsr+)��� �Nrr.rrrrE�s�0�r0r1r2rrrr)�s
�cCsNt�ts#tt�atj��D]\}}|D]\}}t|�|�qqdat|S)aBRetrieve the set of filename extensions matching a given MIMEtype.
    
    Extensions are returned without a leading dot, e.g. 'py'. If no extensions
    are registered for the MIMEtype, returns an empty set.
    
    The extensions are stored in a cache the first time this is called.
    
    .. versionadded:: 1.0
    T)	r@�_mime2ext_cache_uptodaterrG�_mime2ext_cacher�r�r�r�)r�r�r%r"�priorrr�get_extensions�s�r:c
	Cs4|d7}t|��}|��}Wd�n1swYtj�dd�}tj�||�}t�|�D])}zt|��}|��}Wd�n1sEwYWnYq/||krXdSq/datj�t�|�|�}t|d��
}|�	|�Wd�n1szwYd}	t�
tj|	|	t�d��r�t�|�t
d|	��dS)	aCopy 'package_file' as ``~/.local/share/mime/packages/<application>.xml.``
    If package_file is None, install ``<app_dir>/<application>.xml``.
    If already installed, does nothing. May overwrite an existing
    file with the same name (if the contents are different)r)Nr(�packagesFr zupdate-mime-databasez�The '%s' command returned an error code!
Make sure you have the freedesktop.org shared MIME package:
http://standards.freedesktop.org/shared-mime-info/)r�r�r.r/rrr0r��save_data_path�write�spawnlp�P_WAIT�unlink�	Exception)
r��package_filerq�new_data�package_dirr9r��old_data�new_file�commandrrr�install_mime_info�s:

�

����
��rHr%)r�r)Tr�)T);rSr.r�rrgr�r6r�
xdg.Locale�xml.domrr�collectionsrr4rr�r�r�r�rhr~rr�objectrr�rUrArVrWr�r�r�r�r"r
rr	rrrrrr�rr@rrrrrr'r$r)r8r7r:rHrrrr�<module>sj
Kl=^
y








"




%7


Youez - 2016 - github.com/yon3zu
LinuXploit