o
    ©N˜P¡A  ã                   @   sT   d Z ddlmZmZ ddlZddlmZ ddlZ	ddl
Z
ddlZG dd„ deƒZdS )a=  
Complete implementation of the XDG Desktop Entry Specification Version 0.9.4
http://standards.freedesktop.org/desktop-entry-spec/

Not supported:
- Encoding: Legacy Mixed
- Does not check exec parameters
- Does not check URL's
- Does not completly validate deprecated/kde items
- Does not completly check categories
é    )ÚIniFileÚis_asciiN)ÚParsingErrorc                   @   sÆ  e Zd ZdZdZdpdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dDdE„ Z%dFdG„ Z&dHdI„ Z'dJdK„ Z(dLdM„ Z)dNdO„ Z*dPdQ„ Z+dRdS„ Z,dTdU„ Z-dVdW„ Z.dXdY„ Z/dZd[„ Z0d\d]„ Z1d^d_„ Z2d`da„ Z3dbdc„ Z4ddde„ Z5dfdg„ Z6dhdi„ Z7djdk„ Z8dldm„ Z9dndo„ Z:dS )qÚDesktopEntryz+Class to parse and validate Desktop EntriesúDesktop EntryNc                 C   s<   t ƒ | _|rtj |¡r|  |¡ dS |r|  |¡ dS dS )z»Create a new DesktopEntry
        
        If filename exists, it will be parsed as a desktop entry file. If not,
        or if filename is None, a blank DesktopEntry is created.
        N)ÚdictÚcontentÚosÚpathÚexistsÚparseÚnew)ÚselfÚfilename© r   úB/var/www/html/env/lib/python3.10/site-packages/xdg/DesktopEntry.pyÚ__init__   s   ÿzDesktopEntry.__init__c                 C   s   |   ¡ S ©N)ÚgetName©r   r   r   r   Ú__str__%   s   zDesktopEntry.__str__c                 C   s   t  | |ddg¡ dS )zParse a desktop entry file.r   úKDE Desktop EntryN)r   r   )r   Úfiler   r   r   r   (   s   zDesktopEntry.parsec                 C   ó
   |   d¡S )NÚType©Úgetr   r   r   r   ÚgetType-   ó   
