Skip to content

Commit ff15963

Browse files
authored
Fix more escape sequences. (#449)
1 parent c5dfbd1 commit ff15963

File tree

9 files changed

+44
-44
lines changed

9 files changed

+44
-44
lines changed

v7/import_jekyll/import_jekyll.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def link_repl(matchobj):
295295

296296
def slugify_file(filename):
297297
name, _ = os.path.splitext(os.path.basename(filename))
298-
m = re.match('\d+\-\d+\-\d+\-(?P<name>.*)', name)
298+
m = re.match(r'\d+\-\d+\-\d+\-(?P<name>.*)', name)
299299
if m:
300300
name = m.group('name')
301301

v7/markmin/markmin/markmin2html.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
__all__ = ['render', 'markmin2html', 'markmin_escape']
3333

34-
__doc__ = """
34+
__doc__ = r"""
3535
# Markmin markup language
3636
3737
## About
@@ -548,10 +548,10 @@ def test():
548548
regex_del = re.compile(r'~~(?P<t>[^\s*]+( +[^\s*]+)*)~~')
549549
regex_em = re.compile(r"''(?P<t>([^\s']| |'(?!'))+)''")
550550
regex_num = re.compile(r"^\s*[+-]?((\d+(\.\d*)?)|\.\d+)([eE][+-]?[0-9]+)?\s*$")
551-
regex_list = re.compile('^(?:(?:(#{1,6})|(?:(\.+|\++|\-+)(\.)?))\s*)?(.*)$')
552-
regex_bq_headline = re.compile('^(?:(\.+|\++|\-+)(\.)?\s+)?(-{3}-*)$')
551+
regex_list = re.compile(r'^(?:(?:(#{1,6})|(?:(\.+|\++|\-+)(\.)?))\s*)?(.*)$')
552+
regex_bq_headline = re.compile(r'^(?:(\.+|\++|\-+)(\.)?\s+)?(-{3}-*)$')
553553
regex_tq = re.compile(
554-
'^(-{3}-*)(?::(?P<c>[a-zA-Z][_a-zA-Z\-\d]*)(?:\[(?P<p>[a-zA-Z][_a-zA-Z\-\d]*)\])?)?$')
554+
r'^(-{3}-*)(?::(?P<c>[a-zA-Z][_a-zA-Z\-\d]*)(?:\[(?P<p>[a-zA-Z][_a-zA-Z\-\d]*)\])?)?$')
555555
regex_proto = re.compile(
556556
r'(?<!["\w>/=])(?P<p>\w+):(?P<k>\w+://[\w\d\-+=?%&/:.]+)', re.M)
557557
regex_auto = re.compile(
@@ -568,11 +568,11 @@ def test():
568568
'\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x05')
569569
ttab_out = maketrans(
570570
'\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x05', "'`:*~\\[]{}@$+-.#\n")
571-
regex_quote = re.compile('(?P<name>\w+?)\s*\=\s*')
571+
regex_quote = re.compile(r'(?P<name>\w+?)\s*\=\s*')
572572

573573

574574
def make_dict(b):
575-
return '{%s}' % regex_quote.sub("'\g<name>':", b)
575+
return '{%s}' % regex_quote.sub(r"'\g<name>':", b)
576576

577577

