当前位置: 首页>>代码示例>>Python>>正文


Python Path.startswith_slash方法代码示例

本文整理汇总了Python中itools.uri.Path.startswith_slash方法的典型用法代码示例。如果您正苦于以下问题:Python Path.startswith_slash方法的具体用法?Python Path.startswith_slash怎么用?Python Path.startswith_slash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在itools.uri.Path的用法示例。


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

示例1: get_namespace

# 需要导入模块: from itools.uri import Path [as 别名]
# 或者: from itools.uri.Path import startswith_slash [as 别名]
    def get_namespace(self, resource, context):
        path = context.query['path']
        if path is None:
            path = Path('.')

        if path.startswith_slash:
            path.startswith_slash = False

        # Namespace: the location
        base = '/%s/;browse_tests' % context.site_root.get_pathto(resource)
        link = base + '?path=%s'
        location = [{'name': MSG(u'Test Suite'), 'link': link % '.'}]
        for i, name in enumerate(path):
            p = path[:i+1]
            try:
                test_suite.get_handler(p)
            except LookupError:
                location.append({'name': name, 'link': None})
                body = MSG(u'The "{path}" resource has not been found')
                body = body.gettext(path=p)
                return {'location': location, 'body': body}
            else:
                location.append({'name': name, 'link': link % p})

        # Get the handler
        handler = test_suite.get_handler(path)

        # (1) View PO file
        root = context.root
        if isinstance(handler, POFile):
            template = root.get_resource('/ui/odf-i18n/view_po.xml')
            units = handler.get_units()
            msgs = [ {'id': x.source, 'str': x.target} for x in units ]
            namespace = {'messages': msgs}
            body = stl(template, namespace)

            return {'location': location, 'body': body}

        # Load setup file
        if handler.has_handler('setup.conf'):
            setup = handler.get_handler('setup.conf', cls=ConfigFile)
        else:
            setup = None

        # (2) Browse Folders
        children = handler.get_handler_names()
        children.sort()
        a_handler = handler.get_handler(children[0])
        if isinstance(a_handler, Folder):
            files = []
            for child in children:
                child_handler = handler.get_handler(child)
                number = 0
                for x in test_suite.database.fs.traverse(child_handler.key):
                    if x.endswith('.po'):
                        number += 1
                files.append({'child_name': child,
                              'to_child': link % ('%s/%s' % (path, child)),
                              'number': number})

            namespace = {'content': files}
            template = root.get_resource('/ui/odf-i18n/browse_folder.xml')
            body = stl(template, namespace)
            return {'location': location, 'body': body}

        # (3) Test Folder
        if setup is None:
            title = description = reference = url_reference = None
        else:
            title = setup.get_value('title')
            description = setup.get_value('description')
            reference = setup.get_value('reference')
            url_reference = setup.get_value('url_reference')
            # Format the description (may contain XML)
            description = XMLParser(description)

        files = []
        for child in children:
            if child != 'setup.conf':
                child_path = '%s/%s' % (path, child)
                view = (link % child_path) if child.endswith('.po') else None
                files.append({
                    'child_name': child,
                    'view': view,
                    'to_child': ';download?path=%s' % child_path})

        template = root.get_resource('/ui/odf-i18n/browse_test.xml')
        namespace = {
            'title': title,
            'description': description,
            'reference': reference,
            'url_reference': url_reference,
            'content': files}
        body = stl(template, namespace)

        return {'location': location, 'body': body}
开发者ID:hforge,项目名称:hforge,代码行数:98,代码来源:ws_odf.py


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