def op(url, **kw): response, content = request_and_verify(self, 200, url, "GET", **kw) feed_hash = json.loads(content) missing = Hashes.missing_fields(feed_hash, ("url", "source", "active")) if missing: self.fail("missing fields: %s" % missing)
def _op(url, **kw): response, content = request_and_verify(self, 200, url, "GET", **kw) artifact_hash = json.loads(content) missing = Hashes.missing_fields( artifact_hash, ('guid', 'source', 'content-type', 'modified', 'modified-by', 'body')) if missing: self.fail("missing artifact fields: %s" % missing)
class ArtifactsHelper: @classmethod def post(cls, request_handler, **kw): helper = RequestHelper(request_handler) request = request_handler.request username = kw.get("username", None) user = User(username) if username else users.get_current_user() json_body = request.body if not json_body: helper.error(400, "body required") return decoded_body = urllib.unquote(json_body) try: artifact_hash = json.loads(decoded_body) except json.JSONDecodeError, e: msg = "malformed json: %s" % decoded_body helper.error(400, msg) logging.info(msg) return # de-unicodes keys decoded_hash = {} for k, v in artifact_hash.iteritems(): decoded_hash[k.encode("utf-8")] = v fields = ("source", "content-type", "body") result = Hashes.fetch_fields(decoded_hash, fields) if result.missing_fields: msg = "missing fields: %s" % result.missing_fields helper.error(400, msg) logging.info(msg) return source, content_type, content_body = result.values # name of info_key is guid try: info_key, src_key, content_key = ArtifactAccessor.create(source=source, content_type=content_type, body=content_body, modified_by=user) guid = info_key.name() helper.set_status(204) location = cls.artifact_uri(request, guid) helper.header("Location", location) except DuplicateDataException, ex: helper.error(409, ex.message)
def _op(url, **kw): response, content = request_and_verify(self, 200, url, "GET", **kw) artifact_hash = json.loads(content) missing = Hashes.missing_fields(artifact_hash, ('guid', 'source', 'content-type', 'modified', 'modified-by', 'body')) if missing: self.fail("missing artifact fields: %s" % missing)
return success, tuple() decoded_body = urllib.unquote(json_body) try: field_hash = json.loads(decoded_body) except json.JSONDecodeError, e: msg = "malformed json: %s" % decoded_body helper.error(400, msg) if logger: logger.warn(msg) return success, tuple() # de-unicodes keys decoded_hash = unicode_hash(field_hash) result = Hashes.fetch_fields(decoded_hash, fields) if result.missing_fields: success = False msg = "missing fields: %s" % result.missing_fields helper.error(400, msg) if logger: logger.info(msg) else: success = True # returning a (success, values) tuple is a bit weird, # but they seem to do it in erlang a lot return success, result.values def opensearch_wrapper(results, query, total_results=0, items_per_page=0, start_index=0): """ wraps results with opensearch variables """ total_results = 0
return success, tuple() decoded_body = urllib.unquote(json_body) try: field_hash = json.loads(decoded_body) except json.JSONDecodeError, e: msg = "malformed json: %s" % decoded_body helper.error(400, msg) if logger: logger.warn(msg) return success, tuple() # de-unicodes keys decoded_hash = unicode_hash(field_hash) result = Hashes.fetch_fields(decoded_hash, fields) if result.missing_fields: success = False msg = "missing fields: %s" % result.missing_fields helper.error(400, msg) if logger: logger.info(msg) else: success = True # returning a (success, values) tuple is a bit weird, # but they seem to do it in erlang a lot return success, result.values def opensearch_wrapper(results, query,