Example #1
0
    def test_getParent_no_location_info(self):
        from zope.traversing.api import getParent
        test = self

        class Context(object):
            called = False

            def __conform__(self, iface):
                self.called = True
                test.assertEqual(iface, ILocationInfo)
                raise TypeError()

        context = Context()
        with self.assertRaisesRegex(TypeError, "Not enough context"):
            getParent(context)

        self.assertTrue(context.called)
        context.called = False

        # Now give it a parent
        context.__parent__ = self
        self.assertIs(self, getParent(context))

        self.assertTrue(context.called)
        context.called = False

        # Now if it's a root, it has no parent
        interface.alsoProvides(context, IRoot)
        self.assertIsNone(getParent(context))
    def test_getParent_no_location_info(self):
        from zope.traversing.api import getParent
        test = self
        class Context(object):
            called = False
            def __conform__(self, iface):
                self.called = True
                test.assertEqual(iface, ILocationInfo)
                raise TypeError()

        context = Context()
        with self.assertRaisesRegex(TypeError,
                                    "Not enough context"):
            getParent(context)

        self.assertTrue(context.called)
        context.called = False

        # Now give it a parent
        context.__parent__ = self
        self.assertIs(self, getParent(context))

        self.assertTrue(context.called)
        context.called = False

        # Now if it's a root, it has no parent
        interface.alsoProvides(context, IRoot)
        self.assertIsNone(getParent(context))
    def getContextHelpTopic(self):
        """Retrieve a help topic based on the context of the
        help namespace.

        If the context is a view, try to find
        a matching help topic for the view and its context.
        If no help topic is found, try to get a help topic for
        the context only.

        If the context is not a view, try to retrieve a help topic
        based on the context.

        If nothing is found, return the onlinehelp root topic
        """
        if self.topic is not None:
            return self.topic

        onlinehelp = self.context
        help_context = onlinehelp.context
        self.topic = None
        if IBrowserView.providedBy(help_context):
            # called from a view
            self.topic = getTopicFor(getParent(help_context),
                                     getName(help_context))
            if self.topic is None:
                # nothing found for view try context only
                self.topic = getTopicFor(getParent(help_context))
        else:
            # called without view
            self.topic = getTopicFor(help_context)

        if self.topic is None:
            self.topic = onlinehelp

        return self.topic
Example #4
0
 def singleBranchTree(self, root=''):
     parent = getParent(self.context)
     while parent is not None:
             if IReadContainer.providedBy(parent):
                 view = queryMultiAdapter(
                     (parent, self.request), name='singleBranchTree.xml')
                 return view()
             else:
                 parent = getParent(parent)
Example #5
0
 def getEvaluationsOfEvaluator(self, evaluator):
     """See interfaces.IEvaluations"""
     result = [(name, ev) for name, ev in self.items()
               if ev.evaluator == evaluator]
     result = Evaluations(result)
     location.locate(result, getParent(self), getName(self))
     return result
Example #6
0
 def __str__(self):
     if IContainmentRoot.providedBy(self.context):
         return ''
     name = self.context.__name__
     url = absoluteURL(getParent(self.context), self.request)
     url += '/' + name
     return url
Example #7
0
    def render(self):
        parent = getParent(self.context)
        name = self.context.__name__
        del parent[name]

        self.flash((u'The photo %s has been deleted' % name))
        return self.redirect(self.url(parent))
    def getMethods(self):
        # remove the security proxy, so that `attr` is not proxied. We could
        # unproxy `attr` for each turn, but that would be less efficient.
        #
        # `getPermissionIds()` also expects the class's security checker not
        # to be proxied.
        klass = zope.security.proxy.removeSecurityProxy(self.klassView.context)
        obj = zope.security.proxy.removeSecurityProxy(self.context)

        for name in apidoc.utilities.getPublicAttributes(obj):
            val = getattr(obj, name)
            if not (inspect.ismethod(val) or inspect.ismethoddescriptor(val)):
                continue

            signature = apidoc.utilities.getFunctionSignature(val)

            entry = {
                'name': name,
                'signature': signature,
                'doc': apidoc.utilities.renderText(
                    val.__doc__ or '',
                    getParent(self.klassView.context).getPath()),
                'interface': apidoc.utilities.getInterfaceForAttribute(
                    name, klass._Class__all_ifaces)}

            entry.update(apidoc.utilities.getPermissionIds(
                name, klass.getSecurityChecker()))

            yield entry
Example #9
0
 def __str__(self):
     if IContainmentRoot.providedBy(self.context):
         return ''
     name = self.context.__name__
     url = absoluteURL(getParent(self.context), self.request)
     url += '/' + name
     return url
