Skip to content

Commit 2d49407

Browse files
committed
drop Python 2 support
1 parent c00878f commit 2d49407

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+138
-293
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Splash - A javascript rendering service
1515
:target: https://gitter.im/scrapinghub/splash
1616

1717
Splash is a javascript rendering service with an HTTP API. It's a lightweight
18-
browser with an HTTP API, implemented in Python using Twisted and QT.
18+
browser with an HTTP API, implemented in Python 3 using Twisted and QT5.
1919

2020
It's fast, lightweight and state-less which makes it easy to distribute.
2121

docs/api.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ allowed_content_types : string : optional
111111
Comma-separated list of allowed content types.
112112
If present, Splash will abort any request if the response's content type
113113
doesn't match any of the content types in this list.
114-
Wildcards are supported using the `fnmatch <https://docs.python.org/2/library/fnmatch.html>`_
114+
Wildcards are supported using the `fnmatch <https://docs.python.org/3/library/fnmatch.html>`_
115115
syntax.
116116

117117
.. _arg-forbidden-content-types:
@@ -120,7 +120,7 @@ forbidden_content_types : string : optional
120120
Comma-separated list of forbidden content types.
121121
If present, Splash will abort any request if the response's content type
122122
matches any of the content types in this list.
123-
Wildcards are supported using the `fnmatch <https://docs.python.org/2/library/fnmatch.html>`_
123+
Wildcards are supported using the `fnmatch <https://docs.python.org/3/library/fnmatch.html>`_
124124
syntax.
125125

126126
.. _arg-viewport:

docs/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Splash - A javascript rendering service
33
=======================================
44

55
Splash is a javascript rendering service. It's a lightweight web browser
6-
with an HTTP API, implemented in Python using Twisted and QT. The (twisted)
6+
with an HTTP API, implemented in Python 3 using Twisted and QT5. The (twisted)
77
QT reactor is used to make the service fully asynchronous allowing
88
to take advantage of webkit concurrency via QT main loop. Some of Splash
99
features:

requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# install PyQt5 (Splash is tested on PyQT 5.5.1)
1+
# install PyQt5 (Splash is tested on PyQT 5.8)
22
# and the following packages:
33
twisted >= 15.5.0, < 16.3.0
44
qt5reactor
@@ -7,7 +7,6 @@ adblockparser >= 0.5
77
https://github.com/sunu/pyre2/archive/c610be52c3b5379b257d56fc0669d022fd70082a.zip#egg=re2
88
xvfbwrapper
99
Pillow
10-
six
1110

