def delete(self, credentials): if credentials is None: raise BadRequest('Swift backend requires credentials in x-auth-token headers') log.debug('Deleting Swift object %s' % self.context.value) protocol, schema, host, path = parse_uri(self.context.value) uri = "%s:%s%s" % (schema, host, path) client.delete_object(uri, credentials, path)
def create(self): if self.context.value: protocol, schema, host, path = parse_uri(self.context.value) else: uri, protocol = self.make_uri(self.context) self.context.value = uri return getAdapter(self.context, IDataStore, protocol)
def save(self, datastream, encoding, credentials): if credentials is None: raise BadRequest('Swift backend requires credentials in x-auth-token headers') log.debug('Saving Swift object %s' % self.context.value) protocol, schema, host, path = parse_uri(self.context.value) uri = "%s:%s%s" % (schema, host, path) client.put_object(uri, credentials, contents=datastream) log.debug('Swift object "%s" saved' % self.context.value)
def load(self, credentials): if credentials is None: raise BadRequest('Swift backend requires credentials in x-auth-token headers') log.debug('Loading Swift object %s' % self.context.value) protocol, schema, host, path = parse_uri(self.context.value) uri = "%s:%s" % (schema, host) base_path, objname = path.split('/', 1) response, contents = client.get_object(uri, credentials, base_path, objname) return StringIO.StringIO(contents)
def save(self, datastream, encoding, credentials=None): protocol, schema, host, path = parse_uri(self.context.value) assert protocol == 'file', protocol assert path, path b = 6 * 1024 log.debug('Writing file: "%s"' % path) with open(path, 'wb') as f: d = datastream.read(b) if encoding == 'base64': d = base64.b64decode(d) f.write(d) while len(d) == b and not datastream.closed: d = datastream.read(b) f.write(d)
def delete(self, credentials=None): protocol, schema, host, path = parse_uri(self.context.value) assert protocol == 'null', protocol assert path, path
def load(self, credentials=None): protocol, schema, host, path = parse_uri(self.context.value) assert protocol == 'null', protocol assert path, path return StringIO.StringIO('')
def save(self, datastream, encoding, credentials=None): protocol, schema, host, path = parse_uri(self.context.value) assert protocol == 'null', protocol assert path, path
def delete(self, credentials=None): protocol, schema, host, path = parse_uri(self.context.value) assert protocol == 'file', protocol assert path, path log.debug('Unlinking "%s"' % path) os.unlink(path)
def load(self, credentials=None): protocol, schema, host, path = parse_uri(self.context.value) assert protocol == 'file', protocol assert path, path return open(path, 'rb')