python类send_file()的实例源码

path_traversal_sanitised.py 文件源码 项目:pyt 作者: SW10IoT 项目源码 文件源码 阅读 78 收藏 0 点赞 0 评论 0
def cat_picture():
    image_name = request.args.get('image_name')

    image_name = image_name.replace('..', '')

    return send_file(os.path.join(os.getcwd(), image_name))
path_traversal_sanitised_2.py 文件源码 项目:pyt 作者: SW10IoT 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def cat_picture():
    image_name = request.args.get('image_name')

    if not '..' in image_name:
        return 404
    return send_file(os.path.join(os.getcwd(), image_name))
path_traversal.py 文件源码 项目:pyt 作者: SW10IoT 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def cat_picture():
    image_name = request.args.get('image_name')
    if not image_name:
        return 404
    return send_file(os.path.join(os.getcwd(), image_name))
server.py 文件源码 项目:pheweb 作者: statgen 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def api_top_hits():
    return send_file(common_filepaths['top-hits-1k'])
helpers.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_send_file_regular(self):
        app = flask.Flask(__name__)
        with app.test_request_context():
            rv = flask.send_file('static/index.html')
            self.assert_true(rv.direct_passthrough)
            self.assert_equal(rv.mimetype, 'text/html')
            with app.open_resource('static/index.html') as f:
                rv.direct_passthrough = False
                self.assert_equal(rv.data, f.read())
            rv.close()
helpers.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_send_file_xsendfile(self):
        app = flask.Flask(__name__)
        app.use_x_sendfile = True
        with app.test_request_context():
            rv = flask.send_file('static/index.html')
            self.assert_true(rv.direct_passthrough)
            self.assert_in('x-sendfile', rv.headers)
            self.assert_equal(rv.headers['x-sendfile'],
                os.path.join(app.root_path, 'static/index.html'))
            self.assert_equal(rv.mimetype, 'text/html')
            rv.close()
helpers.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_attachment(self):
        app = flask.Flask(__name__)
        with catch_warnings() as captured:
            with app.test_request_context():
                f = open(os.path.join(app.root_path, 'static/index.html'))
                rv = flask.send_file(f, as_attachment=True)
                value, options = parse_options_header(rv.headers['Content-Disposition'])
                self.assert_equal(value, 'attachment')
                rv.close()
            # mimetypes + etag
            self.assert_equal(len(captured), 2)

        with app.test_request_context():
            self.assert_equal(options['filename'], 'index.html')
            rv = flask.send_file('static/index.html', as_attachment=True)
            value, options = parse_options_header(rv.headers['Content-Disposition'])
            self.assert_equal(value, 'attachment')
            self.assert_equal(options['filename'], 'index.html')
            rv.close()

        with app.test_request_context():
            rv = flask.send_file(StringIO('Test'), as_attachment=True,
                                 attachment_filename='index.txt',
                                 add_etags=False)
            self.assert_equal(rv.mimetype, 'text/plain')
            value, options = parse_options_header(rv.headers['Content-Disposition'])
            self.assert_equal(value, 'attachment')
            self.assert_equal(options['filename'], 'index.txt')
            rv.close()
