Avoid conflic with python 3.10 match keyword

merge-requests/30/head
Bob Mottram 2021-10-07 20:03:01 +01:00
parent a8f17d3773
commit c2d9aa3f9b
3 changed files with 38 additions and 37 deletions

View File

@ -181,8 +181,8 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
cssMatches = ('behavior:', ':expression', '?php', '.php', cssMatches = ('behavior:', ':expression', '?php', '.php',
'google', 'regexp', 'localhost', 'google', 'regexp', 'localhost',
'127.0.', '192.168', '10.0.', '@import') '127.0.', '192.168', '10.0.', '@import')
for match in cssMatches: for cssmatch in cssMatches:
if match in content: if cssmatch in content:
return True return True
# search for non-local web links # search for non-local web links
@ -727,8 +727,8 @@ def _autoTag(baseDir: str, nickname: str, domain: str,
continue continue
if '->' not in tagRule: if '->' not in tagRule:
continue continue
match = tagRule.split('->')[0].strip() rulematch = tagRule.split('->')[0].strip()
if match != wordStr: if rulematch != wordStr:
continue continue
tagName = tagRule.split('->')[1].strip() tagName = tagRule.split('->')[1].strip()
if tagName.startswith('#'): if tagName.startswith('#'):

View File

@ -997,8 +997,8 @@ def _addAutoCW(baseDir: str, nickname: str, domain: str,
for cwRule in autoCWList: for cwRule in autoCWList:
if '->' not in cwRule: if '->' not in cwRule:
continue continue
match = cwRule.split('->')[0].strip() rulematch = cwRule.split('->')[0].strip()
if match not in content: if rulematch not in content:
continue continue
cwStr = cwRule.split('->')[1].strip() cwStr = cwRule.split('->')[1].strip()
if newSubject: if newSubject:

View File

@ -340,16 +340,17 @@ def parse_link_header(header):
return rval return rval
r_link_header = r'\s*<([^>]*?)>\s*(?:;\s*(.*))?' r_link_header = r'\s*<([^>]*?)>\s*(?:;\s*(.*))?'
for entry in entries: for entry in entries:
match = re.search(r_link_header, entry) ldmatch = re.search(r_link_header, entry)
if not match: if not ldmatch:
continue continue
match = match.groups() ldmatch = ldmatch.groups()
result = {'target': match[0]} result = {'target': ldmatch[0]}
params = match[1] params = ldmatch[1]
r_params = r'(.*?)=(?:(?:"([^"]*?)")|([^"]*?))\s*(?:(?:;\s*)|$)' r_params = r'(.*?)=(?:(?:"([^"]*?)")|([^"]*?))\s*(?:(?:;\s*)|$)'
matches = re.findall(r_params, params) matches = re.findall(r_params, params)
for match in matches: for ldmatch in matches:
result[match[0]] = match[2] if match[1] is None else match[1] result[ldmatch[0]] = \
ldmatch[2] if ldmatch[1] is None else ldmatch[1]
rel = result.get('rel', '') rel = result.get('rel', '')
if isinstance(rval.get(rel), list): if isinstance(rval.get(rel), list):
rval[rel].append(result) rval[rel].append(result)
@ -1474,30 +1475,30 @@ class JsonLdProcessor(object):
continue continue
# parse quad # parse quad
match = re.search(quad, line) ldmatch = re.search(quad, line)
if match is None: if ldmatch is None:
raise JsonLdError( raise JsonLdError(
'Error while parsing N-Quads invalid quad.', 'Error while parsing N-Quads invalid quad.',
'jsonld.ParseError', {'line': line_number}) 'jsonld.ParseError', {'line': line_number})
match = match.groups() ldmatch = ldmatch.groups()
# create RDF triple # create RDF triple
triple = {'subject': {}, 'predicate': {}, 'object': {}} triple = {'subject': {}, 'predicate': {}, 'object': {}}
# get subject # get subject
if match[0] is not None: if ldmatch[0] is not None:
triple['subject'] = {'type': 'IRI', 'value': match[0]} triple['subject'] = {'type': 'IRI', 'value': ldmatch[0]}
else: else:
triple['subject'] = {'type': 'blank node', 'value': match[1]} triple['subject'] = {'type': 'blank node', 'value': ldmatch[1]}
# get predicate # get predicate
triple['predicate'] = {'type': 'IRI', 'value': match[2]} triple['predicate'] = {'type': 'IRI', 'value': ldmatch[2]}
# get object # get object
if match[3] is not None: if ldmatch[3] is not None:
triple['object'] = {'type': 'IRI', 'value': match[3]} triple['object'] = {'type': 'IRI', 'value': ldmatch[3]}
elif match[4] is not None: elif ldmatch[4] is not None:
triple['object'] = {'type': 'blank node', 'value': match[4]} triple['object'] = {'type': 'blank node', 'value': ldmatch[4]}
else: else:
triple['object'] = {'type': 'literal'} triple['object'] = {'type': 'literal'}
replacements = { replacements = {
@ -1507,24 +1508,24 @@ class JsonLdProcessor(object):
'\\r': '\r', '\\r': '\r',
'\\\\': '\\' '\\\\': '\\'
} }
unescaped = match[5] unescaped = ldmatch[5]
for match, repl in replacements.items(): for ldmatch, repl in replacements.items():
unescaped = unescaped.replace(match, repl) unescaped = unescaped.replace(ldmatch, repl)
if match[6] is not None: if ldmatch[6] is not None:
triple['object']['datatype'] = match[6] triple['object']['datatype'] = ldmatch[6]
elif match[7] is not None: elif ldmatch[7] is not None:
triple['object']['datatype'] = RDF_LANGSTRING triple['object']['datatype'] = RDF_LANGSTRING
triple['object']['language'] = match[7] triple['object']['language'] = ldmatch[7]
else: else:
triple['object']['datatype'] = XSD_STRING triple['object']['datatype'] = XSD_STRING
triple['object']['value'] = unescaped triple['object']['value'] = unescaped
# get graph name ('@default' is used for the default graph) # get graph name ('@default' is used for the default graph)
name = '@default' name = '@default'
if match[8] is not None: if ldmatch[8] is not None:
name = match[8] name = ldmatch[8]
elif match[9] is not None: elif ldmatch[9] is not None:
name = match[9] name = ldmatch[9]
# initialize graph in dataset # initialize graph in dataset
if name not in dataset: if name not in dataset:
@ -1623,8 +1624,8 @@ class JsonLdProcessor(object):
'\"': '\\"' '\"': '\\"'
} }
escaped = o['value'] escaped = o['value']
for match, repl in replacements.items(): for ldmatch, repl in replacements.items():
escaped = escaped.replace(match, repl) escaped = escaped.replace(ldmatch, repl)
quad += '"' + escaped + '"' quad += '"' + escaped + '"'
if o['datatype'] == RDF_LANGSTRING: if o['datatype'] == RDF_LANGSTRING:
if o['language']: if o['language']: