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


Python Response.headers['content-disposition']方法代码示例

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


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

示例1: set_patts

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['content-disposition'] [as 别名]
def set_patts(request):

    if len(request.GET.keys())==0:
        data = open('index.html','rb').read()
        mResponse = Response(data)
        mResponse.headers['content-type'] = 'text/html'
        return mResponse
           
    custom_config = "\n"                                 # string that contains all the patterns that are to be included
    
    for key in request.GET.keys():                       # parse query string for patterns and add them
        if key.startswith('pat/'):
            custom_config += '    "' + CONFMAP[key] + '",\n'

    if len(custom_config) > 1:
        custom_config = custom_config[:-2] + "\n"

    config = TPL_head + custom_config + TPL_tail         # write patterns.js
    data = open(patterns_dir + 'src/' + 'patterns.js', 'wb')
    data.write(config)
    data.close()

    os.chdir(patterns_dir)                              # run make
    subprocess.call(["make"])
    os.chdir(working_dir)
        
    data = open(patterns_dir + 'bundle.js', 'rb').read() # create response with bundle.js as attachment
    mResponse = Response(data)
    mResponse.headers['content-type'] = 'application/javascript'
    mResponse.headers['content-disposition'] = 'attachment;filename=bundle.js'    

    return mResponse
开发者ID:syslabcom,项目名称:slc.scripts,代码行数:34,代码来源:patterns_setter.py

示例2: make_bundle

# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['content-disposition'] [as 别名]
def make_bundle(request):
    if len(request.GET.keys()) == 0:
        data = open('index.html', 'rb').read()
        mResponse = Response(data)
        mResponse.headers['content-type'] = 'text/html'
        return mResponse

    modules = [
        x.replace('pat/', 'pat-')
        for x in request.GET.keys()
        if x.startswith('pat/') or x in ('modernizr', 'less', 'prefixfree')
    ]
    modules.sort()

    log.info("Modules: %s" % str(modules))

    minify = request.GET.get('minify') == 'on' and '.min' or ''
    uglify = minify and 'uglify' or 'none'

    hashkey = hashlib.new('sha1')
    hashkey.update('-'.join(modules))
    # maybe indicate if it's full, core or custom in the name?
    bundlename = "patterns-{0}{1}".format(version, "-min" if minify else "")
    bundlehash = "{0}-{1}".format(bundlename, hashkey.hexdigest())
    bundledir_path = os.path.abspath(os.path.join("bundlecache", bundlehash))
    bundlezip_path = "bundlecache/{0}.zip".format(bundlehash)

    log.info('Hashkey generated: {0}'.format(hashkey.hexdigest()))
    log.info('Bundlehash generated: {0}'.format(bundlehash))

    # Create cache dir if it doesn't exist yet
    if not os.path.exists("bundlecache"):
        os.makedirs('bundlecache')

    if not os.path.exists(bundlezip_path):
        if not os.path.exists(bundledir_path):
            shutil.copytree("skel", bundledir_path)
        build_js(modules, bundlehash, bundlename, bundledir_path, uglify)
#        build_css(bundledir_path, modules, minify, bundlename)
#        build_html(modules, bundledir_path, bundlename)
        build_zipfile(bundlezip_path, bundledir_path)

    data = open(bundlezip_path, 'rb').read()
    mResponse = Response(data)
    mResponse.headers['content-type'] = 'application/zip'
    mResponse.headers[
        'content-disposition'] = 'attachment;filename={0}.zip'.format(bundlename)

    return mResponse
开发者ID:Patternslib,项目名称:Patterns-bundler,代码行数:51,代码来源:bundler.py


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