Helpviewer/HelpUtilities.py

changeset 4318
c2f374ca452b
parent 4021
195a471c327b
child 4326
e52318f11812
--- a/Helpviewer/HelpUtilities.py	Sat Jul 18 15:14:28 2015 +0200
+++ b/Helpviewer/HelpUtilities.py	Sat Jul 18 16:50:24 2015 +0200
@@ -82,3 +82,27 @@
         i += 1
     
     return tmpFileName
+
+
+def parseContentDisposition(reply):
+    """
+    Function to parse a content disposition header.
+    
+    @param reply network reply to be parsed
+    @type QNetworkReply
+    """
+    path = ""
+    # step 1: check the content disposition header for a file name
+    if reply.hasRawHeader("Content-Disposition"):
+        from E5Network.E5RFC6266 import parse_headers
+        contentDisposition = parse_headers(
+            bytes(reply.rawHeader("Content-Disposition")))
+        path = contentDisposition.filename()
+    # step 2: get file name from URL
+    if not path:
+        path = reply.url().path()
+    # step 3: give a generic file name
+    if not path:
+        path = "unnamed_download"
+    
+    return os.path.basename(path)

eric ide

mercurial