コード例 #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))
コード例 #2
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))
コード例 #3
0
    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
コード例 #4
0
ファイル: xmlobject.py プロジェクト: grodniewicz/oship
 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)
コード例 #5
0
ファイル: evaluation.py プロジェクト: mleist/ict-ok.org
 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
コード例 #6
0
ファイル: test_adding.py プロジェクト: CGTIC/Plone_SP
 def __str__(self):
     if IContainmentRoot.providedBy(self.context):
         return ''
     name = self.context.__name__
     url = absoluteURL(getParent(self.context), self.request)
     url += '/' + name
     return url
コード例 #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))
コード例 #8
0
    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
コード例 #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
コード例 #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))
コード例 #11
0
ファイル: objectinfo.py プロジェクト: bendavis78/zope
    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)
コード例 #12
0
ファイル: evaluation.py プロジェクト: mleist/ict-ok.org
 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
コード例 #13
0
ファイル: page.py プロジェクト: sarkartanzil/schooltool
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
コード例 #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))
コード例 #15
0
ファイル: browser.py プロジェクト: jean/zope.app.apidoc
 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
コード例 #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
コード例 #17
0
ファイル: page.py プロジェクト: asley/schooltool
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
コード例 #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
コード例 #19
0
    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
コード例 #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'))
コード例 #21
0
ファイル: policy.py プロジェクト: l1ph0x/schooltool-2
    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
コード例 #22
0
ファイル: policy.py プロジェクト: achouhans/schooltool-2.8.5
    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
コード例 #23
0
ファイル: __init__.py プロジェクト: grodniewicz/oship
 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)
コード例 #24
0
ファイル: utilities.py プロジェクト: jean/zope.app.apidoc
    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
コード例 #25
0
ファイル: zcml.py プロジェクト: jean/zope.app.apidoc
 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
コード例 #26
0
ファイル: evaluation.py プロジェクト: mleist/ict-ok.org
 def evaluatee(self):
     try:
         return getParent(getParent(self))
     except TypeError:
         raise ValueError('Evaluation is not yet assigned to a evaluatee')
コード例 #27
0
ファイル: browser.py プロジェクト: jean/zope.app.apidoc
 def getNamespaceName(self):
     """Return the name of the namespace."""
     name = getParent(self.context).getFullName()
     if name == 'ALL':
         return '<i>all namespaces</i>'
     return name
コード例 #28
0
ファイル: objectinfo.py プロジェクト: bendavis78/zope
 def getParent(self):
     return getParent(self.obj)
コード例 #29
0
ファイル: evaluation.py プロジェクト: mleist/ict-ok.org
 def __repr__(self):
     try:
         parent = getParent(self)
     except TypeError:
         parent = None
     return '<%s for %r>' % (self.__class__.__name__, parent)
コード例 #30
0
ファイル: function.py プロジェクト: jean/zope.app.apidoc
 def getBaseURL(self):
     """Return the URL for the API Documentation Tool."""
     m = getUtility(IDocumentationModule, "Code")
     return absoluteURL(getParent(m), self.request)
コード例 #31
0
ファイル: zcml.py プロジェクト: jean/zope.app.apidoc
def findDocModule(obj):
    if IDocumentationModule.providedBy(obj):
        return obj
    return findDocModule(getParent(obj))
コード例 #32
0
 def testGetParent(self):
     from zope.traversing.api import getParent
     self.assertEqual(getParent(self.item), self.folder)
コード例 #33
0
 def testGetParent(self):
     from zope.traversing.api import getParent
     self.assertEqual(
         getParent(self.item),
         self.folder
         )
コード例 #34
0
 def testGetParentFromRoot(self):
     from zope.traversing.api import getParent
     self.assertEqual(getParent(self.root), None)
コード例 #35
0
ファイル: evaluation.py プロジェクト: mleist/ict-ok.org
 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
コード例 #36
0
 def parent(self):
     return getParent(self.context)
コード例 #37
0
 def getBaseURL(self):
     """Return the URL for the API Documentation Tool."""
     apidoc = findAPIDocumentationRoot(self.context)
     m = apidoc['Code']
     return absoluteURL(getParent(m), self.request)
コード例 #38
0
def findAPIDocumentationRoot(context, request=None):
    if isinstance(context, APIDocumentation):
        return context
    return findAPIDocumentationRoot(getParent(context), request)
コード例 #39
0
ファイル: class_.py プロジェクト: jean/zope.app.apidoc
 def getDoc(self):
     """Get the doc string of the class STX formatted."""
     return renderText(self.context.getDocString() or '',
                       getParent(self.context).getPath())
コード例 #40
0
ファイル: function.py プロジェクト: jean/zope.app.apidoc
 def getDocString(self):
     """Get the doc string of the function in a rendered format."""
     return renderText(self.context.getDocString() or '',
                       getParent(self.context).getPath())
コード例 #41
0
ファイル: utilities.py プロジェクト: jean/zope.app.apidoc
def findAPIDocumentationRootURL(context, request):
    if isinstance(context, APIDocumentation):
        return absoluteURL(context, request)
    else:
        return findAPIDocumentationRootURL(getParent(context), request)
コード例 #42
0
 def testGetParentFromRoot(self):
     from zope.traversing.api import getParent
     self.assertEqual(
         getParent(self.root),
         None
         )