diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-02 00:53:50 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-02 00:53:50 +0100 |
commit | 58958bc249642024724dcbbcd3c14218e5b7982a (patch) | |
tree | 91672a3ed84ccb70cd270a16340dafb827f712ed | |
parent | PEP-8, Python Zen, refactor and reduce code (thx FedeG) (diff) | |
parent | Better solution how to change unicode string to string. (diff) | |
download | pyload-58958bc249642024724dcbbcd3c14218e5b7982a.tar.xz |
Merge branch 'pr/n936_kmarty' into 0.4.10
-rw-r--r-- | pyload/network/HTTPChunk.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/pyload/network/HTTPChunk.py b/pyload/network/HTTPChunk.py index c4e294fc8..a4702e677 100644 --- a/pyload/network/HTTPChunk.py +++ b/pyload/network/HTTPChunk.py @@ -22,6 +22,7 @@ from re import search from pyload.utils import fs_encode import codecs import pycurl +import urllib from HTTPRequest import HTTPRequest @@ -255,9 +256,16 @@ class HTTPChunk(HTTPRequest): if line.startswith("accept-ranges") and "bytes" in line: self.p.chunkSupport = True - if line.startswith("content-disposition") and "filename=" in line: - name = orgline.partition("filename=")[2] - name = name.replace('"', "").replace("'", "").replace(";", "").strip() + if line.startswith("content-disposition") and ("filename=" in line or "filename*=" in line): + if "filename*=" in line: + # extended version according to RFC 6266 and RFC 5987. + encoding = line.partition("*=")[2].partition("''")[0] + name = orgline.partition("''")[2] + name = urllib.unquote(str(name)).decode(charEnc(encoding)) + else: + # basic version, US-ASCII only + name = orgline.partition("filename=")[2] + name = name.replace('"', "").replace("'", "").replace(";", "").replace("/", "_").strip() self.p.nameDisposition = name self.log.debug("Content-Disposition: %s" % name) @@ -290,3 +298,10 @@ class HTTPChunk(HTTPRequest): if self.fp: self.fp.close() self.c.close() if hasattr(self, "p"): del self.p + + +def charEnc(enc): + return { + 'utf-8': 'utf_8', + 'iso-8859-1': 'latin_1', + }.get(enc, 'unknown') |