From 041b6f0a8c4ba724792604121f5aced4fd120b44 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 14 Mar 2021 20:41:37 +0000 Subject: [PATCH] Less verbose --- migrate.py | 2 +- person.py | 2 +- posts.py | 6 +++--- webapp_profile.py | 46 +++++++++++++++++++++++++++------------------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/migrate.py b/migrate.py index 9c24dce82..383e57971 100644 --- a/migrate.py +++ b/migrate.py @@ -76,7 +76,7 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str, 'Accept': 'application/activity+json; profile="' + profileStr + '"' } if not personUrl: - personUrl = getUserUrl(wfRequest) + personUrl = getUserUrl(wfRequest, 0, debug) if not personUrl: return ctr diff --git a/person.py b/person.py index e4d3c3f01..78f82a021 100644 --- a/person.py +++ b/person.py @@ -1204,7 +1204,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool, 'Accept': 'application/activity+json; profile="' + profileStr + '"' } if not personUrl: - personUrl = getUserUrl(wfRequest) + personUrl = getUserUrl(wfRequest, 0, debug) if nickname == domain: personUrl = personUrl.replace('/users/', '/actor/') personUrl = personUrl.replace('/accounts/', '/actor/') diff --git a/posts.py b/posts.py index 5a6bac82a..1bfa0dd50 100644 --- a/posts.py +++ b/posts.py @@ -148,7 +148,7 @@ def _cleanHtml(rawHtml: str) -> str: return html.unescape(text) -def getUserUrl(wfRequest: {}, sourceId=0) -> str: +def getUserUrl(wfRequest: {}, sourceId=0, debug=False) -> str: """Gets the actor url from a webfinger request """ if not wfRequest.get('links'): @@ -166,7 +166,7 @@ def getUserUrl(wfRequest: {}, sourceId=0) -> str: if link['type'] != 'application/activity+json': continue if '/@' not in link['href']: - if not hasUsersPath(link['href']): + if debug and not hasUsersPath(link['href']): print('getUserUrl webfinger activity+json ' + 'contains single user instance actor ' + str(sourceId) + ' ' + str(link)) @@ -229,7 +229,7 @@ def getPersonBox(baseDir: str, session, wfRequest: {}, return None, None, None, None, None, None, None if not wfRequest.get('errors'): - personUrl = getUserUrl(wfRequest, sourceId) + personUrl = getUserUrl(wfRequest, sourceId, False) else: if nickname == 'dev': # try single user instance diff --git a/webapp_profile.py b/webapp_profile.py index 0a4902822..2080b438a 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -75,12 +75,14 @@ def htmlProfileAfterSearch(cssCache: {}, searchDomain, searchPort = getDomainFromActor(profileHandle) else: if '@' not in profileHandle: - print('DEBUG: no @ in ' + profileHandle) + if debug: + print('DEBUG: no @ in ' + profileHandle) return None if profileHandle.startswith('@'): profileHandle = profileHandle[1:] if '@' not in profileHandle: - print('DEBUG: no @ in ' + profileHandle) + if debug: + print('DEBUG: no @ in ' + profileHandle) return None searchNickname = profileHandle.split('@')[0] searchDomain = profileHandle.split('@')[1] @@ -91,17 +93,21 @@ def htmlProfileAfterSearch(cssCache: {}, searchPort = int(searchPortStr) searchDomain = searchDomain.split(':')[0] if searchPort: - print('DEBUG: Search for handle ' + - str(searchNickname) + '@' + str(searchDomain) + ':' + - str(searchPort)) + if debug: + print('DEBUG: Search for handle ' + + str(searchNickname) + '@' + str(searchDomain) + ':' + + str(searchPort)) else: - print('DEBUG: Search for handle ' + - str(searchNickname) + '@' + str(searchDomain)) + if debug: + print('DEBUG: Search for handle ' + + str(searchNickname) + '@' + str(searchDomain)) if not searchNickname: - print('DEBUG: No nickname found in ' + profileHandle) + if debug: + print('DEBUG: No nickname found in ' + profileHandle) return None if not searchDomain: - print('DEBUG: No domain found in ' + profileHandle) + if debug: + print('DEBUG: No domain found in ' + profileHandle) return None searchDomainFull = getFullDomain(searchDomain, searchPort) @@ -117,17 +123,19 @@ def htmlProfileAfterSearch(cssCache: {}, httpPrefix, cachedWebfingers, domain, projectVersion, debug) if not wf: - print('DEBUG: Unable to webfinger ' + - searchNickname + '@' + searchDomainFull) - print('DEBUG: cachedWebfingers ' + str(cachedWebfingers)) - print('DEBUG: httpPrefix ' + httpPrefix) - print('DEBUG: domain ' + domain) + if debug: + print('DEBUG: Unable to webfinger ' + + searchNickname + '@' + searchDomainFull) + print('DEBUG: cachedWebfingers ' + str(cachedWebfingers)) + print('DEBUG: httpPrefix ' + httpPrefix) + print('DEBUG: domain ' + domain) return None if not isinstance(wf, dict): - print('WARN: Webfinger search for ' + - searchNickname + '@' + searchDomainFull + - ' did not return a dict. ' + - str(wf)) + if debug: + print('WARN: Webfinger search for ' + + searchNickname + '@' + searchDomainFull + + ' did not return a dict. ' + + str(wf)) return None personUrl = None @@ -140,7 +148,7 @@ def htmlProfileAfterSearch(cssCache: {}, 'Accept': 'application/activity+json; profile="' + profileStr + '"' } if not personUrl: - personUrl = getUserUrl(wf) + personUrl = getUserUrl(wf, 0, debug) if not personUrl: # try single user instance asHeader = {