Merge lp:~jelmer/loggerhead/python3-compat into lp:loggerhead

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 497
Proposed branch: lp:~jelmer/loggerhead/python3-compat
Merge into: lp:loggerhead
Diff against target: 63 lines (+12/-6)
2 files modified
loggerhead/highlight.py (+5/-2)
loggerhead/tests/test_simple.py (+7/-4)
To merge this branch: bzr merge lp:~jelmer/loggerhead/python3-compat
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+383531@code.launchpad.net

Description of the change

Fix compatibility with python 3.8, where cgi.escape is not available.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/highlight.py'
2--- loggerhead/highlight.py 2017-10-14 14:33:57 +0000
3+++ loggerhead/highlight.py 2020-05-06 19:17:17 +0000
4@@ -17,7 +17,10 @@
5 #
6
7 import breezy.osutils
8-import cgi
9+try:
10+ from html import escape
11+except ImportError:
12+ from cgi import escape
13
14 from pygments import highlight as _highlight_func
15 from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
16@@ -37,7 +40,7 @@
17 """
18
19 if len(text) > MAX_HIGHLIGHT_SIZE:
20- return map(cgi.escape, breezy.osutils.split_lines(text))
21+ return map(escape, breezy.osutils.split_lines(text))
22
23 formatter = HtmlFormatter(style=style, nowrap=True, classprefix='pyg-')
24
25
26=== modified file 'loggerhead/tests/test_simple.py'
27--- loggerhead/tests/test_simple.py 2019-09-18 16:49:18 +0000
28+++ loggerhead/tests/test_simple.py 2020-05-06 19:17:17 +0000
29@@ -17,7 +17,10 @@
30
31 from __future__ import absolute_import
32
33-import cgi
34+try:
35+ from html import escape
36+except ImportError:
37+ from cgi import escape
38 import logging
39 import re
40 import simplejson
41@@ -94,12 +97,12 @@
42 def test_changes(self):
43 app = self.setUpLoggerhead()
44 res = app.get('/changes')
45- res.mustcontain(cgi.escape(self.msg))
46+ res.mustcontain(escape(self.msg))
47
48 def test_changes_for_file(self):
49 app = self.setUpLoggerhead()
50 res = app.get('/changes?filter_file_id=myfilename-id')
51- res.mustcontain(cgi.escape(self.msg))
52+ res.mustcontain(escape(self.msg))
53
54 def test_changes_branch_from(self):
55 app = self.setUpLoggerhead(served_url="lp:loggerhead")
56@@ -126,7 +129,7 @@
57 body_no_span = re.sub(b'<span class="pyg-.">', b'', res.body)
58 body_no_span = body_no_span.replace(b'</span>', b'')
59 for line in self.filecontents.splitlines():
60- escaped = cgi.escape(line).encode('utf-8')
61+ escaped = escape(line).encode('utf-8')
62 self.assertTrue(escaped in body_no_span,
63 "did not find %r in %r" % (escaped, body_no_span))
64

Subscribers

People subscribed via source and target branches