# Path: opennode/oms/model/traversal.py
# def traverse1(path):
#     """Provides a shortcut for absolute path traversals without
#     needing to pass in the root object.
# 
#     """
# 
#     # Do it here just in case; to avoid circular imports:
#     from opennode.oms.zodb import db
# 
#     oms_root = db.get_root()['oms_root']
#     objs, untraversed_path = traverse_path(oms_root, path)
#     if objs and not untraversed_path:
#         return objs[-1]
#     else:
#         return None
# 
# Path: opennode/oms/security/interaction.py
# def new_interaction(principal):
#     if not IPrincipal.providedBy(principal):
#         auth = getUtility(IAuthentication, context=None)
#         principal = auth.getPrincipal(principal)
# 
#     interaction = OmsSecurityPolicy()
#     interaction.add(SessionStub(principal))
#     return interaction
# 
# Path: opennode/oms/security/permissions.py
# class Role(ZopeRole):
#     """Oms roles act as permissions"""
# 
#     nick_to_role = {}
#     role_to_nick = {}
# 
#     def __init__(self, name, nick):
#         super(Role, self).__init__(name, name)
#         self.nick = nick
# 
#         if nick:
#             self.nick_to_role[nick] = self
#             self.role_to_nick[self.id] = nick


import logging
import transaction
from zope.authentication.interfaces import IAuthentication
from zope.component import getUtility
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from opennode.oms.model.traversal import traverse1
from opennode.oms.security.interaction import new_interaction
from opennode.oms.security.permissions import Role
from opennode.oms.zodb import db

    if obj.__transient__:
        log.warning("Transient object %s always inherits permissions from its parent", path)
        return

    if permspec in ('inherit', 'noinherit'):
        obj.inherit_permissions = (permspec == 'inherit')
        return

    auth = getUtility(IAuthentication, context=None)
    interaction = new_interaction(auth.getPrincipal('root'))
    with interaction:
        prinrole = IPrincipalRoleManager(obj)
        action_map = {'allow': prinrole.assignRoleToPrincipal,
                      'deny': prinrole.removeRoleFromPrincipal,
                      'unset': prinrole.unsetRoleForPrincipal}

        parsedspec = permspec.strip().split(':', 3)
        if len(parsedspec) < 4:
            log.error('Format error: not all fields are specified: \'%s\' on line %s', filename, lineno)
            return

        permtype, kind, principal, perms = parsedspec

        if not perms:
            log.warning('No permissions specified for object: \'%s\'; file: \'%s\' line: %s',
                        path, filename, lineno)
            return

        for perm in perms.strip().split(','):

# Path: opennode/oms/model/traversal.py
# def traverse1(path):
#     """Provides a shortcut for absolute path traversals without
#     needing to pass in the root object.
# 
#     """
# 
#     # Do it here just in case; to avoid circular imports:
#     from opennode.oms.zodb import db
# 
#     oms_root = db.get_root()['oms_root']
#     objs, untraversed_path = traverse_path(oms_root, path)
#     if objs and not untraversed_path:
#         return objs[-1]
#     else:
#         return None
# 
# Path: opennode/oms/security/interaction.py
# def new_interaction(principal):
#     if not IPrincipal.providedBy(principal):
#         auth = getUtility(IAuthentication, context=None)
#         principal = auth.getPrincipal(principal)
# 
#     interaction = OmsSecurityPolicy()
#     interaction.add(SessionStub(principal))
#     return interaction
# 
# Path: opennode/oms/security/permissions.py
# class Role(ZopeRole):
#     """Oms roles act as permissions"""
# 
#     nick_to_role = {}
#     role_to_nick = {}
# 
#     def __init__(self, name, nick):
#         super(Role, self).__init__(name, name)
#         self.nick = nick
# 
#         if nick:
#             self.nick_to_role[nick] = self
#             self.role_to_nick[self.id] = nick


# Path: opennode/oms/security/acl.py
import logging
import transaction
from zope.authentication.interfaces import IAuthentication
from zope.component import getUtility
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from opennode.oms.model.traversal import traverse1
from opennode.oms.security.interaction import new_interaction
from opennode.oms.security.permissions import Role
from opennode.oms.zodb import db


    if obj.__transient__:
        log.warning("Transient object %s always inherits permissions from its parent", path)
        return

    if permspec in ('inherit', 'noinherit'):
        obj.inherit_permissions = (permspec == 'inherit')
        return

    auth = getUtility(IAuthentication, context=None)
    interaction = new_interaction(auth.getPrincipal('root'))
    with interaction:
        prinrole = IPrincipalRoleManager(obj)
        action_map = {'allow': prinrole.assignRoleToPrincipal,
                      'deny': prinrole.removeRoleFromPrincipal,
                      'unset': prinrole.unsetRoleForPrincipal}

        parsedspec = permspec.strip().split(':', 3)
        if len(parsedspec) < 4:
            log.error('Format error: not all fields are specified: \'%s\' on line %s', filename, lineno)
            return

        permtype, kind, principal, perms = parsedspec

        if not perms:
            log.warning('No permissions specified for object: \'%s\'; file: \'%s\' line: %s',
                        path, filename, lineno)
            return

        for perm in perms.strip().split(','):

            if perm not in Role.nick_to_role: