• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python traversal.resource_path_tuple函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.traversal.resource_path_tuple函数的典型用法代码示例。如果您正苦于以下问题:Python resource_path_tuple函数的具体用法?Python resource_path_tuple怎么用?Python resource_path_tuple使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了resource_path_tuple函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _get_mailto

def _get_mailto(context, peopledir):
    mailinglist = context.get("mailinglist")
    if mailinglist is not None:
        pd_path = resource_path_tuple(peopledir)
        report_path = resource_path_tuple(context)
        mail_name = "+".join(report_path[len(pd_path) :])
        system_email_domain = get_setting(context, "system_email_domain")
        system_list_subdomain = get_setting(context, "system_list_subdomain", system_email_domain)
        return "mailto:%[email protected]%s" % (mailinglist.short_address, system_list_subdomain)
开发者ID:hathawsh,项目名称:karl,代码行数:9,代码来源:peopledirectory.py


示例2: object_will_be_added

def object_will_be_added(event):
    """ Objects added to folders must always have an __objectid__.  This must
     be an :class:`substanced.event.ObjectWillBeAdded` event subscriber
     so that a resulting object will have an __objectid__ within the (more
     convenient) :class:`substanced.event.ObjectAdded` fired later."""
    obj = event.object
    parent = event.parent
    objectmap = find_service(parent, 'objectmap')
    if objectmap is None:
        return
    if getattr(obj, '__parent__', None):
        raise ValueError(
            'obj %s added to folder %s already has a __parent__ attribute, '
            'please remove it completely from its existing parent (%s) before '
            'trying to readd it to this one' % (obj, parent, obj.__parent__)
            )
    basepath = resource_path_tuple(event.parent)
    name = event.name
    for node in postorder(obj):
        node_path = node_path_tuple(node)
        path_tuple = basepath + (name,) + node_path[1:]
        # the below gives node an objectid; if the will-be-added event is
        # the result of a duplication, replace the oid of the node with a new
        # one
        objectmap.add(node, path_tuple, replace_oid=event.duplicating)
开发者ID:tseaver,项目名称:substanced,代码行数:25,代码来源:__init__.py


示例3: _get_path_tuple

 def _get_path_tuple(self, obj_objectid_or_path_tuple):
     path_tuple = None
     if hasattr(obj_objectid_or_path_tuple, '__parent__'):
         path_tuple = resource_path_tuple(obj_objectid_or_path_tuple)
     elif isinstance(obj_objectid_or_path_tuple, INT_TYPES):
         path_tuple = self.objectid_to_path.get(obj_objectid_or_path_tuple)
     elif isinstance(obj_objectid_or_path_tuple, tuple):
         path_tuple = obj_objectid_or_path_tuple
     return path_tuple
开发者ID:Pylons,项目名称:substanced,代码行数:9,代码来源:__init__.py


示例4: add

    def add(self, name, other, send_events=True, reserved_names=(), duplicating=False, moving=False, registry=None):
        """ Same as ``__setitem__``.

        If ``send_events`` is False, suppress the sending of folder events.
        Don't allow names in the ``reserved_names`` sequence to be
        added. If ``duplicating`` is True, oids will be replaced in
        objectmap.

        This method returns the name used to place the subobject in the
        folder (a derivation of ``name``, usually the result of
        ``self.check_name(name)``).
        """
        if registry is None:
            registry = get_current_registry()

        name = self.check_name(name, reserved_names)

        if getattr(other, "__parent__", None):
            raise ValueError(
                "obj %s added to folder %s already has a __parent__ attribute, "
                "please remove it completely from its existing parent (%s) "
                "before trying to readd it to this one" % (other, self, self.__parent__)
            )

        objectmap = find_objectmap(self)

        if objectmap is not None:

            basepath = resource_path_tuple(self)

            for node in postorder(other):
                node_path = node_path_tuple(node)
                path_tuple = basepath + (name,) + node_path[1:]
                # the below gives node an objectid; if the will-be-added event
                # is the result of a duplication, replace the oid of the node
                # with a new one
                objectmap.add(node, path_tuple, replace_oid=duplicating)

        if send_events:
            event = ObjectWillBeAdded(other, self, name, duplicating=duplicating, moving=moving)
            self._notify(event, registry)

        other.__parent__ = self
        other.__name__ = name

        self.data[name] = other
        self._num_objects.change(1)

        if self._order is not None:
            self._order += (name,)

        if send_events:
            event = ObjectAdded(other, self, name, duplicating=duplicating, moving=moving)
            self._notify(event, registry)

        return name