helpers.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_static_file(self):
        app = flask.Flask(__name__)
        # default cache timeout is 12 hours
        with app.test_request_context():
            # Test with static file handler.
            rv = app.send_static_file('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, 12 * 60 * 60)
            rv.close()
            # Test again with direct use of send_file utility.
            rv = flask.send_file('static/index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, 12 * 60 * 60)
            rv.close()
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
        with app.test_request_context():
            # Test with static file handler.
            rv = app.send_static_file('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, 3600)
            rv.close()
            # Test again with direct use of send_file utility.
            rv = flask.send_file('static/index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, 3600)
            rv.close()
        class StaticFileApp(flask.Flask):
            def get_send_file_max_age(self, filename):
                return 10
        app = StaticFileApp(__name__)
        with app.test_request_context():
            # Test with static file handler.
            rv = app.send_static_file('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, 10)
            rv.close()
            # Test again with direct use of send_file utility.
            rv = flask.send_file('static/index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assert_equal(cc.max_age, 10)
            rv.close()
apiview.py 文件源码 项目:polichombr 作者: ANSSI-FR 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def api_family_export_sampleszip(family_id, tlp_level):
    my_family = api.get_elem_by_type("family", family_id)
    zpath = api.familycontrol.generate_samples_zip_file(my_family, tlp_level)
    if zpath is None:
        return ""
    return send_file("../" + zpath, as_attachment=True,
                     attachment_filename="export.tar.gz")
apiview.py 文件源码 项目:polichombr 作者: ANSSI-FR 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def download_family_file(family_id, file_id):
    """
    Family attachment download endpoint.
    """
    attachment = api.get_elem_by_type("family_file", file_id)
    data_file = attachment.filepath
    if not os.path.exists(data_file):
        abort(404)
    return send_file('../' + data_file,
                     as_attachment=True,
                     attachment_filename=os.path.basename(data_file))
apiview.py 文件源码 项目:polichombr 作者: ANSSI-FR 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def api_get_sample_file(sid):
    """
        Return the sample binary
    """
    sample = api.get_elem_by_type("sample", sid)
    data_file = sample.storage_file
    return send_file('../' + data_file,
                     as_attachment=True,
                     attachment_filename=os.path.basename(data_file))
views.py 文件源码 项目:plexivity 作者: mutschler 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def cache(filename):
    if not config.CACHE_IMAGES:
        return g.plex.get_thumb_data(filename)
    cache_dir = os.path.join(config.DATA_DIR, "cache")
    cache_file = os.path.join(cache_dir, filename)
    if not os.path.exists(cache_file + ".jpg"):
        if helper.cache_file(filename, g.plex):
            return send_from_directory(cache_dir, filename + ".jpg")
        else:
            return send_file('static/images/poster.png')
    else:
        return send_from_directory(cache_dir, filename + ".jpg")
roboserver.py 文件源码 项目:pi-robot-rc-android 作者: grdkly 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def image_jpg():
    myCamera.getImage().save('/home/pi/boot/image.jpg')
    return send_file('/home/pi/boot/image.jpg', attachment_filename='image.jpg')
static.py 文件源码 项目:rc-niceties 作者: mjec 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def home():
    return send_file(os.path.realpath(os.path.join(app.static_folder, 'index.html')))
static.py 文件源码 项目:rc-niceties 作者: mjec 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def font():
    return send_file(os.path.realpath(os.path.join('SFPixelate-Bold.ttf')))
    #return send_from_directory('/', 'SFPixelate-Bold.ttf')
routes.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def index():
    return send_file('templates/index.html')
vxstream.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_vxstream_download(sha256, eid, ftype):
    Sample.query.filter_by(sha256=sha256).first_or_404()
    headers = {
        'Accept': 'text/html',
        'User-Agent': 'VxStream Sandbox API Client'}
    params = {'type': ftype, 'environmentId': eid}
    vx = vxstream.api.get('result/{}'.format(sha256),
                          params=params, headers=headers)
    if ftype in ['xml', 'html', 'bin', 'pcap']:
        ftype += '.gz'
    return send_file(BytesIO(vx),
                     attachment_filename='{}.{}'.format(sha256, ftype),
                     as_attachment=True)
fireeye.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_fireeye_download(sha256, eid, ftype):
    raise ApiException({}, 501)
    Sample.query.filter_by(sha256=sha256).first_or_404()
    headers = {
        'Accept': 'text/html',
        'User-Agent': 'FireEye Sandbox API Client'}
    params = {'type': ftype, 'environmentId': eid}
    vx = fireeye.api.get('result/{}'.format(sha256),
                         params=params, headers=headers)
    if ftype in ['xml', 'html', 'bin', 'pcap']:
        ftype += '.gz'
    return send_file(BytesIO(vx),
                     attachment_filename='{}.{}'.format(sha256, ftype),
                     as_attachment=True)
deliverable_files.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def download_file(file_id):
    """Download file

    **Example request**:

    .. sourcecode:: http

       GET /api/1.0/files/1 HTTP/1.1
       Host: do.cert.europa.eu
       Accept: application/json

    **Example response**:

    .. sourcecode:: http

       HTTP/1.0 200 OK
       Content-Type: application/json
       Content-Disposition: attachment; filename=CIMBL-244-EU.zip
       Content-Length: 55277
       Content-Type: application/zip


    :param file_id: file's unique ID

    :reqheader Accept: Content type(s) accepted by the client
    :resheader Content-Type: this depends on `Accept` header or request

    :status 200: File found
    :status 404: Resource not found
    """
    dfile = DeliverableFile.query.filter_by(id=file_id).first_or_404()
    cfg = current_app.config
    return send_file(os.path.join(cfg['APP_UPLOADS'], dfile.name),
                     attachment_filename=dfile.name, as_attachment=True)
vxstream.py 文件源码 项目:do-portal 作者: certeu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_cp_vxstream_download(sha256, eid, ftype):
    Sample.query.filter_by(sha256=sha256, user_id=g.user.id).first_or_404()
    headers = {
        'Accept': 'text/html',
        'User-Agent': 'VxStream Sandbox API Client'}
    params = {'type': ftype, 'environmentId': eid}
    vx = vxstream.api.get('result/{}'.format(sha256),
                          params=params, headers=headers)
    if ftype in ['xml', 'html', 'bin', 'pcap']:
        ftype += '.gz'
    return send_file(BytesIO(vx),
                     attachment_filename='{}.{}'.format(sha256, ftype),
                     as_attachment=True)


问题


面经


文章

微信
公众号

扫码关注公众号