Created
August 2, 2012 23:14
-
-
Save douglascamata/3241776 to your computer and use it in GitHub Desktop.
My code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@defer.inlineCallbacks | |
@cyclone.web.asynchronous | |
def put(self): | |
self.set_header('Content-Type', 'application/json') | |
key = str(uuid4()) | |
today = datetime.today().strftime(u'%d/%m/%y %H:%M') | |
user = self._get_current_user()[0] | |
value = self._load_request_as_json().get('value') | |
if not value: | |
log.msg("PUT failed!") | |
log.msg("Request didn't have a value to store.") | |
raise cyclone.web.HTTPError(400, 'Malformed request.') | |
data_dict = {u'data':value, u'date':today, u'from_user': user} | |
json_dict = dumps(data_dict) | |
del data_dict | |
# self.settings.db is created by txredisapi.lazyShardedConnectionPool(address_list) | |
# where address_list is something like ['192.168.0.154:6973', '192.168.0.105:6973', '127.0.0.1:6973'] | |
result = yield self.settings.db.set(key, json_dict) | |
checksum = self._calculate_sha1_checksum(json_dict) | |
del json_dict | |
log.msg("Value stored at key %s." % key) | |
self.finish(cyclone.escape.json_encode({u'key':key, u'checksum':checksum})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment