
    b_6D                     f    d Z ddlmZmZ ddlZddlmZ ddlm	Z	 ddl
ZddlZddlZ G d de      Zy)a/  
Complete implementation of the XDG Desktop Entry Specification
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)ParsingError)whichc                   `   e Zd ZdZdZd;dZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z;y)<DesktopEntryz+Class to parse and validate Desktop EntriesDesktop EntryNc                     t               | _        |r1t        j                  j	                  |      r| j                  |       y|r| j                  |       yy)zCreate 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filenames     0lib/python3.12/site-packages/xdg/DesktopEntry.py__init__zDesktopEntry.__init__   s?     vx0JJx HHX     c                 "    | j                         S N)getNamer   s    r   __str__zDesktopEntry.__str__&   s    ||~r   c                 6    t        j                  | |ddg       y)zParse a desktop entry file.
        
        This can raise :class:`~xdg.Exceptions.ParsingError`,
        :class:`~xdg.Exceptions.DuplicateGroupError` or
        :class:`~xdg.Exceptions.DuplicateKeyError`.
        r	   KDE Desktop EntryN)r   r   )r   files     r   r   zDesktopEntry.parse)   s     	dD?4G"HIr   c                 >    | j                  dd      }t        |      S )zLooks in the PATH for the executable given in the TryExec field.
        
        Returns the full path to the executable if it is found, None if not.
        Raises :class:`~xdg.Exceptions.NoKeyError` if TryExec is not present.
        TryExecT)strict)getr   )r   tryexecs     r   findTryExeczDesktopEntry.findTryExec2   s      ((9T(2W~r   c                 $    | j                  d      S )NTyper"   r   s    r   getTypezDesktopEntry.getType<       xxr   c                 (    | j                  dd      S )z)deprecated, use getVersionString instead Versionnumerictyper'   r   s    r   
getVersionzDesktopEntry.getVersion>   s    xx		x22r   c                 $    | j                  d      S )Nr+   r'   r   s    r   getVersionStringzDesktopEntry.getVersionStringA       xx	""r   c                 (    | j                  dd      S )NNameTlocaler'   r   s    r   r   zDesktopEntry.getNameC       xxtx,,r   c                 (    | j                  dd      S )NGenericNameTr5   r'   r   s    r   getGenericNamezDesktopEntry.getGenericNameE       xxdx33r   c                 (    | j                  dd      S )N	NoDisplaybooleanr-   r'   r   s    r   getNoDisplayzDesktopEntry.getNoDisplayG   s    xx)x44r   c                 (    | j                  dd      S )NCommentTr5   r'   r   s    r   
getCommentzDesktopEntry.getCommentI   s    xx	$x//r   c                 (    | j                  dd      S )NIconTr5   r'   r   s    r   getIconzDesktopEntry.getIconK   r7   r   c                 (    | j                  dd      S )NHiddenr>   r-   r'   r   s    r   	getHiddenzDesktopEntry.getHiddenM   s    xxyx11r   c                 (    | j                  dd      S )N
OnlyShowInTlistr'   r   s    r   getOnlyShowInzDesktopEntry.getOnlyShowInO       xx4x00r   c                 (    | j                  dd      S )N	NotShowInTrK   r'   r   s    r   getNotShowInzDesktopEntry.getNotShowInQ       xx$x//r   c                 $    | j                  d      S )Nr    r'   r   s    r   
getTryExeczDesktopEntry.getTryExecS   r2   r   c                 $    | j                  d      S )NExecr'   r   s    r   getExeczDesktopEntry.getExecU   r)   r   c                 $    | j                  d      S )NPathr'   r   s    r   getPathzDesktopEntry.getPathW   r)   r   c                 (    | j                  dd      S )NTerminalr>   r-   r'   r   s    r   getTerminalzDesktopEntry.getTerminalY       xx
x33r   c                 *    | j                  ddd      S )z%deprecated, use getMimeTypes instead MimeTypeTregex)rL   r.   r'   r   s    r   getMimeTypezDesktopEntry.getMimeType[   s    xx
Gx<<r   c                 (    | j                  dd      S )Nr`   TrK   r'   r   s    r   getMimeTypeszDesktopEntry.getMimeTypes^   s    xx
x..r   c                 (    | j                  dd      S )N
CategoriesTrK   r'   r   s    r   getCategorieszDesktopEntry.getCategories`   rN   r   c                 (    | j                  dd      S )NStartupNotifyr>   r-   r'   r   s    r   getStartupNotifyzDesktopEntry.getStartupNotifyb   s    xxix88r   c                 $    | j                  d      S )NStartupWMClassr'   r   s    r   getStartupWMClasszDesktopEntry.getStartupWMClassd   s    xx())r   c                 $    | j                  d      S )NURLr'   r   s    r   getURLzDesktopEntry.getURLf       xxr   c                 (    | j                  dd      S )NServiceTypesTrK   r'   r   s    r   getServiceTypeszDesktopEntry.getServiceTypesk   s    xxTx22r   c                 $    | j                  d      S )NDocPathr'   r   s    r   
getDocPathzDesktopEntry.getDocPathm   r2   r   c                 *    | j                  ddd      S )NKeywordsT)rL   r6   r'   r   s    r   getKeywordszDesktopEntry.getKeywordso   s    xx
dx;;r   c                 $    | j                  d      S )NInitialPreferencer'   r   s    r   getInitialPreferencez!DesktopEntry.getInitialPreferenceq   s    xx+,,r   c                 $    | j                  d      S )NDevr'   r   s    r   getDevzDesktopEntry.getDevs   rq   r   c                 $    | j                  d      S )NFSTyper'   r   s    r   	getFSTypezDesktopEntry.getFSTypeu   s    xx!!r   c                 $    | j                  d      S )N
MountPointr'   r   s    r   getMountPointzDesktopEntry.getMountPointw       xx%%r   c                 (    | j                  dd      S )NReadOnlyr>   r-   r'   r   s    r   getReadonlyzDesktopEntry.getReadonlyy   r^   r   c                 (    | j                  dd      S )NUnmountIconTr5   r'   r   s    r   getUnmountIconzDesktopEntry.getUnmountIcon{   r;   r   c                 (    | j                  dd      S )NMiniIconTr5   r'   r   s    r   getMiniIconzDesktopEntry.getMiniIcon   s    xx
4x00r   c                 $    | j                  d      S )NTerminalOptionsr'   r   s    r   getTerminalOptionszDesktopEntry.getTerminalOptions   s    xx)**r   c                 $    | j                  d      S )N
DefaultAppr'   r   s    r   getDefaultAppzDesktopEntry.getDefaultApp   r   r   c                 (    | j                  dd      S )N	ProtocolsTrK   r'   r   s    r   getProtocolszDesktopEntry.getProtocols   rR   r   c                 (    | j                  dd      S )N
ExtensionsTrK   r'   r   s    r   getExtensionszDesktopEntry.getExtensions   rN   r   c                 $    | j                  d      S )NBinaryPatternr'   r   s    r   getBinaryPatternzDesktopEntry.getBinaryPattern   s    xx((r   c                 $    | j                  d      S )N	MapNotifyr'   r   s    r   getMapNotifyzDesktopEntry.getMapNotify   s    xx$$r   c                 $    | j                  d      S )NEncodingr'   r   s    r   getEncodingzDesktopEntry.getEncoding   s    xx
##r   c                 (    | j                  dd      S )NSwallowTitleTr5   r'   r   s    r   getSwallowTitlezDesktopEntry.getSwallowTitle   s    xxtx44r   c                 $    | j                  d      S )NSwallowExecr'   r   s    r   getSwallowExeczDesktopEntry.getSwallowExec   s    xx&&r   c                 (    | j                  dd      S )N	SortOrderTrK   r'   r   s    r   getSortOrderzDesktopEntry.getSortOrder   rR   r   c                 (    | j                  dd      S )NFilePatternra   r-   r'   r   s    r   getFilePatternzDesktopEntry.getFilePattern   s    xxGx44r   c                 (    | j                  dd      S )NActionsTrK   r'   r   s    r   
getActionszDesktopEntry.getActions   s    xx	x--r   c                 B   t         j                  j                  |      d   dk(  rd}n4t         j                  j                  |      d   dk(  rd}nt        d|      t	               | _        | j                  | j                         | j                  d|       || _	        y)	a$  Make this instance into a new, blank desktop entry.
        
        If filename has a .desktop extension, Type is set to Application. If it
        has a .directory extension, Type is Directory. Other extensions will
        cause :class:`~xdg.Exceptions.ParsingError` to be raised.
           .desktopApplication
.directory	DirectoryzUnknown extensionr&   N)
r   r   splitextr   r   r   addGroupdefaultGroupsetr   )r   r   r.   s      r   r   zDesktopEntry.new   s     77H%a(J6 DWWh'*l:D2H==vd''( r   c                 P   | j                   dk(  r| j                  j                  d       | j                  dk(  r| j                  j                  d       n9| j                  dk7  r*| j                  dk7  r| j                  j                  d       	 | j                  | j                      d   | _        	 | j                  | j                      d
   | _        y # t        $ r | j                  j                  d	       Y Iw xY w# t        $ r | j                  j                  d       Y y w xY w)Nr   z([KDE Desktop Entry]-Header is deprecatedz.kdelnkz$File extension .kdelnk is deprecatedr   r   zUnknown File extensionr&   zKey 'Type' is missingr4   zKey 'Name' is missing)	r   warningsappendfileExtensionr   r.   KeyErrorerrorsnamer   s    r   checkExtraszDesktopEntry.checkExtras   s     33MM  !KL *MM  !GH:-$2D2D2TMM  !9:	8T%6%67?DI
	8T%6%67?DI  	8KK67	8  	8KK67	8s$   !C 2!C> $C;:C;>$D%$D%c                 L   || j                   k(  sVt        j                  d|      s@t        j                  d|      rt        |      s| j                  j                  d|z         y d| j                  |   v r.d| j                  |   v r| j                  j                  d       y y y )Nz^Desktop Action [a-zA-Z0-9-]+$z^X-zInvalid Group name: %srJ   rP   z;Group may either have OnlyShowIn or NotShowIn, but not both)r   rematchr   r   r   r   )r   groups     r   
