Skip to content

Commit

Permalink
drop Python 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Jun 9, 2017
1 parent c00878f commit 2d49407
Show file tree
Hide file tree
Showing 69 changed files with 138 additions and 293 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Splash - A javascript rendering service
:target: https://gitter.im/scrapinghub/splash

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

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

Expand Down
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ allowed_content_types : string : optional
Comma-separated list of allowed content types.
If present, Splash will abort any request if the response's content type
doesn't match any of the content types in this list.
Wildcards are supported using the `fnmatch <https://docs.python.org/2/library/fnmatch.html>`_
Wildcards are supported using the `fnmatch <https://docs.python.org/3/library/fnmatch.html>`_
syntax.

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

.. _arg-viewport:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Splash - A javascript rendering service
=======================================

Splash is a javascript rendering service. It's a lightweight web browser
with an HTTP API, implemented in Python using Twisted and QT. The (twisted)
with an HTTP API, implemented in Python 3 using Twisted and QT5. The (twisted)
QT reactor is used to make the service fully asynchronous allowing
to take advantage of webkit concurrency via QT main loop. Some of Splash
features:
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# install PyQt5 (Splash is tested on PyQT 5.5.1)
# install PyQt5 (Splash is tested on PyQT 5.8)
# and the following packages:
twisted >= 15.5.0, < 16.3.0
qt5reactor
Expand All @@ -7,7 +7,6 @@ adblockparser >= 0.5
https://github.com/sunu/pyre2/archive/c610be52c3b5379b257d56fc0669d022fd70082a.zip#egg=re2
xvfbwrapper
Pillow
six

