diff --git a/cms/djangoapps/models/settings/course_details.py b/cms/djangoapps/models/settings/course_details.py index 3f0c87917a4b4657d87127ce5a1a4ddb23669b32..884a4e4fefe99767b59a5a22b1d387a17e1c31ae 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 30d0483f5082d7828aab5b85c76c007573a04360..869e37f13b7e6d39b2d7702e8b8329684b61d70e 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 de3e52b0800eea75b58df8383dfa8f17843956d3..4da7b9d789156ea6f4cbad8d36ca415cf2feaa9c 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 f31be894f9a2d459dcd6b7fb262d43cbe694f453..e69476a5b7129dd3fe19d19febd2adf8dc8b135a 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 2a9f3d82a327ccbc1621ae1097bd327402ea30b1..d620bac60aa5dec287284ea817afdce3ee7a31af 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 9d7ff719accec8cd67e30408c898e8118fc1e144..f7d586c9d55d2b066cdf351e2a109bc825d8f09e 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 446b832dd7ffc2cc6025e2b493727cbcd2c17fc6..f026568da1228f8a974b7342384ada757cef2761 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 be70e3866cd3c038c5198ea457fb8d27e77f0f53..97319bdb9e73fbd42eec5e6d7eb731f4f5bca215 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 a926d9ae4595d0852c3d11e1e26ff13e26a8d235..ca4e20ace3c395d0276981942be3ba47d3e4571f 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 a704fc2ae866c00ddb45940ef705dfcbb3138cca..ef5fa617de7032596ea79a94c9c8f097d38079f9 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 6c2e44eed51970142a3670ff0eda5ecf9efdfd31..49852ee233b5851c360daf98fa9e6a214e3a741a 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 6ab106ed70a44230922527ed784aa6a2330d2912..74ef7d4a7407585a908eb3dab3d44bc228e08c07 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 da361a2a825e9234ff860870a6081efd4fa13496..76d9bfff982d27f96ced6e7f8bbfbc8402aa41e6 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))