예제 #1
0
 def testExpressionType(self):
     xmlconfig(StringIO(template % (
         """
         <tales:expressiontype
           name="test"
           handler="zope.browserpage.tests.test_expressiontype.Handler"
           />
         """
         )))
     self.assert_("test" in Engine.getTypes())
     self.assert_(Handler is Engine.getTypes()['test'])
예제 #2
0
 def testExpressionType(self):
     xmlconfig(StringIO(template % (
         """
         <tales:expressiontype
           name="test"
           handler="zope.browserpage.tests.test_expressiontype.Handler"
           />
         """
         )))
     self.assert_("test" in Engine.getTypes())
     self.assert_(Handler is Engine.getTypes()['test'])
예제 #3
0
 def testExpressionType(self):
     from cStringIO import StringIO
     from zope.configuration.xmlconfig import xmlconfig
     from zope.pagetemplate.engine import Engine
     xmlconfig(StringIO(template % (
         """
         <tales:expressiontype
           name="test"
           handler="zope.app.pagetemplate.tests.test_directives.Handler"
           />
         """
         )))
     self.assert_("test" in Engine.getTypes())
     self.assert_(Handler is Engine.getTypes()['test'])
    def subMenuItem(self, _context, submenu, title, description=u'',
                    action=u'', icon=None, filter=None, permission=None,
                    extra=None, order=0, item_class=None):
        filter = Engine.compile(filter) if filter is not None else None

        if permission is None:
            permission = self.permission

        if order == 0:
            order = _order_counter.get(self.for_, 1)
            _order_counter[self.for_] = order + 1

        if item_class is None:
            item_class = self.subMenuItemClass

        if not IBrowserSubMenuItem.implementedBy(item_class):
            raise ValueError("Item class (%s) must implement IBrowserSubMenuItem" % item_class)

        factory = MenuItemFactory(
            item_class,
            title=title, description=description, icon=icon, action=action,
            filter=filter, permission=permission, extra=extra, order=order,
            _for=self.for_, submenuId=submenu)
        adapter(_context, (factory,), self.menuItemType,
                (self.for_, self.layer), name=title)
예제 #5
0
def check_availability(menu_item):
    """check availability of a menu against its permission and filter"""
    available = True
    if menu_item.permission is not None:
        available = checkPermission(menu_item.permission, menu_item.context)
    if available and menu_item.filter is not None:
        try:
            available = menu_item.filter(Engine.getContext(
                context = menu_item.context,
                nothing = None,
                request = menu_item.request,
                modules = sys.modules,
                ))
        except Unauthorized:
            available = False
    return available
예제 #6
0
def check_availability(menu_item):
    """check availability of a menu against its permission and filter"""
    available = True
    if menu_item.permission is not None:
        available = checkPermission(menu_item.permission, menu_item.context)
    if available and menu_item.filter is not None:
        try:
            available = menu_item.filter(
                Engine.getContext(
                    context=menu_item.context,
                    nothing=None,
                    request=menu_item.request,
                    modules=sys.modules,
                ))
        except Unauthorized:
            available = False
    return available
예제 #7
0
    def subMenuItem(self,
                    _context,
                    submenu,
                    title,
                    description=_u(''),
                    action=_u(''),
                    icon=None,
                    filter=None,
                    permission=None,
                    extra=None,
                    order=0,
                    item_class=None):

        if filter is not None:
            filter = Engine.compile(filter)

        if permission is None:
            permission = self.permission

        if order == 0:
            order = _order_counter.get(self.for_, 1)
            _order_counter[self.for_] = order + 1

        if item_class is None:
            item_class = self.subMenuItemClass

        if not IBrowserSubMenuItem.implementedBy(item_class):
            raise ValueError(
                "Item class (%s) must implement IBrowserSubMenuItem" %
                item_class)

        factory = MenuItemFactory(item_class,
                                  title=title,
                                  description=description,
                                  icon=icon,
                                  action=action,
                                  filter=filter,
                                  permission=permission,
                                  extra=extra,
                                  order=order,
                                  _for=self.for_,
                                  submenuId=submenu)
        adapter(_context, (factory, ),
                self.menuItemType, (self.for_, self.layer),
                name=title)
예제 #8
0
    def available(self):
        # Make sure we have the permission needed to access the menu's action
        if self.permission is not None:
            # If we have an explicit permission, check that we
            # can access it.
            if not checkPermission(self.permission, self.context):
                return False

        elif self.action != _u(''):
            # Otherwise, test access by attempting access
            path = self.action
            l = self.action.find('?')
            if l >= 0:
                path = self.action[:l]

            traverser = PublicationTraverser()
            try:
                view = traverser.traverseRelativeURL(self.request,
                                                     self.context, path)
            except (Unauthorized, Forbidden, LookupError):
                return False
            else:
                # we're assuming that view pages are callable
                # this is a pretty sound assumption
                if not canAccess(view, '__call__'):
                    return False

        # Make sure that we really want to see this menu item
        if self.filter is not None:

            try:
                include = self.filter(
                    Engine.getContext(
                        context=self.context,
                        nothing=None,
                        request=self.request,
                        modules=sys.modules,
                    ))
            except Unauthorized:
                return False
            else:
                if not include:
                    return False

        return True
예제 #9
0
    def available(self):
        # Make sure we have the permission needed to access the menu's action
        if self.permission is not None:
            # If we have an explicit permission, check that we
            # can access it.
            if not checkPermission(self.permission, self.context):
                return False

        elif self.action != u'':
            # Otherwise, test access by attempting access
            path = self.action
            l = self.action.find('?')
            if l >= 0:
                path = self.action[:l]

            traverser = PublicationTraverser()
            try:
                view = traverser.traverseRelativeURL(
                    self.request, self.context, path)
            except (Unauthorized, Forbidden, LookupError):
                return False
            else:
                # we're assuming that view pages are callable
                # this is a pretty sound assumption
                if not canAccess(view, '__call__'):
                    return False # pragma: no cover

        # Make sure that we really want to see this menu item
        if self.filter is not None:

            try:
                include = self.filter(Engine.getContext(
                    context=self.context,
                    nothing=None,
                    request=self.request,
                    modules=sys.modules,
                ))
            except Unauthorized:
                return False
            else:
                if not include:
                    return False

        return True
예제 #10
0
def clear():
    Engine.__init__()
    _Engine(Engine)
    TrustedEngine.__init__()
    _TrustedEngine(TrustedEngine)
예제 #11
0
def registerType(name, handler):
    Engine.registerType(name, handler)
    TrustedEngine.registerType(name, handler)
예제 #12
0
def clear():
    Engine.__init__()
    _Engine(Engine)
    TrustedEngine.__init__()
    _TrustedEngine(TrustedEngine)
예제 #13
0
def registerType(name, handler):
    Engine.registerType(name, handler)
    TrustedEngine.registerType(name, handler)