0
  8   -ˆl—ß=¿J	Å4Ÿº‚ œPÜi›�¼¦-ÿ‘äÇò 8àDøce°´I?ŸÕƒh¹Ò¿Ï      -0
     /ˆÃ�þ_Œ«6Y^u¶ÚxaxÏÕƒOµÒÂ¿Ï 	¾    /"""
Exception Classes for the xdg package
"""

debug = False

class Error(Exception):
    """Base class for exceptions defined here."""
    def __init__(self, msg):
        self.msg = msg
        Exception.__init__(self, msg)
    def __str__(self):
        return self.msg

class ValidationError(Error):
    """Raised when a file fails to validate.
    
    The filename is the .file attribute.
    """
    def __init__(self, msg, file):
        self.msg = msg
        self.file = file
        Error.__init__(self, "ValidationError in file '%s': %s " % (file, msg))

class ParsingError(Error):
    """Raised when a file cannot be parsed.
    
    The filename is the .file attribute.
    """
    def __init__(self, msg, file):
        self.msg = msg
        self.file = file
        Error.__init__(self, "ParsingError in file '%s', %s" % (file, msg))

class NoKeyError(Error):
    """Raised when trying to access a nonexistant key in an INI-style file.
    
    Attributes are .key, .group and .file.
    """
    def __init__(self, key, group, file):
        Error.__init__(self, "No key '%s' in group %s of file %s" % (key, group, file))
        self.key = key
        self.group = group
        self.file = file

class DuplicateKeyError(Error):
    """Raised when the same key occurs twice in an INI-style file.
    
    Attributes are .key, .group and .file.
    """
    def __init__(self, key, group, file):
        Error.__init__(self, "Duplicate key '%s' in group %s of file %s" % (key, group, file))
        self.key = key
        self.group = group
        self.file = file

class NoGroupError(Error):
    """Raised when trying to access a nonexistant group in an INI-style file.
    
    Attributes are .group and .file.
    """
    def __init__(self, group, file):
        Error.__init__(self, "No group: %s in file %s" % (group, file))
        self.group = group
        self.file = file

class DuplicateGroupError(Error):
    """Raised when the same key occurs twice in an INI-style file.
    
    Attributes are .group and .file.
    """
    def __init__(self, group, file):
        Error.__init__(self, "Duplicate group: %s in file %s" % (group, file))
        self.group = group
        self.file = file

class NoThemeError(Error):
    """Raised when trying to access a nonexistant icon theme.
    
    The name of the theme is the .theme attribute.
    """
    def __init__(self, theme):
        Error.__init__(self, "No such icon-theme: %s" % theme)
        self.theme = theme
  !   1ˆÃ�þZ|²,ÙeyÖÛiá…à?Õ„Ï‰¿ÒÂ¿Ï ?÷     1""" CLass to edit XDG Menus """
import os
try:
    import xml.etree.cElementTree as etree
except ImportError:
    import xml.etree.ElementTree as etree

from xdg.Menu import Menu, MenuEntry, Layout, Separator, XMLMenuBuilder
from xdg.BaseDirectory import xdg_config_dirs, xdg_data_dirs
from xdg.Exceptions import ParsingError 
from xdg.Config import setRootMode

# XML-Cleanups: Move / Exclude
# FIXME: proper reverte/delete
# FIXME: pass AppDirs/DirectoryDirs around in the edit/move functions
# FIXME: catch Exceptions
# FIXME: copy functions
# FIXME: More Layout stuff
# FIXME: unod/redo function / remove menu...
# FIXME: Advanced MenuEditing Stuff: LegacyDir/MergeFile
#        Complex Rules/Deleted/OnlyAllocated/AppDirs/DirectoryDirs


class MenuEditor(object):

    def __init__(self, menu=None, filename=None, root=False):
        self.menu = None
        self.filename = None
        self.tree = None
        self.parser = XMLMenuBuilder()
        self.parse(menu, filename, root)

        # fix for creating two menus with the same name on the fly
        self.filenames = []

    def parse(self, menu=None, filename=None, root=False):
        if root:
            setRootMode(True)

        if isinstance(menu, Menu):
            self.menu = menu
        elif menu:
            self.menu = self.parser.parse(menu)
        else:
            self.menu = self.parser.parse()

        if root:
            self.filen