def delete(self, href, etag): fpath = self._get_filepath(href) if not os.path.isfile(fpath): raise exceptions.NotFoundError(href) actual_etag = _get_etag(fpath) if etag != actual_etag: raise exceptions.WrongEtagError(etag, actual_etag) os.remove(fpath)
def update(self, href, item, etag): if href != self._get_href(item.uid) or href not in self.items: raise exceptions.NotFoundError(href) actual_etag, _ = self.items[href] if etag != actual_etag: raise exceptions.WrongEtagError(etag, actual_etag) new_etag = _get_etag() self.items[href] = (new_etag, item) return new_etag
def update(self, href, item, etag): if href not in self.items: raise exceptions.NotFoundError(href) actual_etag, _ = self.items[href] if etag != actual_etag: raise exceptions.WrongEtagError(etag, actual_etag) new_etag = _random_string() self.items[href] = (new_etag, item) return new_etag
def get(self, href): fpath = self._get_filepath(href) try: with open(fpath, 'rb') as f: return (Item(f.read().decode(self.encoding)), _get_etag(fpath)) except IOError as e: import errno if e.errno == errno.ENOENT: raise exceptions.NotFoundError(href) else: raise
def update(self, href, item, etag): fpath = self._get_filepath(href) if href != self._get_href(item.uid): logger.warning('href != uid + fileext: href={}; uid={}' .format(href, item.uid)) if not os.path.exists(fpath): raise exceptions.NotFoundError(item.uid) actual_etag = _get_etag(fpath) if etag != actual_etag: raise exceptions.WrongEtagError(etag, actual_etag) if not isinstance(item.raw, text_type): raise TypeError('item.raw must be a unicode string.') with safe_write(fpath, 'wb') as f: f.write(item.raw.encode(self.encoding)) return f.get_etag()
def delete(self, href, etag): if not self.has(href): raise exceptions.NotFoundError(href) if etag != self.items[href][0]: raise exceptions.WrongEtagError(etag) del self.items[href]