We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Backwards incompatible change in multistring
The behavior of the `multistring` class with respect to string comparisons has changed in 1.14-rc1, more specifically when the `autoencode` class was removed in 4f9ee7edfc9. At least this is the case in Python 2.7.

I have experienced this in some custom Pootle code when testing out TTK from master — a multistring with non-ASCII characters was being compared against the empty byte string `''`, and it resulted in a encoding error. I can reproduce this in a test case:

``` python
from translate.misc import multistring

def test_cmp():
    t = multistring.multistring
    s1 = t("test")
    assert s1.__cmp__("test") == 0

    s2 = t(u"téßt")
    assert s2.__cmp__("test") > 0
```

(Note that for 1.13.x the multistring constructor needs an `encoding='UTF-8'` parameter in the test).

I'm not sure if this could be considered a bug, after all my understanding is apps/libraries should internally work with code points and not bytes, however this is a breaking change that might potentially affect existing consumer code so I consider it's worth bringing this up to hear people's thoughts.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `translate/misc/multistring.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright 2006 Zuza Software Foundation
4 #
5 # This file is part of translate.
6 #
7 # translate is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # translate is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, see <http://www.gnu.org/licenses/>.
19 
20 """Supports a hybrid Unicode string that can also have a list of alternate
21 strings in the strings attribute"""
22 
23 import six
24 
25 
26 class multistring(six.text_type):
27 
28     def __new__(newtype, string=u"", *args, **kwargs):
29         if isinstance(string, list):
30             if not string:
31                 raise ValueError("multistring must contain at least one string")
32             mainstring = string[0]
33             newstring = multistring.__new__(newtype, string[0])
34             newstring.strings = [newstring] + [multistring.__new__(newtype, altstring) for altstring in string[1:]]
35         else:
36             newstring = six.text_type.__new__(newtype, string)
37             newstring.strings = [newstring]
38         return newstring
39 
40     def __init__(self, *args, **kwargs):
41         super(multistring, self).__init__()
42         if not hasattr(self, "strings"):
43             self.strings = []
44 
45     def __cmp__(self, otherstring):
46         def cmp_compat(s1, s2):
47             # Python 3 compatible cmp() equivalent
48             return (s1 > s2) - (s1 < s2)
49         if isinstance(otherstring, multistring):
50             parentcompare = cmp_compat(six.text_type(self), otherstring)
51             if parentcompare:
52                 return parentcompare
53             else:
54                 return cmp_compat(self.strings[1:], otherstring.strings[1:])
55         elif isinstance(otherstring, six.text_type):
56             return cmp_compat(six.text_type(self), otherstring)
57         elif isinstance(otherstring, bytes):
58             return cmp_compat(bytes(self), otherstring)
59         elif isinstance(otherstring, list) and otherstring:
60             return cmp_compat(self, multistring(otherstring))
61         else:
62             return cmp_compat(str(type(self)), str(type(otherstring)))
63 
64     def __hash__(self):
65         return hash(''.join(self.strings))
66 
67     def __ne__(self, otherstring):
68         return self.__cmp__(otherstring) != 0
69 
70     def __eq__(self, otherstring):
71         return self.__cmp__(otherstring) == 0
72 
73     def __repr__(self):
74         return "multistring([" + ",".join(self.strings) + "])"
75 
76     def replace(self, old, new, count=None):
77         if count is None:
78             newstr = multistring(super(multistring, self).replace(old, new))
79         else:
80             newstr = multistring(super(multistring, self).replace(old, new, count))
81         for s in self.strings[1:]:
82             if count is None:
83                 newstr.strings.append(s.replace(old, new))
84             else:
85                 newstr.strings.append(s.replace(old, new, count))
86         return newstr
87
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/translate/misc/multistring.py b/translate/misc/multistring.py
--- a/translate/misc/multistring.py
+++ b/translate/misc/multistring.py
@@ -55,7 +55,7 @@
         elif isinstance(otherstring, six.text_type):
             return cmp_compat(six.text_type(self), otherstring)
         elif isinstance(otherstring, bytes):
