add dump and load methods to the json module if it isn't simplejson

This commit is contained in:
Damien Churchill 2009-08-10 09:46:57 +00:00
parent 2bece0e03d
commit 33d889aaf8
1 changed files with 9 additions and 0 deletions

View File

@ -53,6 +53,15 @@ if not hasattr(json, "dumps"):
json.dumps = json.write json.dumps = json.write
json.loads = json.read json.loads = json.read
def dump(obj, fp, **kw):
fp.write(json.dumps(obj))
def load(fp, **kw):
return json.loads(fp.read())
json.dump = dump
json.load = load
import pkg_resources import pkg_resources
import xdg, xdg.BaseDirectory import xdg, xdg.BaseDirectory