Snake case

merge-requests/30/head
Bob Mottram 2021-12-26 11:29:40 +00:00
parent 594b3beb55
commit dcafa28ee4
13 changed files with 50 additions and 42 deletions

12
blog.py
View File

@ -19,7 +19,7 @@ from webapp_utils import editTextArea
from webapp_media import addEmbeddedElements from webapp_media import addEmbeddedElements
from utils import local_actor_url from utils import local_actor_url
from utils import get_actor_languages_list from utils import get_actor_languages_list
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import get_content_from_post from utils import get_content_from_post
from utils import isAccountDir from utils import isAccountDir
from utils import removeHtml from utils import removeHtml
@ -368,7 +368,8 @@ def _htmlBlogPostRSS2(authorized: bool,
titleStr = post_json_object['object']['summary'] titleStr = post_json_object['object']['summary']
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT") rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
content = \ content = \
getBaseContentFromPost(post_json_object, system_language) get_base_content_from_post(post_json_object,
system_language)
description = firstParagraphFromString(content) description = firstParagraphFromString(content)
rssStr = ' <item>' rssStr = ' <item>'
rssStr += ' <title>' + titleStr + '</title>' rssStr += ' <title>' + titleStr + '</title>'
@ -402,7 +403,8 @@ def _htmlBlogPostRSS3(authorized: bool,
titleStr = post_json_object['object']['summary'] titleStr = post_json_object['object']['summary']
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT") rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
content = \ content = \
getBaseContentFromPost(post_json_object, system_language) get_base_content_from_post(post_json_object,
system_language)
description = firstParagraphFromString(content) description = firstParagraphFromString(content)
rssStr = 'title: ' + titleStr + '\n' rssStr = 'title: ' + titleStr + '\n'
rssStr += 'link: ' + messageLink + '\n' rssStr += 'link: ' + messageLink + '\n'
@ -427,7 +429,7 @@ def _getSnippetFromBlogContent(post_json_object: {},
system_language: str) -> str: system_language: str) -> str:
"""Returns a snippet of text from the blog post as a preview """Returns a snippet of text from the blog post as a preview
""" """
content = getBaseContentFromPost(post_json_object, system_language) content = get_base_content_from_post(post_json_object, system_language)
if '<p>' in content: if '<p>' in content:
content = content.split('<p>', 1)[1] content = content.split('<p>', 1)[1]
if '</p>' in content: if '</p>' in content:
@ -896,7 +898,7 @@ def htmlEditBlog(media_instance: bool, translate: {},
editBlogForm += ' <br>' editBlogForm += ' <br>'
messageBoxHeight = 800 messageBoxHeight = 800
contentStr = getBaseContentFromPost(post_json_object, system_language) contentStr = get_base_content_from_post(post_json_object, system_language)
contentStr = contentStr.replace('<p>', '').replace('</p>', '\n') contentStr = contentStr.replace('<p>', '').replace('</p>', '\n')
editBlogForm += \ editBlogForm += \

View File

@ -254,7 +254,7 @@ from utils import local_actor_url
from utils import isfloat from utils import isfloat
from utils import validPassword from utils import validPassword
from utils import removeLineEndings from utils import removeLineEndings
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import acctDir from utils import acctDir
from utils import getImageExtensionFromMimeType from utils import getImageExtensionFromMimeType
from utils import getImageMimeType from utils import getImageMimeType
@ -16640,9 +16640,10 @@ class PubServer(BaseHTTPRequestHandler):
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
if pinToProfile: if pinToProfile:
sys_language = self.server.system_language
contentStr = \ contentStr = \
getBaseContentFromPost(message_json, get_base_content_from_post(message_json,
self.server.system_language) sys_language)
followersOnly = False followersOnly = False
pinPost(self.server.base_dir, pinPost(self.server.base_dir,
nickname, self.server.domain, contentStr, nickname, self.server.domain, contentStr,

View File

@ -16,7 +16,7 @@ import webbrowser
import urllib.parse import urllib.parse
from pathlib import Path from pathlib import Path
from random import randint from random import randint
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import has_object_dict from utils import has_object_dict
from utils import getFullDomain from utils import getFullDomain
from utils import isDM from utils import isDM
@ -720,8 +720,8 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
post_json_object2['object'].get('content'): post_json_object2['object'].get('content'):
attributedTo = post_json_object2['object']['attributedTo'] attributedTo = post_json_object2['object']['attributedTo']
content = \ content = \
getBaseContentFromPost(post_json_object2, get_base_content_from_post(post_json_object2,
system_language) system_language)
if isinstance(attributedTo, str) and content: if isinstance(attributedTo, str) and content:
actor = attributedTo actor = attributedTo
nameStr += ' ' + translate['announces'] + ' ' + \ nameStr += ' ' + translate['announces'] + ' ' + \
@ -746,7 +746,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
attributedTo = post_json_object['object']['attributedTo'] attributedTo = post_json_object['object']['attributedTo']
if not attributedTo: if not attributedTo:
return {} return {}
content = getBaseContentFromPost(post_json_object, system_language) content = get_base_content_from_post(post_json_object, system_language)
if not isinstance(attributedTo, str) or \ if not isinstance(attributedTo, str) or \
not isinstance(content, str): not isinstance(content, str):
return {} return {}
@ -1072,7 +1072,8 @@ def _desktopShowBox(indent: str,
published = _formatPublished(post_json_object['published']) published = _formatPublished(post_json_object['published'])
contentStr = getBaseContentFromPost(post_json_object, system_language) contentStr = get_base_content_from_post(post_json_object,
system_language)
content = _textOnlyContent(contentStr) content = _textOnlyContent(contentStr)
if boxName != 'dm': if boxName != 'dm':
if isDM(post_json_object): if isDM(post_json_object):
@ -2423,8 +2424,8 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
post_json_object = post_json_object2 post_json_object = post_json_object2
if post_json_object: if post_json_object:
content = \ content = \
getBaseContentFromPost(post_json_object, get_base_content_from_post(post_json_object,
system_language) system_language)
messageStr, detectedLinks = \ messageStr, detectedLinks = \
speakableText(base_dir, content, translate) speakableText(base_dir, content, translate)
linkOpened = False linkOpened = False
@ -2481,8 +2482,8 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
if post_json_object['object'].get('summary'): if post_json_object['object'].get('summary'):
print(post_json_object['object']['summary']) print(post_json_object['object']['summary'])
contentStr = \ contentStr = \
getBaseContentFromPost(post_json_object, get_base_content_from_post(post_json_object,
system_language) system_language)
print(contentStr) print(contentStr)
print('') print('')
sayStr = 'Confirm delete, yes or no?' sayStr = 'Confirm delete, yes or no?'

View File

@ -28,7 +28,7 @@ from utils import hasObjectStringObject
from utils import getReplyIntervalHours from utils import getReplyIntervalHours
from utils import canReplyTo from utils import canReplyTo
from utils import getUserPaths from utils import getUserPaths
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import acctDir from utils import acctDir
from utils import removeDomainPort from utils import removeDomainPort
from utils import getPortFromDomain from utils import getPortFromDomain
@ -521,7 +521,7 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
return None return None
if post_json_object['object'].get('content'): if post_json_object['object'].get('content'):
contentStr = \ contentStr = \
getBaseContentFromPost(post_json_object, system_language) get_base_content_from_post(post_json_object, system_language)
if contentStr: if contentStr:
if isFiltered(base_dir, nickname, domain, contentStr): if isFiltered(base_dir, nickname, domain, contentStr):
if debug: if debug:
@ -2237,7 +2237,7 @@ def _validPostContent(base_dir: str, nickname: str, domain: str,
message_json['object']['content']): message_json['object']['content']):
return True return True
contentStr = getBaseContentFromPost(message_json, system_language) contentStr = get_base_content_from_post(message_json, system_language)
if dangerousMarkup(contentStr, allow_local_network_access): if dangerousMarkup(contentStr, allow_local_network_access):
if message_json['object'].get('id'): if message_json['object'].get('id'):
print('REJECT ARBITRARY HTML: ' + message_json['object']['id']) print('REJECT ARBITRARY HTML: ' + message_json['object']['id'])

View File

@ -15,7 +15,7 @@ import random
from random import randint from random import randint
from hashlib import sha1 from hashlib import sha1
from auth import createPassword from auth import createPassword
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import getFullDomain from utils import getFullDomain
from utils import getImageExtensions from utils import getImageExtensions
from utils import getVideoExtensions from utils import getVideoExtensions
@ -63,7 +63,7 @@ def _replaceSiloDomain(post_json_object: {},
return return
if not post_json_object['object'].get('content'): if not post_json_object['object'].get('content'):
return return
contentStr = getBaseContentFromPost(post_json_object, system_language) contentStr = get_base_content_from_post(post_json_object, system_language)
if siloDomain not in contentStr: if siloDomain not in contentStr:
return return
contentStr = contentStr.replace(siloDomain, replacementDomain) contentStr = contentStr.replace(siloDomain, replacementDomain)

View File

@ -25,7 +25,7 @@ from newswire import getDictFromNewswire
from posts import createNewsPost from posts import createNewsPost
from posts import archivePostsForPerson from posts import archivePostsForPerson
from content import validHashTag from content import validHashTag
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import removeHtml from utils import removeHtml
from utils import getFullDomain from utils import getFullDomain
from utils import loadJson from utils import loadJson
@ -322,7 +322,7 @@ def _hashtagAdd(base_dir: str, http_prefix: str, domain_full: str,
hashtagHtml = \ hashtagHtml = \
" <a href=\"" + hashtagUrl + "\" class=\"addedHashtag\" " + \ " <a href=\"" + hashtagUrl + "\" class=\"addedHashtag\" " + \
"rel=\"tag\">#<span>" + htId + "</span></a>" "rel=\"tag\">#<span>" + htId + "</span></a>"
content = getBaseContentFromPost(post_json_object, system_language) content = get_base_content_from_post(post_json_object, system_language)
if hashtagHtml in content: if hashtagHtml in content:
return return
@ -357,7 +357,7 @@ def _hashtagRemove(http_prefix: str, domain_full: str, post_json_object: {},
hashtagHtml = \ hashtagHtml = \
"<a href=\"" + hashtagUrl + "\" class=\"addedHashtag\" " + \ "<a href=\"" + hashtagUrl + "\" class=\"addedHashtag\" " + \
"rel=\"tag\">#<span>" + htId + "</span></a>" "rel=\"tag\">#<span>" + htId + "</span></a>"
content = getBaseContentFromPost(post_json_object, system_language) content = get_base_content_from_post(post_json_object, system_language)
if hashtagHtml in content: if hashtagHtml in content:
content = content.replace(hashtagHtml, '').replace(' ', ' ') content = content.replace(hashtagHtml, '').replace(' ', ' ')
post_json_object['object']['content'] = content post_json_object['object']['content'] = content
@ -399,7 +399,8 @@ def _newswireHashtagProcessing(session, base_dir: str, post_json_object: {},
# get the full text content of the post # get the full text content of the post
content = '' content = ''
if post_json_object['object'].get('content'): if post_json_object['object'].get('content'):
content += getBaseContentFromPost(post_json_object, system_language) content += get_base_content_from_post(post_json_object,
system_language)
if post_json_object['object'].get('summary'): if post_json_object['object'].get('summary'):
content += ' ' + post_json_object['object']['summary'] content += ' ' + post_json_object['object']['summary']
content = content.lower() content = content.lower()
@ -708,7 +709,7 @@ def _convertRSStoActivityPub(base_dir: str, http_prefix: str,
"\" class=\"addedHashtag\" " + \ "\" class=\"addedHashtag\" " + \
"rel=\"tag\">#<span>" + \ "rel=\"tag\">#<span>" + \
htId + "</span></a>" htId + "</span></a>"
content = getBaseContentFromPost(blog, system_language) content = get_base_content_from_post(blog, system_language)
if hashtagHtml not in content: if hashtagHtml not in content:
if content.endswith('</p>'): if content.endswith('</p>'):
content = \ content = \

View File

@ -20,7 +20,7 @@ from utils import validPostDate
from categories import setHashtagCategory from categories import setHashtagCategory
from utils import dangerousSVG from utils import dangerousSVG
from utils import getFavFilenameFromUrl from utils import getFavFilenameFromUrl
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import has_object_dict from utils import has_object_dict
from utils import firstParagraphFromString from utils import firstParagraphFromString
from utils import isPublicPost from utils import isPublicPost
@ -1062,8 +1062,8 @@ def _addAccountBlogsToNewswire(base_dir: str, nickname: str, domain: str,
if os.path.isfile(fullPostFilename + '.votes'): if os.path.isfile(fullPostFilename + '.votes'):
votes = loadJson(fullPostFilename + '.votes') votes = loadJson(fullPostFilename + '.votes')
content = \ content = \
getBaseContentFromPost(post_json_object, get_base_content_from_post(post_json_object,
system_language) system_language)
description = firstParagraphFromString(content) description = firstParagraphFromString(content)
description = removeHtml(description) description = removeHtml(description)
tagsFromPost = _getHashtagsFromPost(post_json_object) tagsFromPost = _getHashtagsFromPost(post_json_object)

View File

@ -17,7 +17,7 @@ from posts import savePostToBox
from posts import sendToFollowersThread from posts import sendToFollowersThread
from posts import sendToNamedAddressesThread from posts import sendToNamedAddressesThread
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import has_object_dict from utils import has_object_dict
from utils import getLocalNetworkAddresses from utils import getLocalNetworkAddresses
from utils import getFullDomain from utils import getFullDomain
@ -223,7 +223,7 @@ def postMessageToOutbox(session, translate: {},
# check that the outgoing post doesn't contain any markup # check that the outgoing post doesn't contain any markup
# which can be used to implement exploits # which can be used to implement exploits
if has_object_dict(message_json): if has_object_dict(message_json):
contentStr = getBaseContentFromPost(message_json, system_language) contentStr = get_base_content_from_post(message_json, system_language)
if contentStr: if contentStr:
if dangerousMarkup(contentStr, allow_local_network_access): if dangerousMarkup(contentStr, allow_local_network_access):
print('POST to outbox contains dangerous markup: ' + print('POST to outbox contains dangerous markup: ' +

View File

@ -38,7 +38,7 @@ from utils import hasObjectStringType
from utils import removeIdEnding from utils import removeIdEnding
from utils import replaceUsersWithAt from utils import replaceUsersWithAt
from utils import hasGroupType from utils import hasGroupType
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import removeDomainPort from utils import removeDomainPort
from utils import getPortFromDomain from utils import getPortFromDomain
from utils import has_object_dict from utils import has_object_dict
@ -591,7 +591,7 @@ def _getPosts(session, outboxUrl: str, maxPosts: int,
if item['type'] != 'Note' and item['type'] != 'Page': if item['type'] != 'Note' and item['type'] != 'Page':
thisItem = item['object'] thisItem = item['object']
content = getBaseContentFromPost(item, system_language) content = get_base_content_from_post(item, system_language)
content = content.replace('&apos;', "'") content = content.replace('&apos;', "'")
mentions = [] mentions = []
@ -784,7 +784,7 @@ def getPostDomains(session, outboxUrl: str, maxPosts: int,
break break
if not has_object_dict(item): if not has_object_dict(item):
continue continue
contentStr = getBaseContentFromPost(item, system_language) contentStr = get_base_content_from_post(item, system_language)
if contentStr: if contentStr:
_updateWordFrequency(contentStr, wordFrequency) _updateWordFrequency(contentStr, wordFrequency)
if item['object'].get('inReplyTo'): if item['object'].get('inReplyTo'):

View File

@ -106,7 +106,8 @@ def get_content_from_post(post_json_object: {}, system_language: str,
return content return content
def getBaseContentFromPost(post_json_object: {}, system_language: str) -> str: def get_base_content_from_post(post_json_object: {},
system_language: str) -> str:
"""Returns the content from the post in the given language """Returns the content from the post in the given language
""" """
this_post_json = post_json_object this_post_json = post_json_object

View File

@ -12,7 +12,7 @@ from datetime import datetime
from content import removeLongWords from content import removeLongWords
from content import limitRepeatedWords from content import limitRepeatedWords
from utils import getFavFilenameFromUrl from utils import getFavFilenameFromUrl
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import removeHtml from utils import removeHtml
from utils import locatePost from utils import locatePost
from utils import loadJson from utils import loadJson
@ -704,7 +704,8 @@ def htmlEditNewsPost(cssCache: {}, translate: {}, base_dir: str, path: str,
' <input type="text" name="newsPostTitle" value="' + \ ' <input type="text" name="newsPostTitle" value="' + \
newsPostTitle + '"><br>\n' newsPostTitle + '"><br>\n'
newsPostContent = getBaseContentFromPost(post_json_object, system_language) newsPostContent = get_base_content_from_post(post_json_object,
system_language)
editNewsPostForm += \ editNewsPostForm += \
' <textarea id="message" name="editedNewsPost" ' + \ ' <textarea id="message" name="editedNewsPost" ' + \
'style="height:600px" spellcheck="true">' + \ 'style="height:600px" spellcheck="true">' + \

View File

@ -26,7 +26,7 @@ from posts import populateRepliesJson
from utils import removeHashFromPostId from utils import removeHashFromPostId
from utils import removeHtml from utils import removeHtml
from utils import get_actor_languages_list from utils import get_actor_languages_list
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import get_content_from_post from utils import get_content_from_post
from utils import has_object_dict from utils import has_object_dict
from utils import updateAnnounceCollection from utils import updateAnnounceCollection
@ -409,7 +409,7 @@ def _getReplyIconHtml(base_dir: str, nickname: str, domain: str,
if isinstance(post_json_object['object']['attributedTo'], str): if isinstance(post_json_object['object']['attributedTo'], str):
replyToLink += \ replyToLink += \
'?mention=' + post_json_object['object']['attributedTo'] '?mention=' + post_json_object['object']['attributedTo']
content = getBaseContentFromPost(post_json_object, system_language) content = get_base_content_from_post(post_json_object, system_language)
if content: if content:
mentionedActors = getMentionsFromHtml(content) mentionedActors = getMentionsFromHtml(content)
if mentionedActors: if mentionedActors:

View File

@ -11,7 +11,7 @@ import os
from shutil import copyfile from shutil import copyfile
import urllib.parse import urllib.parse
from datetime import datetime from datetime import datetime
from utils import getBaseContentFromPost from utils import get_base_content_from_post
from utils import isAccountDir from utils import isAccountDir
from utils import getConfigParam from utils import getConfigParam
from utils import getFullDomain from utils import getFullDomain
@ -987,7 +987,8 @@ def rssHashtagSearch(nickname: str, domain: str, port: int,
post_json_object['object']['summary'] + \ post_json_object['object']['summary'] + \
'</title>' '</title>'
description = \ description = \
getBaseContentFromPost(post_json_object, system_language) get_base_content_from_post(post_json_object,
system_language)
description = firstParagraphFromString(description) description = firstParagraphFromString(description)
hashtagFeed += \ hashtagFeed += \
' <description>' + description + '</description>' ' <description>' + description + '</description>'