How to use the vdirsyncer.exceptions.WrongEtagError function in vdirsyncer

To help you get started, we’ve selected a few vdirsyncer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / vdirsyncer / vdirsyncer / storage / singlefile.py View on Github external
def delete(self, href, 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)

        del self._items[href]
github pimutils / vdirsyncer / vdirsyncer / storage / singlefile.py View on Github external
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)

        self._items[href] = item, item.hash
        return item.hash
github pimutils / vdirsyncer / vdirsyncer / storage / memory.py View on Github external
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
github pimutils / vdirsyncer / vdirsyncer / storage / memory.py View on Github external
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]
github pimutils / vdirsyncer / vdirsyncer / storage / etesync.py View on Github external
def delete(self, href, etag):
        try:
            entry = self._journal.collection.get(href)
            old_item = Item(entry.content)
            if old_item.hash != etag:
                raise exceptions.WrongEtagError(etag, old_item.hash)
            entry.delete()
        except etesync.exceptions.DoesNotExist as e:
            raise exceptions.NotFoundError(e)
github pimutils / vdirsyncer / vdirsyncer / storage / filesystem.py View on Github external
def update(self, href, item, etag):
        fpath = self._get_filepath(href)
        if not os.path.exists(fpath):
            raise exceptions.NotFoundError(item.uid)
        actual_etag = get_etag_from_file(fpath)
        if etag != actual_etag:
            raise exceptions.WrongEtagError(etag, actual_etag)

        if not isinstance(item.raw, str):
            raise TypeError('item.raw must be a unicode string.')

        with atomic_write(fpath, mode='wb', overwrite=True) as f:
            f.write(item.raw.encode(self.encoding))
            etag = get_etag_from_file(f)

        if self.post_hook:
            self._run_post_hook(fpath)
        return etag
github pimutils / vdirsyncer / vdirsyncer / native.py View on Github external
def check_error(e):
    try:
        errors.check_exception(e[0])
    except errors.Error.ItemNotFound as e:
        raise exceptions.NotFoundError(e) from e
    except errors.Error.ItemAlreadyExisting as e:
        raise exceptions.AlreadyExistingError(e) from e
    except errors.Error.WrongEtag as e:
        raise exceptions.WrongEtagError(e) from e
    except errors.Error.ReadOnly as e:
        raise exceptions.ReadOnlyError(e) from e
    except errors.Error.UnsupportedVobject as e:
        raise exceptions.UnsupportedVobjectError(e) from e
    except (errors.Error.BadDiscoveryConfig,
            errors.Error.BadCollectionConfig) as e:
        raise TypeError(e) from e
    except errors.Error.MetadataValueUnsupported as e:
        raise exceptions.UnsupportedMetadataError(e) from e
github pimutils / vdirsyncer / vdirsyncer / storage / etesync.py View on Github external
def update(self, href, item, etag):
        try:
            entry = self._journal.collection.get(href)
        except etesync.exceptions.DoesNotExist as e:
            raise exceptions.NotFoundError(e)
        old_item = Item(entry.content)
        if old_item.hash != etag:
            raise exceptions.WrongEtagError(etag, old_item.hash)
        entry.content = item.raw
        entry.save()
        return item.hash