Browse Source

Less verbose

merge-requests/21/head
Bob Mottram 2 months ago
parent
commit
6dc85f69dc
10 changed files with 29 additions and 27 deletions
  1. 1
    1
      epicyon.py
  2. 2
    2
      inbox.py
  3. 2
    2
      migrate.py
  4. 3
    3
      person.py
  5. 9
    8
      posts.py
  6. 4
    4
      session.py
  7. 1
    1
      speaker.py
  8. 2
    2
      webapp_profile.py
  9. 3
    3
      webapp_utils.py
  10. 2
    1
      webfinger.py

+ 1
- 1
epicyon.py View File

@@ -731,7 +731,7 @@ if args.json:
731 731
         'Accept': 'application/ld+json; profile="' + profileStr + '"'
732 732
     }
733 733
     testJson = getJson(session, args.json, asHeader, None,
734
-                       __version__, httpPrefix, None)
734
+                       debug, __version__, httpPrefix, None)
735 735
     pprint(testJson)
736 736
     sys.exit()
737 737
 

+ 2
- 2
inbox.py View File

@@ -253,8 +253,8 @@ def getPersonPubKey(baseDir: str, session, personUrl: str,
253 253
             'Accept': 'application/activity+json; profile="' + profileStr + '"'
254 254
         }
255 255
         personJson = \
256
-            getJson(session, personUrl, asHeader, None, projectVersion,
257
-                    httpPrefix, personDomain)
256
+            getJson(session, personUrl, asHeader, None, debug,
257
+                    projectVersion, httpPrefix, personDomain)
258 258
         if not personJson:
259 259
             return None
260 260
     pubKey = None

+ 2
- 2
migrate.py View File

@@ -85,8 +85,8 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str,
85 85
         'Accept': 'application/ld+json; profile="' + profileStr + '"'
86 86
     }
87 87
     personJson = \
88
-        getJson(session, personUrl, asHeader, None, __version__,
89
-                httpPrefix, None)
88
+        getJson(session, personUrl, asHeader, None,
89
+                debug, __version__, httpPrefix, None)
90 90
     if not personJson:
91 91
         return ctr
92 92
     if not personJson.get('movedTo'):

+ 3
- 3
person.py View File

@@ -1225,8 +1225,8 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
1225 1225
         }
1226 1226
 
1227 1227
     personJson = \
1228
-        getJson(session, personUrl, asHeader, None, __version__,
1229
-                httpPrefix, None, 20, quiet)
1228
+        getJson(session, personUrl, asHeader, None,
1229
+                debug, __version__, httpPrefix, None, 20, quiet)
1230 1230
     if personJson:
1231 1231
         if not quiet:
1232 1232
             pprint(personJson)
@@ -1237,7 +1237,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
1237 1237
         }
1238 1238
         personJson = \
1239 1239
             getJson(session, personUrl, asHeader, None,
1240
-                    __version__, httpPrefix, None)
1240
+                    debug, __version__, httpPrefix, None)
1241 1241
         if not quiet:
1242 1242
             if personJson:
1243 1243
                 pprint(personJson)

+ 9
- 8
posts.py View File

@@ -183,7 +183,7 @@ def parseUserFeed(session, feedUrl: str, asHeader: {},
183 183
         return None
184 184
 
185 185
     feedJson = getJson(session, feedUrl, asHeader, None,
186
-                       projectVersion, httpPrefix, domain)
186
+                       False, projectVersion, httpPrefix, domain)
187 187
     if not feedJson:
188 188
         return None
189 189
 
@@ -220,6 +220,7 @@ def getPersonBox(baseDir: str, session, wfRequest: {},
220 220
                  nickname: str, domain: str,
221 221
                  boxName='inbox',
222 222
                  sourceId=0) -> (str, str, str, str, str, str, str, str):
223
+    debug = False
223 224
     profileStr = 'https://www.w3.org/ns/activitystreams'
