diff --git a/qutebrowser/browser/cookies.py b/qutebrowser/browser/cookies.py index f88ab79a2..f6af98d57 100644 --- a/qutebrowser/browser/cookies.py +++ b/qutebrowser/browser/cookies.py @@ -23,8 +23,8 @@ from PyQt5.QtNetwork import QNetworkCookie, QNetworkCookieJar from PyQt5.QtCore import pyqtSignal, QDateTime from qutebrowser.config import config -from qutebrowser.config.parsers import line as lineparser from qutebrowser.utils import utils, standarddir, objreg +from qutebrowser.misc import lineparser class RAMCookieJar(QNetworkCookieJar): @@ -65,15 +65,15 @@ class CookieJar(RAMCookieJar): """A cookie jar saving cookies to disk. Attributes: - _linecp: The LineConfigParser managing the cookies file. + _lineparser: The LineParser managing the cookies file. """ def __init__(self, parent=None): super().__init__(parent) - self._linecp = lineparser.LineConfigParser( + self._lineparser = lineparser.LineParser( standarddir.data(), 'cookies', binary=True, parent=self) cookies = [] - for line in self._linecp: + for line in self._lineparser: cookies += QNetworkCookie.parseCookies(line) self.setAllCookies(cookies) objreg.get('config').changed.connect(self.cookies_store_changed) @@ -97,13 +97,13 @@ class CookieJar(RAMCookieJar): for cookie in self.allCookies(): if not cookie.isSessionCookie(): lines.append(cookie.toRawForm()) - self._linecp.data = lines - self._linecp.save() + self._lineparser.data = lines + self._lineparser.save() @config.change_filter('content', 'cookies-store') def cookies_store_changed(self): """Delete stored cookies if cookies-store changed.""" if not config.get('content', 'cookies-store'): - self._linecp.data = [] - self._linecp.save() + self._lineparser.data = [] + self._lineparser.save() self.changed.emit() diff --git a/qutebrowser/browser/history.py b/qutebrowser/browser/history.py index 1f7a8dbd2..3f6a75e50 100644 --- a/qutebrowser/browser/history.py +++ b/qutebrowser/browser/history.py @@ -27,7 +27,7 @@ from PyQt5.QtWebKit import QWebHistoryInterface from qutebrowser.utils import utils, objreg, standarddir from qutebrowser.config import config -from qutebrowser.config.parsers import line as lineparser +from qutebrowser.misc import lineparser class HistoryEntry: @@ -64,9 +64,10 @@ class WebHistory(QWebHistoryInterface): def __init__(self, parent=None): super().__init__(parent) - self._linecp = lineparser.LineConfigParser( + self._lineparser = lineparser.LineParser( standarddir.data(), 'history', parent=self) - self._history = [HistoryEntry.from_str(e) for e in self._linecp.data] + self._history = [HistoryEntry.from_str(e) + for e in self._lineparser.data] objreg.get('save-manager').add_saveable('history', self.save, self.changed) @@ -78,8 +79,8 @@ class WebHistory(QWebHistoryInterface): def save(self): """Save the history to disk.""" - self._linecp.data = (str(e) for e in self._history) - self._linecp.save() + self._lineparser.data = (str(e) for e in self._history) + self._lineparser.save() def addHistoryEntry(self, url_string): """Called by WebKit when an URL should be added to the history. diff --git a/qutebrowser/browser/quickmarks.py b/qutebrowser/browser/quickmarks.py index 17f352df3..ba516c492 100644 --- a/qutebrowser/browser/quickmarks.py +++ b/qutebrowser/browser/quickmarks.py @@ -32,7 +32,7 @@ from PyQt5.QtCore import pyqtSignal, QUrl, QObject from qutebrowser.utils import message, usertypes, urlutils, standarddir, objreg from qutebrowser.commands import cmdexc, cmdutils -from qutebrowser.config.parsers import line as lineparser +from qutebrowser.misc import lineparser class QuickmarkManager(QObject): @@ -41,7 +41,7 @@ class QuickmarkManager(QObject): Attributes: marks: An OrderedDict of all quickmarks. - _linecp: The LineConfigParser used for the quickmarks. + _lineparser: The LineParser used for the quickmarks. """ changed = pyqtSignal() @@ -52,9 +52,9 @@ class QuickmarkManager(QObject): self.marks = collections.OrderedDict() - self._linecp = lineparser.LineConfigParser( + self._lineparser = lineparser.LineParser( standarddir.config(), 'quickmarks', parent=self) - for line in self._linecp: + for line in self._lineparser: try: key, url = line.rsplit(maxsplit=1) except ValueError: @@ -68,8 +68,8 @@ class QuickmarkManager(QObject): def save(self): """Save the quickmarks to disk.""" - self._linecp.data = [' '.join(tpl) for tpl in self.marks.items()] - self._linecp.save() + self._lineparser.data = [' '.join(tpl) for tpl in self.marks.items()] + self._lineparser.save() def prompt_save(self, win_id, url): """Prompt for a new quickmark name to be added and add it. diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index a0157fc76..e9f2d1fe6 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -183,10 +183,10 @@ def _init_misc(): save_manager.add_saveable('state-config', state_config.save) # We need to import this here because lineparser needs config. - from qutebrowser.config.parsers import line - command_history = line.LineConfigParser(standarddir.data(), 'cmd-history', - ('completion', 'history-length'), - parent=objreg.get('config')) + from qutebrowser.misc import lineparser + command_history = lineparser.LineParser( + standarddir.data(), 'cmd-history', ('completion', 'history-length'), + parent=objreg.get('config')) objreg.register('command-history', command_history) save_manager.add_saveable('command-history', command_history.save, command_history.changed) diff --git a/qutebrowser/config/parsers/line.py b/qutebrowser/misc/lineparser.py similarity index 96% rename from qutebrowser/config/parsers/line.py rename to qutebrowser/misc/lineparser.py index db5872028..4e6806824 100644 --- a/qutebrowser/config/parsers/line.py +++ b/qutebrowser/misc/lineparser.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with qutebrowser. If not, see . -"""Parser for line-based configurations like histories.""" +"""Parser for line-based files like histories.""" import os import os.path @@ -28,7 +28,7 @@ from qutebrowser.utils import log, utils, objreg, qtutils from qutebrowser.config import config -class LineConfigParser(QObject): +class LineParser(QObject): """Parser for configuration files which are simply line-based. @@ -66,7 +66,7 @@ class LineConfigParser(QObject): if not os.path.isfile(self._configfile): self.data = [] else: - log.init.debug("Reading config from {}".format(self._configfile)) + log.init.debug("Reading {}".format(self._configfile)) self.read(self._configfile) if limit is not None: objreg.get('config').changed.connect(self.cleanup_file)