1211
# for scripting support
1312
lupa >= 1.3

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def get_version():
6868
],
6969
'classifiers': [
7070
'Programming Language :: Python',
71-
'Programming Language :: Python :: 2',
72-
'Programming Language :: Python :: 2.7',
7371
'Programming Language :: Python :: 3',
7472
'Programming Language :: Python :: 3.4',
7573
'Programming Language :: Python :: 3.5',

splash/argument_cache.py

-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
import json
43
import hashlib
54
from collections import OrderedDict
65

76

8-
# Add move_to_end method for python 2.7
9-
# See https://github.com/twitter/commons/blob/master/src/python/twitter/common/collections/ordereddict.py#L284
10-
if not hasattr(OrderedDict, 'move_to_end'):
11-
def move_to_end(self, key, last=True):
12-
link_prev, link_next, key = link = self._OrderedDict__map[key]
13-
link_prev[1] = link_next
14-
link_next[0] = link_prev
15-
root = self._OrderedDict__root
16-
if last:
17-
last = root[0]
18-
link[0] = last
19-
link[1] = root
20-
last[1] = root[0] = link
21-
OrderedDict.move_to_end = move_to_end
22-
23-
247
class ArgumentCache(object):
258
"""
269
>>> cache = ArgumentCache()

splash/browser_tab.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
import base64
43
import functools
54
import os
@@ -13,7 +12,6 @@
1312
from PyQt5.QtWidgets import QApplication
1413
from twisted.internet import defer
1514
from twisted.python import log
16-
import six
1715

1816
from splash import defaults
1917
from splash.har.qt import cookies2har
@@ -359,7 +357,7 @@ def add_cookie(self, cookie):
359357
@property
360358
def url(self):
361359
""" Current URL """
362-
return six.text_type(self.web_page.mainFrame().url().toString())
360+
return str(self.web_page.mainFrame().url().toString())
363361

364362
def go(self, url, callback, errback, baseurl=None, http_method='GET',
365363
body=None, headers=None):
@@ -597,7 +595,7 @@ def _cancel_all_timers(self):
597595
callback_proxy.use_up()
598596

599597
def _on_url_changed(self, url):
600-
self.web_page.har.store_redirect(six.text_type(url.toString()))
598+
self.web_page.har.store_redirect(str(url.toString()))
601599
self._cancel_timers(self._timers_to_cancel_on_redirect)
602600

603601
def _process_js_result(self, obj, allow_dom):
@@ -942,20 +940,20 @@ def last_http_status(self):
942940
def _frame_to_dict(self, frame, children=True, html=True):
943941
g = frame.geometry()
944942
res = {
945-
"url": six.text_type(frame.url().toString()),
946-
"requestedUrl": six.text_type(frame.requestedUrl().toString()),
943+
"url": str(frame.url().toString()),
944+
"requestedUrl": str(frame.requestedUrl().toString()),
947945
"geometry": (g.x(), g.y(), g.width(), g.height()),
948-
"title": six.text_type(frame.title())
946+
"title": str(frame.title())
949947
}
950948
if html:
951-
res["html"] = six.text_type(frame.toHtml())
949+
res["html"] = str(frame.toHtml())
952950

953951
if children:
954952
res["childFrames"] = [
955953
self._frame_to_dict(f, True, html)
956954
for f in frame.childFrames()
957955
]
958-
res["frameName"] = six.text_type(frame.frameName())
956+
res["frameName"] = str(frame.frameName())
959957

960958
return res
961959

@@ -1189,7 +1187,7 @@ def __init__(self, parent=None):
11891187

11901188
@pyqtSlot(str)
11911189
def log(self, message):
1192-
self.messages.append(six.text_type(message))
1190+
self.messages.append(str(message))
11931191

11941192

11951193
class _BrowserTabLogger(object):
@@ -1239,7 +1237,7 @@ def log(self, message, min_level=None):
12391237
if min_level is not None and self.verbosity < min_level:
12401238
return
12411239

1242-
if isinstance(message, six.text_type):
1240+
if isinstance(message, str):
12431241
message = message.encode('unicode-escape').decode('ascii')
12441242

12451243
message = "[%s] %s" % (self.uid, message)

splash/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
from splash import lua
43

54
collect_ignore = []

splash/cookies.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
from PyQt5.QtCore import QDateTime, Qt
43
from PyQt5.QtNetwork import QNetworkRequest, QNetworkCookie, QNetworkCookieJar
54

splash/exceptions.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
3-
4-
52
class BadOption(Exception):
63
""" Incorrect HTTP API arguments """
74
pass

splash/har/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
3-
42
from .utils import get_duration, format_datetime

splash/har/log.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
from collections import namedtuple
43
from datetime import datetime
54

65
import splash
76
from PyQt5.QtCore import PYQT_VERSION_STR, QT_VERSION_STR
87
from PyQt5.QtWebKit import qWebKitVersion
9-
import six
108

119
from .utils import get_duration, format_datetime, cleaned_har_entry
1210

@@ -48,11 +46,11 @@ def has_entry(self, req_id):
4846

4947
def store_url(self, url):
5048
""" Call this method when URL is changed. """
51-
self.events.append(HarEvent(HAR_URL_CHANGED, six.text_type(url)))
49+
self.events.append(HarEvent(HAR_URL_CHANGED, str(url)))
5250

5351
def store_title(self, title):
5452
""" Call this method when page title is changed. """
55-
self.events.append(HarEvent(HAR_TITLE_CHANGED, six.text_type(title)))
53+
self.events.append(HarEvent(HAR_TITLE_CHANGED, str(title)))
5654

5755
def store_timing(self, name):
5856
"""
@@ -86,12 +84,12 @@ def todict(self):
8684
def _get_browser(self):
8785
return {
8886
"name": "QWebKit",
89-
"version": six.text_type(qWebKitVersion()),
87+
"version": str(qWebKitVersion()),
9088
"comment": "PyQt %s, Qt %s" % (PYQT_VERSION_STR, QT_VERSION_STR),
9189
}
9290

9391
def _empty_page(self, page_id, started_dt):
94-
if not isinstance(started_dt, six.string_types):
92+
if not isinstance(started_dt, str):
9593
started_dt = format_datetime(started_dt)
9694

9795
return {

splash/har/qt.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
Module with helper utilities to serialize QWebkit objects to HAR.
44
See http://www.softwareishard.com/blog/har-12-spec/.
55
"""
6-
from __future__ import absolute_import
76
import base64
87

98
from PyQt5.QtCore import Qt, QVariant, QUrlQuery
109
from PyQt5.QtNetwork import QNetworkRequest
11-
import six
1210

1311
from splash.qtutils import (
1412
REQUEST_ERRORS_SHORT,
@@ -62,9 +60,9 @@ def cookie2har(cookie):
6260
cookie = {
6361
"name": qt_to_bytes(cookie.name()).decode('utf8', 'replace'),
6462
"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)),
6866
"httpOnly": cookie.isHttpOnly(),
6967
"secure": cookie.isSecure(),
7068
}
@@ -75,7 +73,7 @@ def cookie2har(cookie):
7573

7674
def querystring2har(url):
7775
return [
78-
{"name": six.text_type(name), "value": six.text_type(value)}
76+
{"name": str(name), "value": str(value)}
7977
for name, value in QUrlQuery(url).queryItems()
8078
]
8179

@@ -105,7 +103,7 @@ def reply2har(reply, content=None):
105103

106104
content_type = reply.header(QNetworkRequest.ContentTypeHeader)
107105
if content_type is not None:
108-
res["content"]["mimeType"] = six.text_type(content_type)
106+
res["content"]["mimeType"] = str(content_type)
109107

110108
content_length = reply.header(QNetworkRequest.ContentLengthHeader)
111109
if content_length is not None:
@@ -120,15 +118,15 @@ def reply2har(reply, content=None):
120118

121119
status_text = reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute)
122120
if status_text is not None:
123-
if not isinstance(status_text, six.text_type):
121+
if not isinstance(status_text, str):
124122
status_text = qt_to_bytes(status_text).decode('latin1')
125123
res['statusText'] = status_text
126124
else:
127125
res["statusText"] = REQUEST_ERRORS_SHORT.get(reply.error(), "?")
128126

129127
redirect_url = reply.attribute(QNetworkRequest.RedirectionTargetAttribute)
130128
if redirect_url is not None:
131-
res["redirectURL"] = six.text_type(redirect_url.toString())
129+
res["redirectURL"] = str(redirect_url.toString())
132130
else:
133131
res["redirectURL"] = ""
134132

@@ -144,7 +142,7 @@ def request2har(request, operation, outgoing_data=None):
144142
""" Serialize QNetworkRequest to HAR. """
145143
return {
146144
"method": OPERATION_NAMES.get(operation, '?'),
147-
"url": six.text_type(request.url().toString()),
145+
"url": str(request.url().toString()),
148146
"httpVersion": "HTTP/1.1",
149147
"cookies": request_cookies2har(request),
150148
"queryString": querystring2har(request.url()),

splash/har/schema.py

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"""
33
Module for validating HAR data. Uses official HAR JSON Schema.
44
"""
5-
from __future__ import absolute_import
6-
7-
85
def validate(instance):
96
""" Validate HAR data; raise an exception if it is invalid """
107
validator = get_validator()

splash/har/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
import base64
43
from operator import itemgetter
54
import itertools

splash/har_builder.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
import copy
43
from datetime import datetime
54

splash/html_element.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import
21
from functools import wraps
32

43
from splash.exceptions import DOMError

splash/kernel/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import

splash/kernel/__main__.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
$ python -m splash.kernel
1010
1111
"""
12-
from __future__ import absolute_import
1312
import sys
1413
from .kernel import start, install
1514

splash/kernel/completer.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33
Autocompleter for Lua code.
44
"""
5-
from __future__ import absolute_import
65
import string
76

87
from splash.utils import dedupe, to_unicode

splash/kernel/errors.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
import lupa
43

54
from splash.exceptions import ScriptError

splash/kernel/inspections.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33
Inspections for Lua code.
44
"""
5-
from __future__ import absolute_import
65
import os
76
import glob
87
import json

splash/kernel/kernel.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
32
import os
4-
import six
53
import sys
64

75
import lupa
@@ -30,7 +28,7 @@
3028

3129
def install(user=True):
3230
""" Install IPython kernel specification """
33-
name = 'splash-py2' if six.PY2 else 'splash-py3'
31+
name = 'splash-py3'
3432
folder = os.path.join(os.path.dirname(__file__), 'kernels', name)
3533
install_kernel_spec(folder, kernel_name="splash", user=user, replace=True)
3634

@@ -168,7 +166,7 @@ def done(result):
168166
reply, result, ct = result
169167
if result:
170168
data = {
171-
'text/plain': result if isinstance(result, six.text_type) else str(result),
169+
'text/plain': result if isinstance(result, str) else str(result),
172170
}
173171
if isinstance(result, BinaryCapsule):
174172
if result.content_type in {'image/png', 'image/jpeg'}:

splash/kernel/kernelbase.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Refactored from IPython.kernel.zmq.kernelbase.Kernel with async execution
44
support. See https://github.com/ipython/ipython/pull/7713.
55
"""
6-
from __future__ import absolute_import
76
import functools
87
import time
98
import sys

0 commit comments

Comments
 (0)