Skip to content

Commit 630e76f

Browse files
committed
Merge branch 'legacy/0.9'
Conflicts: CHANGES.rst isso/ext/notifications.py isso/utils/http.py setup.py
2 parents 9451704 + beca18a commit 630e76f

File tree

8 files changed

+74
-18
lines changed

8 files changed

+74
-18
lines changed

CHANGES.rst

+16-5
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,29 @@ Changelog for Isso
2424
Intra emphasis would compile `foo_bar_baz` to foo<em>bar</em>baz. This
2525
behavior is very confusing for users not knowing the Markdown spec in detail.
2626

27+
- new Bulgarian translation by sahwar, new Swedish translation by <Gustav
28+
Näslund, #143
29+
30+
.. __: https://www.python.org/dev/peps/pep-0466/
31+
32+
33+
0.9.9 (2015-03-04)
34+
------------------
35+
36+
- several Python 3.x related bugfixes
37+
2738
- don't lose comment form if the server rejected the POST request, #144
2839

2940
- add localStorage fallback if QUOTA_EXCEEDED_ERR is thrown (e.g. Safari
3041
private browsing)
3142

32-
- new Bulgarian translation by sahwar, new Swedish translation by <Gustav
33-
Näslund, #143
34-
35-
- add --emptyid flag to import strange Disqus exports, #135
43+
- add '--empty-id' flag to Disqus import, because Disqus' export sucks
3644

37-
.. __: https://www.python.org/dev/peps/pep-0466/
45+
- (re)gain compatibility with Werkzeug 0.8 and really old html5lib versions
46+
available in Debian Squeeze, #170 & #168
3847

48+
- add User-Agent when Isso requests the URL, an alternate way to #151 (add
49+
'X-Isso' when requesting).
3950

4051
0.9.8 (2014-10-08)
4152
------------------

isso/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
from argparse import ArgumentParser
4949
from functools import partial, reduce
5050

51+
import pkg_resources
52+
werkzeug = pkg_resources.get_distribution("werkzeug")
53+
5154
from itsdangerous import URLSafeTimedSerializer
5255

5356
from werkzeug.routing import Map
@@ -191,7 +194,10 @@ class App(Isso, uWSGIMixin):
191194
allowed=("Origin", "Referer", "Content-Type"),
192195
exposed=("X-Set-Cookie", "Date")))
193196

194-
wrapper.extend([wsgi.SubURI, ProxyFix])
197+
wrapper.extend([wsgi.SubURI, ProxyFix, wsgi.LegacyWerkzeugMiddleware])
198+
199+
if werkzeug.version.startswith("0.8"):
200+
wrapper.append(wsgi.LegacyWerkzeugMiddleware)
195201

196202
return reduce(lambda x, f: f(x), wrapper, isso)
197203

isso/ext/notifications.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ def __enter__(self):
7070
else:
7171
self.client.starttls()
7272

73-
if self.conf.get('username') and self.conf.get('password'):
74-
self.client.login(self.conf.get('username').encode('ascii', errors='ignore'),
75-
self.conf.get('password').encode('ascii', errors='ignore'))
73+
username = self.conf.get('username')
74+
password = self.conf.get('password')
75+
if username is not None and password is not None:
76+
if PY2K:
77+
username = username.encode('ascii')
78+
password = password.encode('ascii')
79+
80+
self.client.login(username, password)
7681

7782
return self.client
7883

