Tidy bookmark debug

main
Bob Mottram 2021-03-20 14:09:07 +00:00
parent 24f9c2e6c6
commit eabe1ea535
2 changed files with 29 additions and 45 deletions

View File

@ -519,12 +519,8 @@ def outboxBookmark(recentPostsCache: {},
""" When a bookmark request is received by the outbox from c2s """ When a bookmark request is received by the outbox from c2s
""" """
if not messageJson.get('type'): if not messageJson.get('type'):
if debug:
print('DEBUG: bookmark - no type')
return return
if not messageJson['type'] == 'Add': if messageJson['type'] != 'Add':
if debug:
print('DEBUG: not a bookmark Add')
return return
if not messageJson.get('actor'): if not messageJson.get('actor'):
if debug: if debug:
@ -588,12 +584,8 @@ def outboxUndoBookmark(recentPostsCache: {},
""" When an undo bookmark request is received by the outbox from c2s """ When an undo bookmark request is received by the outbox from c2s
""" """
if not messageJson.get('type'): if not messageJson.get('type'):
if debug:
print('DEBUG: unbookmark - no type')
return return
if not messageJson['type'] == 'Remove': if messageJson['type'] != 'Remove':
if debug:
print('DEBUG: not an unbookmark Remove')
return return
if not messageJson.get('actor'): if not messageJson.get('actor'):
if debug: if debug:

View File

@ -1083,57 +1083,53 @@ def _receiveBookmark(recentPostsCache: {},
"""Receives a bookmark activity within the POST section of HTTPServer """Receives a bookmark activity within the POST section of HTTPServer
""" """
if not messageJson.get('type'): if not messageJson.get('type'):
if debug: return False
print('DEBUG: inbox bookmark - no type') if messageJson['type'] != 'Add':
return return False
if not messageJson['type'] == 'Add':
if debug:
print('DEBUG: not a inbox bookmark Add')
return
if not messageJson.get('actor'): if not messageJson.get('actor'):
if debug: if debug:
print('DEBUG: no actor in inbox bookmark Add') print('DEBUG: no actor in inbox bookmark Add')
return return False
if not messageJson.get('object'): if not messageJson.get('object'):
if debug: if debug:
print('DEBUG: no object in inbox bookmark Add') print('DEBUG: no object in inbox bookmark Add')
return return False
if not messageJson.get('target'): if not messageJson.get('target'):
if debug: if debug:
print('DEBUG: no target in inbox bookmark Add') print('DEBUG: no target in inbox bookmark Add')
return return False
if not isinstance(messageJson['object'], str): if not isinstance(messageJson['object'], str):
if debug: if debug:
print('DEBUG: inbox bookmark Add object is not string') print('DEBUG: inbox bookmark Add object is not string')
return return False
if not isinstance(messageJson['target'], str): if not isinstance(messageJson['target'], str):
if debug: if debug:
print('DEBUG: inbox bookmark Add target is not string') print('DEBUG: inbox bookmark Add target is not string')
return return False
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname): if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
if debug: if debug:
print('DEBUG: inbox bookmark Add unexpected actor') print('DEBUG: inbox bookmark Add unexpected actor')
return return False
if not messageJson['target'].endswith(messageJson['actor'] + if not messageJson['target'].endswith(messageJson['actor'] +
'/tlbookmarks'): '/tlbookmarks'):
if debug: if debug:
print('DEBUG: inbox bookmark Add target invalid ' + print('DEBUG: inbox bookmark Add target invalid ' +
messageJson['target']) messageJson['target'])
return return False
if messageJson['object']['type'] != 'Document': if messageJson['object']['type'] != 'Document':
if debug: if debug:
print('DEBUG: inbox bookmark Add type is not Document') print('DEBUG: inbox bookmark Add type is not Document')
return return False
if not messageJson['object'].get('url'): if not messageJson['object'].get('url'):
if debug: if debug:
print('DEBUG: inbox bookmark Add missing url') print('DEBUG: inbox bookmark Add missing url')
return return False
if '/statuses/' not in messageJson['object']['url']: if '/statuses/' not in messageJson['object']['url']:
if debug: if debug:
print('DEBUG: inbox bookmark Add missing statuses un url') print('DEBUG: inbox bookmark Add missing statuses un url')
return return False
if debug: if debug:
print('DEBUG: c2s inbox bookmark Add request arrived in outbox') print('DEBUG: c2s inbox bookmark Add request arrived in outbox')
@ -1162,59 +1158,55 @@ def _receiveUndoBookmark(recentPostsCache: {},
"""Receives an undo bookmark activity within the POST section of HTTPServer """Receives an undo bookmark activity within the POST section of HTTPServer
""" """
if not messageJson.get('type'): if not messageJson.get('type'):
if debug: return False
print('DEBUG: inbox undo bookmark - no type') if messageJson['type'] != 'Remove':
return return False
if not messageJson['type'] == 'Remove':
if debug:
print('DEBUG: not a inbox undo bookmark Remove')
return
if not messageJson.get('actor'): if not messageJson.get('actor'):
if debug: if debug:
print('DEBUG: no actor in inbox undo bookmark Remove') print('DEBUG: no actor in inbox undo bookmark Remove')
return return False
if not messageJson.get('object'): if not messageJson.get('object'):
if debug: if debug:
print('DEBUG: no object in inbox undo bookmark Remove') print('DEBUG: no object in inbox undo bookmark Remove')
return return False
if not messageJson.get('target'): if not messageJson.get('target'):
if debug: if debug:
print('DEBUG: no target in inbox undo bookmark Remove') print('DEBUG: no target in inbox undo bookmark Remove')
return return False
if not isinstance(messageJson['object'], str): if not isinstance(messageJson['object'], str):
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove object is not string') print('DEBUG: inbox undo bookmark Remove object is not string')
return return False
if not isinstance(messageJson['target'], str): if not isinstance(messageJson['target'], str):
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove target is not string') print('DEBUG: inbox undo bookmark Remove target is not string')
return return False
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname): if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove unexpected actor') print('DEBUG: inbox undo bookmark Remove unexpected actor')
return return False
if not messageJson['target'].endswith(messageJson['actor'] + if not messageJson['target'].endswith(messageJson['actor'] +
'/tlbookmarks'): '/tlbookmarks'):
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove target invalid ' + print('DEBUG: inbox undo bookmark Remove target invalid ' +
messageJson['target']) messageJson['target'])
return return False
if messageJson['object']['type'] != 'Document': if messageJson['object']['type'] != 'Document':
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove type is not Document') print('DEBUG: inbox undo bookmark Remove type is not Document')
return return False
if not messageJson['object'].get('url'): if not messageJson['object'].get('url'):
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove missing url') print('DEBUG: inbox undo bookmark Remove missing url')
return return False
if '/statuses/' not in messageJson['object']['url']: if '/statuses/' not in messageJson['object']['url']:
if debug: if debug:
print('DEBUG: inbox undo bookmark Remove missing statuses un url') print('DEBUG: inbox undo bookmark Remove missing statuses un url')
return return False
if debug: if debug:
print('DEBUG: c2s inbox undo bookmark Remove ' + print('DEBUG: c2s inbox Remove bookmark ' +
'request arrived in outbox') 'request arrived in outbox')
messageUrl = removeIdEnding(messageJson['object']['url']) messageUrl = removeIdEnding(messageJson['object']['url'])