← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands-website/wlwebsite_py36 into lp:widelands-website

 

kaputtnik has proposed merging lp:~widelands-dev/widelands-website/wlwebsite_py36 into lp:widelands-website.

Commit message:
Adapted code for use with python3.6

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1762164 in Widelands Website: "Update website code to use python 3.x"
  https://bugs.launchpad.net/widelands-website/+bug/1762164
  Bug #1828923 in Widelands Website: "Allow usernames with non-English characters"
  https://bugs.launchpad.net/widelands-website/+bug/1828923

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/wlwebsite_py36/+merge/368589

Changes need to get the website running with python 3.6. Because python2.7 is EOL in year 2020 i did not spend any time to make the code python2.7 compatible. So installing the website needs a virtualenvironment created with python 3.6.

Main changes (maybe interesting parts are linked):
 - after running the python 2to3 script: https://bazaar.launchpad.net/~widelands-dev/widelands-website/wlwebsite_py36/revision/533
 - changes regarding to django (mostly replace __unicode__ with __str__)
 - changes regarding str objects, which are bytes objects in python3
 - same for replacing StringIo -> BytesIO when working with images
 - added a python3 compatible version of diff_match_patch.py and applied individual coloring like it is right now
 - fixed template filter 'minutes', renamed it to 'elapsed_time' and applied output of day(s), https://bazaar.launchpad.net/~widelands-dev/widelands-website/wlwebsite_py36/revision/550
 - the url /locale/ shows now also if the environment variable DISPLAY is set
 - after installing on the new server the file README got the needed changes

The added text file 'python3.txt' contain my test results and can be removed if we finally merge this changes into trunk.

I want to merge this before i set up the productive website on the new server.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/wlwebsite_py36 into lp:widelands-website.
=== modified file 'README.txt'
--- README.txt	2019-04-08 05:55:07 +0000
+++ README.txt	2019-06-09 11:20:50 +0000
@@ -1,6 +1,14 @@
 Installing the homepage
 =======================
 
+Used python version
+-------------------
+The website is tested with python 3.6. This README reflects setting up the
+website with this python version.
+
+Install prerequisites
+---------------------
+
 Getting the homepage to run locally is best supported using virtualenv and
 pip. Install those two tools first, either via easy_install or via your local
 package manager. You will also need development tools (gcc or therelike), hg
@@ -11,16 +19,8 @@
 Example:
 On Ubuntu, installing all required tools and dependencies in two commands:
 
-   $ sudo apt-get install python-dev python-virtualenv python-pip mercurial bzr subversion git-core sqlite3
-   $ sudo apt-get build-dep python-numpy
-
-Used python version
--------------------
-
-Currently, the website depends on python 2.7. In case you have python 3 as default (like on arch-linux),
-you have to adjust the python relevant commands to use python 2.7. E.g. 'virtualenv2 wlwebsite' creates
-a virtualenvironment using python 2.7. If the virtualenvironment is activated, python 2.7 will become
-standard for executing python code in this shell.
+   $ sudo apt-get install python3-virtualenv python3-pip bzr libmysqlclient-dev
+   $ sudo apt-get build-dep python3-numpy
 
 Setting up the local environment
 --------------------------------
@@ -33,7 +33,7 @@
 packages from your global site packages. Very important!
 Now, we create and activate our environment:
 
-   $ virtualenv wlwebsite
+   $ virtualenv --python=python3.6 wlwebsite
    $ cd wlwebsite
    $ source bin/activate
 

=== modified file 'check_input/migrations/0001_initial.py'
--- check_input/migrations/0001_initial.py	2017-11-24 10:55:59 +0000
+++ check_input/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 from django.conf import settings

=== modified file 'check_input/models.py'
--- check_input/models.py	2018-04-26 21:10:19 +0000
+++ check_input/models.py	2019-06-09 11:20:50 +0000
@@ -31,7 +31,7 @@
         ordering = ['content_type_id']
         default_permissions = ('change', 'delete',)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.text
 
     def clean(self):

=== modified file 'documentation/conf.py'
--- documentation/conf.py	2018-11-27 17:01:42 +0000
+++ documentation/conf.py	2019-06-09 11:20:50 +0000
@@ -41,8 +41,8 @@
 master_doc = 'index'
 
 # General information about the project.
-project = u'Widelands'
-copyright = u'The Widelands Development Team'
+project = 'Widelands'
+copyright = 'The Widelands Development Team'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the

=== modified file 'documentation/management/commands/create_docs.py'
--- documentation/management/commands/create_docs.py	2018-05-13 09:05:21 +0000
+++ documentation/management/commands/create_docs.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 
 """
 
-from __future__ import print_function
+
 from django.core.management.base import BaseCommand, CommandError
 from django.conf import settings
 from subprocess import check_call, CalledProcessError

=== modified file 'local_settings.py.sample'
--- local_settings.py.sample	2019-04-04 06:47:19 +0000
+++ local_settings.py.sample	2019-06-09 11:20:50 +0000
@@ -3,8 +3,6 @@
 # The above leads python2.7 to read this file as utf-8
 # Needs to be directly after the python shebang
 
-# Treat all strings as unicode
-from __future__ import unicode_literals
 import os
 import re
 

=== modified file 'mainpage/admin.py'
--- mainpage/admin.py	2019-01-18 11:10:27 +0000
+++ mainpage/admin.py	2019-06-09 11:20:50 +0000
@@ -28,7 +28,7 @@
         text += ['has perm.']
     value = ', '.join(text)
     return value
-roles.short_description = u'Groups/Permissions'
+roles.short_description = 'Groups/Permissions'
 
 
 def persons(self):
@@ -38,7 +38,7 @@
 
 def deleted(self):
     return '' if self.wlprofile.deleted==False else 'Yes'
-deleted.short_description = u'Deleted himself'
+deleted.short_description = 'Deleted himself'
 
 
 class GroupAdmin(GroupAdmin):

=== modified file 'mainpage/online_users_middleware.py'
--- mainpage/online_users_middleware.py	2019-03-31 11:08:21 +0000
+++ mainpage/online_users_middleware.py	2019-06-09 11:20:50 +0000
@@ -36,7 +36,7 @@
 
         # Perform the multiget on the individual online uid keys
         online_keys = ['online-%s' % (u,) for u in uids]
-        fresh = cache.get_many(online_keys).keys()
+        fresh = list(cache.get_many(online_keys).keys())
         online_now_ids = [int(k.replace('online-', '')) for k in fresh]
 
         # If the user is authenticated, add their id to the list

=== modified file 'mainpage/settings.py'
--- mainpage/settings.py	2019-04-07 10:02:31 +0000
+++ mainpage/settings.py	2019-06-09 11:20:50 +0000
@@ -288,20 +288,20 @@
 ## Allowed tags/attributes for 'bleach' ##
 ## Used for sanitizing user input.      ##
 ##########################################
-BLEACH_ALLOWED_TAGS = [u'a',
-                       u'abbr',
-                       u'acronym',
-                       u'blockquote',
-                       u'br',
-                       u'em',  u'i',  u'strong', u'b',
-                       u'ul',  u'ol', u'li',
-                       u'div', u'p',
-                       u'h1',  u'h2', u'h3', u'h4', u'h5', u'h6',
-                       u'pre', u'code',
-                       u'img',
-                       u'hr',
-                       u'table', u'tbody', u'thead', u'th', u'tr', u'td',
-                       u'sup',
+BLEACH_ALLOWED_TAGS = ['a',
+                       'abbr',
+                       'acronym',
+                       'blockquote',
+                       'br',
+                       'em',  'i',  'strong', 'b',
+                       'ul',  'ol', 'li',
+                       'div', 'p',
+                       'h1',  'h2', 'h3', 'h4', 'h5', 'h6',
+                       'pre', 'code',
+                       'img',
+                       'hr',
+                       'table', 'tbody', 'thead', 'th', 'tr', 'td',
+                       'sup',
                        ]
 
 BLEACH_ALLOWED_ATTRIBUTES = {'img': ['src', 'alt'], 'a': [
@@ -368,6 +368,6 @@
 
 
 try:
-    from local_settings import *
+    from .local_settings import *
 except ImportError:
     pass

=== modified file 'mainpage/sitemap_urls.py'
--- mainpage/sitemap_urls.py	2019-03-31 11:08:21 +0000
+++ mainpage/sitemap_urls.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 from django.conf.urls import url
 
 from django.contrib.sitemaps.views import sitemap
-from static_sitemap import StaticViewSitemap
+from .static_sitemap import StaticViewSitemap
 from wiki.sitemap import *
 from news.sitemap import *
 from pybb.sitemap import *

=== modified file 'mainpage/templatetags/wl_markdown.py'
--- mainpage/templatetags/wl_markdown.py	2019-03-31 11:08:21 +0000
+++ mainpage/templatetags/wl_markdown.py	2019-06-09 11:20:50 +0000
@@ -11,7 +11,7 @@
 
 from django import template
 from django.conf import settings
-from django.utils.encoding import smart_str, force_unicode
+from django.utils.encoding import smart_bytes, force_text
 from django.utils.safestring import mark_safe
 from django.conf import settings
 from markdownextensions.semanticwikilinks.mdx_semanticwikilinks import SemanticWikiLinkExtension
@@ -19,10 +19,10 @@
 # Try to get a not so fully broken markdown module
 import markdown
 if markdown.version_info[0] < 2:
-    raise ImportError, 'Markdown library to old!'
+    raise ImportError('Markdown library to old!')
 from markdown import markdown
 import re
-import urllib
+import urllib.request, urllib.parse, urllib.error
 import bleach
 
 from bs4 import BeautifulSoup, NavigableString
@@ -138,7 +138,7 @@
 
         # Check for missing wikilink /wiki/PageName[/additionl/stuff]
         # Using href because we need cAsEs here
-        article_name = urllib.unquote(tag['href'][6:].split('/', 1)[0])
+        article_name = urllib.parse.unquote(tag['href'][6:].split('/', 1)[0])
 
         if not len(article_name):  # Wiki root link is not a page
             tag['class'] = 'wrongLink'
@@ -159,7 +159,7 @@
             # get actual title of article
             act_t = Article.objects.get(id=a_id[0]).title
             if article_name != act_t:
-                tag['title'] = 'This is a redirect and points to \"" + act_t + "\"'
+                tag['title'] = 'This is a redirect and points to \"' + act_t + '\"'
                 return
             else:
                 return
@@ -218,7 +218,7 @@
     """Apply wl specific things, like smileys or colored links."""
 
     beautify = keyw.pop('beautify', True)
-    html = smart_str(markdown(value, extensions=md_extensions))
+    html = markdown(value, extensions=md_extensions)
 
     # Sanitize posts from potencial untrusted users (Forum/Wiki/Maps)
     if 'bleachit' in args:
@@ -232,7 +232,7 @@
     soup = BeautifulSoup(html, features='lxml')
     if len(soup.contents) == 0:
         # well, empty soup. Return it
-        return unicode(soup)
+        return str(soup)
 
     if beautify:
         # Insert smileys
@@ -249,7 +249,7 @@
         for tag in soup.find_all('img'):
             _make_clickable_images(tag)
 
-    return unicode(soup)
+    return str(soup)
 
 
 @register.filter

=== modified file 'mainpage/urls.py'
--- mainpage/urls.py	2019-03-31 11:08:21 +0000
+++ mainpage/urls.py	2019-06-09 11:20:50 +0000
@@ -63,7 +63,7 @@
 ]
 
 try:
-    from local_urls import *
+    from .local_urls import *
     urlpatterns += local_urlpatterns
 except ImportError:
     pass

=== modified file 'mainpage/utest/test_wl_markdown.py'
--- mainpage/utest/test_wl_markdown.py	2019-03-31 11:08:21 +0000
+++ mainpage/utest/test_wl_markdown.py	2019-06-09 11:20:50 +0000
@@ -37,222 +37,222 @@
         self.assertEqual(wanted, res)
 
     def test_simple_case__correct_result(self):
-        input = u"Hallo Welt"
-        wanted = u"<p>Hallo Welt</p>"
+        input = "Hallo Welt"
+        wanted = "<p>Hallo Welt</p>"
         self._check(input, wanted)
 
     def test_wikiwords_simple__except_correct_result(self):
-        input = u"Na Du HalloWelt, Du?"
-        wanted = u"""<p>Na Du <a href="/wiki/HalloWelt">HalloWelt</a>, Du?</p>"""
+        input = "Na Du HalloWelt, Du?"
+        wanted = """<p>Na Du <a href="/wiki/HalloWelt">HalloWelt</a>, Du?</p>"""
         self._check(input, wanted)
 
     def test_wikiwords_avoid__except_correct_result(self):
-        input = u"Hi !NotAWikiWord Moretext"
-        wanted = u"""<p>Hi NotAWikiWord Moretext</p>"""
+        input = "Hi !NotAWikiWord Moretext"
+        wanted = """<p>Hi NotAWikiWord Moretext</p>"""
         self._check(input, wanted)
 
     def test_wikiwords_in_link__except_correct_result(self):
-        input = u"""WikiWord [NoWikiWord](/forum/)"""
-        wanted = u"""<p><a href="/wiki/WikiWord">WikiWord</a> <a href="/forum/">NoWikiWord</a></p>"""
+        input = """WikiWord [NoWikiWord](/forum/)"""
+        wanted = """<p><a href="/wiki/WikiWord">WikiWord</a> <a href="/forum/">NoWikiWord</a></p>"""
         self._check(input, wanted)
 
     def test_wikiwords_external_links__except_correct_result(self):
-        input = u"""[NoWikiWord](http://www.sun.com)"""
-        wanted = u"""<p><a href="http://www.sun.com"; class="external">NoWikiWord</a></p>"""
+        input = """[NoWikiWord](http://www.sun.com)"""
+        wanted = """<p><a href="http://www.sun.com"; class="external">NoWikiWord</a></p>"""
         self._check(input, wanted)
 
     def test_wikiwords_noexternal_links__except_correct_result(self):
-        input = u"""[NoWikiWord](http://%s/blahfasel/wiki)""" % _domain
-        wanted = u"""<p><a href="http://%s/blahfasel/wiki";>NoWikiWord</a></p>""" % _domain
+        input = """[NoWikiWord](http://%s/blahfasel/wiki)""" % _domain
+        wanted = """<p><a href="http://%s/blahfasel/wiki";>NoWikiWord</a></p>""" % _domain
         self._check(input, wanted)
 
     def test_wikiwords_noclasschangeforimage_links__except_correct_result(self):
-        input =  u"""<a href="http://www.ccc.de";><img src="/blub" /></a>"""
-        wanted = u"""<p><a href="http://www.ccc.de";><img src="/blub" /></a></p>"""
+        input =  """<a href="http://www.ccc.de";><img src="/blub" /></a>"""
+        wanted = """<p><a href="http://www.ccc.de";><img src="/blub" /></a></p>"""
         self._check(input, wanted)
 
     # Existing links
     def test_existing_link_html(self):
-        input = u"""<a href="/wiki/MainPage">this page</a>"""
-        wanted = u"""<p><a href="/wiki/MainPage">this page</a></p>"""
+        input = """<a href="/wiki/MainPage">this page</a>"""
+        wanted = """<p><a href="/wiki/MainPage">this page</a></p>"""
         self._check(input, wanted)
 
     def test_existing_link_markdown(self):
-        input = u"""[this page](/wiki/MainPage)"""
-        wanted = u"""<p><a href="/wiki/MainPage">this page</a></p>"""
+        input = """[this page](/wiki/MainPage)"""
+        wanted = """<p><a href="/wiki/MainPage">this page</a></p>"""
         self._check(input, wanted)
 
     def test_existing_link_wikiword(self):
-        input = u"""MainPage"""
-        wanted = u"""<p><a href="/wiki/MainPage">MainPage</a></p>"""
+        input = """MainPage"""
+        wanted = """<p><a href="/wiki/MainPage">MainPage</a></p>"""
         self._check(input, wanted)
 
     def test_existing_editlink_wikiword(self):
-        input = u"""<a href="/wiki/MainPage/edit/">this page</a>"""
-        wanted = u"""<p><a href="/wiki/MainPage/edit/">this page</a></p>"""
+        input = """<a href="/wiki/MainPage/edit/">this page</a>"""
+        wanted = """<p><a href="/wiki/MainPage/edit/">this page</a></p>"""
         self._check(input, wanted)
 
     # Missing links
     def test_missing_link_html(self):
-        input = u"""<a href="/wiki/MissingPage">this page</a>"""
-        wanted = u"""<p><a href="/wiki/MissingPage" class="missing">this page</a></p>"""
+        input = """<a href="/wiki/MissingPage">this page</a>"""
+        wanted = """<p><a href="/wiki/MissingPage" class="missing">this page</a></p>"""
         self._check(input, wanted)
 
     def test_missing_link_markdown(self):
-        input = u"""[this page](/wiki/MissingPage)"""
-        wanted = u"""<p><a href="/wiki/MissingPage" class="missing">this page</a></p>"""
+        input = """[this page](/wiki/MissingPage)"""
+        wanted = """<p><a href="/wiki/MissingPage" class="missing">this page</a></p>"""
         self._check(input, wanted)
 
     def test_missing_link_wikiword(self):
-        input = u"""BlubMissingPage"""
-        wanted = u"""<p><a href="/wiki/BlubMissingPage" class="missing">BlubMissingPage</a></p>"""
+        input = """BlubMissingPage"""
+        wanted = """<p><a href="/wiki/BlubMissingPage" class="missing">BlubMissingPage</a></p>"""
         res = do_wl_markdown(input)
         # self._check(input,wanted)
 
     def test_missing_editlink_wikiword(self):
-        input = u"""<a href="/wiki/MissingPage/edit/">this page</a>"""
-        wanted = u"""<p><a href="/wiki/MissingPage/edit/" class="missing">this page</a></p>"""
+        input = """<a href="/wiki/MissingPage/edit/">this page</a>"""
+        wanted = """<p><a href="/wiki/MissingPage/edit/" class="missing">this page</a></p>"""
         self._check(input, wanted)
 
     # Check smileys
     def test_smiley_angel(self):
         input = """O:-)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-angel.png" alt="face-angel.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-angel.png" alt="face-angel.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_crying(self):
         input = """:'-("""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-crying.png" alt="face-crying.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-crying.png" alt="face-crying.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_devilish(self):
         input = """>:-)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-devilish.png" alt="face-devilish.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-devilish.png" alt="face-devilish.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_glasses(self):
         input = """8-)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-glasses.png" alt="face-glasses.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-glasses.png" alt="face-glasses.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_kiss(self):
         input = """:-x"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-kiss.png" alt="face-kiss.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-kiss.png" alt="face-kiss.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_plain(self):
         input = """:-|"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-plain.png" alt="face-plain.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-plain.png" alt="face-plain.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_sad(self):
         input = """:-("""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-sad.png" alt="face-sad.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-sad.png" alt="face-sad.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_smilebig(self):
         input = """:))"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-smile-big.png" alt="face-smile-big.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-smile-big.png" alt="face-smile-big.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_smile(self):
         input = """:-)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-smile.png" alt="face-smile.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-smile.png" alt="face-smile.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_surprise(self):
         input = """:-O"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-surprise.png" alt="face-surprise.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-surprise.png" alt="face-surprise.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_wink(self):
         input = """;-)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-wink.png" alt="face-wink.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-wink.png" alt="face-wink.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_grin(self):
         input = """:D"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-grin.png" alt="face-grin.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-grin.png" alt="face-grin.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_sad(self):
         input = """:("""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-sad.png" alt="face-sad.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-sad.png" alt="face-sad.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_smile(self):
         input = """:)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-smile.png" alt="face-smile.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-smile.png" alt="face-smile.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_surprise(self):
         input = """:O"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-surprise.png" alt="face-surprise.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-surprise.png" alt="face-surprise.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_wink(self):
         input = """;)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-wink.png" alt="face-wink.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-wink.png" alt="face-wink.png" /></p>"""
         self._check(input, wanted)
 
     def test_smiley_monkey(self):
         input = """:(|)"""
-        wanted = u"""<p><img src="/wlmedia/img/smileys/face-monkey.png" alt="face-monkey.png" /></p>"""
+        wanted = """<p><img src="/wlmedia/img/smileys/face-monkey.png" alt="face-monkey.png" /></p>"""
         self._check(input, wanted)
 
     # Occured errors
     def test_wiki_rootlink(self):
-        input = u"""<a href="/wiki">this page</a>"""
-        wanted = u"""<p><a href="/wiki">this page</a></p>"""
+        input = """<a href="/wiki">this page</a>"""
+        wanted = """<p><a href="/wiki">this page</a></p>"""
         self._check(input, wanted)
 
     def test_wiki_rootlink_with_slash(self):
-        input = u"""<a href="/wiki/">this page</a>"""
-        wanted = u"""<p><a href="/wiki/">this page</a></p>"""
+        input = """<a href="/wiki/">this page</a>"""
+        wanted = """<p><a href="/wiki/">this page</a></p>"""
         self._check(input, wanted)
 
     # Special pages
     def test_wiki_specialpage(self):
-        input = u"""<a href="/wiki/list">this page</a>"""
-        wanted = u"""<p><a href="/wiki/list">this page</a></p>"""
+        input = """<a href="/wiki/list">this page</a>"""
+        wanted = """<p><a href="/wiki/list">this page</a></p>"""
         self._check(input, wanted)
 
     def test_wiki_specialpage_markdown(self):
-        input = u"""[list](/wiki/list)"""
-        wanted = u"""<p><a href="/wiki/list">list</a></p>"""
+        input = """[list](/wiki/list)"""
+        wanted = """<p><a href="/wiki/list">list</a></p>"""
         self._check(input, wanted)
 
     # Special problem with emphasis
     def test_markdown_emphasis_problem(self):
-        input = u"""*This is bold*  _This too_\n\n"""
-        wanted = u"""<p><em>This is bold</em> <em>This too</em></p>"""
+        input = """*This is bold*  _This too_\n\n"""
+        wanted = """<p><em>This is bold</em> <em>This too</em></p>"""
         self._check(input, wanted)
 
     # Another markdown problem with alt tag escaping
     def test_markdown_alt_problem(self):
         # {{{ Test strings
-        input = u"""![img_thisisNOTitalicplease_name.png](/wlmedia/blah.png)\n\n"""
-        wanted = u'<p><img alt="img_thisisNOTitalicplease_name.png" src="/wlmedia/blah.png" /></p>'
+        input = """![img_thisisNOTitalicplease_name.png](/wlmedia/blah.png)\n\n"""
+        wanted = '<p><img alt="img_thisisNOTitalicplease_name.png" src="/wlmedia/blah.png" /></p>'
         # }}}
         self._check(input, wanted)
 
     def test_emptystring_problem(self):
         # {{{ Test strings
-        input = u''
-        wanted = u''
+        input = ''
+        wanted = ''
         # }}}
         self._check(input, wanted)
 
     # Damned problem with tables
     def test_markdown_table_problem(self):
         # {{{ Test strings
