Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Ditch simplejson
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Dec 25, 2014
1 parent 01e0de8 commit 907d6a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -37,7 +37,6 @@ def main():
"Paste>=1.7",
"SQLAlchemy>=0.8",
"sqlalchemy-migrate>=0.7.2.24",
"SimpleJSON>=1.7",
"parsedatetime>=0.8.6",
"ipaddr",
],
Expand All @@ -61,7 +60,7 @@ def main():
'static/jquery-ui-css/smoothness/images/*.png',
],
"synoptic.schema_ver_repo": ["migrate.cfg"],
}
}
)

if __name__ == "__main__":
Expand Down
59 changes: 22 additions & 37 deletions synoptic/__init__.py
Expand Up @@ -3,6 +3,7 @@
store_itemversion,
get_current_itemversions_join,
query_itemversions)
import json


def get_static_file(filename):
Expand Down Expand Up @@ -413,12 +414,11 @@ def http_get_tsrange(self, request):

now = time()

from simplejson import dumps
from sqlalchemy import asc, desc
base_query = request.dbsession.query(ItemVersion)
if list(base_query.limit(1)):
return request.respond(
dumps({
json.dumps({
"min":
base_query.order_by(asc(ItemVersion.timestamp))[0].timestamp,
"max":
Expand All @@ -430,7 +430,7 @@ def http_get_tsrange(self, request):
mimetype="text/plain")
else:
return request.respond(
dumps({"min": now, "max": now+1, "now": now, }),
json.dumps({"min": now, "max": now+1, "now": now, }),
mimetype="text/plain")

def get_tags_with_usecounts(self, session, model, parsed_query=None,
Expand Down Expand Up @@ -486,9 +486,8 @@ def http_get_tags(self, request):
request.dbsession, request.datamodel,
startswith=query, limit=limit)

from simplejson import dumps
return request.respond(
dumps([row.name for row in q]),
json.dumps([row.name for row in q]),
mimetype="text/plain")

def http_get_tags_for_query(self, request):
Expand All @@ -513,20 +512,17 @@ def http_get_tags_for_query(self, request):
request.dbsession, request.datamodel, parsed_query,
max_timestamp)

from simplejson import dumps

tags = [list(row) for row in result]

return request.respond(
dumps({
json.dumps({
"tags": tags,
"query_tags": query_tags,
}),
mimetype="text/plain")

def http_rename_tag(self, request):
from simplejson import loads
data = loads(request.POST["json"])
data = json.loads(request.POST["json"])

old_name = data["old_name"]
new_name = data["new_name"]
Expand Down Expand Up @@ -566,8 +562,7 @@ def http_get_item_by_id(self, request):
from paste.httpexceptions import HTTPNotFound
raise HTTPNotFound()

from simplejson import dumps
return request.respond(dumps(self.item_to_json(query.first())),
return request.respond(json.dumps(self.item_to_json(query.first())),
mimetype="text/plain")

def http_get_item_version_by_id(self, request):
Expand All @@ -580,8 +575,7 @@ def http_get_item_version_by_id(self, request):
from paste.httpexceptions import HTTPNotFound
raise HTTPNotFound()

from simplejson import dumps
return request.respond(dumps(self.item_to_json(query.first())),
return request.respond(json.dumps(self.item_to_json(query.first())),
mimetype="text/plain")

def http_get_items(self, request):
Expand Down Expand Up @@ -626,13 +620,11 @@ def http_get_items(self, request):

query_tags = []

from simplejson import dumps

# kind of silly to do two JSON encodes, but what the heck
result_hash = hash(dumps(json_items))
result_hash = hash(json.dumps(json_items))

# and ship them out by JSON
return request.respond(dumps({
return request.respond(json.dumps({
"items": json_items,
"result_hash": result_hash,
"tags": tags,
Expand All @@ -655,11 +647,10 @@ def http_get_result_hash(self, request):
request.dbsession, request.datamodel,
parsed_query, max_timestamp)

from simplejson import dumps
result_hash = hash(dumps(json_items))
result_hash = hash(json.dumps(json_items))

# and ship them out by JSON
return request.respond(dumps(result_hash),
return request.respond(json.dumps(result_hash),
mimetype="text/plain")

def http_print_items(self, request):
Expand Down Expand Up @@ -701,8 +692,7 @@ def http_get_item_history(self, request):
.order_by(ItemVersion.timestamp.desc())]
json[0]["is_current"] = True

from simplejson import dumps
return request.respond(dumps(json),
return request.respond(json.dumps(json),
mimetype="text/plain")

@staticmethod
Expand Down Expand Up @@ -739,8 +729,7 @@ def parse_datetime(data, name, rel_to_name=None, use_utc=False):
data[name] = None

def http_store_item(self, request):
from simplejson import loads, dumps
data = loads(request.POST["json"])
data = json.loads(request.POST["json"])

current_query = data.pop("current_query", None)
deleting = data["contents"] is None
Expand Down Expand Up @@ -789,12 +778,11 @@ def http_store_item(self, request):

# send response
return request.respond(
dumps(self.item_to_json(itemversion)),
json.dumps(self.item_to_json(itemversion)),
mimetype="text/plain")

def http_item_datebump(self, request):
from simplejson import loads, dumps
data = loads(request.POST["json"])
data = json.loads(request.POST["json"])

bump_interval = data["bump_interval"]
bump_direction = data["bump_direction"]
Expand Down Expand Up @@ -879,12 +867,11 @@ def increment_func(timestamp):
data[key] = increment_func(data[key])

return request.respond(
dumps(data),
json.dumps(data),
mimetype="text/plain")

def http_reorder_item(self, request):
from simplejson import loads
data = loads(request.POST["json"])
data = json.loads(request.POST["json"])

from synoptic.query import parse_query
from synoptic.datamodel import ViewOrderingHandler
Expand Down Expand Up @@ -921,9 +908,8 @@ def http_calendar_event_sources(self, request):
className=get_google_calendar_tag(entry_dict),
requireOnline=True))

from simplejson import dumps
return request.respond(
dumps(event_sources),
json.dumps(event_sources),
mimetype="text/plain")

def http_calendar_data(self, request):
Expand Down Expand Up @@ -1000,9 +986,8 @@ def http_calendar_data(self, request):
className=["calendar-now"],
))

from simplejson import dumps
return request.respond(
dumps(data),
json.dumps(data),
mimetype="text/plain")

# }}}
Expand Down Expand Up @@ -1032,8 +1017,8 @@ def http_get_all_js(self, request):
for fn in all_js_filenames)

from synoptic.datamodel import BUMP_INTERVALS
from simplejson import dumps
all_js = "var BUMP_INTERVALS = %s;\n%s" % (dumps(BUMP_INTERVALS), all_js)
all_js = "var BUMP_INTERVALS = %s;\n%s" % (
json.dumps(BUMP_INTERVALS), all_js)

return request.respond(all_js,
mimetype="text/javascript")
Expand Down

0 comments on commit 907d6a3

Please sign in to comment.