Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for indenting #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pickledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -289,4 +291,3 @@ def deldb(self):
self.db = {}
self._autodumpdb()
return True