Esempio n. 1
0
    def test_init(self, tmpdir):
        """Test if creating a line parser correctly reads its file."""
        (tmpdir / 'file').write('one\ntwo\n')
        lineparser = lineparsermod.LineParser(str(tmpdir), 'file')
        assert lineparser.data == ['one', 'two']

        (tmpdir / 'file').write_binary(b'\xfe\n\xff\n')
        lineparser = lineparsermod.LineParser(str(tmpdir), 'file', binary=True)
        assert lineparser.data == [b'\xfe', b'\xff']
Esempio n. 2
0
 def _init_lineparser(self):
     bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks')
     if not os.path.isdir(bookmarks_directory):
         os.makedirs(bookmarks_directory)
     self._lineparser = lineparser.LineParser(standarddir.config(),
                                              'bookmarks/urls',
                                              parent=self)
Esempio n. 3
0
    def _init_lineparser(self):
        bookmarks_directory = os.path.join(standarddir.config(), 'bookmarks')
        os.makedirs(bookmarks_directory, exist_ok=True)

        bookmarks_subdir = os.path.join('bookmarks', 'urls')
        self._lineparser = lineparser.LineParser(
            standarddir.config(), bookmarks_subdir, parent=self)
Esempio n. 4
0
    def _init_lineparser(self):
        bookmarks_directory = self._bookmarks_directory
        if not os.path.isdir(bookmarks_directory):
            os.makedirs(bookmarks_directory)

        self._lineparser = lineparser.LineParser(
            bookmarks_directory, "urls", parent=self)
Esempio n. 5
0
    def __init__(self, parent=None):
        """Initialize and read quickmarks."""
        super().__init__(parent)

        self.marks = collections.OrderedDict()

        if standarddir.config() is None:
            self._lineparser = None
        else:
            self._lineparser = lineparser.LineParser(standarddir.config(),
                                                     'quickmarks',
                                                     parent=self)
            for line in self._lineparser:
                if not line.strip():
                    # Ignore empty or whitespace-only lines.
                    continue
                try:
                    key, url = line.rsplit(maxsplit=1)
                except ValueError:
                    message.error(0, "Invalid quickmark '{}'".format(line))
                else:
                    self.marks[key] = url
            filename = os.path.join(standarddir.config(), 'quickmarks')
            objreg.get('save-manager').add_saveable('quickmark-manager',
                                                    self.save,
                                                    self.changed,
                                                    filename=filename)
Esempio n. 6
0
    def __init__(self, parent=None, *, line_parser=None):
        super().__init__(parent)

        if line_parser:
            self._lineparser = line_parser
        else:
            self._lineparser = lineparser.LineParser(
                standarddir.data(), 'cookies', binary=True, parent=self)
        self.parse_cookies()
        config.instance.changed.connect(self._on_cookies_store_changed)
        objreg.get('save-manager').add_saveable(
            'cookies', self.save, self.changed,
            config_opt='content.cookies.store')
Esempio n. 7
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._lineparser = lineparser.LineParser(standarddir.data(),
                                              'cookies',
                                              binary=True,
                                              parent=self)
     cookies = []
     for line in self._lineparser:
         cookies += QNetworkCookie.parseCookies(line)
     self.setAllCookies(cookies)
     objreg.get('config').changed.connect(self.cookies_store_changed)
     objreg.get('save-manager').add_saveable('cookies',
                                             self.save,
                                             self.changed,
                                             config_opt=('content',
                                                         'cookies-store'))
Esempio n. 8
0
 def _init_lineparser(self):
     self._lineparser = lineparser.LineParser(standarddir.config(),
                                              'quickmarks',
                                              parent=self)
Esempio n. 9
0
 def lineparser(self, tmpdir):
     """Fixture to get a LineParser for tests."""
     lp = lineparsermod.LineParser(str(tmpdir), 'file')
     lp.save()
     return lp