Skip to content

Commit

Permalink
Change variable 'json' --> 'json_data' to avoid conflicts (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss authored Apr 12, 2021
1 parent 12b2cbb commit b6c8555
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 46 deletions.
8 changes: 4 additions & 4 deletions infogami/infobase/_dbstore/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def __init__(self, db, schema=None, indexer=None, property_manager=None):
)
self.thing_ids = {}

def process_json(self, key, json):
def process_json(self, key, json_data):
"""Hack to allow processing of json before using. Required for OL legacy."""
return json
return json_data

def save(self, docs, timestamp, comment, ip, author, action, data=None):
docs = list(docs)
Expand Down Expand Up @@ -200,8 +200,8 @@ def _load_records(self, keys):
records = dict((r.key, r) for r in rows)
for r in records.values():
r.revision = r.latest_revision
json = r.data and self.process_json(r.key, r.data)
r.data = simplejson.loads(json)
json_data = r.data and self.process_json(r.key, r.data)
r.data = simplejson.loads(json_data)
return records

def _fill_types(self, records):
Expand Down
14 changes: 7 additions & 7 deletions infogami/infobase/_dbstore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
- put(key, data)
- delete(key)
- get_json(key) -> json
- set_json(key, json)
- get_json(key) -> json_data
- set_json(key, json_data)
- list(limit=100, offset=0) -> keys
- query(type, name, value, limit=100, offset=0) -> keys
Expand Down Expand Up @@ -85,7 +85,7 @@ def put(self, key, doc):
doc.pop("_key", None)
rev = doc.pop("_rev", None)

json = simplejson.dumps(doc)
json_data = simplejson.dumps(doc)

tx = self.db.transaction()
try:
Expand All @@ -100,13 +100,13 @@ def put(self, key, doc):
# It is important to update the id so that the newly modified
# records show up first in the results.
self.db.query(
"UPDATE store SET json=$json, id=nextval('store_id_seq') WHERE key=$key",
"UPDATE store SET json=$json_data, id=nextval('store_id_seq') WHERE key=$key",
vars=locals(),
)

id = self.get_row(key=key).id
else:
id = self.db.insert("store", key=key, json=json)
id = self.db.insert("store", key=key, json=json_data)

self.add_index(id, key, doc)

Expand All @@ -128,8 +128,8 @@ def put_many(self, docs):
key = doc['_key']
self.put(key, doc)

def put_json(self, key, json):
self.put(key, simplejson.loads(json))
def put_json(self, key, json_data):
self.put(key, simplejson.loads(json_data))

def delete(self, key, rev=None):
tx = self.db.transaction()
Expand Down
9 changes: 3 additions & 6 deletions infogami/infobase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ def unstorify(d):


class ClientException(Exception):
def __init__(self, status, msg, json=None):
def __init__(self, status, msg, json_data=None):
self.status = status
self.json = json
self.json = json_data
Exception.__init__(self, msg)

def get_data(self):
if self.json:
return json.loads(self.json)
else:
return {}
return json.loads(self.json) if self.json else {}