# for scripting support
lupa >= 1.3
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def get_version():
],
'classifiers': [
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Expand Down
17 changes: 0 additions & 17 deletions splash/argument_cache.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import json
import hashlib
from collections import OrderedDict


# Add move_to_end method for python 2.7
# See https://github.com/twitter/commons/blob/master/src/python/twitter/common/collections/ordereddict.py#L284
if not hasattr(OrderedDict, 'move_to_end'):
def move_to_end(self, key, last=True):
link_prev, link_next, key = link = self._OrderedDict__map[key]
link_prev[1] = link_next
link_next[0] = link_prev
root = self._OrderedDict__root
if last:
last = root[0]
link[0] = last
link[1] = root
last[1] = root[0] = link
OrderedDict.move_to_end = move_to_end


class ArgumentCache(object):
"""
>>> cache = ArgumentCache()
Expand Down
20 changes: 9 additions & 11 deletions splash/browser_tab.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import base64
import functools
import os
Expand All @@ -13,7 +12,6 @@
from PyQt5.QtWidgets import QApplication
from twisted.internet import defer
from twisted.python import log
import six

from splash import defaults
from splash.har.qt import cookies2har
Expand Down Expand Up @@ -359,7 +357,7 @@ def add_cookie(self, cookie):
@property
def url(self):
""" Current URL """
return six.text_type(self.web_page.mainFrame().url().toString())
return str(self.web_page.mainFrame().url().toString())

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

def _on_url_changed(self, url):
self.web_page.har.store_redirect(six.text_type(url.toString()))
self.web_page.har.store_redirect(str(url.toString()))
self._cancel_timers(self._timers_to_cancel_on_redirect)

def _process_js_result(self, obj, allow_dom):
Expand Down Expand Up @@ -942,20 +940,20 @@ def last_http_status(self):
def _frame_to_dict(self, frame, children=True, html=True):
g = frame.geometry()
res = {
"url": six.text_type(frame.url().toString()),
"requestedUrl": six.text_type(frame.requestedUrl().toString()),
"url": str(frame.url().toString()),
"requestedUrl": str(frame.requestedUrl().toString()),
"geometry": (g.x(), g.y(), g.width(), g.height()),
"title": six.text_type(frame.title())
"title": str(frame.title())
}
if html:
res["html"] = six.text_type(frame.toHtml())
res["html"] = str(frame.toHtml())

if children:
res["childFrames"] = [
self._frame_to_dict(f, True, html)
for f in frame.childFrames()
]
res["frameName"] = six.text_type(frame.frameName())
res["frameName"] = str(frame.frameName())

return res

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

@pyqtSlot(str)
def log(self, message):
self.messages.append(six.text_type(message))
self.messages.append(str(message))


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

if isinstance(message, six.text_type):
if isinstance(message, str):
message = message.encode('unicode-escape').decode('ascii')

message = "[%s] %s" % (self.uid, message)
Expand Down
1 change: 0 additions & 1 deletion splash/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from splash import lua

collect_ignore = []
Expand Down
1 change: 0 additions & 1 deletion splash/cookies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from PyQt5.QtCore import QDateTime, Qt
from PyQt5.QtNetwork import QNetworkRequest, QNetworkCookie, QNetworkCookieJar

Expand Down
3 changes: 0 additions & 3 deletions splash/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import


class BadOption(Exception):
""" Incorrect HTTP API arguments """
pass
Expand Down
2 changes: 0 additions & 2 deletions splash/har/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from .utils import get_duration, format_datetime
10 changes: 4 additions & 6 deletions splash/har/log.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from collections import namedtuple
from datetime import datetime

import splash
from PyQt5.QtCore import PYQT_VERSION_STR, QT_VERSION_STR
from PyQt5.QtWebKit import qWebKitVersion
import six

from .utils import get_duration, format_datetime, cleaned_har_entry

Expand Down Expand Up @@ -48,11 +46,11 @@ def has_entry(self, req_id):

def store_url(self, url):
""" Call this method when URL is changed. """
self.events.append(HarEvent(HAR_URL_CHANGED, six.text_type(url)))
self.events.append(HarEvent(HAR_URL_CHANGED, str(url)))

def store_title(self, title):
""" Call this method when page title is changed. """
self.events.append(HarEvent(HAR_TITLE_CHANGED, six.text_type(title)))
self.events.append(HarEvent(HAR_TITLE_CHANGED, str(title)))

def store_timing(self, name):
"""
Expand Down Expand Up @@ -86,12 +84,12 @@ def todict(self):
def _get_browser(self):
return {
"name": "QWebKit",
"version": six.text_type(qWebKitVersion()),
"version": str(qWebKitVersion()),
"comment": "PyQt %s, Qt %s" % (PYQT_VERSION_STR, QT_VERSION_STR),
}

def _empty_page(self, page_id, started_dt):
if not isinstance(started_dt, six.string_types):
if not isinstance(started_dt, str):
started_dt = format_datetime(started_dt)

return {
Expand Down
18 changes: 8 additions & 10 deletions splash/har/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
Module with helper utilities to serialize QWebkit objects to HAR.
See http://www.softwareishard.com/blog/har-12-spec/.
"""
from __future__ import absolute_import
import base64

from PyQt5.QtCore import Qt, QVariant, QUrlQuery
from PyQt5.QtNetwork import QNetworkRequest
import six

from splash.qtutils import (
REQUEST_ERRORS_SHORT,
Expand Down Expand Up @@ -62,9 +60,9 @@ def cookie2har(cookie):
cookie = {
"name": qt_to_bytes(cookie.name()).decode('utf8', 'replace'),
"value": qt_to_bytes(cookie.value()).decode('utf8', 'replace'),
"path": six.text_type(cookie.path()),
"domain": six.text_type(cookie.domain()),
"expires": six.text_type(cookie.expirationDate().toString(Qt.ISODate)),
"path": str(cookie.path()),
"domain": str(cookie.domain()),
"expires": str(cookie.expirationDate().toString(Qt.ISODate)),
"httpOnly": cookie.isHttpOnly(),
"secure": cookie.isSecure(),
}
Expand All @@ -75,7 +73,7 @@ def cookie2har(cookie):

def querystring2har(url):
return [
{"name": six.text_type(name), "value": six.text_type(value)}
{"name": str(name), "value": str(value)}
for name, value in QUrlQuery(url).queryItems()
]

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

content_type = reply.header(QNetworkRequest.ContentTypeHeader)
if content_type is not None:
res["content"]["mimeType"] = six.text_type(content_type)
res["content"]["mimeType"] = str(content_type)

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

status_text = reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute)
if status_text is not None:
if not isinstance(status_text, six.text_type):
if not isinstance(status_text, str):
status_text = qt_to_bytes(status_text).decode('latin1')
res['statusText'] = status_text
else:
res["statusText"] = REQUEST_ERRORS_SHORT.get(reply.error(), "?")

redirect_url = reply.attribute(QNetworkRequest.RedirectionTargetAttribute)
if redirect_url is not None:
res["redirectURL"] = six.text_type(redirect_url.toString())
res["redirectURL"] = str(redirect_url.toString())
else:
res["redirectURL"] = ""

Expand All @@ -144,7 +142,7 @@ def request2har(request, operation, outgoing_data=None):
""" Serialize QNetworkRequest to HAR. """
return {
"method": OPERATION_NAMES.get(operation, '?'),
"url": six.text_type(request.url().toString()),
"url": str(request.url().toString()),
"httpVersion": "HTTP/1.1",
"cookies": request_cookies2har(request),
"queryString": querystring2har(request.url()),
Expand Down
3 changes: 0 additions & 3 deletions splash/har/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"""
Module for validating HAR data. Uses official HAR JSON Schema.
"""
from __future__ import absolute_import


def validate(instance):
""" Validate HAR data; raise an exception if it is invalid """
validator = get_validator()
Expand Down
1 change: 0 additions & 1 deletion splash/har/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import base64
from operator import itemgetter
import itertools
Expand Down
1 change: 0 additions & 1 deletion splash/har_builder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import copy
from datetime import datetime

Expand Down
1 change: 0 additions & 1 deletion splash/html_element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from functools import wraps

from splash.exceptions import DOMError
Expand Down
1 change: 0 additions & 1 deletion splash/kernel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
1 change: 0 additions & 1 deletion splash/kernel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
$ python -m splash.kernel
"""
from __future__ import absolute_import
import sys
from .kernel import start, install

Expand Down
1 change: 0 additions & 1 deletion splash/kernel/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
Autocompleter for Lua code.
"""
from __future__ import absolute_import
import string

from splash.utils import dedupe, to_unicode
Expand Down
1 change: 0 additions & 1 deletion splash/kernel/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import lupa

from splash.exceptions import ScriptError
Expand Down
1 change: 0 additions & 1 deletion splash/kernel/inspections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
Inspections for Lua code.
"""
from __future__ import absolute_import
import os
import glob
import json
Expand Down
6 changes: 2 additions & 4 deletions splash/kernel/kernel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import six
import sys

import lupa
Expand Down Expand Up @@ -30,7 +28,7 @@

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

Expand Down Expand Up @@ -168,7 +166,7 @@ def done(result):
reply, result, ct = result
if result:
data = {
'text/plain': result if isinstance(result, six.text_type) else str(result),
'text/plain': result if isinstance(result, str) else str(result),
}
if isinstance(result, BinaryCapsule):
if result.content_type in {'image/png', 'image/jpeg'}:
Expand Down
1 change: 0 additions & 1 deletion splash/kernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Refactored from IPython.kernel.zmq.kernelbase.Kernel with async execution
support. See https://github.com/ipython/ipython/pull/7713.
"""
from __future__ import absolute_import
import functools
import time
import sys
Expand Down
Loading

0 comments on commit 2d49407

Please sign in to comment.