mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: make mreplace polyglot
This commit is contained in:
parent
749885778d
commit
3e64b73c96
@ -1,4 +1,5 @@
|
||||
# multiple replace from dictionnary : http://code.activestate.com/recipes/81330/
|
||||
from __future__ import unicode_literals
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, sengian <sengian1 @ gmail.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
@ -22,6 +23,9 @@ class MReplace(UserDict):
|
||||
def compile_regex(self):
|
||||
if len(self.data) > 0:
|
||||
keys = sorted(self.data, key=len, reverse=True)
|
||||
if isinstance(keys[0], bytes):
|
||||
tmp = b"(%s)" % b"|".join(map(re.escape, keys))
|
||||
else:
|
||||
tmp = "(%s)" % "|".join(map(re.escape, keys))
|
||||
if self.re != tmp:
|
||||
self.re = tmp
|
||||
|
Loading…
x
Reference in New Issue
Block a user