Coverage for qutebrowser/browser/webkit/rfc6266.py : 100%

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 pyPEG2 namespace which prevents setting a value twice."""
# RFC 2616
# RFC 5987
# RFC 5987 gives this alternative construction of the token character class
# Definitions from https://tools.ietf.org/html/rfc2616#section-2.2 # token was redefined from attr_chars to avoid using AnyBut, # which might include non-ascii octets.
"""A token (RFC 2616, Section 2.2)."""
# RFC 2616 says some linear whitespace (LWS) is in fact allowed in text # and qdtext; however it also mentions folding that whitespace into # a single SP (which isn't in CTL) before interpretation. # Assume the caller already that folding when parsing headers.
# NOTE: qdtext also allows non-ascii, which we choose to parse # as ISO-8859-1; rejecting it entirely would also be permitted. # Some broken browsers attempt encoding-sniffing, which is broken # because the spec only allows iso, and because encoding-sniffing # can mangle valid values. # Everything else in this grammar (including RFC 5987 ext values) # is in an ascii-safe encoding.
''.join(chr(i) for i in range(128))))
"""A quoted string (RFC 2616, Section 2.2)."""
"""A value. (RFC 2616, Section 3.6)."""
"""A charset (RFC5987, Section 3.2.1)."""
# Other charsets are forbidden, the spec reserves them # for future evolutions.
"""A language-tag (RFC 5646, Section 2.1).
FIXME: This grammar is not 100% correct yet. https://github.com/qutebrowser/qutebrowser/issues/105 """
"""A value of an attribute.
FIXME: Can we merge this with Value? https://github.com/qutebrowser/qutebrowser/issues/105 """
"""An ext-value of an attribute (RFC 5987, Section 3.2)."""
ValueChars)
"""A token introducing an extended value (RFC 6266, Section 4.1)."""
"""A token introducing a normal value (RFC 6266, Section 4.1)."""
"""A parameter for the Disposition-Type header (RFC6266, Section 4.1)."""
"""An extended parameter (RFC6266, Section 4.1)."""
"""The disposition type (RFC6266, Section 4.1)."""
"""A list of disposition parameters (RFC6266, Section 4.1)."""
"""A complete Content-Disposition value (RFC 6266, Section 4.1)."""
# Allows nonconformant final semicolon # I've seen it in the wild, and browsers accept it # http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqs peg.attr('params', DispositionParmList), peg.optional(';'))
class LangTagged:
"""A string with an associated language."""
"""Base class for RFC6266 errors."""
"""Exception raised when a parameter has been given twice."""
"""Exception raised when a byte is invalid in ISO-8859-1."""
"""Records various indications and hints about content disposition.
These can be used to know if a file should be downloaded or displayed directly, and to hint what filename it should have in the download case. """
"""Used internally after parsing the header."""
"""The filename from the Content-Disposition header or None.
On safety:
This property records the intent of the sender.
You shouldn't use this sender-controlled value as a filesystem path, it can be insecure. Serving files with this filename can be dangerous as well, due to a certain browser using the part after the dot for mime-sniffing. Saving it to a database is fine by itself though. """ # XXX Reject non-ascii (parsed via qdtext) here?
"""Return if the file should be handled inline.
If not, and unless your application supports other dispositions than the standard inline and attachment, it should be handled as an attachment. """
def __repr__(self): return utils.get_repr(self, constructor=True, disposition=self.disposition, assocs=self.assocs)
"""Do LWS (linear whitespace) folding."""
"""Build a _ContentDisposition from header values.""" # We allow non-ascii here (it will only be parsed inside of qdtext, and # rejected by the grammar if it appears in other places), although parsing # it can be ambiguous. Parsing it ensures that a non-ambiguous filename* # value won't get dismissed because of an unrelated ambiguity in the # filename parameter. But it does mean we occasionally give # less-than-certain values for some legacy senders. # Our parsing is relaxed in these regards: # - The grammar allows a final ';' in the header; # - We do LWS-folding, and possibly normalise other broken # whitespace, instead of rejecting non-lws-safe text. # XXX Would prefer to accept only the quoted whitespace # case, rather than normalising everything.
"""Parse the value of an extended attribute.""" else: # Fail if the filename contains an invalid ISO-8859-1 char |