From 9a0c9958859feb1d423997941e2e774d9c866edd Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 17 Jan 2019 16:30:16 +0100 Subject: [PATCH 1/2] ur'strings' are syntax errors in Python 3 --- common/djangoapps/static_replace/__init__.py | 4 ++-- common/lib/calc/calc/preview.py | 20 +++++++++---------- .../xmodule/modulestore/store_utilities.py | 6 +++--- lms/djangoapps/grades/tests/test_signals.py | 2 +- openedx/core/lib/url_utils.py | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/djangoapps/static_replace/__init__.py b/common/djangoapps/static_replace/__init__.py index 467086c8c0..b718ad17a0 100644 --- a/common/djangoapps/static_replace/__init__.py +++ b/common/djangoapps/static_replace/__init__.py @@ -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\\?['"]) # the opening quotes + (?P\\\\?['"]) # the opening quotes (?P{prefix}) # the prefix (?P.*?) # everything else in the url (?P=quote) # the first matching closing quote diff --git a/common/lib/calc/calc/preview.py b/common/lib/calc/calc/preview.py index 544776e4ad..5c04177ac3 100644 --- a/common/lib/calc/calc/preview.py +++ b/common/lib/calc/calc/preview.py @@ -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 diff --git a/common/lib/xmodule/xmodule/modulestore/store_utilities.py b/common/lib/xmodule/xmodule/modulestore/store_utilities.py index 691ce7941d..018734a959 100644 --- a/common/lib/xmodule/xmodule/modulestore/store_utilities.py +++ b/common/lib/xmodule/xmodule/modulestore/store_utilities.py @@ -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\\?['"]) # the opening quotes + (?P\\\\?['"]) # 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[^/+@]+)') usage_block_pattern = usage_block_pattern.replace(placeholder_id, r'(?P.*?)') - 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: diff --git a/lms/djangoapps/grades/tests/test_signals.py b/lms/djangoapps/grades/tests/test_signals.py index 70986c1fcc..bd20ce1793 100644 --- a/lms/djangoapps/grades/tests/test_signals.py +++ b/lms/djangoapps/grades/tests/test_signals.py @@ -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) diff --git a/openedx/core/lib/url_utils.py b/openedx/core/lib/url_utils.py index 4f23ce21ba..b4e87ff5bb 100644 --- a/openedx/core/lib/url_utils.py +++ b/openedx/core/lib/url_utils.py @@ -13,14 +13,14 @@ 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): """ Unquote slashes quoted by `quote_slashes` """ - return re.sub(r'(;;|;_)', _unquote_slashes, text) + return re.sub(u'(;;|;_)', _unquote_slashes, text) def _quote_slashes(match): From 6a41d01c67bc12301a89cc4b1b49ef73e9665a91 Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 19 Mar 2019 07:50:22 +0100 Subject: [PATCH 2/2] Back to r again --- openedx/core/lib/url_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openedx/core/lib/url_utils.py b/openedx/core/lib/url_utils.py index b4e87ff5bb..f31d1ab30a 100644 --- a/openedx/core/lib/url_utils.py +++ b/openedx/core/lib/url_utils.py @@ -20,7 +20,7 @@ def unquote_slashes(text): """ Unquote slashes quoted by `quote_slashes` """ - return re.sub(u'(;;|;_)', _unquote_slashes, text) + return re.sub(r'(;;|;_)', _unquote_slashes, text) def _quote_slashes(match):