From 49a32f004112fedbe5d8a8ed4b3e2d6bf1e8c33d Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 20 Sep 2015 17:11:28 +0200 Subject: [PATCH] First round of lint fixes --- qutebrowser/browser/commands.py | 3 +-- qutebrowser/browser/downloads.py | 1 + qutebrowser/misc/mhtml.py | 38 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 10f1d0233..641e4aaee 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1159,8 +1159,7 @@ class CommandDispatcher: @cmdutils.register(instance='command-dispatcher', scope='window') def download_whole(self, dest): - """Download the current page as a MHTML file, including all assets - (e.g. images) + """Download the current page as a MHTML file, including all assets. Args: dest: The file path to write the download to. diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 568e7bf67..c446b6c55 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -601,6 +601,7 @@ class DownloadItem(QObject): @pyqtSlot() def on_meta_data_change(self): + """Update the download's metadata.""" if self.reply is None: return self.raw_headers = {} diff --git a/qutebrowser/misc/mhtml.py b/qutebrowser/misc/mhtml.py index 6ac43a8c1..1266fb6a3 100644 --- a/qutebrowser/misc/mhtml.py +++ b/qutebrowser/misc/mhtml.py @@ -20,7 +20,6 @@ """Utils for writing a MHTML file.""" import functools -import quopri import io from collections import namedtuple @@ -29,7 +28,6 @@ from urllib.parse import urljoin from uuid import uuid4 from PyQt5.QtCore import QUrl -from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply from qutebrowser.utils import log, objreg @@ -48,32 +46,32 @@ def _chunked_base64(data, maxlen=76, linesep=b"\r\n"): encoded = b64encode(data) result = [] for i in range(0, len(encoded), maxlen): - result.append(encoded[i:i+maxlen]) + result.append(encoded[i:i + maxlen]) return linesep.join(result) + def _rn_quopri(data): """Return a quoted-printable representation of data.""" # See RFC 2045 https://tools.ietf.org/html/rfc2045#section-6.7 # The stdlib version in the quopri module has inconsistencies with line # endings and breaks up character escapes over multiple lines, which isn't # understood by qute and leads to jumbled text - MAXLEN = 76 - WHITESPACE = {ord(b"\t"), ord(b" ")} + maxlen = 76 + whitespace = {ord(b"\t"), ord(b" ")} output = [] current_line = b"" for byte in data: # Literal representation according to (2) and (3) - if (ord(b"!") <= byte <= ord(b"<") or - ord(b">") <= byte <= ord(b"~") or - byte in WHITESPACE): + if (ord(b"!") <= byte <= ord(b"<") or ord(b">") <= byte <= ord(b"~") + or byte in whitespace): current_line += bytes([byte]) else: current_line += b"=" + "{:02X}".format(byte).encode("ascii") - if len(current_line) >= MAXLEN: + if len(current_line) >= maxlen: # We need to account for the = character - split = [current_line[:MAXLEN-1], current_line[MAXLEN-1:]] + split = [current_line[:maxlen - 1], current_line[maxlen - 1:]] quoted_pos = split[0].rfind(b"=") - if quoted_pos + 2 >= MAXLEN - 1: + if quoted_pos + 2 >= maxlen - 1: split[0], token = split[0][:quoted_pos], split[0][quoted_pos:] split[1] = token + split[1] current_line = split[1] @@ -93,8 +91,8 @@ E_QUOPRI = ("quoted-printable", _rn_quopri) class MHTMLWriter(object): - """A class for aggregating multiple files and outputting them to a MHTML - file.""" + + """A class for outputting multiple files to a MHTML document.""" BOUNDARY = b"---qute-mhtml-" + str(uuid4()).encode("ascii") @@ -102,7 +100,7 @@ class MHTMLWriter(object): content_type=None): self.root_content = root_content self.content_location = content_location - self.content_type = None + self.content_type = content_type self._files = {} @@ -130,7 +128,7 @@ class MHTMLWriter(object): del self._files[location] def write_to(self, fp): - """Output the MHTML file to the given file-like object + """Output the MHTML file to the given file-like object. Args: fp: The file-object, openend in "wb" mode. @@ -144,6 +142,7 @@ class MHTMLWriter(object): fp.write(b"--") def _output_header(self, fp): + """Output only the header to the given fileobject.""" if self.content_location is None: raise ValueError("content_location must be set") if self.content_type is None: @@ -158,6 +157,7 @@ class MHTMLWriter(object): fp.write(b'"\r\n\r\n') def _output_root_file(self, fp): + """Output the root document to the fileobject.""" root_file = _File( content=self.root_content, content_type=self.content_type, content_location=self.content_location, transfer_encoding=E_QUOPRI, @@ -165,6 +165,7 @@ class MHTMLWriter(object): self._output_file(fp, root_file) def _output_file(self, fp, file_struct): + """Output the single given file to the fileobject.""" fp.write(b"--") fp.write(self.BOUNDARY) fp.write(b"\r\nContent-Location: ") @@ -200,8 +201,8 @@ def start_download(dest): # we're using .toHtml, it's probably safe to say that the content-type is # HTML writer.content_type = 'text/html; charset="UTF-8"' - # Currently only downloading (stylesheets),