class NotFound(ClientException):
Expand Down
8 changes: 4 additions & 4 deletions infogami/infobase/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def create_test_store():
"""Creates a test implementation for using in doctests.
>>> store = create_test_store()
>>> json = store.get('/type/type')
>>> t = Thing.from_json(store, u'/type/type', json)
>>> json_data = store.get('/type/type')
>>> t = Thing.from_json(store, '/type/type', json_data)
>>> allow_unicode(t)
"<thing: '/type/type'>"
>>> isinstance(t.properties[0], web.utils.Storage)
Expand Down Expand Up @@ -287,10 +287,10 @@ def add_object(data):


class LazyThing:
def __init__(self, store, key, json):
def __init__(self, store, key, json_data):
self.__dict__['_key'] = key
self.__dict__['_store'] = store
self.__dict__['_json'] = json
self.__dict__['_json'] = json_data
self.__dict__['_thing'] = None

def _get(self):
Expand Down
4 changes: 2 additions & 2 deletions infogami/infobase/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def _process(self, value):
elif isinstance(value, dict):
return web.storage((k, self._process(v)) for k, v in iteritems(value))
elif isinstance(value, Reference):
json = self._store.get(value)
return Thing.from_json(self._store, text_type(value), json)
json_data = self._store.get(value)
return Thing.from_json(self._store, text_type(value), json_data)
else:
return value

Expand Down
28 changes: 14 additions & 14 deletions infogami/infobase/dbstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
logger = logging.getLogger("infobase")


def process_json(key, json):
"""Hook to process json."""
return json
def process_json(key, json_data):
"""Hook to process json data."""
return json_data


class DBSiteStore(common.SiteStore):
Expand Down Expand Up @@ -103,14 +103,14 @@ def new_key(self, type, kw):

def get(self, key, revision=None):
if self.cache is None or revision is not None:
json = self._get(key, revision)
json_data = self._get(key, revision)
else:
json = self.cache.get(key)
if json is None:
json = self._get(key, revision)
if json:
self.cache[key] = json
return process_json(key, json)
json_data = self.cache.get(key)
if json_data is None:
json_data = self._get(key, revision)
if json_data:
self.cache[key] = json_data
return process_json(key, json_data)

def _get(self, key, revision):
metadata = self.get_metadata(key)
Expand All @@ -121,8 +121,8 @@ def _get(self, key, revision):
'SELECT data FROM data WHERE thing_id=$metadata.id AND revision=$revision',
vars=locals(),
)
json = d and d[0].data or None
return json
json_data = d and d[0].data or None
return json_data

def get_many_as_dict(self, keys):
if not keys:
Expand Down Expand Up @@ -179,7 +179,7 @@ def save_many(self, docs, timestamp, comment, data, ip, author, action=None):

s = SaveImpl(self.db, self.schema, self.indexer, self.property_manager)

# Hack to allow processing of json before using. Required for OL legacy.
# Hack to allow processing of json data before using. Required for OL legacy.
s.process_json = process_json

docs = common.format_data(docs)
Expand Down Expand Up @@ -220,7 +220,7 @@ def save(

def reindex(self, keys):
s = SaveImpl(self.db, self.schema, self.indexer, self.property_manager)
# Hack to allow processing of json before using. Required for OL legacy.
# Hack to allow processing of json data before using. Required for OL legacy.
s.process_json = process_json
return s.reindex(keys)

Expand Down
8 changes: 4 additions & 4 deletions infogami/infobase/infobase.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ def get(self, key, revision=None):
withKey = get

def _get_thing(self, key, revision=None):
json = self.get(key, revision)
return json and common.Thing.from_json(self.store, key, json)
json_data = self.get(key, revision)
return json_data and common.Thing.from_json(self.store, key, json_data)

def _get_many_things(self, keys):
json = self.get_many(keys)
d = simplejson.loads(json)
json_data = self.get_many(keys)
d = simplejson.loads(json_data)
return dict(
(k, common.Thing.from_dict(self.store, k, doc)) for k, doc in d.items()
)
Expand Down
4 changes: 2 additions & 2 deletions infogami/infobase/readquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


def get_thing(store, key, revision=None):
json = key and store.get(key, revision)
return json and common.Thing.from_json(store, key, json)
json_data = key and store.get(key, revision)
return json_data and common.Thing.from_json(store, key, json_data)


def run_things_query(store, query):
Expand Down
6 changes: 3 additions & 3 deletions infogami/infobase/writequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
def get_thing(store, key, revision=None):
if isinstance(key, common.Reference):
key = text_type(key)
json = store.get(key, revision)
return json and common.Thing.from_json(store, key, json)
json_data = store.get(key, revision)
return json_data and common.Thing.from_json(store, key, json_data)


class PermissionEngine:
Expand Down Expand Up @@ -161,7 +161,7 @@ def get_type(self, key):

def get_many(self, keys):
d = self.store.get_many_as_dict(keys)
return dict((k, simplejson.loads(json)) for k, json in d.items())
return dict((k, simplejson.loads(json_data)) for k, json_data in d.items())

def process(self, key, data):
prev_data = self.get_many([key])
Expand Down

0 comments on commit b6c8555

Please sign in to comment.