###############################################################################
##
## see: https://bugs.launchpad.net/zope2/+bug/511294
##      http://dev.plone.org/plone/ticket/9394
##
## ZCML:
##
##    <adapter
##        factory=".patches.UnauthorizedBindingTraverse"
##        name="at_base_edit_view" />
##
##############################################################################

from zope.component import adapts
from zope.interface import Interface, implements, classImplements
from zope.traversing.interfaces import ITraversable
from zope.publisher.interfaces.http import IHTTPRequest
from Shared.DC.Scripts.Bindings import UnauthorizedBinding
from AccessControl.unauthorized import Unauthorized


class IUnauthorizedBinding(Interface):
    """
    Marker interface for UnauthorizedBinding.
    """

classImplements(UnauthorizedBinding, IUnauthorizedBinding)


class UnauthorizedBindingTraverse(object):
    """
    Traversal adapter for the UnauthorizedBinding.
    """
    implements(ITraversable)
    adapts(IUnauthorizedBinding, IHTTPRequest)

    def __init__(self, context, request=None):
        self.context = context
        self.request = request

    def __getattr__(self, name, default=None):
        raise Unauthorized('Not authorized to access')