1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
From: Simon McVittie <smcv@debian.org>
Date: Wed, 12 Feb 2025 11:47:28 +0000
Subject: Use raw strings for regular expressions
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
This avoids SyntaxWarning for escape sequences such as `\s` and `\.`.
Originally part of commit c8e4f7a5
"Apply Black codestyle format to the project" upstream.
Origin: backport, 2.1.0
Thanks: Matěj Cepl
Bug-Debian: https://bugs.debian.org/1087126
---
typogrify/filters.py | 4 ++--
typogrify/packages/titlecase/__init__.py | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/typogrify/filters.py b/typogrify/filters.py
index 269aca0..bd82bf7 100644
--- a/typogrify/filters.py
+++ b/typogrify/filters.py
@@ -43,7 +43,7 @@ def process_ignores(text, ignore_tags=None):
def _filter_tag(match):
"""Process user tag filters in regex sub"""
- tag = match.group(1) if match.group(1) != '' else '[^\s.#<>]+'
+ tag = match.group(1) if match.group(1) != '' else r'[^\s.#<>]+'
attribute = 'class' if match.group(2)[0] == '.' else 'id'
attribute_value = match.group(2)[1:]
_filter_tag.group += 1
@@ -137,7 +137,7 @@ def amp(text):
"""
# tag_pattern from http://haacked.com/archive/2004/10/25/usingregularexpressionstomatchhtml.aspx
# it kinda sucks but it fixes the standalone amps in attributes bug
- tag_pattern = '</?\w+((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?>'
+ tag_pattern = r"</?\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>"
amp_finder = re.compile(r"(\s| )(&|&|&\#38;)(\s| )")
intra_tag_finder = re.compile(r'(?P<prefix>(%s)?)(?P<text>([^<]*))(?P<suffix>(%s)?)' % (tag_pattern, tag_pattern))
diff --git a/typogrify/packages/titlecase/__init__.py b/typogrify/packages/titlecase/__init__.py
index aeaca97..423ae4f 100755
--- a/typogrify/packages/titlecase/__init__.py
+++ b/typogrify/packages/titlecase/__init__.py
@@ -15,7 +15,7 @@ import re
__all__ = ['titlecase']
__version__ = '0.5.1'
-SMALL = 'a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v\.?|via|vs\.?'
+SMALL = r"a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v\.?|via|vs\.?"
PUNCT = r"""!"#$%&'‘()*+,\-./:;?@[\\\]_`{|}~"""
SMALL_WORDS = re.compile(r'^(%s)$' % SMALL, re.I)
|