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


Python IAnnotations.openDataFile方法代码示例

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


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

示例1: openFileReference

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import openDataFile [as 别名]
def openFileReference(transmogrifier, ref):
    """
    Get an open file handle in one of the following forms:

    * importcontext:file.txt
    * dotted.package:file.txt
    * /file/system/file.txt

    Where "importcontext:" means find the file in the GS import context.
    Return None if there was no file to be found
    """
    if ref.startswith('importcontext:'):
        try:
            from collective.transmogrifier.genericsetup import IMPORT_CONTEXT
            from zope.annotation.interfaces import IAnnotations
            context = IAnnotations(transmogrifier).get(IMPORT_CONTEXT, None)
            (subdir, filename) = os.path.split(ref.replace('importcontext:', ''))
            if subdir == '':
                # Subdir of '' results import contexts looking for a ''
                # directory I think
                subdir = None
            if hasattr(context, "openDataFile"):
                return context.openDataFile(filename, subdir=subdir)
            if hasattr(context, "readDataFile"):
                import StringIO
                return StringIO.StringIO(
                    context.readDataFile(filename, subdir=subdir))
        except ImportError:
            return None
    # Either no import context or not there.
    filename = resolvePackageReferenceOrFile(ref)
    if os.path.isfile(filename):
        return open(filename, 'r')
    return None
开发者ID:tobiasherp,项目名称:collective.transmogrifier,代码行数:36,代码来源:utils.py


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