224 225
     asHeader = {
225 226
         'Accept': 'application/activity+json; profile="' + profileStr + '"'
@@ -229,7 +230,7 @@ def getPersonBox(baseDir: str, session, wfRequest: {},
229 230
         return None, None, None, None, None, None, None
230 231
 
231 232
     if not wfRequest.get('errors'):
232
-        personUrl = getUserUrl(wfRequest, sourceId, False)
233
+        personUrl = getUserUrl(wfRequest, sourceId, debug)
233 234
     else:
234 235
         if nickname == 'dev':
235 236
             # try single user instance
@@ -250,13 +251,13 @@ def getPersonBox(baseDir: str, session, wfRequest: {},
250 251
                 'Accept': 'application/ld+json; profile="' + profileStr + '"'
251 252
             }
252 253
         personJson = getJson(session, personUrl, asHeader, None,
253
-                             projectVersion, httpPrefix, domain)
254
+                             debug, projectVersion, httpPrefix, domain)
254 255
         if not personJson:
255 256
             asHeader = {
256 257
                 'Accept': 'application/ld+json; profile="' + profileStr + '"'
257 258
             }
258 259
             personJson = getJson(session, personUrl, asHeader, None,
259
-                                 projectVersion, httpPrefix, domain)
260
+                                 debug, projectVersion, httpPrefix, domain)
260 261
             if not personJson:
261 262
                 print('Unable to get actor')
262 263
                 return None, None, None, None, None, None, None
@@ -3537,7 +3538,7 @@ def getPublicPostDomains(session, baseDir: str, nickname: str, domain: str,
3537 3538
 def downloadFollowCollection(followType: str,
3538 3539
                              session, httpPrefix,
3539 3540
                              actor: str, pageNumber=1,
3540
-                             noOfPages=1) -> []:
3541
+                             noOfPages=1, debug=False) -> []:
3541 3542
     """Returns a list of following/followers for the given actor
3542 3543
     by downloading the json for their following/followers collection
3543 3544
     """
@@ -3554,8 +3555,8 @@ def downloadFollowCollection(followType: str,
3554 3555
     for pageCtr in range(noOfPages):
3555 3556
         url = actor + '/' + followType + '?page=' + str(pageNumber + pageCtr)
3556 3557
         followersJson = \
3557
-            getJson(session, url, sessionHeaders, None, __version__,
3558
-                    httpPrefix, None)
3558
+            getJson(session, url, sessionHeaders, None,
3559
+                    debug, __version__, httpPrefix, None)
3559 3560
         if followersJson:
3560 3561
             if followersJson.get('orderedItems'):
3561 3562
                 for followerActor in followersJson['orderedItems']:
@@ -3913,7 +3914,7 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str,
3913 3914
                   postJsonObject['object'])
3914 3915
         announcedJson = \
3915 3916
             getJson(session, postJsonObject['object'], asHeader,
3916
-                    None, projectVersion, httpPrefix, domain)
3917
+                    None, debug, projectVersion, httpPrefix, domain)
3917 3918
 
3918 3919
         if not announcedJson:
3919 3920
             return None

+ 4
- 4
session.py View File

@@ -84,11 +84,11 @@ def urlExists(session, url: str, timeoutSec=3,
84 84
     return False
85 85
 
86 86
 
87
-def getJson(session, url: str, headers: {}, params: {},
87
+def getJson(session, url: str, headers: {}, params: {}, debug: bool,
88 88
             version='1.2.0', httpPrefix='https',
89 89
             domain='testdomain', timeoutSec=20, quiet=False) -> {}:
90 90
     if not isinstance(url, str):
91
-        if not quiet:
91
+        if debug and not quiet:
92 92
             print('url: ' + str(url))
93 93
             print('ERROR: getJson failed, url should be a string')
94 94
         return None
@@ -114,7 +114,7 @@ def getJson(session, url: str, headers: {}, params: {},
114 114
         sessionHeaders2 = sessionHeaders.copy()
115 115
         if sessionHeaders2.get('Authorization'):
116 116
             sessionHeaders2['Authorization'] = 'REDACTED'
117
-        if not quiet:
117
+        if debug and not quiet:
118 118
             print('ERROR: getJson failed\nurl: ' + str(url) + ' ' +
119 119
                   'headers: ' + str(sessionHeaders2) + ' ' +
120 120
                   'params: ' + str(sessionParams))
@@ -123,7 +123,7 @@ def getJson(session, url: str, headers: {}, params: {},
123 123
         sessionHeaders2 = sessionHeaders.copy()
124 124
         if sessionHeaders2.get('Authorization'):
125 125
             sessionHeaders2['Authorization'] = 'REDACTED'
126
-        if not quiet:
126
+        if debug and not quiet:
127 127
             print('ERROR: getJson failed\nurl: ' + str(url) + ' ' +
128 128
                   'headers: ' + str(sessionHeaders2) + ' ' +
129 129
                   'params: ' + str(sessionParams) + ' ')

+ 1
- 1
speaker.py View File

@@ -279,7 +279,7 @@ def getSpeakerFromServer(baseDir: str, session,
279 279
         domainFull + '/users/' + nickname + '/speaker'
280 280
 
281 281
     speakerJson = \
282
-        getJson(session, url, headers, None,
282
+        getJson(session, url, headers, None, debug,
283 283
                 __version__, httpPrefix, domain, 20, True)
284 284
     return speakerJson
285 285
 

+ 2
- 2
webapp_profile.py View File

@@ -156,14 +156,14 @@ def htmlProfileAfterSearch(cssCache: {},
156 156
         }
157 157
         personUrl = httpPrefix + '://' + searchDomainFull
158 158
     profileJson = \
159
-        getJson(session, personUrl, asHeader, None,
159
+        getJson(session, personUrl, asHeader, None, debug,
160 160
                 projectVersion, httpPrefix, domain)
161 161
     if not profileJson:
162 162
         asHeader = {
163 163
             'Accept': 'application/ld+json; profile="' + profileStr + '"'
164 164
         }
165 165
         profileJson = \
166
-            getJson(session, personUrl, asHeader, None,
166
+            getJson(session, personUrl, asHeader, None, debug,
167 167
                     projectVersion, httpPrefix, domain)
168 168
     if not profileJson:
169 169
         print('DEBUG: No actor returned from ' + personUrl)

+ 3
- 3
webapp_utils.py View File

@@ -441,7 +441,7 @@ def setBlogAddress(actorJson: {}, blogAddress: str) -> None:
441 441
 def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
442 442
                            actor: str, avatarUrl: str,
443 443
                            personCache: {}, allowDownloads: bool,
444
-                           force=False) -> str:
444
+                           force=False, debug=False) -> str:
445 445
     """Updates the cached avatar for the given actor
446 446
     """
447 447
     if not avatarUrl:
@@ -502,8 +502,8 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
502 502
                 'Accept': 'application/ld+json; profile="' + prof + '"'
503 503
             }
504 504
         personJson = \
505
-            getJson(session, actor, sessionHeaders, None, __version__,
506
-                    httpPrefix, None)
505
+            getJson(session, actor, sessionHeaders, None,
506
+                    debug, __version__, httpPrefix, None)
507 507
         if personJson:
508 508
             if not personJson.get('id'):
509 509
                 return None

+ 2
- 1
webfinger.py View File

@@ -74,7 +74,8 @@ def webfingerHandle(session, handle: str, httpPrefix: str,
74 74
     }
75 75
     try:
76 76
         result = \
77
-            getJson(session, url, hdr, par, projectVersion,
77
+            getJson(session, url, hdr, par,
78
+                    debug, projectVersion,
78 79
                     httpPrefix, fromDomain)
79 80
     except Exception as e:
80 81
         print(e)

Loading…
Cancel
Save