mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
3d9559bf27
commit
c99a29df89
|
@ -33,10 +33,10 @@ def setAvailability(base_dir: str, nickname: str, domain: str,
|
|||
actorFilename = acctDir(base_dir, nickname, domain) + '.json'
|
||||
if not os.path.isfile(actorFilename):
|
||||
return False
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
actorJson['availability'] = status
|
||||
saveJson(actorJson, actorFilename)
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
actor_json['availability'] = status
|
||||
saveJson(actor_json, actorFilename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -46,11 +46,11 @@ def getAvailability(base_dir: str, nickname: str, domain: str) -> str:
|
|||
actorFilename = acctDir(base_dir, nickname, domain) + '.json'
|
||||
if not os.path.isfile(actorFilename):
|
||||
return False
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if not actorJson.get('availability'):
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if not actor_json.get('availability'):
|
||||
return None
|
||||
return actorJson['availability']
|
||||
return actor_json['availability']
|
||||
return None
|
||||
|
||||
|
||||
|
|
10
blog.py
10
blog.py
|
@ -266,11 +266,11 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
blogStr += '<br><center>' + attachmentStr + '</center>'
|
||||
|
||||
personUrl = local_actor_url(http_prefix, nickname, domain_full)
|
||||
actorJson = \
|
||||
actor_json = \
|
||||
getPersonFromCache(base_dir, personUrl, person_cache, False)
|
||||
languagesUnderstood = []
|
||||
if actorJson:
|
||||
languagesUnderstood = get_actor_languages_list(actorJson)
|
||||
if actor_json:
|
||||
languagesUnderstood = get_actor_languages_list(actor_json)
|
||||
jsonContent = getContentFromPost(post_json_object, system_language,
|
||||
languagesUnderstood)
|
||||
if jsonContent:
|
||||
|
@ -945,7 +945,7 @@ def pathContainsBlogLink(base_dir: str,
|
|||
return locatePost(base_dir, nickname, domain, messageId), nickname
|
||||
|
||||
|
||||
def getBlogAddress(actorJson: {}) -> str:
|
||||
def getBlogAddress(actor_json: {}) -> str:
|
||||
"""Returns blog address for the given actor
|
||||
"""
|
||||
return getActorPropertyUrl(actorJson, 'Blog')
|
||||
return getActorPropertyUrl(actor_json, 'Blog')
|
||||
|
|
20
briar.py
20
briar.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getBriarAddress(actorJson: {}) -> str:
|
||||
def getBriarAddress(actor_json: {}) -> str:
|
||||
"""Returns briar address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('briar'):
|
||||
|
@ -43,7 +43,7 @@ def getBriarAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setBriarAddress(actorJson: {}, briarAddress: str) -> None:
|
||||
def setBriarAddress(actor_json: {}, briarAddress: str) -> None:
|
||||
"""Sets an briar address for the given actor
|
||||
"""
|
||||
notBriarAddress = False
|
||||
|
@ -65,12 +65,12 @@ def setBriarAddress(actorJson: {}, briarAddress: str) -> None:
|
|||
if '<' in briarAddress:
|
||||
notBriarAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -80,11 +80,11 @@ def setBriarAddress(actorJson: {}, briarAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notBriarAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -101,4 +101,4 @@ def setBriarAddress(actorJson: {}, briarAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": briarAddress
|
||||
}
|
||||
actorJson['attachment'].append(newBriarAddress)
|
||||
actor_json['attachment'].append(newBriarAddress)
|
||||
|
|
20
cwtch.py
20
cwtch.py
|
@ -10,12 +10,12 @@ __module_group__ = "Profile Metadata"
|
|||
import re
|
||||
|
||||
|
||||
def getCwtchAddress(actorJson: {}) -> str:
|
||||
def getCwtchAddress(actor_json: {}) -> str:
|
||||
"""Returns cwtch address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('cwtch'):
|
||||
|
@ -41,7 +41,7 @@ def getCwtchAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setCwtchAddress(actorJson: {}, cwtchAddress: str) -> None:
|
||||
def setCwtchAddress(actor_json: {}, cwtchAddress: str) -> None:
|
||||
"""Sets an cwtch address for the given actor
|
||||
"""
|
||||
notCwtchAddress = False
|
||||
|
@ -53,12 +53,12 @@ def setCwtchAddress(actorJson: {}, cwtchAddress: str) -> None:
|
|||
if not re.match("^[a-z0-9]*$", cwtchAddress):
|
||||
notCwtchAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -68,11 +68,11 @@ def setCwtchAddress(actorJson: {}, cwtchAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notCwtchAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -89,4 +89,4 @@ def setCwtchAddress(actorJson: {}, cwtchAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": cwtchAddress
|
||||
}
|
||||
actorJson['attachment'].append(newCwtchAddress)
|
||||
actor_json['attachment'].append(newCwtchAddress)
|
||||
|
|
335
daemon.py
335
daemon.py
|
@ -4885,51 +4885,51 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
actorFilename = \
|
||||
acctDir(base_dir, nickname, domain) + '.json'
|
||||
if os.path.isfile(actorFilename):
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if not actorJson.get('discoverable'):
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if not actor_json.get('discoverable'):
|
||||
# discoverable in profile directory
|
||||
# which isn't implemented in Epicyon
|
||||
actorJson['discoverable'] = True
|
||||
actor_json['discoverable'] = True
|
||||
actorChanged = True
|
||||
if actorJson.get('capabilityAcquisitionEndpoint'):
|
||||
del actorJson['capabilityAcquisitionEndpoint']
|
||||
if actor_json.get('capabilityAcquisitionEndpoint'):
|
||||
del actor_json['capabilityAcquisitionEndpoint']
|
||||
actorChanged = True
|
||||
# update the avatar/image url file extension
|
||||
uploads = profileMediaTypesUploaded.items()
|
||||
for mType, lastPart in uploads:
|
||||
repStr = '/' + lastPart
|
||||
if mType == 'avatar':
|
||||
actorUrl = actorJson['icon']['url']
|
||||
actorUrl = actor_json['icon']['url']
|
||||
lastPartOfUrl = actorUrl.split('/')[-1]
|
||||
srchStr = '/' + lastPartOfUrl
|
||||
actorUrl = actorUrl.replace(srchStr, repStr)
|
||||
actorJson['icon']['url'] = actorUrl
|
||||
actor_json['icon']['url'] = actorUrl
|
||||
print('actorUrl: ' + actorUrl)
|
||||
if '.' in actorUrl:
|
||||
imgExt = actorUrl.split('.')[-1]
|
||||
if imgExt == 'jpg':
|
||||
imgExt = 'jpeg'
|
||||
actorJson['icon']['mediaType'] = \
|
||||
actor_json['icon']['mediaType'] = \
|
||||
'image/' + imgExt
|
||||
elif mType == 'image':
|
||||
lastPartOfUrl = \
|
||||
actorJson['image']['url'].split('/')[-1]
|
||||
actor_json['image']['url'].split('/')[-1]
|
||||
srchStr = '/' + lastPartOfUrl
|
||||
actorJson['image']['url'] = \
|
||||
actorJson['image']['url'].replace(srchStr,
|
||||
repStr)
|
||||
if '.' in actorJson['image']['url']:
|
||||
actor_json['image']['url'] = \
|
||||
actor_json['image']['url'].replace(srchStr,
|
||||
repStr)
|
||||
if '.' in actor_json['image']['url']:
|
||||
imgExt = \
|
||||
actorJson['image']['url'].split('.')[-1]
|
||||
actor_json['image']['url'].split('.')[-1]
|
||||
if imgExt == 'jpg':
|
||||
imgExt = 'jpeg'
|
||||
actorJson['image']['mediaType'] = \
|
||||
actor_json['image']['mediaType'] = \
|
||||
'image/' + imgExt
|
||||
|
||||
# set skill levels
|
||||
skillCtr = 1
|
||||
actorSkillsCtr = noOfActorSkills(actorJson)
|
||||
actorSkillsCtr = noOfActorSkills(actor_json)
|
||||
while skillCtr < 10:
|
||||
skillName = \
|
||||
fields.get('skillName' + str(skillCtr))
|
||||
|
@ -4944,20 +4944,20 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if not skillValue:
|
||||
skillCtr += 1
|
||||
continue
|
||||
if not actorHasSkill(actorJson, skillName):
|
||||
if not actorHasSkill(actor_json, skillName):
|
||||
actorChanged = True
|
||||
else:
|
||||
if actorSkillValue(actorJson, skillName) != \
|
||||
if actorSkillValue(actor_json, skillName) != \
|
||||
int(skillValue):
|
||||
actorChanged = True
|
||||
setActorSkillLevel(actorJson,
|
||||
setActorSkillLevel(actor_json,
|
||||
skillName, int(skillValue))
|
||||
skillsStr = self.server.translate['Skills']
|
||||
skillsStr = skillsStr.lower()
|
||||
setHashtagCategory(base_dir, skillName,
|
||||
skillsStr, False)
|
||||
skillCtr += 1
|
||||
if noOfActorSkills(actorJson) != \
|
||||
if noOfActorSkills(actor_json) != \
|
||||
actorSkillsCtr:
|
||||
actorChanged = True
|
||||
|
||||
|
@ -4992,15 +4992,15 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
# change displayed name
|
||||
if fields.get('displayNickname'):
|
||||
if fields['displayNickname'] != actorJson['name']:
|
||||
if fields['displayNickname'] != actor_json['name']:
|
||||
displayName = \
|
||||
removeHtml(fields['displayNickname'])
|
||||
if not isFiltered(base_dir,
|
||||
nickname, domain,
|
||||
displayName):
|
||||
actorJson['name'] = displayName
|
||||
actor_json['name'] = displayName
|
||||
else:
|
||||
actorJson['name'] = nickname
|
||||
actor_json['name'] = nickname
|
||||
if checkNameAndBio:
|
||||
redirectPath = 'previewAvatar'
|
||||
actorChanged = True
|
||||
|
@ -5274,220 +5274,220 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'instanceDescription', '')
|
||||
|
||||
# change email address
|
||||
currentEmailAddress = getEmailAddress(actorJson)
|
||||
currentEmailAddress = getEmailAddress(actor_json)
|
||||
if fields.get('email'):
|
||||
if fields['email'] != currentEmailAddress:
|
||||
setEmailAddress(actorJson, fields['email'])
|
||||
setEmailAddress(actor_json, fields['email'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentEmailAddress:
|
||||
setEmailAddress(actorJson, '')
|
||||
setEmailAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change xmpp address
|
||||
currentXmppAddress = getXmppAddress(actorJson)
|
||||
currentXmppAddress = getXmppAddress(actor_json)
|
||||
if fields.get('xmppAddress'):
|
||||
if fields['xmppAddress'] != currentXmppAddress:
|
||||
setXmppAddress(actorJson,
|
||||
setXmppAddress(actor_json,
|
||||
fields['xmppAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentXmppAddress:
|
||||
setXmppAddress(actorJson, '')
|
||||
setXmppAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change matrix address
|
||||
currentMatrixAddress = getMatrixAddress(actorJson)
|
||||
currentMatrixAddress = getMatrixAddress(actor_json)
|
||||
if fields.get('matrixAddress'):
|
||||
if fields['matrixAddress'] != currentMatrixAddress:
|
||||
setMatrixAddress(actorJson,
|
||||
setMatrixAddress(actor_json,
|
||||
fields['matrixAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentMatrixAddress:
|
||||
setMatrixAddress(actorJson, '')
|
||||
setMatrixAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change SSB address
|
||||
currentSSBAddress = getSSBAddress(actorJson)
|
||||
currentSSBAddress = getSSBAddress(actor_json)
|
||||
if fields.get('ssbAddress'):
|
||||
if fields['ssbAddress'] != currentSSBAddress:
|
||||
setSSBAddress(actorJson,
|
||||
setSSBAddress(actor_json,
|
||||
fields['ssbAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentSSBAddress:
|
||||
setSSBAddress(actorJson, '')
|
||||
setSSBAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change blog address
|
||||
currentBlogAddress = getBlogAddress(actorJson)
|
||||
currentBlogAddress = getBlogAddress(actor_json)
|
||||
if fields.get('blogAddress'):
|
||||
if fields['blogAddress'] != currentBlogAddress:
|
||||
setBlogAddress(actorJson,
|
||||
setBlogAddress(actor_json,
|
||||
fields['blogAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentBlogAddress:
|
||||
setBlogAddress(actorJson, '')
|
||||
setBlogAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change Languages address
|
||||
currentShowLanguages = getActorLanguages(actorJson)
|
||||
currentShowLanguages = getActorLanguages(actor_json)
|
||||
if fields.get('showLanguages'):
|
||||
if fields['showLanguages'] != currentShowLanguages:
|
||||
setActorLanguages(base_dir, actorJson,
|
||||
setActorLanguages(base_dir, actor_json,
|
||||
fields['showLanguages'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentShowLanguages:
|
||||
setActorLanguages(base_dir, actorJson, '')
|
||||
setActorLanguages(base_dir, actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change tox address
|
||||
currentToxAddress = getToxAddress(actorJson)
|
||||
currentToxAddress = getToxAddress(actor_json)
|
||||
if fields.get('toxAddress'):
|
||||
if fields['toxAddress'] != currentToxAddress:
|
||||
setToxAddress(actorJson,
|
||||
setToxAddress(actor_json,
|
||||
fields['toxAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentToxAddress:
|
||||
setToxAddress(actorJson, '')
|
||||
setToxAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change briar address
|
||||
currentBriarAddress = getBriarAddress(actorJson)
|
||||
currentBriarAddress = getBriarAddress(actor_json)
|
||||
if fields.get('briarAddress'):
|
||||
if fields['briarAddress'] != currentBriarAddress:
|
||||
setBriarAddress(actorJson,
|
||||
setBriarAddress(actor_json,
|
||||
fields['briarAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentBriarAddress:
|
||||
setBriarAddress(actorJson, '')
|
||||
setBriarAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change jami address
|
||||
currentJamiAddress = getJamiAddress(actorJson)
|
||||
currentJamiAddress = getJamiAddress(actor_json)
|
||||
if fields.get('jamiAddress'):
|
||||
if fields['jamiAddress'] != currentJamiAddress:
|
||||
setJamiAddress(actorJson,
|
||||
setJamiAddress(actor_json,
|
||||
fields['jamiAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentJamiAddress:
|
||||
setJamiAddress(actorJson, '')
|
||||
setJamiAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change cwtch address
|
||||
currentCwtchAddress = getCwtchAddress(actorJson)
|
||||
currentCwtchAddress = getCwtchAddress(actor_json)
|
||||
if fields.get('cwtchAddress'):
|
||||
if fields['cwtchAddress'] != currentCwtchAddress:
|
||||
setCwtchAddress(actorJson,
|
||||
setCwtchAddress(actor_json,
|
||||
fields['cwtchAddress'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentCwtchAddress:
|
||||
setCwtchAddress(actorJson, '')
|
||||
setCwtchAddress(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change Enigma public key
|
||||
currentEnigmaPubKey = getEnigmaPubKey(actorJson)
|
||||
currentEnigmaPubKey = getEnigmaPubKey(actor_json)
|
||||
if fields.get('enigmapubkey'):
|
||||
if fields['enigmapubkey'] != currentEnigmaPubKey:
|
||||
setEnigmaPubKey(actorJson,
|
||||
setEnigmaPubKey(actor_json,
|
||||
fields['enigmapubkey'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentEnigmaPubKey:
|
||||
setEnigmaPubKey(actorJson, '')
|
||||
setEnigmaPubKey(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change PGP public key
|
||||
currentPGPpubKey = getPGPpubKey(actorJson)
|
||||
currentPGPpubKey = getPGPpubKey(actor_json)
|
||||
if fields.get('pgp'):
|
||||
if fields['pgp'] != currentPGPpubKey:
|
||||
setPGPpubKey(actorJson,
|
||||
setPGPpubKey(actor_json,
|
||||
fields['pgp'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentPGPpubKey:
|
||||
setPGPpubKey(actorJson, '')
|
||||
setPGPpubKey(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change PGP fingerprint
|
||||
currentPGPfingerprint = getPGPfingerprint(actorJson)
|
||||
currentPGPfingerprint = getPGPfingerprint(actor_json)
|
||||
if fields.get('openpgp'):
|
||||
if fields['openpgp'] != currentPGPfingerprint:
|
||||
setPGPfingerprint(actorJson,
|
||||
setPGPfingerprint(actor_json,
|
||||
fields['openpgp'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentPGPfingerprint:
|
||||
setPGPfingerprint(actorJson, '')
|
||||
setPGPfingerprint(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change donation link
|
||||
currentDonateUrl = getDonationUrl(actorJson)
|
||||
currentDonateUrl = getDonationUrl(actor_json)
|
||||
if fields.get('donateUrl'):
|
||||
if fields['donateUrl'] != currentDonateUrl:
|
||||
setDonationUrl(actorJson,
|
||||
setDonationUrl(actor_json,
|
||||
fields['donateUrl'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentDonateUrl:
|
||||
setDonationUrl(actorJson, '')
|
||||
setDonationUrl(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# change website
|
||||
currentWebsite = \
|
||||
getWebsite(actorJson, self.server.translate)
|
||||
getWebsite(actor_json, self.server.translate)
|
||||
if fields.get('websiteUrl'):
|
||||
if fields['websiteUrl'] != currentWebsite:
|
||||
setWebsite(actorJson,
|
||||
setWebsite(actor_json,
|
||||
fields['websiteUrl'],
|
||||
self.server.translate)
|
||||
actorChanged = True
|
||||
else:
|
||||
if currentWebsite:
|
||||
setWebsite(actorJson, '', self.server.translate)
|
||||
setWebsite(actor_json, '', self.server.translate)
|
||||
actorChanged = True
|
||||
|
||||
# account moved to new address
|
||||
movedTo = ''
|
||||
if actorJson.get('movedTo'):
|
||||
movedTo = actorJson['movedTo']
|
||||
if actor_json.get('movedTo'):
|
||||
movedTo = actor_json['movedTo']
|
||||
if fields.get('movedTo'):
|
||||
if fields['movedTo'] != movedTo and \
|
||||
'://' in fields['movedTo'] and \
|
||||
'.' in fields['movedTo']:
|
||||
actorJson['movedTo'] = movedTo
|
||||
actor_json['movedTo'] = movedTo
|
||||
actorChanged = True
|
||||
else:
|
||||
if movedTo:
|
||||
del actorJson['movedTo']
|
||||
del actor_json['movedTo']
|
||||
actorChanged = True
|
||||
|
||||
# Other accounts (alsoKnownAs)
|
||||
occupationName = getOccupationName(actorJson)
|
||||
occupationName = getOccupationName(actor_json)
|
||||
if fields.get('occupationName'):
|
||||
fields['occupationName'] = \
|
||||
removeHtml(fields['occupationName'])
|
||||
if occupationName != \
|
||||
fields['occupationName']:
|
||||
setOccupationName(actorJson,
|
||||
setOccupationName(actor_json,
|
||||
fields['occupationName'])
|
||||
actorChanged = True
|
||||
else:
|
||||
if occupationName:
|
||||
setOccupationName(actorJson, '')
|
||||
setOccupationName(actor_json, '')
|
||||
actorChanged = True
|
||||
|
||||
# Other accounts (alsoKnownAs)
|
||||
alsoKnownAs = []
|
||||
if actorJson.get('alsoKnownAs'):
|
||||
alsoKnownAs = actorJson['alsoKnownAs']
|
||||
if actor_json.get('alsoKnownAs'):
|
||||
alsoKnownAs = actor_json['alsoKnownAs']
|
||||
if fields.get('alsoKnownAs'):
|
||||
alsoKnownAsStr = ''
|
||||
alsoKnownAsCtr = 0
|
||||
|
@ -5510,30 +5510,30 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if '://' in altActor and '.' in altActor:
|
||||
if altActor not in alsoKnownAs:
|
||||
alsoKnownAs.append(altActor)
|
||||
actorJson['alsoKnownAs'] = alsoKnownAs
|
||||
actor_json['alsoKnownAs'] = alsoKnownAs
|
||||
actorChanged = True
|
||||
else:
|
||||
if alsoKnownAs:
|
||||
del actorJson['alsoKnownAs']
|
||||
del actor_json['alsoKnownAs']
|
||||
actorChanged = True
|
||||
|
||||
# change user bio
|
||||
if fields.get('bio'):
|
||||
if fields['bio'] != actorJson['summary']:
|
||||
if fields['bio'] != actor_json['summary']:
|
||||
bioStr = removeHtml(fields['bio'])
|
||||
if not isFiltered(base_dir,
|
||||
nickname, domain, bioStr):
|
||||
actorTags = {}
|
||||
actorJson['summary'] = \
|
||||
actor_json['summary'] = \
|
||||
addHtmlTags(base_dir,
|
||||
http_prefix,
|
||||
nickname,
|
||||
domain_full,
|
||||
bioStr, [], actorTags)
|
||||
if actorTags:
|
||||
actorJson['tag'] = []
|
||||
actor_json['tag'] = []
|
||||
for tagName, tag in actorTags.items():
|
||||
actorJson['tag'].append(tag)
|
||||
actor_json['tag'].append(tag)
|
||||
actorChanged = True
|
||||
else:
|
||||
if checkNameAndBio:
|
||||
|
@ -5905,7 +5905,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# approve followers
|
||||
if onFinalWelcomeScreen:
|
||||
# Default setting created via the welcome screen
|
||||
actorJson['manuallyApprovesFollowers'] = True
|
||||
actor_json['manuallyApprovesFollowers'] = True
|
||||
actorChanged = True
|
||||
else:
|
||||
approveFollowers = False
|
||||
|
@ -5913,8 +5913,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if fields['approveFollowers'] == 'on':
|
||||
approveFollowers = True
|
||||
if approveFollowers != \
|
||||
actorJson['manuallyApprovesFollowers']:
|
||||
actorJson['manuallyApprovesFollowers'] = \
|
||||
actor_json['manuallyApprovesFollowers']:
|
||||
actor_json['manuallyApprovesFollowers'] = \
|
||||
approveFollowers
|
||||
actorChanged = True
|
||||
|
||||
|
@ -6174,23 +6174,23 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# this account is a bot
|
||||
if fields.get('isBot'):
|
||||
if fields['isBot'] == 'on':
|
||||
if actorJson['type'] != 'Service':
|
||||
actorJson['type'] = 'Service'
|
||||
if actor_json['type'] != 'Service':
|
||||
actor_json['type'] = 'Service'
|
||||
actorChanged = True
|
||||
else:
|
||||
# this account is a group
|
||||
if fields.get('isGroup'):
|
||||
if fields['isGroup'] == 'on':
|
||||
if actorJson['type'] != 'Group':
|
||||
if actor_json['type'] != 'Group':
|
||||
# only allow admin to create groups
|
||||
if path.startswith('/users/' +
|
||||
adminNickname + '/'):
|
||||
actorJson['type'] = 'Group'
|
||||
actor_json['type'] = 'Group'
|
||||
actorChanged = True
|
||||
else:
|
||||
# this account is a person (default)
|
||||
if actorJson['type'] != 'Person':
|
||||
actorJson['type'] = 'Person'
|
||||
if actor_json['type'] != 'Person':
|
||||
actor_json['type'] = 'Person'
|
||||
actorChanged = True
|
||||
|
||||
# grayscale theme
|
||||
|
@ -6478,23 +6478,23 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# save actor json file within accounts
|
||||
if actorChanged:
|
||||
# update the context for the actor
|
||||
actorJson['@context'] = [
|
||||
actor_json['@context'] = [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
'https://w3id.org/security/v1',
|
||||
getDefaultPersonContext()
|
||||
]
|
||||
if actorJson.get('nomadicLocations'):
|
||||
del actorJson['nomadicLocations']
|
||||
if not actorJson.get('featured'):
|
||||
actorJson['featured'] = \
|
||||
actorJson['id'] + '/collections/featured'
|
||||
if not actorJson.get('featuredTags'):
|
||||
actorJson['featuredTags'] = \
|
||||
actorJson['id'] + '/collections/tags'
|
||||
randomizeActorImages(actorJson)
|
||||
addActorUpdateTimestamp(actorJson)
|
||||
if actor_json.get('nomadicLocations'):
|
||||
del actor_json['nomadicLocations']
|
||||
if not actor_json.get('featured'):
|
||||
actor_json['featured'] = \
|
||||
actor_json['id'] + '/collections/featured'
|
||||
if not actor_json.get('featuredTags'):
|
||||
actor_json['featuredTags'] = \
|
||||
actor_json['id'] + '/collections/tags'
|
||||
randomizeActorImages(actor_json)
|
||||
addActorUpdateTimestamp(actor_json)
|
||||
# save the actor
|
||||
saveJson(actorJson, actorFilename)
|
||||
saveJson(actor_json, actorFilename)
|
||||
webfingerUpdate(base_dir,
|
||||
nickname, domain,
|
||||
onion_domain,
|
||||
|
@ -6502,20 +6502,20 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# also copy to the actors cache and
|
||||
# person_cache in memory
|
||||
storePersonInCache(base_dir,
|
||||
actorJson['id'], actorJson,
|
||||
actor_json['id'], actor_json,
|
||||
self.server.person_cache,
|
||||
True)
|
||||
# clear any cached images for this actor
|
||||
idStr = actorJson['id'].replace('/', '-')
|
||||
idStr = actor_json['id'].replace('/', '-')
|
||||
removeAvatarFromCache(base_dir, idStr)
|
||||
# save the actor to the cache
|
||||
actorCacheFilename = \
|
||||
base_dir + '/cache/actors/' + \
|
||||
actorJson['id'].replace('/', '#') + '.json'
|
||||
saveJson(actorJson, actorCacheFilename)
|
||||
actor_json['id'].replace('/', '#') + '.json'
|
||||
saveJson(actor_json, actorCacheFilename)
|
||||
# send profile update to followers
|
||||
pubNumber, pubDate = getStatusNumber()
|
||||
updateActorJson = getActorUpdateJson(actorJson)
|
||||
updateActorJson = getActorUpdateJson(actor_json)
|
||||
print('Sending actor update: ' + str(updateActorJson))
|
||||
self._postToOutbox(updateActorJson,
|
||||
self.server.project_version,
|
||||
|
@ -7104,34 +7104,35 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
lockedAccount = False
|
||||
alsoKnownAs = None
|
||||
movedTo = ''
|
||||
actorJson = getPersonFromCache(base_dir,
|
||||
optionsActor,
|
||||
self.server.person_cache,
|
||||
True)
|
||||
if actorJson:
|
||||
if actorJson.get('movedTo'):
|
||||
movedTo = actorJson['movedTo']
|
||||
actor_json = \
|
||||
getPersonFromCache(base_dir,
|
||||
optionsActor,
|
||||
self.server.person_cache,
|
||||
True)
|
||||
if actor_json:
|
||||
if actor_json.get('movedTo'):
|
||||
movedTo = actor_json['movedTo']
|
||||
if '"' in movedTo:
|
||||
movedTo = movedTo.split('"')[1]
|
||||
if actorJson['type'] == 'Group':
|
||||
if actor_json['type'] == 'Group':
|
||||
isGroup = True
|
||||
lockedAccount = getLockedAccount(actorJson)
|
||||
donateUrl = getDonationUrl(actorJson)
|
||||
websiteUrl = getWebsite(actorJson, self.server.translate)
|
||||
xmppAddress = getXmppAddress(actorJson)
|
||||
matrixAddress = getMatrixAddress(actorJson)
|
||||
ssbAddress = getSSBAddress(actorJson)
|
||||
blogAddress = getBlogAddress(actorJson)
|
||||
toxAddress = getToxAddress(actorJson)
|
||||
briarAddress = getBriarAddress(actorJson)
|
||||
jamiAddress = getJamiAddress(actorJson)
|
||||
cwtchAddress = getCwtchAddress(actorJson)
|
||||
emailAddress = getEmailAddress(actorJson)
|
||||
EnigmaPubKey = getEnigmaPubKey(actorJson)
|
||||
PGPpubKey = getPGPpubKey(actorJson)
|
||||
PGPfingerprint = getPGPfingerprint(actorJson)
|
||||
if actorJson.get('alsoKnownAs'):
|
||||
alsoKnownAs = actorJson['alsoKnownAs']
|
||||
lockedAccount = getLockedAccount(actor_json)
|
||||
donateUrl = getDonationUrl(actor_json)
|
||||
websiteUrl = getWebsite(actor_json, self.server.translate)
|
||||
xmppAddress = getXmppAddress(actor_json)
|
||||
matrixAddress = getMatrixAddress(actor_json)
|
||||
ssbAddress = getSSBAddress(actor_json)
|
||||
blogAddress = getBlogAddress(actor_json)
|
||||
toxAddress = getToxAddress(actor_json)
|
||||
briarAddress = getBriarAddress(actor_json)
|
||||
jamiAddress = getJamiAddress(actor_json)
|
||||
cwtchAddress = getCwtchAddress(actor_json)
|
||||
emailAddress = getEmailAddress(actor_json)
|
||||
EnigmaPubKey = getEnigmaPubKey(actor_json)
|
||||
PGPpubKey = getPGPpubKey(actor_json)
|
||||
PGPfingerprint = getPGPfingerprint(actor_json)
|
||||
if actor_json.get('alsoKnownAs'):
|
||||
alsoKnownAs = actor_json['alsoKnownAs']
|
||||
|
||||
if self.server.session:
|
||||
checkForChangedActor(self.server.session,
|
||||
|
@ -9661,11 +9662,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if not os.path.isfile(actorFilename):
|
||||
return False
|
||||
|
||||
actorJson = loadJson(actorFilename)
|
||||
if not actorJson:
|
||||
actor_json = loadJson(actorFilename)
|
||||
if not actor_json:
|
||||
return False
|
||||
|
||||
if actorJson.get('hasOccupation'):
|
||||
if actor_json.get('hasOccupation'):
|
||||
if self._requestHTTP():
|
||||
getPerson = \
|
||||
personLookup(domain, path.replace('/roles', ''),
|
||||
|
@ -9688,7 +9689,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if self.server.keyShortcuts.get(nickname):
|
||||
accessKeys = self.server.keyShortcuts[nickname]
|
||||
|
||||
rolesList = getActorRolesList(actorJson)
|
||||
rolesList = getActorRolesList(actor_json)
|
||||
city = \
|
||||
getSpoofedCity(self.server.city,
|
||||
base_dir, nickname, domain)
|
||||
|
@ -9735,7 +9736,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.debug)
|
||||
else:
|
||||
if self._secure_mode():
|
||||
rolesList = getActorRolesList(actorJson)
|
||||
rolesList = getActorRolesList(actor_json)
|
||||
msg = json.dumps(rolesList,
|
||||
ensure_ascii=False)
|
||||
msg = msg.encode('utf-8')
|
||||
|
@ -9767,9 +9768,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
nickname = postSections[0]
|
||||
actorFilename = acctDir(base_dir, nickname, domain) + '.json'
|
||||
if os.path.isfile(actorFilename):
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if noOfActorSkills(actorJson) > 0:
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if noOfActorSkills(actor_json) > 0:
|
||||
if self._requestHTTP():
|
||||
getPerson = \
|
||||
personLookup(domain,
|
||||
|
@ -9797,7 +9798,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
accessKeys = \
|
||||
self.server.keyShortcuts[nickname]
|
||||
actorSkillsList = \
|
||||
getOccupationSkills(actorJson)
|
||||
getOccupationSkills(actor_json)
|
||||
skills = getSkillsFromList(actorSkillsList)
|
||||
city = getSpoofedCity(self.server.city,
|
||||
base_dir,
|
||||
|
@ -9854,7 +9855,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
else:
|
||||
if self._secure_mode():
|
||||
actorSkillsList = \
|
||||
getOccupationSkills(actorJson)
|
||||
getOccupationSkills(actor_json)
|
||||
skills = getSkillsFromList(actorSkillsList)
|
||||
msg = json.dumps(skills,
|
||||
ensure_ascii=False)
|
||||
|
@ -12188,8 +12189,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
"""Shows the profile for a person
|
||||
"""
|
||||
# look up a person
|
||||
actorJson = personLookup(domain, path, base_dir)
|
||||
if not actorJson:
|
||||
actor_json = personLookup(domain, path, base_dir)
|
||||
if not actor_json:
|
||||
return False
|
||||
if self._requestHTTP():
|
||||
if not self._establishSession("showPersonProfile"):
|
||||
|
@ -12221,7 +12222,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
base_dir,
|
||||
http_prefix,
|
||||
authorized,
|
||||
actorJson, 'posts',
|
||||
actor_json, 'posts',
|
||||
self.server.session,
|
||||
self.server.cached_webfingers,
|
||||
self.server.person_cache,
|
||||
|
@ -12254,7 +12255,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
else:
|
||||
if self._secure_mode():
|
||||
acceptStr = self.headers['Accept']
|
||||
msgStr = json.dumps(actorJson, ensure_ascii=False)
|
||||
msgStr = json.dumps(actor_json, ensure_ascii=False)
|
||||
msg = msgStr.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
if 'application/ld+json' in acceptStr:
|
||||
|
@ -12290,8 +12291,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if self._requestHTTP():
|
||||
self._404()
|
||||
return False
|
||||
actorJson = personLookup(domain, path, base_dir)
|
||||
if not actorJson:
|
||||
actor_json = personLookup(domain, path, base_dir)
|
||||
if not actor_json:
|
||||
print('ERROR: no instance actor found')
|
||||
self._404()
|
||||
return False
|
||||
|
@ -12308,25 +12309,25 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'featuredTags', 'discoverable', 'published',
|
||||
'devices')
|
||||
for r in removeFields:
|
||||
if r in actorJson:
|
||||
del actorJson[r]
|
||||
actorJson['endpoints'] = {}
|
||||
if r in actor_json:
|
||||
del actor_json[r]
|
||||
actor_json['endpoints'] = {}
|
||||
if enable_shared_inbox:
|
||||
actorJson['endpoints'] = {
|
||||
actor_json['endpoints'] = {
|
||||
'sharedInbox': actorDomainUrl + '/inbox'
|
||||
}
|
||||
actorJson['name'] = 'ACTOR'
|
||||
actorJson['preferredUsername'] = domain_full
|
||||
actorJson['id'] = actorDomainUrl + '/actor'
|
||||
actorJson['type'] = 'Application'
|
||||
actorJson['summary'] = 'Instance Actor'
|
||||
actorJson['publicKey']['id'] = actorDomainUrl + '/actor#main-key'
|
||||
actorJson['publicKey']['owner'] = actorDomainUrl + '/actor'
|
||||
actorJson['url'] = actorDomainUrl + '/actor'
|
||||
actorJson['inbox'] = actorUrl + '/inbox'
|
||||
actorJson['followers'] = actorUrl + '/followers'
|
||||
actorJson['following'] = actorUrl + '/following'
|
||||
msgStr = json.dumps(actorJson, ensure_ascii=False)
|
||||
actor_json['name'] = 'ACTOR'
|
||||
actor_json['preferredUsername'] = domain_full
|
||||
actor_json['id'] = actorDomainUrl + '/actor'
|
||||
actor_json['type'] = 'Application'
|
||||
actor_json['summary'] = 'Instance Actor'
|
||||
actor_json['publicKey']['id'] = actorDomainUrl + '/actor#main-key'
|
||||
actor_json['publicKey']['owner'] = actorDomainUrl + '/actor'
|
||||
actor_json['url'] = actorDomainUrl + '/actor'
|
||||
actor_json['inbox'] = actorUrl + '/inbox'
|
||||
actor_json['followers'] = actorUrl + '/followers'
|
||||
actor_json['following'] = actorUrl + '/following'
|
||||
msgStr = json.dumps(actor_json, ensure_ascii=False)
|
||||
if onion_domain and callingDomain.endswith('.onion'):
|
||||
msgStr = msgStr.replace(http_prefix + '://' + domain_full,
|
||||
'http://' + onion_domain)
|
||||
|
|
|
@ -798,12 +798,12 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
return post_json_object
|
||||
|
||||
|
||||
def _desktopShowActor(base_dir: str, actorJson: {}, translate: {},
|
||||
def _desktopShowActor(base_dir: str, actor_json: {}, translate: {},
|
||||
system_language: str, screenreader: str,
|
||||
espeak) -> None:
|
||||
"""Shows information for the given actor
|
||||
"""
|
||||
actor = actorJson['id']
|
||||
actor = actor_json['id']
|
||||
actorNickname = getNicknameFromActor(actor)
|
||||
actorDomain, actorPort = getDomainFromActor(actor)
|
||||
actorDomainFull = getFullDomain(actorDomain, actorPort)
|
||||
|
@ -812,13 +812,13 @@ def _desktopShowActor(base_dir: str, actorJson: {}, translate: {},
|
|||
sayStr = 'Profile for ' + html.unescape(handle)
|
||||
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
|
||||
print(actor)
|
||||
if actorJson.get('movedTo'):
|
||||
sayStr = 'Moved to ' + html.unescape(actorJson['movedTo'])
|
||||
if actor_json.get('movedTo'):
|
||||
sayStr = 'Moved to ' + html.unescape(actor_json['movedTo'])
|
||||
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
|
||||
if actorJson.get('alsoKnownAs'):
|
||||
if actor_json.get('alsoKnownAs'):
|
||||
alsoKnownAsStr = ''
|
||||
ctr = 0
|
||||
for altActor in actorJson['alsoKnownAs']:
|
||||
for altActor in actor_json['alsoKnownAs']:
|
||||
if ctr > 0:
|
||||
alsoKnownAsStr += ', '
|
||||
ctr += 1
|
||||
|
@ -826,8 +826,8 @@ def _desktopShowActor(base_dir: str, actorJson: {}, translate: {},
|
|||
|
||||
sayStr = 'Also known as ' + html.unescape(alsoKnownAsStr)
|
||||
_sayCommand(sayStr, sayStr, screenreader, system_language, espeak)
|
||||
if actorJson.get('summary'):
|
||||
sayStr = html.unescape(removeHtml(actorJson['summary']))
|
||||
if actor_json.get('summary'):
|
||||
sayStr = html.unescape(removeHtml(actor_json['summary']))
|
||||
sayStr = sayStr.replace('"', "'")
|
||||
sayStr2 = speakableText(base_dir, sayStr, translate)[0]
|
||||
_sayCommand(sayStr, sayStr2, screenreader, system_language, espeak)
|
||||
|
@ -869,14 +869,14 @@ def _desktopShowProfile(session, nickname: str, domain: str,
|
|||
isHttp = False
|
||||
if 'http://' in actor:
|
||||
isHttp = True
|
||||
actorJson, asHeader = \
|
||||
actor_json, asHeader = \
|
||||
getActorJson(domain, actor, isHttp, False, False, True,
|
||||
signing_priv_key_pem, session)
|
||||
|
||||
_desktopShowActor(base_dir, actorJson, translate,
|
||||
_desktopShowActor(base_dir, actor_json, translate,
|
||||
system_language, screenreader, espeak)
|
||||
|
||||
return actorJson
|
||||
return actor_json
|
||||
|
||||
|
||||
def _desktopShowProfileFromHandle(session, nickname: str, domain: str,
|
||||
|
@ -890,14 +890,14 @@ def _desktopShowProfileFromHandle(session, nickname: str, domain: str,
|
|||
"""Shows the profile for a handle
|
||||
Returns the actor json
|
||||
"""
|
||||
actorJson, asHeader = \
|
||||
actor_json, asHeader = \
|
||||
getActorJson(domain, handle, False, False, False, True,
|
||||
signing_priv_key_pem, session)
|
||||
|
||||
_desktopShowActor(base_dir, actorJson, translate,
|
||||
_desktopShowActor(base_dir, actor_json, translate,
|
||||
system_language, screenreader, espeak)
|
||||
|
||||
return actorJson
|
||||
return actor_json
|
||||
|
||||
|
||||
def _desktopGetBoxPostObject(boxJson: {}, index: int) -> {}:
|
||||
|
@ -1410,7 +1410,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
|
||||
domain_full = getFullDomain(domain, port)
|
||||
yourActor = local_actor_url(http_prefix, nickname, domain_full)
|
||||
actorJson = None
|
||||
actor_json = None
|
||||
|
||||
notifyJson = {
|
||||
"dmPostId": "Initial",
|
||||
|
@ -1656,10 +1656,10 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
refreshTimeline = True
|
||||
print('')
|
||||
elif commandStr.startswith('profile ') or commandStr == 'profile':
|
||||
actorJson = None
|
||||
actor_json = None
|
||||
if commandStr == 'profile':
|
||||
if post_json_object:
|
||||
actorJson = \
|
||||
actor_json = \
|
||||
_desktopShowProfile(session, nickname, domain,
|
||||
http_prefix, base_dir,
|
||||
currTimeline,
|
||||
|
@ -1695,11 +1695,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
input()
|
||||
prevTimelineFirstId = ''
|
||||
refreshTimeline = True
|
||||
elif not actorJson and boxJson:
|
||||
elif not actor_json and boxJson:
|
||||
_desktopClearScreen()
|
||||
_desktopShowBanner()
|
||||
postIndex = int(postIndexStr)
|
||||
actorJson = \
|
||||
actor_json = \
|
||||
_desktopShowProfile(session, nickname, domain,
|
||||
http_prefix, base_dir,
|
||||
currTimeline,
|
||||
|
@ -2201,8 +2201,8 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
elif (commandStr == 'follow' or
|
||||
commandStr.startswith('follow ')):
|
||||
if commandStr == 'follow':
|
||||
if actorJson:
|
||||
followHandle = actorJson['id']
|
||||
if actor_json:
|
||||
followHandle = actor_json['id']
|
||||
else:
|
||||
followHandle = ''
|
||||
else:
|
||||
|
|
38
donate.py
38
donate.py
|
@ -18,13 +18,13 @@ def _getWebsiteStrings() -> []:
|
|||
return ['www', 'website', 'web', 'homepage']
|
||||
|
||||
|
||||
def getDonationUrl(actorJson: {}) -> str:
|
||||
def getDonationUrl(actor_json: {}) -> str:
|
||||
"""Returns a link used for donations
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
donationType = _getDonationTypes()
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if propertyValue['name'].lower() not in donationType:
|
||||
|
@ -43,14 +43,14 @@ def getDonationUrl(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def getWebsite(actorJson: {}, translate: {}) -> str:
|
||||
def getWebsite(actor_json: {}, translate: {}) -> str:
|
||||
"""Returns a web address link
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
matchStrings = _getWebsiteStrings()
|
||||
matchStrings.append(translate['Website'].lower())
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if propertyValue['name'].lower() not in matchStrings:
|
||||
|
@ -65,7 +65,7 @@ def getWebsite(actorJson: {}, translate: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
|
||||
def setDonationUrl(actor_json: {}, donateUrl: str) -> None:
|
||||
"""Sets a link used for donations
|
||||
"""
|
||||
notUrl = False
|
||||
|
@ -78,8 +78,8 @@ def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
|
|||
if '<' in donateUrl:
|
||||
notUrl = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
donationType = _getDonationTypes()
|
||||
donateName = None
|
||||
|
@ -91,7 +91,7 @@ def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
|
|||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -101,7 +101,7 @@ def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notUrl:
|
||||
return
|
||||
|
||||
|
@ -110,7 +110,7 @@ def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
|
|||
'" rel="me nofollow noopener noreferrer" target="_blank">' + \
|
||||
donateUrl + '</a>'
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -127,10 +127,10 @@ def setDonationUrl(actorJson: {}, donateUrl: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": donateValue
|
||||
}
|
||||
actorJson['attachment'].append(newDonate)
|
||||
actor_json['attachment'].append(newDonate)
|
||||
|
||||
|
||||
def setWebsite(actorJson: {}, websiteUrl: str, translate: {}) -> None:
|
||||
def setWebsite(actor_json: {}, websiteUrl: str, translate: {}) -> None:
|
||||
"""Sets a web address
|
||||
"""
|
||||
websiteUrl = websiteUrl.strip()
|
||||
|
@ -144,15 +144,15 @@ def setWebsite(actorJson: {}, websiteUrl: str, translate: {}) -> None:
|
|||
if '<' in websiteUrl:
|
||||
notUrl = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
matchStrings = _getWebsiteStrings()
|
||||
matchStrings.append(translate['Website'].lower())
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -162,7 +162,7 @@ def setWebsite(actorJson: {}, websiteUrl: str, translate: {}) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notUrl:
|
||||
return
|
||||
|
||||
|
@ -171,4 +171,4 @@ def setWebsite(actorJson: {}, websiteUrl: str, translate: {}) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": websiteUrl
|
||||
}
|
||||
actorJson['attachment'].append(newEntry)
|
||||
actor_json['attachment'].append(newEntry)
|
||||
|
|
20
enigma.py
20
enigma.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getEnigmaPubKey(actorJson: {}) -> str:
|
||||
def getEnigmaPubKey(actor_json: {}) -> str:
|
||||
"""Returns Enigma public key for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('enigma'):
|
||||
|
@ -28,19 +28,19 @@ def getEnigmaPubKey(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setEnigmaPubKey(actorJson: {}, enigmaPubKey: str) -> None:
|
||||
def setEnigmaPubKey(actor_json: {}, enigmaPubKey: str) -> None:
|
||||
"""Sets a Enigma public key for the given actor
|
||||
"""
|
||||
removeKey = False
|
||||
if not enigmaPubKey:
|
||||
removeKey = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -50,11 +50,11 @@ def setEnigmaPubKey(actorJson: {}, enigmaPubKey: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyValue)
|
||||
actor_json['attachment'].remove(propertyValue)
|
||||
if removeKey:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -71,4 +71,4 @@ def setEnigmaPubKey(actorJson: {}, enigmaPubKey: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": enigmaPubKey
|
||||
}
|
||||
actorJson['attachment'].append(newenigmaPubKey)
|
||||
actor_json['attachment'].append(newenigmaPubKey)
|
||||
|
|
|
@ -1434,9 +1434,9 @@ def followerApprovalActive(base_dir: str, nickname: str, domain: str) -> bool:
|
|||
manuallyApprovesFollowers = False
|
||||
actorFilename = acctDir(base_dir, nickname, domain) + '.json'
|
||||
if os.path.isfile(actorFilename):
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if actorJson.get('manuallyApprovesFollowers'):
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if actor_json.get('manuallyApprovesFollowers'):
|
||||
manuallyApprovesFollowers = \
|
||||
actorJson['manuallyApprovesFollowers']
|
||||
actor_json['manuallyApprovesFollowers']
|
||||
return manuallyApprovesFollowers
|
||||
|
|
6
inbox.py
6
inbox.py
|
@ -2608,10 +2608,10 @@ def _groupHandle(base_dir: str, handle: str) -> bool:
|
|||
actorFile = base_dir + '/accounts/' + handle + '.json'
|
||||
if not os.path.isfile(actorFile):
|
||||
return False
|
||||
actorJson = loadJson(actorFile)
|
||||
if not actorJson:
|
||||
actor_json = loadJson(actorFile)
|
||||
if not actor_json:
|
||||
return False
|
||||
return actorJson['type'] == 'Group'
|
||||
return actor_json['type'] == 'Group'
|
||||
|
||||
|
||||
def _sendToGroupMembers(session, base_dir: str, handle: str, port: int,
|
||||
|
|
20
jami.py
20
jami.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getJamiAddress(actorJson: {}) -> str:
|
||||
def getJamiAddress(actor_json: {}) -> str:
|
||||
"""Returns jami address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('jami'):
|
||||
|
@ -39,7 +39,7 @@ def getJamiAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setJamiAddress(actorJson: {}, jamiAddress: str) -> None:
|
||||
def setJamiAddress(actor_json: {}, jamiAddress: str) -> None:
|
||||
"""Sets an jami address for the given actor
|
||||
"""
|
||||
notJamiAddress = False
|
||||
|
@ -57,12 +57,12 @@ def setJamiAddress(actorJson: {}, jamiAddress: str) -> None:
|
|||
if '<' in jamiAddress:
|
||||
notJamiAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -72,11 +72,11 @@ def setJamiAddress(actorJson: {}, jamiAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notJamiAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -93,4 +93,4 @@ def setJamiAddress(actorJson: {}, jamiAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": jamiAddress
|
||||
}
|
||||
actorJson['attachment'].append(newJamiAddress)
|
||||
actor_json['attachment'].append(newJamiAddress)
|
||||
|
|
19
languages.py
19
languages.py
|
@ -18,10 +18,10 @@ from utils import local_actor_url
|
|||
from cache import getPersonFromCache
|
||||
|
||||
|
||||
def getActorLanguages(actorJson: {}) -> str:
|
||||
def getActorLanguages(actor_json: {}) -> str:
|
||||
"""Returns a string containing languages used by the given actor
|
||||
"""
|
||||
langList = get_actor_languages_list(actorJson)
|
||||
langList = get_actor_languages_list(actor_json)
|
||||
if not langList:
|
||||
return ''
|
||||
languagesStr = ''
|
||||
|
@ -33,7 +33,8 @@ def getActorLanguages(actorJson: {}) -> str:
|
|||
return languagesStr
|
||||
|
||||
|
||||
def setActorLanguages(base_dir: str, actorJson: {}, languagesStr: str) -> None:
|
||||
def setActorLanguages(base_dir: str, actor_json: {},
|
||||
languagesStr: str) -> None:
|
||||
"""Sets the languages used by the given actor
|
||||
"""
|
||||
separator = ','
|
||||
|
@ -66,7 +67,7 @@ def setActorLanguages(base_dir: str, actorJson: {}, languagesStr: str) -> None:
|
|||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -76,7 +77,7 @@ def setActorLanguages(base_dir: str, actorJson: {}, languagesStr: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
|
||||
if not langList2:
|
||||
return
|
||||
|
@ -86,7 +87,7 @@ def setActorLanguages(base_dir: str, actorJson: {}, languagesStr: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": langList2
|
||||
}
|
||||
actorJson['attachment'].append(newLanguages)
|
||||
actor_json['attachment'].append(newLanguages)
|
||||
|
||||
|
||||
def understoodPostLanguage(base_dir: str, nickname: str, domain: str,
|
||||
|
@ -106,11 +107,11 @@ def understoodPostLanguage(base_dir: str, nickname: str, domain: str,
|
|||
if msgObject['contentMap'].get(system_language):
|
||||
return True
|
||||
personUrl = local_actor_url(http_prefix, nickname, domain_full)
|
||||
actorJson = getPersonFromCache(base_dir, personUrl, person_cache, False)
|
||||
if not actorJson:
|
||||
actor_json = getPersonFromCache(base_dir, personUrl, person_cache, False)
|
||||
if not actor_json:
|
||||
print('WARN: unable to load actor to check languages ' + personUrl)
|
||||
return False
|
||||
languagesUnderstood = get_actor_languages_list(actorJson)
|
||||
languagesUnderstood = get_actor_languages_list(actor_json)
|
||||
if not languagesUnderstood:
|
||||
return True
|
||||
for lang in languagesUnderstood:
|
||||
|
|
20
matrix.py
20
matrix.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getMatrixAddress(actorJson: {}) -> str:
|
||||
def getMatrixAddress(actor_json: {}) -> str:
|
||||
"""Returns matrix address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('matrix'):
|
||||
|
@ -36,15 +36,15 @@ def getMatrixAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setMatrixAddress(actorJson: {}, matrixAddress: str) -> None:
|
||||
def setMatrixAddress(actor_json: {}, matrixAddress: str) -> None:
|
||||
"""Sets an matrix address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -54,7 +54,7 @@ def setMatrixAddress(actorJson: {}, matrixAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
|
||||
if '@' not in matrixAddress:
|
||||
return
|
||||
|
@ -69,7 +69,7 @@ def setMatrixAddress(actorJson: {}, matrixAddress: str) -> None:
|
|||
if ':' not in matrixAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -86,4 +86,4 @@ def setMatrixAddress(actorJson: {}, matrixAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": matrixAddress
|
||||
}
|
||||
actorJson['attachment'].append(newMatrixAddress)
|
||||
actor_json['attachment'].append(newMatrixAddress)
|
||||
|
|
24
outbox.py
24
outbox.py
|
@ -123,8 +123,8 @@ def _outboxPersonReceiveUpdate(recentPostsCache: {},
|
|||
if not os.path.isfile(actorFilename):
|
||||
print('actorFilename not found: ' + actorFilename)
|
||||
return
|
||||
actorJson = loadJson(actorFilename)
|
||||
if not actorJson:
|
||||
actor_json = loadJson(actorFilename)
|
||||
if not actor_json:
|
||||
return
|
||||
actorChanged = False
|
||||
# update fields within actor
|
||||
|
@ -140,26 +140,26 @@ def _outboxPersonReceiveUpdate(recentPostsCache: {},
|
|||
continue
|
||||
if newPropertyValue['type'] != 'PropertyValue':
|
||||
continue
|
||||
if 'attachment' not in actorJson:
|
||||
if 'attachment' not in actor_json:
|
||||
continue
|
||||
found = False
|
||||
for attachIdx in range(len(actorJson['attachment'])):
|
||||
if actorJson['attachment'][attachIdx]['type'] != \
|
||||
for attachIdx in range(len(actor_json['attachment'])):
|
||||
if actor_json['attachment'][attachIdx]['type'] != \
|
||||
'PropertyValue':
|
||||
continue
|
||||
if actorJson['attachment'][attachIdx]['name'] != \
|
||||
if actor_json['attachment'][attachIdx]['name'] != \
|
||||
newPropertyValue['name']:
|
||||
continue
|
||||
else:
|
||||
if actorJson['attachment'][attachIdx]['value'] != \
|
||||
if actor_json['attachment'][attachIdx]['value'] != \
|
||||
newPropertyValue['value']:
|
||||
actorJson['attachment'][attachIdx]['value'] = \
|
||||
actor_json['attachment'][attachIdx]['value'] = \
|
||||
newPropertyValue['value']
|
||||
actorChanged = True
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
actorJson['attachment'].append({
|
||||
actor_json['attachment'].append({
|
||||
"name": newPropertyValue['name'],
|
||||
"type": "PropertyValue",
|
||||
"value": newPropertyValue['value']
|
||||
|
@ -167,12 +167,12 @@ def _outboxPersonReceiveUpdate(recentPostsCache: {},
|
|||
actorChanged = True
|
||||
# save actor to file
|
||||
if actorChanged:
|
||||
saveJson(actorJson, actorFilename)
|
||||
saveJson(actor_json, actorFilename)
|
||||
if debug:
|
||||
print('actor saved: ' + actorFilename)
|
||||
if debug:
|
||||
print('New attachment: ' + str(actorJson['attachment']))
|
||||
message_json['object'] = actorJson
|
||||
print('New attachment: ' + str(actor_json['attachment']))
|
||||
message_json['object'] = actor_json
|
||||
if debug:
|
||||
print('DEBUG: actor update via c2s - ' + nickname + '@' + domain)
|
||||
|
||||
|
|
98
person.py
98
person.py
|
@ -196,11 +196,11 @@ def randomizeActorImages(personJson: {}) -> None:
|
|||
'/image' + randStr + '.' + existingExtension
|
||||
|
||||
|
||||
def getActorUpdateJson(actorJson: {}) -> {}:
|
||||
def getActorUpdateJson(actor_json: {}) -> {}:
|
||||
"""Returns the json for an Person Update
|
||||
"""
|
||||
pubNumber, _ = getStatusNumber()
|
||||
manuallyApprovesFollowers = actorJson['manuallyApprovesFollowers']
|
||||
manuallyApprovesFollowers = actor_json['manuallyApprovesFollowers']
|
||||
return {
|
||||
'@context': [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
|
@ -271,38 +271,38 @@ def getActorUpdateJson(actorJson: {}) -> {}:
|
|||
}
|
||||
}
|
||||
],
|
||||
'id': actorJson['id'] + '#updates/' + pubNumber,
|
||||
'id': actor_json['id'] + '#updates/' + pubNumber,
|
||||
'type': 'Update',
|
||||
'actor': actorJson['id'],
|
||||
'actor': actor_json['id'],
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'cc': [actorJson['id'] + '/followers'],
|
||||
'cc': [actor_json['id'] + '/followers'],
|
||||
'object': {
|
||||
'id': actorJson['id'],
|
||||
'type': actorJson['type'],
|
||||
'id': actor_json['id'],
|
||||
'type': actor_json['type'],
|
||||
'icon': {
|
||||
'type': 'Image',
|
||||
'url': actorJson['icon']['url']
|
||||
'url': actor_json['icon']['url']
|
||||
},
|
||||
'image': {
|
||||
'type': 'Image',
|
||||
'url': actorJson['image']['url']
|
||||
'url': actor_json['image']['url']
|
||||
},
|
||||
'attachment': actorJson['attachment'],
|
||||
'following': actorJson['id'] + '/following',
|
||||
'followers': actorJson['id'] + '/followers',
|
||||
'inbox': actorJson['id'] + '/inbox',
|
||||
'outbox': actorJson['id'] + '/outbox',
|
||||
'featured': actorJson['id'] + '/collections/featured',
|
||||
'featuredTags': actorJson['id'] + '/collections/tags',
|
||||
'preferredUsername': actorJson['preferredUsername'],
|
||||
'name': actorJson['name'],
|
||||
'summary': actorJson['summary'],
|
||||
'url': actorJson['url'],
|
||||
'attachment': actor_json['attachment'],
|
||||
'following': actor_json['id'] + '/following',
|
||||
'followers': actor_json['id'] + '/followers',
|
||||
'inbox': actor_json['id'] + '/inbox',
|
||||
'outbox': actor_json['id'] + '/outbox',
|
||||
'featured': actor_json['id'] + '/collections/featured',
|
||||
'featuredTags': actor_json['id'] + '/collections/tags',
|
||||
'preferredUsername': actor_json['preferredUsername'],
|
||||
'name': actor_json['name'],
|
||||
'summary': actor_json['summary'],
|
||||
'url': actor_json['url'],
|
||||
'manuallyApprovesFollowers': manuallyApprovesFollowers,
|
||||
'discoverable': actorJson['discoverable'],
|
||||
'published': actorJson['published'],
|
||||
'devices': actorJson['devices'],
|
||||
"publicKey": actorJson['publicKey'],
|
||||
'discoverable': actor_json['discoverable'],
|
||||
'published': actor_json['published'],
|
||||
'devices': actor_json['devices'],
|
||||
"publicKey": actor_json['publicKey'],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1643,15 +1643,15 @@ def getPersonAvatarUrl(base_dir: str, personUrl: str, person_cache: {},
|
|||
return None
|
||||
|
||||
|
||||
def addActorUpdateTimestamp(actorJson: {}) -> None:
|
||||
def addActorUpdateTimestamp(actor_json: {}) -> None:
|
||||
"""Adds 'updated' fields with a timestamp
|
||||
"""
|
||||
updatedTime = datetime.datetime.utcnow()
|
||||
currDateStr = updatedTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
actorJson['updated'] = currDateStr
|
||||
actor_json['updated'] = currDateStr
|
||||
# add updated timestamp to avatar and banner
|
||||
actorJson['icon']['updated'] = currDateStr
|
||||
actorJson['image']['updated'] = currDateStr
|
||||
actor_json['icon']['updated'] = currDateStr
|
||||
actor_json['image']['updated'] = currDateStr
|
||||
|
||||
|
||||
def validSendingActor(session, base_dir: str,
|
||||
|
@ -1675,26 +1675,26 @@ def validSendingActor(session, base_dir: str,
|
|||
return True
|
||||
|
||||
# get their actor
|
||||
actorJson = getPersonFromCache(base_dir, sendingActor, person_cache, True)
|
||||
actor_json = getPersonFromCache(base_dir, sendingActor, person_cache, True)
|
||||
downloadedActor = False
|
||||
if not actorJson:
|
||||
if not actor_json:
|
||||
# download the actor
|
||||
actorJson, _ = getActorJson(domain, sendingActor,
|
||||
True, False, debug, True,
|
||||
signing_priv_key_pem, session)
|
||||
if actorJson:
|
||||
actor_json, _ = getActorJson(domain, sendingActor,
|
||||
True, False, debug, True,
|
||||
signing_priv_key_pem, session)
|
||||
if actor_json:
|
||||
downloadedActor = True
|
||||
if not actorJson:
|
||||
if not actor_json:
|
||||
# if the actor couldn't be obtained then proceed anyway
|
||||
return True
|
||||
if not actorJson.get('preferredUsername'):
|
||||
print('REJECT: no preferredUsername within actor ' + str(actorJson))
|
||||
if not actor_json.get('preferredUsername'):
|
||||
print('REJECT: no preferredUsername within actor ' + str(actor_json))
|
||||
return False
|
||||
# does the actor have a bio ?
|
||||
if not unit_test:
|
||||
bioStr = ''
|
||||
if actorJson.get('summary'):
|
||||
bioStr = removeHtml(actorJson['summary']).strip()
|
||||
if actor_json.get('summary'):
|
||||
bioStr = removeHtml(actor_json['summary']).strip()
|
||||
if not bioStr:
|
||||
# allow no bio if it's an actor in this instance
|
||||
if domain not in sendingActor:
|
||||
|
@ -1705,11 +1705,11 @@ def validSendingActor(session, base_dir: str,
|
|||
print('REJECT: actor bio is not long enough ' +
|
||||
sendingActor + ' ' + bioStr)
|
||||
return False
|
||||
bioStr += ' ' + removeHtml(actorJson['preferredUsername'])
|
||||
bioStr += ' ' + removeHtml(actor_json['preferredUsername'])
|
||||
|
||||
if actorJson.get('attachment'):
|
||||
if isinstance(actorJson['attachment'], list):
|
||||
for tag in actorJson['attachment']:
|
||||
if actor_json.get('attachment'):
|
||||
if isinstance(actor_json['attachment'], list):
|
||||
for tag in actor_json['attachment']:
|
||||
if not isinstance(tag, dict):
|
||||
continue
|
||||
if not tag.get('name'):
|
||||
|
@ -1721,8 +1721,8 @@ def validSendingActor(session, base_dir: str,
|
|||
if isinstance(tag['value'], str):
|
||||
bioStr += ' ' + tag['value']
|
||||
|
||||
if actorJson.get('name'):
|
||||
bioStr += ' ' + removeHtml(actorJson['name'])
|
||||
if actor_json.get('name'):
|
||||
bioStr += ' ' + removeHtml(actor_json['name'])
|
||||
if containsInvalidChars(bioStr):
|
||||
print('REJECT: post actor bio contains invalid characters')
|
||||
return False
|
||||
|
@ -1734,11 +1734,11 @@ def validSendingActor(session, base_dir: str,
|
|||
|
||||
# Check any attached fields for the actor.
|
||||
# Spam actors will sometimes have attached fields which are all empty
|
||||
if actorJson.get('attachment'):
|
||||
if isinstance(actorJson['attachment'], list):
|
||||
if actor_json.get('attachment'):
|
||||
if isinstance(actor_json['attachment'], list):
|
||||
noOfTags = 0
|
||||
tagsWithoutValue = 0
|
||||
for tag in actorJson['attachment']:
|
||||
for tag in actor_json['attachment']:
|
||||
if not isinstance(tag, dict):
|
||||
continue
|
||||
if not tag.get('name'):
|
||||
|
@ -1765,6 +1765,6 @@ def validSendingActor(session, base_dir: str,
|
|||
if downloadedActor:
|
||||
# if the actor is valid and was downloaded then
|
||||
# store it in the cache, but don't write it to file
|
||||
storePersonInCache(base_dir, sendingActor, actorJson, person_cache,
|
||||
storePersonInCache(base_dir, sendingActor, actor_json, person_cache,
|
||||
False)
|
||||
return True
|
||||
|
|
98
pgp.py
98
pgp.py
|
@ -23,12 +23,12 @@ from auth import createBasicAuthHeader
|
|||
from session import postJson
|
||||
|
||||
|
||||
def getEmailAddress(actorJson: {}) -> str:
|
||||
def getEmailAddress(actor_json: {}) -> str:
|
||||
"""Returns the email address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('email'):
|
||||
|
@ -47,12 +47,12 @@ def getEmailAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def getPGPpubKey(actorJson: {}) -> str:
|
||||
def getPGPpubKey(actor_json: {}) -> str:
|
||||
"""Returns PGP public key for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('pgp'):
|
||||
|
@ -69,12 +69,12 @@ def getPGPpubKey(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def getPGPfingerprint(actorJson: {}) -> str:
|
||||
def getPGPfingerprint(actor_json: {}) -> str:
|
||||
"""Returns PGP fingerprint for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('openpgp'):
|
||||
|
@ -91,7 +91,7 @@ def getPGPfingerprint(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setEmailAddress(actorJson: {}, emailAddress: str) -> None:
|
||||
def setEmailAddress(actor_json: {}, emailAddress: str) -> None:
|
||||
"""Sets the email address for the given actor
|
||||
"""
|
||||
notEmailAddress = False
|
||||
|
@ -104,12 +104,12 @@ def setEmailAddress(actorJson: {}, emailAddress: str) -> None:
|
|||
if emailAddress.startswith('@'):
|
||||
notEmailAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -119,11 +119,11 @@ def setEmailAddress(actorJson: {}, emailAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notEmailAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -140,10 +140,10 @@ def setEmailAddress(actorJson: {}, emailAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": emailAddress
|
||||
}
|
||||
actorJson['attachment'].append(newEmailAddress)
|
||||
actor_json['attachment'].append(newEmailAddress)
|
||||
|
||||
|
||||
def setPGPpubKey(actorJson: {}, PGPpubKey: str) -> None:
|
||||
def setPGPpubKey(actor_json: {}, PGPpubKey: str) -> None:
|
||||
"""Sets a PGP public key for the given actor
|
||||
"""
|
||||
removeKey = False
|
||||
|
@ -155,12 +155,12 @@ def setPGPpubKey(actorJson: {}, PGPpubKey: str) -> None:
|
|||
if '<' in PGPpubKey:
|
||||
removeKey = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -170,11 +170,11 @@ def setPGPpubKey(actorJson: {}, PGPpubKey: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyValue)
|
||||
actor_json['attachment'].remove(propertyValue)
|
||||
if removeKey:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -191,10 +191,10 @@ def setPGPpubKey(actorJson: {}, PGPpubKey: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": PGPpubKey
|
||||
}
|
||||
actorJson['attachment'].append(newPGPpubKey)
|
||||
actor_json['attachment'].append(newPGPpubKey)
|
||||
|
||||
|
||||
def setPGPfingerprint(actorJson: {}, fingerprint: str) -> None:
|
||||
def setPGPfingerprint(actor_json: {}, fingerprint: str) -> None:
|
||||
"""Sets a PGP fingerprint for the given actor
|
||||
"""
|
||||
removeFingerprint = False
|
||||
|
@ -204,12 +204,12 @@ def setPGPfingerprint(actorJson: {}, fingerprint: str) -> None:
|
|||
if len(fingerprint) < 10:
|
||||
removeFingerprint = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -219,11 +219,11 @@ def setPGPfingerprint(actorJson: {}, fingerprint: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyValue)
|
||||
actor_json['attachment'].remove(propertyValue)
|
||||
if removeFingerprint:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -240,7 +240,7 @@ def setPGPfingerprint(actorJson: {}, fingerprint: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": fingerprint
|
||||
}
|
||||
actorJson['attachment'].append(newPGPfingerprint)
|
||||
actor_json['attachment'].append(newPGPfingerprint)
|
||||
|
||||
|
||||
def extractPGPPublicKey(content: str) -> str:
|
||||
|
@ -336,22 +336,22 @@ def _pgpEncrypt(content: str, recipientPubKey: str) -> str:
|
|||
|
||||
def _getPGPPublicKeyFromActor(signing_priv_key_pem: str,
|
||||
domain: str, handle: str,
|
||||
actorJson: {} = None) -> str:
|
||||
actor_json: {} = None) -> str:
|
||||
"""Searches tags on the actor to see if there is any PGP
|
||||
public key specified
|
||||
"""
|
||||
if not actorJson:
|
||||
actorJson, asHeader = \
|
||||
if not actor_json:
|
||||
actor_json, asHeader = \
|
||||
getActorJson(domain, handle, False, False, False, True,
|
||||
signing_priv_key_pem, None)
|
||||
if not actorJson:
|
||||
if not actor_json:
|
||||
return None
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return None
|
||||
if not isinstance(actorJson['attachment'], list):
|
||||
if not isinstance(actor_json['attachment'], list):
|
||||
return None
|
||||
# search through the tags on the actor
|
||||
for tag in actorJson['attachment']:
|
||||
for tag in actor_json['attachment']:
|
||||
if not isinstance(tag, dict):
|
||||
continue
|
||||
if not tag.get('value'):
|
||||
|
@ -489,10 +489,10 @@ def pgpPublicKeyUpload(base_dir: str, session,
|
|||
if debug:
|
||||
print('Getting actor for ' + handle)
|
||||
|
||||
actorJson, asHeader = \
|
||||
actor_json, asHeader = \
|
||||
getActorJson(domain_full, handle, False, False, debug, True,
|
||||
signing_priv_key_pem, session)
|
||||
if not actorJson:
|
||||
if not actor_json:
|
||||
if debug:
|
||||
print('No actor returned for ' + handle)
|
||||
return None
|
||||
|
@ -504,42 +504,42 @@ def pgpPublicKeyUpload(base_dir: str, session,
|
|||
handle = replaceUsersWithAt(actor)
|
||||
|
||||
# check that this looks like the correct actor
|
||||
if not actorJson.get('id'):
|
||||
if not actor_json.get('id'):
|
||||
if debug:
|
||||
print('Actor has no id')
|
||||
return None
|
||||
if not actorJson.get('url'):
|
||||
if not actor_json.get('url'):
|
||||
if debug:
|
||||
print('Actor has no url')
|
||||
return None
|
||||
if not actorJson.get('type'):
|
||||
if not actor_json.get('type'):
|
||||
if debug:
|
||||
print('Actor has no type')
|
||||
return None
|
||||
if actorJson['id'] != actor:
|
||||
if actor_json['id'] != actor:
|
||||
if debug:
|
||||
print('Actor id is not ' + actor +
|
||||
' instead is ' + actorJson['id'])
|
||||
' instead is ' + actor_json['id'])
|
||||
return None
|
||||
if actorJson['url'] != handle:
|
||||
if actor_json['url'] != handle:
|
||||
if debug:
|
||||
print('Actor url is not ' + handle)
|
||||
return None
|
||||
if actorJson['type'] != 'Person':
|
||||
if actor_json['type'] != 'Person':
|
||||
if debug:
|
||||
print('Actor type is not Person')
|
||||
return None
|
||||
|
||||
# set the pgp details
|
||||
if PGPpubKeyId:
|
||||
setPGPfingerprint(actorJson, PGPpubKeyId)
|
||||
setPGPfingerprint(actor_json, PGPpubKeyId)
|
||||
else:
|
||||
if debug:
|
||||
print('No PGP key Id. Continuing anyway.')
|
||||
|
||||
if debug:
|
||||
print('Setting PGP key within ' + actor)
|
||||
setPGPpubKey(actorJson, PGPpubKey)
|
||||
setPGPpubKey(actor_json, PGPpubKey)
|
||||
|
||||
# create an actor update
|
||||
statusNumber, published = getStatusNumber()
|
||||
|
@ -550,7 +550,7 @@ def pgpPublicKeyUpload(base_dir: str, session,
|
|||
'actor': actor,
|
||||
'to': [actor],
|
||||
'cc': [],
|
||||
'object': actorJson
|
||||
'object': actor_json
|
||||
}
|
||||
if debug:
|
||||
print('actor update is ' + str(actorUpdate))
|
||||
|
|
56
roles.py
56
roles.py
|
@ -31,14 +31,14 @@ def _clearRoleStatus(base_dir: str, role: str) -> None:
|
|||
filename = os.path.join(base_dir + '/accounts/', filename)
|
||||
if '"' + role + '"' not in open(filename).read():
|
||||
continue
|
||||
actorJson = loadJson(filename)
|
||||
if not actorJson:
|
||||
actor_json = loadJson(filename)
|
||||
if not actor_json:
|
||||
continue
|
||||
rolesList = getActorRolesList(actorJson)
|
||||
rolesList = getActorRolesList(actor_json)
|
||||
if role in rolesList:
|
||||
rolesList.remove(role)
|
||||
setRolesFromList(actorJson, rolesList)
|
||||
saveJson(actorJson, filename)
|
||||
setRolesFromList(actor_json, rolesList)
|
||||
saveJson(actor_json, filename)
|
||||
|
||||
|
||||
def clearEditorStatus(base_dir: str) -> None:
|
||||
|
@ -120,12 +120,12 @@ def _removeRole(base_dir: str, nickname: str, roleFilename: str) -> None:
|
|||
f.write(roleNickname + '\n')
|
||||
|
||||
|
||||
def _setActorRole(actorJson: {}, roleName: str) -> bool:
|
||||
def _setActorRole(actor_json: {}, roleName: str) -> bool:
|
||||
"""Sets a role for an actor
|
||||
"""
|
||||
if not actorJson.get('hasOccupation'):
|
||||
if not actor_json.get('hasOccupation'):
|
||||
return False
|
||||
if not isinstance(actorJson['hasOccupation'], list):
|
||||
if not isinstance(actor_json['hasOccupation'], list):
|
||||
return False
|
||||
|
||||
# occupation category from www.onetonline.org
|
||||
|
@ -143,8 +143,8 @@ def _setActorRole(actorJson: {}, roleName: str) -> bool:
|
|||
if not category:
|
||||
return False
|
||||
|
||||
for index in range(len(actorJson['hasOccupation'])):
|
||||
occupationItem = actorJson['hasOccupation'][index]
|
||||
for index in range(len(actor_json['hasOccupation'])):
|
||||
occupationItem = actor_json['hasOccupation'][index]
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -178,16 +178,16 @@ def _setActorRole(actorJson: {}, roleName: str) -> bool:
|
|||
},
|
||||
"startDate": published
|
||||
}
|
||||
actorJson['hasOccupation'].append(newRole)
|
||||
actor_json['hasOccupation'].append(newRole)
|
||||
return True
|
||||
|
||||
|
||||
def setRolesFromList(actorJson: {}, rolesList: []) -> None:
|
||||
def setRolesFromList(actor_json: {}, rolesList: []) -> None:
|
||||
"""Sets roles from a list
|
||||
"""
|
||||
# clear Roles from the occupation list
|
||||
emptyRolesList = []
|
||||
for occupationItem in actorJson['hasOccupation']:
|
||||
for occupationItem in actor_json['hasOccupation']:
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -195,22 +195,22 @@ def setRolesFromList(actorJson: {}, rolesList: []) -> None:
|
|||
if occupationItem['@type'] == 'Role':
|
||||
continue
|
||||
emptyRolesList.append(occupationItem)
|
||||
actorJson['hasOccupation'] = emptyRolesList
|
||||
actor_json['hasOccupation'] = emptyRolesList
|
||||
|
||||
# create the new list
|
||||
for roleName in rolesList:
|
||||
_setActorRole(actorJson, roleName)
|
||||
_setActorRole(actor_json, roleName)
|
||||
|
||||
|
||||
def getActorRolesList(actorJson: {}) -> []:
|
||||
def getActorRolesList(actor_json: {}) -> []:
|
||||
"""Gets a list of role names from an actor
|
||||
"""
|
||||
if not actorJson.get('hasOccupation'):
|
||||
if not actor_json.get('hasOccupation'):
|
||||
return []
|
||||
if not isinstance(actorJson['hasOccupation'], list):
|
||||
if not isinstance(actor_json['hasOccupation'], list):
|
||||
return []
|
||||
rolesList = []
|
||||
for occupationItem in actorJson['hasOccupation']:
|
||||
for occupationItem in actor_json['hasOccupation']:
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -242,11 +242,11 @@ def setRole(base_dir: str, nickname: str, domain: str,
|
|||
"artist": "artists.txt"
|
||||
}
|
||||
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if not actorJson.get('hasOccupation'):
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if not actor_json.get('hasOccupation'):
|
||||
return False
|
||||
rolesList = getActorRolesList(actorJson)
|
||||
rolesList = getActorRolesList(actor_json)
|
||||
actorChanged = False
|
||||
if role:
|
||||
# add the role
|
||||
|
@ -255,7 +255,7 @@ def setRole(base_dir: str, nickname: str, domain: str,
|
|||
if role not in rolesList:
|
||||
rolesList.append(role)
|
||||
rolesList.sort()
|
||||
setRolesFromList(actorJson, rolesList)
|
||||
setRolesFromList(actor_json, rolesList)
|
||||
actorChanged = True
|
||||
else:
|
||||
# remove the role
|
||||
|
@ -263,15 +263,15 @@ def setRole(base_dir: str, nickname: str, domain: str,
|
|||
_removeRole(base_dir, nickname, roleFiles[role])
|
||||
if role in rolesList:
|
||||
rolesList.remove(role)
|
||||
setRolesFromList(actorJson, rolesList)
|
||||
setRolesFromList(actor_json, rolesList)
|
||||
actorChanged = True
|
||||
if actorChanged:
|
||||
saveJson(actorJson, actorFilename)
|
||||
saveJson(actor_json, actorFilename)
|
||||
return True
|
||||
|
||||
|
||||
def actorHasRole(actorJson: {}, roleName: str) -> bool:
|
||||
def actorHasRole(actor_json: {}, roleName: str) -> bool:
|
||||
"""Returns true if the given actor has the given role
|
||||
"""
|
||||
rolesList = getActorRolesList(actorJson)
|
||||
rolesList = getActorRolesList(actor_json)
|
||||
return roleName in rolesList
|
||||
|
|
44
skills.py
44
skills.py
|
@ -24,14 +24,14 @@ from utils import local_actor_url
|
|||
from utils import hasActor
|
||||
|
||||
|
||||
def setSkillsFromDict(actorJson: {}, skillsDict: {}) -> []:
|
||||
def setSkillsFromDict(actor_json: {}, skillsDict: {}) -> []:
|
||||
"""Converts a dict containing skills to a list
|
||||
Returns the string version of the dictionary
|
||||
"""
|
||||
skillsList = []
|
||||
for name, value in skillsDict.items():
|
||||
skillsList.append(name + ':' + str(value))
|
||||
setOccupationSkillsList(actorJson, skillsList)
|
||||
setOccupationSkillsList(actor_json, skillsList)
|
||||
return skillsList
|
||||
|
||||
|
||||
|
@ -54,10 +54,10 @@ def getSkillsFromList(skillsList: []) -> {}:
|
|||
return skillsDict
|
||||
|
||||
|
||||
def actorSkillValue(actorJson: {}, skillName: str) -> int:
|
||||
def actorSkillValue(actor_json: {}, skillName: str) -> int:
|
||||
"""Returns The skill level from an actor
|
||||
"""
|
||||
ocSkillsList = getOccupationSkills(actorJson)
|
||||
ocSkillsList = getOccupationSkills(actor_json)
|
||||
skillsDict = getSkillsFromList(ocSkillsList)
|
||||
if not skillsDict:
|
||||
return 0
|
||||
|
@ -67,16 +67,16 @@ def actorSkillValue(actorJson: {}, skillName: str) -> int:
|
|||
return 0
|
||||
|
||||
|
||||
def noOfActorSkills(actorJson: {}) -> int:
|
||||
def noOfActorSkills(actor_json: {}) -> int:
|
||||
"""Returns the number of skills that an actor has
|
||||
"""
|
||||
if actorJson.get('hasOccupation'):
|
||||
skillsList = getOccupationSkills(actorJson)
|
||||
if actor_json.get('hasOccupation'):
|
||||
skillsList = getOccupationSkills(actor_json)
|
||||
return len(skillsList)
|
||||
return 0
|
||||
|
||||
|
||||
def setActorSkillLevel(actorJson: {},
|
||||
def setActorSkillLevel(actor_json: {},
|
||||
skill: str, skillLevelPercent: int) -> bool:
|
||||
"""Set a skill level for a person
|
||||
Setting skill level to zero removes it
|
||||
|
@ -84,10 +84,10 @@ def setActorSkillLevel(actorJson: {},
|
|||
if skillLevelPercent < 0 or skillLevelPercent > 100:
|
||||
return False
|
||||
|
||||
if not actorJson:
|
||||
if not actor_json:
|
||||
return True
|
||||
if not actorJson.get('hasOccupation'):
|
||||
actorJson['hasOccupation'] = [{
|
||||
if not actor_json.get('hasOccupation'):
|
||||
actor_json['hasOccupation'] = [{
|
||||
'@type': 'Occupation',
|
||||
'name': '',
|
||||
"occupationLocation": {
|
||||
|
@ -96,19 +96,19 @@ def setActorSkillLevel(actorJson: {},
|
|||
},
|
||||
'skills': []
|
||||
}]
|
||||
ocSkillsList = getOccupationSkills(actorJson)
|
||||
ocSkillsList = getOccupationSkills(actor_json)
|
||||
skillsDict = getSkillsFromList(ocSkillsList)
|
||||
if not skillsDict.get(skill):
|
||||
if len(skillsDict.items()) >= 32:
|
||||
print('WARN: Maximum number of skills reached for ' +
|
||||
actorJson['id'])
|
||||
actor_json['id'])
|
||||
return False
|
||||
if skillLevelPercent > 0:
|
||||
skillsDict[skill] = skillLevelPercent
|
||||
else:
|
||||
if skillsDict.get(skill):
|
||||
del skillsDict[skill]
|
||||
setSkillsFromDict(actorJson, skillsDict)
|
||||
setSkillsFromDict(actor_json, skillsDict)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -123,8 +123,8 @@ def setSkillLevel(base_dir: str, nickname: str, domain: str,
|
|||
if not os.path.isfile(actorFilename):
|
||||
return False
|
||||
|
||||
actorJson = loadJson(actorFilename)
|
||||
return setActorSkillLevel(actorJson,
|
||||
actor_json = loadJson(actorFilename)
|
||||
return setActorSkillLevel(actor_json,
|
||||
skill, skillLevelPercent)
|
||||
|
||||
|
||||
|
@ -135,11 +135,11 @@ def getSkills(base_dir: str, nickname: str, domain: str) -> []:
|
|||
if not os.path.isfile(actorFilename):
|
||||
return False
|
||||
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if not actorJson.get('hasOccupation'):
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if not actor_json.get('hasOccupation'):
|
||||
return None
|
||||
ocSkillsList = getOccupationSkills(actorJson)
|
||||
ocSkillsList = getOccupationSkills(actor_json)
|
||||
return getSkillsFromList(ocSkillsList)
|
||||
return None
|
||||
|
||||
|
@ -265,10 +265,10 @@ def sendSkillViaServer(base_dir: str, session, nickname: str, password: str,
|
|||
return newSkillJson
|
||||
|
||||
|
||||
def actorHasSkill(actorJson: {}, skillName: str) -> bool:
|
||||
def actorHasSkill(actor_json: {}, skillName: str) -> bool:
|
||||
"""Returns true if the given actor has the given skill
|
||||
"""
|
||||
ocSkillsList = getOccupationSkills(actorJson)
|
||||
ocSkillsList = getOccupationSkills(actor_json)
|
||||
for skillStr in ocSkillsList:
|
||||
if skillName + ':' in skillStr:
|
||||
return True
|
||||
|
|
20
ssb.py
20
ssb.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getSSBAddress(actorJson: {}) -> str:
|
||||
def getSSBAddress(actor_json: {}) -> str:
|
||||
"""Returns ssb address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('ssb'):
|
||||
|
@ -39,7 +39,7 @@ def getSSBAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setSSBAddress(actorJson: {}, ssbAddress: str) -> None:
|
||||
def setSSBAddress(actor_json: {}, ssbAddress: str) -> None:
|
||||
"""Sets an ssb address for the given actor
|
||||
"""
|
||||
notSSBAddress = False
|
||||
|
@ -56,12 +56,12 @@ def setSSBAddress(actorJson: {}, ssbAddress: str) -> None:
|
|||
if '<' in ssbAddress:
|
||||
notSSBAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -71,11 +71,11 @@ def setSSBAddress(actorJson: {}, ssbAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notSSBAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -92,4 +92,4 @@ def setSSBAddress(actorJson: {}, ssbAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": ssbAddress
|
||||
}
|
||||
actorJson['attachment'].append(newSSBAddress)
|
||||
actor_json['attachment'].append(newSSBAddress)
|
||||
|
|
56
tests.py
56
tests.py
|
@ -5154,13 +5154,13 @@ def testUpdateActor(base_dir: str):
|
|||
|
||||
# load alice actor
|
||||
print('Loading actor: ' + actorFilename)
|
||||
actorJson = loadJson(actorFilename)
|
||||
assert actorJson
|
||||
if len(actorJson['attachment']) == 0:
|
||||
print("actorJson['attachment'] has no contents")
|
||||
assert len(actorJson['attachment']) > 0
|
||||
actor_json = loadJson(actorFilename)
|
||||
assert actor_json
|
||||
if len(actor_json['attachment']) == 0:
|
||||
print("actor_json['attachment'] has no contents")
|
||||
assert len(actor_json['attachment']) > 0
|
||||
propertyFound = False
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if propertyValue['name'] == 'PGP':
|
||||
print('PGP property set within attachment')
|
||||
assert pubKey in propertyValue['value']
|
||||
|
@ -5455,7 +5455,7 @@ def _testSpoofGeolocation() -> None:
|
|||
|
||||
def _testSkills() -> None:
|
||||
print('testSkills')
|
||||
actorJson = {
|
||||
actor_json = {
|
||||
'hasOccupation': [
|
||||
{
|
||||
'@type': 'Occupation',
|
||||
|
@ -5472,16 +5472,16 @@ def _testSkills() -> None:
|
|||
'bakery': 40,
|
||||
'gardening': 70
|
||||
}
|
||||
setSkillsFromDict(actorJson, skillsDict)
|
||||
assert actorHasSkill(actorJson, 'bakery')
|
||||
assert actorHasSkill(actorJson, 'gardening')
|
||||
assert actorSkillValue(actorJson, 'bakery') == 40
|
||||
assert actorSkillValue(actorJson, 'gardening') == 70
|
||||
setSkillsFromDict(actor_json, skillsDict)
|
||||
assert actorHasSkill(actor_json, 'bakery')
|
||||
assert actorHasSkill(actor_json, 'gardening')
|
||||
assert actorSkillValue(actor_json, 'bakery') == 40
|
||||
assert actorSkillValue(actor_json, 'gardening') == 70
|
||||
|
||||
|
||||
def _testRoles() -> None:
|
||||
print('testRoles')
|
||||
actorJson = {
|
||||
actor_json = {
|
||||
'hasOccupation': [
|
||||
{
|
||||
'@type': 'Occupation',
|
||||
|
@ -5495,12 +5495,12 @@ def _testRoles() -> None:
|
|||
]
|
||||
}
|
||||
testRolesList = ["admin", "moderator"]
|
||||
setRolesFromList(actorJson, testRolesList)
|
||||
assert actorHasRole(actorJson, "admin")
|
||||
assert actorHasRole(actorJson, "moderator")
|
||||
assert not actorHasRole(actorJson, "editor")
|
||||
assert not actorHasRole(actorJson, "counselor")
|
||||
assert not actorHasRole(actorJson, "artist")
|
||||
setRolesFromList(actor_json, testRolesList)
|
||||
assert actorHasRole(actor_json, "admin")
|
||||
assert actorHasRole(actor_json, "moderator")
|
||||
assert not actorHasRole(actor_json, "editor")
|
||||
assert not actorHasRole(actor_json, "counselor")
|
||||
assert not actorHasRole(actor_json, "artist")
|
||||
|
||||
|
||||
def _testUserAgentDomain() -> None:
|
||||
|
@ -5586,20 +5586,20 @@ def _testLimitRepetedWords() -> None:
|
|||
|
||||
def _testSetActorLanguages():
|
||||
print('testSetActorLanguages')
|
||||
actorJson = {
|
||||
actor_json = {
|
||||
"attachment": []
|
||||
}
|
||||
setActorLanguages(None, actorJson, 'es, fr, en')
|
||||
assert len(actorJson['attachment']) == 1
|
||||
assert actorJson['attachment'][0]['name'] == 'Languages'
|
||||
assert actorJson['attachment'][0]['type'] == 'PropertyValue'
|
||||
assert isinstance(actorJson['attachment'][0]['value'], str)
|
||||
assert ',' in actorJson['attachment'][0]['value']
|
||||
langList = get_actor_languages_list(actorJson)
|
||||
setActorLanguages(None, actor_json, 'es, fr, en')
|
||||
assert len(actor_json['attachment']) == 1
|
||||
assert actor_json['attachment'][0]['name'] == 'Languages'
|
||||
assert actor_json['attachment'][0]['type'] == 'PropertyValue'
|
||||
assert isinstance(actor_json['attachment'][0]['value'], str)
|
||||
assert ',' in actor_json['attachment'][0]['value']
|
||||
langList = get_actor_languages_list(actor_json)
|
||||
assert 'en' in langList
|
||||
assert 'fr' in langList
|
||||
assert 'es' in langList
|
||||
languagesStr = getActorLanguages(actorJson)
|
||||
languagesStr = getActorLanguages(actor_json)
|
||||
assert languagesStr == 'en / es / fr'
|
||||
|
||||
|
||||
|
|
20
tox.py
20
tox.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getToxAddress(actorJson: {}) -> str:
|
||||
def getToxAddress(actor_json: {}) -> str:
|
||||
"""Returns tox address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('tox'):
|
||||
|
@ -41,7 +41,7 @@ def getToxAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setToxAddress(actorJson: {}, toxAddress: str) -> None:
|
||||
def setToxAddress(actor_json: {}, toxAddress: str) -> None:
|
||||
"""Sets an tox address for the given actor
|
||||
"""
|
||||
notToxAddress = False
|
||||
|
@ -61,12 +61,12 @@ def setToxAddress(actorJson: {}, toxAddress: str) -> None:
|
|||
if '<' in toxAddress:
|
||||
notToxAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -76,11 +76,11 @@ def setToxAddress(actorJson: {}, toxAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notToxAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -97,4 +97,4 @@ def setToxAddress(actorJson: {}, toxAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": toxAddress
|
||||
}
|
||||
actorJson['attachment'].append(newToxAddress)
|
||||
actor_json['attachment'].append(newToxAddress)
|
||||
|
|
78
utils.py
78
utils.py
|
@ -34,12 +34,12 @@ def local_actor_url(http_prefix: str, nickname: str, domain_full: str) -> str:
|
|||
return http_prefix + '://' + domain_full + '/users/' + nickname
|
||||
|
||||
|
||||
def get_actor_languages_list(actorJson: {}) -> []:
|
||||
def get_actor_languages_list(actor_json: {}) -> []:
|
||||
"""Returns a list containing languages used by the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return []
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith('languages'):
|
||||
|
@ -180,12 +180,12 @@ def decodedHost(host: str) -> str:
|
|||
return host
|
||||
|
||||
|
||||
def getLockedAccount(actorJson: {}) -> bool:
|
||||
def getLockedAccount(actor_json: {}) -> bool:
|
||||
"""Returns whether the given account requires follower approval
|
||||
"""
|
||||
if not actorJson.get('manuallyApprovesFollowers'):
|
||||
if not actor_json.get('manuallyApprovesFollowers'):
|
||||
return False
|
||||
if actorJson['manuallyApprovesFollowers'] is True:
|
||||
if actor_json['manuallyApprovesFollowers'] is True:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -917,10 +917,10 @@ def getDisplayName(base_dir: str, actor: str, person_cache: {}) -> str:
|
|||
cachedActorFilename = \
|
||||
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
|
||||
if os.path.isfile(cachedActorFilename):
|
||||
actorJson = loadJson(cachedActorFilename, 1)
|
||||
if actorJson:
|
||||
if actorJson.get('name'):
|
||||
nameFound = actorJson['name']
|
||||
actor_json = loadJson(cachedActorFilename, 1)
|
||||
if actor_json:
|
||||
if actor_json.get('name'):
|
||||
nameFound = actor_json['name']
|
||||
if nameFound:
|
||||
if dangerousMarkup(nameFound, False):
|
||||
nameFound = "*ADVERSARY*"
|
||||
|
@ -966,20 +966,20 @@ def getGenderFromBio(base_dir: str, actor: str, person_cache: {},
|
|||
pronounStr = translate['pronoun'].lower()
|
||||
else:
|
||||
pronounStr = 'pronoun'
|
||||
actorJson = None
|
||||
actor_json = None
|
||||
if person_cache[actor].get('actor'):
|
||||
actorJson = person_cache[actor]['actor']
|
||||
actor_json = person_cache[actor]['actor']
|
||||
else:
|
||||
# Try to obtain from the cached actors
|
||||
cachedActorFilename = \
|
||||
base_dir + '/cache/actors/' + (actor.replace('/', '#')) + '.json'
|
||||
if os.path.isfile(cachedActorFilename):
|
||||
actorJson = loadJson(cachedActorFilename, 1)
|
||||
if not actorJson:
|
||||
actor_json = loadJson(cachedActorFilename, 1)
|
||||
if not actor_json:
|
||||
return defaultGender
|
||||
# is gender defined as a profile tag?
|
||||
if actorJson.get('attachment'):
|
||||
tagsList = actorJson['attachment']
|
||||
if actor_json.get('attachment'):
|
||||
tagsList = actor_json['attachment']
|
||||
if isinstance(tagsList, list):
|
||||
# look for a gender field name
|
||||
for tag in tagsList:
|
||||
|
@ -1006,8 +1006,8 @@ def getGenderFromBio(base_dir: str, actor: str, person_cache: {},
|
|||
if gender:
|
||||
return gender
|
||||
# if not then use the bio
|
||||
if not bioFound and actorJson.get('summary'):
|
||||
bioFound = actorJson['summary']
|
||||
if not bioFound and actor_json.get('summary'):
|
||||
bioFound = actor_json['summary']
|
||||
if not bioFound:
|
||||
return defaultGender
|
||||
gender = _genderFromString(translate, bioFound)
|
||||
|
@ -2714,14 +2714,14 @@ def dmAllowedFromDomain(base_dir: str,
|
|||
return False
|
||||
|
||||
|
||||
def getOccupationSkills(actorJson: {}) -> []:
|
||||
def getOccupationSkills(actor_json: {}) -> []:
|
||||
"""Returns the list of skills for an actor
|
||||
"""
|
||||
if 'hasOccupation' not in actorJson:
|
||||
if 'hasOccupation' not in actor_json:
|
||||
return []
|
||||
if not isinstance(actorJson['hasOccupation'], list):
|
||||
if not isinstance(actor_json['hasOccupation'], list):
|
||||
return []
|
||||
for occupationItem in actorJson['hasOccupation']:
|
||||
for occupationItem in actor_json['hasOccupation']:
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -2738,14 +2738,14 @@ def getOccupationSkills(actorJson: {}) -> []:
|
|||
return []
|
||||
|
||||
|
||||
def getOccupationName(actorJson: {}) -> str:
|
||||
def getOccupationName(actor_json: {}) -> str:
|
||||
"""Returns the occupation name an actor
|
||||
"""
|
||||
if not actorJson.get('hasOccupation'):
|
||||
if not actor_json.get('hasOccupation'):
|
||||
return ""
|
||||
if not isinstance(actorJson['hasOccupation'], list):
|
||||
if not isinstance(actor_json['hasOccupation'], list):
|
||||
return ""
|
||||
for occupationItem in actorJson['hasOccupation']:
|
||||
for occupationItem in actor_json['hasOccupation']:
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -2760,15 +2760,15 @@ def getOccupationName(actorJson: {}) -> str:
|
|||
return ""
|
||||
|
||||
|
||||
def setOccupationName(actorJson: {}, name: str) -> bool:
|
||||
def setOccupationName(actor_json: {}, name: str) -> bool:
|
||||
"""Sets the occupation name of an actor
|
||||
"""
|
||||
if not actorJson.get('hasOccupation'):
|
||||
if not actor_json.get('hasOccupation'):
|
||||
return False
|
||||
if not isinstance(actorJson['hasOccupation'], list):
|
||||
if not isinstance(actor_json['hasOccupation'], list):
|
||||
return False
|
||||
for index in range(len(actorJson['hasOccupation'])):
|
||||
occupationItem = actorJson['hasOccupation'][index]
|
||||
for index in range(len(actor_json['hasOccupation'])):
|
||||
occupationItem = actor_json['hasOccupation'][index]
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -2780,15 +2780,15 @@ def setOccupationName(actorJson: {}, name: str) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def setOccupationSkillsList(actorJson: {}, skillsList: []) -> bool:
|
||||
def setOccupationSkillsList(actor_json: {}, skillsList: []) -> bool:
|
||||
"""Sets the occupation skills for an actor
|
||||
"""
|
||||
if 'hasOccupation' not in actorJson:
|
||||
if 'hasOccupation' not in actor_json:
|
||||
return False
|
||||
if not isinstance(actorJson['hasOccupation'], list):
|
||||
if not isinstance(actor_json['hasOccupation'], list):
|
||||
return False
|
||||
for index in range(len(actorJson['hasOccupation'])):
|
||||
occupationItem = actorJson['hasOccupation'][index]
|
||||
for index in range(len(actor_json['hasOccupation'])):
|
||||
occupationItem = actor_json['hasOccupation'][index]
|
||||
if not isinstance(occupationItem, dict):
|
||||
continue
|
||||
if not occupationItem.get('@type'):
|
||||
|
@ -2868,13 +2868,13 @@ def getAltPath(actor: str, domain_full: str, callingDomain: str) -> str:
|
|||
return postActor
|
||||
|
||||
|
||||
def getActorPropertyUrl(actorJson: {}, propertyName: str) -> str:
|
||||
def getActorPropertyUrl(actor_json: {}, propertyName: str) -> str:
|
||||
"""Returns a url property from an actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
propertyName = propertyName.lower()
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue['name'].lower().startswith(propertyName):
|
||||
|
|
|
@ -322,15 +322,15 @@ def htmlModerationInfo(cssCache: {}, translate: {},
|
|||
for acct in accounts:
|
||||
acctNickname = acct.split('@')[0]
|
||||
accountDir = os.path.join(base_dir + '/accounts', acct)
|
||||
actorJson = loadJson(accountDir + '.json')
|
||||
if not actorJson:
|
||||
actor_json = loadJson(accountDir + '.json')
|
||||
if not actor_json:
|
||||
continue
|
||||
actor = actorJson['id']
|
||||
actor = actor_json['id']
|
||||
avatarUrl = ''
|
||||
ext = ''
|
||||
if actorJson.get('icon'):
|
||||
if actorJson['icon'].get('url'):
|
||||
avatarUrl = actorJson['icon']['url']
|
||||
if actor_json.get('icon'):
|
||||
if actor_json['icon'].get('url'):
|
||||
avatarUrl = actor_json['icon']['url']
|
||||
if '.' in avatarUrl:
|
||||
ext = '.' + avatarUrl.split('.')[-1]
|
||||
acctUrl = \
|
||||
|
|
|
@ -1850,11 +1850,11 @@ def individualPostAsHtml(signing_priv_key_pem: str,
|
|||
|
||||
domain_full = getFullDomain(domain, port)
|
||||
personUrl = local_actor_url(http_prefix, nickname, domain_full)
|
||||
actorJson = \
|
||||
actor_json = \
|
||||
getPersonFromCache(base_dir, personUrl, person_cache, False)
|
||||
languagesUnderstood = []
|
||||
if actorJson:
|
||||
languagesUnderstood = get_actor_languages_list(actorJson)
|
||||
if actor_json:
|
||||
languagesUnderstood = get_actor_languages_list(actor_json)
|
||||
contentStr = getContentFromPost(post_json_object, system_language,
|
||||
languagesUnderstood)
|
||||
if not contentStr:
|
||||
|
|
|
@ -1985,7 +1985,7 @@ def _getSupportedLanguagesSorted(base_dir: str) -> str:
|
|||
|
||||
def _htmlEditProfileMain(base_dir: str, displayNickname: str, bioStr: str,
|
||||
movedTo: str, donateUrl: str, websiteUrl: str,
|
||||
blogAddress: str, actorJson: {},
|
||||
blogAddress: str, actor_json: {},
|
||||
translate: {}) -> str:
|
||||
"""main info on edit profile screen
|
||||
"""
|
||||
|
@ -2007,16 +2007,16 @@ def _htmlEditProfileMain(base_dir: str, displayNickname: str, bioStr: str,
|
|||
' accept="' + imageFormats + '">\n'
|
||||
|
||||
occupationName = ''
|
||||
if actorJson.get('hasOccupation'):
|
||||
occupationName = getOccupationName(actorJson)
|
||||
if actor_json.get('hasOccupation'):
|
||||
occupationName = getOccupationName(actor_json)
|
||||
|
||||
editProfileForm += \
|
||||
editTextField(translate['Occupation'], 'occupationName',
|
||||
occupationName)
|
||||
|
||||
alsoKnownAsStr = ''
|
||||
if actorJson.get('alsoKnownAs'):
|
||||
alsoKnownAs = actorJson['alsoKnownAs']
|
||||
if actor_json.get('alsoKnownAs'):
|
||||
alsoKnownAs = actor_json['alsoKnownAs']
|
||||
ctr = 0
|
||||
for altActor in alsoKnownAs:
|
||||
if ctr > 0:
|
||||
|
@ -2044,7 +2044,7 @@ def _htmlEditProfileMain(base_dir: str, displayNickname: str, bioStr: str,
|
|||
editTextField('Blog', 'blogAddress', blogAddress, 'https://...')
|
||||
|
||||
languagesListStr = _getSupportedLanguagesSorted(base_dir)
|
||||
showLanguages = getActorLanguages(actorJson)
|
||||
showLanguages = getActorLanguages(actor_json)
|
||||
editProfileForm += \
|
||||
editTextField(translate['Languages'], 'showLanguages',
|
||||
showLanguages, languagesListStr)
|
||||
|
@ -2126,42 +2126,42 @@ def htmlEditProfile(cssCache: {}, translate: {}, base_dir: str, path: str,
|
|||
ssbAddress = blogAddress = toxAddress = jamiAddress = ''
|
||||
cwtchAddress = briarAddress = manuallyApprovesFollowers = ''
|
||||
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if actorJson.get('movedTo'):
|
||||
movedTo = actorJson['movedTo']
|
||||
donateUrl = getDonationUrl(actorJson)
|
||||
websiteUrl = getWebsite(actorJson, translate)
|
||||
xmppAddress = getXmppAddress(actorJson)
|
||||
matrixAddress = getMatrixAddress(actorJson)
|
||||
ssbAddress = getSSBAddress(actorJson)
|
||||
blogAddress = getBlogAddress(actorJson)
|
||||
toxAddress = getToxAddress(actorJson)
|
||||
briarAddress = getBriarAddress(actorJson)
|
||||
jamiAddress = getJamiAddress(actorJson)
|
||||
cwtchAddress = getCwtchAddress(actorJson)
|
||||
emailAddress = getEmailAddress(actorJson)
|
||||
EnigmaPubKey = getEnigmaPubKey(actorJson)
|
||||
PGPpubKey = getPGPpubKey(actorJson)
|
||||
PGPfingerprint = getPGPfingerprint(actorJson)
|
||||
if actorJson.get('name'):
|
||||
if not isFiltered(base_dir, nickname, domain, actorJson['name']):
|
||||
displayNickname = actorJson['name']
|
||||
if actorJson.get('summary'):
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if actor_json.get('movedTo'):
|
||||
movedTo = actor_json['movedTo']
|
||||
donateUrl = getDonationUrl(actor_json)
|
||||
websiteUrl = getWebsite(actor_json, translate)
|
||||
xmppAddress = getXmppAddress(actor_json)
|
||||
matrixAddress = getMatrixAddress(actor_json)
|
||||
ssbAddress = getSSBAddress(actor_json)
|
||||
blogAddress = getBlogAddress(actor_json)
|
||||
toxAddress = getToxAddress(actor_json)
|
||||
briarAddress = getBriarAddress(actor_json)
|
||||
jamiAddress = getJamiAddress(actor_json)
|
||||
cwtchAddress = getCwtchAddress(actor_json)
|
||||
emailAddress = getEmailAddress(actor_json)
|
||||
EnigmaPubKey = getEnigmaPubKey(actor_json)
|
||||
PGPpubKey = getPGPpubKey(actor_json)
|
||||
PGPfingerprint = getPGPfingerprint(actor_json)
|
||||
if actor_json.get('name'):
|
||||
if not isFiltered(base_dir, nickname, domain, actor_json['name']):
|
||||
displayNickname = actor_json['name']
|
||||
if actor_json.get('summary'):
|
||||
bioStr = \
|
||||
actorJson['summary'].replace('<p>', '').replace('</p>', '')
|
||||
actor_json['summary'].replace('<p>', '').replace('</p>', '')
|
||||
if isFiltered(base_dir, nickname, domain, bioStr):
|
||||
bioStr = ''
|
||||
if actorJson.get('manuallyApprovesFollowers'):
|
||||
if actorJson['manuallyApprovesFollowers']:
|
||||
if actor_json.get('manuallyApprovesFollowers'):
|
||||
if actor_json['manuallyApprovesFollowers']:
|
||||
manuallyApprovesFollowers = 'checked'
|
||||
else:
|
||||
manuallyApprovesFollowers = ''
|
||||
if actorJson.get('type'):
|
||||
if actorJson['type'] == 'Service':
|
||||
if actor_json.get('type'):
|
||||
if actor_json['type'] == 'Service':
|
||||
isBot = 'checked'
|
||||
isGroup = ''
|
||||
elif actorJson['type'] == 'Group':
|
||||
elif actor_json['type'] == 'Group':
|
||||
isGroup = 'checked'
|
||||
isBot = ''
|
||||
accountDir = acctDir(base_dir, nickname, domain)
|
||||
|
@ -2266,7 +2266,7 @@ def htmlEditProfile(cssCache: {}, translate: {}, base_dir: str, path: str,
|
|||
editProfileForm += \
|
||||
_htmlEditProfileMain(base_dir, displayNickname, bioStr,
|
||||
movedTo, donateUrl, websiteUrl,
|
||||
blogAddress, actorJson, translate)
|
||||
blogAddress, actor_json, translate)
|
||||
|
||||
# Option checkboxes
|
||||
editProfileForm += \
|
||||
|
|
|
@ -475,14 +475,14 @@ def htmlSkillsSearch(actor: str,
|
|||
if not isAccountDir(f):
|
||||
continue
|
||||
actorFilename = os.path.join(subdir, f)
|
||||
actorJson = loadJson(actorFilename)
|
||||
if actorJson:
|
||||
if actorJson.get('id') and \
|
||||
noOfActorSkills(actorJson) > 0 and \
|
||||
actorJson.get('name') and \
|
||||
actorJson.get('icon'):
|
||||
actor = actorJson['id']
|
||||
actorSkillsList = actorJson['hasOccupation']['skills']
|
||||
actor_json = loadJson(actorFilename)
|
||||
if actor_json:
|
||||
if actor_json.get('id') and \
|
||||
noOfActorSkills(actor_json) > 0 and \
|
||||
actor_json.get('name') and \
|
||||
actor_json.get('icon'):
|
||||
actor = actor_json['id']
|
||||
actorSkillsList = actor_json['hasOccupation']['skills']
|
||||
skills = getSkillsFromList(actorSkillsList)
|
||||
for skillName, skillLevel in skills.items():
|
||||
skillName = skillName.lower()
|
||||
|
@ -496,8 +496,8 @@ def htmlSkillsSearch(actor: str,
|
|||
skillLevelStr = '0' + skillLevelStr
|
||||
indexStr = \
|
||||
skillLevelStr + ';' + actor + ';' + \
|
||||
actorJson['name'] + \
|
||||
';' + actorJson['icon']['url']
|
||||
actor_json['name'] + \
|
||||
';' + actor_json['icon']['url']
|
||||
if indexStr not in results:
|
||||
results.append(indexStr)
|
||||
break
|
||||
|
@ -513,14 +513,14 @@ def htmlSkillsSearch(actor: str,
|
|||
cachedActorJson = loadJson(actorFilename)
|
||||
if cachedActorJson:
|
||||
if cachedActorJson.get('actor'):
|
||||
actorJson = cachedActorJson['actor']
|
||||
if actorJson.get('id') and \
|
||||
noOfActorSkills(actorJson) > 0 and \
|
||||
actorJson.get('name') and \
|
||||
actorJson.get('icon'):
|
||||
actor = actorJson['id']
|
||||
actor_json = cachedActorJson['actor']
|
||||
if actor_json.get('id') and \
|
||||
noOfActorSkills(actor_json) > 0 and \
|
||||
actor_json.get('name') and \
|
||||
actor_json.get('icon'):
|
||||
actor = actor_json['id']
|
||||
actorSkillsList = \
|
||||
actorJson['hasOccupation']['skills']
|
||||
actor_json['hasOccupation']['skills']
|
||||
skills = getSkillsFromList(actorSkillsList)
|
||||
for skillName, skillLevel in skills.items():
|
||||
skillName = skillName.lower()
|
||||
|
@ -534,8 +534,8 @@ def htmlSkillsSearch(actor: str,
|
|||
skillLevelStr = '0' + skillLevelStr
|
||||
indexStr = \
|
||||
skillLevelStr + ';' + actor + ';' + \
|
||||
actorJson['name'] + \
|
||||
';' + actorJson['icon']['url']
|
||||
actor_json['name'] + \
|
||||
';' + actor_json['icon']['url']
|
||||
if indexStr not in results:
|
||||
results.append(indexStr)
|
||||
break
|
||||
|
|
|
@ -170,17 +170,17 @@ def getContentWarningButton(postID: str, translate: {},
|
|||
'</div></details>\n'
|
||||
|
||||
|
||||
def _setActorPropertyUrl(actorJson: {}, propertyName: str, url: str) -> None:
|
||||
def _setActorPropertyUrl(actor_json: {}, propertyName: str, url: str) -> None:
|
||||
"""Sets a url for the given actor property
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
propertyNameLower = propertyName.lower()
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -190,7 +190,7 @@ def _setActorPropertyUrl(actorJson: {}, propertyName: str, url: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
|
||||
prefixes = getProtocolPrefixes()
|
||||
prefixFound = False
|
||||
|
@ -207,7 +207,7 @@ def _setActorPropertyUrl(actorJson: {}, propertyName: str, url: str) -> None:
|
|||
if ',' in url:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -224,13 +224,13 @@ def _setActorPropertyUrl(actorJson: {}, propertyName: str, url: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": url
|
||||
}
|
||||
actorJson['attachment'].append(newAddress)
|
||||
actor_json['attachment'].append(newAddress)
|
||||
|
||||
|
||||
def setBlogAddress(actorJson: {}, blogAddress: str) -> None:
|
||||
def setBlogAddress(actor_json: {}, blogAddress: str) -> None:
|
||||
"""Sets an blog address for the given actor
|
||||
"""
|
||||
_setActorPropertyUrl(actorJson, 'Blog', removeHtml(blogAddress))
|
||||
_setActorPropertyUrl(actor_json, 'Blog', removeHtml(blogAddress))
|
||||
|
||||
|
||||
def updateAvatarImageCache(signing_priv_key_pem: str,
|
||||
|
@ -550,13 +550,13 @@ def htmlHeaderWithExternalStyle(cssFilename: str, instanceTitle: str,
|
|||
|
||||
|
||||
def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
||||
actorJson: {}, city: str,
|
||||
actor_json: {}, city: str,
|
||||
content_license_url: str,
|
||||
lang='en') -> str:
|
||||
"""html header which includes person markup
|
||||
https://schema.org/Person
|
||||
"""
|
||||
if not actorJson:
|
||||
if not actor_json:
|
||||
htmlStr = \
|
||||
htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None, lang)
|
||||
return htmlStr
|
||||
|
@ -580,11 +580,11 @@ def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
|||
' },\n'
|
||||
|
||||
skillsMarkup = ''
|
||||
if actorJson.get('hasOccupation'):
|
||||
if isinstance(actorJson['hasOccupation'], list):
|
||||
if actor_json.get('hasOccupation'):
|
||||
if isinstance(actor_json['hasOccupation'], list):
|
||||
skillsMarkup = ' "hasOccupation": [\n'
|
||||
firstEntry = True
|
||||
for skillDict in actorJson['hasOccupation']:
|
||||
for skillDict in actor_json['hasOccupation']:
|
||||
if skillDict['@type'] == 'Role':
|
||||
if not firstEntry:
|
||||
skillsMarkup += ',\n'
|
||||
|
@ -650,19 +650,19 @@ def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
|||
firstEntry = False
|
||||
skillsMarkup += '\n ],\n'
|
||||
|
||||
description = removeHtml(actorJson['summary'])
|
||||
nameStr = removeHtml(actorJson['name'])
|
||||
domain_full = actorJson['id'].split('://')[1].split('/')[0]
|
||||
handle = actorJson['preferredUsername'] + '@' + domain_full
|
||||
description = removeHtml(actor_json['summary'])
|
||||
nameStr = removeHtml(actor_json['name'])
|
||||
domain_full = actor_json['id'].split('://')[1].split('/')[0]
|
||||
handle = actor_json['preferredUsername'] + '@' + domain_full
|
||||
|
||||
personMarkup = \
|
||||
' "about": {\n' + \
|
||||
' "@type" : "Person",\n' + \
|
||||
' "name": "' + nameStr + '",\n' + \
|
||||
' "image": "' + actorJson['icon']['url'] + '",\n' + \
|
||||
' "image": "' + actor_json['icon']['url'] + '",\n' + \
|
||||
' "description": "' + description + '",\n' + \
|
||||
cityMarkup + skillsMarkup + \
|
||||
' "url": "' + actorJson['id'] + '"\n' + \
|
||||
' "url": "' + actor_json['id'] + '"\n' + \
|
||||
' },\n'
|
||||
|
||||
profileMarkup = \
|
||||
|
@ -672,7 +672,7 @@ def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
|||
' "@type": "ProfilePage",\n' + \
|
||||
' "mainEntityOfPage": {\n' + \
|
||||
' "@type": "WebPage",\n' + \
|
||||
" \"@id\": \"" + actorJson['id'] + "\"\n" + \
|
||||
" \"@id\": \"" + actor_json['id'] + "\"\n" + \
|
||||
' },\n' + personMarkup + \
|
||||
' "accountablePerson": {\n' + \
|
||||
' "@type": "Person",\n' + \
|
||||
|
@ -683,7 +683,7 @@ def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
|||
' "name": "' + nameStr + '"\n' + \
|
||||
' },\n' + \
|
||||
' "name": "' + nameStr + '",\n' + \
|
||||
' "image": "' + actorJson['icon']['url'] + '",\n' + \
|
||||
' "image": "' + actor_json['icon']['url'] + '",\n' + \
|
||||
' "description": "' + description + '",\n' + \
|
||||
' "license": "' + content_license_url + '"\n' + \
|
||||
' }\n' + \
|
||||
|
@ -694,7 +694,7 @@ def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
|||
" <meta content=\"profile\" property=\"og:type\" />\n" + \
|
||||
" <meta content=\"" + description + \
|
||||
"\" name='description'>\n" + \
|
||||
" <meta content=\"" + actorJson['url'] + \
|
||||
" <meta content=\"" + actor_json['url'] + \
|
||||
"\" property=\"og:url\" />\n" + \
|
||||
" <meta content=\"" + domain_full + \
|
||||
"\" property=\"og:site_name\" />\n" + \
|
||||
|
@ -702,19 +702,19 @@ def htmlHeaderWithPersonMarkup(cssFilename: str, instanceTitle: str,
|
|||
")\" property=\"og:title\" />\n" + \
|
||||
" <meta content=\"" + description + \
|
||||
"\" property=\"og:description\" />\n" + \
|
||||
" <meta content=\"" + actorJson['icon']['url'] + \
|
||||
" <meta content=\"" + actor_json['icon']['url'] + \
|
||||
"\" property=\"og:image\" />\n" + \
|
||||
" <meta content=\"400\" property=\"og:image:width\" />\n" + \
|
||||
" <meta content=\"400\" property=\"og:image:height\" />\n" + \
|
||||
" <meta content=\"summary\" property=\"twitter:card\" />\n" + \
|
||||
" <meta content=\"" + handle + \
|
||||
"\" property=\"profile:username\" />\n"
|
||||
if actorJson.get('attachment'):
|
||||
if actor_json.get('attachment'):
|
||||
ogTags = (
|
||||
'email', 'openpgp', 'blog', 'xmpp', 'matrix', 'briar',
|
||||
'jami', 'cwtch', 'languages'
|
||||
)
|
||||
for attachJson in actorJson['attachment']:
|
||||
for attachJson in actor_json['attachment']:
|
||||
if not attachJson.get('name'):
|
||||
continue
|
||||
if not attachJson.get('value'):
|
||||
|
|
|
@ -100,15 +100,15 @@ def htmlWelcomeProfile(base_dir: str, nickname: str, domain: str,
|
|||
profileForm += '</center>\n'
|
||||
|
||||
actorFilename = acctDir(base_dir, nickname, domain) + '.json'
|
||||
actorJson = loadJson(actorFilename)
|
||||
displayNickname = actorJson['name']
|
||||
actor_json = loadJson(actorFilename)
|
||||
displayNickname = actor_json['name']
|
||||
profileForm += '<div class="container">\n'
|
||||
profileForm += \
|
||||
editTextField(translate['Nickname'], 'displayNickname',
|
||||
displayNickname)
|
||||
|
||||
bioStr = \
|
||||
actorJson['summary'].replace('<p>', '').replace('</p>', '')
|
||||
actor_json['summary'].replace('<p>', '').replace('</p>', '')
|
||||
if not bioStr:
|
||||
bioStr = translate['Your bio']
|
||||
profileForm += ' <label class="labels">' + \
|
||||
|
|
34
webfinger.py
34
webfinger.py
|
@ -279,12 +279,12 @@ def webfingerLookup(path: str, base_dir: str,
|
|||
return wfJson
|
||||
|
||||
|
||||
def _webfingerUpdateAvatar(wfJson: {}, actorJson: {}) -> bool:
|
||||
def _webfingerUpdateAvatar(wfJson: {}, actor_json: {}) -> bool:
|
||||
"""Updates the avatar image link
|
||||
"""
|
||||
found = False
|
||||
avatarUrl = actorJson['icon']['url']
|
||||
mediaType = actorJson['icon']['mediaType']
|
||||
avatarUrl = actor_json['icon']['url']
|
||||
mediaType = actor_json['icon']['mediaType']
|
||||
for link in wfJson['links']:
|
||||
if not link.get('rel'):
|
||||
continue
|
||||
|
@ -306,18 +306,18 @@ def _webfingerUpdateAvatar(wfJson: {}, actorJson: {}) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def _webfingerAddBlogLink(wfJson: {}, actorJson: {}) -> bool:
|
||||
def _webfingerAddBlogLink(wfJson: {}, actor_json: {}) -> bool:
|
||||
"""Adds a blog link to webfinger if needed
|
||||
"""
|
||||
found = False
|
||||
if '/users/' in actorJson['id']:
|
||||
if '/users/' in actor_json['id']:
|
||||
blogUrl = \
|
||||
actorJson['id'].split('/users/')[0] + '/blog/' + \
|
||||
actorJson['id'].split('/users/')[1]
|
||||
actor_json['id'].split('/users/')[0] + '/blog/' + \
|
||||
actor_json['id'].split('/users/')[1]
|
||||
else:
|
||||
blogUrl = \
|
||||
actorJson['id'].split('/@')[0] + '/blog/' + \
|
||||
actorJson['id'].split('/@')[1]
|
||||
actor_json['id'].split('/@')[0] + '/blog/' + \
|
||||
actor_json['id'].split('/@')[1]
|
||||
for link in wfJson['links']:
|
||||
if not link.get('rel'):
|
||||
continue
|
||||
|
@ -337,11 +337,11 @@ def _webfingerAddBlogLink(wfJson: {}, actorJson: {}) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def _webfingerUpdateFromProfile(wfJson: {}, actorJson: {}) -> bool:
|
||||
def _webfingerUpdateFromProfile(wfJson: {}, actor_json: {}) -> bool:
|
||||
"""Updates webfinger Email/blog/xmpp links from profile
|
||||
Returns true if one or more tags has been changed
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return False
|
||||
|
||||
changed = False
|
||||
|
@ -361,7 +361,7 @@ def _webfingerUpdateFromProfile(wfJson: {}, actorJson: {}) -> bool:
|
|||
for name, alias in webfingerPropertyName.items():
|
||||
aliasesNotFound.append(alias)
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
propertyName = propertyValue['name'].lower()
|
||||
|
@ -411,10 +411,10 @@ def _webfingerUpdateFromProfile(wfJson: {}, actorJson: {}) -> bool:
|
|||
wfJson['aliases'].remove(fullAlias)
|
||||
changed = True
|
||||
|
||||
if _webfingerUpdateAvatar(wfJson, actorJson):
|
||||
if _webfingerUpdateAvatar(wfJson, actor_json):
|
||||
changed = True
|
||||
|
||||
if _webfingerAddBlogLink(wfJson, actorJson):
|
||||
if _webfingerAddBlogLink(wfJson, actor_json):
|
||||
changed = True
|
||||
|
||||
return changed
|
||||
|
@ -442,10 +442,10 @@ def webfingerUpdate(base_dir: str, nickname: str, domain: str,
|
|||
return
|
||||
|
||||
actorFilename = base_dir + '/accounts/' + handle + '.json'
|
||||
actorJson = loadJson(actorFilename)
|
||||
if not actorJson:
|
||||
actor_json = loadJson(actorFilename)
|
||||
if not actor_json:
|
||||
return
|
||||
|
||||
if _webfingerUpdateFromProfile(wfJson, actorJson):
|
||||
if _webfingerUpdateFromProfile(wfJson, actor_json):
|
||||
if saveJson(wfJson, filename):
|
||||
storeWebfingerInCache(handle, wfJson, cached_webfingers)
|
||||
|
|
20
xmpp.py
20
xmpp.py
|
@ -8,12 +8,12 @@ __status__ = "Production"
|
|||
__module_group__ = "Profile Metadata"
|
||||
|
||||
|
||||
def getXmppAddress(actorJson: {}) -> str:
|
||||
def getXmppAddress(actor_json: {}) -> str:
|
||||
"""Returns xmpp address for the given actor
|
||||
"""
|
||||
if not actorJson.get('attachment'):
|
||||
if not actor_json.get('attachment'):
|
||||
return ''
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
nameLower = propertyValue['name'].lower()
|
||||
|
@ -34,7 +34,7 @@ def getXmppAddress(actorJson: {}) -> str:
|
|||
return ''
|
||||
|
||||
|
||||
def setXmppAddress(actorJson: {}, xmppAddress: str) -> None:
|
||||
def setXmppAddress(actor_json: {}, xmppAddress: str) -> None:
|
||||
"""Sets an xmpp address for the given actor
|
||||
"""
|
||||
notXmppAddress = False
|
||||
|
@ -47,12 +47,12 @@ def setXmppAddress(actorJson: {}, xmppAddress: str) -> None:
|
|||
if '<' in xmppAddress:
|
||||
notXmppAddress = True
|
||||
|
||||
if not actorJson.get('attachment'):
|
||||
actorJson['attachment'] = []
|
||||
if not actor_json.get('attachment'):
|
||||
actor_json['attachment'] = []
|
||||
|
||||
# remove any existing value
|
||||
propertyFound = None
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -63,11 +63,11 @@ def setXmppAddress(actorJson: {}, xmppAddress: str) -> None:
|
|||
propertyFound = propertyValue
|
||||
break
|
||||
if propertyFound:
|
||||
actorJson['attachment'].remove(propertyFound)
|
||||
actor_json['attachment'].remove(propertyFound)
|
||||
if notXmppAddress:
|
||||
return
|
||||
|
||||
for propertyValue in actorJson['attachment']:
|
||||
for propertyValue in actor_json['attachment']:
|
||||
if not propertyValue.get('name'):
|
||||
continue
|
||||
if not propertyValue.get('type'):
|
||||
|
@ -86,4 +86,4 @@ def setXmppAddress(actorJson: {}, xmppAddress: str) -> None:
|
|||
"type": "PropertyValue",
|
||||
"value": xmppAddress
|
||||
}
|
||||
actorJson['attachment'].append(newXmppAddress)
|
||||
actor_json['attachment'].append(newXmppAddress)
|
||||
|
|
Loading…
Reference in New Issue