flake8 style

main
Bob Mottram 2020-04-01 19:39:27 +00:00
parent 805aef6a74
commit 2c6169fa64
1 changed files with 64 additions and 55 deletions

View File

@ -6,8 +6,6 @@ __maintainer__="Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
import time
import os
from webfinger import webfingerHandle
from auth import createBasicAuthHeader
@ -18,7 +16,8 @@ from utils import getDomainFromActor
from utils import loadJson
from utils import saveJson
def setAvailability(baseDir: str,nickname: str,domain: str, \
def setAvailability(baseDir: str, nickname: str, domain: str,
status: str) -> bool:
"""Set an availability status
"""
@ -34,6 +33,7 @@ def setAvailability(baseDir: str,nickname: str,domain: str, \
saveJson(actorJson, actorFilename)
return True
def getAvailability(baseDir: str, nickname: str, domain: str) -> str:
"""Returns the availability for a given person
"""
@ -47,7 +47,8 @@ def getAvailability(baseDir: str,nickname: str,domain: str) -> str:
return actorJson['availability']
return None
def outboxAvailability(baseDir: str,nickname: str,messageJson: {}, \
def outboxAvailability(baseDir: str, nickname: str, messageJson: {},
debug: bool) -> bool:
"""Handles receiving an availability update
"""
@ -70,12 +71,13 @@ def outboxAvailability(baseDir: str,nickname: str,messageJson: {}, \
return setAvailability(baseDir, nickname, domain, status)
def sendAvailabilityViaServer(baseDir: str,session, \
nickname: str,password: str, \
domain: str,port: int, \
httpPrefix: str, \
status: str, \
cachedWebfingers: {},personCache: {}, \
def sendAvailabilityViaServer(baseDir: str, session,
nickname: str, password: str,
domain: str, port: int,
httpPrefix: str,
status: str,
cachedWebfingers: {}, personCache: {},
debug: bool, projectVersion: str) -> {}:
"""Sets the availability for a person via c2s
"""
@ -90,7 +92,8 @@ def sendAvailabilityViaServer(baseDir: str,session, \
domainFull = domain + ':' + str(port)
toUrl = httpPrefix + '://' + domainFull + '/users/' + nickname
ccUrl=httpPrefix+'://'+domainFull+'/users/'+nickname+'/followers'
ccUrl = httpPrefix + '://' + domainFull + '/users/' + nickname + \
'/followers'
newAvailabilityJson = {
'type': 'Availability',
@ -103,8 +106,8 @@ def sendAvailabilityViaServer(baseDir: str,session, \
handle = httpPrefix + '://' + domainFull + '/@' + nickname
# lookup the inbox for the To handle
wfRequest= \
webfingerHandle(session,handle,httpPrefix,cachedWebfingers, \
wfRequest = webfingerHandle(session, handle, httpPrefix,
cachedWebfingers,
domain, projectVersion)
if not wfRequest:
if debug:
@ -114,9 +117,13 @@ def sendAvailabilityViaServer(baseDir: str,session, \
postToBox = 'outbox'
# get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName= \
getPersonBox(baseDir,session,wfRequest,personCache, \
projectVersion,httpPrefix,nickname,domain,postToBox)
(inboxUrl, pubKeyId, pubKey,
fromPersonId, sharedInbox,
capabilityAcquisition,
avatarUrl, displayName) = getPersonBox(baseDir, session, wfRequest,
personCache, projectVersion,
httpPrefix, nickname,
domain, postToBox)
if not inboxUrl:
if debug:
@ -127,15 +134,17 @@ def sendAvailabilityViaServer(baseDir: str,session, \
print('DEBUG: No actor was found for ' + handle)
return 4
authHeader=createBasicAuthHeader(Nickname,password)
authHeader = createBasicAuthHeader(nickname, password)
headers = {
'host': domain, \
'Content-type': 'application/json', \
'host': domain,
'Content-type': 'application/json',
'Authorization': authHeader
}
postResult= \
postJson(session,newAvailabilityJson,[],inboxUrl,headers,"inbox:write")
postResult = postJson(session, newAvailabilityJson, [],
inboxUrl, headers, "inbox:write")
if not postResult:
print('WARN: failed to post availability')
if debug:
print('DEBUG: c2s POST availability success')