| 1 | Patch-Source: https://github.com/itstool/itstool/pull/51/commits/32c7d07664dc37765100285d1202d488cd6a27e8
|
| 2 | --
|
| 3 | From 32c7d07664dc37765100285d1202d488cd6a27e8 Mon Sep 17 00:00:00 2001
|
| 4 | From: Nils Philippsen <[email protected]>
|
| 5 | Date: Mon, 9 Oct 2023 14:26:43 +0200
|
| 6 | Subject: [PATCH] Fix insufficiently quoted regular expressions
|
| 7 |
|
| 8 | These went under the radar until Python 3.12 started warning about them.
|
| 9 |
|
| 10 | Signed-off-by: Nils Philippsen <[email protected]>
|
| 11 | ---
|
| 12 | itstool.in | 14 +++++++-------
|
| 13 | 1 file changed, 7 insertions(+), 7 deletions(-)
|
| 14 |
|
| 15 | diff --git a/itstool.in b/itstool.in
|
| 16 | index c21ad4b..4452616 100755
|
| 17 | |
| 18 | |
| 19 | @@ -220,7 +220,7 @@ class Message (object):
|
| 20 | if not isinstance(text, ustr_type):
|
| 21 | text = ustr(text, 'utf-8')
|
| 22 | self._message[-1] += text.replace('&', '&').replace('<', '<').replace('>', '>')
|
| 23 | - if re.sub('\s+', ' ', text).strip() != '':
|
| 24 | + if re.sub(r'\s+', ' ', text).strip() != '':
|
| 25 | self._empty = False
|
| 26 |
|
| 27 | def add_entity_ref (self, name):
|
| 28 | @@ -318,7 +318,7 @@ class Message (object):
|
| 29 | message += '<_:%s-%i/>' % (msg.name, placeholder)
|
| 30 | placeholder += 1
|
| 31 | if not self._preserve:
|
| 32 | - message = re.sub('\s+', ' ', message).strip()
|
| 33 | + message = re.sub(r'\s+', ' ', message).strip()
|
| 34 | return message
|
| 35 |
|
| 36 | def get_preserve_space (self):
|
| 37 | @@ -456,9 +456,9 @@ class LocNote (object):
|
| 38 | if self._preserve_space:
|
| 39 | return self.locnote
|
| 40 | else:
|
| 41 | - return re.sub('\s+', ' ', self.locnote).strip()
|
| 42 | + return re.sub(r'\s+', ' ', self.locnote).strip()
|
| 43 | elif self.locnoteref is not None:
|
| 44 | - return '(itstool) link: ' + re.sub('\s+', ' ', self.locnoteref).strip()
|
| 45 | + return '(itstool) link: ' + re.sub(r'\s+', ' ', self.locnoteref).strip()
|
| 46 | return ''
|
| 47 |
|
| 48 |
|
| 49 | @@ -889,7 +889,7 @@ class Document (object):
|
| 50 | trans = translations.ugettext('_\x04translator-credits')
|
| 51 | if trans is None or trans == 'translator-credits':
|
| 52 | return
|
| 53 | - regex = re.compile('(.*) \<(.*)\>, (.*)')
|
| 54 | + regex = re.compile(r'(.*) \<(.*)\>, (.*)')
|
| 55 | for credit in trans.split('\n'):
|
| 56 | match = regex.match(credit)
|
| 57 | if not match:
|
| 58 | @@ -924,7 +924,7 @@ class Document (object):
|
| 59 | prevnode = None
|
| 60 | if node.prev is not None and node.prev.type == 'text':
|
| 61 | prevtext = node.prev.content
|
| 62 | - if re.sub('\s+', '', prevtext) == '':
|
| 63 | + if re.sub(r'\s+', '', prevtext) == '':
|
| 64 | prevnode = node.prev
|
| 65 | for lang in sorted(list(translations.keys()), reverse=True):
|
| 66 | locale = self.get_its_locale_filter(node)
|
| 67 | @@ -1468,7 +1468,7 @@ def match_locale(extrange, locale):
|
| 68 | localei += 1
|
| 69 | return True
|
| 70 |
|
| 71 | -_locale_pattern = re.compile('([a-zA-Z0-9-]+)(_[A-Za-z0-9]+)?(@[A-Za-z0-9]+)?(\.[A-Za-z0-9]+)?')
|
| 72 | +_locale_pattern = re.compile(r'([a-zA-Z0-9-]+)(_[A-Za-z0-9]+)?(@[A-Za-z0-9]+)?(\.[A-Za-z0-9]+)?')
|
| 73 | def convert_locale (locale):
|
| 74 | # Automatically convert POSIX-style locales to BCP47
|
| 75 | match = _locale_pattern.match(locale)
|