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


Python flask.safe_join方法代码示例

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


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

示例1: handle_old_templates

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def handle_old_templates(self, upgrade_templates=False):
        old_ids = [t.stem for t
                   in self.template_dir.glob('*' + FileExt.old_template)]
        if len(old_ids) > 0 and upgrade_templates:
            print "Converting {} old style templates".format(len(old_ids))
            for lm_id in old_ids:
                fp = safe_join(str(self.template_dir),
                               lm_id + FileExt.old_template)
                convert_legacy_template(fp)

        elif len(old_ids) > 0:
            print((
                "\nWARNING: ignored {} old style '.txt' templates in '{}' " +
                "({}).\n" +
                "See https://github.com/menpo/landmarkerio-server#templates " +
                "more information. You can restart with the " +
                "'--upgrade-templates' flag to convert them automatically " +
                "(one time operation)\n"
            ).format(
                len(old_ids),
                self.template_dir,
                ", ".join(['{}.txt'.format(t) for t in old_ids]))
            ) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:25,代码来源:template.py

示例2: texture_file

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def texture_file(self, asset_id):
        return reduce(safe_join, (str(self.cache_dir),
                                  asset_id, CacheFile.texture)) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:5,代码来源:asset.py

示例3: thumbnail_file

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def thumbnail_file(self, asset_id):
        return reduce(safe_join,
                      (str(self.cache_dir), asset_id, CacheFile.thumbnail)) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:5,代码来源:asset.py

示例4: mesh

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def mesh(self, asset_id):
        return reduce(safe_join, (str(self.cache_dir), asset_id,
                                  CacheFile.mesh)) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:5,代码来源:asset.py

示例5: load_template

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def load_template(self, lm_id):
        fp = safe_join(str(self.template_dir), lm_id + FileExt.template)
        return load_template(fp, self.n_dims) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:5,代码来源:template.py

示例6: _lm_paths

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def _lm_paths(self, asset_id=None):
        # what landmarks do exist and where
        if asset_id is None:
            asset_id = '*'
        g = glob.glob(p.join(safe_join(self.lm_dir, asset_id), '*'))
        return filter(lambda f: p.isfile(f) and
                                p.splitext(f)[-1] == FileExt.lm, g) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:9,代码来源:landmark.py

示例7: save_lm

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def save_lm(self, asset_id, lm_id, lm_json):
        r"""
        Persist a given landmark definition to disk.
        """
        subject_dir = safe_join(self.lm_dir, asset_id)
        if not p.isdir(subject_dir):
            os.mkdir(subject_dir)
        super(SeparateDirFileLmAdapter, self).save_lm(asset_id, lm_id, lm_json) 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:10,代码来源:landmark.py

示例8: full_path

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def full_path(self):
        # build storage path, e.g.
        # /app/uploads/acme/2coffee12345678123123123123123123
        return safe_join(current_app.config["UPLOAD_ROOT"], self.path) 
开发者ID:jazzband-roadies,项目名称:website,代码行数:6,代码来源:models.py

示例9: view_page

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def view_page(name):
    markdown_file = flask.safe_join(CONTENT, f"{name}.md")

    if not os.path.exists(markdown_file):
        flask.abort(404)

    with open(markdown_file, "r") as fh:
        content = cmarkgfm.markdown_to_html_with_extensions(
            fh.read(), extensions=["table", "autolink", "strikethrough"]
        )

    # content = content.replace("<h1>", "<h1 class=\"title is-1 is-spaced\">")
    # content = content.replace("<h2>", "<h2 class=\"subtitle is-2 is-spaced\">")

    return flask.render_template("page.html", content=content) 
开发者ID:theacodes,项目名称:conducthotline.com,代码行数:17,代码来源:webhandlers.py

