Merge pull request #19621 from cclauss/Fix-ur-strings-for-Python3

ur'strings' are syntax errors in Python 3
This commit is contained in:
Jeremy Bowman
2019-03-19 15:34:55 -04:00
committed by GitHub
5 changed files with 17 additions and 17 deletions

View File

@@ -21,9 +21,9 @@ def _url_replace_regex(prefix):
To anyone contemplating making this more complicated:
http://xkcd.com/1171/
"""
return ur"""
return u"""
(?x) # flags=re.VERBOSE
(?P<quote>\\?['"]) # the opening quotes
(?P<quote>\\\\?['"]) # the opening quotes
(?P<prefix>{prefix}) # the prefix
(?P<rest>.*?) # everything else in the url
(?P=quote) # the first matching closing quote

View File

@@ -91,14 +91,14 @@ def render_number(children):
suffix = ""
if children_latex[-1] in SUFFIXES:
suffix = children_latex.pop()
suffix = ur"\text{{{s}}}".format(s=suffix)
suffix = u"\\text{{{s}}}".format(s=suffix)
# Exponential notation-- the "E" splits the mantissa and exponent
if "E" in children_latex:
pos = children_latex.index("E")
mantissa = "".join(children_latex[:pos])
exponent = "".join(children_latex[pos + 1:])
latex = ur"{m}\!\times\!10^{{{e}}}{s}".format(
latex = u"{m}\\!\\times\\!10^{{{e}}}{s}".format(
m=mantissa, e=exponent, s=suffix
)
return LatexRendered(latex, tall=True)
@@ -125,7 +125,7 @@ def enrich_varname(varname):
greek.append('infty')
if varname in greek:
return ur"\{letter}".format(letter=varname)
return u"\\{letter}".format(letter=varname)
else:
return varname.replace("_", r"\_")
@@ -146,7 +146,7 @@ def variable_closure(variables, casify):
if second:
# Then 'a_b' must become 'a_{b}'
varname = ur"{a}_{{{b}}}".format(
varname = u"{a}_{{{b}}}".format(
a=enrich_varname(first),
b=enrich_varname(second)
)
@@ -177,19 +177,19 @@ def function_closure(functions, casify):
inner = u"{{{expr}}}".format(expr=inner)
else:
if children[1].tall:
inner = ur"\left({expr}\right)".format(expr=inner)
inner = u"\\left({expr}\\right)".format(expr=inner)
else:
inner = u"({expr})".format(expr=inner)
# Correctly format the name of the function.
if fname == "sqrt":
fname = ur"\sqrt"
fname = u"\\sqrt"
elif fname == "log10":
fname = ur"\log_{10}"
fname = u"\\log_{10}"
elif fname == "log2":
fname = ur"\log_2"
fname = u"\\log_2"
else:
fname = ur"\text{{{fname}}}".format(fname=fname)
fname = u"\\text{{{fname}}}".format(fname=fname)
# Put it together.
latex = fname + inner
@@ -245,7 +245,7 @@ def render_frac(numerator, denominator):
else:
den_latex = r"\cdot ".join(k.latex for k in denominator)
latex = ur"\frac{{{num}}}{{{den}}}".format(num=num_latex, den=den_latex)
latex = u"\\frac{{{num}}}{{{den}}}".format(num=num_latex, den=den_latex)
return latex

View File

@@ -12,9 +12,9 @@ def _prefix_only_url_replace_regex(pattern):
"""
Match urls in quotes pulling out the fields from pattern
"""
return re.compile(ur"""
return re.compile(u"""
(?x) # flags=re.VERBOSE
(?P<quote>\\?['"]) # the opening quotes
(?P<quote>\\\\?['"]) # the opening quotes
{}
(?P=quote) # the first matching closing quote
""".format(pattern))
@@ -53,7 +53,7 @@ def rewrite_nonportable_content_links(source_course_id, dest_course_id, text):
usage_block_pattern = unicode(source_course_id.make_usage_key(placeholder_category, placeholder_id))
usage_block_pattern = usage_block_pattern.replace(placeholder_category, r'(?P<category>[^/+@]+)')
usage_block_pattern = usage_block_pattern.replace(placeholder_id, r'(?P<block_id>.*?)')
jump_to_link_base = ur'/courses/{course_key_string}/jump_to/{usage_key_string}'.format(
jump_to_link_base = u'/courses/{course_key_string}/jump_to/{usage_key_string}'.format(
course_key_string=unicode(source_course_id), usage_key_string=usage_block_pattern
)
try:

View File

@@ -21,7 +21,7 @@ from ..signals.handlers import (
)
from ..signals.signals import PROBLEM_RAW_SCORE_CHANGED
UUID_REGEX = re.compile(ur'%(hex)s{8}-%(hex)s{4}-%(hex)s{4}-%(hex)s{4}-%(hex)s{12}' % {'hex': u'[0-9a-f]'})
UUID_REGEX = re.compile(u'%(hex)s{8}-%(hex)s{4}-%(hex)s{4}-%(hex)s{4}-%(hex)s{12}' % {'hex': u'[0-9a-f]'})
FROZEN_NOW_DATETIME = datetime.now().replace(tzinfo=pytz.UTC)
FROZEN_NOW_TIMESTAMP = to_timestamp(FROZEN_NOW_DATETIME)

View File

@@ -13,7 +13,7 @@ def quote_slashes(text):
';;'. By making the escape sequence fixed length, and escaping
identifier character ';', we are able to reverse the escaping.
"""
return re.sub(ur'[;/]', _quote_slashes, text)
return re.sub(r'[;/]', _quote_slashes, text)
def unquote_slashes(text):