开发者ID:reebalazs,项目名称:substanced,代码行数:56,代码来源:__init__.py


示例5: _get_path_tuple

 def _get_path_tuple(self, obj_or_path_tuple):
     if hasattr(obj_or_path_tuple, '__parent__'):
         path_tuple = resource_path_tuple(obj_or_path_tuple)
     elif isinstance(obj_or_path_tuple, tuple):
         path_tuple = obj_or_path_tuple
     else:
         raise ValueError(
             'must provide a traversable object or a '
             'path tuple, got %s' % (obj_or_path_tuple,))
     return path_tuple
开发者ID:dhavlik,项目名称:substanced,代码行数:10,代码来源:__init__.py


示例6: objectid_for

 def objectid_for(self, obj_or_path_tuple):
     """ Returns an objectid or ``None``, given an object or a path tuple"""
     if isinstance(obj_or_path_tuple, tuple):
         path_tuple = obj_or_path_tuple
     elif hasattr(obj_or_path_tuple, '__parent__'):
         path_tuple = resource_path_tuple(obj_or_path_tuple)
     else:
         raise ValueError(
             'objectid_for accepts a traversable object or a path tuple, '
             'got %s' % (obj_or_path_tuple,))
     return self.path_to_objectid.get(path_tuple)
开发者ID:dhavlik,项目名称:substanced,代码行数:11,代码来源:__init__.py


示例7: _parse_path

 def _parse_path(self, obj_or_path):
     path_tuple = obj_or_path
     if hasattr(obj_or_path, '__parent__'):
         path_tuple = resource_path_tuple(obj_or_path)
     elif isinstance(obj_or_path, basestring):
         tmp = filter(None, url_unquote_text(obj_or_path).split(u'/'))
         path_tuple = (u'',) + tuple(tmp)
     elif not isinstance(obj_or_path, tuple):
         raise ValueError(
             'Must be object, path string, or tuple, not %s' % (
                 obj_or_path,))
     return path_tuple
开发者ID:ericrasmussen,项目名称:substanced,代码行数:12,代码来源:indexes.py


示例8: _parse_path

 def _parse_path(self, obj_or_path):
     depth = self.depth
     include_origin = self.include_origin
     path_tuple = obj_or_path
     if hasattr(obj_or_path, '__parent__'):
         path_tuple = resource_path_tuple(obj_or_path)
     elif isinstance(obj_or_path, STRING_TYPES):
         path_tuple, depth, include_origin = self._parse_path_str(
             obj_or_path)
     elif not isinstance(obj_or_path, tuple):
         raise ValueError(
             'Must be object, path string, or tuple, not %s' % (
                 obj_or_path,))
     return path_tuple, depth, include_origin
开发者ID:Web5design,项目名称:substanced,代码行数:14,代码来源:indexes.py


示例9: create_dummy_resources

def create_dummy_resources(parent=None, count=1):
    """Create dummy resources and add it to the parent objectmap."""
    from pyramid.traversal import resource_path_tuple
    resources = ()
    for x in range(count):
        resource = testing.DummyResource(__parent__=parent)
        oid = parent.__objectmap__.new_objectid()
        resource.__oid__ = oid
        resource.__name__ = str(oid)
        path = resource_path_tuple(resource)
        parent[resource.__name__] = resource
        parent.__objectmap__.add(resource, path)
        resources = resources + (resource,)
    return resources[0] if count == 1 else resources
开发者ID:Janaba,项目名称:adhocracy3,代码行数:14,代码来源:test_init.py


示例10: test_object_has_a_parent

 def test_object_has_a_parent(self):
     from ..interfaces import IFolder
     from pyramid.traversal import resource_path_tuple
     objectmap = DummyObjectMap()
     site = _makeSite(objectmap=objectmap)
     bogusroot = testing.DummyModel(__provides__=IFolder)
     bogusparent2 = testing.DummyModel(__provides__=IFolder)
     one = testing.DummyModel(__provides__=IFolder)
     two = testing.DummyModel(__provides__=IFolder)
     bogusroot['bogusparent2'] = bogusparent2
     bogusparent2['one'] = one
     one['two'] = two
     self.assertEqual(resource_path_tuple(one), 
                      ('', 'bogusparent2', 'one'))
     event = DummyEvent(one, site)
     self.assertRaises(ValueError, self._callFUT, event)
