From 2b1f238204670aa6764964b15460c70ccae93fee Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sat, 29 Jun 2019 13:29:13 +0000 Subject: [PATCH] Changed regex strings to raw strings and fixed a sort comparison int/str issue. - Legacy-Id: 16333 --- ietf/doc/utils.py | 16 ++++++++-------- ietf/doc/views_search.py | 4 ++-- ietf/group/models.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ietf/doc/utils.py b/ietf/doc/utils.py index 6e5a755fe..4b935b454 100644 --- a/ietf/doc/utils.py +++ b/ietf/doc/utils.py @@ -767,7 +767,7 @@ def get_search_cache_key(params): from ietf.doc.views_search import SearchForm fields = set(SearchForm.base_fields) - set(['sort',]) kwargs = dict([ (k,v) for (k,v) in list(params.items()) if k in fields ]) - key = "doc:document:search:" + hashlib.sha512(json.dumps(kwargs, sort_keys=True)).hexdigest() + key = "doc:document:search:" + hashlib.sha512(json.dumps(kwargs, sort_keys=True).encode()).hexdigest() return key def label_wrap(label, items, joiner=',', max=50): @@ -817,21 +817,21 @@ def build_doc_meta_block(doc, path): ipr_url = "%s?submit=draft&id=%s" % (urlreverse('ietf.ipr.views.search'), name) for i, line in enumerate(lines): # add draft links - line = re.sub(r'\b(draft-[-a-z0-9]+)\b', '\g<1>'%(path, ), line) + line = re.sub(r'\b(draft-[-a-z0-9]+)\b', r'\g<1>'%(path, ), line) # add rfcXXXX to RFC links - line = re.sub(r' (rfc[0-9]+)\b', ' \g<1>'%(path, ), line) + line = re.sub(r' (rfc[0-9]+)\b', r' \g<1>'%(path, ), line) # add XXXX to RFC links - line = re.sub(r' ([0-9]{3,5})\b', ' \g<1>'%(path, ), line) + line = re.sub(r' ([0-9]{3,5})\b', r' \g<1>'%(path, ), line) # add draft revision links - line = re.sub(r' ([0-9]{2})\b', ' \g<1>'%(path, name, ), line) + line = re.sub(r' ([0-9]{2})\b', r' \g<1>'%(path, name, ), line) if rfcnum: # add errata link - line = re.sub(r'Errata exist', 'Errata exist'%(errata_url, ), line) + line = re.sub(r'Errata exist', r'Errata exist'%(errata_url, ), line) if is_hst or not rfcnum: # make current draft rev bold line = re.sub(r'>(%s)<'%rev, '>\g<1><', line) - line = re.sub(r'IPR declarations', 'IPR declarations'%(ipr_url, ), line) - line = line.replace(r'[txt]', '[txt]' % doc.href()) + line = re.sub(r'IPR declarations', r'IPR declarations'%(ipr_url, ), line) + line = line.replace(r'[txt]', r'[txt]' % doc.href()) lines[i] = line return lines # diff --git a/ietf/doc/views_search.py b/ietf/doc/views_search.py index 24ec9f51e..5f9a26fd8 100644 --- a/ietf/doc/views_search.py +++ b/ietf/doc/views_search.py @@ -265,7 +265,7 @@ def search_for_name(request, name): return HttpResponseRedirect(url) # chop away extension - extension_split = re.search("^(.+)\.(txt|ps|pdf)$", n) + extension_split = re.search(r"^(.+)\.(txt|ps|pdf)$", n) if extension_split: n = extension_split.group(1) @@ -494,7 +494,7 @@ def index_all_drafts(request): if name.startswith("rfc"): name = name.upper() - sort_key = -int(name[3:]) + sort_key = '%09d' % (100000000-int(name[3:])) names.append((name, sort_key)) diff --git a/ietf/group/models.py b/ietf/group/models.py index 62879df80..ec36e8014 100644 --- a/ietf/group/models.py +++ b/ietf/group/models.py @@ -192,7 +192,7 @@ class Group(GroupInfo): text = self.charter.text() # split into paragraphs and grab the first non-empty one if text: - desc = [ p for p in re.split('\r?\n\s*\r?\n\s*', text) if p.strip() ][0] + desc = [ p for p in re.split(r'\r?\n\s*\r?\n\s*', text) if p.strip() ][0] return desc