Exemplo n.º 1
0
    def post(self, obj):
        """Take data for a new object. Return its unique identifier.

        After the data is stored, share the new object with other nodes.

        """
        _, _, ext = obj.rpartition(".")
        so = StoredObject(extension=ext)
        data = self.request.body
        so.write(data)
        self.set_status(200)
        self.write({"status": "OK", "name": u".".join([so.name, so.extension])})
Exemplo n.º 2
0
    def delete(self, obj):
        """Delete an object.

        If the delete is successful, return an OK and alert other nodes.

        """
        name, _, ext = obj.rpartition(".")
        try:
            so = StoredObject(name=name, extension=ext)
        except DoesNotExist:
            self.set_status(404)
            self.finish()
            return

        so.delete()
        self.set_status(200)
        self.write({"status": "OK"})
        self.finish()
Exemplo n.º 3
0
    def get(self, obj):
        """
        Handle a conditional GET from a browser and return an object or 404.

        If I don't know about an object, query other nodes.

        """
        name, _, ext = obj.rpartition('.')
        try:
            so = StoredObject(name=name, extension=ext)
        except DoesNotExist:
            # TODO: Ask other nodes about this object.
            self.set_status(404)
            self.finish()
            return

        data = so.read()
        mimetype = mimetypes.guess_type(obj)
        self.set_header('Expires', datetime.now() + timedelta(days=3653))
        self.set_header('X-Joshua-Node', 'my-unique-node-name')
        self.set_header('Content-type', mimetype[0])
        self.write(data)
        self.finish()