-            return cmp_compat(bytes(self), otherstring)
+            return cmp_compat(self.encode('utf-8'), otherstring)
         elif isinstance(otherstring, list) and otherstring:
             return cmp_compat(self, multistring(otherstring))
         else:
@@ -71,7 +71,8 @@
         return self.__cmp__(otherstring) == 0
 
     def __repr__(self):
-        return "multistring([" + ",".join(self.strings) + "])"
+        _repr = "multistring([" + u",".join(self.strings) + "])"
+        return _repr.encode('utf-8') if six.PY2 else _repr
 
     def replace(self, old, new, count=None):
         if count is None:

{"golden_diff": "diff --git a/translate/misc/multistring.py b/translate/misc/multistring.py\n--- a/translate/misc/multistring.py\n+++ b/translate/misc/multistring.py\n@@ -55,7 +55,7 @@\n         elif isinstance(otherstring, six.text_type):\n             return cmp_compat(six.text_type(self), otherstring)\n         elif isinstance(otherstring, bytes):\n-            return cmp_compat(bytes(self), otherstring)\n+            return cmp_compat(self.encode('utf-8'), otherstring)\n         elif isinstance(otherstring, list) and otherstring:\n             return cmp_compat(self, multistring(otherstring))\n         else:\n@@ -71,7 +71,8 @@\n         return self.__cmp__(otherstring) == 0\n \n     def __repr__(self):\n-        return \"multistring([\" + \",\".join(self.strings) + \"])\"\n+        _repr = \"multistring([\" + u\",\".join(self.strings) + \"])\"\n+        return _repr.encode('utf-8') if six.PY2 else _repr\n \n     def replace(self, old, new, count=None):\n         if count is None:\n", "issue": "Backwards incompatible change in multistring\nThe behavior of the `multistring` class with respect to string comparisons has changed in 1.14-rc1, more specifically when the `autoencode` class was removed in 4f9ee7edfc9. At least this is the case in Python 2.7.\n\nI have experienced this in some custom Pootle code when testing out TTK from master \u2014 a multistring with non-ASCII characters was being compared against the empty byte string `''`, and it resulted in a encoding error. I can reproduce this in a test case:\n\n``` python\nfrom translate.misc import multistring\n\ndef test_cmp():\n    t = multistring.multistring\n    s1 = t(\"test\")\n    assert s1.__cmp__(\"test\") == 0\n\n    s2 = t(u\"t\u00e9\u00dft\")\n    assert s2.__cmp__(\"test\") > 0\n```\n\n(Note that for 1.13.x the multistring constructor needs an `encoding='UTF-8'` parameter in the test).\n\nI'm not sure if this could be considered a bug, after all my understanding is apps/libraries should internally work with code points and not bytes, however this is a breaking change that might potentially affect existing consumer code so I consider it's worth bringing this up to hear people's thoughts.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright 2006 Zuza Software Foundation\n#\n# This file is part of translate.\n#\n# translate is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2 of the License, or\n# (at your option) any later version.\n#\n# translate is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n\"\"\"Supports a hybrid Unicode string that can also have a list of alternate\nstrings in the strings attribute\"\"\"\n\nimport six\n\n\nclass multistring(six.text_type):\n\n    def __new__(newtype, string=u\"\", *args, **kwargs):\n        if isinstance(string, list):\n            if not string:\n                raise ValueError(\"multistring must contain at least one string\")\n            mainstring = string[0]\n            newstring = multistring.__new__(newtype, string[0])\n            newstring.strings = [newstring] + [multistring.__new__(newtype, altstring) for altstring in string[1:]]\n        else:\n            newstring = six.text_type.__new__(newtype, string)\n            newstring.strings = [newstring]\n        return newstring\n\n    def __init__(self, *args, **kwargs):\n        super(multistring, self).__init__()\n        if not hasattr(self, \"strings\"):\n            self.strings = []\n\n    def __cmp__(self, otherstring):\n        def cmp_compat(s1, s2):\n            # Python 3 compatible cmp() equivalent\n            return (s1 > s2) - (s1 < s2)\n        if isinstance(otherstring, multistring):\n            parentcompare = cmp_compat(six.text_type(self), otherstring)\n            if parentcompare:\n                return parentcompare\n            else:\n                return cmp_compat(self.strings[1:], otherstring.strings[1:])\n        elif isinstance(otherstring, six.text_type):\n            return cmp_compat(six.text_type(self), otherstring)\n        elif isinstance(otherstring, bytes):\n            return cmp_compat(bytes(self), otherstring)\n        elif isinstance(otherstring, list) and otherstring:\n            return cmp_compat(self, multistring(otherstring))\n        else:\n            return cmp_compat(str(type(self)), str(type(otherstring)))\n\n    def __hash__(self):\n        return hash(''.join(self.strings))\n\n    def __ne__(self, otherstring):\n        return self.__cmp__(otherstring) != 0\n\n    def __eq__(self, otherstring):\n        return self.__cmp__(otherstring) == 0\n\n    def __repr__(self):\n        return \"multistring([\" + \",\".join(self.strings) + \"])\"\n\n    def replace(self, old, new, count=None):\n        if count is None:\n            newstr = multistring(super(multistring, self).replace(old, new))\n        else:\n            newstr = multistring(super(multistring, self).replace(old, new, count))\n        for s in self.strings[1:]:\n            if count is None:\n                newstr.strings.append(s.replace(old, new))\n            else:\n                newstr.strings.append(s.replace(old, new, count))\n        return newstr\n", "path": "translate/misc/multistring.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright 2006 Zuza Software Foundation\n#\n# This file is part of translate.\n#\n# translate is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2 of the License, or\n# (at your option) any later version.\n#\n# translate is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n\"\"\"Supports a hybrid Unicode string that can also have a list of alternate\nstrings in the strings attribute\"\"\"\n\nimport six\n\n\nclass multistring(six.text_type):\n\n    def __new__(newtype, string=u\"\", *args, **kwargs):\n        if isinstance(string, list):\n            if not string:\n                raise ValueError(\"multistring must contain at least one string\")\n            mainstring = string[0]\n            newstring = multistring.__new__(newtype, string[0])\n            newstring.strings = [newstring] + [multistring.__new__(newtype, altstring) for altstring in string[1:]]\n        else:\n            newstring = six.text_type.__new__(newtype, string)\n            newstring.strings = [newstring]\n        return newstring\n\n    def __init__(self, *args, **kwargs):\n        super(multistring, self).__init__()\n        if not hasattr(self, \"strings\"):\n            self.strings = []\n\n    def __cmp__(self, otherstring):\n        def cmp_compat(s1, s2):\n            # Python 3 compatible cmp() equivalent\n            return (s1 > s2) - (s1 < s2)\n        if isinstance(otherstring, multistring):\n            parentcompare = cmp_compat(six.text_type(self), otherstring)\n            if parentcompare:\n                return parentcompare\n            else:\n                return cmp_compat(self.strings[1:], otherstring.strings[1:])\n        elif isinstance(otherstring, six.text_type):\n            return cmp_compat(six.text_type(self), otherstring)\n        elif isinstance(otherstring, bytes):\n            return cmp_compat(self.encode('utf-8'), otherstring)\n        elif isinstance(otherstring, list) and otherstring:\n            return cmp_compat(self, multistring(otherstring))\n        else:\n            return cmp_compat(str(type(self)), str(type(otherstring)))\n\n    def __hash__(self):\n        return hash(''.join(self.strings))\n\n    def __ne__(self, otherstring):\n        return self.__cmp__(otherstring) != 0\n\n    def __eq__(self, otherstring):\n        return self.__cmp__(otherstring) == 0\n\n    def __repr__(self):\n        _repr = \"multistring([\" + u\",\".join(self.strings) + \"])\"\n        return _repr.encode('utf-8') if six.PY2 else _repr\n\n    def replace(self, old, new, count=None):\n        if count is None:\n            newstr = multistring(super(multistring, self).replace(old, new))\n        else:\n            newstr = multistring(super(multistring, self).replace(old, new, count))\n        for s in self.strings[1:]:\n            if count is None:\n                newstr.strings.append(s.replace(old, new))\n            else:\n                newstr.strings.append(s.replace(old, new, count))\n        return newstr\n", "path": "translate/misc/multistring.py"}]}