示例#1
0
文件: worker_view.py 项目: ms705/ciel
    def default(self, id):
        safe_id = id
        if cherrypy.request.method == 'GET':
            filename = self.block_store.producer_filename(safe_id)
            response_body = serve_file(filename)
            return response_body
#            filename = self.block_store.filename(safe_id)
#            try:
#                response_body = serve_file(filename)
#                return response_body
#            except cherrypy.HTTPError as he:
#                if he.status == 404:
#                    response_body = serve_file(self.block_store.producer_filename(safe_id))
#                    return response_body
#                else:
#                    raise
                
        elif cherrypy.request.method == 'POST':
            request_body = cherrypy.request.body.read()
            new_ref = ref_from_string(request_body, safe_id)
            if self.backup_sender is not None:
                self.backup_sender.add_data(safe_id, request_body)
            #if self.task_pool is not None:
            #    self.task_pool.publish_refs({safe_id : new_ref})
            return simplejson.dumps(new_ref, cls=SWReferenceJSONEncoder)
        
        elif cherrypy.request.method == 'HEAD':
            if os.path.exists(self.block_store.filename(id)):
                return
            else:
                raise cherrypy.HTTPError(404)

        else:
            raise cherrypy.HTTPError(405)
示例#2
0
def ref_from_object(object, encoder, id):
    """Encodes an object, returning either a DataValue or ConcreteReference as appropriate"""
    cache_object(object, encoder, id)
    buffer = StringIO()
    encoders[encoder](object, buffer)
    ret = ref_from_string(buffer.getvalue(), id)
    buffer.close()
    return ret
示例#3
0
文件: worker_view.py 项目: ms705/ciel
 def index(self):
     if cherrypy.request.method == 'POST':
         id = self.block_store.allocate_new_id()
         request_body = cherrypy.request.body.read()
         new_ref = ref_from_string(request_body, id)
         if self.backup_sender is not None:
             self.backup_sender.add_data(id, request_body)
         #if self.task_pool is not None:
         #    self.task_pool.publish_refs({id : new_ref})
         return simplejson.dumps(new_ref, cls=SWReferenceJSONEncoder)
     elif cherrypy.request.method == 'GET':
         return serve_file(self.block_store.generate_block_list_file())
     else:
         raise cherrypy.HTTPError(405)