From df6d3f9b2f9f9023b4f2710c8c1ee5c05aeef9b1 Mon Sep 17 00:00:00 2001 From: Ned Batchelder <ned@nedbatchelder.com> Date: Mon, 17 Jun 2013 20:43:18 -0400 Subject: [PATCH] Fix strings that should be raw. --- cms/djangoapps/models/settings/course_details.py | 4 ++-- common/djangoapps/student/management/commands/set_staff.py | 2 +- common/djangoapps/student/views.py | 6 +++--- common/djangoapps/terrain/steps.py | 2 +- common/lib/capa/capa/capa_problem.py | 4 ++-- common/lib/capa/capa/customrender.py | 4 ++-- common/lib/capa/capa/inputtypes.py | 2 +- common/lib/capa/capa/responsetypes.py | 5 ++--- common/lib/symmath/symmath/formula.py | 4 ++-- common/lib/xmodule/xmodule/modulestore/xml.py | 2 +- common/lib/xmodule/xmodule/tests/test_stringify.py | 2 +- lms/djangoapps/course_wiki/views.py | 2 +- lms/djangoapps/foldit/views.py | 2 +- 13 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cms/djangoapps/models/settings/course_details.py b/cms/djangoapps/models/settings/course_details.py index 3f0c87917a4..884a4e4fefe 100644 --- a/cms/djangoapps/models/settings/course_details.py +++ b/cms/djangoapps/models/settings/course_details.py @@ -153,9 +153,9 @@ class CourseDetails(object): if not raw_video: return None - keystring_matcher = re.search('(?<=embed/)[a-zA-Z0-9_-]+', raw_video) + keystring_matcher = re.search(r'(?<=embed/)[a-zA-Z0-9_-]+', raw_video) if keystring_matcher is None: - keystring_matcher = re.search('<?=\d+:[a-zA-Z0-9_-]+', raw_video) + keystring_matcher = re.search(r'<?=\d+:[a-zA-Z0-9_-]+', raw_video) if keystring_matcher: return keystring_matcher.group(0) diff --git a/common/djangoapps/student/management/commands/set_staff.py b/common/djangoapps/student/management/commands/set_staff.py index 30d0483f508..869e37f13b7 100644 --- a/common/djangoapps/student/management/commands/set_staff.py +++ b/common/djangoapps/student/management/commands/set_staff.py @@ -26,7 +26,7 @@ class Command(BaseCommand): raise CommandError('Usage is set_staff {0}'.format(self.args)) for user in args: - if re.match('[^@]+@[^@]+\.[^@]+', user): + if re.match(r'[^@]+@[^@]+\.[^@]+', user): try: v = User.objects.get(email=user) except: diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index de3e52b0800..4da7b9d7891 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -3,6 +3,7 @@ import feedparser import json import logging import random +import re import string import urllib import uuid @@ -95,9 +96,8 @@ def course_from_id(course_id): course_loc = CourseDescriptor.id_to_location(course_id) return modulestore().get_instance(course_id, course_loc) -import re -day_pattern = re.compile('\s\d+,\s') -multimonth_pattern = re.compile('\s?\-\s?\S+\s') +day_pattern = re.compile(r'\s\d+,\s') +multimonth_pattern = re.compile(r'\s?\-\s?\S+\s') def get_date_for_press(publish_date): diff --git a/common/djangoapps/terrain/steps.py b/common/djangoapps/terrain/steps.py index f31be894f9a..e69476a5b71 100644 --- a/common/djangoapps/terrain/steps.py +++ b/common/djangoapps/terrain/steps.py @@ -21,7 +21,7 @@ from logging import getLogger logger = getLogger(__name__) -@step(u'I wait (?:for )?"(\d+)" seconds?$') +@step(r'I wait (?:for )?"(\d+)" seconds?$') def wait(step, seconds): world.wait(seconds) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 2a9f3d82a32..d620bac60aa 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -103,8 +103,8 @@ class LoncapaProblem(object): self.input_state = state.get('input_state', {}) # Convert startouttext and endouttext to proper <text></text> - problem_text = re.sub("startouttext\s*/", "text", problem_text) - problem_text = re.sub("endouttext\s*/", "/text", problem_text) + problem_text = re.sub(r"startouttext\s*/", "text", problem_text) + problem_text = re.sub(r"endouttext\s*/", "/text", problem_text) self.problem_text = problem_text # parse problem XML file into an element tree diff --git a/common/lib/capa/capa/customrender.py b/common/lib/capa/capa/customrender.py index 9d7ff719acc..f7d586c9d55 100644 --- a/common/lib/capa/capa/customrender.py +++ b/common/lib/capa/capa/customrender.py @@ -26,7 +26,7 @@ class MathRenderer(object): tags = ['math'] def __init__(self, system, xml): - ''' + r''' Render math using latex-like formatting. Examples: @@ -41,7 +41,7 @@ class MathRenderer(object): self.system = system self.xml = xml - mathstr = re.sub('\$(.*)\$', r'[mathjaxinline]\1[/mathjaxinline]', xml.text) + mathstr = re.sub(r'\$(.*)\$', r'[mathjaxinline]\1[/mathjaxinline]', xml.text) mtag = 'mathjax' if not r'\displaystyle' in mathstr: mtag += 'inline' diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 446b832dd7f..f026568da12 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -856,7 +856,7 @@ class ImageInput(InputTypeBase): """ if value is of the form [x,y] then parse it and send along coordinates of previous answer """ - m = re.match('\[([0-9]+),([0-9]+)]', + m = re.match(r'\[([0-9]+),([0-9]+)]', self.value.strip().replace(' ', '')) if m: # Note: we subtract 15 to compensate for the size of the dot on the screen. diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index be70e3866cd..97319bdb9e7 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1902,8 +1902,7 @@ class ImageResponse(LoncapaResponse): if not given: # No answer to parse. Mark as incorrect and move on continue # parse given answer - m = re.match( - '\[([0-9]+),([0-9]+)]', given.strip().replace(' ', '')) + m = re.match(r'\[([0-9]+),([0-9]+)]', given.strip().replace(' ', '')) if not m: raise Exception('[capamodule.capa.responsetypes.imageinput] ' 'error grading %s (input=%s)' % (aid, given)) @@ -1918,7 +1917,7 @@ class ImageResponse(LoncapaResponse): # parse expected answer # TODO: Compile regexp on file load m = re.match( - '[\(\[]([0-9]+),([0-9]+)[\)\]]-[\(\[]([0-9]+),([0-9]+)[\)\]]', + r'[\(\[]([0-9]+),([0-9]+)[\)\]]-[\(\[]([0-9]+),([0-9]+)[\)\]]', solution_rectangle.strip().replace(' ', '')) if not m: msg = 'Error in problem specification! cannot parse rectangle in %s' % ( diff --git a/common/lib/symmath/symmath/formula.py b/common/lib/symmath/symmath/formula.py index a926d9ae459..ca4e20ace3c 100644 --- a/common/lib/symmath/symmath/formula.py +++ b/common/lib/symmath/symmath/formula.py @@ -50,7 +50,7 @@ class dot(sympy.operations.LatticeOp): # my dot product def _print_dot(self, expr): - return '{((%s) \cdot (%s))}' % (expr.args[0], expr.args[1]) + return r'{((%s) \cdot (%s))}' % (expr.args[0], expr.args[1]) LatexPrinter._print_dot = _print_dot @@ -202,7 +202,7 @@ class formula(object): return xml def preprocess_pmathml(self, xml): - ''' + r''' Pre-process presentation MathML from ASCIIMathML to make it more acceptable for SnuggleTeX, and also to accomodate some sympy conventions (eg hat(i) for \hat{i}). diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index a704fc2ae86..ef5fa617de7 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -38,7 +38,7 @@ log = logging.getLogger(__name__) # into the cms from xml def clean_out_mako_templating(xml_string): xml_string = xml_string.replace('%include', 'include') - xml_string = re.sub("(?m)^\s*%.*$", '', xml_string) + xml_string = re.sub(r"(?m)^\s*%.*$", '', xml_string) return xml_string diff --git a/common/lib/xmodule/xmodule/tests/test_stringify.py b/common/lib/xmodule/xmodule/tests/test_stringify.py index 6c2e44eed51..49852ee233b 100644 --- a/common/lib/xmodule/xmodule/tests/test_stringify.py +++ b/common/lib/xmodule/xmodule/tests/test_stringify.py @@ -12,7 +12,7 @@ def test_stringify(): def test_stringify_again(): - html = """<html name="Voltage Source Answer" >A voltage source is non-linear! + html = r"""<html name="Voltage Source Answer" >A voltage source is non-linear! <div align="center"> <img src="/static/images/circuits/voltage-source.png"/> \(V=V_C\) diff --git a/lms/djangoapps/course_wiki/views.py b/lms/djangoapps/course_wiki/views.py index 6ab106ed70a..74ef7d4a740 100644 --- a/lms/djangoapps/course_wiki/views.py +++ b/lms/djangoapps/course_wiki/views.py @@ -49,7 +49,7 @@ def course_wiki_redirect(request, course_id): if not course_slug: log.exception("This course is improperly configured. The slug cannot be empty.") valid_slug = False - if re.match('^[-\w\.]+$', course_slug) is None: + if re.match(r'^[-\w\.]+$', course_slug) is None: log.exception("This course is improperly configured. The slug can only contain letters, numbers, periods or hyphens.") valid_slug = False diff --git a/lms/djangoapps/foldit/views.py b/lms/djangoapps/foldit/views.py index da361a2a825..76d9bfff982 100644 --- a/lms/djangoapps/foldit/views.py +++ b/lms/djangoapps/foldit/views.py @@ -46,7 +46,7 @@ def foldit_ops(request): # To allow for fixes without breaking this, the regex should only # match unquoted strings, a = re.compile(r':([a-zA-Z]*),') - puzzle_scores_json = re.sub(a, ':"\g<1>",', puzzle_scores_json) + puzzle_scores_json = re.sub(a, r':"\g<1>",', puzzle_scores_json) puzzle_scores = json.loads(puzzle_scores_json) responses.append(save_scores(request.user, puzzle_scores)) -- GitLab