From c5815a2564bb38061588147ab6305b678da5c6ca Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 26 Jun 2021 22:29:49 +0100 Subject: [PATCH] Tidying --- posts.py | 42 +++++++++++++++++++++++++++--------------- tests.py | 14 ++++++++++++++ 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/posts.py b/posts.py index 230b7d72f..22bb0cf4a 100644 --- a/posts.py +++ b/posts.py @@ -852,6 +852,30 @@ def _addAutoCW(baseDir: str, nickname: str, domain: str, return newSubject +def _createPostCWFromReply(baseDir: str, nickname: str, domain: str, + inReplyTo: str, + sensitive: bool, summary: str) -> (bool, str): + """If this is a reply and the original post has a CW + then use the same CW + """ + if inReplyTo and not sensitive: + # locate the post which this is a reply to and check if + # it has a content warning. If it does then reproduce + # the same warning + replyPostFilename = \ + locatePost(baseDir, nickname, domain, inReplyTo) + if replyPostFilename: + replyToJson = loadJson(replyPostFilename) + if replyToJson: + if replyToJson.get('object'): + if replyToJson['object'].get('sensitive'): + if replyToJson['object']['sensitive']: + sensitive = True + if replyToJson['object'].get('summary'): + summary = replyToJson['object']['summary'] + return sensitive, summary + + def _createPostBase(baseDir: str, nickname: str, domain: str, port: int, toUrl: str, ccUrl: str, httpPrefix: str, content: str, followersOnly: bool, saveToFile: bool, @@ -952,21 +976,9 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int, _updateHashtagsIndex(baseDir, tag, newPostId) # print('Content tags: ' + str(tags)) - if inReplyTo and not sensitive: - # locate the post which this is a reply to and check if - # it has a content warning. If it does then reproduce - # the same warning - replyPostFilename = \ - locatePost(baseDir, nickname, domain, inReplyTo) - if replyPostFilename: - replyToJson = loadJson(replyPostFilename) - if replyToJson: - if replyToJson.get('object'): - if replyToJson['object'].get('sensitive'): - if replyToJson['object']['sensitive']: - sensitive = True - if replyToJson['object'].get('summary'): - summary = replyToJson['object']['summary'] + sensitive, summary = \ + _createPostCWFromReply(baseDir, nickname, domain, + inReplyTo, sensitive, summary) # get the ending date and time endDateStr = None diff --git a/tests.py b/tests.py index 7ccfbd7e1..cefa769d7 100644 --- a/tests.py +++ b/tests.py @@ -3016,6 +3016,7 @@ def _testFunctions(): if not line.strip().startswith('def '): if lineCount > 0: lineCount += 1 + # add LOC count for this function if len(prevLine.strip()) == 0 and \ len(line.strip()) == 0 and \ lineCount > 2: @@ -3051,6 +3052,19 @@ def _testFunctions(): "module": modName, "calledInModule": [] } + # LOC count for the last function + if lineCount > 2: + lineCount -= 2 + if lineCount > 80: + locStr = str(lineCount) + ';' + methodName + if lineCount < 1000: + locStr = '0' + locStr + if lineCount < 100: + locStr = '0' + locStr + if lineCount < 10: + locStr = '0' + locStr + if locStr not in methodLOC: + methodLOC.append(locStr) break print('LOC counts:')