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