core.filestorage
Filestorage is a way to store files locally or on a remote server, with the interface being the same, no matter where the files are stored.
Based on https://docs.pyfilesystem.org/en/latest/
See onegov.core.framework.Framework.filestorage for more information.
Attributes
Exceptions
Too many backrefs exist in a path. |
Classes
A minimal implementation of |
|
Defines a static file served by the application. The difference |
Functions
|
Returns a random filename that can't be guessed. |
|
|
|
|
|
Renders the given filestorage file in the browser. |
|
Deletes the given filestorage file. By default the permission is |
Module Contents
- exception core.filestorage.IllegalBackReference(path: str)[source]
Bases:
ValueErrorToo many backrefs exist in a path.
- class core.filestorage.Filestorage(root_path: _typeshed.StrOrBytesPath, create: bool = False, create_mode: int = 511, expand_vars: bool = True)[source]
A minimal implementation of
fs/PyFilesystem’sOSFSclass, that can do everything we need in OneGov.Since
fswas no longer maintained and the maintained alternativefsspecdoes not yet have type hints of any kind and we don’t really use anything other thanOSFSin any of our deployments this seemed like the most sensible solution.We can always migrate to
fsspeclater, if we do end up needing more control again.- open(path: str, mode: _typeshed.OpenTextMode = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str = '') io.TextIOWrapper[source]
- open(path: str, mode: _typeshed.OpenBinaryMode, buffering: Literal[0], encoding: None = None, errors: None = None, newline: str = '') io.FileIO
- open(path: str, mode: _typeshed.OpenBinaryModeUpdating, buffering: Literal[-1, 1] = -1, encoding: None = None, errors: None = None, newline: str = '') io.BufferedRandom
- open(path: str, mode: _typeshed.OpenBinaryModeWriting, buffering: Literal[-1, 1] = -1, encoding: None = None, errors: None = None, newline: str = '') io.BufferedWriter
- open(path: str, mode: _typeshed.OpenBinaryModeReading, buffering: Literal[-1, 1] = -1, encoding: None = None, errors: None = None, newline: str = '') io.BufferedReader
- open(path: str, mode: _typeshed.OpenBinaryMode, buffering: int = -1, encoding: None = None, errors: None = None, newline: str = '') IO[bytes]
- open(path: str, mode: str, buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str = '') IO[Any]
- class core.filestorage.FilestorageFile(path: str)[source]
Defines a static file served by the application. The difference between this and
onegov.core.static.StaticFileis the storage.Filestorage files are stored per application_id locally or on the cloud. Static files are the same for the whole application class and they are deployed statically. That means they are not content, but part of the distribution.
Note that this is only used if the file is local. Files stored in the filestorage should be linked using
onegov.core.request.CoreRequest.filestorage_link(), which might result in a local path, for which this class is used. Or it might result in a remote path that is served by some different webserver.
- core.filestorage.get_filestorage_file(app: onegov.core.framework.Framework, absorb: str) FilestorageFile | None[source]
- core.filestorage.view_filestorage_file(self: FilestorageFile, request: core.request.CoreRequest) str[source]
Renders the given filestorage file in the browser.
- core.filestorage.delete_static_file(self: FilestorageFile, request: core.request.CoreRequest) None[source]
Deletes the given filestorage file. By default the permission is
Private. An application using the framework can override this though.Since a DELETE can only be sent through AJAX it is protected by the same-origin policy. That means that we don’t need to use any CSRF protection here.
That being said, browser bugs and future changes in the HTML standard make it possible for this to happen one day. Therefore, a time-limited token must be passed as query parameter to this function.
New tokens can be acquired through
request.new_csrf_token.