From c3c519ad0ee4a436fbf2ef2469cbaadeae72b947 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Tue, 24 Feb 2015 21:12:21 +0100 Subject: [PATCH 01/10] add compatibility middleware for werkzeug 0.8, #170 --- isso/__init__.py | 8 +++++++- isso/wsgi.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/isso/__init__.py b/isso/__init__.py index 0df6af2..baf7aa6 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -48,6 +48,9 @@ from os.path import dirname, join from argparse import ArgumentParser from functools import partial, reduce +import pkg_resources +werkzeug = pkg_resources.get_distribution("werkzeug") + from itsdangerous import URLSafeTimedSerializer from werkzeug.routing import Map @@ -192,7 +195,10 @@ def make_app(conf=None, threading=True, multiprocessing=False, uwsgi=False): allowed=("Origin", "Referer", "Content-Type"), exposed=("X-Set-Cookie", "Date"))) - wrapper.extend([wsgi.SubURI, ProxyFix]) + wrapper.extend([wsgi.SubURI, ProxyFix, wsgi.LegacyWerkzeugMiddleware]) + + if werkzeug.version.startswith("0.8"): + wrapper.append(wsgi.LegacyWerkzeugMiddleware) return reduce(lambda x, f: f(x), wrapper, isso) diff --git a/isso/wsgi.py b/isso/wsgi.py index 50214f3..49f54f6 100644 --- a/isso/wsgi.py +++ b/isso/wsgi.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals +import sys import socket try: @@ -149,6 +150,27 @@ class CORSMiddleware(object): return self.app(environ, add_cors_headers) +class LegacyWerkzeugMiddleware(object): + # Add compatibility with werkzeug 0.8 + # -- https://github.com/posativ/isso/pull/170 + + def __init__(self, app): + self.app = app + + def __call__(self, environ, start_response): + + def to_native(x, charset=sys.getdefaultencoding(), errors='strict'): + if x is None or isinstance(x, str): + return x + return x.decode(charset, errors) + + def fix_headers(status, headers, exc_info=None): + headers = [(to_native(key), value) for key, value in headers] + return start_response(status, headers, exc_info) + + return self.app(environ, fix_headers) + + class Request(_Request): # Assuming UTF-8, comments with 65536 characters would consume From f681002e7ec01b4b529e33dad756d32dc6b736e6 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 25 Feb 2015 10:48:09 +0100 Subject: [PATCH 02/10] add support for html5lib below 0.95, #168 --- isso/tests/test_html.py | 4 ++-- isso/utils/html.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/isso/tests/test_html.py b/isso/tests/test_html.py index 65d6056..a316f15 100644 --- a/isso/tests/test_html.py +++ b/isso/tests/test_html.py @@ -62,7 +62,7 @@ class TestHTML(unittest.TestCase): print("Hello, World") """) - @unittest.skipIf(html.html5lib_version == "0.95", "backport") + @unittest.skipIf(html.HTML5LIB_VERSION <= html.HTML5LIB_SIMPLETREE, "backport") def test_sanitizer(self): sanitizer = html.Sanitizer(elements=[], attributes=[]) examples = [ @@ -75,7 +75,7 @@ class TestHTML(unittest.TestCase): for (input, expected) in examples: self.assertEqual(html.sanitize(sanitizer, input), expected) - @unittest.skipIf(html.html5lib_version == "0.95", "backport") + @unittest.skipIf(html.HTML5LIB_VERSION <= html.HTML5LIB_SIMPLETREE, "backport") def test_sanitizer_extensions(self): sanitizer = html.Sanitizer(elements=["img"], attributes=["src"]) examples = [ diff --git a/isso/utils/html.py b/isso/utils/html.py index 4c8013a..5ee6199 100644 --- a/isso/utils/html.py +++ b/isso/utils/html.py @@ -2,14 +2,17 @@ from __future__ import unicode_literals -import pkg_resources import operator +import pkg_resources + +from distutils.version import LooseVersion as Version + +HTML5LIB_VERSION = Version(pkg_resources.get_distribution("html5lib").version) +HTML5LIB_SIMPLETREE = Version("0.9.5") from isso.compat import reduce import html5lib -html5lib_version = pkg_resources.get_distribution("html5lib").version - from html5lib.sanitizer import HTMLSanitizer from html5lib.serializer import HTMLSerializer @@ -45,7 +48,11 @@ def sanitize(tokenizer, document): parser = html5lib.HTMLParser(tokenizer=tokenizer) domtree = parser.parseFragment(document) - builder = "simpletree" if html5lib_version == "0.95" else "etree" + if HTML5LIB_VERSION > HTML5LIB_SIMPLETREE: + builder = "etree" + else: + builder = "simpletree" + stream = html5lib.treewalkers.getTreeWalker(builder)(domtree) serializer = HTMLSerializer(quote_attr_values=True, omit_optional_tags=False) From 8e4db5a7a21684c231c78839c4a7313849c5a090 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 25 Feb 2015 10:57:55 +0100 Subject: [PATCH 03/10] typo --- isso/utils/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isso/utils/html.py b/isso/utils/html.py index 5ee6199..294b8d4 100644 --- a/isso/utils/html.py +++ b/isso/utils/html.py @@ -8,7 +8,7 @@ import pkg_resources from distutils.version import LooseVersion as Version HTML5LIB_VERSION = Version(pkg_resources.get_distribution("html5lib").version) -HTML5LIB_SIMPLETREE = Version("0.9.5") +HTML5LIB_SIMPLETREE = Version("0.95") from isso.compat import reduce From 45053f9c0ce287d3197a8585074d4f9b59a31d9f Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 4 Mar 2015 21:09:28 +0100 Subject: [PATCH 04/10] catch errors in http response --- isso/utils/http.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/isso/utils/http.py b/isso/utils/http.py index 7a347c6..b9dd5ec 100644 --- a/isso/utils/http.py +++ b/isso/utils/http.py @@ -39,7 +39,10 @@ class curl(object): except (httplib.HTTPException, socket.error): return None - return self.con.getresponse() + try: + return self.con.getresponse() + except httplib.HTTPException: + return None def __exit__(self, exc_type, exc_value, traceback): self.con.close() From 56c81c2d0693a1c994166ebfb2aa14c839671e62 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 1 Mar 2015 16:42:03 +0300 Subject: [PATCH 05/10] Update ru.js --- isso/js/app/i18n/ru.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isso/js/app/i18n/ru.js b/isso/js/app/i18n/ru.js index 7c8c02f..91c46eb 100644 --- a/isso/js/app/i18n/ru.js +++ b/isso/js/app/i18n/ru.js @@ -1,5 +1,5 @@ define({ - "postbox-text": "Комментировать здесь (миниум 3 символа)", + "postbox-text": "Комментировать здесь (минимум 3 символа)", "postbox-author": "Имя (необязательно)", "postbox-email": "Email (необязательно)", "postbox-submit": "Отправить", From 596acb7f79c33ba0c338d62ef9942a6f9cee81f1 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 4 Mar 2015 21:33:01 +0100 Subject: [PATCH 06/10] request with User-Agent 'Isso/...', #151 --- isso/utils/http.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/isso/utils/http.py b/isso/utils/http.py index b9dd5ec..a0b0d0a 100644 --- a/isso/utils/http.py +++ b/isso/utils/http.py @@ -7,6 +7,7 @@ try: except ImportError: import http.client as httplib +from isso import dist from isso.wsgi import urlsplit @@ -21,6 +22,10 @@ class curl(object): return resp.status """ + headers = { + "User-Agent": "Isso/{0} (+http://posativ.org/isso)".format(dist.version) + } + def __init__(self, method, host, path, timeout=3): self.method = method self.host = host @@ -35,7 +40,7 @@ class curl(object): self.con = http(host, port, timeout=self.timeout) try: - self.con.request(self.method, self.path) + self.con.request(self.method, self.path, headers=self.headers) except (httplib.HTTPException, socket.error): return None From f5566c13254bb22c981a3945fb52a5b5aa606a81 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 4 Mar 2015 21:44:39 +0100 Subject: [PATCH 07/10] encode username/password in SMTP auth only for Python 2, fix #146 --- isso/ext/notifications.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/isso/ext/notifications.py b/isso/ext/notifications.py index 46663bc..f027c20 100644 --- a/isso/ext/notifications.py +++ b/isso/ext/notifications.py @@ -63,11 +63,16 @@ class SMTP(object): timeout=self.conf.getint('timeout')) if self.conf.get('security') == 'starttls': - self.client.starttls(); + self.client.starttls() - if self.conf.get('username') and self.conf.get('password'): - self.client.login(self.conf.get('username').encode('ascii', errors='ignore'), - self.conf.get('password').encode('ascii', errors='ignore')) + username = self.conf.get('username') + password = self.conf.get('password') + if username is not None and password is not None: + if PY2K: + username = username.encode('ascii') + password = password.encode('ascii') + + self.client.login(username, password) return self.client From ed38ce13d850f54c12c04432e2c480a4fd461785 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 4 Mar 2015 21:56:22 +0100 Subject: [PATCH 08/10] update changelog --- CHANGES.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 12db988..1ff4f7d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,8 +4,13 @@ Changelog for Isso 0.9.9 (unreleased) ------------------ -- Nothing changed yet. - +- several Python 3.x related bugfixes +- add compatibility with Safari's incognito mode +- add '--empty-id' flag to Disqus import, because Disqus' export sucks +- (re)gain compatibility with Werkzeug 0.8 and really old html5lib versions + available in Debian Squeeze, #170 & #168 +- add User-Agent when Isso requests the URL, an alternate way to #151 (add + 'X-Isso' when requesting). 0.9.8 (2014-10-08) ------------------ From c8655731d6d183a590c04bdf1f97a0afbebee822 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 4 Mar 2015 21:57:40 +0100 Subject: [PATCH 09/10] Preparing release 0.9.9 --- CHANGES.rst | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1ff4f7d..e1d9a3e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ Changelog for Isso ================== -0.9.9 (unreleased) +0.9.9 (2015-03-04) ------------------ - several Python 3.x related bugfixes diff --git a/setup.py b/setup.py index 4d7c9d1..b254fa9 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ else: setup( name='isso', - version='0.9.9.dev0', + version='0.9.9', author='Martin Zimmermann', author_email='info@posativ.org', packages=find_packages(), From beca18a34458536541599a50e01d6952636e8e07 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 4 Mar 2015 21:58:04 +0100 Subject: [PATCH 10/10] Back to development: 0.9.10 --- CHANGES.rst | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e1d9a3e..b8f0219 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Changelog for Isso ================== +0.9.10 (unreleased) +------------------- + +- Nothing changed yet. + + 0.9.9 (2015-03-04) ------------------ diff --git a/setup.py b/setup.py index b254fa9..1b9c118 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ else: setup( name='isso', - version='0.9.9', + version='0.9.10.dev0', author='Martin Zimmermann', author_email='info@posativ.org', packages=find_packages(),