示例10: get_file_hash

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def get_file_hash(filename):
    if not hasattr(g, 'static_hashes'):
        g.static_hashes = {}
    # Check the cache if not in debug mode
    if not current_app.debug:
        try:
            return g.static_hashes[filename]
        except KeyError:
            pass
    hasher = hashlib.md5()
    with open(safe_join(current_app.static_folder, filename), 'rb') as f:
        hasher.update(f.read())
    filehash = hasher.hexdigest()[:8]
    g.static_hashes[filename] = filehash
    return filehash 
开发者ID:paxswill,项目名称:evesrp,代码行数:17,代码来源:versioned_static.py

示例11: get

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def get(self, batch, file):
        """
        Retrieves the file at *file* in batch *batch*.

        ** Request **

        .. sourcecode:: http

            GET /pages/:batch/:path

        ** Response **

        .. sourcecode:: http

            HTTP/1.1 200 OK
            Content-Type: application/octet-stream

            ...

        :param batch: batch's unique id
        :type batch: str
        :param file: path to the batch's file
        :type file: path
        :status 200: No error
        :status 404: File not found
        """
        log.debug('routing to pages with URN: {}/{}'.format(batch, file))
        return send_from_directory(abspath(expanduser(nidaba_cfg['storage_path'])), safe_join(batch, file)) 
开发者ID:OpenPhilology,项目名称:nidaba,代码行数:30,代码来源:api.py

示例12: static_fetcher

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def static_fetcher(resource_name):
    resource_name = safe_join('static', resource_name)
    if resource_name in application.resources:
        return Response(open(resource_name, mode='rb').read(), status=200, mimetype='application/octet-stream')
    return Response(application.four_o_four, status=404)


# This is where we process a transform request. 
开发者ID:redcanari,项目名称:canari3,代码行数:10,代码来源:plume.py

示例13: files_get_sha256_helper

# 需要导入模块: import flask [as 别名]
# 或者: from flask import safe_join [as 别名]
def files_get_sha256_helper(sha256, raw='f'):
    '''
    Returns binary from storage. Defaults to password protected zipfile.
    '''
    file_path = safe_join(api_config['api']['upload_folder'], sha256)
    if not os.path.exists(file_path):
        abort(HTTP_NOT_FOUND)

    with open(file_path, 'rb') as fh:
        fh_content = fh.read()

    raw = str(raw)[0].lower()
    if raw in ['t', 'y', '1']:
        response = make_response(fh_content)
        response.headers['Content-Type'] = 'application/octet-stream; charset=UTF-8'
        # better way to include fname?
        response.headers['Content-Disposition'] = 'inline; filename={}.bin'.format(sha256)
    else:
        # ref: https://github.com/crits/crits/crits/core/data_tools.py#L122
        rawname = sha256 + '.bin'
        with open(safe_join('/tmp/', rawname), 'wb') as raw_fh:
            raw_fh.write(fh_content)

        zipname = sha256 + '.zip'
        args = ['/usr/bin/zip', '-j',
                safe_join('/tmp', zipname),
                safe_join('/tmp', rawname),
                '-P', 'infected']
        proc = subprocess.Popen(args)
        wait_seconds = 30
        while proc.poll() is None and wait_seconds:
            time.sleep(1)
            wait_seconds -= 1

        if proc.returncode:
            return make_response(jsonify({'Error': 'Failed to create zip ()'.format(proc.returncode)}))
        elif not wait_seconds:
            proc.terminate()
            return make_response(jsonify({'Error': 'Process timed out'}))
        else:
            with open(safe_join('/tmp', zipname), 'rb') as zip_fh:
                zip_data = zip_fh.read()
            if len(zip_data) == 0:
                return make_response(jsonify({'Error': 'Zip file empty'}))
            response = make_response(zip_data)
            response.headers['Content-Type'] = 'application/zip; charset=UTF-8'
            response.headers['Content-Disposition'] = 'inline; filename={}.zip'.format(sha256)
    return response 
开发者ID:mitre,项目名称:multiscanner,代码行数:50,代码来源:api.py


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