forked from indymedia/epicyon
flake8 format
parent
0a5a9d439b
commit
ba493f9e20
|
@ -7,16 +7,16 @@ __email__="bob@freedombone.net"
|
|||
__status__ = "Production"
|
||||
|
||||
import os
|
||||
import datetime
|
||||
import time
|
||||
import json
|
||||
from auth import createPassword
|
||||
from utils import getNicknameFromActor
|
||||
from utils import getDomainFromActor
|
||||
from utils import loadJson
|
||||
from utils import saveJson
|
||||
|
||||
def getOcapFilename(baseDir :str,nickname: str,domain: str,actor :str,subdir: str) -> str:
|
||||
|
||||
def getOcapFilename(baseDir: str,
|
||||
nickname: str, domain: str,
|
||||
actor: str, subdir: str) -> str:
|
||||
"""Returns the filename for a particular capability accepted or granted
|
||||
Also creates directories as needed
|
||||
"""
|
||||
|
@ -37,11 +37,15 @@ def getOcapFilename(baseDir :str,nickname: str,domain: str,actor :str,subdir: st
|
|||
if not os.path.isdir(ocDir):
|
||||
os.mkdir(ocDir)
|
||||
|
||||
ocDir=baseDir+'/accounts/'+nickname+'@'+domain+'/ocap/'+subdir
|
||||
ocDir = baseDir + '/accounts/' + \
|
||||
nickname + '@' + domain + '/ocap/' + subdir
|
||||
if not os.path.isdir(ocDir):
|
||||
os.mkdir(ocDir)
|
||||
|
||||
return baseDir+'/accounts/'+nickname+'@'+domain+'/ocap/'+subdir+'/'+actor.replace('/','#')+'.json'
|
||||
return baseDir + '/accounts/' + \
|
||||
nickname + '@' + domain + '/ocap/' + \
|
||||
subdir + '/' + actor.replace('/', '#') + '.json'
|
||||
|
||||
|
||||
def CapablePost(postJson: {}, capabilityList: [], debug: bool) -> bool:
|
||||
"""Determines whether a post arriving in the inbox
|
||||
|
@ -52,13 +56,15 @@ def CapablePost(postJson: {}, capabilityList: [], debug :bool) -> bool:
|
|||
if postJson['type'] == 'Announce':
|
||||
if 'inbox:noannounce' in capabilityList:
|
||||
if debug:
|
||||
print('DEBUG: inbox post rejected because inbox:noannounce')
|
||||
print('DEBUG: ' +
|
||||
'inbox post rejected because inbox:noannounce')
|
||||
return False
|
||||
# No likes
|
||||
if postJson['type'] == 'Like':
|
||||
if 'inbox:nolike' in capabilityList:
|
||||
if debug:
|
||||
print('DEBUG: inbox post rejected because inbox:nolike')
|
||||
print('DEBUG: ' +
|
||||
'inbox post rejected because inbox:nolike')
|
||||
return False
|
||||
if postJson['type'] == 'Create':
|
||||
if postJson.get('object'):
|
||||
|
@ -67,28 +73,34 @@ def CapablePost(postJson: {}, capabilityList: [], debug :bool) -> bool:
|
|||
if postJson['object']['inReplyTo']:
|
||||
if 'inbox:noreply' in capabilityList:
|
||||
if debug:
|
||||
print('DEBUG: inbox post rejected because inbox:noreply')
|
||||
print('DEBUG: ' +
|
||||
'inbox post rejected because ' +
|
||||
'inbox:noreply')
|
||||
return False
|
||||
# are content warnings enforced?
|
||||
if postJson['object'].get('sensitive'):
|
||||
if not postJson['object']['sensitive']:
|
||||
if 'inbox:cw' in capabilityList:
|
||||
if debug:
|
||||
print('DEBUG: inbox post rejected because inbox:cw')
|
||||
print('DEBUG: ' +
|
||||
'inbox post rejected because inbox:cw')
|
||||
return False
|
||||
# content warning must have non-zero summary
|
||||
if postJson['object'].get('summary'):
|
||||
if len(postJson['object']['summary']) < 2:
|
||||
if 'inbox:cw' in capabilityList:
|
||||
if debug:
|
||||
print('DEBUG: inbox post rejected because inbox:cw, summary missing')
|
||||
print('DEBUG: ' +
|
||||
'inbox post rejected because ' +
|
||||
'inbox:cw, summary missing')
|
||||
return False
|
||||
if 'inbox:write' in capabilityList:
|
||||
return True
|
||||
return True
|
||||
|
||||
def capabilitiesRequest(baseDir: str,httpPrefix: str,domain: str, \
|
||||
requestedActor: str, \
|
||||
|
||||
def capabilitiesRequest(baseDir: str, httpPrefix: str, domain: str,
|
||||
requestedActor: str, requestedDomain: str,
|
||||
requestedCaps=["inbox:write", "objects:read"]) -> {}:
|
||||
# This is sent to the capabilities endpoint /caps/new
|
||||
# which could be instance wide or for a particular person
|
||||
|
@ -103,9 +115,10 @@ def capabilitiesRequest(baseDir: str,httpPrefix: str,domain: str, \
|
|||
}
|
||||
return ocapRequest
|
||||
|
||||
def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
||||
nickname: str,domain: str, port: int, \
|
||||
acceptedActor: str, saveToFile: bool, \
|
||||
|
||||
def capabilitiesAccept(baseDir: str, httpPrefix: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
acceptedActor: str, saveToFile: bool,
|
||||
acceptedCaps=["inbox:write", "objects:read"]) -> {}:
|
||||
# This gets returned to capabilities requester
|
||||
# This could also be added to a follow Accept activity
|
||||
|
@ -121,7 +134,8 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
|||
fullDomain = domain + ':' + str(port)
|
||||
|
||||
# make directories to store capabilities
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,acceptedActor,'accept')
|
||||
ocapFilename = \
|
||||
getOcapFilename(baseDir, nickname, fullDomain, acceptedActor, 'accept')
|
||||
if not ocapFilename:
|
||||
return None
|
||||
ocapAccept = None
|
||||
|
@ -135,11 +149,14 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
|||
if not acceptedActorNickname:
|
||||
print('WARN: unable to find nickname in ' + acceptedActor)
|
||||
return None
|
||||
acceptedActorDomain,acceptedActorPort=getDomainFromActor(acceptedActor)
|
||||
acceptedActorDomain, acceptedActorPort = \
|
||||
getDomainFromActor(acceptedActor)
|
||||
if acceptedActorPort:
|
||||
ocapId=acceptedActorNickname+'@'+acceptedActorDomain+':'+str(acceptedActorPort)+'#'+createPassword(32)
|
||||
ocapId = acceptedActorNickname + '@' + acceptedActorDomain + \
|
||||
':' + str(acceptedActorPort) + '#'+createPassword(32)
|
||||
else:
|
||||
ocapId=acceptedActorNickname+'@'+acceptedActorDomain+'#'+createPassword(32)
|
||||
ocapId = acceptedActorNickname + '@' + acceptedActorDomain + \
|
||||
'#' + createPassword(32)
|
||||
ocapAccept = {
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"id": httpPrefix + "://" + fullDomain + "/caps/" + ocapId,
|
||||
|
@ -149,27 +166,32 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \
|
|||
"actor": httpPrefix + "://" + fullDomain
|
||||
}
|
||||
if nickname:
|
||||
ocapAccept['actor']=httpPrefix+"://"+fullDomain+'/users/'+nickname
|
||||
ocapAccept['actor'] = \
|
||||
httpPrefix + "://" + fullDomain + '/users/' + nickname
|
||||
|
||||
if saveToFile:
|
||||
saveJson(ocapAccept, ocapFilename)
|
||||
return ocapAccept
|
||||
|
||||
def capabilitiesGrantedSave(baseDir :str,nickname :str,domain :str,ocap: {}) -> bool:
|
||||
|
||||
def capabilitiesGrantedSave(baseDir: str,
|
||||
nickname: str, domain: str, ocap: {}) -> bool:
|
||||
"""A capabilities accept is received, so stor it for
|
||||
reference when sending to the actor
|
||||
"""
|
||||
if not ocap.get('actor'):
|
||||
return False
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,domain,ocap['actor'],'granted')
|
||||
ocapFilename = \
|
||||
getOcapFilename(baseDir, nickname, domain, ocap['actor'], 'granted')
|
||||
if not ocapFilename:
|
||||
return False
|
||||
saveJson(ocap, ocapFilename)
|
||||
return True
|
||||
|
||||
def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
||||
nickname: str,domain: str, port: int, \
|
||||
updateActor: str, \
|
||||
|
||||
def capabilitiesUpdate(baseDir: str, httpPrefix: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
updateActor: str,
|
||||
updateCaps: []) -> {}:
|
||||
"""Used to sends an update for a change of object capabilities
|
||||
Note that the capability id gets changed with a new random token
|
||||
|
@ -187,7 +209,8 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
|||
fullDomain = domain + ':' + str(port)
|
||||
|
||||
# Get the filename of the capability
|
||||
ocapFilename=getOcapFilename(baseDir,nickname,fullDomain,updateActor,'accept')
|
||||
ocapFilename = \
|
||||
getOcapFilename(baseDir, nickname, fullDomain, updateActor, 'accept')
|
||||
if not ocapFilename:
|
||||
return None
|
||||
|
||||
|
@ -218,9 +241,11 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
|||
return None
|
||||
updateActorDomain, updateActorPort = getDomainFromActor(updateActor)
|
||||
if updateActorPort:
|
||||
ocapId=updateActorNickname+'@'+updateActorDomain+':'+str(updateActorPort)+'#'+createPassword(32)
|
||||
ocapId = updateActorNickname + '@' + updateActorDomain + \
|
||||
':' + str(updateActorPort) + '#' + createPassword(32)
|
||||
else:
|
||||
ocapId=updateActorNickname+'@'+updateActorDomain+'#'+createPassword(32)
|
||||
ocapId = updateActorNickname + '@' + updateActorDomain + \
|
||||
'#' + createPassword(32)
|
||||
ocapJson['id'] = httpPrefix + "://" + fullDomain + "/caps/" + ocapId
|
||||
ocapUpdate['object'] = ocapJson
|
||||
|
||||
|
@ -229,10 +254,11 @@ def capabilitiesUpdate(baseDir: str,httpPrefix: str, \
|
|||
|
||||
return ocapUpdate
|
||||
|
||||
def capabilitiesReceiveUpdate(baseDir :str, \
|
||||
nickname :str,domain :str,port :int, \
|
||||
actor :str, \
|
||||
newCapabilitiesId :str, \
|
||||
|
||||
def capabilitiesReceiveUpdate(baseDir: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
actor: str,
|
||||
newCapabilitiesId: str,
|
||||
capabilityList: [], debug: bool) -> bool:
|
||||
"""An update for a capability or the given actor has arrived
|
||||
"""
|
||||
|
|
|
@ -10,7 +10,7 @@ echo "Starting static analysis"
|
|||
|
||||
for sourceFile in *.py
|
||||
do
|
||||
if [[ "$sourceFile" == 'tests.py' || "$sourceFile" == 'blurhash.py' || "$sourceFile" == 'capabilities.py' ]]; then
|
||||
if [[ "$sourceFile" == 'tests.py' || "$sourceFile" == 'blurhash.py' ]]; then
|
||||
continue
|
||||
fi
|
||||
result=$($cmd "$sourceFile")
|
||||
|
|
Loading…
Reference in New Issue