80 tmpFileName = tmpFileName[:index] + appendString + \ |
80 tmpFileName = tmpFileName[:index] + appendString + \ |
81 tmpFileName[index:] |
81 tmpFileName[index:] |
82 i += 1 |
82 i += 1 |
83 |
83 |
84 return tmpFileName |
84 return tmpFileName |
|
85 |
|
86 |
|
87 def parseContentDisposition(reply): |
|
88 """ |
|
89 Function to parse a content disposition header. |
|
90 |
|
91 @param reply network reply to be parsed |
|
92 @type QNetworkReply |
|
93 """ |
|
94 path = "" |
|
95 # step 1: check the content disposition header for a file name |
|
96 if reply.hasRawHeader("Content-Disposition"): |
|
97 from E5Network.E5RFC6266 import parse_headers |
|
98 contentDisposition = parse_headers( |
|
99 bytes(reply.rawHeader("Content-Disposition"))) |
|
100 path = contentDisposition.filename() |
|
101 # step 2: get file name from URL |
|
102 if not path: |
|
103 path = reply.url().path() |
|
104 # step 3: give a generic file name |
|
105 if not path: |
|
106 path = "unnamed_download" |
|
107 |
|
108 return os.path.basename(path) |