Coverage for qutebrowser/misc/lineparser.py : 78%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org> # # This file is part of qutebrowser. # # qutebrowser is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # qutebrowser is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""A LineParser without any real data.
Attributes: _configdir: Directory to read the config from, or None. _configfile: The config file path. _fname: Filename of the config. _binary: Whether to open the file in binary mode.
Signals: changed: Emitted when the history was changed. """
"""Constructor.
Args: configdir: Directory to read the config from. fname: Filename of the config file. binary: Whether to open the file in binary mode. _opened: Whether the underlying file is open """
def __repr__(self): return utils.get_repr(self, constructor=True, configdir=self._configdir, fname=self._fname, binary=self._binary)
"""Prepare saving of the file.
Return: True if the file should be saved, False otherwise. """
"""Log a message after saving is done."""
def _open(self, mode): """Open self._configfile for reading.
Args: mode: The mode to use ('a'/'r'/'w')
Raises: IOError: if the file is already open
Yields: a file object for the config file """ else: finally:
"""Write the data to a file.
Args: fp: A file object to write the data to. data: The data to write. """ else:
"""Save the history to disk.""" raise NotImplementedError
"""Clear the contents of the file.""" raise NotImplementedError
"""Parser for configuration files which are simply line-based.
Attributes: data: A list of lines. """
"""Constructor.
Args: configdir: Directory to read the config from. fname: Filename of the config file. binary: Whether to open the file in binary mode. """ else:
return iter(self.data)
return self.data[key]
"""Read the data from self._configfile.""" else:
"""Save the config file.""" finally:
"""A LineParser with a limited count of lines.
Attributes: _limit: The config option used to limit the maximum number of lines. """
"""Constructor.
Args: configdir: Directory to read the config from, or None. fname: Filename of the config file. limit: Config option which contains a limit. binary: Whether to open the file in binary mode. """
def __repr__(self): return utils.get_repr(self, constructor=True, configdir=self._configdir, fname=self._fname, limit=self._limit, binary=self._binary)
def _cleanup_file(self, option): """Delete the file if the limit was changed to 0.""" assert self._configfile is not None if option != self._limit: return value = config.instance.get(option) if value == 0: if os.path.exists(self._configfile): os.remove(self._configfile)
"""Save the config file.""" limit = config.instance.get(self._limit) if limit == 0: return do_save = self._prepare_save() if not do_save: return assert self._configfile is not None with qtutils.savefile_open(self._configfile, self._binary) as f: self._write(f, self.data[-limit:]) self._after_save() |