From 54702269a31dbc3e3c8456219748250892645cc0 Mon Sep 17 00:00:00 2001 From: Myxi <86738916+m-y-x-i@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:31:13 +0530 Subject: [PATCH] Added support for indenting Added support for the `indent` parameter of `json.dump`. --- pickledb.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pickledb.py b/pickledb.py index 160b0d5..6be3d00 100644 --- a/pickledb.py +++ b/pickledb.py @@ -38,19 +38,20 @@ from threading import Thread -def load(location, auto_dump, sig=True): +def load(location, auto_dump, sig=True, indent=4): '''Return a pickledb object. location is the path to the json file.''' - return PickleDB(location, auto_dump, sig) + return PickleDB(location, auto_dump, sig, indent) class PickleDB(object): key_string_error = TypeError('Key/name must be a string!') - def __init__(self, location, auto_dump, sig): + def __init__(self, location, auto_dump, sig=True, indent=4): '''Creates a database object and loads the data from the location path. If the file does not exist it will be created on the first update. ''' + self.indent_level = indent self.load(location, auto_dump) self.dthread = None if sig: @@ -92,6 +93,7 @@ def dump(self): json.dump(self.db, open(self.loco, 'wt')) self.dthread = Thread( target=json.dump, + kwargs={"indent":self.indent_level}, args=(self.db, open(self.loco, 'wt'))) self.dthread.start() self.dthread.join() @@ -289,4 +291,3 @@ def deldb(self): self.db = {} self._autodumpdb() return True -