Пример #1
0
 def test_req_not_strip(self, req_m, request_data, expected):
     req_m.form = request_data
     if expected == RuntimeError:
         with pytest.raises(expected):
             get_post_arg("data", required=True, strip=False)
     else:
         assert get_post_arg("data", required=True, strip=False) == expected
Пример #2
0
def upload_files():
    folder = get_post_arg("folder")

    log("User %r made a POST request to /upload", get_user())

    if folder is None:
        flash("No folder supplied or an invalid folder was supplied", "danger")
        return redirect("/")

    folders = get_folders()

    try:
        folder = folders[int(folder)]
    except (IndexError, ValueError):
        flash("Invalid index folder (index %r)" % folder, "danger")
        return redirect("/")

    files = request.files.getlist("files[]")

    if not files:
        flash("No files supplied", "danger")
        return redirect("/")

    log_files = []
    for file in files:
        filename = secure_filename(file.filename)
        if not filename:
            continue

        log_files.append(filename)
        filename = cfg.CLOUD_PATH / folder / filename
        try:
            file.save(filename.as_posix())
        except PermissionError as exc:
            flash("Permission Error: %s" % exc, "danger")
            log("User %r encoutered a PermissionError: %r" % (get_user(), exc))
            return redirect("/")

    if not log_files:
        flash("Supplied only %d empty files" % len(files), "danger")
        return redirect("/")

    log(
        "User %r upload files to folder %r: %s",
        get_user(),
        folder.as_posix(),
        log_files,
    )
    flash("Files uploaded successfully", "success")
    return redirect("/")
Пример #3
0
 def test_not_req_not_strip(self, req_m, request_data, expected):
     req_m.form = request_data
     assert get_post_arg("data", required=False, strip=False) == expected