checkGroupzDesktopEntry.checkGroup   s    ***884e<HHUE"xKK7%?@ U 33+V[I\:\""#`a ;]3r   c                 V   |dk(  rC|dk(  s
|dk(  s|dk(  r| j                   j                  d|z         nN|dk(  r| j                   j                  d       n-|dk(  s(|d	k(  s#|d
k(  s| j                  j                  d|z         | j                  dk(  r$|d
k(  s| j                   j                  d|z         n/| j                  dk(  r |d
k(  r| j                   j                  d       |dk(  r,d| j                  |   vr| j                   j                  d       |d	k(  r.d| j                  |   vr| j                   j                  d       y y y |dk(  r| j                  ||       y t        j                  dt        j                  j                  z   dz   |      ry t        j                  dt        j                  j                  z   dz   |      ry |dk(  r| j                  ||d       y t        j                  dt        j                  j                  z   dz   |      ry t        j                  dt        j                  j                  z   dz   |      r| j                  ||       y |dk(  r| j                  ||d       y |dk(  r&| j                  ||d        | j                  |       y |d!k(  r&| j                  ||d        | j                  |       y |d"k(  r%| j                  ||       | j                  |d       y |dk(  r%| j                  ||       | j                  |d       y |d#k(  r%| j                  ||       | j                  |d       y |d$k(  r'| j                  ||d       | j                  |d       y |d%k(  r'| j                  ||d        | j                  |d       y |dk(  r'| j                  ||d        | j                  |d       y |d&k(  r6| j                  ||       | j                  |d       | j                  |       y t        j                  d't        j                  j                  z   dz   |      r(| j                  ||d(d)       | j                  |d       y |d*k(  r'| j                  ||d       | j                  |d       y |d+k(  r| j                  |d       y |dk(  r%| j                  ||       | j                  |d       y |d,k(  r3| j                  ||d        | j                   j                  d-|z         y |d.k(  r1| j                  ||       | j                   j                  d-|z         y |d/k(  r3| j                  ||d0       | j                   j                  d-|z         y |d1k(  rC| j                  ||       | j                  |d       | j                   j                  d-|z         y |d2k(  rC| j                  ||       | j                  |d       | j                   j                  d-|z         y |d3k(  rC| j                  ||       | j                  |d       | j                   j                  d-|z         y |d4k(  rE| j                  ||d       | j                  |d       | j                   j                  d-|z         y t        j                  d5t        j                  j                  z   dz   |      rC| j                  ||       | j                  |d       | j                   j                  d-|z         y |d6k(  r1| j                  ||       | j                   j                  d7|z         y t        j                  d8t        j                  j                  z   dz   |      r1| j                  ||       | j                   j                  d7|z         y |d9k(  r1| j                  ||       | j                   j                  d7|z         y |d:k(  r1| j                  ||       | j                   j                  d7|z         y |d;k(  r3| j                  ||d        | j                   j                  d7|z         y |d<k(  r3| j                  ||d        | j                   j                  d7|z         y |d=k(  r1| j                  ||       | j                   j                  d7|z         y |d>k(  r1| j                  ||       | j                   j                  d7|z         y t        j                  d?t        j                  j                  z   dz   |      r| j                   j                  d7|z         y |d@k(  r1| j                  ||       | j                   j                  d7|z         y |dAk(  r4| j                  ||dBd)       | j                   j                  d7|z         y |dCk(  r3| j                  ||d        | j                   j                  d7|z         y t        j                  dD|      ry | j                  j                  dE|z         y )FNr&   ServiceTypeServiceFSDevicezType=%s is a KDE extensionr`   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 .directoryrV   z!Type=Application needs 'Exec' keyro   zType=Link needs 'URL' keyr+   z^Name$z^GenericNamer=   r>   r-   z^Commentz^IconrG   rJ   TrK   rP   r    rY   r\   r   rf   z	^Keywordslocalestring)r.   rL   ri   rl   rs   zKey '%s' is a KDE extensionrv   r|   r,   r   r   r   r   z^UnmountIconr   zKey '%s' is deprecatedz	^MiniIconr   r   r   r   r   r   z^SwallowTitler   r   ra   r   z^X-[a-zA-Z0-9-]+zInvalid key: %s)r   r   r   r   r   
checkValuer   r   xdgLocalera   checkOnlyShowIn	checkTypecheckCategories)r   keyvaluer   s       r   checkKeyzDesktopEntry.checkKey   s   &=%));u
?R$$%AC%GH*$$$%BC},5KCW""#lot#tu!!\1%;:N$$%UX]%]^##z1e{6J$$%ef%e!44MM(()LMU 33MM(()DE 4  IOOC'XXgcjj...s2C8XXnSZZ%5%55c93?KOOCYO7XXj!1!11#5s;XXgcjj...s2C8OOC'H_OOCYO7L OOCTO2  'KOOCTO2  'IOOC'NN3.F]OOC'NN3.F]OOC'NN3.JOOCYO7NN3.IOOCTO2NN3.JOOCTO2NN3.L OOC'NN3.  'XXk#**"2"2236<OOC^$OGNN3.O#OOCYO7NN3.$$NN3.E\OOC'NN3& N"OOCTO2MM  !>!DEIOOC'MM  !>!DE''OOCYO7MM  !>!DEE\OOC'NN3
+MM  !>!DEH_OOC'NN3
+MM  !>!DEL OOC'NN3
+MM  !>!DEJOOCYO7NN3
+MM  !>!DEXXnSZZ%5%55c93?OOC'NN3
+MM  !>!DE JOOC'MM  !9C!?@XXk#**"2"2236<OOC'MM  !9C!?@%%OOC'MM  !9C!?@L OOC'MM  !9C!?@KOOCTO2MM  !9C!?@L OOCTO2MM  !9C!?@O#OOC'MM  !9C!?@KOOC'MM  !9C!?@XXocjj&6&66s:C@MM  !9C!?@M!OOC'MM  !9C!?@M!OOCW4O@MM  !9C!?@KOOCTO2MM  !9C!?@ XX(#. KK0367r   c                 n    | j                         |k(  s"| j                  j                  d|d|       y y )NzKey 'z' only allowed in Type=)r(   r   r   )r   r   r.   s      r   r   zDesktopEntry.checkType  s,    ||~%KKS$OP &r   c                     | j                  |      }g d}|D ].  }||vs|dd dk7  s| j                  j                  d|z         0 y )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items        r   r   zDesktopEntry.checkOnlyShowIn  sO    e$ D5 T!AY$%6""#NQU#UV r   c                    | j                  |      }g dt        fd|D              s| j                  j                  d       g d}|z   }|D ]7  }||vs|j	                  d      r| j                  j                  d|z         9 y )N)
AudioVideoAudioVideoDevelopment	EducationGameGraphicsNetworkOfficeScienceSettingsSystemUtilityc              3   &   K   | ]  }|v  
 y wr    ).0r   mains     r   	<genexpr>z/DesktopEntry.checkCategories.<locals>.<genexpr>  s     3FD44<Fs   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   s         @r   r   zDesktopEntry.checkCategories  s    e$ a3F33KK67 c
"T)D=(1F""#F#MN r   c                 X    t        j                  dt               | j                  |      S )z`Deprecated alias for checkCategories - only exists for backwards
        compatibility.
        z1checkCategorie is deprecated, use checkCategories)r   warnDeprecationWarningr   )r   r   s     r   checkCategoriezDesktopEntry.checkCategorie  s(     	I<N	P##E**r   r   )<__name__
__module____qualname____doc__r   r   r   r   r$   r(   r/   r1   r   r:   r?   rB   rE   rH   rM   rQ   rT   rW   rZ   r]   rb   rd   rg   rj   rm   rp   rt   rw   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r      s$   1"L
J 3#-450-210#  4=/19*
3#<-"&44
1+&01)%$5'05.
!*8.	bz8xQXP+r   r   )r  xdg.IniFiler   r   
xdg.Localer   xdg.Exceptionsr   xdg.utilr   os.pathr   r   r   r   r   r   r   <module>r     s/   
 *  '   	 [+7 [+r   