def test_modify(self):
        i = IniFile.IniFile()
        i.addGroup('foo')
        i.set('bar', u('wallöby'), group='foo')
        self.assertEqual(i.get('bar', group='foo'), u('wallöby'))

        self.assertEqual(list(i.groups()), ['foo'])

        i.removeKey('bar', group='foo')
        i.removeGroup('foo')
Beispiel #2
0
 def test_modify(self):
     i = IniFile.IniFile()
     i.addGroup('foo')
     i.set('bar', u('wallöby'), group='foo')
     self.assertEqual(i.get('bar', group='foo'), u('wallöby'))
     
     self.assertEqual(list(i.groups()), ['foo'])
     
     i.removeKey('bar', group='foo')
     i.removeGroup('foo')
Beispiel #3
0
    def write(self, filename=None, trusted=False):
        if not filename and not self.filename:
            raise ParsingError("File not found", "")

        if filename:
            self.filename = filename
        else:
            filename = self.filename

        if os.path.dirname(filename) and not os.path.isdir(
                os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        with io.open(filename, 'w', encoding='utf-8') as fp:

            # An executable bit signifies that the desktop file is
            # trusted, but then the file can be executed. Add hashbang to
            # make sure that the file is opened by something that
            # understands desktop files.
            if trusted:
                fp.write(u("#!/usr/bin/env xdg-open\n"))

            if self.defaultGroup:
                fp.write(u("[%s]\n") % self.defaultGroup)
                for (key, value) in self.content[self.defaultGroup].items():
                    fp.write(u("%s=%s\n") % (key, value))
                fp.write(u("\n"))
            for (name, group) in self.content.items():
                if name != self.defaultGroup:
                    fp.write(u("[%s]\n") % name)
                    for (key, value) in group.items():
                        fp.write(u("%s=%s\n") % (key, value))
                    fp.write(u("\n"))

        # Add executable bits to the file to show that it's trusted.
        if trusted:
            oldmode = os.stat(filename).st_mode
            mode = oldmode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
            os.chmod(filename, mode)

        self.tainted = False
Beispiel #4
0
    def write(self, filename=None, trusted=False):
        if not filename and not self.filename:
            raise ParsingError("File not found", "")

        if filename:
            self.filename = filename
        else:
            filename = self.filename

        if os.path.dirname(filename) and not os.path.isdir(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        with io.open(filename, 'w', encoding='utf-8') as fp:

            # An executable bit signifies that the desktop file is
            # trusted, but then the file can be executed. Add hashbang to
            # make sure that the file is opened by something that
            # understands desktop files.
            if trusted:
                fp.write(u("#!/usr/bin/env xdg-open\n"))

            if self.defaultGroup:
                fp.write(u("[%s]\n") % self.defaultGroup)
                for (key, value) in self.content[self.defaultGroup].items():
                    fp.write(u("%s=%s\n") % (key, value))
                fp.write(u("\n"))
            for (name, group) in self.content.items():
                if name != self.defaultGroup:
                    fp.write(u("[%s]\n") % name)
                    for (key, value) in group.items():
                        fp.write(u("%s=%s\n") % (key, value))
                    fp.write(u("\n"))

        # Add executable bits to the file to show that it's trusted.
        if trusted:
            oldmode = os.stat(filename).st_mode
            mode = oldmode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
            os.chmod(filename, mode)

        self.tainted = False
Beispiel #5
0
 def test_unicode_name(self):
     with io.open(self.test_file, "w", encoding='utf-8') as f:
         f.write(resources.unicode_desktop)
     
     entry = DesktopEntry(self.test_file)
     self.assertEqual(entry.getName(), u('Abc€þ'))
Beispiel #6
0
    def test_unicode_name(self):
        with io.open(self.test_file, "w", encoding='utf-8') as f:
            f.write(resources.unicode_desktop)

        entry = DesktopEntry(self.test_file)
        self.assertEqual(entry.getName(), u('Abc€þ'))
 def test_check_string(self):
     i = IniFile.IniFile()
     self.assertEqual(i.checkString(u('abc')), 0)
     self.assertEqual(i.checkString('abc'), 0)
     self.assertEqual(i.checkString(u('abcö')), 1)
     self.assertEqual(i.checkString('abcö'), 1)
Beispiel #8
0
 def test_check_string(self):
     i = IniFile.IniFile()
     self.assertEqual(i.checkString(u('abc')), 0)
     self.assertEqual(i.checkString('abc'), 0)
     self.assertEqual(i.checkString(u('abcö')), 1)
     self.assertEqual(i.checkString('abcö'), 1)