Snake case

merge-requests/30/head
Bob Mottram 2021-12-26 19:15:36 +00:00
parent fa67322c4e
commit 413bd33613
9 changed files with 38 additions and 38 deletions

View File

@ -20,8 +20,8 @@ from utils import save_json
from utils import fileLastModified from utils import fileLastModified
from utils import getLinkPrefixes from utils import getLinkPrefixes
from utils import dangerousMarkup from utils import dangerousMarkup
from utils import isPGPEncrypted from utils import is_pgp_encrypted
from utils import containsPGPPublicKey from utils import contains_pgp_public_key
from utils import acct_dir from utils import acct_dir
from utils import is_float from utils import is_float
from utils import get_currencies from utils import get_currencies
@ -76,7 +76,7 @@ def _removeQuotesWithinQuotes(content: str) -> str:
def htmlReplaceEmailQuote(content: str) -> str: def htmlReplaceEmailQuote(content: str) -> str:
"""Replaces an email style quote "> Some quote" with html blockquote """Replaces an email style quote "> Some quote" with html blockquote
""" """
if isPGPEncrypted(content) or containsPGPPublicKey(content): if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content return content
# replace quote paragraph # replace quote paragraph
if '<p>&quot;' in content: if '<p>&quot;' in content:
@ -119,7 +119,7 @@ def htmlReplaceQuoteMarks(content: str) -> str:
"""Replaces quotes with html formatting """Replaces quotes with html formatting
"hello" becomes <q>hello</q> "hello" becomes <q>hello</q>
""" """
if isPGPEncrypted(content) or containsPGPPublicKey(content): if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content return content
if '"' not in content: if '"' not in content:
if '&quot;' not in content: if '&quot;' not in content:
@ -218,7 +218,7 @@ def switchWords(base_dir: str, nickname: str, domain: str, content: str,
rules: [] = []) -> str: rules: [] = []) -> str:
"""Performs word replacements. eg. Trump -> The Orange Menace """Performs word replacements. eg. Trump -> The Orange Menace
""" """
if isPGPEncrypted(content) or containsPGPPublicKey(content): if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content return content
if not rules: if not rules:
@ -671,7 +671,7 @@ def _addMention(wordStr: str, http_prefix: str, following: str, petnames: str,
def replaceContentDuplicates(content: str) -> str: def replaceContentDuplicates(content: str) -> str:
"""Replaces invalid duplicates within content """Replaces invalid duplicates within content
""" """
if isPGPEncrypted(content) or containsPGPPublicKey(content): if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content return content
while '<<' in content: while '<<' in content:
content = content.replace('<<', '<') content = content.replace('<<', '<')
@ -684,7 +684,7 @@ def replaceContentDuplicates(content: str) -> str:
def removeTextFormatting(content: str) -> str: def removeTextFormatting(content: str) -> str:
"""Removes markup for bold, italics, etc """Removes markup for bold, italics, etc
""" """
if isPGPEncrypted(content) or containsPGPPublicKey(content): if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content return content
if '<' not in content: if '<' not in content:
return content return content
@ -703,7 +703,7 @@ def removeLongWords(content: str, maxWordLength: int,
"""Breaks up long words so that on mobile screens this doesn't """Breaks up long words so that on mobile screens this doesn't
disrupt the layout disrupt the layout
""" """
if isPGPEncrypted(content) or containsPGPPublicKey(content): if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content return content
content = replaceContentDuplicates(content) content = replaceContentDuplicates(content)
if ' ' not in content: if ' ' not in content:

View File

@ -24,7 +24,7 @@ from utils import load_translations_from_file
from utils import removeHtml from utils import removeHtml
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import isPGPEncrypted from utils import is_pgp_encrypted
from utils import local_actor_url from utils import local_actor_url
from session import createSession from session import createSession
from speaker import speakableText from speaker import speakableText
@ -755,11 +755,11 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
content = _textOnlyContent(content) content = _textOnlyContent(content)
content += _getImageDescription(post_json_object) content += _getImageDescription(post_json_object)
if isPGPEncrypted(content): if is_pgp_encrypted(content):
sayStr = 'Encrypted message. Please enter your passphrase.' sayStr = 'Encrypted message. Please enter your passphrase.'
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak) _sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
content = pgpDecrypt(domain, content, actor, signing_priv_key_pem) content = pgpDecrypt(domain, content, actor, signing_priv_key_pem)
if isPGPEncrypted(content): if is_pgp_encrypted(content):
sayStr = 'Message could not be decrypted' sayStr = 'Message could not be decrypted'
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak) _sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
return {} return {}
@ -1079,14 +1079,14 @@ def _desktopShowBox(indent: str,
if isDM(post_json_object): if isDM(post_json_object):
content = '📧' + content content = '📧' + content
if not contentWarning: if not contentWarning:
if isPGPEncrypted(content): if is_pgp_encrypted(content):
content = '🔒' + content content = '🔒' + content
elif '://' in content: elif '://' in content:
content = '🔗' + content content = '🔗' + content
content = _padToWidth(content, contentWidth) content = _padToWidth(content, contentWidth)
else: else:
# display content warning # display content warning
if isPGPEncrypted(content): if is_pgp_encrypted(content):
content = '🔒' + contentWarning content = '🔒' + contentWarning
else: else:
if '://' in content: if '://' in content:

View File

@ -20,7 +20,7 @@ from reaction import validEmojiContent
from utils import domainPermitted from utils import domainPermitted
from utils import is_group_account from utils import is_group_account
from utils import isSystemAccount from utils import isSystemAccount
from utils import invalidCiphertext from utils import invalid_ciphertext
from utils import removeHtml from utils import removeHtml
from utils import fileLastModified from utils import fileLastModified
from utils import has_object_string from utils import has_object_string
@ -2290,7 +2290,7 @@ def _validPostContent(base_dir: str, nickname: str, domain: str,
print('REJECT: reply to post which does not ' + print('REJECT: reply to post which does not ' +
'allow comments: ' + originalPostId) 'allow comments: ' + originalPostId)
return False return False
if invalidCiphertext(message_json['object']['content']): if invalid_ciphertext(message_json['object']['content']):
print('REJECT: malformed ciphertext in content') print('REJECT: malformed ciphertext in content')
return False return False
if debug: if debug:

16
pgp.py
View File

@ -11,8 +11,8 @@ import os
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from person import getActorJson from person import getActorJson
from utils import containsPGPPublicKey from utils import contains_pgp_public_key
from utils import isPGPEncrypted from utils import is_pgp_encrypted
from utils import get_full_domain from utils import get_full_domain
from utils import getStatusNumber from utils import getStatusNumber
from utils import local_actor_url from utils import local_actor_url
@ -63,7 +63,7 @@ def getPGPpubKey(actor_json: {}) -> str:
continue continue
if property_value['type'] != 'PropertyValue': if property_value['type'] != 'PropertyValue':
continue continue
if not containsPGPPublicKey(property_value['value']): if not contains_pgp_public_key(property_value['value']):
continue continue
return property_value['value'] return property_value['value']
return '' return ''
@ -150,7 +150,7 @@ def setPGPpubKey(actor_json: {}, PGPpubKey: str) -> None:
if not PGPpubKey: if not PGPpubKey:
removeKey = True removeKey = True
else: else:
if not containsPGPPublicKey(PGPpubKey): if not contains_pgp_public_key(PGPpubKey):
removeKey = True removeKey = True
if '<' in PGPpubKey: if '<' in PGPpubKey:
removeKey = True removeKey = True
@ -329,7 +329,7 @@ def _pgpEncrypt(content: str, recipientPubKey: str) -> str:
if not encryptResult: if not encryptResult:
return None return None
encryptResult = encryptResult.decode('utf-8') encryptResult = encryptResult.decode('utf-8')
if not isPGPEncrypted(encryptResult): if not is_pgp_encrypted(encryptResult):
return None return None
return encryptResult return encryptResult
@ -358,7 +358,7 @@ def _getPGPPublicKeyFromActor(signing_priv_key_pem: str,
continue continue
if not isinstance(tag['value'], str): if not isinstance(tag['value'], str):
continue continue
if containsPGPPublicKey(tag['value']): if contains_pgp_public_key(tag['value']):
return tag['value'] return tag['value']
return None return None
@ -393,11 +393,11 @@ def pgpDecrypt(domain: str, content: str, fromHandle: str,
""" Encrypt using your default pgp key to the given recipient """ Encrypt using your default pgp key to the given recipient
fromHandle can be a handle or actor url fromHandle can be a handle or actor url
""" """
if not isPGPEncrypted(content): if not is_pgp_encrypted(content):
return content return content
# if the public key is also included within the message then import it # if the public key is also included within the message then import it
if containsPGPPublicKey(content): if contains_pgp_public_key(content):
pubKey = extractPGPPublicKey(content) pubKey = extractPGPPublicKey(content)
else: else:
pubKey = \ pubKey = \

View File

@ -33,7 +33,7 @@ from httpsig import createSignedHeader
from siteactive import siteIsActive from siteactive import siteIsActive
from languages import understoodPostLanguage from languages import understoodPostLanguage
from utils import get_user_paths from utils import get_user_paths
from utils import invalidCiphertext from utils import invalid_ciphertext
from utils import has_object_stringType from utils import has_object_stringType
from utils import removeIdEnding from utils import removeIdEnding
from utils import replace_users_with_at from utils import replace_users_with_at
@ -4683,7 +4683,7 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
recentPostsCache) recentPostsCache)
return None return None
if invalidCiphertext(contentStr): if invalid_ciphertext(contentStr):
_rejectAnnounce(announceFilename, _rejectAnnounce(announceFilename,
base_dir, nickname, domain, postId, base_dir, nickname, domain, postId,
recentPostsCache) recentPostsCache)

View File

@ -22,7 +22,7 @@ from utils import getDisplayName
from utils import removeHtml from utils import removeHtml
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
from utils import isPGPEncrypted from utils import is_pgp_encrypted
from utils import has_object_dict from utils import has_object_dict
from utils import acct_dir from utils import acct_dir
from utils import local_actor_url from utils import local_actor_url
@ -382,7 +382,7 @@ def speakableText(base_dir: str, content: str, translate: {}) -> (str, []):
which includes changes for prononciation which includes changes for prononciation
""" """
content = str(content) content = str(content)
if isPGPEncrypted(content): if is_pgp_encrypted(content):
return content, [] return content, []
# replace some emoji before removing html # replace some emoji before removing html
@ -422,7 +422,7 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
content = urllib.parse.unquote_plus(post_json_object['object']['content']) content = urllib.parse.unquote_plus(post_json_object['object']['content'])
content = html.unescape(content) content = html.unescape(content)
content = content.replace('<p>', '').replace('</p>', ' ') content = content.replace('<p>', '').replace('</p>', ' ')
if not isPGPEncrypted(content): if not is_pgp_encrypted(content):
# replace some emoji before removing html # replace some emoji before removing html
if ' <3' in content: if ' <3' in content:
content = content.replace(' <3', ' ' + translate['heart']) content = content.replace(' <3', ' ' + translate['heart'])

View File

@ -87,7 +87,7 @@ from utils import dangerousMarkup
from utils import acct_dir from utils import acct_dir
from pgp import extractPGPPublicKey from pgp import extractPGPPublicKey
from pgp import pgpPublicKeyUpload from pgp import pgpPublicKeyUpload
from utils import containsPGPPublicKey from utils import contains_pgp_public_key
from follow import followerOfPerson from follow import followerOfPerson
from follow import unfollowAccount from follow import unfollowAccount
from follow import unfollowerOfAccount from follow import unfollowerOfAccount
@ -5053,8 +5053,8 @@ def _testExtractPGPPublicKey():
'=gv5G\n' + \ '=gv5G\n' + \
'-----END PGP PUBLIC KEY BLOCK-----' '-----END PGP PUBLIC KEY BLOCK-----'
testStr = "Some introduction\n\n" + pubKey + "\n\nSome message." testStr = "Some introduction\n\n" + pubKey + "\n\nSome message."
assert containsPGPPublicKey(testStr) assert contains_pgp_public_key(testStr)
assert not containsPGPPublicKey('String without a pgp key') assert not contains_pgp_public_key('String without a pgp key')
result = extractPGPPublicKey(testStr) result = extractPGPPublicKey(testStr)
assert result assert result
assert result == pubKey assert result == pubKey

View File

@ -2646,7 +2646,7 @@ def isReply(post_json_object: {}, actor: str) -> bool:
return False return False
def containsPGPPublicKey(content: str) -> bool: def contains_pgp_public_key(content: str) -> bool:
"""Returns true if the given content contains a PGP public key """Returns true if the given content contains a PGP public key
""" """
if '--BEGIN PGP PUBLIC KEY BLOCK--' in content: if '--BEGIN PGP PUBLIC KEY BLOCK--' in content:
@ -2655,7 +2655,7 @@ def containsPGPPublicKey(content: str) -> bool:
return False return False
def isPGPEncrypted(content: str) -> bool: def is_pgp_encrypted(content: str) -> bool:
"""Returns true if the given content is PGP encrypted """Returns true if the given content is PGP encrypted
""" """
if '--BEGIN PGP MESSAGE--' in content: if '--BEGIN PGP MESSAGE--' in content:
@ -2664,12 +2664,12 @@ def isPGPEncrypted(content: str) -> bool:
return False return False
def invalidCiphertext(content: str) -> bool: def invalid_ciphertext(content: str) -> bool:
"""Returns true if the given content contains an invalid key """Returns true if the given content contains an invalid key
""" """
if '----BEGIN ' in content or '----END ' in content: if '----BEGIN ' in content or '----END ' in content:
if not containsPGPPublicKey(content) and \ if not contains_pgp_public_key(content) and \
not isPGPEncrypted(content): not is_pgp_encrypted(content):
return True return True
return False return False

View File

@ -30,7 +30,7 @@ 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
from utils import isPGPEncrypted from utils import is_pgp_encrypted
from utils import isDM from utils import isDM
from utils import rejectPostId from utils import rejectPostId
from utils import isRecentPost from utils import isRecentPost
@ -1871,7 +1871,7 @@ def individualPostAsHtml(signing_priv_key_pem: str,
_logPostTiming(enableTimingLog, postStartTime, '16') _logPostTiming(enableTimingLog, postStartTime, '16')
if not isPGPEncrypted(contentStr): if not is_pgp_encrypted(contentStr):
if not isPatch: if not isPatch:
objectContent = \ objectContent = \
removeLongWords(contentStr, 40, []) removeLongWords(contentStr, 40, [])