flake8 format

main
Bob Mottram 2020-04-03 16:36:21 +00:00
parent 6b092d63ec
commit 128e431e9f
1 changed files with 31 additions and 27 deletions

58
like.py
View File

@ -65,7 +65,7 @@ def undoLikesCollectionEntry(recentPostsCache: {},
if likeItem.get('actor'): if likeItem.get('actor'):
if likeItem['actor'] == actor: if likeItem['actor'] == actor:
if debug: if debug:
print('DEBUG: like was removed for '+actor) print('DEBUG: like was removed for ' + actor)
postJsonObject['object']['likes']['items'].remove(likeItem) postJsonObject['object']['likes']['items'].remove(likeItem)
itemFound = True itemFound = True
break break
@ -131,12 +131,12 @@ def updateLikesCollection(recentPostsCache: {},
if not postJsonObject.get('object'): if not postJsonObject.get('object'):
if debug: if debug:
pprint(postJsonObject) pprint(postJsonObject)
print('DEBUG: post '+objectUrl+' has no object') print('DEBUG: post ' + objectUrl + ' has no object')
return return
if not isinstance(postJsonObject['object'], dict): if not isinstance(postJsonObject['object'], dict):
return return
if not objectUrl.endswith('/likes'): if not objectUrl.endswith('/likes'):
objectUrl = objectUrl+'/likes' objectUrl = objectUrl + '/likes'
if not postJsonObject['object'].get('likes'): if not postJsonObject['object'].get('likes'):
if debug: if debug:
print('DEBUG: Adding initial likes to '+objectUrl) print('DEBUG: Adding initial likes to '+objectUrl)
@ -198,7 +198,7 @@ def like(recentPostsCache: {},
newLikeJson = { newLikeJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
'type': 'Like', 'type': 'Like',
'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'actor': httpPrefix + '://' + fullDomain + '/users/' + nickname,
'object': objectUrl 'object': objectUrl
} }
if ccList: if ccList:
@ -222,10 +222,10 @@ def like(recentPostsCache: {},
if likedPostNickname: if likedPostNickname:
postFilename = locatePost(baseDir, nickname, domain, objectUrl) postFilename = locatePost(baseDir, nickname, domain, objectUrl)
if not postFilename: if not postFilename:
print('DEBUG: like baseDir: '+baseDir) print('DEBUG: like baseDir: ' + baseDir)
print('DEBUG: like nickname: '+nickname) print('DEBUG: like nickname: ' + nickname)
print('DEBUG: like domain: '+domain) print('DEBUG: like domain: ' + domain)
print('DEBUG: like objectUrl: '+objectUrl) print('DEBUG: like objectUrl: ' + objectUrl)
return None return None
updateLikesCollection(recentPostsCache, updateLikesCollection(recentPostsCache,
@ -258,10 +258,10 @@ def likePost(recentPostsCache: {},
if likePort: if likePort:
if likePort != 80 and likePort != 443: if likePort != 80 and likePort != 443:
if ':' not in likeDomain: if ':' not in likeDomain:
likeDomain = likeDomain+':'+str(likePort) likeDomain = likeDomain + ':' + str(likePort)
actorLiked = httpPrefix + '://'+likeDomain+'/users/'+likeNickname actorLiked = httpPrefix + '://' + likeDomain + '/users/' + likeNickname
objectUrl = actorLiked+'/statuses/'+str(likeStatusNumber) objectUrl = actorLiked + '/statuses/' + str(likeStatusNumber)
return like(recentPostsCache, return like(recentPostsCache,
session, baseDir, federationList, nickname, domain, port, session, baseDir, federationList, nickname, domain, port,
@ -291,7 +291,7 @@ def undolike(recentPostsCache: {},
if port: if port:
if port != 80 and port != 443: if port != 80 and port != 443:
if ':' not in domain: if ':' not in domain:
fullDomain = domain+':'+str(port) fullDomain = domain + ':' + str(port)
newUndoLikeJson = { newUndoLikeJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
@ -299,7 +299,7 @@ def undolike(recentPostsCache: {},
'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname,
'object': { 'object': {
'type': 'Like', 'type': 'Like',
'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'actor': httpPrefix + '://' + fullDomain + '/users/' + nickname,
'object': objectUrl 'object': objectUrl
} }
} }
@ -359,16 +359,18 @@ def sendLikeViaServer(baseDir: str, session,
if fromPort: if fromPort:
if fromPort != 80 and fromPort != 443: if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain: if ':' not in fromDomain:
fromDomainFull = fromDomain+':'+str(fromPort) fromDomainFull = fromDomain + ':' + str(fromPort)
actor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
newLikeJson = { newLikeJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
'type': 'Like', 'type': 'Like',
'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'actor': actor,
'object': likeUrl 'object': likeUrl
} }
handle = httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle = httpPrefix + '://' + fromDomainFull + '/@' + fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix, wfRequest = webfingerHandle(session, handle, httpPrefix,
@ -376,7 +378,7 @@ def sendLikeViaServer(baseDir: str, session,
fromDomain, projectVersion) fromDomain, projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for ' + handle)
return 1 return 1
postToBox = 'outbox' postToBox = 'outbox'
@ -392,11 +394,11 @@ def sendLikeViaServer(baseDir: str, session,
if not inboxUrl: if not inboxUrl:
if debug: if debug:
print('DEBUG: No '+postToBox+' was found for '+handle) print('DEBUG: No ' + postToBox + ' was found for ' + handle)
return 3 return 3
if not fromPersonId: if not fromPersonId:
if debug: if debug:
print('DEBUG: No actor was found for '+handle) print('DEBUG: No actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = createBasicAuthHeader(fromNickname, password)
@ -434,20 +436,22 @@ def sendUndoLikeViaServer(baseDir: str, session,
if fromPort: if fromPort:
if fromPort != 80 and fromPort != 443: if fromPort != 80 and fromPort != 443:
if ':' not in fromDomain: if ':' not in fromDomain:
fromDomainFull = fromDomain+':'+str(fromPort) fromDomainFull = fromDomain + ':' + str(fromPort)
actor = httpPrefix + '://' + fromDomainFull + '/users/' + fromNickname
newUndoLikeJson = { newUndoLikeJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
'type': 'Undo', 'type': 'Undo',
'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'actor': actor,
'object': { 'object': {
'type': 'Like', 'type': 'Like',
'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'actor': actor,
'object': likeUrl 'object': likeUrl
} }
} }
handle = httpPrefix+'://'+fromDomainFull+'/@'+fromNickname handle = httpPrefix + '://' + fromDomainFull + '/@' + fromNickname
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest = webfingerHandle(session, handle, httpPrefix, wfRequest = webfingerHandle(session, handle, httpPrefix,
@ -455,7 +459,7 @@ def sendUndoLikeViaServer(baseDir: str, session,
fromDomain, projectVersion) fromDomain, projectVersion)
if not wfRequest: if not wfRequest:
if debug: if debug:
print('DEBUG: announce webfinger failed for '+handle) print('DEBUG: announce webfinger failed for ' + handle)
return 1 return 1
postToBox = 'outbox' postToBox = 'outbox'
@ -470,11 +474,11 @@ def sendUndoLikeViaServer(baseDir: str, session,
if not inboxUrl: if not inboxUrl:
if debug: if debug:
print('DEBUG: No '+postToBox+' was found for '+handle) print('DEBUG: No ' + postToBox + ' was found for ' + handle)
return 3 return 3
if not fromPersonId: if not fromPersonId:
if debug: if debug:
print('DEBUG: No actor was found for '+handle) print('DEBUG: No actor was found for ' + handle)
return 4 return 4
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = createBasicAuthHeader(fromNickname, password)
@ -534,7 +538,7 @@ def outboxLike(recentPostsCache: {},
baseDir, postFilename, messageId, baseDir, postFilename, messageId,
messageJson['actor'], domain, debug) messageJson['actor'], domain, debug)
if debug: if debug:
print('DEBUG: post liked via c2s - '+postFilename) print('DEBUG: post liked via c2s - ' + postFilename)
def outboxUndoLike(recentPostsCache: {}, def outboxUndoLike(recentPostsCache: {},