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