Example #10
0
    def render(self):
        parent = getParent(self.context)
        name = self.context.__name__
        del parent[name]

        self.flash((u"The sponsor %s has been deleted" % name))
        return self.redirect(self.url(parent))
Example #11
0
    def getParent(self):
        """Get the parent of the wrapped object.

        This might result in a `TypeError` if the wrapped object is
        not locatable in sense of ILocation, i.e. if it doesn't
        provide ``__parent__`` attribute.
        """
        return getParent(self.obj)
Example #12
0
 def getEvaluationsForRequirement(self, req, recurse=True):
     """See interfaces.IEvaluations"""
     requirements = getRequirementList(req, recurse)
     result = [(name, ev) for name, ev in self.items()
               if ev.requirement in requirements]
     result = Evaluations(result)
     location.locate(result, getParent(self), getName(self))
     return result
Example #13
0
def getParentActiveViewletName(context, request, view, manager):
    parent = getParent(context)
    if parent is None:
        return None
    name = queryMultiAdapter((parent, request, view, manager),
                             interfaces.IActiveViewletName,
                             name='',
                             default=None)
    return name
Example #14
0
 def getMenuLink(self, node):
     """Return the HTML link of the node that is displayed in the menu."""
     obj = node.context
     apidoc_url = findAPIDocumentationRootURL(self.context, self.request)
     if isinstance(obj, Utility):
         iface = getParent(obj)
         return '%s/Utility/%s/%s/index.html' % (apidoc_url, getName(iface), getName(obj))
     if isinstance(obj, UtilityInterface):
         return '%s/Interface/%s/index.html' % (apidoc_url, getName(obj))
Example #15
0
 def getMenuLink(self, node):
     """Return the HTML link of the node that is displayed in the menu."""
     obj = node.context
     if isinstance(obj, Directive):
         ns = getParent(obj)
         apidoc_url = findAPIDocumentationRootURL(self.context, self.request)
         return '%s/ZCML/%s/%s/index.html' % (
             apidoc_url, getName(ns), getName(obj))
     return None
Example #16
0
def getParentTitleContent(context, request, view):
    parent = getParent(context)
    if parent is None:
        return None
    providers = queryMultiAdapter((parent, request, view),
                                  flourish.interfaces.IContentProviders)
    if providers is None:
        return None
    content = providers.get("title")
    return content
Example #17
0
def getParentActiveViewletName(context, request, view, manager):
    parent = getParent(context)
    if parent is None:
        return None
    name = queryMultiAdapter(
        (parent, request, view, manager),
        interfaces.IActiveViewletName,
        name='',
        default=None)
    return name
Example #18
0
def getParentTitleContent(context, request, view):
    parent = getParent(context)
    if parent is None:
        return None
    providers = queryMultiAdapter(
        (parent, request, view),
        flourish.interfaces.IContentProviders)
    if providers is None:
        return None
    content = providers.get("title")
    return content
    def matches(self, obj):
        """Decide whether the object is shown in the tree."""
        matches = False
        if interfaces.IPreferenceCategory.providedBy(obj):
            # IPreferenceGroup objects dynamically implement
            # IPreferenceCategory
            matches = True
        elif interfaces.IPreferenceGroup.providedBy(obj):
            parent = getParent(obj)
            matches = interfaces.IPreferenceCategory.providedBy(parent)

        return matches
Example #20
0
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        changes = self.applyChanges(data)
        if changes:
            self.status = self.successMessage
        else:
            self.status = self.noChangesMessage

        parent = getParent(self.context)
        self.redirect(self.url(parent, 'admin'))
Example #21
0
    def checkByAdaptation(self, permission, obj):
        crowd = queryAdapter(obj, ICrowd, name=permission, default=None)
        # If there is no crowd that has the given permission on this
        # object, try to look up a crowd that includes the parent.
        while crowd is None and obj is not None:
            obj = getParent(obj)
            crowd = queryAdapter(obj, ICrowd, name=permission, default=None)
        if crowd is None:  # no crowds found
            raise AssertionError('no crowd found for', obj, permission)

        for participation in self.participations:
            if crowd.contains(participation.principal):
                return True
        else:
            return False
Example #22
0
    def checkByAdaptation(self, permission, obj):
        crowd = queryAdapter(obj, ICrowd, name=permission, default=None)
        # If there is no crowd that has the given permission on this
        # object, try to look up a crowd that includes the parent.
        while crowd is None and obj is not None:
            obj = getParent(obj)
            crowd = queryAdapter(obj, ICrowd, name=permission, default=None)
        if crowd is None: # no crowds found
            raise AssertionError('no crowd found for', obj, permission)

        for participation in self.participations:
            if crowd.contains(participation.principal):
                return True
        else:
            return False
