Mini Shell

Direktori : /usr/lib/python3.6/site-packages/xdg/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/xdg/__pycache__/RecentFiles.cpython-36.pyc

3

ѢUP��@sXdZddlZddlZddlZddlZddlZddlmZGdd�d�Z	Gdd�d�Z
dS)z{
Implementation of the XDG Recent File Storage Specification Version 0.2
http://standards.freedesktop.org/recent-file-spec
�N)�ParsingErrorc@sTeZdZdd�Zddd�Zdd�Zddd	�Zddd�Zddd�Zdd�Z	dd�Z
dS)�RecentFilescCsg|_d|_dS)N�)r�filename)�self�r�!/usr/lib/python3.6/RecentFiles.py�__init__szRecentFiles.__init__NcCs�|stjjtjd�d�}ytjjj|�}Wn@tk
rHt	d|��Yn$tj
jjk
rjt	d|��YnX||_
x\|jD]R}|jtjjjkrz|jdkrzx2|jD](}|jtjjjkr�|jdkr�|j|�q�WqzW|j�dS)ziParse a list of recently used files.
        
        filename defaults to ``~/.recently-used``.
        �HOMEz.recently-usedzFile not foundzNot a valid .menu filerZ
RecentItemN)�os�path�join�getenv�xml�domZminidom�parse�IOErrorrZparsersZexpatZ
ExpatErrorr�
childNodes�nodeType�Node�ELEMENT_NODE�tagName�_RecentFiles__parseRecentItem�sort)rr�docZchild�recentrrrrs"

zRecentFiles.parsecCs�t�}|jj|�x�|jD]�}|jtjjjkr|j	dkrH|jdj
|_q|j	dkrb|jdj
|_q|j	dkr�t
|jdj
�|_q|j	dkr�d|_q|j	dkrx<|jD]2}|jtjjjkr�|j	dkr�|jj|jdj
�q�WqWdS)	N�URIrz	Mime-Type�	Timestamp�PrivateT�GroupsZGroup)�
RecentFiler�appendrrrrrrrZ	nodeValuer�MimeType�intrZPrviater)r�itemrZ	attribute�grouprrrZ__parseRecentItem*s"





zRecentFiles.__parseRecentItemcCs&|r|jrtd|��n
|s$|j}t|d�}tj|tj�|jd�|jd�x�|jD]�}|jd�|jdtj	j
j|j��|jd|j
�|jd|j�|jd	kr�|jd
�t|j�dkr�|jd�x|jD]}|jd
|�q�W|jd�|jd�qXW|jd�tj|tj�|j�dS)z�Write the list of recently used files to disk.
        
        If the instance is already associated with a file, filename can be
        omitted to save it there again.
        zFile not found�wz<?xml version="1.0"?>
z<RecentFiles>
z  <RecentItem>
z    <URI>%s</URI>
z    <Mime-Type>%s</Mime-Type>
z    <Timestamp>%s</Timestamp>
Tz    <Private/>
rz
    <Groups>
z      <Group>%s</Group>
z    </Groups>
z  </RecentItem>
z</RecentFiles>
N)rr�open�fcntl�lockfZLOCK_EX�writerrZsaxZsaxutils�escaperr"rr�lenrZLOCK_UN�close)rr�f�rr%rrrr*?s0








zRecentFiles.writerc	Cs�g}d}x�|jD]�}|rDxv|D] }||jkr|j|�|d7}qWnL|rtxF|D] }||jkrN|j|�|d7}qNWn|jdkr�|j|�|d7}|dkr||krPqW|S)z�Get a list of recently used files.
        
        The parameters can be used to filter by mime types, by group, or to
        limit the number of items returned. By default, the entire list is
        returned, except for items marked private.
        r�F)rrr!r"r)	rZ	mimetypes�groups�limitZtmp�ir$r%�mimetyperrr�getFilesas&







zRecentFiles.getFilesFcCs�||jkr"|jj|�}|j|}n*t|j�dkr:|jj�t�}|jj|�||_||_tt	j	��|_
||_|rv||_|j
�dS)z}Add a recently used file.
        
        item should be the URI of the file, typically starting with ``file:///``.
        i�N)r�indexr,�popr r!rr"r#�timerrrr)rr$r4r1Zprivater6rrrr�addFile~s

zRecentFiles.addFilecCs||jkr|jj|�dS)z<Remove a recently used file, by URI, from the list.
        N)r�remove)rr$rrr�
deleteFile�s
zRecentFiles.deleteFilecCs|jj�|jj�dS)N)rr�reverse)rrrrr�s
zRecentFiles.sort)N)N)NNr)NF)�__name__�
__module__�__qualname__r	rrr*r5r9r;rrrrrr
s

"

rc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)r cCs"d|_d|_d|_d|_g|_dS)NrF)rr"rrr)rrrrr	�s
zRecentFile.__init__cCst|j|j�S)N)Zcmpr)r�otherrrr�__cmp__�szRecentFile.__cmp__cCs|j|jkS)N)r)rr@rrr�__lt__�szRecentFile.__lt__cCs|jt|�kS)N)r�str)rr@rrr�__eq__�szRecentFile.__eq__cCs|jS)N)r)rrrr�__str__�szRecentFile.__str__N)r=r>r?r	rArBrDrErrrrr �s
r )�__doc__Zxml.dom.minidomrZxml.sax.saxutilsrr8r(Zxdg.Exceptionsrrr rrrr�<module>s