Snake case

main
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 utils import local_actor_url
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 isAccountDir
from utils import removeHtml
@ -368,7 +368,8 @@ def _htmlBlogPostRSS2(authorized: bool,
titleStr = post_json_object['object']['summary']
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
content = \
getBaseContentFromPost(post_json_object, system_language)
get_base_content_from_post(post_json_object,
system_language)
description = firstParagraphFromString(content)
rssStr = ' <item>'
rssStr += ' <title>' + titleStr + '</title>'
@ -402,7 +403,8 @@ def _htmlBlogPostRSS3(authorized: bool,
titleStr = post_json_object['object']['summary']
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
content = \
getBaseContentFromPost(post_json_object, system_language)
get_base_content_from_post(post_json_object,
system_language)
description = firstParagraphFromString(content)
rssStr = 'title: ' + titleStr + '\n'
rssStr += 'link: ' + messageLink + '\n'
@ -427,7 +429,7 @@ def _getSnippetFromBlogContent(post_json_object: {},
system_language: str) -> str:
"""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:
content = content.split('<p>', 1)[1]
if '</p>' in content:
@ -896,7 +898,7 @@ def htmlEditBlog(media_instance: bool, translate: {},
editBlogForm += ' <br>'
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')
editBlogForm += \

View File

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

View File

@ -16,7 +16,7 @@ import webbrowser
import urllib.parse
from pathlib import Path
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 getFullDomain
from utils import isDM
@ -720,7 +720,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
post_json_object2['object'].get('content'):
attributedTo = post_json_object2['object']['attributedTo']
content = \
getBaseContentFromPost(post_json_object2,
get_base_content_from_post(post_json_object2,
system_language)
if isinstance(attributedTo, str) and content:
actor = attributedTo
@ -746,7 +746,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
attributedTo = post_json_object['object']['attributedTo']
if not attributedTo:
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 \
not isinstance(content, str):
return {}
@ -1072,7 +1072,8 @@ def _desktopShowBox(indent: str,
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)
if boxName != 'dm':
if isDM(post_json_object):
@ -2423,7 +2424,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
post_json_object = post_json_object2
if post_json_object:
content = \
getBaseContentFromPost(post_json_object,
get_base_content_from_post(post_json_object,
system_language)
messageStr, detectedLinks = \
speakableText(base_dir, content, translate)
@ -2481,7 +2482,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
if post_json_object['object'].get('summary'):
print(post_json_object['object']['summary'])
contentStr = \
getBaseContentFromPost(post_json_object,
get_base_content_from_post(post_json_object,
system_language)
print(contentStr)
print('')

View File

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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ from utils import validPostDate
from categories import setHashtagCategory
from utils import dangerousSVG
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 firstParagraphFromString
from utils import isPublicPost
@ -1062,7 +1062,7 @@ def _addAccountBlogsToNewswire(base_dir: str, nickname: str, domain: str,
if os.path.isfile(fullPostFilename + '.votes'):
votes = loadJson(fullPostFilename + '.votes')
content = \
getBaseContentFromPost(post_json_object,
get_base_content_from_post(post_json_object,
system_language)
description = firstParagraphFromString(content)
description = removeHtml(description)

View File

@ -17,7 +17,7 @@ from posts import savePostToBox
from posts import sendToFollowersThread
from posts import sendToNamedAddressesThread
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 getLocalNetworkAddresses
from utils import getFullDomain
@ -223,7 +223,7 @@ def postMessageToOutbox(session, translate: {},
# check that the outgoing post doesn't contain any markup
# which can be used to implement exploits
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 dangerousMarkup(contentStr, allow_local_network_access):
print('POST to outbox contains dangerous markup: ' +

View File

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

View File

@ -106,7 +106,8 @@ def get_content_from_post(post_json_object: {}, system_language: str,
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
"""
this_post_json = post_json_object

View File

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

View File

@ -26,7 +26,7 @@ from posts import populateRepliesJson
from utils import removeHashFromPostId
from utils import removeHtml
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 has_object_dict
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):
replyToLink += \
'?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:
mentionedActors = getMentionsFromHtml(content)
if mentionedActors:

View File

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