开发者ID:tseaver,项目名称:substanced,代码行数:16,代码来源:tests.py


示例11: get_breadcrumbs

def get_breadcrumbs(request, context=None):
    breadcrumbs = []
    req = request
    if not context:
        context = request.context
    pathes = resource_path_tuple(context)
    resources = []
    t = request.root
    for i, item in enumerate(pathes):
        t = traverse(t, item)['context']
        resources.append((i, t, item))
    end = len(resources)
    for i, resource, item in resources:
        infos = get_nav_infos(resource, req, item)
        if i == 0:
            infos['class'] = 'start'
        if 0 < i < end-1:
            infos['class'] = 'middle'
        if i == end-1:
            infos['class'] = 'end'
        breadcrumbs.append(infos)
    return breadcrumbs
开发者ID:mobyle2-legacy,项目名称:mobyle2.core,代码行数:22,代码来源:__init__.py


示例12: __call__

 def __call__(self, context, request):
     if getattr(context, '__name__', _marker) is not _marker:
         return resource_path_tuple(context) == self.val
     return False
开发者ID:JDeuce,项目名称:pyramid,代码行数:4,代码来源:predicates.py


示例13: mgmt_url

 def mgmt_url(self, obj, *arg, **kw):
     request = self.request
     traverse = resource_path_tuple(obj)
     kw['traverse'] = traverse
     return request.route_url(MANAGE_ROUTE_NAME, *arg, **kw)
开发者ID:dhavlik,项目名称:substanced,代码行数:5,代码来源:__init__.py


示例14: remove

    def remove(self, obj_objectid_or_path_tuple, moving=False):
        """ Remove an object from the object map give an object, an object id
        or a path tuple.  If ``moving`` is ``False``, also remove any
        references added via ``connect`` and any extents related to the removed
        objects.

        Return a set of removed oids (including the oid related to the object
        passed).
        """
        if hasattr(obj_objectid_or_path_tuple, '__parent__'):
            path_tuple = resource_path_tuple(obj_objectid_or_path_tuple)
        elif isinstance(obj_objectid_or_path_tuple, INT_TYPES):
            path_tuple = self.objectid_to_path[obj_objectid_or_path_tuple]
        elif isinstance(obj_objectid_or_path_tuple, tuple):
            path_tuple = obj_objectid_or_path_tuple
        else:
            raise ValueError(
                'Value passed to remove must be a traversable '
                'object, an object id, or a path tuple, got %s' % (
                    (obj_objectid_or_path_tuple,)))

        pathlen = len(path_tuple)

        omap = self.pathindex.get(path_tuple)

        # rationale: if this key isn't present, no path added ever contained it
        if omap is None:
            return set()

        removed = self.family.IF.Set()
        items = omap.items()
        removepaths = []

        for k, dm in self.pathindex.items(min=path_tuple):
            if k[:pathlen] == path_tuple:
                for oidset in dm.values():
                    removed.update(oidset)
                    for oid in oidset:
                        if oid in self.objectid_to_path:
                            p = self.objectid_to_path[oid]
                            del self.objectid_to_path[oid]
                            del self.path_to_objectid[p]
                # dont mutate while iterating
                removepaths.append(k)
            else:
                break

        for k in removepaths:
            del self.pathindex[k]

        for x in range(pathlen-1):

            offset = x + 1
            els = path_tuple[:pathlen-offset]
            omap2 = self.pathindex[els]
            for level, oidset in items:

                i = level + offset
                oidset2 = omap2[i]

                for oid in oidset:
                    if oid in oidset2:
                        oidset2.remove(oid)
                        # adding to removed and removing from
                        # objectid_to_path and path_to_objectid should have
                        # been taken care of above in the for k, dm in
                        # self.pathindex.items() loop
                        assert oid in removed, oid
                        assert not oid in self.objectid_to_path, oid

                if not oidset2:
                    del omap2[i]

        if not moving:
            self.referencemap.remove(removed)
            self.extentmap.remove(removed)

        return removed
