Remove excess references to commentjson

merge-requests/30/head
Bob Mottram 2019-11-23 10:08:00 +00:00
parent a8c72965f5
commit 9de4fc04c1
25 changed files with 50 additions and 111 deletions

View File

@ -7,7 +7,6 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import commentjson
from capabilities import capabilitiesAccept from capabilities import capabilitiesAccept
from capabilities import capabilitiesGrantedSave from capabilities import capabilitiesGrantedSave
from utils import getStatusNumber from utils import getStatusNumber

View File

@ -9,7 +9,6 @@ __status__ = "Production"
import os import os
import time import time
import json import json
import commentjson
from pprint import pprint from pprint import pprint
from utils import getStatusNumber from utils import getStatusNumber
from utils import createOutboxDir from utils import createOutboxDir

View File

@ -8,7 +8,6 @@ __status__ = "Production"
import json import json
import time import time
import commentjson
import os import os
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader

View File

@ -9,7 +9,6 @@ __status__ = "Production"
import os import os
import json import json
import time import time
import commentjson
from pprint import pprint from pprint import pprint
from utils import urlPermitted from utils import urlPermitted
from utils import getNicknameFromActor from utils import getNicknameFromActor

View File

@ -9,7 +9,6 @@ __status__ = "Production"
import os import os
import time import time
import datetime import datetime
import commentjson
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson

View File

@ -10,7 +10,6 @@ import os
import datetime import datetime
import time import time
import json import json
import commentjson
from auth import createPassword from auth import createPassword
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor

View File

@ -9,7 +9,6 @@ __status__ = "Production"
import os import os
import time import time
import json import json
import commentjson
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson

View File

@ -8,9 +8,9 @@ __status__ = "Production"
import os import os
import time import time
import commentjson
import email.parser import email.parser
from shutil import copyfile from shutil import copyfile
from utils import loadJson
def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str: def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
"""Uses the tags to replace :emoji: with html image markup """Uses the tags to replace :emoji: with html image markup
@ -341,21 +341,7 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
# will be retained even if default_emoji.json is subsequently updated # will be retained even if default_emoji.json is subsequently updated
if not os.path.isfile(baseDir+'/emoji/emoji.json'): if not os.path.isfile(baseDir+'/emoji/emoji.json'):
copyfile(baseDir+'/emoji/default_emoji.json',baseDir+'/emoji/emoji.json') copyfile(baseDir+'/emoji/default_emoji.json',baseDir+'/emoji/emoji.json')
emojiDictCtr=0 emojiDict=loadJson(baseDir+'/emoji/emoji.json')
while not emojiDict and emojiDictCtr<5:
if emojiDictCtr>0:
print('Retry emoji load '+baseDir+'/emoji/emoji.json')
try:
with open(baseDir+'/emoji/emoji.json', 'r') as fp:
emojiDict=commentjson.load(fp)
if emojiDictCtr>0:
print('emojiDict loaded on try '+str(emojiDictCtr))
break
except:
print('WARN: commentjson exception addHtmlTags')
print('Failed to load emoji (try '+str(emojiDictCtr)+'): '+baseDir+'/emoji/emoji.json')
time.sleep(1)
emojiDictCtr+=1
#print('TAG: looking up emoji for :'+wordStr2+':') #print('TAG: looking up emoji for :'+wordStr2+':')
addEmoji(baseDir,':'+wordStr2+':',httpPrefix,originalDomain,replaceEmoji,hashtags,emojiDict) addEmoji(baseDir,':'+wordStr2+':',httpPrefix,originalDomain,replaceEmoji,hashtags,emojiDict)

View File

@ -8,7 +8,6 @@ __status__ = "Production"
from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer from http.server import BaseHTTPRequestHandler,ThreadingHTTPServer
#import socketserver #import socketserver
import commentjson
import json import json
import time import time
import base64 import base64
@ -817,12 +816,6 @@ class PubServer(BaseHTTPRequestHandler):
timeDiff=int((time.time()-beginSaveTime)*1000) timeDiff=int((time.time()-beginSaveTime)*1000)
if timeDiff>200: if timeDiff>200:
print('SLOW: slow save of inbox queue item '+queueFilename+' took '+str(timeDiff)+' mS') print('SLOW: slow save of inbox queue item '+queueFilename+' took '+str(timeDiff)+' mS')
try:
with open(queueFilename, 'r') as fp:
queueJson=commentjson.load(fp)
print('SLOW: '+str(queueJson))
except:
pass
self.send_response(201) self.send_response(201)
self.end_headers() self.end_headers()
self.server.POSTbusy=False self.server.POSTbusy=False

View File

@ -8,7 +8,6 @@ __status__ = "Production"
import os import os
import json import json
import commentjson
from utils import getStatusNumber from utils import getStatusNumber
from utils import createOutboxDir from utils import createOutboxDir
from utils import urlPermitted from utils import urlPermitted

View File

@ -8,7 +8,6 @@ __status__ = "Production"
import json import json
import time import time
import commentjson
from pprint import pprint from pprint import pprint
import os import os
import sys import sys

View File

@ -11,7 +11,6 @@ import os
import datetime import datetime
import time import time
import json import json
import commentjson
from shutil import copyfile from shutil import copyfile
from utils import urlPermitted from utils import urlPermitted
from utils import createInboxQueueDir from utils import createInboxQueueDir
@ -1867,11 +1866,6 @@ def runInboxQueue(projectVersion: str, \
'accounts': {} 'accounts': {}
} }
# keep track of the number of queue item read failures
# so that if a file is corrupt then it will eventually
# be ignored rather than endlessly retried
itemReadFailed=0
heartBeatCtr=0 heartBeatCtr=0
queueRestoreCtr=0 queueRestoreCtr=0
@ -1912,24 +1906,19 @@ def runInboxQueue(projectVersion: str, \
print('Loading queue item '+queueFilename) print('Loading queue item '+queueFilename)
# Load the queue json # Load the queue json
try: queueJson=loadJson(queueFilename,1)
with open(queueFilename, 'r') as fp: if not queueJson:
queueJson=commentjson.load(fp) print('WARN: runInboxQueue failed to load inbox queue item '+queueFilename)
except: # Assume that the file is probably corrupt/unreadable
itemReadFailed+=1 if len(queue)>0:
print('WARN: commentjson exception runInboxQueue') queue.pop(0)
print('WARN: Failed to load inbox queue item '+queueFilename+' (try '+str(itemReadFailed)+')') # delete the queue file
if itemReadFailed>4: if os.path.isfile(queueFilename):
# After a few tries we can assume that the file try:
# is probably corrupt/unreadable
if len(queue)>0:
queue.pop(0)
itemReadFailed=0
# delete the queue file
if os.path.isfile(queueFilename):
os.remove(queueFilename) os.remove(queueFilename)
except:
pass
continue continue
itemReadFailed=0
# clear the daily quotas for maximum numbers of received posts # clear the daily quotas for maximum numbers of received posts
if currTime-quotasLastUpdate>60*60*24: if currTime-quotasLastUpdate>60*60*24:

View File

@ -9,7 +9,6 @@ __status__ = "Production"
import os import os
import json import json
import time import time
import commentjson
from pprint import pprint from pprint import pprint
from utils import urlPermitted from utils import urlPermitted
from utils import getNicknameFromActor from utils import getNicknameFromActor

View File

@ -8,7 +8,6 @@ __status__ = "Production"
import os import os
import json import json
import commentjson
import time import time
from follow import followedAccountAccepts from follow import followedAccountAccepts
from follow import followedAccountRejects from follow import followedAccountRejects

View File

@ -12,7 +12,6 @@ import numpy
import os import os
import sys import sys
import json import json
import commentjson
import datetime import datetime
from auth import createPassword from auth import createPassword
from shutil import copyfile from shutil import copyfile

View File

@ -8,7 +8,7 @@ __status__ = "Production"
import os import os
import json import json
import commentjson from utils import loadJson
from utils import noOfAccounts from utils import noOfAccounts
from utils import noOfActiveAccountsMonthly from utils import noOfActiveAccountsMonthly
@ -50,14 +50,9 @@ def metaDataInstance(instanceTitle: str, \
if not os.path.isfile(adminActorFilename): if not os.path.isfile(adminActorFilename):
return {} return {}
adminActor=None adminActor=loadJson(adminActorFilename,0)
try:
with open(adminActorFilename, 'r') as fp:
adminActor=commentjson.load(fp)
except:
print('WARN: commentjson exception metaDataInstance')
if not adminActor: if not adminActor:
print('WARN: json load exception metaDataInstance')
return {} return {}
isBot=False isBot=False

View File

@ -8,7 +8,6 @@ __status__ = "Production"
import json import json
import time import time
import commentjson
import os import os
import fileinput import fileinput
import subprocess import subprocess

View File

@ -8,7 +8,6 @@ __status__ = "Production"
import requests import requests
import json import json
import commentjson
import html import html
import datetime import datetime
import os import os
@ -2001,11 +2000,9 @@ def createSharedInboxIndex(baseDir: str,sharedBoxDir: str, \
sharedInboxFilename=os.path.join(sharedBoxDir, postFilename) sharedInboxFilename=os.path.join(sharedBoxDir, postFilename)
# get the actor from the shared post # get the actor from the shared post
try: postJsonObject=loadJson(sharedInboxFilename,0)
with open(sharedInboxFilename, 'r') as fp: if not postJsonObject:
postJsonObject=commentjson.load(fp) print('WARN: json load exception createSharedInboxIndex')
except:
print('WARN: commentjson exception createSharedInboxIndex')
continue continue
actorNickname=getNicknameFromActor(postJsonObject['actor']) actorNickname=getNicknameFromActor(postJsonObject['actor'])
@ -2035,15 +2032,10 @@ def createSharedInboxIndex(baseDir: str,sharedBoxDir: str, \
continue continue
# read the capabilities id # read the capabilities id
loadedOcap=False ocapJson=loadJson(ocapFilename,0)
try: if not ocapJson:
with open(ocapFilename, 'r') as fp: print('WARN: json load exception createSharedInboxIndex')
ocapJson=commentjson.load(fp) else:
loadedOcap=True
except:
print('WARN: commentjson exception createSharedInboxIndex')
if loadedOcap:
if ocapJson.get('id'): if ocapJson.get('id'):
if ocapJson['id'] in capsList: if ocapJson['id'] in capsList:
postsInBoxDict[statusNumber]=sharedInboxFilename postsInBoxDict[statusNumber]=sharedInboxFilename

View File

@ -7,7 +7,6 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import commentjson
import os import os
import time import time
from webfinger import webfingerHandle from webfinger import webfingerHandle

View File

@ -7,7 +7,6 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import commentjson
import os import os
import time import time
from shutil import copyfile from shutil import copyfile

View File

@ -7,7 +7,6 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import json import json
import commentjson
import os import os
import time import time
from webfinger import webfingerHandle from webfinger import webfingerHandle

View File

@ -10,7 +10,6 @@ import base64
import time import time
import os, os.path import os, os.path
import shutil import shutil
import commentjson
import json import json
from time import gmtime, strftime from time import gmtime, strftime
from pprint import pprint from pprint import pprint
@ -41,6 +40,8 @@ from utils import followPerson
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import copytree from utils import copytree
from utils import loadJson
from utils import saveJson
from utils import getStatusNumber from utils import getStatusNumber
from follow import followerOfPerson from follow import followerOfPerson
from follow import unfollowPerson from follow import unfollowPerson
@ -439,9 +440,8 @@ def testPostMessageBetweenServers():
for name in os.listdir(inboxPath): for name in os.listdir(inboxPath):
filename=os.path.join(inboxPath, name) filename=os.path.join(inboxPath, name)
assert os.path.isfile(filename) assert os.path.isfile(filename)
receivedJson=None receivedJson=loadJson(filename,0)
with open(filename, 'r') as fp: if receivedJson:
receivedJson=commentjson.load(fp)
pprint(receivedJson['object']['content']) pprint(receivedJson['object']['content'])
assert receivedJson assert receivedJson
assert 'Why is a mouse when it spins?' in receivedJson['object']['content'] assert 'Why is a mouse when it spins?' in receivedJson['object']['content']
@ -480,8 +480,8 @@ def testPostMessageBetweenServers():
break break
time.sleep(1) time.sleep(1)
with open(outboxPostFilename, 'r') as fp: alicePostJson=loadJson(outboxPostFilename,0)
alicePostJson=commentjson.load(fp) if alicePostJson:
pprint(alicePostJson) pprint(alicePostJson)
assert 'likes' in open(outboxPostFilename).read() assert 'likes' in open(outboxPostFilename).read()
@ -638,8 +638,8 @@ def testFollowBetweenServersWithCapabilities():
break break
time.sleep(1) time.sleep(1)
with open(bobCapsFilename, 'r') as fp: bobCapsJson=loadJson(bobCapsFilename,0)
bobCapsJson=commentjson.load(fp) if bobCapsJson:
if not bobCapsJson.get('capability'): if not bobCapsJson.get('capability'):
print("Unexpected format for Bob's capabilities") print("Unexpected format for Bob's capabilities")
pprint(bobCapsJson) pprint(bobCapsJson)
@ -725,14 +725,16 @@ def testFollowBetweenServersWithCapabilities():
bobPersonCache={} bobPersonCache={}
bobCachedWebfingers={} bobCachedWebfingers={}
print("Bob's capabilities for Alice:") print("Bob's capabilities for Alice:")
with open(bobCapsFilename, 'r') as fp: bobCapsJson=loadJson(bobCapsFilename,0)
bobCapsJson=commentjson.load(fp) if bobCapsJson:
pprint(bobCapsJson) pprint(bobCapsJson)
assert bobCapsJson.get('capability')
assert "inbox:noreply" not in bobCapsJson['capability'] assert "inbox:noreply" not in bobCapsJson['capability']
print("Alice's capabilities granted by Bob") print("Alice's capabilities granted by Bob")
with open(aliceCapsFilename, 'r') as fp: aliceCapsJson=loadJson(aliceCapsFilename,0)
aliceCapsJson=commentjson.load(fp) if aliceCapsJson:
pprint(aliceCapsJson) pprint(aliceCapsJson)
assert aliceCapsJson.get('capability')
assert "inbox:noreply" not in aliceCapsJson['capability'] assert "inbox:noreply" not in aliceCapsJson['capability']
newCapabilities=["inbox:write","objects:read","inbox:noreply"] newCapabilities=["inbox:write","objects:read","inbox:noreply"]
sendCapabilitiesUpdate(sessionBob,bobDir,httpPrefix, \ sendCapabilitiesUpdate(sessionBob,bobDir,httpPrefix, \
@ -748,8 +750,9 @@ def testFollowBetweenServersWithCapabilities():
bobNewCapsJson=None bobNewCapsJson=None
for i in range(20): for i in range(20):
time.sleep(1) time.sleep(1)
with open(bobCapsFilename, 'r') as fp: bobNewCapsJson=loadJson(bobCapsFilename,0)
bobNewCapsJson=commentjson.load(fp) if bobNewCapsJson:
assert bobNewCapsJson.get('capability')
if "inbox:noreply" in bobNewCapsJson['capability']: if "inbox:noreply" in bobNewCapsJson['capability']:
print("Bob's capabilities were changed") print("Bob's capabilities were changed")
pprint(bobNewCapsJson) pprint(bobNewCapsJson)
@ -762,8 +765,9 @@ def testFollowBetweenServersWithCapabilities():
aliceNewCapsJson=None aliceNewCapsJson=None
for i in range(20): for i in range(20):
time.sleep(1) time.sleep(1)
with open(aliceCapsFilename, 'r') as fp: aliceNewCapsJson=loadJson(aliceCapsFilename,0)
aliceNewCapsJson=commentjson.load(fp) if aliceNewCapsJson:
assert aliceNewCapsJson.get('capability')
if "inbox:noreply" in aliceNewCapsJson['capability']: if "inbox:noreply" in aliceNewCapsJson['capability']:
print("Alice's granted capabilities were changed") print("Alice's granted capabilities were changed")
pprint(aliceNewCapsJson) pprint(aliceNewCapsJson)
@ -1367,8 +1371,8 @@ def testClientToServer():
if '#statuses#' in name: if '#statuses#' in name:
statusNumber=int(name.split('#statuses#')[1].replace('.json','').replace('#activity','')) statusNumber=int(name.split('#statuses#')[1].replace('.json','').replace('#activity',''))
outboxPostFilename=outboxPath+'/'+name outboxPostFilename=outboxPath+'/'+name
with open(outboxPostFilename, 'r') as fp: postJsonObject=loadJson(outboxPostFilename,0)
postJsonObject=commentjson.load(fp) if postJsonObject:
outboxPostId=postJsonObject['id'].replace('/activity','') outboxPostId=postJsonObject['id'].replace('/activity','')
assert outboxPostId assert outboxPostId
print('message id obtained: '+outboxPostId) print('message id obtained: '+outboxPostId)
@ -1620,11 +1624,8 @@ def testCommentJson() -> None:
testJson={ testJson={
"content": messageStr "content": messageStr
} }
with open(filename, 'w') as fp: assert saveJson(testJson,filename)
commentjson.dump(testJson, fp, indent=2, sort_keys=False) receivedJson=loadJson(filename,0)
receivedJson=None
with open(filename, 'r') as fp:
receivedJson=commentjson.load(fp)
assert receivedJson assert receivedJson
assert receivedJson['content']==messageStr assert receivedJson['content']==messageStr
encodedStr=json.dumps(testJson, ensure_ascii=False) encodedStr=json.dumps(testJson, ensure_ascii=False)

View File

@ -27,7 +27,7 @@ def saveJson(jsonObject: {},filename: str) -> bool:
tries+=1 tries+=1
return False return False
def loadJson(filename: str) -> {}: def loadJson(filename: str,delaySec=2) -> {}:
"""Makes a few attempts to load a json formatted file """Makes a few attempts to load a json formatted file
""" """
jsonObject=None jsonObject=None
@ -39,7 +39,8 @@ def loadJson(filename: str) -> {}:
break break
except: except:
print('WARN: loadJson exception') print('WARN: loadJson exception')
time.sleep(2) if delaySec>0:
time.sleep(delaySec)
tries+=1 tries+=1
return jsonObject return jsonObject

View File

@ -11,7 +11,6 @@ from Crypto.PublicKey import RSA
from Crypto.Util import number from Crypto.Util import number
import requests import requests
import json import json
import commentjson
import os import os
import time import time
from session import getJson from session import getJson

View File

@ -9,7 +9,6 @@ __status__ = "Production"
import json import json
import time import time
import os import os
import commentjson
from collections import OrderedDict from collections import OrderedDict
from datetime import datetime from datetime import datetime
from datetime import date from datetime import date