Fix for python 3.12:

Fix insufficiently quoted regular expressions
https://github.com/itstool/itstool/pull/51
This commit is contained in:
ajacoutot
2024-12-30 08:35:55 +00:00
parent dd1369456b
commit d282df0a6c
2 changed files with 60 additions and 1 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ PKG_ARCH= *
COMMENT= translate XML documents with PO files
DISTNAME= itstool-2.0.7
REVISION= 4
REVISION= 5
CATEGORIES= textproc
+59
View File
@@ -5,6 +5,8 @@ Forwarded: https://github.com/itstool/itstool/issues/25
Bug: https://github.com/itstool/itstool/issues/36
PR: https://github.com/itstool/itstool/pull/47
https://github.com/itstool/itstool/pull/51
Index: itstool.in
--- itstool.in.orig
+++ itstool.in
@@ -31,6 +33,54 @@ Index: itstool.in
NS_ITS = 'http://www.w3.org/2005/11/its'
NS_ITST = 'http://itstool.org/extensions/'
@@ -220,7 +233,7 @@ class Message (object):
if not isinstance(text, ustr_type):
text = ustr(text, 'utf-8')
self._message[-1] += text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
- if re.sub('\s+', ' ', text).strip() != '':
+ if re.sub(r'\s+', ' ', text).strip() != '':
self._empty = False
def add_entity_ref (self, name):
@@ -318,7 +331,7 @@ class Message (object):
message += '<_:%s-%i/>' % (msg.name, placeholder)
placeholder += 1
if not self._preserve:
- message = re.sub('\s+', ' ', message).strip()
+ message = re.sub(r'\s+', ' ', message).strip()
return message
def get_preserve_space (self):
@@ -456,9 +469,9 @@ class LocNote (object):
if self._preserve_space:
return self.locnote
else:
- return re.sub('\s+', ' ', self.locnote).strip()
+ return re.sub(r'\s+', ' ', self.locnote).strip()
elif self.locnoteref is not None:
- return '(itstool) link: ' + re.sub('\s+', ' ', self.locnoteref).strip()
+ return '(itstool) link: ' + re.sub(r'\s+', ' ', self.locnoteref).strip()
return ''
@@ -889,7 +902,7 @@ class Document (object):
trans = translations.ugettext('_\x04translator-credits')
if trans is None or trans == 'translator-credits':
return
- regex = re.compile('(.*) \<(.*)\>, (.*)')
+ regex = re.compile(r'(.*) \<(.*)\>, (.*)')
for credit in trans.split('\n'):
match = regex.match(credit)
if not match:
@@ -924,7 +937,7 @@ class Document (object):
prevnode = None
if node.prev is not None and node.prev.type == 'text':
prevtext = node.prev.content
- if re.sub('\s+', '', prevtext) == '':
+ if re.sub(r'\s+', '', prevtext) == '':
prevnode = node.prev
for lang in sorted(list(translations.keys()), reverse=True):
locale = self.get_its_locale_filter(node)
@@ -1077,9 +1090,9 @@ class Document (object):
if strict:
raise
@@ -64,3 +114,12 @@ Index: itstool.in
self._xml_err = ''
ctxt.doc().freeDoc()
return node
@@ -1468,7 +1483,7 @@ def match_locale(extrange, locale):
localei += 1
return True
-_locale_pattern = re.compile('([a-zA-Z0-9-]+)(_[A-Za-z0-9]+)?(@[A-Za-z0-9]+)?(\.[A-Za-z0-9]+)?')
+_locale_pattern = re.compile(r'([a-zA-Z0-9-]+)(_[A-Za-z0-9]+)?(@[A-Za-z0-9]+)?(\.[A-Za-z0-9]+)?')
def convert_locale (locale):
# Automatically convert POSIX-style locales to BCP47
match = _locale_pattern.match(locale)