开发者ID:dhavlik,项目名称:substanced,代码行数:78,代码来源:__init__.py


示例15: __call__

 def __call__(self, obj, *arg, **kw):
     traverse = resource_path_tuple(obj)
     kw['traverse'] = traverse
     return self.request.route_path(MANAGE_ROUTE_NAME, *arg, **kw)
开发者ID:ericrasmussen,项目名称:substanced,代码行数:4,代码来源:__init__.py


示例16: mgmt_path

def mgmt_path(request, obj, *arg, **kw):
    traverse = resource_path_tuple(obj)
    kw['traverse'] = traverse
    return request.route_path(MANAGE_ROUTE_NAME, *arg, **kw)
开发者ID:dextermilo,项目名称:substanced,代码行数:4,代码来源:__init__.py


示例17: pencil_icon

def pencil_icon(resource, request):
    traverse = resource_path_tuple(resource)[1:]
    url = request.route_url('sdexternaledit', traverse=traverse)
    return ' <a href="%s"><i class="icon-pencil"></i></a>' % url
开发者ID:Pylons,项目名称:sdexternaledit,代码行数:4,代码来源:__init__.py


示例18: namespace

 def namespace(self):
     return '.'.join(resource_path_tuple(self)[1:])
开发者ID:boothead,项目名称:snotty,代码行数:2,代码来源:utils.py


示例19: add

    def add(self, name, other, send_events=True, reserved_names=(),
            duplicating=None, moving=None, loading=False, registry=None):
        """ Same as ``__setitem__``.

        If ``send_events`` is False, suppress the sending of folder events.
        Don't allow names in the ``reserved_names`` sequence to be added.

        If ``duplicating`` not ``None``, it must be the object which is being
        duplicated; a result of a non-``None`` duplicating means that oids will
        be replaced in objectmap.  If ``moving`` is not ``None``, it must be
        the folder from which the object is moving; this will be the ``moving``
        attribute of events sent by this function too.  If ``loading`` is
        ``True``, the ``loading`` attribute of events sent as a result of
        calling this method will be ``True`` too.

        This method returns the name used to place the subobject in the
        folder (a derivation of ``name``, usually the result of
        ``self.check_name(name)``).
        """
        if registry is None:
            registry = get_current_registry()

        name = self.check_name(name, reserved_names)

        if getattr(other, '__parent__', None):
            raise ValueError(
                'obj %s added to folder %s already has a __parent__ attribute, '
                'please remove it completely from its existing parent (%s) '
                'before trying to readd it to this one' % (
                    other, self, self.__parent__)
                )

        with statsd_timer('folder.add'):

            objectmap = find_objectmap(self)

            if objectmap is not None:

                basepath = resource_path_tuple(self)

                for node in postorder(other):
                    node_path = node_path_tuple(node)
                    path_tuple = basepath + (name,) + node_path[1:]
                    # the below gives node an objectid; if the will-be-added
                    # event is the result of a duplication, replace the oid of
                    # the node with a new one
                    objectmap.add(
                        node,
                        path_tuple,
                        duplicating=duplicating is not None,
                        moving=moving is not None,
                        )

            if send_events:
                event = ObjectWillBeAdded(
                    other, self, name, duplicating=duplicating, moving=moving,
                    loading=loading,
                    )
                self._notify(event, registry)

            other.__parent__ = self
            other.__name__ = name

            self.data[name] = other
            self._num_objects.change(1)

            if self._order is not None:
                oid = get_oid(other)
                self._order += (name,)
                self._order_oids += (oid,)

            if send_events:
                event = ObjectAdded(
                    other, self, name, duplicating=duplicating, moving=moving,
                    loading=loading,
                    )
                self._notify(event, registry)

            return name
开发者ID:Web5design,项目名称:substanced,代码行数:79,代码来源:__init__.py


示例20: __call__

 def __call__(self, context, request):
     return resource_path_tuple(context) == self.val
开发者ID:AndreaCrotti,项目名称:pyramid,代码行数:2,代码来源:predicates.py



注:本文中的pyramid.traversal.resource_path_tuple函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python traversal.traversal_path函数代码示例发布时间:2022-05-27
下一篇:
Python traversal.resource_path函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap