3
3
Module with helper utilities to serialize QWebkit objects to HAR.
4
4
See http://www.softwareishard.com/blog/har-12-spec/.
5
5
"""
6
- from __future__ import absolute_import
7
6
import base64
8
7
9
8
from PyQt5 .QtCore import Qt , QVariant , QUrlQuery
10
9
from PyQt5 .QtNetwork import QNetworkRequest
11
- import six
12
10
13
11
from splash .qtutils import (
14
12
REQUEST_ERRORS_SHORT ,
@@ -62,9 +60,9 @@ def cookie2har(cookie):
62
60
cookie = {
63
61
"name" : qt_to_bytes (cookie .name ()).decode ('utf8' , 'replace' ),
64
62
"value" : qt_to_bytes (cookie .value ()).decode ('utf8' , 'replace' ),
65
- "path" : six . text_type (cookie .path ()),
66
- "domain" : six . text_type (cookie .domain ()),
67
- "expires" : six . text_type (cookie .expirationDate ().toString (Qt .ISODate )),
63
+ "path" : str (cookie .path ()),
64
+ "domain" : str (cookie .domain ()),
65
+ "expires" : str (cookie .expirationDate ().toString (Qt .ISODate )),
68
66
"httpOnly" : cookie .isHttpOnly (),
69
67
"secure" : cookie .isSecure (),
70
68
}
@@ -75,7 +73,7 @@ def cookie2har(cookie):
75
73
76
74
def querystring2har (url ):
77
75
return [
78
- {"name" : six . text_type (name ), "value" : six . text_type (value )}
76
+ {"name" : str (name ), "value" : str (value )}
79
77
for name , value in QUrlQuery (url ).queryItems ()
80
78
]
81
79
@@ -105,7 +103,7 @@ def reply2har(reply, content=None):
105
103
106
104
content_type = reply .header (QNetworkRequest .ContentTypeHeader )
107
105
if content_type is not None :
108
- res ["content" ]["mimeType" ] = six . text_type (content_type )
106
+ res ["content" ]["mimeType" ] = str (content_type )
109
107
110
108
content_length = reply .header (QNetworkRequest .ContentLengthHeader )
111
109
if content_length is not None :
@@ -120,15 +118,15 @@ def reply2har(reply, content=None):
120
118
121
119
status_text = reply .attribute (QNetworkRequest .HttpReasonPhraseAttribute )
122
120
if status_text is not None :
123
- if not isinstance (status_text , six . text_type ):
121
+ if not isinstance (status_text , str ):
124
122
status_text = qt_to_bytes (status_text ).decode ('latin1' )
125
123
res ['statusText' ] = status_text
126
124
else :
127
125
res ["statusText" ] = REQUEST_ERRORS_SHORT .get (reply .error (), "?" )
128
126
129
127
redirect_url = reply .attribute (QNetworkRequest .RedirectionTargetAttribute )
130
128
if redirect_url is not None :
131
- res ["redirectURL" ] = six . text_type (redirect_url .toString ())
129
+ res ["redirectURL" ] = str (redirect_url .toString ())
132
130
else :
133
131
res ["redirectURL" ] = ""
134
132
@@ -144,7 +142,7 @@ def request2har(request, operation, outgoing_data=None):
144
142
""" Serialize QNetworkRequest to HAR. """
145
143
return {
146
144
"method" : OPERATION_NAMES .get (operation , '?' ),
147
- "url" : six . text_type (request .url ().toString ()),
145
+ "url" : str (request .url ().toString ()),
148
146
"httpVersion" : "HTTP/1.1" ,
149
147
"cookies" : request_cookies2har (request ),
150
148
"queryString" : querystring2har (request .url ()),
0 commit comments