Example #23
0
 def __init__(self, context):
     self.context = context
     try:
         parent = getParent(self.context)
     except TypeError:
         parent = None
     if parent is not None:
         try:
             pp = getPath(parent)
         except TypeError:
             pp = ""
         if not pp.endswith("/"):
             pp += "/"
         self.pp = pp # parentpath
     else:
         self.pp = ""
     self.pplen = len(self.pp)
Example #24
0
    def __call__(self):
        """Create breadcrumbs for a module or an object in a module or package.

        We cannot reuse the system's bread crumbs, since they go all the
        way up to the root, but we just want to go to the root module.
        """
        obj = self.context
        crumbs = []
        while not IDocumentationModule.providedBy(obj):
            crumbs.append(
                {'name': getName(obj),
                 'url': absoluteURL(obj, self.request)}
                )
            obj = getParent(obj)

        crumbs.append(
            {'name': _('[top]'),
             'url': absoluteURL(obj, self.request)}
            )
        crumbs.reverse()
        return crumbs
Example #25
0
 def url(self):
     directive = removeSecurityProxy(self.context)
     subDirective = None
     # Sub-directives are not directly documented, so use parent
     parent = getParent(directive)
     if not (IRootDirective.providedBy(parent) or
             IRootDirective.providedBy(directive)):
         subDirective = directive
         directive = parent
     ns, name = directive.name
     # Sometimes ns is `None`, especially in the slug files, where no
     # namespaces are used.
     ns = quoteNS(ns or 'ALL')
     zcml = getUtility(IDocumentationModule, 'ZCML')
     if name not in zcml[ns]:
         ns = 'ALL'
     link = '%s/ZCML/%s/%s/index.html' % (
         findAPIDocumentationRootURL(self.context, self.request), ns, name)
     if subDirective:
         link += '#' + subDirective.name[1]
     return link
Example #26
0
 def evaluatee(self):
     try:
         return getParent(getParent(self))
     except TypeError:
         raise ValueError('Evaluation is not yet assigned to a evaluatee')
Example #27
0
 def getNamespaceName(self):
     """Return the name of the namespace."""
     name = getParent(self.context).getFullName()
     if name == 'ALL':
         return '<i>all namespaces</i>'
     return name
Example #28
0
 def getParent(self):
     return getParent(self.obj)
Example #29
0
 def __repr__(self):
     try:
         parent = getParent(self)
     except TypeError:
         parent = None
     return '<%s for %r>' % (self.__class__.__name__, parent)
Example #30
0
 def getBaseURL(self):
     """Return the URL for the API Documentation Tool."""
     m = getUtility(IDocumentationModule, "Code")
     return absoluteURL(getParent(m), self.request)
Example #31
0
def findDocModule(obj):
    if IDocumentationModule.providedBy(obj):
        return obj
    return findDocModule(getParent(obj))
Example #32
0
 def testGetParent(self):
     from zope.traversing.api import getParent
     self.assertEqual(getParent(self.item), self.folder)
 def testGetParent(self):
     from zope.traversing.api import getParent
     self.assertEqual(
         getParent(self.item),
         self.folder
         )
Example #34
0
 def testGetParentFromRoot(self):
     from zope.traversing.api import getParent
     self.assertEqual(getParent(self.root), None)
Example #35
0
 def __call__(self, *args, **kwargs):
     """See interfaces.IEvaluationsQuery"""
     result = Evaluations(self._query(*args, **kwargs))
     location.locate(result, getParent(self.context), getName(self.context))
     return result
 def parent(self):
     return getParent(self.context)
 def getBaseURL(self):
     """Return the URL for the API Documentation Tool."""
     apidoc = findAPIDocumentationRoot(self.context)
     m = apidoc['Code']
     return absoluteURL(getParent(m), self.request)
def findAPIDocumentationRoot(context, request=None):
    if isinstance(context, APIDocumentation):
        return context
    return findAPIDocumentationRoot(getParent(context), request)
Example #39
0
 def getDoc(self):
     """Get the doc string of the class STX formatted."""
     return renderText(self.context.getDocString() or '',
                       getParent(self.context).getPath())
Example #40
0
 def getDocString(self):
     """Get the doc string of the function in a rendered format."""
     return renderText(self.context.getDocString() or '',
                       getParent(self.context).getPath())
Example #41
0
def findAPIDocumentationRootURL(context, request):
    if isinstance(context, APIDocumentation):
        return absoluteURL(context, request)
    else:
        return findAPIDocumentationRootURL(getParent(context), request)
 def testGetParentFromRoot(self):
     from zope.traversing.api import getParent
     self.assertEqual(
         getParent(self.root),
         None
         )