eric6/E5Network/E5RFC6266.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8218
7c09585bd960
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a Content-Disposition parser iaw. RFC 6266.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 #
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 # This code is adapted from the rfc6266.py module of qutebrowser.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 # Original copyright 2014-2015 Florian Bruhin (The Compiler)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 # <mail@qutebrowser.org>
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 #
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
16 import urllib.parse as parse
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import collections
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import string
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import re
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 try:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 import pypeg2 as peg
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class UniqueNamespace(peg.Namespace):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 A pyPEG2 namespace which prevents setting a value twice.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 def __setitem__(self, key, value):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Special method to set an item.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param key key for the item
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param value value of the item
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 if key in self:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 raise DuplicateParamError(key)
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
37 super(UniqueNamespace, self).__setitem__(key, value)
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 # RFC 2616
5616
adcffadf4962 Reworked some __IGNORE_WARNING__ comments to be more specific.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
40 separator_chars = "()<>@,;:\\\"/[]?={} \t" # __IGNORE_WARNING_M613__
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 ctl_chars = ''.join(chr(i) for i in range(32)) + chr(127)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 nontoken_chars = separator_chars + ctl_chars
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 # RFC 5987
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 attr_chars_nonalnum = '!#$&+-.^_`|~'
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 attr_chars = string.ascii_letters + string.digits + attr_chars_nonalnum
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 # RFC 5987 gives this alternative construction of the token character class
5616
adcffadf4962 Reworked some __IGNORE_WARNING__ comments to be more specific.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
49 token_chars = attr_chars + "*'%" # __IGNORE_WARNING_M601__
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 # Definitions from https://tools.ietf.org/html/rfc2616#section-2.2
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 # token was redefined from attr_chars to avoid using AnyBut,
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 # which might include non-ascii octets.
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4318
diff changeset
54 token_re = '[{0}]+'.format(re.escape(token_chars))
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 class Token(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 A token (RFC 2616, Section 2.2).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 grammar = re.compile(token_re)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 # RFC 2616 says some linear whitespace (LWS) is in fact allowed in text
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 # and qdtext; however it also mentions folding that whitespace into
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 # a single SP (which isn't in CTL) before interpretation.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 # Assume the caller already that folding when parsing headers.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 # Note: qdtext also allows non-ascii, which we choose to parse
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 # as ISO-8859-1; rejecting it entirely would also be permitted.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 # Some broken browsers attempt encoding-sniffing, which is broken
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 # because the spec only allows iso, and because encoding-sniffing
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 # can mangle valid values.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 # Everything else in this grammar (including RFC 5987 ext values)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 # is in an ascii-safe encoding.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4318
diff changeset
75 qdtext_re = r'[^"{0}]'.format(re.escape(ctl_chars))
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4318
diff changeset
76 quoted_pair_re = r'\\[{0}]'.format(re.escape(
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 ''.join(chr(i) for i in range(128))))
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 class QuotedString(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 A quoted string (RFC 2616, Section 2.2).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4318
diff changeset
83 grammar = re.compile(r'"({0}|{1})+"'.format(quoted_pair_re, qdtext_re))
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 def __str__(self):
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
86 s = super(QuotedString, self).__str__()
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 s = s[1:-1] # remove quotes
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 s = re.sub(r'\\(.)', r'\1', s) # drop backslashes
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 return s
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 class Value(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 A value. (RFC 2616, Section 3.6).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 grammar = [re.compile(token_re), QuotedString]
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 class Charset(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 A charset (RFC5987, Section 3.2.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 # Other charsets are forbidden, the spec reserves them
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 # for future evolutions.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 grammar = re.compile('UTF-8|ISO-8859-1', re.I)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 class Language(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 A language-tag (RFC 5646, Section 2.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Fixme: This grammar is not 100% correct yet.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 https://github.com/The-Compiler/qutebrowser/issues/105
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 grammar = re.compile('[A-Za-z0-9-]+')
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4318
diff changeset
114 attr_char_re = '[{0}]'.format(re.escape(attr_chars))
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 hex_digit_re = '%[' + string.hexdigits + ']{2}'
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 class ValueChars(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 A value of an attribute.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 Fixme: Can we merge this with Value?
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 https://github.com/The-Compiler/qutebrowser/issues/105
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
4543
2e6a880670e9 Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4318
diff changeset
124 grammar = re.compile('({0}|{1})*'.format(attr_char_re, hex_digit_re))
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 class ExtValue(peg.List):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 An ext-value of an attribute (RFC 5987, Section 3.2).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 grammar = peg.contiguous(Charset, "'", peg.optional(Language), "'",
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 ValueChars)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 class ExtToken(peg.Symbol):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 A token introducing an extended value (RFC 6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 regex = re.compile(token_re + r'\*')
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 def __str__(self):
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
140 return super(ExtToken, self).__str__().lower()
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 class NoExtToken(peg.Symbol):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 A token introducing a normal value (RFC 6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 regex = re.compile(token_re + r'(?<!\*)')
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 def __str__(self):
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
149 return super(NoExtToken, self).__str__().lower()
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 class DispositionParm(str):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 A parameter for the Disposition-Type header (RFC6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 grammar = peg.attr('name', NoExtToken), '=', Value
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 class ExtDispositionParm:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 An extended parameter (RFC6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 grammar = peg.attr('name', ExtToken), '=', ExtValue
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 def __init__(self, value, name=None):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.name = name
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.value = value
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 class DispositionType(peg.List):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 The disposition type (RFC6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 grammar = [re.compile('(inline|attachment)', re.I), Token]
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 class DispositionParmList(UniqueNamespace):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 A list of disposition parameters (RFC6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 grammar = peg.maybe_some(';', [ExtDispositionParm, DispositionParm])
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 class ContentDispositionValue:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 A complete Content-Disposition value (RFC 6266, Section 4.1).
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 # Allows nonconformant final semicolon
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 # I've seen it in the wild, and browsers accept it
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 # http://greenbytes.de/tech/tc2231/#attwithasciifilenamenqs
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 grammar = (peg.attr('dtype', DispositionType),
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 peg.attr('params', DispositionParmList),
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 peg.optional(';'))
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 LangTagged = collections.namedtuple('LangTagged', ['string', 'langtag'])
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 class DuplicateParamError(Exception):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 Exception raised when a parameter has been given twice.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 class InvalidISO8859Error(Exception):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 Exception raised when a byte is invalid in ISO-8859-1.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 class ContentDisposition:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 Records various indications and hints about content disposition.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 These can be used to know if a file should be downloaded or
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 displayed directly, and to hint what filename it should have
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 in the download case.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 def __init__(self, disposition='inline', assocs=None):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 Used internally after parsing the header.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 Instances should generally be created from a factory
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 function, such as parse_headers and its variants.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 if len(disposition) != 1:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 self.disposition = 'inline'
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 else:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 self.disposition = disposition[0]
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 if assocs is None:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 self.assocs = {}
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 else:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 self.assocs = dict(assocs) # So we can change values
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 if 'filename*' in self.assocs:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 param = self.assocs['filename*']
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
227 if isinstance(param, ExtDispositionParm):
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
228 self.assocs['filename*'] = (
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
229 parse_ext_value(param.value).string
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
230 )
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 def filename(self):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 The filename from the Content-Disposition header or None.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 On safety:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 This property records the intent of the sender.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 You shouldn't use this sender-controlled value as a filesystem
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 path, it can be insecure. Serving files with this filename can be
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 dangerous as well, due to a certain browser using the part after
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 the dot for mime-sniffing. Saving it to a database is fine by
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 itself though.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 if 'filename*' in self.assocs:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 return self.assocs['filename*']
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 elif 'filename' in self.assocs:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 # XXX Reject non-ascii (parsed via qdtext) here?
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 return self.assocs['filename']
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
250 else:
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
251 return None
4318
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 def is_inline(self):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 Return if the file should be handled inline.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 If not, and unless your application supports other dispositions
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 than the standard inline and attachment, it should be handled
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 as an attachment.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 return self.disposition.lower() == 'inline'
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 def normalize_ws(text):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 Do LWS (linear whitespace) folding.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 return ' '.join(text.split())
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 def parse_headers(content_disposition):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 Build a ContentDisposition from header values.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 @param content_disposition contents of the disposition header
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 @type bytes
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 # We allow non-ascii here (it will only be parsed inside of qdtext, and
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 # rejected by the grammar if it appears in other places), although
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 # parsing it can be ambiguous. Parsing it ensures that a non-ambiguous
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 # filename* value won't get dismissed because of an unrelated ambiguity
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 # in the filename parameter. But it does mean we occasionally give
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 # less-than-certain values for some legacy senders.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 content_disposition = content_disposition.decode('iso-8859-1')
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 # Our parsing is relaxed in these regards:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 # - The grammar allows a final ';' in the header;
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 # - We do LWS-folding, and possibly normalise other broken
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 # whitespace, instead of rejecting non-lws-safe text.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 # XXX Would prefer to accept only the quoted whitespace
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 # case, rather than normalising everything.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 content_disposition = normalize_ws(content_disposition)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 try:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 parsed = peg.parse(content_disposition, ContentDispositionValue)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 except (SyntaxError, DuplicateParamError, InvalidISO8859Error):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 return ContentDisposition()
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 else:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 return ContentDisposition(disposition=parsed.dtype,
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 assocs=parsed.params)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 def parse_ext_value(val):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 Parse the value of an extended attribute.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 if len(val) == 3:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 charset, langtag, coded = val
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 else:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 charset, coded = val
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 langtag = None
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 decoded = parse.unquote(coded, charset, errors='strict')
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 if charset == 'iso-8859-1':
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 # Fail if the filename contains an invalid ISO-8859-1 char
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 for c in decoded:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 if 0x7F <= ord(c) <= 0x9F:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 raise InvalidISO8859Error(c)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 return LangTagged(decoded, langtag)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 except ImportError:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 class ContentDisposition:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 Records various indications and hints about content disposition.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 These can be used to know if a file should be downloaded or
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 displayed directly, and to hint what filename it should have
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 in the download case.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 def __init__(self, filename):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 Constructor
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @param filename file name to be stored in this surrogate class
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 @type str
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 self.__filename = filename
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 def filename(self):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 Public method to get the stored file name
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 @return file name
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 @rtype str
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 return self.__filename
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 def parse_headers(content_disposition):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 Build a ContentDisposition from header values.
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 @param content_disposition contents of the disposition header
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 @type bytes
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 header = content_disposition.decode()
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 if header:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 pos = header.find("filename=")
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 if pos != -1:
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 path = header[pos + 9:]
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 if path.startswith('"') and path.endswith('"'):
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 path = path[1:-1]
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 return ContentDisposition(path)
c2f374ca452b Improved parsing of the content disposition header analog to the way it is done in qutebrowser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 return ContentDisposition("")

eric ide

mercurial