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


Python Template.endswith方法代码示例

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


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

示例1: build_sync_paths

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import endswith [as 别名]
def build_sync_paths(input_path):
    """
    Build the source and target paths for rsync by replacing the
    template parameters with the correct values
    input_path: the triggered directory
    """
    conf = Settings()

    # check the length of the triggered path
    input_path_list = input_path.split('/')
    src_path_list = conf['source']['folder_list']
    if len(input_path_list) < len(src_path_list):
        raise Exception(("The triggered path (%s) is shorter than the "%input_path)+
                        ("source path (%s)!"%conf['source']['folder']))

    # match the path elements between the input and the config source path
    # and extract the template values from the triggered path
    tmp_dict = {}
    for i in range(len(src_path_list)):
        input_element = input_path_list[i]
        path_element = src_path_list[i]
        if path_element.startswith('${') and path_element.endswith('}'):
            tmp_dict[path_element[2:len(path_element)-1]] = input_element
        else:
            if path_element != input_element:
                raise Exception(("Non matching path element '%s' "%input_element)+
                                 "found in input path!")

    # substitute the template parameters in the source and target path
    source = Template(conf['source']['folder']).substitute(tmp_dict)
    target = Template(conf['target']['folder']).substitute(tmp_dict)

    # make sure the triggered path starts with the substituted config source path
    if not input_path.startswith(source):
        raise Exception("There is a mismatch between the substituted config source "+
                        "path (%s) and the triggered path (%s)!"%(input_path, source))

    # append subdirectories
    if len(input_path_list) > len(src_path_list):
        post = input_path_list[len(src_path_list):]
        source = os.path.join(source, *post)
        target = os.path.join(target, *post)

    # make sure the paths end with a trailing slash
    if not source.endswith("/"):
        source += "/"

    if not target.endswith("/"):
        target += "/"

    return source, target
开发者ID:AustralianSynchrotron,项目名称:saxs-archive,代码行数:53,代码来源:syncutils.py

示例2: wrapped_f

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import endswith [as 别名]
 def wrapped_f(*args, **kwargs):
     config = args[0]._config
     if config.profile:
         pr = cProfile.Profile()
         pr.enable()
         pr.runcall(f, *args, **kwargs)
         pr.disable()
         pr.create_stats()
         if fn is None:
             pr.print_stats(sorting)
         else:
             # this is a bit subtile: because fn is a non mutable string,
             # reassigning fn in this scope would lead to masking fn from
             # the outer scope, resulting in:
             # UnboundLocalError: local variable 'fn' referenced before assignment
             # solution: assign to a local var
             # see: http://stackoverflow.com/questions/8447947
             _fn = fn
             now = datetime.datetime.now()
             d = dict(date = now.strftime(config.dateformat),
                      time = now.strftime(config.timeformat))
             _fn = Template(_fn).safe_substitute(d)
             if not _fn.endswith('.pstats'):
                 _fn += '.pstats'
             pr.dump_stats(os.path.join(config.profiledir, _fn))
     else:
         f(*args, **kwargs)
开发者ID:dagelf,项目名称:squid_dedup,代码行数:29,代码来源:profile.py

示例3: doInclude

# 需要导入模块: from string import Template [as 别名]
# 或者: from string.Template import endswith [as 别名]
def doInclude( includeLines, indent, params, out ):
    for line in includeLines:
        if ( type( line ) == str ):
            ind = "" if (line.isspace() or len( line ) == 0) else indent
            # TODO: using Template is only partial support for INCLUDE args, should use build recursively
            line = Template( line ).safe_substitute( params )
            if (line.endswith('\n')):
                out.write( ind + line )
            else:
                out.write( ind + line + '\n' )
        elif ( type( line ) == list ):
            if line[0] == "INCLUDE":
                run_include( indent + line[1], line[2], dict( line[3].items() + params.items() ), line[4], out )
            elif line[0] == "FOREACH":
                run_foreach( indent + line[1], line[2], dict( line[3].items() + params.items() ), line[4], out )
开发者ID:anukat2015,项目名称:gm-sparql,代码行数:17,代码来源:BlockTemplate.py


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