-        input = u"""
+        input = """
 Header1 | Header 2
 ------- | --------
 Value 1 | Value 2
 Value 3 | Value 4
 """
-        wanted = u"""<table>
+        wanted = """<table>
 <thead>
 <tr>
 <th>Header1</th>
@@ -274,13 +274,13 @@
         self._check(input, wanted)
 
     def test_svnrevision_replacement(self):
-        input = u"- Fixed this bug (bzr:r3222)"
-        wanted = u"""<ul>\n<li>Fixed this bug (<a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3222"; class="external">r3222</a>)</li>\n</ul>"""
+        input = "- Fixed this bug (bzr:r3222)"
+        wanted = """<ul>\n<li>Fixed this bug (<a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3222"; class="external">r3222</a>)</li>\n</ul>"""
         self._check(input, wanted)
 
     def test_svnrevision_multiple_replacement(self):
-        input = u"- Fixed this bug (bzr:r3222, bzr:r3424)"
-        wanted = u"""<ul>\n<li>Fixed this bug (<a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3222"; class="external">r3222</a>, <a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3424"; class="external">r3424</a>)</li>\n</ul>"""
+        input = "- Fixed this bug (bzr:r3222, bzr:r3424)"
+        wanted = """<ul>\n<li>Fixed this bug (<a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3222"; class="external">r3222</a>, <a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3424"; class="external">r3424</a>)</li>\n</ul>"""
         self._check(input, wanted)
 
 

=== modified file 'mainpage/views.py'
--- mainpage/views.py	2019-03-31 11:08:21 +0000
+++ mainpage/views.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 from django.conf import settings
-from templatetags.wl_markdown import do_wl_markdown
+from .templatetags.wl_markdown import do_wl_markdown
 from operator import itemgetter
 from django.core.mail import send_mail
 from mainpage.forms import ContactForm
@@ -119,12 +119,12 @@
 
                 # Add a subheader or/and the member(s)
                 for entry in head['entries']:
-                    if 'subheading' in entry.keys():
+                    if 'subheading' in list(entry.keys()):
                         txt = txt + '###' + entry['subheading'] + '\n'
-                    if 'members' in entry.keys():
+                    if 'members' in list(entry.keys()):
                         for name in entry['members']:
                             txt = txt + '* ' + name + '\n'
-                    if 'translate' in entry.keys():
+                    if 'translate' in list(entry.keys()):
                         for transl in entry['translate']:
                             txt = txt + '* ' + transl + '\n'
 
@@ -160,5 +160,7 @@
     loc_info = 'getlocale: ' + str(locale.getlocale()) + \
         '<br/>getdefaultlocale(): ' + str(locale.getdefaultlocale()) + \
         '<br/>fs_encoding: ' + str(sys.getfilesystemencoding()) + \
-        '<br/>sys default encoding: ' + str(sys.getdefaultencoding())
+        '<br/>sys default encoding: ' + str(sys.getdefaultencoding()) + \
+        '<br><br> Environment variables:' + \
+        '<br>DISPLAY: ' + os.environ.get('DISPLAY', 'Not set')
     return HttpResponse(loc_info)

=== modified file 'mainpage/wlwebsite_wsgi.py'
--- mainpage/wlwebsite_wsgi.py	2019-03-31 11:08:21 +0000
+++ mainpage/wlwebsite_wsgi.py	2019-06-09 11:20:50 +0000
@@ -16,7 +16,7 @@
 if activate_this is None:
     raise RuntimeException('Could not find virtualenv to start up!')
 
-execfile(activate_this, dict(__file__=activate_this))
+exec(compile(open(activate_this, "rb").read(), activate_this, 'exec'), dict(__file__=activate_this))
 
 sys.path.append(parent_dir(code_directory))
 sys.path.append(code_directory)

=== modified file 'news/migrations/0001_initial.py'
--- news/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ news/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 from django.conf import settings

=== modified file 'news/migrations/0002_auto_20170417_1857.py'
--- news/migrations/0002_auto_20170417_1857.py	2017-04-17 17:08:27 +0000
+++ news/migrations/0002_auto_20170417_1857.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'news/models.py'
--- news/models.py	2019-03-31 11:08:21 +0000
+++ news/models.py	2019-06-09 11:20:50 +0000
@@ -29,8 +29,8 @@
         db_table = 'news_categories'
         ordering = ('title',)
 
-    def __unicode__(self):
-        return u'%s' % self.title
+    def __str__(self):
+        return '%s' % self.title
 
     def get_absolute_url(self):
         return reverse('category_posts', args=(self.slug,))
@@ -65,8 +65,8 @@
         ordering = ('-publish',)
         get_latest_by = 'publish'
 
-    def __unicode__(self):
-        return u'%s' % self.title
+    def __str__(self):
+        return '%s' % self.title
 
     #########
     # IMAGE #

=== modified file 'news/templatetags/news_extras.py'
--- news/templatetags/news_extras.py	2016-12-13 18:28:51 +0000
+++ news/templatetags/news_extras.py	2019-06-09 11:20:50 +0000
@@ -42,9 +42,9 @@
     try:
         tag_name, arg = token.contents.split(None, 1)
     except ValueError:
-        raise template.TemplateSyntaxError, '%s tag requires arguments' % token.contents.split()[0]
+        raise template.TemplateSyntaxError('%s tag requires arguments' % token.contents.split()[0])
     m = re.search(r'(.*?) as (\w+)', arg)
     if not m:
-        raise template.TemplateSyntaxError, '%s tag had invalid arguments' % tag_name
+        raise template.TemplateSyntaxError('%s tag had invalid arguments' % tag_name)
     format_string, var_name = m.groups()
     return LatestPosts(format_string, var_name)

=== modified file 'notification/engine.py'
--- notification/engine.py	2017-04-29 19:52:28 +0000
+++ notification/engine.py	2019-06-09 11:20:50 +0000
@@ -5,7 +5,7 @@
 import traceback
 
 try:
-    import cPickle as pickle
+    import pickle as pickle
 except ImportError:
     import pickle
 
@@ -14,7 +14,7 @@
 from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
 
-from lockfile import FileLock, AlreadyLocked, LockTimeout
+from .lockfile import FileLock, AlreadyLocked, LockTimeout
 
 from notification.models import NoticeQueueBatch
 from notification import models as notification

=== modified file 'notification/lockfile.py'
--- notification/lockfile.py	2016-12-13 18:28:51 +0000
+++ notification/lockfile.py	2019-06-09 11:20:50 +0000
@@ -48,7 +48,7 @@
             NotMyLock - File was locked but not by the current thread/process
 """
 
-from __future__ import division
+
 
 import sys
 import socket
@@ -385,8 +385,8 @@
 
     def __init__(self, path, threaded=True):
         LockBase.__init__(self, path, threaded)
-        self.lock_file = unicode(self.lock_file)
-        self.unique_name = unicode(self.unique_name)
+        self.lock_file = str(self.lock_file)
+        self.unique_name = str(self.unique_name)
 
         import sqlite3
         self.connection = sqlite3.connect(SQLiteFileLock.testdb)

=== modified file 'notification/migrations/0001_initial.py'
--- notification/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ notification/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 import datetime

=== modified file 'notification/migrations/0002_auto_20170417_1857.py'
--- notification/migrations/0002_auto_20170417_1857.py	2017-04-17 17:08:27 +0000
+++ notification/migrations/0002_auto_20170417_1857.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'notification/migrations/0003_auto_20190409_0924.py'
--- notification/migrations/0003_auto_20190409_0924.py	2019-04-10 16:01:43 +0000
+++ notification/migrations/0003_auto_20190409_0924.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.20 on 2019-04-09 09:24
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 

=== modified file 'notification/models.py'
--- notification/models.py	2018-04-19 17:48:31 +0000
+++ notification/models.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 import datetime
 
 try:
-    import cPickle as pickle
+    import pickle as pickle
 except ImportError:
     import pickle
 
@@ -48,7 +48,7 @@
     # number
     default = models.IntegerField(_('default'))
 
-    def __unicode__(self):
+    def __str__(self):
         return self.label
 
     class Meta:
@@ -150,12 +150,12 @@
         if updated:
             notice_type.save()
             if verbosity > 1:
-                print 'Updated %s NoticeType' % label
+                print('Updated %s NoticeType' % label)
     except NoticeType.DoesNotExist:
         NoticeType(label=label, display=display,
                    description=description, default=default).save()
         if verbosity > 1:
-            print 'Created %s NoticeType' % label
+            print('Created %s NoticeType' % label)
 
 
 def get_notification_language(user):
@@ -222,8 +222,8 @@
         notice_type = NoticeType.objects.get(label=label)
 
         current_site = Site.objects.get_current()
-        notices_url = u"http://%s%s"; % (
-            unicode(current_site),
+        notices_url = "http://%s%s"; % (
+            str(current_site),
             reverse('notification_notices'),
         )
 
@@ -257,12 +257,12 @@
 
             # get prerendered format messages and subjects
             messages = get_formatted_messages(formats, label, context)
-            
+
             # Create the subject
             # Use 'email_subject.txt' to add Strings in every emails subject
             subject = render_to_string('notification/email_subject.txt',
                                        {'message': messages['short.txt'],}).replace('\n', '')
-            
+
             # Strip leading newlines. Make writing the email templates easier:
             # Each linebreak in the templates results in a linebreak in the emails
             # If the first line in a template contains only template tags the 
@@ -275,8 +275,8 @@
             if should_send(user, notice_type, '1') and user.email:  # Email
                 recipients.append(user.email)
 
-            send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
-        
+            send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients, fail_silently=True)
+
         # reset environment to original language
         activate(current_language)
     except NoticeType.DoesNotExist:

=== modified file 'notification/views.py'
--- notification/views.py	2018-04-03 05:18:03 +0000
+++ notification/views.py	2019-06-09 11:20:50 +0000
@@ -29,5 +29,5 @@
 
     return render(request, 'notification/notice_settings.html', {
         'column_headers': [medium_display for medium_id, medium_display in NOTICE_MEDIA],
-        'app_tables': OrderedDict(sorted(app_tables.items(), key=lambda t: t[0]))
+        'app_tables': OrderedDict(sorted(list(app_tables.items()), key=lambda t: t[0]))
     })

=== modified file 'privacy_policy/admin.py'
--- privacy_policy/admin.py	2018-10-08 17:51:36 +0000
+++ privacy_policy/admin.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.contrib import admin
 from privacy_policy.models import PrivacyPolicy

=== modified file 'privacy_policy/apps.py'
--- privacy_policy/apps.py	2018-10-02 16:55:42 +0000
+++ privacy_policy/apps.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.apps import AppConfig
 

=== modified file 'privacy_policy/migrations/0001_initial.py'
--- privacy_policy/migrations/0001_initial.py	2018-10-08 17:51:36 +0000
+++ privacy_policy/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-10-08 18:23
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 

=== modified file 'privacy_policy/models.py'
--- privacy_policy/models.py	2018-10-14 07:58:31 +0000
+++ privacy_policy/models.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models
 from django.urls import reverse
@@ -17,7 +17,7 @@
     class Meta:
         ordering = ['language']
 
-    def __unicode__(self):
+    def __str__(self):
         return self.language
     
     def get_absolute_url(self):

=== modified file 'privacy_policy/views.py'
--- privacy_policy/views.py	2019-04-07 09:01:06 +0000
+++ privacy_policy/views.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.shortcuts import render
 from django.core.exceptions import ObjectDoesNotExist

=== modified file 'pybb/lib/phpserialize.py'
--- pybb/lib/phpserialize.py	2009-02-25 16:55:36 +0000
+++ pybb/lib/phpserialize.py	2019-06-09 11:20:50 +0000
@@ -96,7 +96,7 @@
     :copyright: 2007-2008 by Armin Ronacher.
     license: BSD
 """
-from StringIO import StringIO
+from io import StringIO
 
 __author__ = 'Armin Ronacher <armin.ronacher@xxxxxxxxxxxx>'
 __version__ = '1.1'
@@ -108,10 +108,10 @@
     """
     def _serialize(obj, keypos):
         if keypos:
-            if isinstance(obj, (int, long, float, bool)):
+            if isinstance(obj, (int, float, bool)):
                 return 'i:%i;' % obj
-            if isinstance(obj, basestring):
-                if isinstance(obj, unicode):
+            if isinstance(obj, str):
+                if isinstance(obj, str):
                     obj = obj.encode(charset, errors)
                 return 's:%i:"%s";' % (len(obj), obj)
             if obj is None:
@@ -122,18 +122,18 @@
                 return 'N;'
             if isinstance(obj, bool):
                 return 'b:%i;' % obj
-            if isinstance(obj, (int, long)):
+            if isinstance(obj, int):
                 return 'i:%s;' % obj
             if isinstance(obj, float):
                 return 'd:%s;' % obj
-            if isinstance(obj, basestring):
-                if isinstance(obj, unicode):
+            if isinstance(obj, str):
+                if isinstance(obj, str):
                     obj = obj.encode(charset, errors)
                 return 's:%i:"%s";' % (len(obj), obj)
             if isinstance(obj, (list, tuple, dict)):
                 out = []
                 if isinstance(obj, dict):
-                    iterable = obj.iteritems()
+                    iterable = iter(obj.items())
                 else:
                     iterable = enumerate(obj)
                 for key, value in iterable:
@@ -202,7 +202,7 @@
             _expect('{')
             result = {}
             last_item = Ellipsis
-            for idx in xrange(items):
+            for idx in range(items):
                 item = _unserialize()
                 if last_item is Ellipsis:
                     last_item = item
@@ -238,7 +238,7 @@
 def dict_to_list(d):
     """Converts an ordered dict into a list."""
     try:
-        return [d[x] for x in xrange(len(d))]
+        return [d[x] for x in range(len(d))]
     except KeyError:
         raise ValueError('dict is not a sequence')
 

=== modified file 'pybb/management/__init__.py'
--- pybb/management/__init__.py	2010-06-08 19:11:54 +0000
+++ pybb/management/__init__.py	2019-06-09 11:20:50 +0000
@@ -1,1 +1,1 @@
-import pybb_notifications
+from . import pybb_notifications

=== modified file 'pybb/management/commands/pybb_resave_post.py'
--- pybb/management/commands/pybb_resave_post.py	2018-04-08 15:53:05 +0000
+++ pybb/management/commands/pybb_resave_post.py	2019-06-09 11:20:50 +0000
@@ -14,5 +14,5 @@
 
         for count, post in enumerate(Post.objects.all()):
             if count and not count % 1000:
-                print count
+                print(count)
             post.save()

=== modified file 'pybb/management/pybb_notifications.py'
--- pybb/management/pybb_notifications.py	2018-04-03 18:57:40 +0000
+++ pybb/management/pybb_notifications.py	2019-06-09 11:20:50 +0000
@@ -14,4 +14,4 @@
                                         _('Forum New Post'),
                                         _('a new comment has been posted to a topic you observe'))
 except ImportError:
-    print 'Skipping creation of NoticeTypes as notification app not found'
+    print('Skipping creation of NoticeTypes as notification app not found')

=== modified file 'pybb/markups/postmarkup.py'
--- pybb/markups/postmarkup.py	2016-12-13 18:28:51 +0000
+++ pybb/markups/postmarkup.py	2019-06-09 11:20:50 +0000
@@ -8,8 +8,8 @@
 __version__ = '1.1.3'
 
 import re
-from urllib import quote, unquote, quote_plus
-from urlparse import urlparse, urlunparse
+from urllib.parse import quote, unquote, quote_plus
+from urllib.parse import urlparse, urlunparse
 
 pygments_available = True
 try:
@@ -28,7 +28,7 @@
     domain -- Domain parsed from url
 
     """
-    return u" [%s]" % _escape(domain)
+    return " [%s]" % _escape(domain)
 
 
 re_url = re.compile(
@@ -62,7 +62,7 @@
     if match is None:
         return ''
     excerpt = match.group(0)
-    excerpt = excerpt.replace(u'\n', u"<br/>")
+    excerpt = excerpt.replace('\n', "<br/>")
     return remove_markup(excerpt)
 
 
@@ -73,7 +73,7 @@
 
     """
 
-    return u"".join([t[1] for t in PostMarkup.tokenize(bbcode) if t[0] == PostMarkup.TOKEN_TEXT])
+    return "".join([t[1] for t in PostMarkup.tokenize(bbcode) if t[0] == PostMarkup.TOKEN_TEXT])
 
 
 def create(include=None, exclude=None, use_pygments=True, **kwargs):
@@ -107,28 +107,28 @@
 
     add_tag(QuoteTag, 'quote')
 
-    add_tag(SearchTag, u'wiki',
-            u"http://en.wikipedia.org/wiki/Special:Search?search=%s";, u'wikipedia.com', **kwargs)
-    add_tag(SearchTag, u'google',
-            u"http://www.google.com/search?hl=en&q=%s&btnG=Google+Search";, u'google.com', **kwargs)
-    add_tag(SearchTag, u'dictionary',
-            u"http://dictionary.reference.com/browse/%s";, u'dictionary.com', **kwargs)
-    add_tag(SearchTag, u'dict',
-            u"http://dictionary.reference.com/browse/%s";, u'dictionary.com', **kwargs)
-
-    add_tag(ImgTag, u'img')
-    add_tag(ListTag, u'list')
-    add_tag(ListItemTag, u'*')
-
-    add_tag(SizeTag, u"size")
-    add_tag(ColorTag, u"color")
-    add_tag(CenterTag, u"center")
+    add_tag(SearchTag, 'wiki',
+            "http://en.wikipedia.org/wiki/Special:Search?search=%s";, 'wikipedia.com', **kwargs)
+    add_tag(SearchTag, 'google',
+            "http://www.google.com/search?hl=en&q=%s&btnG=Google+Search";, 'google.com', **kwargs)
+    add_tag(SearchTag, 'dictionary',
+            "http://dictionary.reference.com/browse/%s";, 'dictionary.com', **kwargs)
+    add_tag(SearchTag, 'dict',
+            "http://dictionary.reference.com/browse/%s";, 'dictionary.com', **kwargs)
+
+    add_tag(ImgTag, 'img')
+    add_tag(ListTag, 'list')
+    add_tag(ListItemTag, '*')
+
+    add_tag(SizeTag, "size")
+    add_tag(ColorTag, "color")
+    add_tag(CenterTag, "center")
 
     if use_pygments:
         assert pygments_available, 'Install Pygments (http://pygments.org/) or call create with use_pygments=False'
-        add_tag(PygmentsCodeTag, u'code', **kwargs)
+        add_tag(PygmentsCodeTag, 'code', **kwargs)
     else:
-        add_tag(CodeTag, u'code', **kwargs)
+        add_tag(CodeTag, 'code', **kwargs)
 
     return postmarkup
 
@@ -203,7 +203,7 @@
     def get_contents_text(self, parser):
         """Returns the string between the the open and close tag, minus bbcode
         tags."""
-        return u"".join(parser.get_text_nodes(self.open_node_index, self.close_node_index))
+        return "".join(parser.get_text_nodes(self.open_node_index, self.close_node_index))
 
     def skip_contents(self, parser):
         """Skips the contents of a tag while rendering."""
@@ -223,10 +223,10 @@
         self.html_name = html_name
 
     def render_open(self, parser, node_index):
-        return u"<%s>" % self.html_name
+        return "<%s>" % self.html_name
 
     def render_close(self, parser, node_index):
-        return u"</%s>" % self.html_name
+        return "</%s>" % self.html_name
 
 
 class DivStyleTag(TagBase):
@@ -239,10 +239,10 @@
         self.value = value
 
     def render_open(self, parser, node_index):
-        return u'<div style="%s:%s;">' % (self.style, self.value)
+        return '<div style="%s:%s;">' % (self.style, self.value)
 
     def render_close(self, parser, node_index):
-        return u'</div>'
+        return '</div>'
 
 
 class LinkTag(TagBase):
@@ -254,13 +254,13 @@
 
     def render_open(self, parser, node_index):
 
-        self.domain = u''
+        self.domain = ''
         tag_data = parser.tag_data
         nest_level = tag_data['link_nest_level'] = tag_data.setdefault(
             'link_nest_level', 0) + 1
 
         if nest_level > 1:
-            return u""
+            return ""
 
         if self.params:
             url = self.params.strip()
@@ -272,12 +272,12 @@
         self.url = unquote(url)
 
         # Disallow javascript links
-        if u"javascript:" in self.url.lower():
+        if "javascript:" in self.url.lower():
             return ''
 
         # Disallow non http: links
         url_parsed = urlparse(self.url)
-        if url_parsed[0] and not url_parsed[0].lower().startswith(u'http'):
+        if url_parsed[0] and not url_parsed[0].lower().startswith('http'):
             return ''
 
         # Prepend http: if it is not present
@@ -289,21 +289,21 @@
         self.domain = url_parsed[1].lower()
 
         # Remove www for brevity
-        if self.domain.startswith(u'www.'):
+        if self.domain.startswith('www.'):
             self.domain = self.domain[4:]
 
         # Quote the url
         #self.url="http:"+urlunparse( map(quote, (u"",)+url_parsed[1:]) )
-        self.url = unicode(urlunparse(
+        self.url = str(urlunparse(
             [quote(component.encode('utf-8'), safe='/=&?:+') for component in url_parsed]))
 
         if not self.url:
-            return u""
+            return ""
 
         if self.domain:
-            return u'<a href="%s">' % self.url
+            return '<a href="%s">' % self.url
         else:
-            return u""
+            return ""
 
     def render_close(self, parser, node_index):
 
@@ -311,19 +311,19 @@
         tag_data['link_nest_level'] -= 1
 
         if tag_data['link_nest_level'] > 0:
-            return u''
+            return ''
 
         if self.domain:
-            return u'</a>' + self.annotate_link(self.domain)
+            return '</a>' + self.annotate_link(self.domain)
         else:
-            return u''
+            return ''
 
     def annotate_link(self, domain=None):
 
         if domain and self.annotate_links:
             return annotate_link(domain)
         else:
-            return u""
+            return ""
 
 
 class QuoteTag(TagBase):
@@ -339,12 +339,12 @@
 
     def render_open(self, parser, node_index):
         if self.params:
-            return u'<blockquote><em>%s</em><br/>' % (PostMarkup.standard_replace(self.params))
+            return '<blockquote><em>%s</em><br/>' % (PostMarkup.standard_replace(self.params))
         else:
-            return u'<blockquote>'
+            return '<blockquote>'
 
     def render_close(self, parser, node_index):
-        return u"</blockquote>"
+        return "</blockquote>"
 
 
 class SearchTag(TagBase):
@@ -361,8 +361,8 @@
             search = self.params
         else:
             search = self.get_contents(parser)
-        link = u'<a href="%s">' % self.url
-        if u'%' in link:
+        link = '<a href="%s">' % self.url
+        if '%' in link:
             return link % quote_plus(search.encode('UTF-8'))
         else:
             return link
@@ -370,12 +370,12 @@
     def render_close(self, parser, node_index):
 
         if self.label:
-            ret = u'</a>'
+            ret = '</a>'
             if self.annotate_links:
                 ret += annotate_link(self.label)
             return ret
         else:
-            return u''
+            return ''
 
 
 class PygmentsCodeTag(TagBase):
@@ -421,9 +421,9 @@
         contents = self.get_contents(parser)
         self.skip_contents(parser)
 
-        contents = strip_bbcode(contents).replace(u'"', '%22')
+        contents = strip_bbcode(contents).replace('"', '%22')
 
-        return u'<img src="%s"></img>' % contents
+        return '<img src="%s"></img>' % contents
 
 
 class ListTag(TagBase):
@@ -439,30 +439,30 @@
 
     def render_open(self, parser, node_index):
 
-        self.close_tag = u""
+        self.close_tag = ""
 
         tag_data = parser.tag_data
         tag_data.setdefault('ListTag.count', 0)
 
         if tag_data['ListTag.count']:
-            return u""
+            return ""
 
         tag_data['ListTag.count'] += 1
 
         tag_data['ListItemTag.initial_item'] = True
 
         if self.params == '1':
-            self.close_tag = u"</li></ol>"
-            return u"<ol><li>"
+            self.close_tag = "</li></ol>"
+            return "<ol><li>"
         elif self.params == 'a':
-            self.close_tag = u"</li></ol>"
-            return u'<ol style="list-style-type: lower-alpha;"><li>'
+            self.close_tag = "</li></ol>"
+            return '<ol style="list-style-type: lower-alpha;"><li>'
         elif self.params == 'A':
-            self.close_tag = u"</li></ol>"
-            return u'<ol style="list-style-type: upper-alpha;"><li>'
+            self.close_tag = "</li></ol>"
+            return '<ol style="list-style-type: upper-alpha;"><li>'
         else:
-            self.close_tag = u"</li></ul>"
-            return u"<ul><li>"
+            self.close_tag = "</li></ul>"
+            return "<ul><li>"
 
     def render_close(self, parser, node_index):
 
@@ -482,13 +482,13 @@
 
         tag_data = parser.tag_data
         if not tag_data.setdefault('ListTag.count', 0):
-            return u""
+            return ""
 
         if tag_data['ListItemTag.initial_item']:
             tag_data['ListItemTag.initial_item'] = False
             return
 
-        return u"</li><li>"
+        return "</li><li>"
 
 
 class SizeTag(TagBase):
@@ -507,18 +507,18 @@
             self.size = None
 
         if self.size is None:
-            return u""
+            return ""
 
         self.size = self.validate_size(self.size)
 
-        return u'<span style="font-size:%spx">' % self.size
+        return '<span style="font-size:%spx">' % self.size
 
     def render_close(self, parser, node_index):
 
         if self.size is None:
-            return u""
+            return ""
 
-        return u'</span>'
+        return '</span>'
 
     def validate_size(self, size):
 
@@ -541,26 +541,26 @@
         self.color = ''.join([c for c in color if c in valid_chars])
 
         if not self.color:
-            return u""
+            return ""
 
-        return u'<span style="color:%s">' % self.color
+        return '<span style="color:%s">' % self.color
 
     def render_close(self, parser, node_index):
 
         if not self.color:
-            return u''
-        return u'</span>'
+            return ''
+        return '</span>'
 
 
 class CenterTag(TagBase):
 
     def render_open(self, parser, node_index, **kwargs):
 
-        return u'<div style="text-align:center">'
+        return '<div style="text-align:center">'
 
     def render_close(self, parser, node_index):
 
-        return u'</div>'
+        return '</div>'
 
 # http://effbot.org/zone/python-replace.htm
 
@@ -570,10 +570,10 @@
     def __init__(self, repl_dict):
 
         # string to string mapping; use a regular expression
-        keys = repl_dict.keys()
+        keys = list(repl_dict.keys())
         keys.sort()  # lexical order
         keys.reverse()  # use longest match first
-        pattern = u"|".join([re.escape(key) for key in keys])
+        pattern = "|".join([re.escape(key) for key in keys])
         self.pattern = re.compile(pattern)
         self.dict = repl_dict
 
@@ -673,16 +673,16 @@
 
 class PostMarkup(object):
 
-    standard_replace = MultiReplace({u'<': u'&lt;',
-                                     u'>': u'&gt;',
-                                     u'&': u'&amp;',
-                                     u'\n': u'<br/>'})
-
-    standard_replace_no_break = MultiReplace({u'<': u'&lt;',
-                                              u'>': u'&gt;',
-                                              u'&': u'&amp;', })
-
-    TOKEN_TAG, TOKEN_PTAG, TOKEN_TEXT = range(3)
+    standard_replace = MultiReplace({'<': '&lt;',
+                                     '>': '&gt;',
+                                     '&': '&amp;',
+                                     '\n': '<br/>'})
+
+    standard_replace_no_break = MultiReplace({'<': '&lt;',
+                                              '>': '&gt;',
+                                              '&': '&amp;', })
+
+    TOKEN_TAG, TOKEN_PTAG, TOKEN_TEXT = list(range(3))
 
     # I tried to use RE's. Really I did.
     @classmethod
@@ -702,7 +702,7 @@
 
         while True:
 
-            brace_pos = post.find(u'[', pos)
+            brace_pos = post.find('[', pos)
             if brace_pos == -1:
                 if pos < len(post):
                     yield PostMarkup.TOKEN_TEXT, post[pos:], pos, len(post)
@@ -713,8 +713,8 @@
             pos = brace_pos
             end_pos = pos + 1
 
-            open_tag_pos = post.find(u'[', end_pos)
-            end_pos = find_first(post, end_pos, u']=')
+            open_tag_pos = post.find('[', end_pos)
+            end_pos = find_first(post, end_pos, ']=')
             if end_pos == -1:
                 yield PostMarkup.TOKEN_TEXT, post[pos:], pos, len(post)
                 return
@@ -736,20 +736,20 @@
                     while post[end_pos] == ' ':
                         end_pos += 1
                     if post[end_pos] != '"':
-                        end_pos = post.find(u']', end_pos + 1)
+                        end_pos = post.find(']', end_pos + 1)
                         if end_pos == -1:
                             return
                         yield PostMarkup.TOKEN_TAG, post[pos:end_pos + 1], pos, end_pos + 1
                     else:
-                        end_pos = find_first(post, end_pos, u'"]')
+                        end_pos = find_first(post, end_pos, '"]')
 
                         if end_pos == -1:
                             return
                         if post[end_pos] == '"':
-                            end_pos = post.find(u'"', end_pos + 1)
+                            end_pos = post.find('"', end_pos + 1)
                             if end_pos == -1:
                                 return
-                            end_pos = post.find(u']', end_pos + 1)
+                            end_pos = post.find(']', end_pos + 1)
                             if end_pos == -1:
                                 return
                             yield PostMarkup.TOKEN_PTAG, post[pos:end_pos + 1], pos, end_pos + 1
@@ -763,7 +763,7 @@
         """Surrounds urls with url bbcode tags."""
 
         def repl(match):
-            return u'[url]%s[/url]' % match.group(0)
+            return '[url]%s[/url]' % match.group(0)
 
         text_tokens = []
         for tag_type, tag_token, start_pos, end_pos in self.tokenize(postmarkup):
@@ -773,7 +773,7 @@
             else:
                 text_tokens.append(tag_token)
 
-        return u"".join(text_tokens)
+        return "".join(text_tokens)
 
     def __init__(self, tag_factory=None):
 
@@ -784,10 +784,10 @@
 
         add_tag = self.tag_factory.add_tag
 
-        add_tag(SimpleTag, u'b', u'strong')
-        add_tag(SimpleTag, u'i', u'em')
-        add_tag(SimpleTag, u'u', u'u')
-        add_tag(SimpleTag, u's', u's')
+        add_tag(SimpleTag, 'b', 'strong')
+        add_tag(SimpleTag, 'i', 'em')
+        add_tag(SimpleTag, 'u', 'u')
+        add_tag(SimpleTag, 's', 's')
 
     def get_supported_tags(self):
         """Returns a list of the supported tags."""
@@ -808,8 +808,8 @@
 
         """
 
-        if not isinstance(post_markup, unicode):
-            post_markup = unicode(post_markup, encoding, 'replace')
+        if not isinstance(post_markup, str):
+            post_markup = str(post_markup, encoding, 'replace')
 
         if auto_urls:
             post_markup = self.tagify_urls(post_markup)
@@ -901,24 +901,24 @@
             elif tag_type == PostMarkup.TOKEN_TAG:
                 tag_token = tag_token[1:-1].lstrip()
                 if ' ' in tag_token:
-                    tag_name, tag_attribs = tag_token.split(u' ', 1)
+                    tag_name, tag_attribs = tag_token.split(' ', 1)
                     tag_attribs = tag_attribs.strip()
                 else:
                     if '=' in tag_token:
-                        tag_name, tag_attribs = tag_token.split(u'=', 1)
+                        tag_name, tag_attribs = tag_token.split('=', 1)
                         tag_attribs = tag_attribs.strip()
                     else:
                         tag_name = tag_token
-                        tag_attribs = u""
+                        tag_attribs = ""
             else:
                 tag_token = tag_token[1:-1].lstrip()
-                tag_name, tag_attribs = tag_token.split(u'=', 1)
+                tag_name, tag_attribs = tag_token.split('=', 1)
                 tag_attribs = tag_attribs.strip()[1:-1]
 
             tag_name = tag_name.strip().lower()
 
             end_tag = False
-            if tag_name.startswith(u'/'):
+            if tag_name.startswith('/'):
                 end_tag = True
                 tag_name = tag_name[1:]
 
@@ -996,7 +996,7 @@
                 text.append(node_text)
             parser.render_node_index += 1
 
-        return u"".join(text)
+        return "".join(text)
 
     __call__ = render_to_html
 
@@ -1009,7 +1009,7 @@
     post_markup = create(use_pygments=True)
 
     tests = []
-    print """<link rel="stylesheet" href="code.css" type="text/css" />\n"""
+    print("""<link rel="stylesheet" href="code.css" type="text/css" />\n""")
 
     tests.append(']')
     tests.append('[')
@@ -1020,8 +1020,8 @@
     tests.append('[link http://www.willmcgugan.com]My homepage[/link]')
     tests.append('[link]http://www.willmcgugan.com[/link]')
 
-    tests.append(u"[b]Hello AndrУЉ[/b]")
-    tests.append(u"[google]AndrУЉ[/google]")
+    tests.append("[b]Hello AndrУЉ[/b]")
+    tests.append("[google]AndrУЉ[/google]")
     tests.append('[s]Strike through[/s]')
     tests.append('[b]bold [i]bold and italic[/b] italic[/i]')
     tests.append('[google]Will McGugan[/google]')
@@ -1042,7 +1042,7 @@
         return self.__str__()
 [/code]""")
 
-    tests.append(u"[img]http://upload.wikimedia.org/wikipedia/commons";
+    tests.append("[img]http://upload.wikimedia.org/wikipedia/commons";
                  '/6/61/Triops_longicaudatus.jpg[/img]')
 
     tests.append('[list][*]Apples[*]Oranges[*]Pears[/list]')
@@ -1081,13 +1081,13 @@
     tests.append(
         'Nested urls, i.e. [url][url]www.becontrary.com[/url][/url], are condensed in to a single tag.')
 
-    tests.append(u'[google]ЩИЮВfvЮИУАsz[/google]')
-
-    tests.append(u'[size 30]Hello, World![/size]')
-
-    tests.append(u'[color red]This should be red[/color]')
-    tests.append(u'[color #0f0]This should be green[/color]')
-    tests.append(u"[center]This should be in the center!")
+    tests.append('[google]ЩИЮВfvЮИУАsz[/google]')
+
+    tests.append('[size 30]Hello, World![/size]')
+
+    tests.append('[color red]This should be red[/color]')
+    tests.append('[color #0f0]This should be green[/color]')
+    tests.append("[center]This should be in the center!")
 
     tests.append(
         'Nested urls, i.e. [url][url]www.becontrary.com[/url][/url], are condensed in to a single tag.')
@@ -1125,17 +1125,17 @@
     # tests=["""[b]b[i]i[/b][/i]"""]
 
     for test in tests:
-        print u"<pre>%s</pre>" % str(test.encode('ascii', 'xmlcharrefreplace'))
-        print u"<p>%s</p>" % str(post_markup(test).encode('ascii', 'xmlcharrefreplace'))
-        print u"<hr/>"
-        print
-
-    print repr(post_markup('[url=<script>Attack</script>]Attack[/url]'))
-
-    print repr(post_markup('http://www.google.com/search?as_q=bbcode&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA'))
+        print("<pre>%s</pre>" % str(test.encode('ascii', 'xmlcharrefreplace')))
+        print("<p>%s</p>" % str(post_markup(test).encode('ascii', 'xmlcharrefreplace')))
+        print("<hr/>")
+        print()
+
+    print(repr(post_markup('[url=<script>Attack</script>]Attack[/url]')))
+
+    print(repr(post_markup('http://www.google.com/search?as_q=bbcode&btnG=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA')))
 
     p = create(use_pygments=False)
-    print(p('[code]foo\nbar[/code]'))
+    print((p('[code]foo\nbar[/code]')))
 
     # print render_bbcode("[b]For the lazy, use the http://www.willmcgugan.com
     # render_bbcode function.[/b]")

=== modified file 'pybb/migrations/0001_initial.py'
--- pybb/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ pybb/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 from django.conf import settings

=== modified file 'pybb/migrations/0002_auto_20161001_2046.py'
--- pybb/migrations/0002_auto_20161001_2046.py	2016-10-08 09:30:34 +0000
+++ pybb/migrations/0002_auto_20161001_2046.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'pybb/migrations/0003_remove_post_user_ip.py'
--- pybb/migrations/0003_remove_post_user_ip.py	2018-10-03 09:01:09 +0000
+++ pybb/migrations/0003_remove_post_user_ip.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-10-02 19:31
-from __future__ import unicode_literals
+
 
 from django.db import migrations
 

=== modified file 'pybb/migrations/0004_auto_20181209_1334.py'
--- pybb/migrations/0004_auto_20181209_1334.py	2018-12-10 16:37:12 +0000
+++ pybb/migrations/0004_auto_20181209_1334.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-12-09 13:34
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 import django.db.models.deletion

=== modified file 'pybb/migrations/0005_auto_20181221_1047.py'
--- pybb/migrations/0005_auto_20181221_1047.py	2018-12-21 09:50:32 +0000
+++ pybb/migrations/0005_auto_20181221_1047.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-12-21 10:47
-from __future__ import unicode_literals
+
 
 from django.db import migrations
 

=== modified file 'pybb/models.py'
--- pybb/models.py	2019-03-24 08:28:15 +0000
+++ pybb/models.py	2019-06-09 11:20:50 +0000
@@ -61,7 +61,7 @@
         # See also settings.INTERNAL_PERM
         permissions = (("can_access_internal", "Can access Internal Forums"),)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def forum_count(self):
@@ -100,7 +100,7 @@
         verbose_name = _('Forum')
         verbose_name_plural = _('Forums')
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def topic_count(self):
@@ -154,7 +154,7 @@
         verbose_name = _('Topic')
         verbose_name_plural = _('Topics')
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     @property
@@ -215,7 +215,7 @@
         if self.markup == 'bbcode':
             self.body_html = mypostmarkup.markup(self.body, auto_urls=False)
         elif self.markup == 'markdown':
-            self.body_html = unicode(do_wl_markdown(
+            self.body_html = str(do_wl_markdown(
                 self.body, 'bleachit'))
         else:
             raise Exception('Invalid markup property: %s' % self.markup)
@@ -308,7 +308,7 @@
         tail = len(self.body) > LIMIT and '...' or ''
         return self.body[:LIMIT] + tail
 
-    __unicode__ = summary
+    __str__ = summary
 
     def save(self, *args, **kwargs):
         if self.created is None:
@@ -380,8 +380,8 @@
             self.time = datetime.now()
         super(Read, self).save(*args, **kwargs)
 
-    def __unicode__(self):
-        return u'T[%d], U[%d]: %s' % (self.topic.id, self.user.id, unicode(self.time))
+    def __str__(self):
+        return 'T[%d], U[%d]: %s' % (self.topic.id, self.user.id, str(self.time))
 
 
 class Attachment(models.Model):
@@ -401,7 +401,7 @@
                 str(self.id) + settings.SECRET_KEY).hexdigest()
         super(Attachment, self).save(*args, **kwargs)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def get_absolute_url(self):

=== modified file 'pybb/orm.py'
--- pybb/orm.py	2016-12-13 18:28:51 +0000
+++ pybb/orm.py	2019-06-09 11:20:50 +0000
@@ -6,12 +6,12 @@
     rel_field = rel_qs.model._meta.get_field(rel_field_name)
     cache_field_name = '%s_cache' % rel_qs.model.__name__.lower()
 
-    rel_objects = rel_qs.filter(**{'%s__in' % rel_field.name: obj_map.keys()})
+    rel_objects = rel_qs.filter(**{'%s__in' % rel_field.name: list(obj_map.keys())})
 
     temp_map = {}
     for rel_obj in rel_objects:
         pk = getattr(rel_obj, rel_field.attname)
         temp_map.setdefault(pk, []).append(rel_obj)
 
-    for pk, rel_list in temp_map.iteritems():
+    for pk, rel_list in temp_map.items():
         setattr(obj_map[pk], cache_field_name, rel_list)

=== modified file 'pybb/templates/pybb/last_posts.html'
--- pybb/templates/pybb/last_posts.html	2019-03-16 20:10:31 +0000
+++ pybb/templates/pybb/last_posts.html	2019-06-09 11:20:50 +0000
@@ -12,7 +12,7 @@
 				<li>
 					{{ post.topic.forum.name }}<br />
 					<a href="{{ post.get_absolute_url }}" title="{{ post.topic.name }}">{{ post.topic.name|truncatechars:30 }}</a><br />
-					by {{ post.user|user_link }} {{ post.created|minutes }} ago
+					by {{ post.user|user_link }} {{ post.created|elapsed_time }} ago
 				</li>
 			{% endfor %}
 			<li class="small">

=== modified file 'pybb/templatetags/pybb_extras.py'
--- pybb/templatetags/pybb_extras.py	2019-03-23 09:00:44 +0000
+++ pybb/templatetags/pybb_extras.py	2019-06-09 11:20:50 +0000
@@ -7,7 +7,7 @@
 from django import template
 from django.utils.safestring import mark_safe
 from django.template.defaultfilters import stringfilter
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_text
 from django.utils.html import escape
 
 from pybb.models import Post, Forum, Topic, Read
@@ -42,12 +42,12 @@
 
 
 @register.simple_tag
-def pybb_link(object, anchor=u''):
+def pybb_link(object, anchor=''):
     """Return A tag with link to object."""
 
     url = hasattr(
         object, 'get_absolute_url') and object.get_absolute_url() or None
-    anchor = anchor or smart_unicode(object)
+    anchor = anchor or smart_text(object)
     return mark_safe('<a href="%s">%s</a>' % (url, escape(anchor)))
 
 

=== modified file 'pybb/util.py'
--- pybb/util.py	2018-12-21 11:14:06 +0000
+++ pybb/util.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 from django.http import HttpResponse
 from django.utils.functional import Promise
 from django.utils.translation import check_for_language
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
 from django import forms
 from django.core.paginator import Paginator, EmptyPage, InvalidPage
 from django.conf import settings
@@ -59,7 +59,7 @@
         if request.method == 'POST':
             try:
                 response = func(request, *args, **kwargs)
-            except Exception, ex:
+            except Exception as ex:
                 response = {'error': traceback.format_exc()}
         else:
             response = {'error': {'type': 403,
@@ -76,7 +76,7 @@
 
     def default(self, o):
         if isinstance(o, Promise):
-            return force_unicode(o)
+            return force_text(o)
         else:
             return super(LazyJSONEncoder, self).default(o)
 
@@ -144,7 +144,7 @@
         # Apply the new content
         found_string.parent.contents = new_content
 
-    return unicode(soup)
+    return str(soup)
 
 
 def quote_text(text, user, markup):

=== modified file 'pybb/views.py'
--- pybb/views.py	2019-05-27 15:46:36 +0000
+++ pybb/views.py	2019-06-09 11:20:50 +0000
@@ -365,7 +365,7 @@
     content = request.POST.get('content')
     markup = request.POST.get('markup')
 
-    if not markup in dict(MARKUP_CHOICES).keys():
+    if not markup in list(dict(MARKUP_CHOICES).keys()):
         return {'error': 'Invalid markup'}
 
     if not content:
@@ -374,7 +374,7 @@
     if markup == 'bbcode':
         html = mypostmarkup.markup(content, auto_urls=False)
     elif markup == 'markdown':
-        html = unicode(do_wl_markdown(content, 'bleachit'))
+        html = str(do_wl_markdown(content, 'bleachit'))
 
     html = urlize(html)
     return {'content': html}

=== added file 'python3.txt'
--- python3.txt	1970-01-01 00:00:00 +0000
+++ python3.txt	2019-06-09 11:20:50 +0000
@@ -0,0 +1,104 @@
+Anmerkungen zum update auf python3:
+
+Der code für die implementierung vom gravatar-service ist ungetestet, da es nie
+implementiert wurde.
+
+virtualenvironment
+------------------
+
+Installiere die richtige python Version (hier python3.6).
+Erstellen des virtualenvironments:
+    
+    $:> virtualenv --python=python3.6 wlwebsite
+
+Getestet
+========
+
+Wiki
+----
+- editieren, Vorschau, speichern
+- upload von Bildern
+- wiki-syntax
+- History: Diff anzeigen, Artikel wieder herstellen (Revert)
+- Backlinks
+- Artikel beobachten
+- Atom feed
+
+Registrierung
+-------------
+- Registrierung, Anmeldung
+- Passwortänderung
+- Passwort vergessen
+- Logout
+
+Maps
+----
+- Upload maps with comment
+- Edit uploader comment, also with polish characters
+- Rate a map
+- Make a threadedcomment on a map
+- Delete map
+
+WlHelp (Encyclopedia)
+---------------------
+- Run ./manage.py update_help
+- Run ./manage.py update_help_pdf
+- views
+
+Screenshots
+-----------
+- upload a new screenshot
+- delete screenshot
+- delete category
+
+Search
+------
+- update index
+- searching
+
+News
+----
+- create new News
+- public in future (not show)
+- edit News
+- deletion
+- commenting
+
+Polls
+-----
+- create one
+- edit
+- deletion
+
+Webchat
+-------
+- connect
+
+Documentation
+-------------
+- run ./manage.py create_docs
+- views
+
+wlprofile
+---------
+- editing (Website/signature)
+
+pybb
+----
+- create topic
+- create post
+- post with markdown/bbcode
+- quoting a post
+- edit own post
+- stick/unstick topic
+- close/open topic
+- subscribe to topic (emailing works, also then)
+- edit foreign posts by forum mod
+- delete post by forum mod
+- delete post by posts author
+
+
+Others
+------
+- changelog page
+- developers page

=== modified file 'threadedcomments/admin.py'
--- threadedcomments/admin.py	2018-10-04 16:00:34 +0000
+++ threadedcomments/admin.py	2019-06-09 11:20:50 +0000
@@ -12,7 +12,7 @@
                                 'date_modified', 'date_approved', 'is_approved')}),
     )
     list_display = ('user', 'date_submitted', 'content_type',
-                    'get_content_object', 'parent', '__unicode__')
+                    'get_content_object', 'parent', '__str__')
     list_filter = ('date_submitted',)
     date_hierarchy = 'date_submitted'
     search_fields = ('comment', 'user__username')

=== modified file 'threadedcomments/migrations/0001_initial.py'
--- threadedcomments/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ threadedcomments/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 import datetime

=== modified file 'threadedcomments/migrations/0002_auto_20181003_1238.py'
--- threadedcomments/migrations/0002_auto_20181003_1238.py	2018-10-03 10:53:41 +0000
+++ threadedcomments/migrations/0002_auto_20181003_1238.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-10-03 12:38
-from __future__ import unicode_literals
+
 
 from django.db import migrations
 

=== modified file 'threadedcomments/models.py'
--- threadedcomments/models.py	2018-10-04 16:00:34 +0000
+++ threadedcomments/models.py	2019-06-09 11:20:50 +0000
@@ -6,7 +6,7 @@
 from django.db.models import Q
 from django.utils.translation import ugettext_lazy as _
 from django.conf import settings
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
 
 DEFAULT_MAX_COMMENT_LENGTH = getattr(
     settings, 'DEFAULT_MAX_COMMENT_LENGTH', 1000)
@@ -178,7 +178,7 @@
     objects = ThreadedCommentManager()
     public = PublicThreadedCommentManager()
 
-    def __unicode__(self):
+    def __str__(self):
         if len(self.comment) > 50:
             return self.comment[:50] + '...'
         return self.comment[:50]

=== modified file 'threadedcomments/templatetags/gravatar.py'
--- threadedcomments/templatetags/gravatar.py	2018-04-03 05:18:03 +0000
+++ threadedcomments/templatetags/gravatar.py	2019-06-09 11:20:50 +0000
@@ -1,16 +1,16 @@
 from django import template
 from django.conf import settings
 from django.template.defaultfilters import stringfilter
-from django.utils.encoding import smart_str
+from django.utils.encoding import smart_bytes
 from django.utils.safestring import mark_safe
 from hashlib import md5 as md5_constructor
-import urllib
+import urllib.request, urllib.parse, urllib.error
 
 GRAVATAR_MAX_RATING = getattr(settings, 'GRAVATAR_MAX_RATING', 'R')
 GRAVATAR_DEFAULT_IMG = getattr(settings, 'GRAVATAR_DEFAULT_IMG', 'img:blank')
 GRAVATAR_SIZE = getattr(settings, 'GRAVATAR_SIZE', 80)
 
-GRAVATAR_URL = u'http://www.gravatar.com/avatar.php?gravatar_id=%(hash)s&rating=%(rating)s&size=%(size)s&default=%(default)s'
+GRAVATAR_URL = 'http://www.gravatar.com/avatar.php?gravatar_id=%(hash)s&rating=%(rating)s&size=%(size)s&default=%(default)s'
 
 
 def get_gravatar_url(parser, token):
@@ -34,12 +34,12 @@
     words = token.contents.split()
     tagname = words.pop(0)
     if len(words) < 2:
-        raise template.TemplateSyntaxError, '%r tag: At least one argument should be provided.' % tagname
+        raise template.TemplateSyntaxError('%r tag: At least one argument should be provided.' % tagname)
     if words.pop(0) != 'for':
-        raise template.TemplateSyntaxError, '%r tag: Syntax is {% get_gravatar_url for myemailvar rating 'R" size 80 default img:blank as gravatar_url %}, where everything after myemailvar is optional."
+        raise template.TemplateSyntaxError('%r tag: Syntax is {% get_gravatar_url for myemailvar rating 'R" size 80 default img:blank as gravatar_url %}, where everything after myemailvar is optional.")
     email = words.pop(0)
     if len(words) % 2 != 0:
-        raise template.TemplateSyntaxError, '%r tag: Imbalanced number of arguments.' % tagname
+        raise template.TemplateSyntaxError('%r tag: Imbalanced number of arguments.' % tagname)
     args = {
         'email': email,
         'rating': GRAVATAR_MAX_RATING,
@@ -49,8 +49,8 @@
     for name, value in zip(words[::2], words[1::2]):
         name = name.lower()
         if name not in ('rating', 'size', 'default', 'as'):
-            raise template.TemplateSyntaxError, '%r tag: Invalid argument %r.' % tagname, name
-        args[smart_str(name)] = value
+            raise template.TemplateSyntaxError('%r tag: Invalid argument %r.' % tagname).with_traceback(name)
+        args[smart_bytes(name)] = value
     return GravatarUrlNode(**args)
 
 
@@ -93,7 +93,7 @@
             'hash': md5_constructor(email).hexdigest(),
             'rating': rating,
             'size': size,
-            'default': urllib.quote_plus(default),
+            'default': urllib.parse.quote_plus(default),
         }
         url = GRAVATAR_URL % gravatargs
         if 'as' in self.other_kwargs:
@@ -112,7 +112,7 @@
         'hash': hashed_email,
         'rating': GRAVATAR_MAX_RATING,
         'size': GRAVATAR_SIZE,
-        'default': urllib.quote_plus(GRAVATAR_DEFAULT_IMG),
+        'default': urllib.parse.quote_plus(GRAVATAR_DEFAULT_IMG),
     })
 gravatar = stringfilter(gravatar)
 

=== modified file 'threadedcomments/templatetags/threadedcommentstags.py'
--- threadedcomments/templatetags/threadedcommentstags.py	2018-10-04 06:15:32 +0000
+++ threadedcomments/templatetags/threadedcommentstags.py	2019-06-09 11:20:50 +0000
@@ -2,7 +2,7 @@
 from django import template
 from django.contrib.contenttypes.models import ContentType
 from django.urls import reverse
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
 from django.utils.safestring import mark_safe
 from threadedcomments.models import ThreadedComment
 from threadedcomments.forms import ThreadedCommentForm
@@ -28,7 +28,7 @@
     kwargs = get_contenttype_kwargs(content_object)
     if parent:
         if not isinstance(parent, ThreadedComment):
-            raise template.TemplateSyntaxError, 'get_comment_url requires its parent object to be of type ThreadedComment'
+            raise template.TemplateSyntaxError('get_comment_url requires its parent object to be of type ThreadedComment')
         kwargs.update({'parent_id': getattr(
             parent, 'pk', getattr(parent, 'id'))})
         return reverse('tc_comment_parent', kwargs=kwargs)
@@ -48,7 +48,7 @@
     kwargs.update({'ajax': ajax_type})
     if parent:
         if not isinstance(parent, ThreadedComment):
-            raise template.TemplateSyntaxError, 'get_comment_url_ajax requires its parent object to be of type ThreadedComment'
+            raise template.TemplateSyntaxError('get_comment_url_ajax requires its parent object to be of type ThreadedComment')
         kwargs.update({'parent_id': getattr(
             parent, 'pk', getattr(parent, 'id'))})
         return reverse('tc_comment_parent_ajax', kwargs=kwargs)
@@ -63,7 +63,7 @@
     try:
         return get_comment_url_ajax(content_object, parent, ajax_type='json')
     except template.TemplateSyntaxError:
-        raise template.TemplateSyntaxError, 'get_comment_url_json requires its parent object to be of type ThreadedComment'
+        raise template.TemplateSyntaxError('get_comment_url_json requires its parent object to be of type ThreadedComment')
     return ''
 
 
@@ -74,7 +74,7 @@
     try:
         return get_comment_url_ajax(content_object, parent, ajax_type='xml')
     except template.TemplateSyntaxError:
-        raise template.TemplateSyntaxError, 'get_comment_url_xml requires its parent object to be of type ThreadedComment'
+        raise template.TemplateSyntaxError('get_comment_url_xml requires its parent object to be of type ThreadedComment')
     return ''
 
 
@@ -92,13 +92,13 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, '%r tag must be of format {%% %r COMMENT %%} or of format {%% %r COMMENT as CONTEXT_VARIABLE %%}' % (token.contents.split()[0], token.contents.split()[0], token.contents.split()[0])
+        raise template.TemplateSyntaxError('%r tag must be of format {%% %r COMMENT %%} or of format {%% %r COMMENT as CONTEXT_VARIABLE %%}' % (token.contents.split()[0], token.contents.split()[0], token.contents.split()[0]))
     if len(split) == 2:
         return AutoTransformMarkupNode(split[1])
     elif len(split) == 4:
         return AutoTransformMarkupNode(split[1], context_name=split[3])
     else:
-        raise template.TemplateSyntaxError, 'Invalid number of arguments for tag %r' % split[0]
+        raise template.TemplateSyntaxError('Invalid number of arguments for tag %r' % split[0])
 
 
 class AutoTransformMarkupNode(template.Node):
@@ -167,9 +167,9 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if split[1] != 'for' or split[3] != 'as':
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     return ThreadedCommentCountNode(split[2], split[4])
 
 
@@ -202,11 +202,11 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if split[1] != 'as':
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if len(split) != 3:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     
     return ThreadedCommentFormNode(split[2])
 
@@ -230,11 +230,11 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if len(split) != 4:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if split[2] != 'as':
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
 
     return LatestCommentsNode(split[1], split[3])
 
@@ -259,9 +259,9 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if len(split) != 5:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
 
     return UserCommentsNode(split[2], split[4])
 
@@ -285,9 +285,9 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if len(split) != 5:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
 
     return UserCommentCountNode(split[2], split[4])
 

=== modified file 'threadedcomments/utils.py'
--- threadedcomments/utils.py	2016-12-13 18:28:51 +0000
+++ threadedcomments/utils.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 from django.core.serializers import serialize
 from django.http import HttpResponse
 from django.utils.functional import Promise
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
 import json as simplejson
 
 
@@ -9,7 +9,7 @@
 
     def default(self, obj):
         if isinstance(obj, Promise):
-            return force_unicode(obj)
+            return force_text(obj)
         return obj
 
 

=== modified file 'threadedcomments/views.py'
--- threadedcomments/views.py	2019-03-31 11:08:21 +0000
+++ threadedcomments/views.py	2019-06-09 11:20:50 +0000
@@ -121,7 +121,7 @@
 </errorlist>
         """
         response_str = Template(template_str).render(
-            Context({'errors': zip(form.errors.values(), form.errors.keys())}))
+            Context({'errors': list(zip(list(form.errors.values()), list(form.errors.keys())))}))
         return XMLResponse(response_str, is_iterable=False)
     else:
         return _preview(request, context_processors, extra_context, form_class=form_class)

=== modified file 'widelandslib/make_flow_diagram.py'
--- widelandslib/make_flow_diagram.py	2019-03-31 11:08:21 +0000
+++ widelandslib/make_flow_diagram.py	2019-06-09 11:20:50 +0000
@@ -68,7 +68,7 @@
 def add_building(g, b, limit_inputs=None, limit_outputs=None, limit_buildings=None, link_workers=True, limit_recruits=None):
     # Add the nice node
     workers = ''
-    if isinstance(b, (ProductionSite,)):
+    if isinstance(b, ProductionSite):
         workers = r"""<table border="0px" cellspacing="0">"""
         for worker in b.workers:
             wo = b.tribe.workers[worker]
@@ -86,7 +86,7 @@
                 g.add_edge(Edge(b.name, wo.name, color='darkgreen'))
         workers += r"""</table>"""
 
-    if isinstance(b, (MilitarySite,)):
+    if isinstance(b, MilitarySite):
         workers = r"""<table border="0px" cellspacing="0">"""
         workers += (r"""<tr><td border="0px">Keeps %s Soldiers</td></tr>"""
                     r"""<tr><td border="0px">Conquers %s fields</td></tr>"""
@@ -94,7 +94,7 @@
         workers += r"""</table>"""
 
     costs = r"""<tr><td colspan="2"><table border="0px" cellspacing="0">"""
-    for ware, count in b.buildcost.items():
+    for ware, count in list(b.buildcost.items()):
         w = b.tribe.wares[ware]
         costs += ('<tr><td border="0px">%s x </td><td border="0px"><img src="%s"/></td><td border="0px">%s</td></tr>' %
                   (count, w.image, w.descname))
@@ -133,7 +133,7 @@
     else:
         g.add_node(n)
 
-    if isinstance(b, (ProductionSite,)):
+    if isinstance(b, ProductionSite):
         # for worker,c in b.workers:
         #     g.add_edge(Edge(worker, name, color="orange"))
 
@@ -181,24 +181,23 @@
 def make_graph(tribe_name):
     global tdir
     tdir = mkdtemp(prefix='widelands-help')
-
     json_directory = path.normpath(settings.MEDIA_ROOT + '/map_object_info')
-    tribeinfo_file = open(path.normpath(
-        json_directory + '/tribe_' + tribe_name + '.json'), 'r')
-    tribeinfo = json.load(tribeinfo_file)
+    with open(path.normpath(
+            json_directory + '/tribe_' + tribe_name + '.json'), 'r') as tribeinfo_file:
+        tribeinfo = json.load(tribeinfo_file)
 
     t = Tribe(tribeinfo, json_directory)
 
     g = CleanedDot(concentrate='false', style='filled', bgcolor='white',
                    overlap='false', splines='true', rankdir='LR')
 
-    for name, w in t.wares.items():
+    for name, w in list(t.wares.items()):
         add_ware(g, w)
     #
     # for name,w in t.workers.items():
     #     add_worker(g, w)
 
-    for name, b in t.buildings.items():
+    for name, b in list(t.buildings.items()):
         add_building(g, b, link_workers=False)
 
     g.write_pdf(path.join(tdir, '%s.pdf' % tribe_name))
@@ -211,7 +210,7 @@
 
 
 def make_building_graph(t, building_name):
-    if isinstance(t, basestring):
+    if isinstance(t, str):
         t = Tribe(t)
 
     b = t.buildings[building_name]
@@ -219,7 +218,7 @@
     g = CleanedDot(concentrate='false', bgcolor='transparent',
                    overlap='false', splines='true', rankdir='LR')
 
-    if not isinstance(b, (ProductionSite,)):
+    if not isinstance(b, ProductionSite):
         inputs, outputs = [], []
     else:
         # TODO: prepare for tribes having buildings with a ware as both input
@@ -254,7 +253,7 @@
 
 
 def make_worker_graph(t, worker_name):
-    if isinstance(t, basestring):
+    if isinstance(t, str):
         t = Tribe(t)
 
     w = t.workers[worker_name]
@@ -262,7 +261,7 @@
     g = CleanedDot(concentrate='false', bgcolor='transparent',
                    overlap='false', splines='true', rankdir='LR')
 
-    buildings = [bld for bld in t.buildings.values() if
+    buildings = [bld for bld in list(t.buildings.values()) if
                  isinstance(bld, ProductionSite) and
                  (w.name in bld.workers or w.name in bld.recruits)]
 
@@ -275,7 +274,7 @@
     sg = Subgraph('%s_enhancements' % w.name,
                   ordering='out', rankdir='TB', rank='same')
     # find exactly one level of enhancement
-    for other in t.workers.values():
+    for other in list(t.workers.values()):
         if other.becomes == w.name:
             add_worker(sg, other)
             g.add_edge(Edge(other.name, w.name, color='blue'))
@@ -294,15 +293,15 @@
 
 
 def make_ware_graph(t, ware_name):
-    if isinstance(t, basestring):
+    if isinstance(t, str):
         t = Tribe(t)
     w = t.wares[ware_name]
 
     g = CleanedDot(concentrate='false', bgcolor='transparent',
                    overlap='false', splines='true', rankdir='LR')
 
-    buildings = [bld for bld in t.buildings.values() if isinstance(
-        bld, (ProductionSite, )) and (w.name in bld.inputs or w.name in bld.outputs)]
+    buildings = [bld for bld in list(t.buildings.values()) if isinstance(
+        bld, ProductionSite) and (w.name in bld.inputs or w.name in bld.outputs)]
     [add_building(g, bld, limit_inputs=[w.name], limit_outputs=[w.name], limit_buildings=[
                   b.name for b in buildings], link_workers=False) for bld in buildings]
 
@@ -326,28 +325,28 @@
 def make_all_subgraphs(t):
     global tdir
     tdir = mkdtemp(prefix='widelands-help')
-    if isinstance(t, basestring):
+    if isinstance(t, str):
         t = Tribe(t)
-    print 'making all subgraphs for tribe', t.name, 'in', tdir
+    print('making all subgraphs for tribe', t.name, 'in', tdir)
 
-    print '  making wares'
+    print('  making wares')
 
     for w in t.wares:
-        print '    ' + w
+        print('    ' + w)
         make_ware_graph(t, w)
         process_dotfile(path.join(tdir, 'help/%s/wares/%s/' % (t.name, w)))
 
-    print '  making workers'
+    print('  making workers')
 
     for w in t.workers:
-        print '    ' + w
+        print('    ' + w)
         make_worker_graph(t, w)
         process_dotfile(path.join(tdir, 'help/%s/workers/%s/' % (t.name, w)))
 
-    print '  making buildings'
+    print('  making buildings')
 
     for b in t.buildings:
-        print '    ' + b
+        print('    ' + b)
         make_building_graph(t, b)
         process_dotfile(path.join(tdir, 'help/%s/buildings/%s/' % (t.name, b)))
 
@@ -359,5 +358,6 @@
     if b.enhanced_building:
         add_building()
 
+
 if __name__ == '__main__':
     make_all_subgraphs()

=== modified file 'widelandslib/test/test_conf.py'
--- widelandslib/test/test_conf.py	2016-12-13 18:28:51 +0000
+++ widelandslib/test/test_conf.py	2019-06-09 11:20:50 +0000
@@ -13,7 +13,7 @@
 sys.path.append('..')
 
 import unittest
-from cStringIO import StringIO
+from io import StringIO
 
 from conf import WidelandsConfigParser
 

=== modified file 'widelandslib/test/test_map.py'
--- widelandslib/test/test_map.py	2016-12-13 18:28:51 +0000
+++ widelandslib/test/test_map.py	2019-06-09 11:20:50 +0000
@@ -8,7 +8,7 @@
 from numpy import *
 import unittest
 import base64
-from cStringIO import StringIO
+from io import StringIO
 from itertools import *
 
 from map import *
@@ -186,12 +186,12 @@
     # }}}
 
     def test_R(self):
-        r = [i.name == j for i, j in izip(
+        r = [i.name == j for i, j in zip(
             self.m.ter_r.flat, self.ter_r_names.flat)]
         self.assertTrue(all(r))
 
     def test_D(self):
-        d = [i.name == j for i, j in izip(
+        d = [i.name == j for i, j in zip(
             self.m.ter_d.flat, self.ter_d_names.flat)]
         self.assertTrue(all(d))
 

=== modified file 'widelandslib/tribe.py'
--- widelandslib/tribe.py	2019-03-31 11:08:21 +0000
+++ widelandslib/tribe.py	2019-06-09 11:20:50 +0000
@@ -55,7 +55,7 @@
     def base_building(self):
         if not self.enhanced_building:
             return None
-        bases = [b for b in self.tribe.buildings.values()
+        bases = [b for b in list(self.tribe.buildings.values())
                  if b.enhancement == self.name]
         if len(bases) == 0 and self.enhanced_building:
             raise Exception('Building %s has no bases in tribe %s' %
@@ -152,30 +152,29 @@
     def __init__(self, tribeinfo, json_directory):
         self.name = tribeinfo['name']
 
-        wares_file = open(p.normpath(json_directory + '/' +
-                                     self.name + '_wares.json'), 'r')
-        waresinfo = json.load(wares_file)
+        with open(p.normpath(json_directory + '/' +
+                             self.name + '_wares.json'), 'r') as wares_file:
+            waresinfo = json.load(wares_file)
         self.wares = dict()
         for ware in waresinfo['wares']:
-            descname = ware['descname'].encode('ascii', 'xmlcharrefreplace')
+            descname = ware['descname']
             self.wares[ware['name']] = Ware(self, ware['name'], descname, ware)
 
-        workers_file = open(p.normpath(
-            json_directory + '/' + self.name + '_workers.json'), 'r')
-        workersinfo = json.load(workers_file)
+        with open(p.normpath(
+                json_directory + '/' + self.name + '_workers.json'), 'r') as workers_file:
+            workersinfo = json.load(workers_file)
         self.workers = dict()
         for worker in workersinfo['workers']:
-            descname = worker['descname'].encode('ascii', 'xmlcharrefreplace')
+            descname = worker['descname']
             self.workers[worker['name']] = Worker(
                 self, worker['name'], descname, worker)
 
-        buildings_file = open(p.normpath(
-            json_directory + '/' + self.name + '_buildings.json'), 'r')
-        buildingsinfo = json.load(buildings_file)
+        with open(p.normpath(
+                json_directory + '/' + self.name + '_buildings.json'), 'r') as buildings_file:
+            buildingsinfo = json.load(buildings_file)
         self.buildings = dict()
         for building in buildingsinfo['buildings']:
-            descname = building['descname'].encode(
-                'ascii', 'xmlcharrefreplace')
+            descname = building['descname']
             if building['type'] == 'productionsite':
                 self.buildings[building['name']] = ProductionSite(
                     self, building['name'], descname, building)

=== modified file 'wiki/diff_match_patch.py'
--- wiki/diff_match_patch.py	2019-03-31 11:08:21 +0000
+++ wiki/diff_match_patch.py	2019-06-09 11:20:50 +0000
@@ -1,11 +1,11 @@
-#!/usr/bin/python2.4
-
-# Taken from google because they do not provide a setup.py file. Thanks anyway
-
-"""Diff Match and Patch.
-
-Copyright 2006 Google Inc.
-http://code.google.com/p/google-diff-match-patch/
+#!/usr/bin/python3
+
+# Taken from https://github.com/google/diff-match-patch/blob/master/python3/diff_match_patch.py
+# Applied class attribute in diff_prettyHtml() to get variable coloring
+
+"""Diff Match and Patch
+Copyright 2018 The diff-match-patch Authors.
+https://github.com/google/diff-match-patch
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-
 """
 
 """Functions for diff, match and patch.
@@ -29,1901 +28,1883 @@
 
 __author__ = 'fraser@xxxxxxxxxx (Neil Fraser)'
 
-import math
+import re
+import sys
 import time
-import urllib
-import re
+import urllib.parse
 
 
 class diff_match_patch:
-    """Class containing the diff, match and patch methods.
-
-    Also contains the behaviour settings.
-
-    """
-
-    def __init__(self):
-        """Inits a diff_match_patch object with default settings.
-
-        Redefine these in your program to override the defaults.
-
-        """
-
-        # Number of seconds to map a diff before giving up (0 for infinity).
-        self.Diff_Timeout = 1.0
-        # Cost of an empty edit operation in terms of edit characters.
-        self.Diff_EditCost = 4
-        # The size beyond which the double-ended diff activates.
-        # Double-ending is twice as fast, but less accurate.
-        self.Diff_DualThreshold = 32
-        # At what point is no match declared (0.0 = perfection, 1.0 = very
-        # loose).
-        self.Match_Threshold = 0.5
-        # How far to search for a match (0 = exact location, 1000+ = broad match).
-        # A match this many characters away from the expected location will add
-        # 1.0 to the score (0.0 is a perfect match).
-        self.Match_Distance = 1000
-        # When deleting a large block of text (over ~64 characters), how close does
-        # the contents have to match the expected contents. (0.0 = perfection,
-        # 1.0 = very loose).  Note that Match_Threshold controls how closely the
-        # end points of a delete need to match.
-        self.Patch_DeleteThreshold = 0.5
-        # Chunk size for context length.
-        self.Patch_Margin = 4
-
-        # How many bits in a number?
-        # Python has no maximum, thus to disable patch splitting set to 0.
-        # However to avoid long patches in certain pathological cases, use 32.
-        # Multiple short patches (using native ints) are much faster than long
-        # ones.
-        self.Match_MaxBits = 32
-
-    #  DIFF FUNCTIONS
-
-    # The data structure representing a diff is an array of tuples:
-    # [(DIFF_DELETE, "Hello"), (DIFF_INSERT, "Goodbye"), (DIFF_EQUAL, " world.")]
-    # which means: delete "Hello", add "Goodbye" and keep " world."
-    DIFF_DELETE = -1
-    DIFF_INSERT = 1
-    DIFF_EQUAL = 0
-
-    def diff_main(self, text1, text2, checklines=True):
-        """Find the differences between two texts.  Simplifies the problem by
-        stripping any common prefix or suffix off the texts before diffing.
-
-        Args:
-          text1: Old string to be diffed.
-          text2: New string to be diffed.
-          checklines: Optional speedup flag.  If present and false, then don't run
-            a line-level diff first to identify the changed areas.
-            Defaults to true, which does a faster, slightly less optimal diff.
-
-        Returns:
-          Array of changes.
-
-        """
-
-        # Check for equality (speedup)
-        if text1 == text2:
-            return [(self.DIFF_EQUAL, text1)]
-
-        # Trim off common prefix (speedup)
-        commonlength = self.diff_commonPrefix(text1, text2)
-        commonprefix = text1[:commonlength]
-        text1 = text1[commonlength:]
-        text2 = text2[commonlength:]
-
-        # Trim off common suffix (speedup)
-        commonlength = self.diff_commonSuffix(text1, text2)
-        if commonlength == 0:
-            commonsuffix = ''
-        else:
-            commonsuffix = text1[-commonlength:]
-            text1 = text1[:-commonlength]
-            text2 = text2[:-commonlength]
-
-        # Compute the diff on the middle block
-        diffs = self.diff_compute(text1, text2, checklines)
-
-        # Restore the prefix and suffix
-        if commonprefix:
-            diffs[:0] = [(self.DIFF_EQUAL, commonprefix)]
-        if commonsuffix:
-            diffs.append((self.DIFF_EQUAL, commonsuffix))
-        self.diff_cleanupMerge(diffs)
-        return diffs
-
-    def diff_compute(self, text1, text2, checklines):
-        """Find the differences between two texts.  Assumes that the texts do
-        not have any common prefix or suffix.
-
-        Args:
-          text1: Old string to be diffed.
-          text2: New string to be diffed.
-          checklines: Speedup flag.  If false, then don't run a line-level diff
-            first to identify the changed areas.
-            If true, then run a faster, slightly less optimal diff.
-
-        Returns:
-          Array of changes.
-
-        """
-        if not text1:
-            # Just add some text (speedup)
-            return [(self.DIFF_INSERT, text2)]
-
-        if not text2:
-            # Just delete some text (speedup)
-            return [(self.DIFF_DELETE, text1)]
-
-        if len(text1) > len(text2):
-            (longtext, shorttext) = (text1, text2)
-        else:
-            (shorttext, longtext) = (text1, text2)
-        i = longtext.find(shorttext)
-        if i != -1:
-            # Shorter text is inside the longer text (speedup)
-            diffs = [(self.DIFF_INSERT, longtext[:i]), (self.DIFF_EQUAL, shorttext),
-                     (self.DIFF_INSERT, longtext[i + len(shorttext):])]
-            # Swap insertions for deletions if diff is reversed.
-            if len(text1) > len(text2):
-                diffs[0] = (self.DIFF_DELETE, diffs[0][1])
-                diffs[2] = (self.DIFF_DELETE, diffs[2][1])
-            return diffs
-        longtext = shorttext = None  # Garbage collect.
-
-        # Check to see if the problem can be split in two.
-        hm = self.diff_halfMatch(text1, text2)
-        if hm:
-            # A half-match was found, sort out the return data.
-            (text1_a, text1_b, text2_a, text2_b, mid_common) = hm
-            # Send both pairs off for separate processing.
-            diffs_a = self.diff_main(text1_a, text2_a, checklines)
-            diffs_b = self.diff_main(text1_b, text2_b, checklines)
-            # Merge the results.
-            return diffs_a + [(self.DIFF_EQUAL, mid_common)] + diffs_b
-
-        # Perform a real diff.
-        if checklines and (len(text1) < 100 or len(text2) < 100):
-            checklines = False  # Too trivial for the overhead.
-        if checklines:
-            # Scan the text on a line-by-line basis first.
-            (text1, text2, linearray) = self.diff_linesToChars(text1, text2)
-
-        diffs = self.diff_map(text1, text2)
-        if not diffs:  # No acceptable result.
-            diffs = [(self.DIFF_DELETE, text1), (self.DIFF_INSERT, text2)]
-        if checklines:
-            # Convert the diff back to original text.
-            self.diff_charsToLines(diffs, linearray)
-            # Eliminate freak matches (e.g. blank lines)
-            self.diff_cleanupSemantic(diffs)
-
-            # Rediff any replacement blocks, this time character-by-character.
-            # Add a dummy entry at the end.
-            diffs.append((self.DIFF_EQUAL, ''))
-            pointer = 0
-            count_delete = 0
-            count_insert = 0
-            text_delete = ''
-            text_insert = ''
-            while pointer < len(diffs):
-                if diffs[pointer][0] == self.DIFF_INSERT:
-                    count_insert += 1
-                    text_insert += diffs[pointer][1]
-                elif diffs[pointer][0] == self.DIFF_DELETE:
-                    count_delete += 1
-                    text_delete += diffs[pointer][1]
-                elif diffs[pointer][0] == self.DIFF_EQUAL:
-                    # Upon reaching an equality, check for prior redundancies.
-                    if count_delete >= 1 and count_insert >= 1:
-                        # Delete the offending records and add the merged ones.
-                        a = self.diff_main(text_delete, text_insert, False)
-                        diffs[pointer - count_delete -
-                              count_insert: pointer] = a
-                        pointer = pointer - count_delete - \
-                            count_insert + len(a)
-                    count_insert = 0
-                    count_delete = 0
-                    text_delete = ''
-                    text_insert = ''
-
-                pointer += 1
-
-            diffs.pop()  # Remove the dummy entry at the end.
-        return diffs
-
-    def diff_linesToChars(self, text1, text2):
-        """Split two texts into an array of strings.  Reduce the texts to a
-        string of hashes where each Unicode character represents one line.
-
-        Args:
-          text1: First string.
-          text2: Second string.
-
-        Returns:
-          Three element tuple, containing the encoded text1, the encoded text2 and
-          the array of unique strings.  The zeroth element of the array of unique
-          strings is intentionally blank.
-
-        """
-        lineArray = []  # e.g. lineArray[4] == "Hello\n"
-        lineHash = {}   # e.g. lineHash["Hello\n"] == 4
-
-        # "\x00" is a valid character, but various debuggers don't like it.
-        # So we'll insert a junk entry to avoid generating a null character.
-        lineArray.append('')
-
-        def diff_linesToCharsMunge(text):
-            """Split a text into an array of strings.  Reduce the texts to a
-            string of hashes where each Unicode character represents one line.
-            Modifies linearray and linehash through being a closure.
-
-            Args:
-              text: String to encode.
-
-            Returns:
-              Encoded string.
-
-            """
-            chars = []
-            # Walk the text, pulling out a substring for each line.
-            # text.split('\n') would would temporarily double our memory footprint.
-            # Modifying text would create many large strings to garbage
-            # collect.
-            lineStart = 0
-            lineEnd = -1
-            while lineEnd < len(text) - 1:
-                lineEnd = text.find('\n', lineStart)
-                if lineEnd == -1:
-                    lineEnd = len(text) - 1
-                line = text[lineStart:lineEnd + 1]
-                lineStart = lineEnd + 1
-
-                if line in lineHash:
-                    chars.append(unichr(lineHash[line]))
-                else:
-                    lineArray.append(line)
-                    lineHash[line] = len(lineArray) - 1
-                    chars.append(unichr(len(lineArray) - 1))
-            return ''.join(chars)
-
-        chars1 = diff_linesToCharsMunge(text1)
-        chars2 = diff_linesToCharsMunge(text2)
-        return (chars1, chars2, lineArray)
-
-    def diff_charsToLines(self, diffs, lineArray):
-        """Rehydrate the text in a diff from a string of line hashes to real
-        lines of text.
-
-        Args:
-          diffs: Array of diff tuples.
-          lineArray: Array of unique strings.
-
-        """
-        for x in xrange(len(diffs)):
-            text = []
-            for char in diffs[x][1]:
-                text.append(lineArray[ord(char)])
-            diffs[x] = (diffs[x][0], ''.join(text))
-
-    def diff_map(self, text1, text2):
-        """Explore the intersection points between the two texts.
-
-        Args:
-          text1: Old string to be diffed.
-          text2: New string to be diffed.
-
-        Returns:
-          Array of diff tuples or None if no diff available.
-
-        """
-
-        # Unlike in most languages, Python counts time in seconds.
-        s_end = time.time() + self.Diff_Timeout  # Don't run for too long.
-        # Cache the text lengths to prevent multiple calls.
-        text1_length = len(text1)
-        text2_length = len(text2)
-        max_d = text1_length + text2_length - 1
-        doubleEnd = self.Diff_DualThreshold * 2 < max_d
-        v_map1 = []
-        v_map2 = []
-        v1 = {}
-        v2 = {}
-        v1[1] = 0
-        v2[1] = 0
-        footsteps = {}
-        done = False
-        # If the total number of characters is odd, then the front path will
-        # collide with the reverse path.
-        front = (text1_length + text2_length) % 2
-        for d in xrange(max_d):
-            # Bail out if timeout reached.
-            if self.Diff_Timeout > 0 and time.time() > s_end:
-                return None
-
-            # Walk the front path one step.
-            v_map1.append({})
-            for k in xrange(-d, d + 1, 2):
-                if k == -d or k != d and v1[k - 1] < v1[k + 1]:
-                    x = v1[k + 1]
-                else:
-                    x = v1[k - 1] + 1
-                y = x - k
-                if doubleEnd:
-                    footstep = (x, y)
-                    if front and footstep in footsteps:
-                        done = True
-                    if not front:
-                        footsteps[footstep] = d
-
-                while (not done and x < text1_length and y < text2_length and
-                       text1[x] == text2[y]):
-                    x += 1
-                    y += 1
-                    if doubleEnd:
-                        footstep = (x, y)
-                        if front and footstep in footsteps:
-                            done = True
-                        if not front:
-                            footsteps[footstep] = d
-
-                v1[k] = x
-                v_map1[d][(x, y)] = True
-                if x == text1_length and y == text2_length:
-                    # Reached the end in single-path mode.
-                    return self.diff_path1(v_map1, text1, text2)
-                elif done:
-                    # Front path ran over reverse path.
-                    v_map2 = v_map2[:footsteps[footstep] + 1]
-                    a = self.diff_path1(v_map1, text1[:x], text2[:y])
-                    b = self.diff_path2(v_map2, text1[x:], text2[y:])
-                    return a + b
-
-            if doubleEnd:
-                # Walk the reverse path one step.
-                v_map2.append({})
-                for k in xrange(-d, d + 1, 2):
-                    if k == -d or k != d and v2[k - 1] < v2[k + 1]:
-                        x = v2[k + 1]
-                    else:
-                        x = v2[k - 1] + 1
-                    y = x - k
-                    footstep = (text1_length - x, text2_length - y)
-                    if not front and footstep in footsteps:
-                        done = True
-                    if front:
-                        footsteps[footstep] = d
-                    while (not done and x < text1_length and y < text2_length and
-                           text1[-x - 1] == text2[-y - 1]):
-                        x += 1
-                        y += 1
-                        footstep = (text1_length - x, text2_length - y)
-                        if not front and footstep in footsteps:
-                            done = True
-                        if front:
-                            footsteps[footstep] = d
-
-                    v2[k] = x
-                    v_map2[d][(x, y)] = True
-                    if done:
-                        # Reverse path ran over front path.
-                        v_map1 = v_map1[:footsteps[footstep] + 1]
-                        a = self.diff_path1(v_map1, text1[:text1_length - x],
-                                            text2[:text2_length - y])
-                        b = self.diff_path2(v_map2, text1[text1_length - x:],
-                                            text2[text2_length - y:])
-                        return a + b
-
-        # Number of diffs equals number of characters, no commonality at all.
+  """Class containing the diff, match and patch methods.
+
+  Also contains the behaviour settings.
+  """
+
+  def __init__(self):
+    """Inits a diff_match_patch object with default settings.
+    Redefine these in your program to override the defaults.
+    """
+
+    # Number of seconds to map a diff before giving up (0 for infinity).
+    self.Diff_Timeout = 1.0
+    # Cost of an empty edit operation in terms of edit characters.
+    self.Diff_EditCost = 4
+    # At what point is no match declared (0.0 = perfection, 1.0 = very loose).
+    self.Match_Threshold = 0.5
+    # How far to search for a match (0 = exact location, 1000+ = broad match).
+    # A match this many characters away from the expected location will add
+    # 1.0 to the score (0.0 is a perfect match).
+    self.Match_Distance = 1000
+    # When deleting a large block of text (over ~64 characters), how close do
+    # the contents have to be to match the expected contents. (0.0 = perfection,
+    # 1.0 = very loose).  Note that Match_Threshold controls how closely the
+    # end points of a delete need to match.
+    self.Patch_DeleteThreshold = 0.5
+    # Chunk size for context length.
+    self.Patch_Margin = 4
+
+    # The number of bits in an int.
+    # Python has no maximum, thus to disable patch splitting set to 0.
+    # However to avoid long patches in certain pathological cases, use 32.
+    # Multiple short patches (using native ints) are much faster than long ones.
+    self.Match_MaxBits = 32
+
+  #  DIFF FUNCTIONS
+
+  # The data structure representing a diff is an array of tuples:
+  # [(DIFF_DELETE, "Hello"), (DIFF_INSERT, "Goodbye"), (DIFF_EQUAL, " world.")]
+  # which means: delete "Hello", add "Goodbye" and keep " world."
+  DIFF_DELETE = -1
+  DIFF_INSERT = 1
+  DIFF_EQUAL = 0
+
+  def diff_main(self, text1, text2, checklines=True, deadline=None):
+    """Find the differences between two texts.  Simplifies the problem by
+      stripping any common prefix or suffix off the texts before diffing.
+
+    Args:
+      text1: Old string to be diffed.
+      text2: New string to be diffed.
+      checklines: Optional speedup flag.  If present and false, then don't run
+        a line-level diff first to identify the changed areas.
+        Defaults to true, which does a faster, slightly less optimal diff.
+      deadline: Optional time when the diff should be complete by.  Used
+        internally for recursive calls.  Users should set DiffTimeout instead.
+
+    Returns:
+      Array of changes.
+    """
+    # Set a deadline by which time the diff must be complete.
+    if deadline == None:
+      # Unlike in most languages, Python counts time in seconds.
+      if self.Diff_Timeout <= 0:
+        deadline = sys.maxsize
+      else:
+        deadline = time.time() + self.Diff_Timeout
+
+    # Check for null inputs.
+    if text1 == None or text2 == None:
+      raise ValueError("Null inputs. (diff_main)")
+
+    # Check for equality (speedup).
+    if text1 == text2:
+      if text1:
+        return [(self.DIFF_EQUAL, text1)]
+      return []
+
+    # Trim off common prefix (speedup).
+    commonlength = self.diff_commonPrefix(text1, text2)
+    commonprefix = text1[:commonlength]
+    text1 = text1[commonlength:]
+    text2 = text2[commonlength:]
+
+    # Trim off common suffix (speedup).
+    commonlength = self.diff_commonSuffix(text1, text2)
+    if commonlength == 0:
+      commonsuffix = ''
+    else:
+      commonsuffix = text1[-commonlength:]
+      text1 = text1[:-commonlength]
+      text2 = text2[:-commonlength]
+
+    # Compute the diff on the middle block.
+    diffs = self.diff_compute(text1, text2, checklines, deadline)
+
+    # Restore the prefix and suffix.
+    if commonprefix:
+      diffs[:0] = [(self.DIFF_EQUAL, commonprefix)]
+    if commonsuffix:
+      diffs.append((self.DIFF_EQUAL, commonsuffix))
+    self.diff_cleanupMerge(diffs)
+    return diffs
+
+  def diff_compute(self, text1, text2, checklines, deadline):
+    """Find the differences between two texts.  Assumes that the texts do not
+      have any common prefix or suffix.
+
+    Args:
+      text1: Old string to be diffed.
+      text2: New string to be diffed.
+      checklines: Speedup flag.  If false, then don't run a line-level diff
+        first to identify the changed areas.
+        If true, then run a faster, slightly less optimal diff.
+      deadline: Time when the diff should be complete by.
+
+    Returns:
+      Array of changes.
+    """
+    if not text1:
+      # Just add some text (speedup).
+      return [(self.DIFF_INSERT, text2)]
+
+    if not text2:
+      # Just delete some text (speedup).
+      return [(self.DIFF_DELETE, text1)]
+
+    if len(text1) > len(text2):
+      (longtext, shorttext) = (text1, text2)
+    else:
+      (shorttext, longtext) = (text1, text2)
+    i = longtext.find(shorttext)
+    if i != -1:
+      # Shorter text is inside the longer text (speedup).
+      diffs = [(self.DIFF_INSERT, longtext[:i]), (self.DIFF_EQUAL, shorttext),
+               (self.DIFF_INSERT, longtext[i + len(shorttext):])]
+      # Swap insertions for deletions if diff is reversed.
+      if len(text1) > len(text2):
+        diffs[0] = (self.DIFF_DELETE, diffs[0][1])
+        diffs[2] = (self.DIFF_DELETE, diffs[2][1])
+      return diffs
+
+    if len(shorttext) == 1:
+      # Single character string.
+      # After the previous speedup, the character can't be an equality.
+      return [(self.DIFF_DELETE, text1), (self.DIFF_INSERT, text2)]
+
+    # Check to see if the problem can be split in two.
+    hm = self.diff_halfMatch(text1, text2)
+    if hm:
+      # A half-match was found, sort out the return data.
+      (text1_a, text1_b, text2_a, text2_b, mid_common) = hm
+      # Send both pairs off for separate processing.
+      diffs_a = self.diff_main(text1_a, text2_a, checklines, deadline)
+      diffs_b = self.diff_main(text1_b, text2_b, checklines, deadline)
+      # Merge the results.
+      return diffs_a + [(self.DIFF_EQUAL, mid_common)] + diffs_b
+
+    if checklines and len(text1) > 100 and len(text2) > 100:
+      return self.diff_lineMode(text1, text2, deadline)
+
+    return self.diff_bisect(text1, text2, deadline)
+
+  def diff_lineMode(self, text1, text2, deadline):
+    """Do a quick line-level diff on both strings, then rediff the parts for
+      greater accuracy.
+      This speedup can produce non-minimal diffs.
+
+    Args:
+      text1: Old string to be diffed.
+      text2: New string to be diffed.
+      deadline: Time when the diff should be complete by.
+
+    Returns:
+      Array of changes.
+    """
+
+    # Scan the text on a line-by-line basis first.
+    (text1, text2, linearray) = self.diff_linesToChars(text1, text2)
+
+    diffs = self.diff_main(text1, text2, False, deadline)
+
+    # Convert the diff back to original text.
+    self.diff_charsToLines(diffs, linearray)
+    # Eliminate freak matches (e.g. blank lines)
+    self.diff_cleanupSemantic(diffs)
+
+    # Rediff any replacement blocks, this time character-by-character.
+    # Add a dummy entry at the end.
+    diffs.append((self.DIFF_EQUAL, ''))
+    pointer = 0
+    count_delete = 0
+    count_insert = 0
+    text_delete = ''
+    text_insert = ''
+    while pointer < len(diffs):
+      if diffs[pointer][0] == self.DIFF_INSERT:
+        count_insert += 1
+        text_insert += diffs[pointer][1]
+      elif diffs[pointer][0] == self.DIFF_DELETE:
+        count_delete += 1
+        text_delete += diffs[pointer][1]
+      elif diffs[pointer][0] == self.DIFF_EQUAL:
+        # Upon reaching an equality, check for prior redundancies.
+        if count_delete >= 1 and count_insert >= 1:
+          # Delete the offending records and add the merged ones.
+          subDiff = self.diff_main(text_delete, text_insert, False, deadline)
+          diffs[pointer - count_delete - count_insert : pointer] = subDiff
+          pointer = pointer - count_delete - count_insert + len(subDiff)
+        count_insert = 0
+        count_delete = 0
+        text_delete = ''
+        text_insert = ''
+
+      pointer += 1
+
+    diffs.pop()  # Remove the dummy entry at the end.
+
+    return diffs
+
+  def diff_bisect(self, text1, text2, deadline):
+    """Find the 'middle snake' of a diff, split the problem in two
+      and return the recursively constructed diff.
+      See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.
+
+    Args:
+      text1: Old string to be diffed.
+      text2: New string to be diffed.
+      deadline: Time at which to bail if not yet complete.
+
+    Returns:
+      Array of diff tuples.
+    """
+
+    # Cache the text lengths to prevent multiple calls.
+    text1_length = len(text1)
+    text2_length = len(text2)
+    max_d = (text1_length + text2_length + 1) // 2
+    v_offset = max_d
+    v_length = 2 * max_d
+    v1 = [-1] * v_length
+    v1[v_offset + 1] = 0
+    v2 = v1[:]
+    delta = text1_length - text2_length
+    # If the total number of characters is odd, then the front path will
+    # collide with the reverse path.
+    front = (delta % 2 != 0)
+    # Offsets for start and end of k loop.
+    # Prevents mapping of space beyond the grid.
+    k1start = 0
+    k1end = 0
+    k2start = 0
+    k2end = 0
+    for d in range(max_d):
+      # Bail out if deadline is reached.
+      if time.time() > deadline:
+        break
+
+      # Walk the front path one step.
+      for k1 in range(-d + k1start, d + 1 - k1end, 2):
+        k1_offset = v_offset + k1
+        if k1 == -d or (k1 != d and
+            v1[k1_offset - 1] < v1[k1_offset + 1]):
+          x1 = v1[k1_offset + 1]
+        else:
+          x1 = v1[k1_offset - 1] + 1
+        y1 = x1 - k1
+        while (x1 < text1_length and y1 < text2_length and
+               text1[x1] == text2[y1]):
+          x1 += 1
+          y1 += 1
+        v1[k1_offset] = x1
+        if x1 > text1_length:
+          # Ran off the right of the graph.
+          k1end += 2
+        elif y1 > text2_length:
+          # Ran off the bottom of the graph.
+          k1start += 2
+        elif front:
+          k2_offset = v_offset + delta - k1
+          if k2_offset >= 0 and k2_offset < v_length and v2[k2_offset] != -1:
+            # Mirror x2 onto top-left coordinate system.
+            x2 = text1_length - v2[k2_offset]
+            if x1 >= x2:
+              # Overlap detected.
+              return self.diff_bisectSplit(text1, text2, x1, y1, deadline)
+
+      # Walk the reverse path one step.
+      for k2 in range(-d + k2start, d + 1 - k2end, 2):
+        k2_offset = v_offset + k2
+        if k2 == -d or (k2 != d and
+            v2[k2_offset - 1] < v2[k2_offset + 1]):
+          x2 = v2[k2_offset + 1]
+        else:
+          x2 = v2[k2_offset - 1] + 1
+        y2 = x2 - k2
+        while (x2 < text1_length and y2 < text2_length and
+               text1[-x2 - 1] == text2[-y2 - 1]):
+          x2 += 1
+          y2 += 1
+        v2[k2_offset] = x2
+        if x2 > text1_length:
+          # Ran off the left of the graph.
+          k2end += 2
+        elif y2 > text2_length:
+          # Ran off the top of the graph.
+          k2start += 2
+        elif not front:
+          k1_offset = v_offset + delta - k2
+          if k1_offset >= 0 and k1_offset < v_length and v1[k1_offset] != -1:
+            x1 = v1[k1_offset]
+            y1 = v_offset + x1 - k1_offset
+            # Mirror x2 onto top-left coordinate system.
+            x2 = text1_length - x2
+            if x1 >= x2:
+              # Overlap detected.
+              return self.diff_bisectSplit(text1, text2, x1, y1, deadline)
+
+    # Diff took too long and hit the deadline or
+    # number of diffs equals number of characters, no commonality at all.
+    return [(self.DIFF_DELETE, text1), (self.DIFF_INSERT, text2)]
+
+  def diff_bisectSplit(self, text1, text2, x, y, deadline):
+    """Given the location of the 'middle snake', split the diff in two parts
+    and recurse.
+
+    Args:
+      text1: Old string to be diffed.
+      text2: New string to be diffed.
+      x: Index of split point in text1.
+      y: Index of split point in text2.
+      deadline: Time at which to bail if not yet complete.
+
+    Returns:
+      Array of diff tuples.
+    """
+    text1a = text1[:x]
+    text2a = text2[:y]
+    text1b = text1[x:]
+    text2b = text2[y:]
+
+    # Compute both diffs serially.
+    diffs = self.diff_main(text1a, text2a, False, deadline)
+    diffsb = self.diff_main(text1b, text2b, False, deadline)
+
+    return diffs + diffsb
+
+  def diff_linesToChars(self, text1, text2):
+    """Split two texts into an array of strings.  Reduce the texts to a string
+    of hashes where each Unicode character represents one line.
+
+    Args:
+      text1: First string.
+      text2: Second string.
+
+    Returns:
+      Three element tuple, containing the encoded text1, the encoded text2 and
+      the array of unique strings.  The zeroth element of the array of unique
+      strings is intentionally blank.
+    """
+    lineArray = []  # e.g. lineArray[4] == "Hello\n"
+    lineHash = {}   # e.g. lineHash["Hello\n"] == 4
+
+    # "\x00" is a valid character, but various debuggers don't like it.
+    # So we'll insert a junk entry to avoid generating a null character.
+    lineArray.append('')
+
+    def diff_linesToCharsMunge(text):
+      """Split a text into an array of strings.  Reduce the texts to a string
+      of hashes where each Unicode character represents one line.
+      Modifies linearray and linehash through being a closure.
+
+      Args:
+        text: String to encode.
+
+      Returns:
+        Encoded string.
+      """
+      chars = []
+      # Walk the text, pulling out a substring for each line.
+      # text.split('\n') would would temporarily double our memory footprint.
+      # Modifying text would create many large strings to garbage collect.
+      lineStart = 0
+      lineEnd = -1
+      while lineEnd < len(text) - 1:
+        lineEnd = text.find('\n', lineStart)
+        if lineEnd == -1:
+          lineEnd = len(text) - 1
+        line = text[lineStart:lineEnd + 1]
+
+        if line in lineHash:
+          chars.append(chr(lineHash[line]))
+        else:
+          if len(lineArray) == maxLines:
+            # Bail out at 1114111 because chr(1114112) throws.
+            line = text[lineStart:]
+            lineEnd = len(text)
+          lineArray.append(line)
+          lineHash[line] = len(lineArray) - 1
+          chars.append(chr(len(lineArray) - 1))
+        lineStart = lineEnd + 1
+      return "".join(chars)
+
+    # Allocate 2/3rds of the space for text1, the rest for text2.
+    maxLines = 666666
+    chars1 = diff_linesToCharsMunge(text1)
+    maxLines = 1114111
+    chars2 = diff_linesToCharsMunge(text2)
+    return (chars1, chars2, lineArray)
+
+  def diff_charsToLines(self, diffs, lineArray):
+    """Rehydrate the text in a diff from a string of line hashes to real lines
+    of text.
+
+    Args:
+      diffs: Array of diff tuples.
+      lineArray: Array of unique strings.
+    """
+    for i in range(len(diffs)):
+      text = []
+      for char in diffs[i][1]:
+        text.append(lineArray[ord(char)])
+      diffs[i] = (diffs[i][0], "".join(text))
+
+  def diff_commonPrefix(self, text1, text2):
+    """Determine the common prefix of two strings.
+
+    Args:
+      text1: First string.
+      text2: Second string.
+
+    Returns:
+      The number of characters common to the start of each string.
+    """
+    # Quick check for common null cases.
+    if not text1 or not text2 or text1[0] != text2[0]:
+      return 0
+    # Binary search.
+    # Performance analysis: https://neil.fraser.name/news/2007/10/09/
+    pointermin = 0
+    pointermax = min(len(text1), len(text2))
+    pointermid = pointermax
+    pointerstart = 0
+    while pointermin < pointermid:
+      if text1[pointerstart:pointermid] == text2[pointerstart:pointermid]:
+        pointermin = pointermid
+        pointerstart = pointermin
+      else:
+        pointermax = pointermid
+      pointermid = (pointermax - pointermin) // 2 + pointermin
+    return pointermid
+
+  def diff_commonSuffix(self, text1, text2):
+    """Determine the common suffix of two strings.
+
+    Args:
+      text1: First string.
+      text2: Second string.
+
+    Returns:
+      The number of characters common to the end of each string.
+    """
+    # Quick check for common null cases.
+    if not text1 or not text2 or text1[-1] != text2[-1]:
+      return 0
+    # Binary search.
+    # Performance analysis: https://neil.fraser.name/news/2007/10/09/
+    pointermin = 0
+    pointermax = min(len(text1), len(text2))
+    pointermid = pointermax
+    pointerend = 0
+    while pointermin < pointermid:
+      if (text1[-pointermid:len(text1) - pointerend] ==
+          text2[-pointermid:len(text2) - pointerend]):
+        pointermin = pointermid
+        pointerend = pointermin
+      else:
+        pointermax = pointermid
+      pointermid = (pointermax - pointermin) // 2 + pointermin
+    return pointermid
+
+  def diff_commonOverlap(self, text1, text2):
+    """Determine if the suffix of one string is the prefix of another.
+
+    Args:
+      text1 First string.
+      text2 Second string.
+
+    Returns:
+      The number of characters common to the end of the first
+      string and the start of the second string.
+    """
+    # Cache the text lengths to prevent multiple calls.
+    text1_length = len(text1)
+    text2_length = len(text2)
+    # Eliminate the null case.
+    if text1_length == 0 or text2_length == 0:
+      return 0
+    # Truncate the longer string.
+    if text1_length > text2_length:
+      text1 = text1[-text2_length:]
+    elif text1_length < text2_length:
+      text2 = text2[:text1_length]
+    text_length = min(text1_length, text2_length)
+    # Quick check for the worst case.
+    if text1 == text2:
+      return text_length
+
+    # Start by looking for a single character match
+    # and increase length until no match is found.
+    # Performance analysis: https://neil.fraser.name/news/2010/11/04/
+    best = 0
+    length = 1
+    while True:
+      pattern = text1[-length:]
+      found = text2.find(pattern)
+      if found == -1:
+        return best
+      length += found
+      if found == 0 or text1[-length:] == text2[:length]:
+        best = length
+        length += 1
+
+  def diff_halfMatch(self, text1, text2):
+    """Do the two texts share a substring which is at least half the length of
+    the longer text?
+    This speedup can produce non-minimal diffs.
+
+    Args:
+      text1: First string.
+      text2: Second string.
+
+    Returns:
+      Five element Array, containing the prefix of text1, the suffix of text1,
+      the prefix of text2, the suffix of text2 and the common middle.  Or None
+      if there was no match.
+    """
+    if self.Diff_Timeout <= 0:
+      # Don't risk returning a non-optimal diff if we have unlimited time.
+      return None
+    if len(text1) > len(text2):
+      (longtext, shorttext) = (text1, text2)
+    else:
+      (shorttext, longtext) = (text1, text2)
+    if len(longtext) < 4 or len(shorttext) * 2 < len(longtext):
+      return None  # Pointless.
+
+    def diff_halfMatchI(longtext, shorttext, i):
+      """Does a substring of shorttext exist within longtext such that the
+      substring is at least half the length of longtext?
+      Closure, but does not reference any external variables.
+
+      Args:
+        longtext: Longer string.
+        shorttext: Shorter string.
+        i: Start index of quarter length substring within longtext.
+
+      Returns:
+        Five element Array, containing the prefix of longtext, the suffix of
+        longtext, the prefix of shorttext, the suffix of shorttext and the
+        common middle.  Or None if there was no match.
+      """
+      seed = longtext[i:i + len(longtext) // 4]
+      best_common = ''
+      j = shorttext.find(seed)
+      while j != -1:
+        prefixLength = self.diff_commonPrefix(longtext[i:], shorttext[j:])
+        suffixLength = self.diff_commonSuffix(longtext[:i], shorttext[:j])
+        if len(best_common) < suffixLength + prefixLength:
+          best_common = (shorttext[j - suffixLength:j] +
+              shorttext[j:j + prefixLength])
+          best_longtext_a = longtext[:i - suffixLength]
+          best_longtext_b = longtext[i + prefixLength:]
+          best_shorttext_a = shorttext[:j - suffixLength]
+          best_shorttext_b = shorttext[j + prefixLength:]
+        j = shorttext.find(seed, j + 1)
+
+      if len(best_common) * 2 >= len(longtext):
+        return (best_longtext_a, best_longtext_b,
+                best_shorttext_a, best_shorttext_b, best_common)
+      else:
         return None
 
-    def diff_path1(self, v_map, text1, text2):
-        """Work from the middle back to the start to determine the path.
-
-        Args:
-          v_map: Array of paths.
-          text1: Old string fragment to be diffed.
-          text2: New string fragment to be diffed.
-
-        Returns:
-          Array of diff tuples.
-
-        """
-        path = []
-        x = len(text1)
-        y = len(text2)
-        last_op = None
-        for d in xrange(len(v_map) - 2, -1, -1):
-            while True:
-                if (x - 1, y) in v_map[d]:
-                    x -= 1
-                    if last_op == self.DIFF_DELETE:
-                        path[0] = (self.DIFF_DELETE, text1[x] + path[0][1])
-                    else:
-                        path[:0] = [(self.DIFF_DELETE, text1[x])]
-                    last_op = self.DIFF_DELETE
-                    break
-                elif (x, y - 1) in v_map[d]:
-                    y -= 1
-                    if last_op == self.DIFF_INSERT:
-                        path[0] = (self.DIFF_INSERT, text2[y] + path[0][1])
-                    else:
-                        path[:0] = [(self.DIFF_INSERT, text2[y])]
-                    last_op = self.DIFF_INSERT
-                    break
-                else:
-                    x -= 1
-                    y -= 1
-                    assert text1[x] == text2[y], ('No diagonal.  ' +
-                                                  "Can't happen. (diff_path1)")
-                    if last_op == self.DIFF_EQUAL:
-                        path[0] = (self.DIFF_EQUAL, text1[x] + path[0][1])
-                    else:
-                        path[:0] = [(self.DIFF_EQUAL, text1[x])]
-                    last_op = self.DIFF_EQUAL
-        return path
-
-    def diff_path2(self, v_map, text1, text2):
-        """Work from the middle back to the end to determine the path.
-
-        Args:
-          v_map: Array of paths.
-          text1: Old string fragment to be diffed.
-          text2: New string fragment to be diffed.
-
-        Returns:
-          Array of diff tuples.
-
-        """
-        path = []
-        x = len(text1)
-        y = len(text2)
-        last_op = None
-        for d in xrange(len(v_map) - 2, -1, -1):
-            while True:
-                if (x - 1, y) in v_map[d]:
-                    x -= 1
-                    if last_op == self.DIFF_DELETE:
-                        path[-1] = (self.DIFF_DELETE, path[-1]
-                                    [1] + text1[-x - 1])
-                    else:
-                        path.append((self.DIFF_DELETE, text1[-x - 1]))
-                    last_op = self.DIFF_DELETE
-                    break
-                elif (x, y - 1) in v_map[d]:
-                    y -= 1
-                    if last_op == self.DIFF_INSERT:
-                        path[-1] = (self.DIFF_INSERT, path[-1]
-                                    [1] + text2[-y - 1])
-                    else:
-                        path.append((self.DIFF_INSERT, text2[-y - 1]))
-                    last_op = self.DIFF_INSERT
-                    break
-                else:
-                    x -= 1
-                    y -= 1
-                    assert text1[-x - 1] == text2[-y - 1], ('No diagonal.  ' +
-                                                            "Can't happen. (diff_path2)")
-                    if last_op == self.DIFF_EQUAL:
-                        path[-1] = (self.DIFF_EQUAL, path[-1]
-                                    [1] + text1[-x - 1])
-                    else:
-                        path.append((self.DIFF_EQUAL, text1[-x - 1]))
-                    last_op = self.DIFF_EQUAL
-        return path
-
-    def diff_commonPrefix(self, text1, text2):
-        """Determine the common prefix of two strings.
-
-        Args:
-          text1: First string.
-          text2: Second string.
-
-        Returns:
-          The number of characters common to the start of each string.
-
-        """
-        # Quick check for common null cases.
-        if not text1 or not text2 or text1[0] != text2[0]:
-            return 0
-        # Binary search.
-        # Performance analysis: http://neil.fraser.name/news/2007/10/09/
-        pointermin = 0
-        pointermax = min(len(text1), len(text2))
-        pointermid = pointermax
-        pointerstart = 0
-        while pointermin < pointermid:
-            if text1[pointerstart:pointermid] == text2[pointerstart:pointermid]:
-                pointermin = pointermid
-                pointerstart = pointermin
-            else:
-                pointermax = pointermid
-            pointermid = int((pointermax - pointermin) / 2 + pointermin)
-        return pointermid
-
-    def diff_commonSuffix(self, text1, text2):
-        """Determine the common suffix of two strings.
-
-        Args:
-          text1: First string.
-          text2: Second string.
-
-        Returns:
-          The number of characters common to the end of each string.
-
-        """
-        # Quick check for common null cases.
-        if not text1 or not text2 or text1[-1] != text2[-1]:
-            return 0
-        # Binary search.
-        # Performance analysis: http://neil.fraser.name/news/2007/10/09/
-        pointermin = 0
-        pointermax = min(len(text1), len(text2))
-        pointermid = pointermax
-        pointerend = 0
-        while pointermin < pointermid:
-            if (text1[-pointermid:len(text1) - pointerend] ==
-                    text2[-pointermid:len(text2) - pointerend]):
-                pointermin = pointermid
-                pointerend = pointermin
-            else:
-                pointermax = pointermid
-            pointermid = int((pointermax - pointermin) / 2 + pointermin)
-        return pointermid
-
-    def diff_halfMatch(self, text1, text2):
-        """Do the two texts share a substring which is at least half the length
-        of the longer text?
-
-        Args:
-          text1: First string.
-          text2: Second string.
-
-        Returns:
-          Five element Array, containing the prefix of text1, the suffix of text1,
-          the prefix of text2, the suffix of text2 and the common middle.  Or None
-          if there was no match.
-
-        """
-        if len(text1) > len(text2):
-            (longtext, shorttext) = (text1, text2)
-        else:
-            (shorttext, longtext) = (text1, text2)
-        if len(longtext) < 10 or len(shorttext) < 1:
-            return None  # Pointless.
-
-        def diff_halfMatchI(longtext, shorttext, i):
-            """Does a substring of shorttext exist within longtext such that
-            the substring is at least half the length of longtext? Closure, but
-            does not reference any external variables.
-
-            Args:
-              longtext: Longer string.
-              shorttext: Shorter string.
-              i: Start index of quarter length substring within longtext.
-
-            Returns:
-              Five element Array, containing the prefix of longtext, the suffix of
-              longtext, the prefix of shorttext, the suffix of shorttext and the
-              common middle.  Or None if there was no match.
-
-            """
-            seed = longtext[i:i + len(longtext) / 4]
-            best_common = ''
-            j = shorttext.find(seed)
-            while j != -1:
-                prefixLength = self.diff_commonPrefix(
-                    longtext[i:], shorttext[j:])
-                suffixLength = self.diff_commonSuffix(
-                    longtext[:i], shorttext[:j])
-                if len(best_common) < suffixLength + prefixLength:
-                    best_common = (shorttext[j - suffixLength:j] +
-                                   shorttext[j:j + prefixLength])
-                    best_longtext_a = longtext[:i - suffixLength]
-                    best_longtext_b = longtext[i + prefixLength:]
-                    best_shorttext_a = shorttext[:j - suffixLength]
-                    best_shorttext_b = shorttext[j + prefixLength:]
-                j = shorttext.find(seed, j + 1)
-
-            if len(best_common) >= len(longtext) / 2:
-                return (best_longtext_a, best_longtext_b,
-                        best_shorttext_a, best_shorttext_b, best_common)
-            else:
-                return None
-
-        # First check if the second quarter is the seed for a half-match.
-        hm1 = diff_halfMatchI(longtext, shorttext, (len(longtext) + 3) / 4)
-        # Check again based on the third quarter.
-        hm2 = diff_halfMatchI(longtext, shorttext, (len(longtext) + 1) / 2)
-        if not hm1 and not hm2:
-            return None
-        elif not hm2:
-            hm = hm1
-        elif not hm1:
-            hm = hm2
-        else:
-            # Both matched.  Select the longest.
-            if len(hm1[4]) > len(hm2[4]):
-                hm = hm1
-            else:
-                hm = hm2
-
-        # A half-match was found, sort out the return data.
-        if len(text1) > len(text2):
-            (text1_a, text1_b, text2_a, text2_b, mid_common) = hm
-        else:
-            (text2_a, text2_b, text1_a, text1_b, mid_common) = hm
-        return (text1_a, text1_b, text2_a, text2_b, mid_common)
-
-    def diff_cleanupSemantic(self, diffs):
-        """Reduce the number of edits by eliminating semantically trivial
-        equalities.
-
-        Args:
-          diffs: Array of diff tuples.
-
-        """
-        changes = False
-        equalities = []  # Stack of indices where equalities are found.
-        lastequality = None  # Always equal to equalities[-1][1]
-        pointer = 0  # Index of current position.
-        # Number of chars that changed prior to the equality.
-        length_changes1 = 0
-        length_changes2 = 0  # Number of chars that changed after the equality.
-        while pointer < len(diffs):
-            if diffs[pointer][0] == self.DIFF_EQUAL:  # equality found
-                equalities.append(pointer)
-                length_changes1 = length_changes2
-                length_changes2 = 0
-                lastequality = diffs[pointer][1]
-            else:  # an insertion or deletion
-                length_changes2 += len(diffs[pointer][1])
-                if (lastequality != None and (len(lastequality) <= length_changes1) and
-                        (len(lastequality) <= length_changes2)):
-                    # Duplicate record
-                    diffs.insert(equalities[-1],
-                                 (self.DIFF_DELETE, lastequality))
-                    # Change second copy to insert.
-                    diffs[equalities[-1] + 1] = (self.DIFF_INSERT,
-                                                 diffs[equalities[-1] + 1][1])
-                    # Throw away the equality we just deleted.
-                    equalities.pop()
-                    # Throw away the previous equality (it needs to be
-                    # reevaluated).
-                    if len(equalities) != 0:
-                        equalities.pop()
-                    if len(equalities):
-                        pointer = equalities[-1]
-                    else:
-                        pointer = -1
-                    length_changes1 = 0  # Reset the counters.
-                    length_changes2 = 0
-                    lastequality = None
-                    changes = True
-            pointer += 1
-
-        if changes:
-            self.diff_cleanupMerge(diffs)
-
-        self.diff_cleanupSemanticLossless(diffs)
-
-    def diff_cleanupSemanticLossless(self, diffs):
-        """Look for single edits surrounded on both sides by equalities
-        which can be shifted sideways to align the edit to a word boundary.
-        e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
-
-        Args:
-          diffs: Array of diff tuples.
-        """
-
-        def diff_cleanupSemanticScore(one, two):
-            """Given two strings, compute a score representing whether the
-            internal boundary falls on logical boundaries. Scores range from 5
-            (best) to 0 (worst). Closure, but does not reference any external
-            variables.
-
-            Args:
-              one: First string.
-              two: Second string.
-
-            Returns:
-              The score.
-
-            """
-            if not one or not two:
-                # Edges are the best.
-                return 5
-
-            # Each port of this function behaves slightly differently due to
-            # subtle differences in each language's definition of things like
-            # 'whitespace'.  Since this function's purpose is largely cosmetic,
-            # the choice has been made to use each language's native features
-            # rather than force total conformity.
-            score = 0
-            # One point for non-alphanumeric.
-            if not one[-1].isalnum() or not two[0].isalnum():
-                score += 1
-                # Two points for whitespace.
-                if one[-1].isspace() or two[0].isspace():
-                    score += 1
-                    # Three points for line breaks.
-                    if (one[-1] == '\r' or one[-1] == '\n' or
-                            two[0] == '\r' or two[0] == '\n'):
-                        score += 1
-                        # Four points for blank lines.
-                        if (re.search('\\n\\r?\\n$', one) or
-                                re.match('^\\r?\\n\\r?\\n', two)):
-                            score += 1
-            return score
-
-        pointer = 1
-        # Intentionally ignore the first and last element (don't need
-        # checking).
-        while pointer < len(diffs) - 1:
-            if (diffs[pointer - 1][0] == self.DIFF_EQUAL and
-                    diffs[pointer + 1][0] == self.DIFF_EQUAL):
-                # This is a single edit surrounded by equalities.
-                equality1 = diffs[pointer - 1][1]
-                edit = diffs[pointer][1]
-                equality2 = diffs[pointer + 1][1]
-
-                # First, shift the edit as far left as possible.
-                commonOffset = self.diff_commonSuffix(equality1, edit)
-                if commonOffset:
-                    commonString = edit[-commonOffset:]
-                    equality1 = equality1[:-commonOffset]
-                    edit = commonString + edit[:-commonOffset]
-                    equality2 = commonString + equality2
-
-                # Second, step character by character right, looking for the
-                # best fit.
-                bestEquality1 = equality1
-                bestEdit = edit
-                bestEquality2 = equality2
-                bestScore = (diff_cleanupSemanticScore(equality1, edit) +
-                             diff_cleanupSemanticScore(edit, equality2))
-                while edit and equality2 and edit[0] == equality2[0]:
-                    equality1 += edit[0]
-                    edit = edit[1:] + equality2[0]
-                    equality2 = equality2[1:]
-                    score = (diff_cleanupSemanticScore(equality1, edit) +
-                             diff_cleanupSemanticScore(edit, equality2))
-                    # The >= encourages trailing rather than leading whitespace
-                    # on edits.
-                    if score >= bestScore:
-                        bestScore = score
-                        bestEquality1 = equality1
-                        bestEdit = edit
-                        bestEquality2 = equality2
-
-                if diffs[pointer - 1][1] != bestEquality1:
-                    # We have an improvement, save it back to the diff.
-                    if bestEquality1:
-                        diffs[pointer - 1] = (diffs[pointer - 1]
-                                              [0], bestEquality1)
-                    else:
-                        del diffs[pointer - 1]
-                        pointer -= 1
-                    diffs[pointer] = (diffs[pointer][0], bestEdit)
-                    if bestEquality2:
-                        diffs[pointer + 1] = (diffs[pointer + 1]
-                                              [0], bestEquality2)
-                    else:
-                        del diffs[pointer + 1]
-                        pointer -= 1
-            pointer += 1
-
-    def diff_cleanupEfficiency(self, diffs):
-        """Reduce the number of edits by eliminating operationally trivial
-        equalities.
-
-        Args:
-          diffs: Array of diff tuples.
-
-        """
-        changes = False
-        equalities = []  # Stack of indices where equalities are found.
-        lastequality = ''  # Always equal to equalities[-1][1]
-        pointer = 0  # Index of current position.
-        # Is there an insertion operation before the last equality.
-        pre_ins = False
-        # Is there a deletion operation before the last equality.
-        pre_del = False
-        # Is there an insertion operation after the last equality.
-        post_ins = False
-        # Is there a deletion operation after the last equality.
-        post_del = False
-        while pointer < len(diffs):
-            if diffs[pointer][0] == self.DIFF_EQUAL:  # equality found
-                if (len(diffs[pointer][1]) < self.Diff_EditCost and
-                        (post_ins or post_del)):
-                    # Candidate found.
-                    equalities.append(pointer)
-                    pre_ins = post_ins
-                    pre_del = post_del
-                    lastequality = diffs[pointer][1]
-                else:
-                    # Not a candidate, and can never become one.
-                    equalities = []
-                    lastequality = ''
-
-                post_ins = post_del = False
-            else:  # an insertion or deletion
-                if diffs[pointer][0] == self.DIFF_DELETE:
-                    post_del = True
-                else:
-                    post_ins = True
-
-                # Five types to be split:
-                # <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
-                # <ins>A</ins>X<ins>C</ins><del>D</del>
-                # <ins>A</ins><del>B</del>X<ins>C</ins>
-                # <ins>A</del>X<ins>C</ins><del>D</del>
-                # <ins>A</ins><del>B</del>X<del>C</del>
-
-                if lastequality and ((pre_ins and pre_del and post_ins and post_del) or
-                                     ((len(lastequality) < self.Diff_EditCost / 2) and
-                                      (pre_ins + pre_del + post_ins + post_del) == 3)):
-                    # Duplicate record
-                    diffs.insert(equalities[-1],
-                                 (self.DIFF_DELETE, lastequality))
-                    # Change second copy to insert.
-                    diffs[equalities[-1] + 1] = (self.DIFF_INSERT,
-                                                 diffs[equalities[-1] + 1][1])
-                    equalities.pop()  # Throw away the equality we just deleted
-                    lastequality = ''
-                    if pre_ins and pre_del:
-                        # No changes made which could affect previous entry,
-                        # keep going.
-                        post_ins = post_del = True
-                        equalities = []
-                    else:
-                        if len(equalities):
-                            equalities.pop()  # Throw away the previous equality
-                        if len(equalities):
-                            pointer = equalities[-1]
-                        else:
-                            pointer = -1
-                        post_ins = post_del = False
-                    changes = True
-            pointer += 1
-
-        if changes:
-            self.diff_cleanupMerge(diffs)
-
-    def diff_cleanupMerge(self, diffs):
-        """Reorder and merge like edit sections.  Merge equalities. Any edit
-        section can move as long as it doesn't cross an equality.
-
-        Args:
-          diffs: Array of diff tuples.
-
-        """
-        diffs.append((self.DIFF_EQUAL, ''))  # Add a dummy entry at the end.
-        pointer = 0
+    # First check if the second quarter is the seed for a half-match.
+    hm1 = diff_halfMatchI(longtext, shorttext, (len(longtext) + 3) // 4)
+    # Check again based on the third quarter.
+    hm2 = diff_halfMatchI(longtext, shorttext, (len(longtext) + 1) // 2)
+    if not hm1 and not hm2:
+      return None
+    elif not hm2:
+      hm = hm1
+    elif not hm1:
+      hm = hm2
+    else:
+      # Both matched.  Select the longest.
+      if len(hm1[4]) > len(hm2[4]):
+        hm = hm1
+      else:
+        hm = hm2
+
+    # A half-match was found, sort out the return data.
+    if len(text1) > len(text2):
+      (text1_a, text1_b, text2_a, text2_b, mid_common) = hm
+    else:
+      (text2_a, text2_b, text1_a, text1_b, mid_common) = hm
+    return (text1_a, text1_b, text2_a, text2_b, mid_common)
+
+  def diff_cleanupSemantic(self, diffs):
+    """Reduce the number of edits by eliminating semantically trivial
+    equalities.
+
+    Args:
+      diffs: Array of diff tuples.
+    """
+    changes = False
+    equalities = []  # Stack of indices where equalities are found.
+    lastEquality = None  # Always equal to diffs[equalities[-1]][1]
+    pointer = 0  # Index of current position.
+    # Number of chars that changed prior to the equality.
+    length_insertions1, length_deletions1 = 0, 0
+    # Number of chars that changed after the equality.
+    length_insertions2, length_deletions2 = 0, 0
+    while pointer < len(diffs):
+      if diffs[pointer][0] == self.DIFF_EQUAL:  # Equality found.
+        equalities.append(pointer)
+        length_insertions1, length_insertions2 = length_insertions2, 0
+        length_deletions1, length_deletions2 = length_deletions2, 0
+        lastEquality = diffs[pointer][1]
+      else:  # An insertion or deletion.
+        if diffs[pointer][0] == self.DIFF_INSERT:
+          length_insertions2 += len(diffs[pointer][1])
+        else:
+          length_deletions2 += len(diffs[pointer][1])
+        # Eliminate an equality that is smaller or equal to the edits on both
+        # sides of it.
+        if (lastEquality and (len(lastEquality) <=
+            max(length_insertions1, length_deletions1)) and
+            (len(lastEquality) <= max(length_insertions2, length_deletions2))):
+          # Duplicate record.
+          diffs.insert(equalities[-1], (self.DIFF_DELETE, lastEquality))
+          # Change second copy to insert.
+          diffs[equalities[-1] + 1] = (self.DIFF_INSERT,
+              diffs[equalities[-1] + 1][1])
+          # Throw away the equality we just deleted.
+          equalities.pop()
+          # Throw away the previous equality (it needs to be reevaluated).
+          if len(equalities):
+            equalities.pop()
+          if len(equalities):
+            pointer = equalities[-1]
+          else:
+            pointer = -1
+          # Reset the counters.
+          length_insertions1, length_deletions1 = 0, 0
+          length_insertions2, length_deletions2 = 0, 0
+          lastEquality = None
+          changes = True
+      pointer += 1
+
+    # Normalize the diff.
+    if changes:
+      self.diff_cleanupMerge(diffs)
+    self.diff_cleanupSemanticLossless(diffs)
+
+    # Find any overlaps between deletions and insertions.
+    # e.g: <del>abcxxx</del><ins>xxxdef</ins>
+    #   -> <del>abc</del>xxx<ins>def</ins>
+    # e.g: <del>xxxabc</del><ins>defxxx</ins>
+    #   -> <ins>def</ins>xxx<del>abc</del>
+    # Only extract an overlap if it is as big as the edit ahead or behind it.
+    pointer = 1
+    while pointer < len(diffs):
+      if (diffs[pointer - 1][0] == self.DIFF_DELETE and
+          diffs[pointer][0] == self.DIFF_INSERT):
+        deletion = diffs[pointer - 1][1]
+        insertion = diffs[pointer][1]
+        overlap_length1 = self.diff_commonOverlap(deletion, insertion)
+        overlap_length2 = self.diff_commonOverlap(insertion, deletion)
+        if overlap_length1 >= overlap_length2:
+          if (overlap_length1 >= len(deletion) / 2.0 or
+              overlap_length1 >= len(insertion) / 2.0):
+            # Overlap found.  Insert an equality and trim the surrounding edits.
+            diffs.insert(pointer, (self.DIFF_EQUAL,
+                                   insertion[:overlap_length1]))
+            diffs[pointer - 1] = (self.DIFF_DELETE,
+                                  deletion[:len(deletion) - overlap_length1])
+            diffs[pointer + 1] = (self.DIFF_INSERT,
+                                  insertion[overlap_length1:])
+            pointer += 1
+        else:
+          if (overlap_length2 >= len(deletion) / 2.0 or
+              overlap_length2 >= len(insertion) / 2.0):
+            # Reverse overlap found.
+            # Insert an equality and swap and trim the surrounding edits.
+            diffs.insert(pointer, (self.DIFF_EQUAL, deletion[:overlap_length2]))
+            diffs[pointer - 1] = (self.DIFF_INSERT,
+                                  insertion[:len(insertion) - overlap_length2])
+            diffs[pointer + 1] = (self.DIFF_DELETE, deletion[overlap_length2:])
+            pointer += 1
+        pointer += 1
+      pointer += 1
+
+  def diff_cleanupSemanticLossless(self, diffs):
+    """Look for single edits surrounded on both sides by equalities
+    which can be shifted sideways to align the edit to a word boundary.
+    e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
+
+    Args:
+      diffs: Array of diff tuples.
+    """
+
+    def diff_cleanupSemanticScore(one, two):
+      """Given two strings, compute a score representing whether the
+      internal boundary falls on logical boundaries.
+      Scores range from 6 (best) to 0 (worst).
+      Closure, but does not reference any external variables.
+
+      Args:
+        one: First string.
+        two: Second string.
+
+      Returns:
+        The score.
+      """
+      if not one or not two:
+        # Edges are the best.
+        return 6
+
+      # Each port of this function behaves slightly differently due to
+      # subtle differences in each language's definition of things like
+      # 'whitespace'.  Since this function's purpose is largely cosmetic,
+      # the choice has been made to use each language's native features
+      # rather than force total conformity.
+      char1 = one[-1]
+      char2 = two[0]
+      nonAlphaNumeric1 = not char1.isalnum()
+      nonAlphaNumeric2 = not char2.isalnum()
+      whitespace1 = nonAlphaNumeric1 and char1.isspace()
+      whitespace2 = nonAlphaNumeric2 and char2.isspace()
+      lineBreak1 = whitespace1 and (char1 == "\r" or char1 == "\n")
+      lineBreak2 = whitespace2 and (char2 == "\r" or char2 == "\n")
+      blankLine1 = lineBreak1 and self.BLANKLINEEND.search(one)
+      blankLine2 = lineBreak2 and self.BLANKLINESTART.match(two)
+
+      if blankLine1 or blankLine2:
+        # Five points for blank lines.
+        return 5
+      elif lineBreak1 or lineBreak2:
+        # Four points for line breaks.
+        return 4
+      elif nonAlphaNumeric1 and not whitespace1 and whitespace2:
+        # Three points for end of sentences.
+        return 3
+      elif whitespace1 or whitespace2:
+        # Two points for whitespace.
+        return 2
+      elif nonAlphaNumeric1 or nonAlphaNumeric2:
+        # One point for non-alphanumeric.
+        return 1
+      return 0
+
+    pointer = 1
+    # Intentionally ignore the first and last element (don't need checking).
+    while pointer < len(diffs) - 1:
+      if (diffs[pointer - 1][0] == self.DIFF_EQUAL and
+          diffs[pointer + 1][0] == self.DIFF_EQUAL):
+        # This is a single edit surrounded by equalities.
+        equality1 = diffs[pointer - 1][1]
+        edit = diffs[pointer][1]
+        equality2 = diffs[pointer + 1][1]
+
+        # First, shift the edit as far left as possible.
+        commonOffset = self.diff_commonSuffix(equality1, edit)
+        if commonOffset:
+          commonString = edit[-commonOffset:]
+          equality1 = equality1[:-commonOffset]
+          edit = commonString + edit[:-commonOffset]
+          equality2 = commonString + equality2
+
+        # Second, step character by character right, looking for the best fit.
+        bestEquality1 = equality1
+        bestEdit = edit
+        bestEquality2 = equality2
+        bestScore = (diff_cleanupSemanticScore(equality1, edit) +
+            diff_cleanupSemanticScore(edit, equality2))
+        while edit and equality2 and edit[0] == equality2[0]:
+          equality1 += edit[0]
+          edit = edit[1:] + equality2[0]
+          equality2 = equality2[1:]
+          score = (diff_cleanupSemanticScore(equality1, edit) +
+              diff_cleanupSemanticScore(edit, equality2))
+          # The >= encourages trailing rather than leading whitespace on edits.
+          if score >= bestScore:
+            bestScore = score
+            bestEquality1 = equality1
+            bestEdit = edit
+            bestEquality2 = equality2
+
+        if diffs[pointer - 1][1] != bestEquality1:
+          # We have an improvement, save it back to the diff.
+          if bestEquality1:
+            diffs[pointer - 1] = (diffs[pointer - 1][0], bestEquality1)
+          else:
+            del diffs[pointer - 1]
+            pointer -= 1
+          diffs[pointer] = (diffs[pointer][0], bestEdit)
+          if bestEquality2:
+            diffs[pointer + 1] = (diffs[pointer + 1][0], bestEquality2)
+          else:
+            del diffs[pointer + 1]
+            pointer -= 1
+      pointer += 1
+
+  # Define some regex patterns for matching boundaries.
+  BLANKLINEEND = re.compile(r"\n\r?\n$")
+  BLANKLINESTART = re.compile(r"^\r?\n\r?\n")
+
+  def diff_cleanupEfficiency(self, diffs):
+    """Reduce the number of edits by eliminating operationally trivial
+    equalities.
+
+    Args:
+      diffs: Array of diff tuples.
+    """
+    changes = False
+    equalities = []  # Stack of indices where equalities are found.
+    lastEquality = None  # Always equal to diffs[equalities[-1]][1]
+    pointer = 0  # Index of current position.
+    pre_ins = False  # Is there an insertion operation before the last equality.
+    pre_del = False  # Is there a deletion operation before the last equality.
+    post_ins = False  # Is there an insertion operation after the last equality.
+    post_del = False  # Is there a deletion operation after the last equality.
+    while pointer < len(diffs):
+      if diffs[pointer][0] == self.DIFF_EQUAL:  # Equality found.
+        if (len(diffs[pointer][1]) < self.Diff_EditCost and
+            (post_ins or post_del)):
+          # Candidate found.
+          equalities.append(pointer)
+          pre_ins = post_ins
+          pre_del = post_del
+          lastEquality = diffs[pointer][1]
+        else:
+          # Not a candidate, and can never become one.
+          equalities = []
+          lastEquality = None
+
+        post_ins = post_del = False
+      else:  # An insertion or deletion.
+        if diffs[pointer][0] == self.DIFF_DELETE:
+          post_del = True
+        else:
+          post_ins = True
+
+        # Five types to be split:
+        # <ins>A</ins><del>B</del>XY<ins>C</ins><del>D</del>
+        # <ins>A</ins>X<ins>C</ins><del>D</del>
+        # <ins>A</ins><del>B</del>X<ins>C</ins>
+        # <ins>A</del>X<ins>C</ins><del>D</del>
+        # <ins>A</ins><del>B</del>X<del>C</del>
+
+        if lastEquality and ((pre_ins and pre_del and post_ins and post_del) or
+                             ((len(lastEquality) < self.Diff_EditCost / 2) and
+                              (pre_ins + pre_del + post_ins + post_del) == 3)):
+          # Duplicate record.
+          diffs.insert(equalities[-1], (self.DIFF_DELETE, lastEquality))
+          # Change second copy to insert.
+          diffs[equalities[-1] + 1] = (self.DIFF_INSERT,
+              diffs[equalities[-1] + 1][1])
+          equalities.pop()  # Throw away the equality we just deleted.
+          lastEquality = None
+          if pre_ins and pre_del:
+            # No changes made which could affect previous entry, keep going.
+            post_ins = post_del = True
+            equalities = []
+          else:
+            if len(equalities):
+              equalities.pop()  # Throw away the previous equality.
+            if len(equalities):
+              pointer = equalities[-1]
+            else:
+              pointer = -1
+            post_ins = post_del = False
+          changes = True
+      pointer += 1
+
+    if changes:
+      self.diff_cleanupMerge(diffs)
+
+  def diff_cleanupMerge(self, diffs):
+    """Reorder and merge like edit sections.  Merge equalities.
+    Any edit section can move as long as it doesn't cross an equality.
+
+    Args:
+      diffs: Array of diff tuples.
+    """
+    diffs.append((self.DIFF_EQUAL, ''))  # Add a dummy entry at the end.
+    pointer = 0
+    count_delete = 0
+    count_insert = 0
+    text_delete = ''
+    text_insert = ''
+    while pointer < len(diffs):
+      if diffs[pointer][0] == self.DIFF_INSERT:
+        count_insert += 1
+        text_insert += diffs[pointer][1]
+        pointer += 1
+      elif diffs[pointer][0] == self.DIFF_DELETE:
+        count_delete += 1
+        text_delete += diffs[pointer][1]
+        pointer += 1
+      elif diffs[pointer][0] == self.DIFF_EQUAL:
+        # Upon reaching an equality, check for prior redundancies.
+        if count_delete + count_insert > 1:
+          if count_delete != 0 and count_insert != 0:
+            # Factor out any common prefixies.
+            commonlength = self.diff_commonPrefix(text_insert, text_delete)
+            if commonlength != 0:
+              x = pointer - count_delete - count_insert - 1
+              if x >= 0 and diffs[x][0] == self.DIFF_EQUAL:
+                diffs[x] = (diffs[x][0], diffs[x][1] +
+                            text_insert[:commonlength])
+              else:
+                diffs.insert(0, (self.DIFF_EQUAL, text_insert[:commonlength]))
+                pointer += 1
+              text_insert = text_insert[commonlength:]
+              text_delete = text_delete[commonlength:]
+            # Factor out any common suffixies.
+            commonlength = self.diff_commonSuffix(text_insert, text_delete)
+            if commonlength != 0:
+              diffs[pointer] = (diffs[pointer][0], text_insert[-commonlength:] +
+                  diffs[pointer][1])
+              text_insert = text_insert[:-commonlength]
+              text_delete = text_delete[:-commonlength]
+          # Delete the offending records and add the merged ones.
+          new_ops = []
+          if len(text_delete) != 0:
+            new_ops.append((self.DIFF_DELETE, text_delete))
+          if len(text_insert) != 0:
+            new_ops.append((self.DIFF_INSERT, text_insert))
+          pointer -= count_delete + count_insert
+          diffs[pointer : pointer + count_delete + count_insert] = new_ops
+          pointer += len(new_ops) + 1
+        elif pointer != 0 and diffs[pointer - 1][0] == self.DIFF_EQUAL:
+          # Merge this equality with the previous one.
+          diffs[pointer - 1] = (diffs[pointer - 1][0],
+                                diffs[pointer - 1][1] + diffs[pointer][1])
+          del diffs[pointer]
+        else:
+          pointer += 1
+
+        count_insert = 0
         count_delete = 0
-        count_insert = 0
         text_delete = ''
         text_insert = ''
-        while pointer < len(diffs):
-            if diffs[pointer][0] == self.DIFF_INSERT:
-                count_insert += 1
-                text_insert += diffs[pointer][1]
-                pointer += 1
-            elif diffs[pointer][0] == self.DIFF_DELETE:
-                count_delete += 1
-                text_delete += diffs[pointer][1]
-                pointer += 1
-            elif diffs[pointer][0] == self.DIFF_EQUAL:
-                # Upon reaching an equality, check for prior redundancies.
-                if count_delete != 0 or count_insert != 0:
-                    if count_delete != 0 and count_insert != 0:
-                        # Factor out any common prefixies.
-                        commonlength = self.diff_commonPrefix(
-                            text_insert, text_delete)
-                        if commonlength != 0:
-                            x = pointer - count_delete - count_insert - 1
-                            if x >= 0 and diffs[x][0] == self.DIFF_EQUAL:
-                                diffs[x] = (diffs[x][0], diffs[x][1] +
-                                            text_insert[:commonlength])
-                            else:
-                                diffs.insert(
-                                    0, (self.DIFF_EQUAL, text_insert[:commonlength]))
-                                pointer += 1
-                            text_insert = text_insert[commonlength:]
-                            text_delete = text_delete[commonlength:]
-                        # Factor out any common suffixies.
-                        commonlength = self.diff_commonSuffix(
-                            text_insert, text_delete)
-                        if commonlength != 0:
-                            diffs[pointer] = (diffs[pointer][0], text_insert[-commonlength:] +
-                                              diffs[pointer][1])
-                            text_insert = text_insert[:-commonlength]
-                            text_delete = text_delete[:-commonlength]
-                    # Delete the offending records and add the merged ones.
-                    if count_delete == 0:
-                        diffs[pointer - count_insert: pointer] = [
-                            (self.DIFF_INSERT, text_insert)]
-                    elif count_insert == 0:
-                        diffs[pointer - count_delete: pointer] = [
-                            (self.DIFF_DELETE, text_delete)]
-                    else:
-                        diffs[pointer - count_delete - count_insert: pointer] = [
-                            (self.DIFF_DELETE, text_delete),
-                            (self.DIFF_INSERT, text_insert)]
-                    pointer = pointer - count_delete - count_insert + 1
-                    if count_delete != 0:
-                        pointer += 1
-                    if count_insert != 0:
-                        pointer += 1
-                elif pointer != 0 and diffs[pointer - 1][0] == self.DIFF_EQUAL:
-                    # Merge this equality with the previous one.
-                    diffs[pointer - 1] = (diffs[pointer - 1][0],
-                                          diffs[pointer - 1][1] + diffs[pointer][1])
-                    del diffs[pointer]
-                else:
-                    pointer += 1
-
-                count_insert = 0
-                count_delete = 0
-                text_delete = ''
-                text_insert = ''
-
-        if diffs[-1][1] == '':
-            diffs.pop()  # Remove the dummy entry at the end.
-
-        # Second pass: look for single edits surrounded on both sides by equalities
-        # which can be shifted sideways to eliminate an equality.
-        # e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
-        changes = False
-        pointer = 1
-        # Intentionally ignore the first and last element (don't need
-        # checking).
-        while pointer < len(diffs) - 1:
-            if (diffs[pointer - 1][0] == self.DIFF_EQUAL and
-                    diffs[pointer + 1][0] == self.DIFF_EQUAL):
-                # This is a single edit surrounded by equalities.
-                if diffs[pointer][1].endswith(diffs[pointer - 1][1]):
-                    # Shift the edit over the previous equality.
-                    diffs[pointer] = (diffs[pointer][0],
-                                      diffs[pointer - 1][1] +
-                                      diffs[pointer][1][:-len(diffs[pointer - 1][1])])
-                    diffs[pointer + 1] = (diffs[pointer + 1][0],
-                                          diffs[pointer - 1][1] + diffs[pointer + 1][1])
-                    del diffs[pointer - 1]
-                    changes = True
-                elif diffs[pointer][1].startswith(diffs[pointer + 1][1]):
-                    # Shift the edit over the next equality.
-                    diffs[pointer - 1] = (diffs[pointer - 1][0],
-                                          diffs[pointer - 1][1] + diffs[pointer + 1][1])
-                    diffs[pointer] = (diffs[pointer][0],
-                                      diffs[pointer][1][len(diffs[pointer + 1][1]):] +
-                                      diffs[pointer + 1][1])
-                    del diffs[pointer + 1]
-                    changes = True
-            pointer += 1
-
-        # If shifts were made, the diff needs reordering and another shift
-        # sweep.
-        if changes:
-            self.diff_cleanupMerge(diffs)
-
-    def diff_xIndex(self, diffs, loc):
-        """loc is a location in text1, compute and return the equivalent location
-        in text2.  e.g. "The cat" vs "The big cat", 1->1, 5->8
-
-        Args:
-          diffs: Array of diff tuples.
-          loc: Location within text1.
-
-        Returns:
-          Location within text2.
-        """
-        chars1 = 0
-        chars2 = 0
-        last_chars1 = 0
-        last_chars2 = 0
-        for x in xrange(len(diffs)):
-            (op, text) = diffs[x]
-            if op != self.DIFF_INSERT:  # Equality or deletion.
-                chars1 += len(text)
-            if op != self.DIFF_DELETE:  # Equality or insertion.
-                chars2 += len(text)
-            if chars1 > loc:  # Overshot the location.
-                break
-            last_chars1 = chars1
-            last_chars2 = chars2
-
-        if len(diffs) != x and diffs[x][0] == self.DIFF_DELETE:
-            # The location was deleted.
-            return last_chars2
-        # Add the remaining len(character).
-        return last_chars2 + (loc - last_chars1)
-
-    def diff_prettyHtml(self, diffs):
-        """Convert a diff array into a pretty HTML report.
-
-        Args:
-          diffs: Array of diff tuples.
-
-        Returns:
-          HTML representation.
-
-        """
-        html = []
-        i = 0
-        for (op, data) in diffs:
-            text = (data.replace('&', '&amp;').replace('<', '&lt;')
-                    .replace('>', '&gt;').replace('\n', '&para;<BR>'))
-            if op == self.DIFF_INSERT:
-                html.append("<SPAN STYLE=\"color: #00FF00;\" TITLE=\"i=%i\">%s</SPAN>"
-                            % (i, text))
-            elif op == self.DIFF_DELETE:
-                html.append("<SPAN STYLE=\"color: #FF0000;\" TITLE=\"i=%i\">%s</SPAN>"
-                            % (i, text))
-            elif op == self.DIFF_EQUAL:
-                html.append("<SPAN TITLE=\"i=%i\">%s</SPAN>" % (i, text))
-            if op != self.DIFF_DELETE:
-                i += len(data)
-        return ''.join(html)
-
-    def diff_text1(self, diffs):
-        """Compute and return the source text (all equalities and deletions).
-
-        Args:
-          diffs: Array of diff tuples.
-
-        Returns:
-          Source text.
-
-        """
-        text = []
-        for (op, data) in diffs:
-            if op != self.DIFF_INSERT:
-                text.append(data)
-        return ''.join(text)
-
-    def diff_text2(self, diffs):
-        """Compute and return the destination text (all equalities and
-        insertions).
-
-        Args:
-          diffs: Array of diff tuples.
-
-        Returns:
-          Destination text.
-
-        """
-        text = []
-        for (op, data) in diffs:
-            if op != self.DIFF_DELETE:
-                text.append(data)
-        return ''.join(text)
-
-    def diff_levenshtein(self, diffs):
-        """Compute the Levenshtein distance; the number of inserted, deleted or
-        substituted characters.
-
-        Args:
-          diffs: Array of diff tuples.
-
-        Returns:
-          Number of changes.
-
-        """
-        levenshtein = 0
+
+    if diffs[-1][1] == '':
+      diffs.pop()  # Remove the dummy entry at the end.
+
+    # Second pass: look for single edits surrounded on both sides by equalities
+    # which can be shifted sideways to eliminate an equality.
+    # e.g: A<ins>BA</ins>C -> <ins>AB</ins>AC
+    changes = False
+    pointer = 1
+    # Intentionally ignore the first and last element (don't need checking).
+    while pointer < len(diffs) - 1:
+      if (diffs[pointer - 1][0] == self.DIFF_EQUAL and
+          diffs[pointer + 1][0] == self.DIFF_EQUAL):
+        # This is a single edit surrounded by equalities.
+        if diffs[pointer][1].endswith(diffs[pointer - 1][1]):
+          # Shift the edit over the previous equality.
+          if diffs[pointer - 1][1] != "":
+            diffs[pointer] = (diffs[pointer][0],
+                diffs[pointer - 1][1] +
+                diffs[pointer][1][:-len(diffs[pointer - 1][1])])
+            diffs[pointer + 1] = (diffs[pointer + 1][0],
+                                  diffs[pointer - 1][1] + diffs[pointer + 1][1])
+          del diffs[pointer - 1]
+          changes = True
+        elif diffs[pointer][1].startswith(diffs[pointer + 1][1]):
+          # Shift the edit over the next equality.
+          diffs[pointer - 1] = (diffs[pointer - 1][0],
+                                diffs[pointer - 1][1] + diffs[pointer + 1][1])
+          diffs[pointer] = (diffs[pointer][0],
+              diffs[pointer][1][len(diffs[pointer + 1][1]):] +
+              diffs[pointer + 1][1])
+          del diffs[pointer + 1]
+          changes = True
+      pointer += 1
+
+    # If shifts were made, the diff needs reordering and another shift sweep.
+    if changes:
+      self.diff_cleanupMerge(diffs)
+
+  def diff_xIndex(self, diffs, loc):
+    """loc is a location in text1, compute and return the equivalent location
+    in text2.  e.g. "The cat" vs "The big cat", 1->1, 5->8
+
+    Args:
+      diffs: Array of diff tuples.
+      loc: Location within text1.
+
+    Returns:
+      Location within text2.
+    """
+    chars1 = 0
+    chars2 = 0
+    last_chars1 = 0
+    last_chars2 = 0
+    for x in range(len(diffs)):
+      (op, text) = diffs[x]
+      if op != self.DIFF_INSERT:  # Equality or deletion.
+        chars1 += len(text)
+      if op != self.DIFF_DELETE:  # Equality or insertion.
+        chars2 += len(text)
+      if chars1 > loc:  # Overshot the location.
+        break
+      last_chars1 = chars1
+      last_chars2 = chars2
+
+    if len(diffs) != x and diffs[x][0] == self.DIFF_DELETE:
+      # The location was deleted.
+      return last_chars2
+    # Add the remaining len(character).
+    return last_chars2 + (loc - last_chars1)
+
+  def diff_prettyHtml(self, diffs):
+    """Convert a diff array into a pretty HTML report.
+
+    Args:
+      diffs: Array of diff tuples.
+
+    Returns:
+      HTML representation.
+    """
+    html = []
+    for (op, data) in diffs:
+      text = (data.replace("&", "&amp;").replace("<", "&lt;")
+                 .replace(">", "&gt;").replace("\n", "&para;<br>"))
+      if op == self.DIFF_INSERT:
+        html.append("<ins class=\"inserted\">%s</ins>" % text)
+      elif op == self.DIFF_DELETE:
+        html.append("<del class=\"removed\">%s</del>" % text)
+      elif op == self.DIFF_EQUAL:
+        html.append("<span>%s</span>" % text)
+    return "".join(html)
+
+  def diff_text1(self, diffs):
+    """Compute and return the source text (all equalities and deletions).
+
+    Args:
+      diffs: Array of diff tuples.
+
+    Returns:
+      Source text.
+    """
+    text = []
+    for (op, data) in diffs:
+      if op != self.DIFF_INSERT:
+        text.append(data)
+    return "".join(text)
+
+  def diff_text2(self, diffs):
+    """Compute and return the destination text (all equalities and insertions).
+
+    Args:
+      diffs: Array of diff tuples.
+
+    Returns:
+      Destination text.
+    """
+    text = []
+    for (op, data) in diffs:
+      if op != self.DIFF_DELETE:
+        text.append(data)
+    return "".join(text)
+
+  def diff_levenshtein(self, diffs):
+    """Compute the Levenshtein distance; the number of inserted, deleted or
+    substituted characters.
+
+    Args:
+      diffs: Array of diff tuples.
+
+    Returns:
+      Number of changes.
+    """
+    levenshtein = 0
+    insertions = 0
+    deletions = 0
+    for (op, data) in diffs:
+      if op == self.DIFF_INSERT:
+        insertions += len(data)
+      elif op == self.DIFF_DELETE:
+        deletions += len(data)
+      elif op == self.DIFF_EQUAL:
+        # A deletion and an insertion is one substitution.
+        levenshtein += max(insertions, deletions)
         insertions = 0
         deletions = 0
-        for (op, data) in diffs:
-            if op == self.DIFF_INSERT:
-                insertions += len(data)
-            elif op == self.DIFF_DELETE:
-                deletions += len(data)
-            elif op == self.DIFF_EQUAL:
-                # A deletion and an insertion is one substitution.
-                levenshtein += max(insertions, deletions)
-                insertions = 0
-                deletions = 0
-        levenshtein += max(insertions, deletions)
-        return levenshtein
-
-    def diff_toDelta(self, diffs):
-        """Crush the diff into an encoded string which describes the operations
-        required to transform text1 into text2.
-        E.g. =3\t-2\t+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'.
-        Operations are tab-separated.  Inserted text is escaped using %xx notation.
-
-        Args:
-          diffs: Array of diff tuples.
-
-        Returns:
-          Delta text.
-        """
-        text = []
-        for (op, data) in diffs:
-            if op == self.DIFF_INSERT:
-                # High ascii will raise UnicodeDecodeError.  Use Unicode
-                # instead.
-                data = data.encode('utf-8')
-                text.append('+' + urllib.quote(data, "!~*'();/?:@&=+$,# "))
-            elif op == self.DIFF_DELETE:
-                text.append('-%d' % len(data))
-            elif op == self.DIFF_EQUAL:
-                text.append('=%d' % len(data))
-        return '\t'.join(text)
-
-    def diff_fromDelta(self, text1, delta):
-        """Given the original text1, and an encoded string which describes the
-        operations required to transform text1 into text2, compute the full
-        diff.
-
-        Args:
-          text1: Source string for the diff.
-          delta: Delta text.
-
-        Returns:
-          Array of diff tuples.
-
-        Raises:
-          ValueError: If invalid input.
-
-        """
-        if type(delta) == unicode:
-            # Deltas should be composed of a subset of ascii chars, Unicode not
-            # required.  If this encode raises UnicodeEncodeError, delta is
-            # invalid.
-            delta = delta.encode('ascii')
-        diffs = []
-        pointer = 0  # Cursor in text1
-        tokens = delta.split('\t')
-        for token in tokens:
-            if token == '':
-                # Blank tokens are ok (from a trailing \t).
-                continue
-            # Each token begins with a one character parameter which specifies the
-            # operation of this token (delete, insert, equality).
-            param = token[1:]
-            if token[0] == '+':
-                param = urllib.unquote(param).decode('utf-8')
-                diffs.append((self.DIFF_INSERT, param))
-            elif token[0] == '-' or token[0] == '=':
-                try:
-                    n = int(param)
-                except ValueError:
-                    raise ValueError, 'Invalid number in diff_fromDelta: ' + param
-                if n < 0:
-                    raise ValueError, 'Negative number in diff_fromDelta: ' + param
-                text = text1[pointer: pointer + n]
-                pointer += n
-                if token[0] == '=':
-                    diffs.append((self.DIFF_EQUAL, text))
-                else:
-                    diffs.append((self.DIFF_DELETE, text))
+    levenshtein += max(insertions, deletions)
+    return levenshtein
+
+  def diff_toDelta(self, diffs):
+    """Crush the diff into an encoded string which describes the operations
+    required to transform text1 into text2.
+    E.g. =3\t-2\t+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'.
+    Operations are tab-separated.  Inserted text is escaped using %xx notation.
+
+    Args:
+      diffs: Array of diff tuples.
+
+    Returns:
+      Delta text.
+    """
+    text = []
+    for (op, data) in diffs:
+      if op == self.DIFF_INSERT:
+        # High ascii will raise UnicodeDecodeError.  Use Unicode instead.
+        data = data.encode("utf-8")
+        text.append("+" + urllib.parse.quote(data, "!~*'();/?:@&=+$,# "))
+      elif op == self.DIFF_DELETE:
+        text.append("-%d" % len(data))
+      elif op == self.DIFF_EQUAL:
+        text.append("=%d" % len(data))
+    return "\t".join(text)
+
+  def diff_fromDelta(self, text1, delta):
+    """Given the original text1, and an encoded string which describes the
+    operations required to transform text1 into text2, compute the full diff.
+
+    Args:
+      text1: Source string for the diff.
+      delta: Delta text.
+
+    Returns:
+      Array of diff tuples.
+
+    Raises:
+      ValueError: If invalid input.
+    """
+    diffs = []
+    pointer = 0  # Cursor in text1
+    tokens = delta.split("\t")
+    for token in tokens:
+      if token == "":
+        # Blank tokens are ok (from a trailing \t).
+        continue
+      # Each token begins with a one character parameter which specifies the
+      # operation of this token (delete, insert, equality).
+      param = token[1:]
+      if token[0] == "+":
+        param = urllib.parse.unquote(param)
+        diffs.append((self.DIFF_INSERT, param))
+      elif token[0] == "-" or token[0] == "=":
+        try:
+          n = int(param)
+        except ValueError:
+          raise ValueError("Invalid number in diff_fromDelta: " + param)
+        if n < 0:
+          raise ValueError("Negative number in diff_fromDelta: " + param)
+        text = text1[pointer : pointer + n]
+        pointer += n
+        if token[0] == "=":
+          diffs.append((self.DIFF_EQUAL, text))
+        else:
+          diffs.append((self.DIFF_DELETE, text))
+      else:
+        # Anything else is an error.
+        raise ValueError("Invalid diff operation in diff_fromDelta: " +
+            token[0])
+    if pointer != len(text1):
+      raise ValueError(
+          "Delta length (%d) does not equal source text length (%d)." %
+         (pointer, len(text1)))
+    return diffs
+
+  #  MATCH FUNCTIONS
+
+  def match_main(self, text, pattern, loc):
+    """Locate the best instance of 'pattern' in 'text' near 'loc'.
+
+    Args:
+      text: The text to search.
+      pattern: The pattern to search for.
+      loc: The location to search around.
+
+    Returns:
+      Best match index or -1.
+    """
+    # Check for null inputs.
+    if text == None or pattern == None:
+      raise ValueError("Null inputs. (match_main)")
+
+    loc = max(0, min(loc, len(text)))
+    if text == pattern:
+      # Shortcut (potentially not guaranteed by the algorithm)
+      return 0
+    elif not text:
+      # Nothing to match.
+      return -1
+    elif text[loc:loc + len(pattern)] == pattern:
+      # Perfect match at the perfect spot!  (Includes case of null pattern)
+      return loc
+    else:
+      # Do a fuzzy compare.
+      match = self.match_bitap(text, pattern, loc)
+      return match
+
+  def match_bitap(self, text, pattern, loc):
+    """Locate the best instance of 'pattern' in 'text' near 'loc' using the
+    Bitap algorithm.
+
+    Args:
+      text: The text to search.
+      pattern: The pattern to search for.
+      loc: The location to search around.
+
+    Returns:
+      Best match index or -1.
+    """
+    # Python doesn't have a maxint limit, so ignore this check.
+    #if self.Match_MaxBits != 0 and len(pattern) > self.Match_MaxBits:
+    #  raise ValueError("Pattern too long for this application.")
+
+    # Initialise the alphabet.
+    s = self.match_alphabet(pattern)
+
+    def match_bitapScore(e, x):
+      """Compute and return the score for a match with e errors and x location.
+      Accesses loc and pattern through being a closure.
+
+      Args:
+        e: Number of errors in match.
+        x: Location of match.
+
+      Returns:
+        Overall score for match (0.0 = good, 1.0 = bad).
+      """
+      accuracy = float(e) / len(pattern)
+      proximity = abs(loc - x)
+      if not self.Match_Distance:
+        # Dodge divide by zero error.
+        return proximity and 1.0 or accuracy
+      return accuracy + (proximity / float(self.Match_Distance))
+
+    # Highest score beyond which we give up.
+    score_threshold = self.Match_Threshold
+    # Is there a nearby exact match? (speedup)
+    best_loc = text.find(pattern, loc)
+    if best_loc != -1:
+      score_threshold = min(match_bitapScore(0, best_loc), score_threshold)
+      # What about in the other direction? (speedup)
+      best_loc = text.rfind(pattern, loc + len(pattern))
+      if best_loc != -1:
+        score_threshold = min(match_bitapScore(0, best_loc), score_threshold)
+
+    # Initialise the bit arrays.
+    matchmask = 1 << (len(pattern) - 1)
+    best_loc = -1
+
+    bin_max = len(pattern) + len(text)
+    # Empty initialization added to appease pychecker.
+    last_rd = None
+    for d in range(len(pattern)):
+      # Scan for the best match each iteration allows for one more error.
+      # Run a binary search to determine how far from 'loc' we can stray at
+      # this error level.
+      bin_min = 0
+      bin_mid = bin_max
+      while bin_min < bin_mid:
+        if match_bitapScore(d, loc + bin_mid) <= score_threshold:
+          bin_min = bin_mid
+        else:
+          bin_max = bin_mid
+        bin_mid = (bin_max - bin_min) // 2 + bin_min
+
+      # Use the result from this iteration as the maximum for the next.
+      bin_max = bin_mid
+      start = max(1, loc - bin_mid + 1)
+      finish = min(loc + bin_mid, len(text)) + len(pattern)
+
+      rd = [0] * (finish + 2)
+      rd[finish + 1] = (1 << d) - 1
+      for j in range(finish, start - 1, -1):
+        if len(text) <= j - 1:
+          # Out of range.
+          charMatch = 0
+        else:
+          charMatch = s.get(text[j - 1], 0)
+        if d == 0:  # First pass: exact match.
+          rd[j] = ((rd[j + 1] << 1) | 1) & charMatch
+        else:  # Subsequent passes: fuzzy match.
+          rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) | (
+              ((last_rd[j + 1] | last_rd[j]) << 1) | 1) | last_rd[j + 1]
+        if rd[j] & matchmask:
+          score = match_bitapScore(d, j - 1)
+          # This match will almost certainly be better than any existing match.
+          # But check anyway.
+          if score <= score_threshold:
+            # Told you so.
+            score_threshold = score
+            best_loc = j - 1
+            if best_loc > loc:
+              # When passing loc, don't exceed our current distance from loc.
+              start = max(1, 2 * loc - best_loc)
             else:
-                # Anything else is an error.
-                raise ValueError, ('Invalid diff operation in diff_fromDelta: ' +
-                                   token[0])
-        if pointer != len(text1):
-            raise ValueError, (
-                'Delta length (%d) does not equal source text length (%d).' %
-                (pointer, len(text1)))
-        return diffs
-
-    #  MATCH FUNCTIONS
-
-    def match_main(self, text, pattern, loc):
-        """Locate the best instance of 'pattern' in 'text' near 'loc'.
-
-        Args:
-          text: The text to search.
-          pattern: The pattern to search for.
-          loc: The location to search around.
-
-        Returns:
-          Best match index or -1.
-
-        """
-        loc = max(0, min(loc, len(text)))
-        if text == pattern:
-            # Shortcut (potentially not guaranteed by the algorithm)
-            return 0
-        elif not text:
-            # Nothing to match.
-            return -1
-        elif text[loc:loc + len(pattern)] == pattern:
-            # Perfect match at the perfect spot!  (Includes case of null
-            # pattern)
-            return loc
-        else:
-            # Do a fuzzy compare.
-            match = self.match_bitap(text, pattern, loc)
-            return match
-
-    def match_bitap(self, text, pattern, loc):
-        """Locate the best instance of 'pattern' in 'text' near 'loc' using the
-        Bitap algorithm.
-
-        Args:
-          text: The text to search.
-          pattern: The pattern to search for.
-          loc: The location to search around.
-
-        Returns:
-          Best match index or -1.
-
-        """
-        # Python doesn't have a maxint limit, so ignore this check.
-        # if self.Match_MaxBits != 0 and len(pattern) > self.Match_MaxBits:
-        #  raise ValueError("Pattern too long for this application.")
-
-        # Initialise the alphabet.
-        s = self.match_alphabet(pattern)
-
-        def match_bitapScore(e, x):
-            """Compute and return the score for a match with e errors and x
-            location. Accesses loc and pattern through being a closure.
-
-            Args:
-              e: Number of errors in match.
-              x: Location of match.
-
-            Returns:
-              Overall score for match (0.0 = good, 1.0 = bad).
-
-            """
-            accuracy = float(e) / len(pattern)
-            proximity = abs(loc - x)
-            if not self.Match_Distance:
-                # Dodge divide by zero error.
-                return proximity and 1.0 or accuracy
-            return accuracy + (proximity / float(self.Match_Distance))
-
-        # Highest score beyond which we give up.
-        score_threshold = self.Match_Threshold
-        # Is there a nearby exact match? (speedup)
-        best_loc = text.find(pattern, loc)
-        if best_loc != -1:
-            score_threshold = min(match_bitapScore(
-                0, best_loc), score_threshold)
-            # What about in the other direction? (speedup)
-            best_loc = text.rfind(pattern, loc + len(pattern))
-            if best_loc != -1:
-                score_threshold = min(match_bitapScore(
-                    0, best_loc), score_threshold)
-
-        # Initialise the bit arrays.
-        matchmask = 1 << (len(pattern) - 1)
-        best_loc = -1
-
-        bin_max = len(pattern) + len(text)
-        # Empty initialization added to appease pychecker.
-        last_rd = None
-        for d in xrange(len(pattern)):
-            # Scan for the best match each iteration allows for one more error.
-            # Run a binary search to determine how far from 'loc' we can stray at
-            # this error level.
-            bin_min = 0
-            bin_mid = bin_max
-            while bin_min < bin_mid:
-                if match_bitapScore(d, loc + bin_mid) <= score_threshold:
-                    bin_min = bin_mid
-                else:
-                    bin_max = bin_mid
-                bin_mid = (bin_max - bin_min) / 2 + bin_min
-
-            # Use the result from this iteration as the maximum for the next.
-            bin_max = bin_mid
-            start = max(1, loc - bin_mid + 1)
-            finish = min(loc + bin_mid, len(text)) + len(pattern)
-
-            rd = range(finish + 1)
-            rd.append((1 << d) - 1)
-            for j in xrange(finish, start - 1, -1):
-                if len(text) <= j - 1:
-                    # Out of range.
-                    charMatch = 0
-                else:
-                    charMatch = s.get(text[j - 1], 0)
-                if d == 0:  # First pass: exact match.
-                    rd[j] = ((rd[j + 1] << 1) | 1) & charMatch
-                else:  # Subsequent passes: fuzzy match.
-                    rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (
-                        ((last_rd[j + 1] | last_rd[j]) << 1) | 1) | last_rd[j + 1]
-                if rd[j] & matchmask:
-                    score = match_bitapScore(d, j - 1)
-                    # This match will almost certainly be better than any existing match.
-                    # But check anyway.
-                    if score <= score_threshold:
-                        # Told you so.
-                        score_threshold = score
-                        best_loc = j - 1
-                        if best_loc > loc:
-                            # When passing loc, don't exceed our current
-                            # distance from loc.
-                            start = max(1, 2 * loc - best_loc)
-                        else:
-                            # Already passed loc, downhill from here on in.
-                            break
-            # No hope for a (better) match at greater error levels.
-            if match_bitapScore(d + 1, loc) > score_threshold:
-                break
-            last_rd = rd
-        return best_loc
-
-    def match_alphabet(self, pattern):
-        """Initialise the alphabet for the Bitap algorithm.
-
-        Args:
-          pattern: The text to encode.
-
-        Returns:
-          Hash of character locations.
-
-        """
-        s = {}
-        for char in pattern:
-            s[char] = 0
-        for i in xrange(len(pattern)):
-            s[pattern[i]] |= 1 << (len(pattern) - i - 1)
-        return s
-
-    #  PATCH FUNCTIONS
-
-    def patch_addContext(self, patch, text):
-        """Increase the context until it is unique, but don't let the pattern
-        expand beyond Match_MaxBits.
-
-        Args:
-          patch: The patch to grow.
-          text: Source text.
-
-        """
-        if len(text) == 0:
-            return
-        pattern = text[patch.start2: patch.start2 + patch.length1]
-        padding = 0
-
-        # Look for the first and last matches of pattern in text.  If two different
-        # matches are found, increase the pattern length.
-        while (text.find(pattern) != text.rfind(pattern) and (self.Match_MaxBits ==
-                                                              0 or len(pattern) < self.Match_MaxBits - self.Patch_Margin -
-                                                              self.Patch_Margin)):
-            padding += self.Patch_Margin
-            pattern = text[max(0, patch.start2 - padding):
-                           patch.start2 + patch.length1 + padding]
-        # Add one chunk for good luck.
-        padding += self.Patch_Margin
-
-        # Add the prefix.
-        prefix = text[max(0, patch.start2 - padding): patch.start2]
-        if prefix:
-            patch.diffs[:0] = [(self.DIFF_EQUAL, prefix)]
-        # Add the suffix.
-        suffix = text[patch.start2 + patch.length1:
-                      patch.start2 + patch.length1 + padding]
-        if suffix:
-            patch.diffs.append((self.DIFF_EQUAL, suffix))
-
-        # Roll back the start points.
-        patch.start1 -= len(prefix)
-        patch.start2 -= len(prefix)
-        # Extend lengths.
-        patch.length1 += len(prefix) + len(suffix)
-        patch.length2 += len(prefix) + len(suffix)
-
-    def patch_make(self, a, b=None, c=None):
-        """Compute a list of patches to turn text1 into text2.
-        Use diffs if provided, otherwise compute it ourselves.
-        There are four ways to call this function, depending on what data is
-        available to the caller:
-        Method 1:
-        a = text1, b = text2
-        Method 2:
-        a = diffs
-        Method 3 (optimal):
-        a = text1, b = diffs
-        Method 4 (deprecated, use method 3):
-        a = text1, b = text2, c = diffs
-
-        Args:
-          a: text1 (methods 1,3,4) or Array of diff tuples for text1 to
-              text2 (method 2).
-          b: text2 (methods 1,4) or Array of diff tuples for text1 to
-              text2 (method 3) or undefined (method 2).
-          c: Array of diff tuples for text1 to text2 (method 4) or
-              undefined (methods 1,2,3).
-
-        Returns:
-          Array of patch objects.
-        """
-        text1 = None
-        diffs = None
-        # Note that texts may arrive as 'str' or 'unicode'.
-        if isinstance(a, basestring) and isinstance(b, basestring) and c is None:
-            # Method 1: text1, text2
-            # Compute diffs from text1 and text2.
-            text1 = a
-            diffs = self.diff_main(text1, b, True)
-            if len(diffs) > 2:
-                self.diff_cleanupSemantic(diffs)
-                self.diff_cleanupEfficiency(diffs)
-        elif isinstance(a, list) and b is None and c is None:
-            # Method 2: diffs
-            # Compute text1 from diffs.
-            diffs = a
-            text1 = self.diff_text1(diffs)
-        elif isinstance(a, basestring) and isinstance(b, list) and c is None:
-            # Method 3: text1, diffs
-            text1 = a
-            diffs = b
-        elif (isinstance(a, basestring) and isinstance(b, basestring) and
-              isinstance(c, list)):
-            # Method 4: text1, text2, diffs
-            # text2 is not used.
-            text1 = a
-            diffs = c
-        else:
-            raise ValueError('Unknown call format to patch_make.')
-
-        if not diffs:
-            return []  # Get rid of the None case.
-        patches = []
+              # Already passed loc, downhill from here on in.
+              break
+      # No hope for a (better) match at greater error levels.
+      if match_bitapScore(d + 1, loc) > score_threshold:
+        break
+      last_rd = rd
+    return best_loc
+
+  def match_alphabet(self, pattern):
+    """Initialise the alphabet for the Bitap algorithm.
+
+    Args:
+      pattern: The text to encode.
+
+    Returns:
+      Hash of character locations.
+    """
+    s = {}
+    for char in pattern:
+      s[char] = 0
+    for i in range(len(pattern)):
+      s[pattern[i]] |= 1 << (len(pattern) - i - 1)
+    return s
+
+  #  PATCH FUNCTIONS
+
+  def patch_addContext(self, patch, text):
+    """Increase the context until it is unique,
+    but don't let the pattern expand beyond Match_MaxBits.
+
+    Args:
+      patch: The patch to grow.
+      text: Source text.
+    """
+    if len(text) == 0:
+      return
+    pattern = text[patch.start2 : patch.start2 + patch.length1]
+    padding = 0
+
+    # Look for the first and last matches of pattern in text.  If two different
+    # matches are found, increase the pattern length.
+    while (text.find(pattern) != text.rfind(pattern) and (self.Match_MaxBits ==
+        0 or len(pattern) < self.Match_MaxBits - self.Patch_Margin -
+        self.Patch_Margin)):
+      padding += self.Patch_Margin
+      pattern = text[max(0, patch.start2 - padding) :
+                     patch.start2 + patch.length1 + padding]
+    # Add one chunk for good luck.
+    padding += self.Patch_Margin
+
+    # Add the prefix.
+    prefix = text[max(0, patch.start2 - padding) : patch.start2]
+    if prefix:
+      patch.diffs[:0] = [(self.DIFF_EQUAL, prefix)]
+    # Add the suffix.
+    suffix = text[patch.start2 + patch.length1 :
+                  patch.start2 + patch.length1 + padding]
+    if suffix:
+      patch.diffs.append((self.DIFF_EQUAL, suffix))
+
+    # Roll back the start points.
+    patch.start1 -= len(prefix)
+    patch.start2 -= len(prefix)
+    # Extend lengths.
+    patch.length1 += len(prefix) + len(suffix)
+    patch.length2 += len(prefix) + len(suffix)
+
+  def patch_make(self, a, b=None, c=None):
+    """Compute a list of patches to turn text1 into text2.
+    Use diffs if provided, otherwise compute it ourselves.
+    There are four ways to call this function, depending on what data is
+    available to the caller:
+    Method 1:
+    a = text1, b = text2
+    Method 2:
+    a = diffs
+    Method 3 (optimal):
+    a = text1, b = diffs
+    Method 4 (deprecated, use method 3):
+    a = text1, b = text2, c = diffs
+
+    Args:
+      a: text1 (methods 1,3,4) or Array of diff tuples for text1 to
+          text2 (method 2).
+      b: text2 (methods 1,4) or Array of diff tuples for text1 to
+          text2 (method 3) or undefined (method 2).
+      c: Array of diff tuples for text1 to text2 (method 4) or
+          undefined (methods 1,2,3).
+
+    Returns:
+      Array of Patch objects.
+    """
+    text1 = None
+    diffs = None
+    if isinstance(a, str) and isinstance(b, str) and c is None:
+      # Method 1: text1, text2
+      # Compute diffs from text1 and text2.
+      text1 = a
+      diffs = self.diff_main(text1, b, True)
+      if len(diffs) > 2:
+        self.diff_cleanupSemantic(diffs)
+        self.diff_cleanupEfficiency(diffs)
+    elif isinstance(a, list) and b is None and c is None:
+      # Method 2: diffs
+      # Compute text1 from diffs.
+      diffs = a
+      text1 = self.diff_text1(diffs)
+    elif isinstance(a, str) and isinstance(b, list) and c is None:
+      # Method 3: text1, diffs
+      text1 = a
+      diffs = b
+    elif (isinstance(a, str) and isinstance(b, str) and
+          isinstance(c, list)):
+      # Method 4: text1, text2, diffs
+      # text2 is not used.
+      text1 = a
+      diffs = c
+    else:
+      raise ValueError("Unknown call format to patch_make.")
+
+    if not diffs:
+      return []  # Get rid of the None case.
+    patches = []
+    patch = patch_obj()
+    char_count1 = 0  # Number of characters into the text1 string.
+    char_count2 = 0  # Number of characters into the text2 string.
+    prepatch_text = text1  # Recreate the patches to determine context info.
+    postpatch_text = text1
+    for x in range(len(diffs)):
+      (diff_type, diff_text) = diffs[x]
+      if len(patch.diffs) == 0 and diff_type != self.DIFF_EQUAL:
+        # A new patch starts here.
+        patch.start1 = char_count1
+        patch.start2 = char_count2
+      if diff_type == self.DIFF_INSERT:
+        # Insertion
+        patch.diffs.append(diffs[x])
+        patch.length2 += len(diff_text)
+        postpatch_text = (postpatch_text[:char_count2] + diff_text +
+                          postpatch_text[char_count2:])
+      elif diff_type == self.DIFF_DELETE:
+        # Deletion.
+        patch.length1 += len(diff_text)
+        patch.diffs.append(diffs[x])
+        postpatch_text = (postpatch_text[:char_count2] +
+                          postpatch_text[char_count2 + len(diff_text):])
+      elif (diff_type == self.DIFF_EQUAL and
+            len(diff_text) <= 2 * self.Patch_Margin and
+            len(patch.diffs) != 0 and len(diffs) != x + 1):
+        # Small equality inside a patch.
+        patch.diffs.append(diffs[x])
+        patch.length1 += len(diff_text)
+        patch.length2 += len(diff_text)
+
+      if (diff_type == self.DIFF_EQUAL and
+          len(diff_text) >= 2 * self.Patch_Margin):
+        # Time for a new patch.
+        if len(patch.diffs) != 0:
+          self.patch_addContext(patch, prepatch_text)
+          patches.append(patch)
+          patch = patch_obj()
+          # Unlike Unidiff, our patch lists have a rolling context.
+          # https://github.com/google/diff-match-patch/wiki/Unidiff
+          # Update prepatch text & pos to reflect the application of the
+          # just completed patch.
+          prepatch_text = postpatch_text
+          char_count1 = char_count2
+
+      # Update the current character count.
+      if diff_type != self.DIFF_INSERT:
+        char_count1 += len(diff_text)
+      if diff_type != self.DIFF_DELETE:
+        char_count2 += len(diff_text)
+
+    # Pick up the leftover patch if not empty.
+    if len(patch.diffs) != 0:
+      self.patch_addContext(patch, prepatch_text)
+      patches.append(patch)
+    return patches
+
+  def patch_deepCopy(self, patches):
+    """Given an array of patches, return another array that is identical.
+
+    Args:
+      patches: Array of Patch objects.
+
+    Returns:
+      Array of Patch objects.
+    """
+    patchesCopy = []
+    for patch in patches:
+      patchCopy = patch_obj()
+      # No need to deep copy the tuples since they are immutable.
+      patchCopy.diffs = patch.diffs[:]
+      patchCopy.start1 = patch.start1
+      patchCopy.start2 = patch.start2
+      patchCopy.length1 = patch.length1
+      patchCopy.length2 = patch.length2
+      patchesCopy.append(patchCopy)
+    return patchesCopy
+
+  def patch_apply(self, patches, text):
+    """Merge a set of patches onto the text.  Return a patched text, as well
+    as a list of true/false values indicating which patches were applied.
+
+    Args:
+      patches: Array of Patch objects.
+      text: Old text.
+
+    Returns:
+      Two element Array, containing the new text and an array of boolean values.
+    """
+    if not patches:
+      return (text, [])
+
+    # Deep copy the patches so that no changes are made to originals.
+    patches = self.patch_deepCopy(patches)
+
+    nullPadding = self.patch_addPadding(patches)
+    text = nullPadding + text + nullPadding
+    self.patch_splitMax(patches)
+
+    # delta keeps track of the offset between the expected and actual location
+    # of the previous patch.  If there are patches expected at positions 10 and
+    # 20, but the first patch was found at 12, delta is 2 and the second patch
+    # has an effective expected position of 22.
+    delta = 0
+    results = []
+    for patch in patches:
+      expected_loc = patch.start2 + delta
+      text1 = self.diff_text1(patch.diffs)
+      end_loc = -1
+      if len(text1) > self.Match_MaxBits:
+        # patch_splitMax will only provide an oversized pattern in the case of
+        # a monster delete.
+        start_loc = self.match_main(text, text1[:self.Match_MaxBits],
+                                    expected_loc)
+        if start_loc != -1:
+          end_loc = self.match_main(text, text1[-self.Match_MaxBits:],
+              expected_loc + len(text1) - self.Match_MaxBits)
+          if end_loc == -1 or start_loc >= end_loc:
+            # Can't find valid trailing context.  Drop this patch.
+            start_loc = -1
+      else:
+        start_loc = self.match_main(text, text1, expected_loc)
+      if start_loc == -1:
+        # No match found.  :(
+        results.append(False)
+        # Subtract the delta for this failed patch from subsequent patches.
+        delta -= patch.length2 - patch.length1
+      else:
+        # Found a match.  :)
+        results.append(True)
+        delta = start_loc - expected_loc
+        if end_loc == -1:
+          text2 = text[start_loc : start_loc + len(text1)]
+        else:
+          text2 = text[start_loc : end_loc + self.Match_MaxBits]
+        if text1 == text2:
+          # Perfect match, just shove the replacement text in.
+          text = (text[:start_loc] + self.diff_text2(patch.diffs) +
+                      text[start_loc + len(text1):])
+        else:
+          # Imperfect match.
+          # Run a diff to get a framework of equivalent indices.
+          diffs = self.diff_main(text1, text2, False)
+          if (len(text1) > self.Match_MaxBits and
+              self.diff_levenshtein(diffs) / float(len(text1)) >
+              self.Patch_DeleteThreshold):
+            # The end points match, but the content is unacceptably bad.
+            results[-1] = False
+          else:
+            self.diff_cleanupSemanticLossless(diffs)
+            index1 = 0
+            for (op, data) in patch.diffs:
+              if op != self.DIFF_EQUAL:
+                index2 = self.diff_xIndex(diffs, index1)
+              if op == self.DIFF_INSERT:  # Insertion
+                text = text[:start_loc + index2] + data + text[start_loc +
+                                                               index2:]
+              elif op == self.DIFF_DELETE:  # Deletion
+                text = text[:start_loc + index2] + text[start_loc +
+                    self.diff_xIndex(diffs, index1 + len(data)):]
+              if op != self.DIFF_DELETE:
+                index1 += len(data)
+    # Strip the padding off.
+    text = text[len(nullPadding):-len(nullPadding)]
+    return (text, results)
+
+  def patch_addPadding(self, patches):
+    """Add some padding on text start and end so that edges can match
+    something.  Intended to be called only from within patch_apply.
+
+    Args:
+      patches: Array of Patch objects.
+
+    Returns:
+      The padding string added to each side.
+    """
+    paddingLength = self.Patch_Margin
+    nullPadding = ""
+    for x in range(1, paddingLength + 1):
+      nullPadding += chr(x)
+
+    # Bump all the patches forward.
+    for patch in patches:
+      patch.start1 += paddingLength
+      patch.start2 += paddingLength
+
+    # Add some padding on start of first diff.
+    patch = patches[0]
+    diffs = patch.diffs
+    if not diffs or diffs[0][0] != self.DIFF_EQUAL:
+      # Add nullPadding equality.
+      diffs.insert(0, (self.DIFF_EQUAL, nullPadding))
+      patch.start1 -= paddingLength  # Should be 0.
+      patch.start2 -= paddingLength  # Should be 0.
+      patch.length1 += paddingLength
+      patch.length2 += paddingLength
+    elif paddingLength > len(diffs[0][1]):
+      # Grow first equality.
+      extraLength = paddingLength - len(diffs[0][1])
+      newText = nullPadding[len(diffs[0][1]):] + diffs[0][1]
+      diffs[0] = (diffs[0][0], newText)
+      patch.start1 -= extraLength
+      patch.start2 -= extraLength
+      patch.length1 += extraLength
+      patch.length2 += extraLength
+
+    # Add some padding on end of last diff.
+    patch = patches[-1]
+    diffs = patch.diffs
+    if not diffs or diffs[-1][0] != self.DIFF_EQUAL:
+      # Add nullPadding equality.
+      diffs.append((self.DIFF_EQUAL, nullPadding))
+      patch.length1 += paddingLength
+      patch.length2 += paddingLength
+    elif paddingLength > len(diffs[-1][1]):
+      # Grow last equality.
+      extraLength = paddingLength - len(diffs[-1][1])
+      newText = diffs[-1][1] + nullPadding[:extraLength]
+      diffs[-1] = (diffs[-1][0], newText)
+      patch.length1 += extraLength
+      patch.length2 += extraLength
+
+    return nullPadding
+
+  def patch_splitMax(self, patches):
+    """Look through the patches and break up any which are longer than the
+    maximum limit of the match algorithm.
+    Intended to be called only from within patch_apply.
+
+    Args:
+      patches: Array of Patch objects.
+    """
+    patch_size = self.Match_MaxBits
+    if patch_size == 0:
+      # Python has the option of not splitting strings due to its ability
+      # to handle integers of arbitrary precision.
+      return
+    for x in range(len(patches)):
+      if patches[x].length1 <= patch_size:
+        continue
+      bigpatch = patches[x]
+      # Remove the big old patch.
+      del patches[x]
+      x -= 1
+      start1 = bigpatch.start1
+      start2 = bigpatch.start2
+      precontext = ''
+      while len(bigpatch.diffs) != 0:
+        # Create one of several smaller patches.
         patch = patch_obj()
-        char_count1 = 0  # Number of characters into the text1 string.
-        char_count2 = 0  # Number of characters into the text2 string.
-        # Recreate the patches to determine context info.
-        prepatch_text = text1
-        postpatch_text = text1
-        for x in xrange(len(diffs)):
-            (diff_type, diff_text) = diffs[x]
-            if len(patch.diffs) == 0 and diff_type != self.DIFF_EQUAL:
-                # A new patch starts here.
-                patch.start1 = char_count1
-                patch.start2 = char_count2
-            if diff_type == self.DIFF_INSERT:
-                # Insertion
-                patch.diffs.append(diffs[x])
-                patch.length2 += len(diff_text)
-                postpatch_text = (postpatch_text[:char_count2] + diff_text +
-                                  postpatch_text[char_count2:])
-            elif diff_type == self.DIFF_DELETE:
-                # Deletion.
-                patch.length1 += len(diff_text)
-                patch.diffs.append(diffs[x])
-                postpatch_text = (postpatch_text[:char_count2] +
-                                  postpatch_text[char_count2 + len(diff_text):])
-            elif (diff_type == self.DIFF_EQUAL and
-                  len(diff_text) <= 2 * self.Patch_Margin and
-                  len(patch.diffs) != 0 and len(diffs) != x + 1):
-                # Small equality inside a patch.
-                patch.diffs.append(diffs[x])
-                patch.length1 += len(diff_text)
-                patch.length2 += len(diff_text)
-
-            if (diff_type == self.DIFF_EQUAL and
-                    len(diff_text) >= 2 * self.Patch_Margin):
-                # Time for a new patch.
-                if len(patch.diffs) != 0:
-                    self.patch_addContext(patch, prepatch_text)
-                    patches.append(patch)
-                    patch = patch_obj()
-                    # Unlike Unidiff, our patch lists have a rolling context.
-                    # http://code.google.com/p/google-diff-match-patch/wiki/Unidiff
-                    # Update prepatch text & pos to reflect the application of the
-                    # just completed patch.
-                    prepatch_text = postpatch_text
-                    char_count1 = char_count2
-
-            # Update the current character count.
-            if diff_type != self.DIFF_INSERT:
-                char_count1 += len(diff_text)
-            if diff_type != self.DIFF_DELETE:
-                char_count2 += len(diff_text)
-
-        # Pick up the leftover patch if not empty.
-        if len(patch.diffs) != 0:
-            self.patch_addContext(patch, prepatch_text)
-            patches.append(patch)
-        return patches
-
-    def patch_deepCopy(self, patches):
-        """Given an array of patches, return another array that is identical.
-
-        Args:
-          patches: Array of patch objects.
-
-        Returns:
-          Array of patch objects.
-
-        """
-        patchesCopy = []
-        for patch in patches:
-            patchCopy = patch_obj()
-            # No need to deep copy the tuples since they are immutable.
-            patchCopy.diffs = patch.diffs[:]
-            patchCopy.start1 = patch.start1
-            patchCopy.start2 = patch.start2
-            patchCopy.length1 = patch.length1
-            patchCopy.length2 = patch.length2
-            patchesCopy.append(patchCopy)
-        return patchesCopy
-
-    def patch_apply(self, patches, text):
-        """Merge a set of patches onto the text.  Return a patched text, as
-        well as a list of true/false values indicating which patches were
-        applied.
-
-        Args:
-          patches: Array of patch objects.
-          text: Old text.
-
-        Returns:
-          Two element Array, containing the new text and an array of boolean values.
-
-        """
-        if not patches:
-            return (text, [])
-
-        # Deep copy the patches so that no changes are made to originals.
-        patches = self.patch_deepCopy(patches)
-
-        nullPadding = self.patch_addPadding(patches)
-        text = nullPadding + text + nullPadding
-        self.patch_splitMax(patches)
-
-        # delta keeps track of the offset between the expected and actual location
-        # of the previous patch.  If there are patches expected at positions 10 and
-        # 20, but the first patch was found at 12, delta is 2 and the second patch
-        # has an effective expected position of 22.
-        delta = 0
-        results = []
-        for patch in patches:
-            expected_loc = patch.start2 + delta
-            text1 = self.diff_text1(patch.diffs)
-            end_loc = -1
-            if len(text1) > self.Match_MaxBits:
-                # patch_splitMax will only provide an oversized pattern in the case of
-                # a monster delete.
-                start_loc = self.match_main(text, text1[:self.Match_MaxBits],
-                                            expected_loc)
-                if start_loc != -1:
-                    end_loc = self.match_main(text, text1[-self.Match_MaxBits:],
-                                              expected_loc + len(text1) - self.Match_MaxBits)
-                    if end_loc == -1 or start_loc >= end_loc:
-                        # Can't find valid trailing context.  Drop this patch.
-                        start_loc = -1
-            else:
-                start_loc = self.match_main(text, text1, expected_loc)
-            if start_loc == -1:
-                # No match found.  :(
-                results.append(False)
-                # Subtract the delta for this failed patch from subsequent
-                # patches.
-                delta -= patch.length2 - patch.length1
-            else:
-                # Found a match.  :)
-                results.append(True)
-                delta = start_loc - expected_loc
-                if end_loc == -1:
-                    text2 = text[start_loc: start_loc + len(text1)]
-                else:
-                    text2 = text[start_loc: end_loc + self.Match_MaxBits]
-                if text1 == text2:
-                    # Perfect match, just shove the replacement text in.
-                    text = (text[:start_loc] + self.diff_text2(patch.diffs) +
-                            text[start_loc + len(text1):])
-                else:
-                    # Imperfect match.
-                    # Run a diff to get a framework of equivalent indices.
-                    diffs = self.diff_main(text1, text2, False)
-                    if (len(text1) > self.Match_MaxBits and
-                            self.diff_levenshtein(diffs) / float(len(text1)) >
-                            self.Patch_DeleteThreshold):
-                        # The end points match, but the content is unacceptably
-                        # bad.
-                        results[-1] = False
-                    else:
-                        self.diff_cleanupSemanticLossless(diffs)
-                        index1 = 0
-                        for (op, data) in patch.diffs:
-                            if op != self.DIFF_EQUAL:
-                                index2 = self.diff_xIndex(diffs, index1)
-                            if op == self.DIFF_INSERT:  # Insertion
-                                text = text[:start_loc + index2] + data + text[start_loc +
-                                                                               index2:]
-                            elif op == self.DIFF_DELETE:  # Deletion
-                                text = text[:start_loc + index2] + text[start_loc +
-                                                                        self.diff_xIndex(diffs, index1 + len(data)):]
-                            if op != self.DIFF_DELETE:
-                                index1 += len(data)
-        # Strip the padding off.
-        text = text[len(nullPadding):-len(nullPadding)]
-        return (text, results)
-
-    def patch_addPadding(self, patches):
-        """Add some padding on text start and end so that edges can match
-        something.  Intended to be called only from within patch_apply.
-
-        Args:
-          patches: Array of patch objects.
-
-        Returns:
-          The padding string added to each side.
-
-        """
-        paddingLength = self.Patch_Margin
-        nullPadding = ''
-        for x in xrange(1, paddingLength + 1):
-            nullPadding += chr(x)
-
-        # Bump all the patches forward.
-        for patch in patches:
-            patch.start1 += paddingLength
-            patch.start2 += paddingLength
-
-        # Add some padding on start of first diff.
-        patch = patches[0]
-        diffs = patch.diffs
-        if not diffs or diffs[0][0] != self.DIFF_EQUAL:
-            # Add nullPadding equality.
-            diffs.insert(0, (self.DIFF_EQUAL, nullPadding))
-            patch.start1 -= paddingLength  # Should be 0.
-            patch.start2 -= paddingLength  # Should be 0.
-            patch.length1 += paddingLength
-            patch.length2 += paddingLength
-        elif paddingLength > len(diffs[0][1]):
-            # Grow first equality.
-            extraLength = paddingLength - len(diffs[0][1])
-            newText = nullPadding[len(diffs[0][1]):] + diffs[0][1]
-            diffs[0] = (diffs[0][0], newText)
-            patch.start1 -= extraLength
-            patch.start2 -= extraLength
-            patch.length1 += extraLength
-            patch.length2 += extraLength
-
-        # Add some padding on end of last diff.
-        patch = patches[-1]
-        diffs = patch.diffs
-        if not diffs or diffs[-1][0] != self.DIFF_EQUAL:
-            # Add nullPadding equality.
-            diffs.append((self.DIFF_EQUAL, nullPadding))
-            patch.length1 += paddingLength
-            patch.length2 += paddingLength
-        elif paddingLength > len(diffs[-1][1]):
-            # Grow last equality.
-            extraLength = paddingLength - len(diffs[-1][1])
-            newText = diffs[-1][1] + nullPadding[:extraLength]
-            diffs[-1] = (diffs[-1][0], newText)
-            patch.length1 += extraLength
-            patch.length2 += extraLength
-
-        return nullPadding
-
-    def patch_splitMax(self, patches):
-        """Look through the patches and break up any which are longer than the
-        maximum limit of the match algorithm.
-
-        Args:
-          patches: Array of patch objects.
-
-        """
-        if self.Match_MaxBits == 0:
-            return
-        for x in xrange(len(patches)):
-            if patches[x].length1 > self.Match_MaxBits:
-                bigpatch = patches[x]
-                # Remove the big old patch.
-                del patches[x]
-                x -= 1
-                patch_size = self.Match_MaxBits
-                start1 = bigpatch.start1
-                start2 = bigpatch.start2
-                precontext = ''
-                while len(bigpatch.diffs) != 0:
-                    # Create one of several smaller patches.
-                    patch = patch_obj()
-                    empty = True
-                    patch.start1 = start1 - len(precontext)
-                    patch.start2 = start2 - len(precontext)
-                    if precontext:
-                        patch.length1 = patch.length2 = len(precontext)
-                        patch.diffs.append((self.DIFF_EQUAL, precontext))
-
-                    while (len(bigpatch.diffs) != 0 and
-                           patch.length1 < patch_size - self.Patch_Margin):
-                        (diff_type, diff_text) = bigpatch.diffs[0]
-                        if diff_type == self.DIFF_INSERT:
-                            # Insertions are harmless.
-                            patch.length2 += len(diff_text)
-                            start2 += len(diff_text)
-                            patch.diffs.append(bigpatch.diffs.pop(0))
-                            empty = False
-                        elif (diff_type == self.DIFF_DELETE and len(patch.diffs) == 1 and
-                              patch.diffs[0][0] == self.DIFF_EQUAL and
-                              len(diff_text) > 2 * patch_size):
-                            # This is a large deletion.  Let it pass in one
-                            # chunk.
-                            patch.length1 += len(diff_text)
-                            start1 += len(diff_text)
-                            empty = False
-                            patch.diffs.append((diff_type, diff_text))
-                            del bigpatch.diffs[0]
-                        else:
-                            # Deletion or equality.  Only take as much as we
-                            # can stomach.
-                            diff_text = diff_text[:patch_size - patch.length1 -
-                                                  self.Patch_Margin]
-                            patch.length1 += len(diff_text)
-                            start1 += len(diff_text)
-                            if diff_type == self.DIFF_EQUAL:
-                                patch.length2 += len(diff_text)
-                                start2 += len(diff_text)
-                            else:
-                                empty = False
-
-                            patch.diffs.append((diff_type, diff_text))
-                            if diff_text == bigpatch.diffs[0][1]:
-                                del bigpatch.diffs[0]
-                            else:
-                                bigpatch.diffs[0] = (bigpatch.diffs[0][0],
-                                                     bigpatch.diffs[0][1][len(diff_text):])
-
-                    # Compute the head context for the next patch.
-                    precontext = self.diff_text2(patch.diffs)
-                    precontext = precontext[-self.Patch_Margin:]
-                    # Append the end context for this patch.
-                    postcontext = self.diff_text1(bigpatch.diffs)[
-                        :self.Patch_Margin]
-                    if postcontext:
-                        patch.length1 += len(postcontext)
-                        patch.length2 += len(postcontext)
-                        if len(patch.diffs) != 0 and patch.diffs[-1][0] == self.DIFF_EQUAL:
-                            patch.diffs[-1] = (self.DIFF_EQUAL, patch.diffs[-1][1] +
-                                               postcontext)
-                        else:
-                            patch.diffs.append((self.DIFF_EQUAL, postcontext))
-
-                    if not empty:
-                        x += 1
-                        patches.insert(x, patch)
-
-    def patch_toText(self, patches):
-        """Take a list of patches and return a textual representation.
-
-        Args:
-          patches: Array of patch objects.
-
-        Returns:
-          Text representation of patches.
-
-        """
-        text = []
-        for patch in patches:
-            text.append(str(patch))
-        return ''.join(text)
-
-    def patch_fromText(self, textline):
-        """Parse a textual representation of patches and return a list of patch
-        objects.
-
-        Args:
-          textline: Text representation of patches.
-
-        Returns:
-          Array of patch objects.
-
-        Raises:
-          ValueError: If invalid input.
-
-        """
-        if type(textline) == unicode:
-            # Patches should be composed of a subset of ascii chars, Unicode not
-            # required.  If this encode raises UnicodeEncodeError, patch is
-            # invalid.
-            textline = textline.encode('ascii')
-        patches = []
-        if not textline:
-            return patches
-        text = textline.split('\n')
-        while len(text) != 0:
-            m = re.match('^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$', text[0])
-            if not m:
-                raise ValueError, 'Invalid patch string: ' + text[0]
-            patch = patch_obj()
-            patches.append(patch)
-            patch.start1 = int(m.group(1))
-            if m.group(2) == '':
-                patch.start1 -= 1
-                patch.length1 = 1
-            elif m.group(2) == '0':
-                patch.length1 = 0
-            else:
-                patch.start1 -= 1
-                patch.length1 = int(m.group(2))
-
-            patch.start2 = int(m.group(3))
-            if m.group(4) == '':
-                patch.start2 -= 1
-                patch.length2 = 1
-            elif m.group(4) == '0':
-                patch.length2 = 0
-            else:
-                patch.start2 -= 1
-                patch.length2 = int(m.group(4))
-
-            del text[0]
-
-            while len(text) != 0:
-                if text[0]:
-                    sign = text[0][0]
-                else:
-                    sign = ''
-                line = urllib.unquote(text[0][1:])
-                line = line.decode('utf-8')
-                if sign == '+':
-                    # Insertion.
-                    patch.diffs.append((self.DIFF_INSERT, line))
-                elif sign == '-':
-                    # Deletion.
-                    patch.diffs.append((self.DIFF_DELETE, line))
-                elif sign == ' ':
-                    # Minor equality.
-                    patch.diffs.append((self.DIFF_EQUAL, line))
-                elif sign == '@':
-                    # Start of next patch.
-                    break
-                elif sign == '':
-                    # Blank line?  Whatever.
-                    pass
-                else:
-                    # WTF?
-                    raise ValueError, "Invalid patch mode: '%s'\n%s" % (sign, line)
-                del text[0]
-        return patches
+        empty = True
+        patch.start1 = start1 - len(precontext)
+        patch.start2 = start2 - len(precontext)
+        if precontext:
+          patch.length1 = patch.length2 = len(precontext)
+          patch.diffs.append((self.DIFF_EQUAL, precontext))
+
+        while (len(bigpatch.diffs) != 0 and
+               patch.length1 < patch_size - self.Patch_Margin):
+          (diff_type, diff_text) = bigpatch.diffs[0]
+          if diff_type == self.DIFF_INSERT:
+            # Insertions are harmless.
+            patch.length2 += len(diff_text)
+            start2 += len(diff_text)
+            patch.diffs.append(bigpatch.diffs.pop(0))
+            empty = False
+          elif (diff_type == self.DIFF_DELETE and len(patch.diffs) == 1 and
+              patch.diffs[0][0] == self.DIFF_EQUAL and
+              len(diff_text) > 2 * patch_size):
+            # This is a large deletion.  Let it pass in one chunk.
+            patch.length1 += len(diff_text)
+            start1 += len(diff_text)
+            empty = False
+            patch.diffs.append((diff_type, diff_text))
+            del bigpatch.diffs[0]
+          else:
+            # Deletion or equality.  Only take as much as we can stomach.
+            diff_text = diff_text[:patch_size - patch.length1 -
+                                  self.Patch_Margin]
+            patch.length1 += len(diff_text)
+            start1 += len(diff_text)
+            if diff_type == self.DIFF_EQUAL:
+              patch.length2 += len(diff_text)
+              start2 += len(diff_text)
+            else:
+              empty = False
+
+            patch.diffs.append((diff_type, diff_text))
+            if diff_text == bigpatch.diffs[0][1]:
+              del bigpatch.diffs[0]
+            else:
+              bigpatch.diffs[0] = (bigpatch.diffs[0][0],
+                                   bigpatch.diffs[0][1][len(diff_text):])
+
+        # Compute the head context for the next patch.
+        precontext = self.diff_text2(patch.diffs)
+        precontext = precontext[-self.Patch_Margin:]
+        # Append the end context for this patch.
+        postcontext = self.diff_text1(bigpatch.diffs)[:self.Patch_Margin]
+        if postcontext:
+          patch.length1 += len(postcontext)
+          patch.length2 += len(postcontext)
+          if len(patch.diffs) != 0 and patch.diffs[-1][0] == self.DIFF_EQUAL:
+            patch.diffs[-1] = (self.DIFF_EQUAL, patch.diffs[-1][1] +
+                               postcontext)
+          else:
+            patch.diffs.append((self.DIFF_EQUAL, postcontext))
+
+        if not empty:
+          x += 1
+          patches.insert(x, patch)
+
+  def patch_toText(self, patches):
+    """Take a list of patches and return a textual representation.
+
+    Args:
+      patches: Array of Patch objects.
+
+    Returns:
+      Text representation of patches.
+    """
+    text = []
+    for patch in patches:
+      text.append(str(patch))
+    return "".join(text)
+
+  def patch_fromText(self, textline):
+    """Parse a textual representation of patches and return a list of patch
+    objects.
+
+    Args:
+      textline: Text representation of patches.
+
+    Returns:
+      Array of Patch objects.
+
+    Raises:
+      ValueError: If invalid input.
+    """
+    patches = []
+    if not textline:
+      return patches
+    text = textline.split('\n')
+    while len(text) != 0:
+      m = re.match("^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$", text[0])
+      if not m:
+        raise ValueError("Invalid patch string: " + text[0])
+      patch = patch_obj()
+      patches.append(patch)
+      patch.start1 = int(m.group(1))
+      if m.group(2) == '':
+        patch.start1 -= 1
+        patch.length1 = 1
+      elif m.group(2) == '0':
+        patch.length1 = 0
+      else:
+        patch.start1 -= 1
+        patch.length1 = int(m.group(2))
+
+      patch.start2 = int(m.group(3))
+      if m.group(4) == '':
+        patch.start2 -= 1
+        patch.length2 = 1
+      elif m.group(4) == '0':
+        patch.length2 = 0
+      else:
+        patch.start2 -= 1
+        patch.length2 = int(m.group(4))
+
+      del text[0]
+
+      while len(text) != 0:
+        if text[0]:
+          sign = text[0][0]
+        else:
+          sign = ''
+        line = urllib.parse.unquote(text[0][1:])
+        if sign == '+':
+          # Insertion.
+          patch.diffs.append((self.DIFF_INSERT, line))
+        elif sign == '-':
+          # Deletion.
+          patch.diffs.append((self.DIFF_DELETE, line))
+        elif sign == ' ':
+          # Minor equality.
+          patch.diffs.append((self.DIFF_EQUAL, line))
+        elif sign == '@':
+          # Start of next patch.
+          break
+        elif sign == '':
+          # Blank line?  Whatever.
+          pass
+        else:
+          # WTF?
+          raise ValueError("Invalid patch mode: '%s'\n%s" % (sign, line))
+        del text[0]
+    return patches
 
 
 class patch_obj:
-    """Class representing one patch operation."""
-
-    def __init__(self):
-        """Initializes with an empty list of diffs."""
-        self.diffs = []
-        self.start1 = None
-        self.start2 = None
-        self.length1 = 0
-        self.length2 = 0
-
-    def __str__(self):
-        """Emmulate GNU diff's format.
-        Header: @@ -382,8 +481,9 @@
-        Indicies are printed as 1-based, not 0-based.
-
-        Returns:
-          The GNU diff string.
-        """
-        if self.length1 == 0:
-            coords1 = str(self.start1) + ',0'
-        elif self.length1 == 1:
-            coords1 = str(self.start1 + 1)
-        else:
-            coords1 = str(self.start1 + 1) + ',' + str(self.length1)
-        if self.length2 == 0:
-            coords2 = str(self.start2) + ',0'
-        elif self.length2 == 1:
-            coords2 = str(self.start2 + 1)
-        else:
-            coords2 = str(self.start2 + 1) + ',' + str(self.length2)
-        text = ['@@ -', coords1, ' +', coords2, ' @@\n']
-        # Escape the body of the patch with %xx notation.
-        for (op, data) in self.diffs:
-            if op == diff_match_patch.DIFF_INSERT:
-                text.append('+')
-            elif op == diff_match_patch.DIFF_DELETE:
-                text.append('-')
-            elif op == diff_match_patch.DIFF_EQUAL:
-                text.append(' ')
-            # High ascii will raise UnicodeDecodeError.  Use Unicode instead.
-            data = data.encode('utf-8')
-            text.append(urllib.quote(data, "!~*'();/?:@&=+$,# ") + '\n')
-        return ''.join(text)
+  """Class representing one patch operation.
+  """
+
+  def __init__(self):
+    """Initializes with an empty list of diffs.
+    """
+    self.diffs = []
+    self.start1 = None
+    self.start2 = None
+    self.length1 = 0
+    self.length2 = 0
+
+  def __str__(self):
+    """Emulate GNU diff's format.
+    Header: @@ -382,8 +481,9 @@
+    Indices are printed as 1-based, not 0-based.
+
+    Returns:
+      The GNU diff string.
+    """
+    if self.length1 == 0:
+      coords1 = str(self.start1) + ",0"
+    elif self.length1 == 1:
+      coords1 = str(self.start1 + 1)
+    else:
+      coords1 = str(self.start1 + 1) + "," + str(self.length1)
+    if self.length2 == 0:
+      coords2 = str(self.start2) + ",0"
+    elif self.length2 == 1:
+      coords2 = str(self.start2 + 1)
+    else:
+      coords2 = str(self.start2 + 1) + "," + str(self.length2)
+    text = ["@@ -", coords1, " +", coords2, " @@\n"]
+    # Escape the body of the patch with %xx notation.
+    for (op, data) in self.diffs:
+      if op == diff_match_patch.DIFF_INSERT:
+        text.append("+")
+      elif op == diff_match_patch.DIFF_DELETE:
+        text.append("-")
+      elif op == diff_match_patch.DIFF_EQUAL:
+        text.append(" ")
+      # High ascii will raise UnicodeDecodeError.  Use Unicode instead.
+      data = data.encode("utf-8")
+      text.append(urllib.parse.quote(data, "!~*'();/?:@&=+$,# ") + "\n")
+    return "".join(text)
\ No newline at end of file

=== modified file 'wiki/feeds.py'
--- wiki/feeds.py	2018-09-12 07:45:35 +0000
+++ wiki/feeds.py	2019-06-09 11:20:50 +0000
@@ -42,8 +42,8 @@
 
 class RssArticleHistoryFeed(Feed):
     feed_type = Rss201rev2Feed
-    title_template = u'wiki/feeds/history_title.html'
-    description_template = u'wiki/feeds/history_description.html'
+    title_template = 'wiki/feeds/history_title.html'
+    description_template = 'wiki/feeds/history_description.html'
 
     def get_object(self, request, *args, **kwargs):
         return Article.objects.get(title=kwargs['title'])

=== modified file 'wiki/management.py'
--- wiki/management.py	2018-04-03 18:57:40 +0000
+++ wiki/management.py	2019-06-09 11:20:50 +0000
@@ -14,4 +14,4 @@
                                         _('an article you observe has changed'))
 
 except ImportError:
-    print 'Skipping creation of NoticeTypes as notification app not found'
+    print('Skipping creation of NoticeTypes as notification app not found')

=== modified file 'wiki/migrations/0001_initial.py'
--- wiki/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ wiki/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 import datetime

=== modified file 'wiki/migrations/0002_auto_20161218_1056.py'
--- wiki/migrations/0002_auto_20161218_1056.py	2016-12-18 14:02:27 +0000
+++ wiki/migrations/0002_auto_20161218_1056.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'wiki/migrations/0003_auto_20180918_0836.py'
--- wiki/migrations/0003_auto_20180918_0836.py	2018-09-18 06:42:18 +0000
+++ wiki/migrations/0003_auto_20180918_0836.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-09-18 08:36
-from __future__ import unicode_literals
+
 
 from django.db import migrations
 

=== modified file 'wiki/models.py'
--- wiki/models.py	2018-09-18 06:42:18 +0000
+++ wiki/models.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 
 # Google Diff Match Patch library
 # http://code.google.com/p/google-diff-match-patch
-from diff_match_patch import diff_match_patch
+from .diff_match_patch import diff_match_patch
 
 from django.db import models
 from django.conf import settings
@@ -35,20 +35,20 @@
     markup_choices = settings.WIKI_MARKUP_CHOICES
 except AttributeError:
     markup_choices = (
-        ('crl', _(u'Creole')),
-        ('rst', _(u'reStructuredText')),
-        ('txl', _(u'Textile')),
-        ('mrk', _(u'Markdown')),
+        ('crl', _('Creole')),
+        ('rst', _('reStructuredText')),
+        ('txl', _('Textile')),
+        ('mrk', _('Markdown')),
     )
 
 
 class Article(models.Model):
     """A wiki page reflecting the actual revision."""
-    title = models.CharField(_(u"Title"), max_length=50, unique=True)
-    content = models.TextField(_(u"Content"))
-    summary = models.CharField(_(u"Summary"), max_length=150,
+    title = models.CharField(_("Title"), max_length=50, unique=True)
+    content = models.TextField(_("Content"))
+    summary = models.CharField(_("Summary"), max_length=150,
                                null=True, blank=True)
-    markup = models.CharField(_(u"Content Markup"), max_length=3,
+    markup = models.CharField(_("Content Markup"), max_length=3,
                               choices=markup_choices,
                               null=True, blank=True)
     creator = models.ForeignKey(User, verbose_name=_('Article Creator'),
@@ -65,8 +65,8 @@
     tags = TagField()
 
     class Meta:
-        verbose_name = _(u'Article')
-        verbose_name_plural = _(u'Articles')
+        verbose_name = _('Article')
+        verbose_name_plural = _('Articles')
         app_label = 'wiki'
         default_permissions = ('change', 'add',)
         ordering = ['title']
@@ -116,7 +116,7 @@
         changeset = self.changeset_set.get(revision=to_revision)
         return changeset.compare_to(from_revision)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
 
 
@@ -134,37 +134,37 @@
 class ChangeSet(models.Model):
     """A report of an older version of some Article."""
 
-    article = models.ForeignKey(Article, verbose_name=_(u"Article"))
+    article = models.ForeignKey(Article, verbose_name=_("Article"))
 
     # Editor identification -- logged
-    editor = models.ForeignKey(User, verbose_name=_(u'Editor'),
+    editor = models.ForeignKey(User, verbose_name=_('Editor'),
                                null=True)
 
     # Revision number, starting from 1
-    revision = models.IntegerField(_(u"Revision Number"))
+    revision = models.IntegerField(_("Revision Number"))
 
     # How to recreate this version
-    old_title = models.CharField(_(u"Old Title"), max_length=50, blank=True)
-    old_markup = models.CharField(_(u"Article Content Markup"), max_length=3,
+    old_title = models.CharField(_("Old Title"), max_length=50, blank=True)
+    old_markup = models.CharField(_("Article Content Markup"), max_length=3,
                                   choices=markup_choices,
                                   null=True, blank=True)
-    content_diff = models.TextField(_(u"Content Patch"), blank=True)
+    content_diff = models.TextField(_("Content Patch"), blank=True)
 
-    comment = models.TextField(_(u"Editor comment"), blank=True)
-    modified = models.DateTimeField(_(u"Modified at"), default=datetime.now)
-    reverted = models.BooleanField(_(u"Reverted Revision"), default=False)
+    comment = models.TextField(_("Editor comment"), blank=True)
+    modified = models.DateTimeField(_("Modified at"), default=datetime.now)
+    reverted = models.BooleanField(_("Reverted Revision"), default=False)
 
     objects = ChangeSetManager()
 
     class Meta:
-        verbose_name = _(u'Change set')
-        verbose_name_plural = _(u'Change sets')
+        verbose_name = _('Change set')
+        verbose_name_plural = _('Change sets')
         get_latest_by = 'modified'
         ordering = ('-revision',)
         app_label = 'wiki'
 
-    def __unicode__(self):
-        return u'#%s' % self.revision
+    def __str__(self):
+        return '#%s' % self.revision
 
     def get_absolute_url(self):
         if self.article.group is None:
@@ -245,10 +245,10 @@
         return content
 
     def compare_to(self, revision_from):
-        other_content = u""
-        if revision_from > 0:
+        other_content = ""
+        if int(revision_from) > 0:
             other_content = ChangeSet.objects.filter(
                 article=self.article, revision__lte=revision_from).order_by('-revision')[0].get_content()
         diffs = dmp.diff_main(other_content, self.get_content())
-        dmp.diff_cleanupSemantic(diffs)
+        #dmp.diff_cleanupSemantic(diffs)
         return dmp.diff_prettyHtml(diffs)

=== modified file 'wiki/static/css/wiki.css'
--- wiki/static/css/wiki.css	2018-11-22 17:50:41 +0000
+++ wiki/static/css/wiki.css	2019-06-09 11:20:50 +0000
@@ -136,3 +136,16 @@
 	display: block;
 	margin: auto;
 }
+
+/*********************/
+/* diff_match_patch */
+/*********************/
+ins.inserted {
+	text-decoration: none;
+	color: #00FF00;
+}
+
+del.removed {
+	text-decoration: none;
+	color: #FF0000;
+}

=== modified file 'wiki/templatetags/restructuredtext.py'
--- wiki/templatetags/restructuredtext.py	2016-12-13 18:28:51 +0000
+++ wiki/templatetags/restructuredtext.py	2019-06-09 11:20:50 +0000
@@ -16,7 +16,7 @@
         from docutils.core import publish_parts
     except ImportError:
         if settings.DEBUG:
-            raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed."
+            raise template.TemplateSyntaxError("Error in {% restructuredtext %} filter: The Python docutils library isn't installed.")
         return value
     else:
         docutils_settings = dict(

=== modified file 'wiki/templatetags/wiki_extras.py'
--- wiki/templatetags/wiki_extras.py	2018-04-08 15:53:05 +0000
+++ wiki/templatetags/wiki_extras.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 import re
 from django import template
 from django.conf import settings
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
 from django.utils.safestring import mark_safe
 
 
@@ -15,7 +15,7 @@
     """We need to restore " " for textile to work properly."""
     s = s.replace('&quot;', '"')
     s = s.replace('&quot;', '"')
-    return force_unicode(s)
+    return force_text(s)
 restore_commandsymbols.is_safe = True
 
 

=== modified file 'wiki/views.py'
--- wiki/views.py	2019-03-31 11:08:21 +0000
+++ wiki/views.py	2019-06-09 11:20:50 +0000
@@ -24,7 +24,7 @@
 from mainpage.wl_utils import get_valid_cache_key
 
 import re
-import urllib
+import urllib.request, urllib.parse, urllib.error
 
 # Settings
 #  lock duration in minutes
@@ -662,7 +662,7 @@
         for regexp in search_title:
             # Need to unqoute the content to match
             # e.g. [[ Back | Title%20of%20Page ]]
-            match = regexp.search(urllib.unquote(article.content))
+            match = regexp.search(urllib.parse.unquote(article.content))
             if match:
                 found_links.append({'title': article.title})
 

=== modified file 'wlevents/admin.py'
--- wlevents/admin.py	2016-12-13 18:28:51 +0000
+++ wlevents/admin.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 #!/usr/bin/env python -tt
 # encoding: utf-8
 
-from models import Event
+from .models import Event
 from django.contrib import admin
 
 

=== modified file 'wlevents/migrations/0001_initial.py'
--- wlevents/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ wlevents/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'wlevents/templatetags/wlevents_extras.py'
--- wlevents/templatetags/wlevents_extras.py	2016-12-13 18:28:51 +0000
+++ wlevents/templatetags/wlevents_extras.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 
 from wlevents.models import Event
 from django import template
-from urllib import urlencode, quote
+from urllib.parse import urlencode, quote
 
 import datetime
 

=== modified file 'wlevents/tests.py'
--- wlevents/tests.py	2016-12-13 18:28:51 +0000
+++ wlevents/tests.py	2019-06-09 11:20:50 +0000
@@ -14,7 +14,7 @@
         """
         Tests that 1 + 1 always equals 2.
         """
-        self.failUnlessEqual(1 + 1, 2)
+        self.assertEqual(1 + 1, 2)
 
 __test__ = {'doctest': """
 Another way to test that 1 + 1 is equal to 2.

=== modified file 'wlggz/admin.py'
--- wlggz/admin.py	2016-12-13 18:28:51 +0000
+++ wlggz/admin.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 
 from django.utils.translation import ugettext_lazy as _
 from django.contrib import admin
-from models import GGZAuth
+from .models import GGZAuth
 
 
 class GGZAdmin(admin.ModelAdmin):

=== modified file 'wlggz/forms.py'
--- wlggz/forms.py	2019-05-15 17:22:54 +0000
+++ wlggz/forms.py	2019-06-09 11:20:50 +0000
@@ -7,12 +7,12 @@
 #
 
 from django import forms
-from models import GGZAuth
+from .models import GGZAuth
 from django.utils.translation import ugettext_lazy as _
 
 
 class EditGGZForm(forms.ModelForm):
-    password = forms.CharField(label=_(u'Online Gaming Password'),
+    password = forms.CharField(label=_('Online Gaming Password'),
                                widget=forms.PasswordInput(render_value=False), required=True)
     password2 = forms.CharField(label=_(u'Enter the password again'),
                                widget=forms.PasswordInput(render_value=False), required=True)

=== modified file 'wlggz/migrations/0001_initial.py'
--- wlggz/migrations/0001_initial.py	2019-03-31 11:08:21 +0000
+++ wlggz/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 from django.conf import settings

=== modified file 'wlggz/migrations/0002_auto_20160805_2004.py'
--- wlggz/migrations/0002_auto_20160805_2004.py	2016-08-05 18:20:29 +0000
+++ wlggz/migrations/0002_auto_20160805_2004.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'wlggz/urls.py'
--- wlggz/urls.py	2016-12-13 18:28:51 +0000
+++ wlggz/urls.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 #
 
 from django.conf.urls import *
-import views
+from . import views
 
 urlpatterns = [
     url(r'^changepw$', views.change_password, name='wlggz_changepw'),

=== modified file 'wlggz/views.py'
--- wlggz/views.py	2019-05-16 06:21:02 +0000
+++ wlggz/views.py	2019-06-09 11:20:50 +0000
@@ -7,7 +7,7 @@
 from django.http import HttpResponseRedirect
 from django.contrib import messages
 
-from forms import EditGGZForm
+from .forms import EditGGZForm
 
 
 @login_required

=== modified file 'wlhelp/management/commands/update_help.py'
--- wlhelp/management/commands/update_help.py	2019-03-31 11:08:21 +0000
+++ wlhelp/management/commands/update_help.py	2019-06-09 11:20:50 +0000
@@ -48,9 +48,9 @@
         base_directory = os.path.normpath(settings.WIDELANDS_SVN_DIR + '/data')
         json_directory = os.path.normpath(settings.MEDIA_ROOT + '/map_object_info')
 
-        tribeinfo_file = open(os.path.normpath(
-            json_directory + '/tribe_' + name + '.json'), 'r')
-        tribeinfo = json.load(tribeinfo_file)
+        with open(os.path.normpath(
+            json_directory + '/tribe_' + name + '.json'), 'r') as tribeinfo_file:
+            tribeinfo = json.load(tribeinfo_file)
 
         self._tribe = Tribe(tribeinfo, json_directory)
         # Generate the Tribe
@@ -62,7 +62,7 @@
                               (settings.MEDIA_ROOT, tribeinfo['name']))
         try:
             os.makedirs(dn)
-        except OSError, o:
+        except OSError as o:
             if o.errno != 17:
                 raise
         new_name = path.join(dn, 'icon.png')
@@ -77,17 +77,17 @@
         self._delete_old_data(
             tribename)  # You can deactivate this line if you don't need to clean house.
 
-        wares_file = open(os.path.normpath(
-            json_directory + '/' + tribename + '_wares.json'), 'r')
-        self._parse_wares(base_directory, json.load(wares_file))
-
-        workers_file = open(os.path.normpath(
-            json_directory + '/' + tribename + '_workers.json'), 'r')
-        self._parse_workers(base_directory, json.load(workers_file))
-
-        buildings_file = open(os.path.normpath(
-            json_directory + '/' + tribename + '_buildings.json'), 'r')
-        self._parse_buildings(base_directory, json.load(buildings_file))
+        with open(os.path.normpath(
+            json_directory + '/' + tribename + '_wares.json'), 'r') as wares_file:
+            self._parse_wares(base_directory, json.load(wares_file))
+
+        with open(os.path.normpath(
+            json_directory + '/' + tribename + '_workers.json'), 'r') as workers_file:
+            self._parse_workers(base_directory, json.load(workers_file))
+
+        with open(os.path.normpath(
+            json_directory + '/' + tribename + '_buildings.json'), 'r') as buildings_file:
+            self._parse_buildings(base_directory, json.load(buildings_file))
 
     def graph(self):
         """Make all graphs."""
@@ -102,13 +102,14 @@
                     url = self._copy_picture(
                         path.join(fpath, 'menu.png'), inst.name, 'graph.png')
                     inst.graph_url = url
-                    inst.imagemap = open(path.join(fpath, 'map.map')).read()
+                    with open(path.join(fpath, 'map.map')) as map_file:
+                        inst.imagemap = map_file.read()
                     inst.imagemap = self.map_mouseover_pattern.sub(
                         r"\1Show the \2 \3\4", inst.imagemap)
                     inst.save()
-                except Exception, e:
-                    print 'Exception while handling', cls, 'of', self._tribe.name, ':', inst.name
-                    print type(e), e, repr(e)
+                except Exception as e:
+                    print('Exception while handling', cls, 'of', self._tribe.name, ':', inst.name)
+                    print(type(e), e, repr(e))
 
         shutil.rmtree(tdir)
 
@@ -147,7 +148,7 @@
                               (settings.MEDIA_ROOT, self._to.name, name))
         try:
             os.makedirs(dn)
-        except OSError, o:
+        except OSError as o:
             if o.errno != 17:
                 raise
         new_name = path.join(dn, fname)
@@ -157,10 +158,10 @@
 
     def _parse_workers(self, base_directory, workersinfo):
         """Put the workers into the database."""
-        print '  parsing workers'
+        print('  parsing workers')
 
         for worker in workersinfo['workers']:
-            print '    ' + worker['name']
+            print('    ' + worker['name'])
             nn = self._copy_picture(os.path.normpath(
                 base_directory + '/' + worker['icon']), worker['name'], 'menu.png')
 
@@ -187,10 +188,10 @@
             workero.save()
 
     def _parse_wares(self, base_directory, waresinfo):
-        print '  parsing wares'
+        print('  parsing wares')
 
         for ware in waresinfo['wares']:
-            print '    ' + ware['name']
+            print('    ' + ware['name'])
             nn = self._copy_picture(os.path.normpath(
                 base_directory + '/' + ware['icon']), ware['name'], 'menu.png')
 
@@ -213,16 +214,16 @@
             # be made, e.g. build_cost and build_wares in 
             # models.get_build_cost() and other functions over there.
             element_set = collections.OrderedDict(sorted(element_set.items()))
-            counts = ' '.join(element_set.values())
+            counts = ' '.join(list(element_set.values()))
             objects = [objtype.objects.get_or_create(name=w, tribe=self._to)[
-                0] for w in element_set.keys()]
+                0] for w in list(element_set.keys())]
             return counts, objects
 
         enhancement_hierarchy = []
-        print '  parsing buildings'
+        print('  parsing buildings')
 
         for building in buildingsinfo['buildings']:
-            print '    ' + building['name']
+            print('    ' + building['name'])
             b = BuildingModel.objects.get_or_create(
                 tribe=self._to, name=building['name'])[0]
             b.displayname = building['descname']
@@ -274,7 +275,7 @@
             try:
                 b.enhancement = BuildingModel.objects.get(
                     name=tgt, tribe=self._to)
-            except Exception, e:
+            except Exception as e:
                 raise
             b.save()
 
@@ -290,7 +291,7 @@
         if not os.path.exists(json_directory):
             os.makedirs(json_directory)
 
-        print('JSON files will be written to: ' + json_directory)
+        print(('JSON files will be written to: ' + json_directory))
 
         # First, we make sure that JSON files have been generated.
         current_dir = os.path.dirname(os.path.realpath(__file__))
@@ -308,8 +309,8 @@
         validator_script = os.path.normpath(
             settings.WIDELANDS_SVN_DIR + '/utils/validate_json.py')
         if not os.path.isfile(validator_script):
-            print("Wrong path for 'utils/validate_json.py': " +
-                  validator_script + ' does not exist!')
+            print(("Wrong path for 'utils/validate_json.py': " +
+                  validator_script + ' does not exist!'))
             sys.exit(1)
         try:
             subprocess.check_call(
@@ -324,13 +325,13 @@
         # We regenerate the encyclopedia only if the JSON files passed the
         # syntax check
         if is_json_valid:
-            source_file = open(os.path.normpath(
-                json_directory + '/tribes.json'), 'r')
-            tribesinfo = json.load(source_file)
+            with open(os.path.normpath(
+                json_directory + '/tribes.json'), 'r') as source_file:
+                tribesinfo = json.load(source_file)
 
             for t in tribesinfo['tribes']:
                 tribename = t['name']
-                print 'updating help for tribe ', tribename
+                print('updating help for tribe ', tribename)
                 p = TribeParser(tribename)
                 p.parse(tribename, directory, json_directory)
                 p.graph()

=== modified file 'wlhelp/management/commands/update_help_pdf.py'
--- wlhelp/management/commands/update_help_pdf.py	2019-03-31 11:08:21 +0000
+++ wlhelp/management/commands/update_help_pdf.py	2019-06-09 11:20:50 +0000
@@ -18,15 +18,15 @@
         """Update the overview pdfs of all tribes in a current checkout"""
 
     def handle(self, json_directory=os.path.normpath(settings.MEDIA_ROOT + '/map_object_info'), **kwargs):
-        source_file = open(os.path.normpath(
-            json_directory + '/tribes.json'), 'r')
-        tribesinfo = json.load(source_file)
+        with open(os.path.normpath(
+                json_directory + '/tribes.json'), 'r') as source_file:
+            tribesinfo = json.load(source_file)
 
-        print 'updating pdf files for all tribes'
+        print('updating pdf files for all tribes')
 
         for t in tribesinfo['tribes']:
             tribename = t['name']
-            print '  updating pdf file for tribe ', tribename
+            print('  updating pdf file for tribe ', tribename)
             gdir = make_graph(tribename)
             pdffile = path.join(gdir, tribename + '.pdf')
             giffile = path.join(gdir, tribename + '.gif')
@@ -50,6 +50,6 @@
                     '%s/%s/%s' % (settings.MEDIA_URL, targetdir[len(settings.MEDIA_ROOT):], tribename + '.gif'))
                 tribe.save()
             else:
-                print 'Could not set tribe urls'
+                print('Could not set tribe urls')
 
             shutil.rmtree(gdir)

=== modified file 'wlhelp/migrations/0001_initial.py'
--- wlhelp/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ wlhelp/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'wlhelp/migrations/0002_auto_20190410_1734.py'
--- wlhelp/migrations/0002_auto_20190410_1734.py	2019-04-10 16:01:43 +0000
+++ wlhelp/migrations/0002_auto_20190410_1734.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.20 on 2019-04-10 17:34
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 

=== modified file 'wlhelp/models.py'
--- wlhelp/models.py	2018-05-02 06:33:13 +0000
+++ wlhelp/models.py	2019-06-09 11:20:50 +0000
@@ -13,8 +13,8 @@
         ordering = ['name']
 
 
-    def __unicode__(self):
-        return u'%s' % self.name
+    def __str__(self):
+        return '%s' % self.name
 
 
 class Worker(models.Model):
@@ -38,8 +38,8 @@
         ordering = ['name']
 
 
-    def __unicode__(self):
-        return u'%s' % self.name
+    def __str__(self):
+        return '%s' % self.name
 
 
 class Ware(models.Model):
@@ -59,8 +59,8 @@
         ordering = ['name']
 
 
-    def __unicode__(self):
-        return u'%s' % self.name
+    def __str__(self):
+        return '%s' % self.name
 
 
 class BuildingManager(models.Manager):
@@ -168,7 +168,7 @@
     def get_build_cost(self):
         # Creating the relation between build_cost and build_wares
         # Querying the wares returns the wares in alphabetical order!
-        count = map(int, self.build_costs.split())
+        count = list(map(int, self.build_costs.split()))
         for c, w in zip(count, self.build_wares.all()):
             yield [w] * c
 
@@ -176,7 +176,7 @@
         return (self.workers_types.all().count() != 0)
 
     def get_workers(self):
-        count = map(int, self.workers_count.split())
+        count = list(map(int, self.workers_count.split()))
         for c, wor in zip(count, self.workers_types.all()):
             yield [wor] * c
 
@@ -199,9 +199,9 @@
         return (self.store_wares.all().count() != 0)
 
     def get_stored_wares(self):
-        count = map(int, self.store_count.split())
+        count = list(map(int, self.store_count.split()))
         for c, w in zip(count, self.store_wares.all()):
             yield [w] * c
 
-    def __unicode__(self):
-        return u"%s/%s" % (self.tribe.name, self.name)
+    def __str__(self):
+        return "%s/%s" % (self.tribe.name, self.name)

=== modified file 'wlhelp/tests.py'
--- wlhelp/tests.py	2016-07-02 12:38:06 +0000
+++ wlhelp/tests.py	2019-06-09 11:20:50 +0000
@@ -14,7 +14,7 @@
         """
         Tests that 1 + 1 always equals 2.
         """
-        self.failUnlessEqual(1 + 1, 2)
+        self.assertEqual(1 + 1, 2)
 
 __test__ = {'doctest': """
 Another way to test that 1 + 1 is equal to 2.

=== modified file 'wlhelp/urls.py'
--- wlhelp/urls.py	2018-03-09 11:26:52 +0000
+++ wlhelp/urls.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 #
 
 from django.conf.urls import *
-from views import *
+from .views import *
 
 urlpatterns = [
     url(r'^$', index, name='wlhelp_index'),

=== modified file 'wlimages/admin.py'
--- wlimages/admin.py	2018-09-18 07:02:26 +0000
+++ wlimages/admin.py	2019-06-09 11:20:50 +0000
@@ -11,7 +11,7 @@
 
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
-from models import Image
+from .models import Image
 
 
 def delete_with_file(modeladmin, request, queryset):
@@ -24,7 +24,7 @@
 
 class ImageAdmin(admin.ModelAdmin):
     readonly_fields = ('content_object', 'content_type', 'object_id')
-    list_display = ('__unicode__', 'date_submitted', 'content_type', 'user')
+    list_display = ('__str__', 'date_submitted', 'content_type', 'user')
     list_filter = ('date_submitted',)
     date_hierarchy = 'date_submitted'
     search_fields = ('image', 'user__username')

=== modified file 'wlimages/forms.py'
--- wlimages/forms.py	2016-12-13 18:28:51 +0000
+++ wlimages/forms.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 from django import forms
-from models import Image
+from .models import Image
 
 import os
 

=== modified file 'wlimages/migrations/0001_initial.py'
--- wlimages/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ wlimages/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 import datetime

=== modified file 'wlimages/migrations/0002_remove_image_url.py'
--- wlimages/migrations/0002_remove_image_url.py	2016-11-27 19:24:29 +0000
+++ wlimages/migrations/0002_remove_image_url.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 

=== modified file 'wlimages/migrations/0003_remove_image_editor_ip.py'
--- wlimages/migrations/0003_remove_image_editor_ip.py	2018-09-18 07:02:26 +0000
+++ wlimages/migrations/0003_remove_image_editor_ip.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-09-18 09:01
-from __future__ import unicode_literals
+
 
 from django.db import migrations
 

=== modified file 'wlimages/models.py'
--- wlimages/models.py	2019-03-31 11:08:21 +0000
+++ wlimages/models.py	2019-06-09 11:20:50 +0000
@@ -78,7 +78,7 @@
 
     objects = ImageManager()
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
     def get_content_object(self):

=== modified file 'wlimages/templatetags/wlimages_extras.py'
--- wlimages/templatetags/wlimages_extras.py	2016-12-13 18:28:51 +0000
+++ wlimages/templatetags/wlimages_extras.py	2019-06-09 11:20:50 +0000
@@ -20,11 +20,11 @@
     try:
         split = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if split[1] != 'as':
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     if len(split) != 3:
-        raise template.TemplateSyntaxError, error_message
+        raise template.TemplateSyntaxError(error_message)
     return UploadFormNode(split[2])
 
 

=== modified file 'wlimages/tests.py'
--- wlimages/tests.py	2018-04-08 14:40:17 +0000
+++ wlimages/tests.py	2019-06-09 11:20:50 +0000
@@ -17,7 +17,7 @@
 sys.path.append('..')
 
 import PIL
-from cStringIO import StringIO
+from io import StringIO
 
 from django.test import TestCase
 from django.contrib.contenttypes.models import ContentType
@@ -27,10 +27,10 @@
 from django.urls import reverse
 from django.db import IntegrityError
 
-from models import Image
-from forms import UploadImageForm
+from .models import Image
+from .forms import UploadImageForm
 
-from views import upload
+from .views import upload
 
 
 class _TestUploadingBase(TestCase):

=== modified file 'wlimages/urls.py'
--- wlimages/urls.py	2016-12-13 18:28:51 +0000
+++ wlimages/urls.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 from django.conf.urls import *
-from views import *
+from .views import *
 
 urlpatterns = [
     url(r'^upload/(?P<content_type>\d+)/(?P<object_id>\d+)/(?P<next>.*)$',

=== modified file 'wlimages/views.py'
--- wlimages/views.py	2018-09-19 18:45:57 +0000
+++ wlimages/views.py	2019-06-09 11:20:50 +0000
@@ -3,8 +3,8 @@
 from django.http import HttpResponse, HttpResponseRedirect
 from django.shortcuts import get_object_or_404, render
 
-from models import Image
-from forms import UploadImageForm
+from .models import Image
+from .forms import UploadImageForm
 
 
 def display(request, image, revision):
@@ -37,7 +37,7 @@
 
     # Get the App (model) to which this image belongs to:
     app = ContentType.objects.get(id=content_type)
-    # Get the current object's name (provided by __unicode__()) from this model
+    # Get the current object's name (provided by __str__()) from this model
     name = app.get_object_for_this_type(id=object_id)
 
     return render(request, 'wlimages/upload.html', {

=== modified file 'wlmaps/admin.py'
--- wlmaps/admin.py	2018-02-22 08:49:03 +0000
+++ wlmaps/admin.py	2019-06-09 11:20:50 +0000
@@ -2,7 +2,7 @@
 # encoding: utf-8
 #
 
-from models import Map
+from .models import Map
 from django.contrib import admin
 
 

=== modified file 'wlmaps/management.py'
--- wlmaps/management.py	2018-04-03 18:57:40 +0000
+++ wlmaps/management.py	2019-06-09 11:20:50 +0000
@@ -10,4 +10,4 @@
                                         _('A new Map is available'),
                                         _('a new map is available for download'), 1)
 except ImportError:
-    print 'Skipping creation of NoticeTypes as notification app not found'
+    print('Skipping creation of NoticeTypes as notification app not found')

=== modified file 'wlmaps/migrations/0001_initial.py'
--- wlmaps/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ wlmaps/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 import datetime

=== modified file 'wlmaps/migrations/0002_auto_20181119_1855.py'
--- wlmaps/migrations/0002_auto_20181119_1855.py	2018-11-19 18:03:21 +0000
+++ wlmaps/migrations/0002_auto_20181119_1855.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-11-19 18:55
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 

=== modified file 'wlmaps/models.py'
--- wlmaps/models.py	2019-03-04 17:46:34 +0000
+++ wlmaps/models.py	2019-06-09 11:20:50 +0000
@@ -44,8 +44,8 @@
     def get_absolute_url(self):
         return reverse('wlmaps_view', kwargs={'map_slug': self.slug})
 
-    def __unicode__(self):
-        return u'%s by %s' % (self.name, self.author)
+    def __str__(self):
+        return '%s by %s' % (self.name, self.author)
 
     def save(self, *args, **kwargs):
         if not self.slug:

=== modified file 'wlmaps/tests/__init__.py'
--- wlmaps/tests/__init__.py	2016-12-13 18:28:51 +0000
+++ wlmaps/tests/__init__.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 #!/usr/bin/env python -tt
 # encoding: utf-8
 
-from test_views import *
-from test_models import *
+from .test_views import *
+from .test_models import *

=== modified file 'wlmaps/urls.py'
--- wlmaps/urls.py	2018-11-18 17:22:39 +0000
+++ wlmaps/urls.py	2019-06-09 11:20:50 +0000
@@ -1,8 +1,8 @@
 #!/usr/bin/env python -tt
 # encoding: utf-8
 from django.conf.urls import *
-from models import Map
-from views import *
+from .models import Map
+from .views import *
 
 
 urlpatterns = [

=== modified file 'wlmaps/views.py'
--- wlmaps/views.py	2019-03-31 11:08:21 +0000
+++ wlmaps/views.py	2019-06-09 11:20:50 +0000
@@ -2,13 +2,13 @@
 # encoding: utf-8
 #
 
-from forms import UploadMapForm, EditCommentForm
+from .forms import UploadMapForm, EditCommentForm
 from django.shortcuts import render, get_object_or_404
 from django.contrib.auth.decorators import login_required
 from django.http import HttpResponseRedirect, HttpResponseNotAllowed, HttpResponse, HttpResponseBadRequest
 from django.urls import reverse
 from django.conf import settings
-import models
+from . import models
 
 from mainpage.wl_utils import get_real_ip
 import os

=== modified file 'wlpoll/admin.py'
--- wlpoll/admin.py	2016-12-13 18:28:51 +0000
+++ wlpoll/admin.py	2019-06-09 11:20:50 +0000
@@ -2,7 +2,7 @@
 # encoding: utf-8
 #
 
-from models import Poll, Choice
+from .models import Poll, Choice
 from django.contrib import admin
 
 

=== modified file 'wlpoll/migrations/0001_initial.py'
--- wlpoll/migrations/0001_initial.py	2016-12-13 18:28:51 +0000
+++ wlpoll/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 import datetime

=== modified file 'wlpoll/models.py'
--- wlpoll/models.py	2018-04-08 16:23:55 +0000
+++ wlpoll/models.py	2019-06-09 11:20:50 +0000
@@ -37,7 +37,7 @@
     def get_absolute_url(self):
         return reverse('wlpoll_detail', kwargs={'pk': self.id})
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
 
@@ -46,8 +46,8 @@
     choice = models.CharField(max_length=256)
     votes = models.PositiveIntegerField(default=0)
 
-    def __unicode__(self):
-        return u"%i:%s" % (self.votes, self.choice)
+    def __str__(self):
+        return "%i:%s" % (self.votes, self.choice)
 
 
 class Vote(models.Model):

=== modified file 'wlpoll/templatetags/wlpoll_extras.py'
--- wlpoll/templatetags/wlpoll_extras.py	2017-09-23 08:52:36 +0000
+++ wlpoll/templatetags/wlpoll_extras.py	2019-06-09 11:20:50 +0000
@@ -4,7 +4,7 @@
 
 from wlpoll.models import Choice, Poll
 from django import template
-from urllib import urlencode, quote
+from urllib.parse import urlencode, quote
 
 register = template.Library()
 
@@ -69,7 +69,7 @@
     try:
         tag_name, poll_var = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, '%r tag requires a single argument' % token.contents.split()[0]
+        raise template.TemplateSyntaxError('%r tag requires a single argument' % token.contents.split()[0])
 
     return DisplayPollNode(poll_var)
 
@@ -95,7 +95,7 @@
     try:
         tag_name, as_name, variable = token.split_contents()
     except ValueError:
-        raise template.TemplateSyntaxError, 'required: %r as <variable name>' % token.contents.split()[0]
+        raise template.TemplateSyntaxError('required: %r as <variable name>' % token.contents.split()[0])
 
     return GetOpenPolls(variable)
 

=== modified file 'wlpoll/tests.py'
--- wlpoll/tests.py	2016-12-13 18:28:51 +0000
+++ wlpoll/tests.py	2019-06-09 11:20:50 +0000
@@ -14,7 +14,7 @@
         """
         Tests that 1 + 1 always equals 2.
         """
-        self.failUnlessEqual(1 + 1, 2)
+        self.assertEqual(1 + 1, 2)
 
 __test__ = {'doctest': """
 Another way to test that 1 + 1 is equal to 2.

=== modified file 'wlpoll/urls.py'
--- wlpoll/urls.py	2016-12-13 18:28:51 +0000
+++ wlpoll/urls.py	2019-06-09 11:20:50 +0000
@@ -2,7 +2,7 @@
 # encoding: utf-8
 #
 
-from models import Poll
+from .models import Poll
 from django.conf.urls import *
 from . import views
 from django.views.generic.dates import ArchiveIndexView

=== modified file 'wlpoll/views.py'
--- wlpoll/views.py	2018-04-08 14:40:17 +0000
+++ wlpoll/views.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 from django.template import RequestContext
 from django.http import HttpResponseNotAllowed, HttpResponseRedirect, HttpResponseForbidden
 from django.urls import reverse
-from models import Poll, Choice, Vote
+from .models import Poll, Choice, Vote
 from django.views import generic
 
 

=== modified file 'wlprofile/admin.py'
--- wlprofile/admin.py	2019-01-18 11:10:27 +0000
+++ wlprofile/admin.py	2019-06-09 11:20:50 +0000
@@ -11,7 +11,7 @@
 
 from django.utils.translation import ugettext_lazy as _
 from django.contrib import admin
-from models import Profile
+from .models import Profile
 from django.contrib.auth.models import User
 from django.contrib.auth.admin import UserAdmin
 

=== modified file 'wlprofile/fields.py'
--- wlprofile/fields.py	2016-12-13 18:28:51 +0000
+++ wlprofile/fields.py	2019-06-09 11:20:50 +0000
@@ -1,4 +1,4 @@
-from StringIO import StringIO
+from io import BytesIO
 from django.db import models
 import logging
 from django.core.files.uploadedfile import SimpleUploadedFile
@@ -30,7 +30,7 @@
         """Resize image to fit it into (width, height) box."""
         from PIL import Image
 
-        image = Image.open(StringIO(rawdata))
+        image = Image.open(BytesIO(rawdata))
         try:
             oldw, oldh = image.size
 
@@ -42,10 +42,10 @@
                     y = int(round((oldh - oldw) / 2.0))
                     image = image.crop((0, y, oldw - 1, (y + oldw) - 1))
                 image = image.resize((width, height), resample=Image.ANTIALIAS)
-        except Exception, err:
+        except Exception as err:
             logging.error(err)
             return ''
 
-        string = StringIO()
+        string = BytesIO()
         image.save(string, format='PNG')
         return string.getvalue()

=== modified file 'wlprofile/forms.py'
--- wlprofile/forms.py	2019-03-31 11:08:21 +0000
+++ wlprofile/forms.py	2019-06-09 11:20:50 +0000
@@ -7,7 +7,7 @@
 #
 
 from django import forms
-from models import Profile
+from .models import Profile
 
 from django.conf import settings
 import re

=== modified file 'wlprofile/gravatar.py'
--- wlprofile/gravatar.py	2016-12-13 18:28:51 +0000
+++ wlprofile/gravatar.py	2019-06-09 11:20:50 +0000
@@ -6,8 +6,8 @@
 import os.path
 import warnings
 import logging
-import urllib
-import urllib2
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
 from datetime import datetime, timedelta
 import shutil
 import socket
@@ -28,24 +28,24 @@
 
     hash = md5(email).hexdigest()
     size = max(pybb_settings.AVATAR_WIDTH, pybb_settings.AVATAR_HEIGHT)
-    default = urllib.quote('http://spam.egg/')
+    default = urllib.parse.quote('http://spam.egg/')
 
     url = 'http://www.gravatar.com/avatar/%s?s=%d&d=%s' % (hash, size, default)
     fname = os.tmpnam()
 
-    class RedirectHandler(urllib2.HTTPRedirectHandler):
+    class RedirectHandler(urllib.request.HTTPRedirectHandler):
 
         def http_error_302(*args):
             raise IOError('Redirect found')
 
     timeout = socket.getdefaulttimeout()
     socket.setdefaulttimeout(10)
-    opener = urllib2.build_opener(RedirectHandler())
+    opener = urllib.request.build_opener(RedirectHandler())
     socket.setdefaulttimeout(timeout)
 
     try:
         file(fname, 'wb').write(opener.open(url, fname).read())
-    except IOError, ex:
+    except IOError as ex:
         # logging.error(ex)
         return None
     else:

=== modified file 'wlprofile/management/commands/profile_fetch_gravatars.py'
--- wlprofile/management/commands/profile_fetch_gravatars.py	2018-04-08 15:53:05 +0000
+++ wlprofile/management/commands/profile_fetch_gravatars.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 
     def handle(self, *args, **kwargs):
         for user in User.objects.all():
-            print user.username
+            print(user.username)
             old_avatar = user.wlprofile.avatar
             if check_gravatar(user, ignore_date_joined=True):
-                print ' + Found gravatar'
+                print(' + Found gravatar')

=== modified file 'wlprofile/migrations/0001_initial.py'
--- wlprofile/migrations/0001_initial.py	2019-03-31 11:08:21 +0000
+++ wlprofile/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 from django.conf import settings

=== modified file 'wlprofile/migrations/0002_profile_deleted.py'
--- wlprofile/migrations/0002_profile_deleted.py	2018-09-13 20:19:07 +0000
+++ wlprofile/migrations/0002_profile_deleted.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.12 on 2018-09-13 21:23
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 

=== modified file 'wlprofile/models.py'
--- wlprofile/models.py	2019-05-06 17:55:58 +0000
+++ wlprofile/models.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 from django.db import models
 from django.contrib.auth.models import User
-from fields import ExtendedImageField
+from .fields import ExtendedImageField
 from mainpage.wl_utils import AutoOneToOneField
 from django.utils.translation import ugettext_lazy as _
 from pybb.models import Post

=== modified file 'wlprofile/templatetags/custom_date.py'
--- wlprofile/templatetags/custom_date.py	2019-03-31 11:08:21 +0000
+++ wlprofile/templatetags/custom_date.py	2019-06-09 11:20:50 +0000
@@ -105,11 +105,11 @@
         delta = ddate(date.year, date.month, date.day) - \
             ddate(now.year, now.month, now.day)
         if delta.days == 0:
-            return _(ur'\T\o\d\a\y')
+            return _(r'\T\o\d\a\y')
         elif delta.days == 1:
-            return _(ur'\T\o\m\o\r\r\o\w')
+            return _(r'\T\o\m\o\r\r\o\w')
         elif delta.days == -1:
-            return _(ur'\Y\e\s\t\e\r\d\a\y')
+            return _(r'\Y\e\s\t\e\r\d\a\y')
         else:
             return g.group(1)
     try:
@@ -142,29 +142,44 @@
 custom_date.is_safe = False
 
 
-def total_seconds(td):
-    # Not defined in 2.6, so we redefine it.
-    return (td.microseconds + (td.seconds + td.days * 24. * 3600.) * 1000000.) / 1000000.
+def pluralize (value, name):
+    """Pluralize a name.
+
+    Depending on 'value', the 'name' will be pluralized or not. Negative
+    values get a minus sign.
+    """
+
+    if value > 1:
+        return '{:-.0f} {}'.format(value, name + 's')
+
+    return '{:-.0f} {}'.format(value, name)
 
 
 @register.filter
-def minutes(date):
+def elapsed_time(date):
+    """Calculate elapsed time.
+
+    Returns either minutes, hours or days
+    """
+
     today = datetime.today()
-    seconds = int(total_seconds(today - date))
-    sign = ''
-    if seconds < 0:
-        sign = '-'
-    seconds = abs(seconds)
-    minutes = seconds / 60
-    hours = minutes / 60
+    seconds = (today - date).total_seconds()
+
+    # Python3: Operator '//' = floor division (result is rounded down)
+    minutes = seconds // 60
+    hours = minutes // 60
+    days = hours // 24
+
     if hours == 0 and minutes <= 1:
-        return sign + '1 minute'
+        return pluralize(1, 'minute')
     elif hours == 0:
-        return sign + '%d minutes' % (minutes)
-    elif hours == 1:
-        return sign + '1 hour'
+        return pluralize(minutes, 'minute')
+    elif hours == 1 or days == 0:
+        return pluralize(hours, 'hour')
     else:
-        return sign + '%d hours' % (hours)
+        return pluralize(days, 'day')
+
+    return 'Failure'
 
 
 @register.simple_tag

=== modified file 'wlprofile/templatetags/wlprofile_extras.py'
--- wlprofile/templatetags/wlprofile_extras.py	2019-01-18 11:10:27 +0000
+++ wlprofile/templatetags/wlprofile_extras.py	2019-06-09 11:20:50 +0000
@@ -27,7 +27,7 @@
         # Check for is_authenticated is needed for threadedcomments reply_to.js
         return mark_safe('<span title="This user has left our community">{}</span>'.format(settings.DELETED_USERNAME))
     else:
-        data = u'<a href="%s">%s</a>' % (
+        data = '<a href="%s">%s</a>' % (
             reverse('profile_view', args=[user.username]), user.username)
     return mark_safe(data)
 

=== modified file 'wlprofile/tests.py'
--- wlprofile/tests.py	2016-12-13 18:28:51 +0000
+++ wlprofile/tests.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 import unittest
 import datetime
 
-from templatetags.custom_date import do_custom_date
+from .templatetags.custom_date import do_custom_date
 
 
 class _CustomDate_Base(unittest.TestCase):
@@ -70,7 +70,7 @@
 class TestCustomDate_NaturalDayReplacementYesterday_ExceptCorrectResult(_CustomDate_Base):
 
     def runTest(self):
-        now = datetime.datetime(2008, 4, 13, 00, 00, 01)
+        now = datetime.datetime(2008, 4, 13, 00, 00, 0o1)
         rv = do_custom_date('j.m.y: %ND(j.m.y)', self.date, 0, now)
         self.assertEqual('12.04.08: yesterday', rv)
 
@@ -78,7 +78,7 @@
 class TestCustomDate_NaturalDayReplacementNoSpecialDay_ExceptCorrectResult(_CustomDate_Base):
 
     def runTest(self):
-        now = datetime.datetime(2011, 4, 13, 00, 00, 01)
+        now = datetime.datetime(2011, 4, 13, 00, 00, 0o1)
         rv = do_custom_date('j.m.y: %ND(j.m.Y)', self.date, 0, now)
         self.assertEqual('12.04.08: 12.04.2008', rv)
 
@@ -86,7 +86,7 @@
 class TestCustomDate_RecursiveReplacementNoHit_ExceptCorrectResult(_CustomDate_Base):
 
     def runTest(self):
-        now = datetime.datetime(2011, 4, 13, 00, 00, 01)
+        now = datetime.datetime(2011, 4, 13, 00, 00, 0o1)
         rv = do_custom_date('j.m.y%ND(: j.m%NY(.Y))', self.date, 0, now)
         self.assertEqual('12.04.08: 12.04.2008', rv)
 
@@ -94,7 +94,7 @@
 class TestCustomDate_RecursiveReplacementMissDayHitYear_ExceptCorrectResult(_CustomDate_Base):
 
     def runTest(self):
-        now = datetime.datetime(2008, 9, 13, 00, 00, 01)
+        now = datetime.datetime(2008, 9, 13, 00, 00, 0o1)
         rv = do_custom_date('j.m.y: %ND(j.m.%NY(Y))', self.date, 0, now)
         self.assertEqual('12.04.08: 12.04.', rv)
 
@@ -102,7 +102,7 @@
 class TestCustomDate_RecursiveReplacementHitDayTodayHitYear_ExceptCorrectResult(_CustomDate_Base):
 
     def runTest(self):
-        now = datetime.datetime(2008, 4, 12, 00, 00, 01)
+        now = datetime.datetime(2008, 4, 12, 00, 00, 0o1)
         rv = do_custom_date('j.m.y: %ND(j.m.%NY(Y))', self.date, 0, now)
         self.assertEqual('12.04.08: today', rv)
 

=== modified file 'wlprofile/urls.py'
--- wlprofile/urls.py	2018-09-07 16:33:58 +0000
+++ wlprofile/urls.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 #
 
 from django.conf.urls import *
-import views
+from . import views
 
 urlpatterns = [
     url(r'^edit/$', views.edit, name='profile_edit'),

=== modified file 'wlprofile/views.py'
--- wlprofile/views.py	2019-05-16 06:21:02 +0000
+++ wlprofile/views.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 from django.conf import settings
 from django.contrib import messages
 
-from forms import EditProfileForm
+from .forms import EditProfileForm
 
 
 @login_required

=== modified file 'wlscheduling/migrations/0001_initial.py'
--- wlscheduling/migrations/0001_initial.py	2017-12-23 09:15:02 +0000
+++ wlscheduling/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+
 
 from django.db import models, migrations
 from django.conf import settings

=== modified file 'wlscheduling/urls.py'
--- wlscheduling/urls.py	2017-12-23 09:15:02 +0000
+++ wlscheduling/urls.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 #!/usr/bin/env python -tt
 # encoding: utf-8
 from django.conf.urls import *
-from views import scheduling, scheduling_main, scheduling_find
+from .views import scheduling, scheduling_main, scheduling_find
 
 urlpatterns = [
     url(r'^scheduling/$', scheduling, name='scheduling_scheduling'),

=== modified file 'wlscheduling/views.py'
--- wlscheduling/views.py	2018-02-25 11:51:33 +0000
+++ wlscheduling/views.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 #
 
 from django.shortcuts import render
-from models import Availabilities
+from .models import Availabilities
 from django.contrib.auth.decorators import login_required
 import json
 from datetime import datetime, timedelta

=== modified file 'wlscreens/admin.py'
--- wlscreens/admin.py	2019-04-10 15:33:49 +0000
+++ wlscreens/admin.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 #!/usr/bin/env python -tt
 # encoding: utf-8
 
-from models import Category, Screenshot
+from .models import Category, Screenshot
 from django.contrib import admin
 
 

=== modified file 'wlscreens/migrations/0001_initial.py'
--- wlscreens/migrations/0001_initial.py	2018-04-05 18:55:35 +0000
+++ wlscreens/migrations/0001_initial.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11 on 2018-04-05 20:49
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 import django.db.models.deletion

=== modified file 'wlscreens/migrations/0002_auto_20190410_1737.py'
--- wlscreens/migrations/0002_auto_20190410_1737.py	2019-04-10 16:01:43 +0000
+++ wlscreens/migrations/0002_auto_20190410_1737.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.20 on 2019-04-10 17:37
-from __future__ import unicode_literals
+
 
 from django.db import migrations, models
 

=== modified file 'wlscreens/models.py'
--- wlscreens/models.py	2019-04-10 15:33:49 +0000
+++ wlscreens/models.py	2019-06-09 11:20:50 +0000
@@ -2,13 +2,11 @@
 
 from django.template.defaultfilters import slugify
 from PIL import Image
-from PIL.Image import core as _imaging
-from cStringIO import StringIO
-from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile
+from io import BytesIO
+from django.core.files.uploadedfile import SimpleUploadedFile
 from django.core.files.storage import FileSystemStorage
 import os
 from django.conf import settings
-from django.urls import reverse
 
 
 # Taken from django snippet 976
@@ -38,8 +36,8 @@
 
         return super(Category, self).save(*args, **kwargs)
 
-    def __unicode__(self):
-        return u"%s" % self.name
+    def __str__(self):
+        return "%s" % self.name
 
 
 def screenshot_path(instance, filename):
@@ -97,8 +95,9 @@
             image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS)
     
             # Save the thumbnail
-            temp_handle = StringIO()
+            temp_handle = BytesIO()
             image.save(temp_handle, 'png')
+            image.close()
             temp_handle.seek(0)
     
             # Save to the thumbnail field
@@ -114,5 +113,5 @@
             pass
 
 
-    def __unicode__(self):
-        return u"%s:%s" % (self.category.name, self.name)
+    def __str__(self):
+        return "%s:%s" % (self.category.name, self.name)

=== modified file 'wlscreens/tests/__init__.py'
--- wlscreens/tests/__init__.py	2009-04-11 15:21:15 +0000
+++ wlscreens/tests/__init__.py	2019-06-09 11:20:50 +0000
@@ -1,4 +1,4 @@
 
 
-from test_models import *
-from test_views import *
+from .test_models import *
+from .test_views import *

=== modified file 'wlscreens/tests/test_models.py'
--- wlscreens/tests/test_models.py	2019-03-31 11:08:21 +0000
+++ wlscreens/tests/test_models.py	2019-06-09 11:20:50 +0000
@@ -13,7 +13,7 @@
 from django.test import TestCase as DjangoTest
 from django.db import IntegrityError
 from django.core.files.uploadedfile import SimpleUploadedFile
-from cStringIO import StringIO
+from io import StringIO
 
 from unittest import TestCase
 

=== modified file 'wlscreens/urls.py'
--- wlscreens/urls.py	2019-04-09 18:22:27 +0000
+++ wlscreens/urls.py	2019-06-09 11:20:50 +0000
@@ -1,8 +1,8 @@
 #!/usr/bin/env python -tt
 # encoding: utf-8
 from django.conf.urls import *
-from models import Category, Screenshot
-from views import *
+from .models import Category, Screenshot
+from .views import *
 
 urlpatterns = [
     url(r'^$', CategoryList.as_view(), name='wlscreens_index'),

=== modified file 'wlscreens/views.py'
--- wlscreens/views.py	2019-04-10 15:33:49 +0000
+++ wlscreens/views.py	2019-06-09 11:20:50 +0000
@@ -1,6 +1,6 @@
 # Create your views here.
 
-from models import Category
+from .models import Category
 from django.views.generic.list import ListView
 
 class CategoryList(ListView):

=== modified file 'wlsearch/urls.py'
--- wlsearch/urls.py	2018-04-03 05:18:03 +0000
+++ wlsearch/urls.py	2019-06-09 11:20:50 +0000
@@ -10,7 +10,7 @@
 #
 
 from django.conf.urls import *
-from views import search
+from .views import search
 
 urlpatterns = [
     url(r'^$', search, name='search'),

=== modified file 'wlsearch/views.py'
--- wlsearch/views.py	2019-05-26 07:57:30 +0000
+++ wlsearch/views.py	2019-06-09 11:20:50 +0000
@@ -1,7 +1,7 @@
 from django.urls import reverse
 from django.shortcuts import render
 from django.http import HttpResponseRedirect
-from forms import WlSearchForm
+from .forms import WlSearchForm
 from pybb.models import Topic
 from pybb.models import Post as ForumPost
 from wiki.models import Article
@@ -33,7 +33,7 @@
             section = choices.get(request.POST['section'], 'all')
             if section == 'all':
                 # Add initial values of all the form fields
-                for field, v in form.fields.iteritems():
+                for field, v in form.fields.items():
                     if field == 'q':
                         # Don't change the query string
                         continue

=== modified file 'wlwebchat/tests.py'
--- wlwebchat/tests.py	2016-12-13 18:28:51 +0000
+++ wlwebchat/tests.py	2019-06-09 11:20:50 +0000
@@ -14,7 +14,7 @@
         """
         Tests that 1 + 1 always equals 2.
         """
-        self.failUnlessEqual(1 + 1, 2)
+        self.assertEqual(1 + 1, 2)
 
 __test__ = {'doctest': """
 Another way to test that 1 + 1 is equal to 2.

=== modified file 'wlwebchat/urls.py'
--- wlwebchat/urls.py	2016-12-13 18:28:51 +0000
+++ wlwebchat/urls.py	2019-06-09 11:20:50 +0000
@@ -3,7 +3,7 @@
 #
 
 from django.conf.urls import *
-from views import webchat
+from .views import webchat
 
 urlpatterns = [
     # Uncomment the next line to enable the admin:


Follow ups