578578
def safe_eval(node_or_string, env):
@@ -708,7 +708,7 @@ def render(text,
708708
class_prefix='',
709709
id_prefix='markmin_',
710710
pretty_print=False):
711-
"""
711+
r"""
712712
Arguments:
713713
- text is the text to be processed
714714
- extra is a dict like extra=dict(custom=lambda value: value) that process custom code
@@ -959,7 +959,7 @@ def render(text,
959959
text = replace_at_urls(text, URL)
960960

961961
if latex == 'google':
962-
text = regex_dd.sub('``\g<latex>``:latex ', text)
962+
text = regex_dd.sub(r'``\g<latex>``:latex ', text)
963963

964964
#############################################################
965965
# replace all blocks marked with ``...``:class[id] with META
@@ -1321,9 +1321,9 @@ def parse_table_or_blockquote(s, mtag, lineno):
13211321
#############################################################
13221322
# do strong,em,del
13231323
#############################################################
1324-
text = regex_strong.sub('<strong>\g<t></strong>', text)
1325-
text = regex_del.sub('<del>\g<t></del>', text)
1326-
text = regex_em.sub('<em>\g<t></em>', text)
1324+
text = regex_strong.sub(r'<strong>\g<t></strong>', text)
1325+
text = regex_del.sub(r'<del>\g<t></del>', text)
1326+
text = regex_em.sub(r'<em>\g<t></em>', text)
13271327

13281328
#############################################################
13291329
# deal with images, videos, audios and links

v7/sphinx_roles/sphinx_roles.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def unknown_visit(self, node):
551551
return [pnode], msg_list
552552

553553

554-
_abbr_re = re.compile("\((.*)\)$", re.S)
554+
_abbr_re = re.compile(r"\((.*)\)$", re.S)
555555

556556

557557
class abbreviation(nodes.Inline, nodes.TextElement):

v7/static_comments/static_comments.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class StaticComments(SignalHandler):
7272
"""Add static comments to posts."""
7373

7474
# Used to parse comment headers
75-
_header_regex = re.compile('^\.\. (.*?): (.*)')
75+
_header_regex = re.compile(r'^\.\. (.*?): (.*)')
7676

7777
def _compile_content(self, compiler_name, content, filename):
7878
"""Compile comment content with specified page compiler."""

v7/wordpress_compiler/wordpress/default_filters.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,27 @@ def __wptexturize_setup(self):
8787

8888
dynamic = []
8989
if "'" != apos:
90-
dynamic.append(('\'(\d\d(?:&#8217;|\')?s)', apos + '\\1')) # '99's
91-
dynamic.append(('\'(\d)', apos + '\\1')) # '99
90+
dynamic.append((r'\'(\d\d(?:&#8217;|\')?s)', apos + '\\1')) # '99's
91+
dynamic.append((r'\'(\d)', apos + '\\1')) # '99
9292
if "'" != opening_single_quote:
93-
dynamic.append(('(\s|\A|[([{<]|")\'', '\\1' + opening_single_quote)) # opening single quote, even after (, {, <, [
93+
dynamic.append((r'(\s|\A|[([{<]|")\'', '\\1' + opening_single_quote)) # opening single quote, even after (, {, <, [
9494
if '"' != double_prime:
95-
dynamic.append(('(\d)"', '\\1' + double_prime)) # 9" (double prime)
95+
dynamic.append((r'(\d)"', '\\1' + double_prime)) # 9" (double prime)
9696
if "'" != prime:
97-
dynamic.append(('(\d)\'', '\\1' + prime)) # 9' (prime)
97+
dynamic.append((r'(\d)\'', '\\1' + prime)) # 9' (prime)
9898
if "'" != apos:
99-
dynamic.append(('(\S)\'([^\'\s])', '\\1' + apos + '\\2')) # apostrophe in a word
99+
dynamic.append((r'(\S)\'([^\'\s])', '\\1' + apos + '\\2')) # apostrophe in a word
100100
if '"' != opening_quote:
101-
dynamic.append(('(\s|\A|[([{<])"(?!\s)', '\\1' + opening_quote)) # opening double quote, even after (, {, <, [
101+
dynamic.append((r'(\s|\A|[([{<])"(?!\s)', '\\1' + opening_quote)) # opening double quote, even after (, {, <, [
102102
# PHP: the original PHP regular expression had a problem, since there was only one capturing group, but both \1 and \2 were
103103
# used on the right-hand side. Since Python throws an exception in that case, while PHP simply treats \2 as an empty string,
104104
# I had to remove the "+'\\2'" after opening_quote.
105105
if '"' != closing_quote:
106-
dynamic.append(('"(\s|\S|\Z)', closing_quote + '\\1')) # closing double quote
106+
dynamic.append((r'"(\s|\S|\Z)', closing_quote + '\\1')) # closing double quote
107107
if "'" != closing_single_quote:
108-
dynamic.append(('\'([\s.]|\Z)', closing_single_quote + '\\1')) # closing single quote
108+
dynamic.append((r'\'([\s.]|\Z)', closing_single_quote + '\\1')) # closing single quote
109109

110-
dynamic.append(('\b(\d+)x(\d+)\b', '\\1&#215;\\2')) # 9x9 (times)
110+
dynamic.append((r'\b(\d+)x(\d+)\b', '\\1&#215;\\2')) # 9x9 (times)
111111

112112
self.dynamic = dynamic
113113

@@ -144,7 +144,7 @@ def wptexturize(self, text):
144144
no_texturize_shortcodes_stack = []
145145

146146
# PHP: Since Python doesn't support PHP's /U modifier (which inverts quantifier's greediness), I modified the regular expression accordingly
147-
textarr = regex.split('(<.*?>|\[.*?\])', text, flags=regex.DOTALL)
147+
textarr = regex.split(r'(<.*?>|\[.*?\])', text, flags=regex.DOTALL)
148148

149149
result = []
150150
for curl in textarr:
@@ -240,8 +240,8 @@ def __convert_chars_setup(self):
240240

241241
def convert_chars(self, content):
242242
# Remove metadata tags
243-
content = regex.sub('<title>(.+?)<\/title>', '', content)
244-
content = regex.sub('<category>(.+?)<\/category>', '', content)
243+
content = regex.sub(r'<title>(.+?)<\/title>', '', content)
244+
content = regex.sub(r'<category>(.+?)<\/category>', '', content)
245245

246246
# Converts lone & characters into &#38; (a.k.a. &amp;)
247247
content = regex.sub('&([^#])(?![a-z1-4]{1,8};)', '&#038;\\1', content, regex.IGNORECASE)
@@ -288,36 +288,36 @@ def wpautop(self, pee, br=True):
288288

289289
pee += last_pee
290290

291-
pee = regex.sub('<br />\s*<br />', "\n\n", pee)
291+
pee = regex.sub(r'<br />\s*<br />', "\n\n", pee)
292292
# Space things out a little
293293
self.allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'
294294
pee = regex.sub('(<' + self.allblocks + '[^>]*>)', "\n\\1", pee)
295295
pee = regex.sub('(</' + self.allblocks + '>)', "\\1\n\n", pee)
296296
pee = pee.replace("\r\n", "\n").replace("\r", "\n") # cross-platform newlines
297297
if pee.find('<object') >= 0:
298-
pee = regex.sub('\s*<param([^>]*)>\s*', "<param\\1>", pee) # no pee inside object/embed
299-
pee = regex.sub('\s*</embed>\s*', '</embed>', pee)
298+
pee = regex.sub(r'\s*<param([^>]*)>\s*', "<param\\1>", pee) # no pee inside object/embed
299+
pee = regex.sub(r'\s*</embed>\s*', '</embed>', pee)
300300
pee = regex.sub("\n\n+", "\n\n", pee) # take care of duplicates
301301
# make paragraphs, including one at the end
302-
pees = regex.split('\n\s*\n', pee)
302+
pees = regex.split('\n\\s*\n', pee)
303303
pee = ''
304304
for trinkle in pees:
305305
if len(trinkle) > 0: # PHP: this emulates PHP's flag PREG_SPLIT_NO_EMPTY for preg_split()
306306
pee += '<p>' + trinkle.strip("\n") + "</p>\n"
307-
pee = regex.sub('<p>\s*</p>', '', pee) # under certain strange conditions it could create a P of entirely whitespace
307+
pee = regex.sub(r'<p>\s*</p>', '', pee) # under certain strange conditions it could create a P of entirely whitespace
308308
pee = regex.sub('<p>([^<]+)</(div|address|form)>', "<p>\\1</p></\\2>", pee)
309-
pee = regex.sub('<p>\s*(</?' + self.allblocks + '[^>]*>)\s*</p>', "\\1", pee) # don't pee all over a tag
309+
pee = regex.sub(r'<p>\s*(</?' + self.allblocks + r'[^>]*>)\s*</p>', "\\1", pee) # don't pee all over a tag
310310
pee = regex.sub("<p>(<li.+?)</p>", "\\1", pee) # problem with nested lists
311311
pee = regex.sub('<p><blockquote([^>]*)>', "<blockquote\\1><p>", pee, regex.IGNORECASE)
312312
pee = pee.replace('</blockquote></p>', '</p></blockquote>')
313-
pee = regex.sub('<p>\s*(</?' + self.allblocks + '[^>]*>)', "\\1", pee)
314-
pee = regex.sub('(</?' + self.allblocks + '[^>]*>)\s*</p>', "\\1", pee)
313+
pee = regex.sub(r'<p>\s*(</?' + self.allblocks + '[^>]*>)', "\\1", pee)
314+
pee = regex.sub('(</?' + self.allblocks + r'[^>]*>)\s*</p>', "\\1", pee)
315315
if br:
316-
pee = php.preg_replace_callback('<(script|style).*?<\/\\1>', lambda x: self.__autop_newline_preservation_helper(x), pee, regex.DOTALL)
317-
pee = regex.sub('(?<!<br />)\s*\n', "<br />\n", pee) # optionally make line breaks
316+
pee = php.preg_replace_callback('<(script|style).*?<\\/\\1>', lambda x: self.__autop_newline_preservation_helper(x), pee, regex.DOTALL)
317+
pee = regex.sub('(?<!<br />)\\s*\n', "<br />\n", pee) # optionally make line breaks
318318
pee = pee.replace('<WPPreserveNewline />', "\n")
319-
pee = regex.sub('(</?' + self.allblocks + '[^>]*>)\s*<br />', "\\1", pee)
320-
pee = regex.sub('<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)', '\\1', pee)
319+
pee = regex.sub('(</?' + self.allblocks + r'[^>]*>)\s*<br />', "\\1", pee)
320+
pee = regex.sub(r'<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)', '\\1', pee)
321321
pee = regex.sub("\n</p>$", '</p>', pee)
322322

323323
if len(pre_tags) > 0:

v7/wordpress_compiler/wordpress/plugins/wordpress_shortcode_code.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def __init__(self):
3939

4040
def _filter_code_tags(self, text, context):
4141
result = ''
42-
for piece in regex.split('(\[code(?:|\s+language="[^"]*?")\].*?\[/code\])', text, flags=regex.DOTALL | regex.IGNORECASE):
43-
match = regex.match('\[code(?:|\s+language="([^"]*?)")\](.*?)\[/code\]', piece, flags=regex.DOTALL | regex.IGNORECASE)
42+
for piece in regex.split(r'(\[code(?:|\s+language="[^"]*?")\].*?\[/code\])', text, flags=regex.DOTALL | regex.IGNORECASE):
43+
match = regex.match(r'\[code(?:|\s+language="([^"]*?)")\](.*?)\[/code\]', piece, flags=regex.DOTALL | regex.IGNORECASE)
4444
if match is not None:
4545
the_id = str(context.inc_plugin_counter('wordpress_shortcode_code', 'counter'))
4646
context.store_plugin_data('wordpress_shortcode_code', the_id, (match.group(2), match.group(1)))

v7/wordpress_compiler/wordpress/shortcodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def unregister_shortcode(self, tag):
120120
del self._shorcode_tags[tag]
121121

122122
def _extract_arguments(self, argsString):
123-
pattern = '(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)'
123+
pattern = r'(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)'
124124
argsString = regex.sub("[\u00A0\u200B]+", " ", argsString)
125125
matches = regex.findall(pattern, argsString)
126126
if len(matches) > 0:

v8/markmin/markmin/markmin2html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def test():
603603
"\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x05",
604604
"'`:*~\\[]{}@$+-.#\n",
605605
)
606-
regex_quote = re.compile("(?P<name>\w+?)\s*\=\s*")
606+
regex_quote = re.compile(r"(?P<name>\w+?)\s*\=\s*")
607607

608608

609609
def make_dict(b):

v8/webmentions/webmentions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def check_link_header_for_webmention(self, header):
265265
"""Process a header and look for webmention related entries"""
266266

267267
regexes = [
268-
"<(.[^>]+)>;\s+rel\s?=\s?[\"']?(http:\/\/)?webmention(\.org)?\/?[\"']?"
268+
r"<(.[^>]+)>;\s+rel\s?=\s?[\"']?(http:\/\/)?webmention(\.org)?\/?[\"']?"
269269
]
270270

271271
if "webmention" not in header:

0 commit comments

Comments
 (0)