py3: misc fixes

This commit is contained in:
Kovid Goyal 2019-04-03 14:40:34 +05:30
parent 69ecc8eb9f
commit 8ece061387
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -4,7 +4,10 @@ __copyright__ = '2010, sengian <sengian1 @ gmail.com>'
__docformat__ = 'restructuredtext en'
import re
from UserDict import UserDict
try:
from collections import UserDict
except ImportError:
from UserDict import UserDict
class MReplace(UserDict):
@ -18,7 +21,7 @@ class MReplace(UserDict):
def compile_regex(self):
if len(self.data) > 0:
keys = sorted(self.data.keys(), key=len, reverse=True)
keys = sorted(self.data, key=len, reverse=True)
tmp = "(%s)" % "|".join(map(re.escape, keys))
if self.re != tmp:
self.re = tmp
@ -35,4 +38,3 @@ class MReplace(UserDict):
if len(self.data) < 1 or self.re is None:
return text
return self.regex.sub(self, text)