當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。