zDesktopEntry.getTypec                 C   ó   | j ddd�S )z)deprecated, use getVersionString instead ÚVersionÚnumeric©Útyper   r   r   r   r   Ú
getVersion/   s   zDesktopEntry.getVersionc                 C   r   )Nr    r   r   r   r   r   ÚgetVersionString2   r   zDesktopEntry.getVersionStringc                 C   r   )NÚNameT©Úlocaler   r   r   r   r   r   4   ó   zDesktopEntry.getNamec                 C   r   )NÚGenericNameTr'   r   r   r   r   r   ÚgetGenericName6   r)   zDesktopEntry.getGenericNamec                 C   r   )NÚ	NoDisplayÚbooleanr"   r   r   r   r   r   ÚgetNoDisplay8   r)   zDesktopEntry.getNoDisplayc                 C   r   )NÚCommentTr'   r   r   r   r   r   Ú
getComment:   r)   zDesktopEntry.getCommentc                 C   r   )NÚIconTr'   r   r   r   r   r   ÚgetIcon<   r)   zDesktopEntry.getIconc                 C   r   )NÚHiddenr-   r"   r   r   r   r   r   Ú	getHidden>   r)   zDesktopEntry.getHiddenc                 C   r   )NÚ
OnlyShowInT©Úlistr   r   r   r   r   ÚgetOnlyShowIn@   r)   zDesktopEntry.getOnlyShowInc                 C   r   )NÚ	NotShowInTr6   r   r   r   r   r   ÚgetNotShowInB   r)   zDesktopEntry.getNotShowInc                 C   r   )NÚTryExecr   r   r   r   r   Ú
getTryExecD   r   zDesktopEntry.getTryExecc                 C   r   )NÚExecr   r   r   r   r   ÚgetExecF   r   zDesktopEntry.getExecc                 C   r   )NÚPathr   r   r   r   r   ÚgetPathH   r   zDesktopEntry.getPathc                 C   r   )NÚTerminalr-   r"   r   r   r   r   r   ÚgetTerminalJ   r)   zDesktopEntry.getTerminalc                 C   s   | j dddd�S )z%deprecated, use getMimeTypes instead ÚMimeTypeTÚregex)r7   r#   r   r   r   r   r   ÚgetMimeTypeL   s   zDesktopEntry.getMimeTypec                 C   r   )NrC   Tr6   r   r   r   r   r   ÚgetMimeTypesO   r)   zDesktopEntry.getMimeTypesc                 C   r   )NÚ
CategoriesTr6   r   r   r   r   r   ÚgetCategoriesQ   r)   zDesktopEntry.getCategoriesc                 C   r   )NÚStartupNotifyr-   r"   r   r   r   r   r   ÚgetStartupNotifyS   r)   zDesktopEntry.getStartupNotifyc                 C   r   )NÚStartupWMClassr   r   r   r   r   ÚgetStartupWMClassU   r   zDesktopEntry.getStartupWMClassc                 C   r   )NÚURLr   r   r   r   r   ÚgetURLW   r   zDesktopEntry.getURLc                 C   r   )NÚServiceTypesTr6   r   r   r   r   r   ÚgetServiceTypes\   r)   zDesktopEntry.getServiceTypesc                 C   r   )NÚDocPathr   r   r   r   r   Ú
getDocPath^   r   zDesktopEntry.getDocPathc                 C   s   | j dddd�S )NÚKeywordsT)r7   r(   r   r   r   r   r   ÚgetKeywords`   s   zDesktopEntry.getKeywordsc                 C   r   )NÚInitialPreferencer   r   r   r   r   ÚgetInitialPreferenceb   r   z!DesktopEntry.getInitialPreferencec                 C   r   )NÚDevr   r   r   r   r   ÚgetDevd   r   zDesktopEntry.getDevc                 C   r   )NÚFSTyper   r   r   r   r   Ú	getFSTypef   r   zDesktopEntry.getFSTypec                 C   r   )NÚ
MountPointr   r   r   r   r   ÚgetMountPointh   r   zDesktopEntry.getMountPointc                 C   r   )NÚReadOnlyr-   r"   r   r   r   r   r   ÚgetReadonlyj   r)   zDesktopEntry.getReadonlyc                 C   r   )NÚUnmountIconTr'   r   r   r   r   r   ÚgetUnmountIconl   r)   zDesktopEntry.getUnmountIconc                 C   r   )NÚMiniIconTr'   r   r   r   r   r   ÚgetMiniIconq   r)   zDesktopEntry.getMiniIconc                 C   r   )NÚTerminalOptionsr   r   r   r   r   ÚgetTerminalOptionss   r   zDesktopEntry.getTerminalOptionsc                 C   r   )NÚ
DefaultAppr   r   r   r   r   ÚgetDefaultAppu   r   zDesktopEntry.getDefaultAppc                 C   r   )NÚ	ProtocolsTr6   r   r   r   r   r   ÚgetProtocolsw   r)   zDesktopEntry.getProtocolsc                 C   r   )NÚ
ExtensionsTr6   r   r   r   r   r   ÚgetExtensionsy   r)   zDesktopEntry.getExtensionsc                 C   r   )NÚBinaryPatternr   r   r   r   r   ÚgetBinaryPattern{   r   zDesktopEntry.getBinaryPatternc                 C   r   )NÚ	MapNotifyr   r   r   r   r   ÚgetMapNotify}   r   zDesktopEntry.getMapNotifyc                 C   r   )NÚEncodingr   r   r   r   r   ÚgetEncoding   r   zDesktopEntry.getEncodingc                 C   r   )NÚSwallowTitleTr'   r   r   r   r   r   ÚgetSwallowTitle�   r)   zDesktopEntry.getSwallowTitlec                 C   r   )NÚSwallowExecr   r   r   r   r   ÚgetSwallowExecƒ   r   zDesktopEntry.getSwallowExecc                 C   r   )NÚ	SortOrderTr6   r   r   r   r   r   ÚgetSortOrder…   r)   zDesktopEntry.getSortOrderc                 C   r   )NÚFilePatternrD   r"   r   r   r   r   r   ÚgetFilePattern‡   r)   zDesktopEntry.getFilePatternc                 C   r   )NÚActionsTr6   r   r   r   r   r   Ú
getActions‰   r)   zDesktopEntry.getActionsc                 C   sh   t j |¡d dkrd}nt j |¡d dkrd}ntd|ƒ‚tƒ | _|  | j¡ |  d|¡ || _	dS )	zÅMake this instance into a new desktop entry.
        
        If filename has a .desktop extension, Type is set to Application. If it
        has a .directory extension, Type is Directory.
        é   ú.desktopÚApplicationú
.directoryÚ	DirectoryzUnknown extensionr   N)
r	   r
   Úsplitextr   r   r   ÚaddGroupÚdefaultGroupÚsetr   )r   r   r#   r   r   r   r   Ž   s   

zDesktopEntry.newc                 C   s¾   | j dkr| j d¡ | jdkr| j d¡ n| jdkr'| jdkr'| j d¡ z| j| j  d | _W n tyA   | j d	¡ Y nw z| j| j  d
 | _W d S  ty^   | j d¡ Y d S w )Nr   z([KDE Desktop Entry]-Header is deprecatedz.kdelnkz$File extension .kdelnk is deprecatedr|   r~   zUnknown File extensionr   zKey 'Type' is missingr&   zKey 'Name' is missing)	r‚   ÚwarningsÚappendÚfileExtensionr   r#   ÚKeyErrorÚerrorsÚnamer   r   r   r   ÚcheckExtras¢   s    

ÿÿzDesktopEntry.checkExtrasc                 C   sr   || j kst d|¡st d|¡rt|ƒs| j d| ¡ d S d| j| v r5d| j| v r7| j d¡ d S d S d S )Nz^Desktop Action [a-zA-Z0-9\-]+$z^X-zInvalid Group name: %sr5   r9   z;Group may either have OnlyShowIn or NotShowIn, but not both)r‚   ÚreÚmatchr   rˆ   r…   r   )r   Úgroupr   r   r   Ú
checkGroup¹   s   

ÿ
þþÿzDesktopEntry.checkGroupc                 C   sÎ  |dkr�|dks|dks|dkr| j  d| ¡ n|dkr$| j  d¡ n|dks8|d	ks8|d
ks8| j d| ¡ | jdkrJ|d
ksJ| j  d| ¡ n| jdkrY|d
krY| j  d¡ |dkrjd| j| vrj| j  d¡ |d	kr}d| j| vr| j  d¡ d S d S d S |dkr�|  ||¡ d S t dtj	j
 d |¡r›d S t dtj	j
 d |¡r©d S |dkr·| j||dd� d S t dtj	j
 d |¡rÅd S t dtj	j
 d |¡rÙ|  ||¡ d S |dkrç| j||dd� d S |dkrú| j||dd � |  |¡ d S |d!k�r| j||dd � |  |¡ d S |d"k�r!|  ||¡ |  |d¡ d S |dk�r4|  ||¡ |  |d¡ d S |d#k�rG|  ||¡ |  |d¡ d S |d$k�r\| j||dd� |  |d¡ d S |d%k�rq| j||dd � |  |d¡ d S |dk�r†| j||dd � |  |d¡ d S |d&k�rž|  ||¡ |  |d¡ |  |¡ d S t d'tj	j
 d |¡�r¼| j||d(dd)� |  |d¡ d S |d*k�rÑ| j||dd� |  |d¡ d S |d+k�rÞ|  |d¡ d S |dk�rñ|  ||¡ |  |d¡ d S |d,k�r| j||dd � | j  d-| ¡ d S |d.k�r|  ||¡ | j  d-| ¡ d S |d/k�r4| j||d0d� | j  d-| ¡ d S |d1k�rO|  ||¡ |  |d¡ | j  d-| ¡ d S |d2k�rj|  ||¡ |  |d¡ | j  d-| ¡ d S |d3k�r…|  ||¡ |  |d¡ | j  d-| ¡ d S |d4k�r¢| j||dd� |  |d¡ | j  d-| ¡ d S t d5tj	j
 d |¡�rÅ|  ||¡ |  |d¡ | j  d-| ¡ d S |d6k�rÚ|  ||¡ | j  d7| ¡ d S t d8tj	j
 d |¡�r÷|  ||¡ | j  d7| ¡ d S |d9k�r|  ||¡ | j  d7| ¡ d S |d:k�r!|  ||¡ | j  d7| ¡ d S |d;k�r8| j||dd � | j  d7| ¡ d S |d<k�rO| j||dd � | j  d7| ¡ d S |d=k�rd|  ||¡ | j  d7| ¡ d S |d>k�ry|  ||¡ | j  d7| ¡ d S t d?tj	j
 d |¡�r�| j  d7| ¡ d S |d@k�r¥|  ||¡ | j  d7| ¡ d S |dAk�r½| j||dBdd)� | j  d7| ¡ d S |dCk�rÔ| j||dd � | j  d7| ¡ d S t dD|¡�rÝd S | j dE| ¡ d S )FNr   ÚServiceTypeÚServiceÚFSDevicezType=%s is a KDE extensionrC   zType=MimeType is deprecatedr}   ÚLinkr   zGValue of key 'Type' must be Application, Link or Directory, but is '%s'r~   z.File extension is .directory, but Type is '%s'r|   z>Files with Type=Directory should have the extension .directoryr=   z!Type=Application needs 'Exec' keyrM   zType=Link needs 'URL' keyr    z^Nameú$z^GenericNamer,   r-   r"   z^Commentz^Iconr3   r5   Tr6   r9   r;   r?   rA   ry   rG   z	^KeywordsÚlocalestring)r#   r7   rI   rK   rO   zKey '%s' is a KDE extensionrQ   rU   r!   rW   rY   r[   r]   z^UnmountIconro   zKey '%s' is deprecatedz	^MiniIconrc   re   rg   ri   rk   rm   z^SwallowTitlers   rw   rD   ru   z^X-[a-zA-Z0-9-]+zInvalid key: %s)r„   r…   rˆ   r†   r   Ú
checkValuer‹   rŒ   ÚxdgÚLocalerD   ÚcheckOnlyShowInÚ	checkTypeÚcheckCategories)r   ÚkeyÚvaluer�   r   r   r   ÚcheckKeyÄ   s  þ



























zDesktopEntry.checkKeyc                 C   s(   |   ¡ |ks| j d||f ¡ d S d S )Nz Key '%s' only allowed in Type=%s)r   rˆ   r…   )r   r›   r#   r   r   r   r™   €  s   ÿzDesktopEntry.checkTypec                 C   sH   |   |¡}g d¢}|D ]}||vr!|dd… dkr!| j d| ¡ qd S )N)
ÚGNOMEÚKDEÚLXDEÚMATEÚRazorÚROXÚTDEÚUnityÚXFCEÚOldr   é   úX-z)'%s' is not a registered OnlyShowIn value)ÚgetListrˆ   r…   )r   rœ   ÚvaluesÚvalidÚitemr   r   r   r˜   „  s   
€þzDesktopEntry.checkOnlyShowInc                    st   |   |¡}g d¢‰ t‡ fdd„|D ƒƒs| j d¡ g d¢}|ˆ  }|D ]}||vr7| d¡s7| j d| ¡ q$d S )N)Ú
AudioVideoÚAudioÚVideoÚDevelopmentÚ	EducationÚGameÚGraphicsÚNetworkÚOfficeÚScienceÚSettingsÚSystemÚUtilityc                 3   s   � | ]}|ˆ v V  qd S r   r   )Ú.0r­   ©Úmainr   r   Ú	<genexpr>�  s   € z/DesktopEntry.checkCategories.<locals>.<genexpr>zMissing main category)~ÚBuildingÚDebuggerÚIDEÚGUIDesignerÚ	ProfilingÚRevisionControlÚTranslationÚCalendarÚContactManagementÚDatabaseÚ
DictionaryÚChartÚEmailÚFinanceÚ	FlowChartÚPDAÚProjectManagementÚPresentationÚSpreadsheetÚWordProcessorÚ
2DGraphicsÚVectorGraphicsÚRasterGraphicsÚ
3DGraphicsÚScanningÚOCRÚPhotographyÚ
PublishingÚViewerÚ	TextToolsÚDesktopSettingsÚHardwareSettingsÚPrintingÚPackageManagerÚDialupÚInstantMessagingÚChatÚ	IRCClientÚFeedÚFileTransferÚHamRadioÚNewsÚP2PÚRemoteAccessÚ	TelephonyÚTelephonyToolsÚVideoConferenceÚ
WebBrowserÚWebDevelopmentÚMidiÚMixerÚ	SequencerÚTunerÚTVÚAudioVideoEditingÚPlayerÚRecorderÚDiscBurningÚ
ActionGameÚAdventureGameÚ
ArcadeGameÚ	BoardGameÚ
BlocksGameÚCardGameÚKidsGameÚ	LogicGameÚRolePlayingÚShooterÚ
SimulationÚ
SportsGameÚStrategyGameÚArtÚConstructionÚMusicÚ	LanguagesÚArtificialIntelligenceÚ	AstronomyÚBiologyÚ	ChemistryÚComputerScienceÚDataVisualizationÚEconomyÚElectricityÚ	GeographyÚGeologyÚ
GeoscienceÚHistoryÚ
HumanitiesÚImageProcessingÚ
LiteratureÚMapsÚMathÚNumericalAnalysisÚMedicalSoftwareÚPhysicsÚRoboticsÚSpiritualityÚSportsÚParallelComputingÚ	AmusementÚ	ArchivingÚCompressionÚElectronicsÚEmulatorÚEngineeringÚ	FileToolsÚFileManagerÚTerminalEmulatorÚ
FilesystemÚMonitorÚSecurityÚAccessibilityÚ
CalculatorÚClockÚ
TextEditorÚDocumentationÚAdultÚCorerŸ   rž   r¦   ÚGTKÚQtÚMotifÚJavaÚConsoleOnlyr©   z!'%s' is not a registered Category)rª   Úanyrˆ   r…   Ú
startswith)r   rœ   r«   Ú
additionalÚallcategoriesr­   r   r¼   r   rš   Œ  s   
€þzDesktopEntry.checkCategoriesc                 C   s   t  dt¡ |  |¡S )z`Deprecated alias for checkCategories - only exists for backwards
        compatibility.
        z1checkCategorie is deprecated, use checkCategories)r„   ÚwarnÚDeprecationWarningrš   )r   rœ   r   r   r   ÚcheckCategorieš  s   ÿ
zDesktopEntry.checkCategorier   );Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‚   r   r   r   r   r$   r%   r   r+   r.   r0   r2   r4   r8   r:   r<   r>   r@   rB   rE   rF   rH   rJ   rL   rN   rP   rR   rT   rV   rX   rZ   r\   r^   r`   rb   rd   rf   rh   rj   rl   rn   rp   rr   rt   rv   rx   rz   r   rŠ   rŽ   r�   r™   r˜   rš   r@  r   r   r   r   r      st    
 =r   )rD  Úxdg.IniFiler   r   Ú
xdg.Localer–   Úxdg.Exceptionsr   Úos.pathr	   r‹   r„   r   r   r   r   r   Ú<module>   s    