isso/js/app/i18n/ru.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
define({
2-
"postbox-text": "Комментировать здесь (миниум 3 символа)",
2+
"postbox-text": "Комментировать здесь (минимум 3 символа)",
33
"postbox-author": "Имя (необязательно)",
44
"postbox-email": "Email (необязательно)",
55
"postbox-submit": "Отправить",

isso/tests/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_github_flavoured_markdown(self):
6363
print("Hello, World")
6464
</code></pre>""")
6565

66-
@unittest.skipIf(html.html5lib_version == "0.95", "backport")
66+
@unittest.skipIf(html.HTML5LIB_VERSION <= html.HTML5LIB_SIMPLETREE, "backport")
6767
def test_sanitizer(self):
6868
sanitizer = html.Sanitizer(elements=[], attributes=[])
6969
examples = [
@@ -76,7 +76,7 @@ def test_sanitizer(self):
7676
for (input, expected) in examples:
7777
self.assertEqual(html.sanitize(sanitizer, input), expected)
7878

79-
@unittest.skipIf(html.html5lib_version == "0.95", "backport")
79+
@unittest.skipIf(html.HTML5LIB_VERSION <= html.HTML5LIB_SIMPLETREE, "backport")
8080
def test_sanitizer_extensions(self):
8181
sanitizer = html.Sanitizer(elements=["img"], attributes=["src"])
8282
examples = [

isso/utils/html.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
from __future__ import unicode_literals
44

5-
import pkg_resources
65
import operator
6+
import pkg_resources
7+
8+
from distutils.version import LooseVersion as Version
9+
10+
HTML5LIB_VERSION = Version(pkg_resources.get_distribution("html5lib").version)
11+
HTML5LIB_SIMPLETREE = Version("0.95")
712

813
from isso.compat import reduce
914

1015
import html5lib
11-
html5lib_version = pkg_resources.get_distribution("html5lib").version
12-
1316
from html5lib.sanitizer import HTMLSanitizer
1417
from html5lib.serializer import HTMLSerializer
1518

@@ -45,7 +48,11 @@ def sanitize(tokenizer, document):
4548
parser = html5lib.HTMLParser(tokenizer=tokenizer)
4649
domtree = parser.parseFragment(document)
4750

48-
builder = "simpletree" if html5lib_version == "0.95" else "etree"
51+
if HTML5LIB_VERSION > HTML5LIB_SIMPLETREE:
52+
builder = "etree"
53+
else:
54+
builder = "simpletree"
55+
4956
stream = html5lib.treewalkers.getTreeWalker(builder)(domtree)
5057
serializer = HTMLSerializer(quote_attr_values=True, omit_optional_tags=False)
5158

isso/utils/http.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
except ImportError:
88
import http.client as httplib
99

10+
from isso import dist
1011
from isso.wsgi import urlsplit
1112

1213

@@ -21,6 +22,10 @@ class curl(object):
2122
return resp.status
2223
"""
2324

25+
headers = {
26+
"User-Agent": "Isso/{0} (+http://posativ.org/isso)".format(dist.version)
27+
}
28+
2429
def __init__(self, method, host, path, timeout=3):
2530
self.method = method
2631
self.host = host
@@ -35,13 +40,13 @@ def __enter__(self):
3540
self.con = http(host, port, timeout=self.timeout)
3641

3742
try:
38-
self.con.request(self.method, self.path)
43+
self.con.request(self.method, self.path, headers=self.headers)
3944
except (httplib.HTTPException, socket.error):
4045
return None
4146

4247
try:
4348
return self.con.getresponse()
44-
except (socket.timeout, socket.error):
49+
except (httplib.HTTPException, socket.timeout, socket.error):
4550
return None
4651

4752
def __exit__(self, exc_type, exc_value, traceback):

isso/wsgi.py

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import unicode_literals
44

5+
import sys
56
import socket
67

78
try:
@@ -149,6 +150,27 @@ def add_cors_headers(status, headers, exc_info=None):
149150
return self.app(environ, add_cors_headers)
150151

151152

153+
class LegacyWerkzeugMiddleware(object):
154+
# Add compatibility with werkzeug 0.8
155+
# -- https://github.com/posativ/isso/pull/170
156+
157+
def __init__(self, app):
158+
self.app = app
159+
160+
def __call__(self, environ, start_response):
161+
162+
def to_native(x, charset=sys.getdefaultencoding(), errors='strict'):
163+
if x is None or isinstance(x, str):
164+
return x
165+
return x.decode(charset, errors)
166+
167+
def fix_headers(status, headers, exc_info=None):
168+
headers = [(to_native(key), value) for key, value in headers]
169+
return start_response(status, headers, exc_info)
170+
171+
return self.app(environ, fix_headers)
172+
173+
152174
class Request(_Request):
153175

154176
# Assuming UTF-8, comments with 65536 characters would consume

0 commit comments

Comments
 (0)