import graveldb
PATH = '/gravel/system/api'


class Ownership(graveldb.Table('ownerships', PATH)):
    default = dict(owner=None)

    @staticmethod
    def get(kind, ident):
        assert ':' not in kind
        return Ownership('%s:%s' % (kind, ident))


def set_owner(kind, ident, owner, overwrite=False):
    ownership = Ownership.get(kind, ident)
    if not overwrite and ownership.exists:
        raise ValueError('object %r already owned' % ownership.name)
    ownership.data.owner = owner
    ownership.save()


def verify_owner(kind, ident, owner):
    ownership = Ownership.get(kind, ident)
    if owner != ownership.data.owner:
        raise PermissionDenied()


class PermissionDenied(Exception):

    def __init__(self, msg='Permission denied'):
        Exception.__init__(self, msg)

42ab1851c72f8f60ac787ce244d1b97d2b16737e
<mask token>


class Ownership(graveldb.Table('ownerships', PATH)):
    default = dict(owner=None)

    @staticmethod
    def get(kind, ident):
        assert ':' not in kind
        return Ownership('%s:%s' % (kind, ident))


<mask token>


class PermissionDenied(Exception):

    def __init__(self, msg='Permission denied'):
        Exception.__init__(self, msg)

<mask token>


class Ownership(graveldb.Table('ownerships', PATH)):
    default = dict(owner=None)

    @staticmethod
    def get(kind, ident):
        assert ':' not in kind
        return Ownership('%s:%s' % (kind, ident))


def set_owner(kind, ident, owner, overwrite=False):
    ownership = Ownership.get(kind, ident)
    if not overwrite and ownership.exists:
        raise ValueError('object %r already owned' % ownership.name)
    ownership.data.owner = owner
    ownership.save()


def verify_owner(kind, ident, owner):
    ownership = Ownership.get(kind, ident)
    if owner != ownership.data.owner:
        raise PermissionDenied()


class PermissionDenied(Exception):

    def __init__(self, msg='Permission denied'):
        Exception.__init__(self, msg)

<mask token>
PATH = '/gravel/system/api'


class Ownership(graveldb.Table('ownerships', PATH)):
    default = dict(owner=None)

    @staticmethod
    def get(kind, ident):
        assert ':' not in kind
        return Ownership('%s:%s' % (kind, ident))


def set_owner(kind, ident, owner, overwrite=False):
    ownership = Ownership.get(kind, ident)
    if not overwrite and ownership.exists:
        raise ValueError('object %r already owned' % ownership.name)
    ownership.data.owner = owner
    ownership.save()


def verify_owner(kind, ident, owner):
    ownership = Ownership.get(kind, ident)
    if owner != ownership.data.owner:
        raise PermissionDenied()


class PermissionDenied(Exception):

    def __init__(self, msg='Permission denied'):
        Exception.__init__(self, msg)

import graveldb
PATH = '/gravel/system/api'


class Ownership(graveldb.Table('ownerships', PATH)):
    default = dict(owner=None)

    @staticmethod
    def get(kind, ident):
        assert ':' not in kind
        return Ownership('%s:%s' % (kind, ident))


def set_owner(kind, ident, owner, overwrite=False):
    ownership = Ownership.get(kind, ident)
    if not overwrite and ownership.exists:
        raise ValueError('object %r already owned' % ownership.name)
    ownership.data.owner = owner
    ownership.save()


def verify_owner(kind, ident, owner):
    ownership = Ownership.get(kind, ident)
    if owner != ownership.data.owner:
        raise PermissionDenied()


class PermissionDenied(Exception):

    def __init__(self, msg='Permission denied'):
        Exception.__init__(self, msg)
