diff --git a/content.py b/content.py index c0eece9d3..7bb8b5c5a 100644 --- a/content.py +++ b/content.py @@ -20,8 +20,8 @@ from utils import save_json from utils import fileLastModified from utils import getLinkPrefixes from utils import dangerousMarkup -from utils import isPGPEncrypted -from utils import containsPGPPublicKey +from utils import is_pgp_encrypted +from utils import contains_pgp_public_key from utils import acct_dir from utils import is_float from utils import get_currencies @@ -76,7 +76,7 @@ def _removeQuotesWithinQuotes(content: str) -> str: def htmlReplaceEmailQuote(content: str) -> str: """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 # replace quote paragraph if '
"' in content:
@@ -119,7 +119,7 @@ def htmlReplaceQuoteMarks(content: str) -> str:
"""Replaces quotes with html formatting
"hello" becomes hello
"""
- if isPGPEncrypted(content) or containsPGPPublicKey(content):
+ if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content
if '"' not in content:
if '"' not in content:
@@ -218,7 +218,7 @@ def switchWords(base_dir: str, nickname: str, domain: str, content: str,
rules: [] = []) -> str:
"""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
if not rules:
@@ -671,7 +671,7 @@ def _addMention(wordStr: str, http_prefix: str, following: str, petnames: str,
def replaceContentDuplicates(content: str) -> str:
"""Replaces invalid duplicates within content
"""
- if isPGPEncrypted(content) or containsPGPPublicKey(content):
+ if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content
while '<<' in content:
content = content.replace('<<', '<')
@@ -684,7 +684,7 @@ def replaceContentDuplicates(content: str) -> str:
def removeTextFormatting(content: str) -> str:
"""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
if '<' not in 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
disrupt the layout
"""
- if isPGPEncrypted(content) or containsPGPPublicKey(content):
+ if is_pgp_encrypted(content) or contains_pgp_public_key(content):
return content
content = replaceContentDuplicates(content)
if ' ' not in content:
diff --git a/desktop_client.py b/desktop_client.py
index 04c7620db..57c6d143f 100644
--- a/desktop_client.py
+++ b/desktop_client.py
@@ -24,7 +24,7 @@ from utils import load_translations_from_file
from utils import removeHtml
from utils import getNicknameFromActor
from utils import getDomainFromActor
-from utils import isPGPEncrypted
+from utils import is_pgp_encrypted
from utils import local_actor_url
from session import createSession
from speaker import speakableText
@@ -755,11 +755,11 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
content = _textOnlyContent(content)
content += _getImageDescription(post_json_object)
- if isPGPEncrypted(content):
+ if is_pgp_encrypted(content):
sayStr = 'Encrypted message. Please enter your passphrase.'
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
content = pgpDecrypt(domain, content, actor, signing_priv_key_pem)
- if isPGPEncrypted(content):
+ if is_pgp_encrypted(content):
sayStr = 'Message could not be decrypted'
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
return {}
@@ -1079,14 +1079,14 @@ def _desktopShowBox(indent: str,
if isDM(post_json_object):
content = '📧' + content
if not contentWarning:
- if isPGPEncrypted(content):
+ if is_pgp_encrypted(content):
content = '🔒' + content
elif '://' in content:
content = '🔗' + content
content = _padToWidth(content, contentWidth)
else:
# display content warning
- if isPGPEncrypted(content):
+ if is_pgp_encrypted(content):
content = '🔒' + contentWarning
else:
if '://' in content:
diff --git a/inbox.py b/inbox.py
index bf431ccb6..51ec777b8 100644
--- a/inbox.py
+++ b/inbox.py
@@ -20,7 +20,7 @@ from reaction import validEmojiContent
from utils import domainPermitted
from utils import is_group_account
from utils import isSystemAccount
-from utils import invalidCiphertext
+from utils import invalid_ciphertext
from utils import removeHtml
from utils import fileLastModified
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 ' +
'allow comments: ' + originalPostId)
return False
- if invalidCiphertext(message_json['object']['content']):
+ if invalid_ciphertext(message_json['object']['content']):
print('REJECT: malformed ciphertext in content')
return False
if debug:
diff --git a/pgp.py b/pgp.py
index bb26bbd61..4c3727b73 100644
--- a/pgp.py
+++ b/pgp.py
@@ -11,8 +11,8 @@ import os
import subprocess
from pathlib import Path
from person import getActorJson
-from utils import containsPGPPublicKey
-from utils import isPGPEncrypted
+from utils import contains_pgp_public_key
+from utils import is_pgp_encrypted
from utils import get_full_domain
from utils import getStatusNumber
from utils import local_actor_url
@@ -63,7 +63,7 @@ def getPGPpubKey(actor_json: {}) -> str:
continue
if property_value['type'] != 'PropertyValue':
continue
- if not containsPGPPublicKey(property_value['value']):
+ if not contains_pgp_public_key(property_value['value']):
continue
return property_value['value']
return ''
@@ -150,7 +150,7 @@ def setPGPpubKey(actor_json: {}, PGPpubKey: str) -> None:
if not PGPpubKey:
removeKey = True
else:
- if not containsPGPPublicKey(PGPpubKey):
+ if not contains_pgp_public_key(PGPpubKey):
removeKey = True
if '<' in PGPpubKey:
removeKey = True
@@ -329,7 +329,7 @@ def _pgpEncrypt(content: str, recipientPubKey: str) -> str:
if not encryptResult:
return None
encryptResult = encryptResult.decode('utf-8')
- if not isPGPEncrypted(encryptResult):
+ if not is_pgp_encrypted(encryptResult):
return None
return encryptResult
@@ -358,7 +358,7 @@ def _getPGPPublicKeyFromActor(signing_priv_key_pem: str,
continue
if not isinstance(tag['value'], str):
continue
- if containsPGPPublicKey(tag['value']):
+ if contains_pgp_public_key(tag['value']):
return tag['value']
return None
@@ -393,11 +393,11 @@ def pgpDecrypt(domain: str, content: str, fromHandle: str,
""" Encrypt using your default pgp key to the given recipient
fromHandle can be a handle or actor url
"""
- if not isPGPEncrypted(content):
+ if not is_pgp_encrypted(content):
return content
# 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)
else:
pubKey = \
diff --git a/posts.py b/posts.py
index cdcc68a51..bedac4a08 100644
--- a/posts.py
+++ b/posts.py
@@ -33,7 +33,7 @@ from httpsig import createSignedHeader
from siteactive import siteIsActive
from languages import understoodPostLanguage
from utils import get_user_paths
-from utils import invalidCiphertext
+from utils import invalid_ciphertext
from utils import has_object_stringType
from utils import removeIdEnding
from utils import replace_users_with_at
@@ -4683,7 +4683,7 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
recentPostsCache)
return None
- if invalidCiphertext(contentStr):
+ if invalid_ciphertext(contentStr):
_rejectAnnounce(announceFilename,
base_dir, nickname, domain, postId,
recentPostsCache)
diff --git a/speaker.py b/speaker.py
index 9722b26c5..f715e7373 100644
--- a/speaker.py
+++ b/speaker.py
@@ -22,7 +22,7 @@ from utils import getDisplayName
from utils import removeHtml
from utils import load_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 acct_dir
from utils import local_actor_url
@@ -382,7 +382,7 @@ def speakableText(base_dir: str, content: str, translate: {}) -> (str, []):
which includes changes for prononciation
"""
content = str(content)
- if isPGPEncrypted(content):
+ if is_pgp_encrypted(content):
return content, []
# 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 = html.unescape(content)
content = content.replace('
', '').replace('
', ' ') - if not isPGPEncrypted(content): + if not is_pgp_encrypted(content): # replace some emoji before removing html if ' <3' in content: content = content.replace(' <3', ' ' + translate['heart']) diff --git a/tests.py b/tests.py index 850a527a6..665700f1f 100644 --- a/tests.py +++ b/tests.py @@ -87,7 +87,7 @@ from utils import dangerousMarkup from utils import acct_dir from pgp import extractPGPPublicKey from pgp import pgpPublicKeyUpload -from utils import containsPGPPublicKey +from utils import contains_pgp_public_key from follow import followerOfPerson from follow import unfollowAccount from follow import unfollowerOfAccount @@ -5053,8 +5053,8 @@ def _testExtractPGPPublicKey(): '=gv5G\n' + \ '-----END PGP PUBLIC KEY BLOCK-----' testStr = "Some introduction\n\n" + pubKey + "\n\nSome message." - assert containsPGPPublicKey(testStr) - assert not containsPGPPublicKey('String without a pgp key') + assert contains_pgp_public_key(testStr) + assert not contains_pgp_public_key('String without a pgp key') result = extractPGPPublicKey(testStr) assert result assert result == pubKey diff --git a/utils.py b/utils.py index bf8151b2c..548dbf354 100644 --- a/utils.py +++ b/utils.py @@ -2646,7 +2646,7 @@ def isReply(post_json_object: {}, actor: str) -> bool: 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 """ if '--BEGIN PGP PUBLIC KEY BLOCK--' in content: @@ -2655,7 +2655,7 @@ def containsPGPPublicKey(content: str) -> bool: return False -def isPGPEncrypted(content: str) -> bool: +def is_pgp_encrypted(content: str) -> bool: """Returns true if the given content is PGP encrypted """ if '--BEGIN PGP MESSAGE--' in content: @@ -2664,12 +2664,12 @@ def isPGPEncrypted(content: str) -> bool: return False -def invalidCiphertext(content: str) -> bool: +def invalid_ciphertext(content: str) -> bool: """Returns true if the given content contains an invalid key """ if '----BEGIN ' in content or '----END ' in content: - if not containsPGPPublicKey(content) and \ - not isPGPEncrypted(content): + if not contains_pgp_public_key(content) and \ + not is_pgp_encrypted(content): return True return False diff --git a/webapp_post.py b/webapp_post.py index fc998d4f2..35d788e06 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -30,7 +30,7 @@ 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 -from utils import isPGPEncrypted +from utils import is_pgp_encrypted from utils import isDM from utils import rejectPostId from utils import isRecentPost @@ -1871,7 +1871,7 @@ def individualPostAsHtml(signing_priv_key_pem: str, _logPostTiming(enableTimingLog, postStartTime, '16') - if not isPGPEncrypted(contentStr): + if not is_pgp_encrypted(contentStr): if not isPatch: objectContent = \ removeLongWords(contentStr, 40, [])