From 2a714858d494879856e7e38ee5e5623dae7ca7d4 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Sun, 28 Aug 2016 16:41:32 +0200 Subject: [PATCH 1/3] import ServerProxy from xmlrpc.client on Python 3 --- tw2/devtools/browser.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tw2/devtools/browser.py b/tw2/devtools/browser.py index 11b06cd..a1e4f08 100644 --- a/tw2/devtools/browser.py +++ b/tw2/devtools/browser.py @@ -11,7 +11,12 @@ import pygments import subprocess import sys -import xmlrpclib +try: + # Python 3 + from xmlrpc.client import ServerProxy +except ImportError: + # Python 2 + from xmlrpclib import ServerProxy import warnings from . import memoize @@ -32,7 +37,7 @@ def prepare(self): self.modules = sorted(ep.module_name for ep in pr.iter_entry_points('tw2.widgets') if not ep.module_name.endswith('.samples')) - self.pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi') + self.pypi = ServerProxy('http://pypi.python.org/pypi') @memoize.memoize def _pypi_versions(self, module): From ffc8614931afc1ebe68e05cf4846420ae27bf4eb Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Sun, 28 Aug 2016 16:54:22 +0200 Subject: [PATCH 2/3] drop using webhelpers The webhelpers modules isn't compatible with Python 3 and wasn't maintained since 2013. Use markupsafe.Markup directly rather than the webhelpers.html.literal shim. --- setup.py | 2 +- tw2/devtools/tabs.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 821514e..7c4df55 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ 'tw2.core>=2.1.0a', 'gearbox', 'weberror', - 'webhelpers', + 'markupsafe', 'docutils', "tw2.jquery", "tw2.jqplugins.ui", diff --git a/tw2/devtools/tabs.py b/tw2/devtools/tabs.py index 53eb7f7..5bfbe97 100644 --- a/tw2/devtools/tabs.py +++ b/tw2/devtools/tabs.py @@ -5,7 +5,7 @@ import pygments.lexers import pygments.formatters import warnings -import webhelpers.html +import markupsafe import tw2.core as twc import tw2.core.templating as twt @@ -135,7 +135,6 @@ def _make_tmpl(widget): funcs = [_make_demo, _make_docs, _make_params, _make_source, _make_tmpl] - def make_tabs(widget): _items = [func(widget) for func in funcs] _items = filter(lambda item: item, _items) @@ -147,4 +146,8 @@ class Tabs(tw2.jqplugins.ui.TabsWidget): id = widget.compound_id.replace(':', '-') + "-tabs" items = _items - return webhelpers.html.literal(Tabs.display()) + tabs = Tabs.display() + if tabs is not None: + return markupsafe.Markup(tabs) + else: + return markupsafe.Markup(u"") From c36437c30ed6b1615dc39cdfbdf52984bda7f974 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Sun, 28 Aug 2016 17:07:39 +0200 Subject: [PATCH 3/3] use byte literals for replacing in byte strings Requires Python >= 2.6. --- tw2/devtools/tabs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tw2/devtools/tabs.py b/tw2/devtools/tabs.py index 5bfbe97..4bcc162 100644 --- a/tw2/devtools/tabs.py +++ b/tw2/devtools/tabs.py @@ -76,7 +76,7 @@ def rst2html(rst): 'template': os.path.dirname(__file__) + '/rststub.txt' } ) - html = html.replace('
', '').replace('
', '') + html = html.replace(b'
', b'').replace(b'
', b'') return gsi.HTML(html.decode('utf-8'))