main
Bob Mottram 2020-10-17 17:46:21 +01:00
parent 30f4a03b5c
commit aa1017b3a8
1 changed files with 8 additions and 8 deletions

View File

@ -73,7 +73,7 @@ def removeControlCharacters(content: str) -> str:
return content return content
def hasttagRuleResolve(tree: [], hashtags: []) -> bool: def hashtagRuleResolve(tree: [], hashtags: []) -> bool:
"""Returns whether the tree for a hashtag rule evaluates to true or false """Returns whether the tree for a hashtag rule evaluates to true or false
""" """
if not tree: if not tree:
@ -84,7 +84,7 @@ def hasttagRuleResolve(tree: [], hashtags: []) -> bool:
if isinstance(tree[1], str): if isinstance(tree[1], str):
return tree[1] not in hashtags return tree[1] not in hashtags
elif isinstance(tree[1], list): elif isinstance(tree[1], list):
return not hasttagRuleResolve(tree[1], hashtags) return not hashtagRuleResolve(tree[1], hashtags)
elif tree[0] == 'and': elif tree[0] == 'and':
if len(tree) == 3: if len(tree) == 3:
@ -92,13 +92,13 @@ def hasttagRuleResolve(tree: [], hashtags: []) -> bool:
if isinstance(tree[1], str): if isinstance(tree[1], str):
firstArg = (tree[1] in hashtags) firstArg = (tree[1] in hashtags)
elif isinstance(tree[1], list): elif isinstance(tree[1], list):
firstArg = (hasttagRuleResolve(tree[1], hashtags)) firstArg = (hashtagRuleResolve(tree[1], hashtags))
secondArg = False secondArg = False
if isinstance(tree[2], str): if isinstance(tree[2], str):
secondArg = (tree[2] in hashtags) secondArg = (tree[2] in hashtags)
elif isinstance(tree[2], list): elif isinstance(tree[2], list):
secondArg = (hasttagRuleResolve(tree[2], hashtags)) secondArg = (hashtagRuleResolve(tree[2], hashtags))
return firstArg and secondArg return firstArg and secondArg
elif tree[0] == 'or': elif tree[0] == 'or':
if len(tree) == 3: if len(tree) == 3:
@ -107,13 +107,13 @@ def hasttagRuleResolve(tree: [], hashtags: []) -> bool:
if isinstance(tree[1], str): if isinstance(tree[1], str):
firstArg = (tree[1] in hashtags) firstArg = (tree[1] in hashtags)
elif isinstance(tree[1], list): elif isinstance(tree[1], list):
firstArg = (hasttagRuleResolve(tree[1], hashtags)) firstArg = (hashtagRuleResolve(tree[1], hashtags))
secondArg = False secondArg = False
if isinstance(tree[2], str): if isinstance(tree[2], str):
secondArg = (tree[2] in hashtags) secondArg = (tree[2] in hashtags)
elif isinstance(tree[2], list): elif isinstance(tree[2], list):
secondArg = (hasttagRuleResolve(tree[2], hashtags)) secondArg = (hashtagRuleResolve(tree[2], hashtags))
return firstArg or secondArg return firstArg or secondArg
elif tree[0].startswith('#') and len(tree) == 1: elif tree[0].startswith('#') and len(tree) == 1:
return tree[0] in hashtags return tree[0] in hashtags
@ -165,7 +165,7 @@ def hashtagRuleTree(operators: [],
def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {}, def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
hashtags: str, httpPrefix: str, hashtags: [], httpPrefix: str,
domain: str, port: int, domain: str, port: int,
personCache: {}, personCache: {},
cachedWebfingers: {}, cachedWebfingers: {},
@ -203,7 +203,7 @@ def newswireHashtagProcessing(session, baseDir: str, postJsonObject: {},
# does the rule contain any hashtags? # does the rule contain any hashtags?
if not tagsInConditions: if not tagsInConditions:
continue continue
if not hasttagRuleResolve(tree, hashtags): if not hashtagRuleResolve(tree, hashtags):
continue continue
# the condition matches, so do something # the condition matches, so do something
actionStr = ruleStr.split(' then ')[1].strip() actionStr = ruleStr.split(' then ')[1].strip()