Fix loading json files to db on Python 3.5

This commit is contained in:
shortcutme 2019-03-20 00:49:27 +01:00
parent 77530f13ee
commit 7aff97b6ff
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 7 additions and 3 deletions

View File

@ -5,12 +5,12 @@ import logging
import re
import os
import atexit
import sys
import gevent
from Debug import Debug
from .DbCursor import DbCursor
from Config import config
from util import SafeRe
from util import helper
@ -26,6 +26,7 @@ def dbCleanup():
if idle > 60 * 5 and db.close_idle:
db.close()
def dbCommitCheck():
while 1:
time.sleep(5)
@ -38,6 +39,7 @@ def dbCommitCheck():
db.need_commit = False
time.sleep(0.1)
def dbCloseAll():
for db in opened_dbs[:]:
db.close()
@ -117,7 +119,6 @@ class Db(object):
self.log.error("Commit error: %s" % err)
return False
def insertOrUpdate(self, *args, **kwargs):
if not self.conn:
self.connect()
@ -298,7 +299,10 @@ class Db(object):
data = {}
else:
if file_path.endswith("json.gz"):
data = json.load(helper.limitedGzipFile(fileobj=file))
file = helper.limitedGzipFile(fileobj=file)
if sys.version_info.major == 3 and sys.version_info.minor < 6:
data = json.loads(file.read().decode("utf8"))
else:
data = json.load(file)
except Exception as err: