webdb.files¶
This sub package can be used to provide user files for web applications.
webdb.files.file¶
File overlays for providing files to web applications.
-
class
webdb.files.file.FileOverlay(path, root, modes, nickname, maxsize=inf, cpy_chunk_size=255)¶ This is the main file overlay providing methods on files that are useful when operating over a remote connection.
path- relative path of the file
root- absolute path of the “root” directory for files,
os.path.join(root, path)must be the absolute path of the file modesstring or list of characters:
"r"readable"w"writable"c"file can be created"p"also parent directories can be created.
nickname- the name of the file that the client knows.
-
copy_file_part(offset, file_part)¶ Copy the
file_parttooffset.This will read
cpy_chunk_sizechunks and write them atoffset.If the maxsize is exceeded it will stop after writing enough chunks to not yet exceed the size.
-
create_file()¶ Create the file or raise IOError.
-
get_file_part(offset, chunk_size)¶ Return a
FilePartof this file.
-
remove_file()¶ Remove this file.
-
truncate(size=None)¶ Truncate the file to
size.
-
write_file_part(offset, chunk)¶ Write a part of a file. If the file is not at least
offsetbytes long, raiseIndexError. This is a protection against people that think it would be funny to fill the disk up with zeros.
webdb.files.dispatcher¶
File dispatchers for serving files for web applications.
-
class
webdb.files.dispatcher.AbstractFileDispatcher¶ Abstract base class for file dispatchers.
-
cleanup_path(path)¶ Clean up the path. Remove any “..”s and a leading “/”.
dispatch_filemust call this method before actually dispatching the file.
-
dispatch_file(path, *args)¶ Dispatch the file. This must always return a
FileOverlay. Even if the file must not be accessed, or does not exist. In this case themodesmust be emtpy.
-
-
class
webdb.files.dispatcher.QuotaUserFileDispatcher(root, quota)¶ This file dispatcher has a seperated path for every user. The user is allowed to do anything in this path (read, write, create, create parents).
This file dispatcher will refuse changes, if a quota has been exceeded.
Only use this for “semi reliable” clients.
-
dispatch_file(path, username)¶ Dispatch the file. This must always return a
FileOverlay. Even if the file must not be accessed, or does not exist. In this case themodesmust be emtpy.
-
-
class
webdb.files.dispatcher.SQLFileDispatcher(db_connection)¶ This is a nice dispatcher for controlled environments, such as sharing files between users or a limited set of files.
The dispatcher looks up the files in a database, dispatchs the real path and returns the according FileOverlay.
The commands for creating the tables are:
CREATE TABLE files(path text UNIQUE, id integer PRIMARY KEY AUTOINCREMENT, max_size integer); CREATE TABLE access(file_id integer, username text, modes text); CREATE TABLE nicknames(name text PRIMARY KEY, file_id integer); CREATE INDEX access_index ON access(file_id); CREATE TABLE root(root text UNIQUE);
NOTE: This dispatcher does NOT allow creating files.
- NOTE: if
max_sizeis-1it will be interpreted as - “has no max size”.
-
dispatch_file(nickname, username)¶ This method looks up the file in the sqlite database and resolves the real path, the access rights and the modes
- NOTE: if
-
class
webdb.files.dispatcher.UserFileDispatcher(root)¶ This file dispatcher has a seperated path for every user. The user is allowed to do anything in this path (read, write, create, create parents).
Only use this for “reliable” clients.
-
dispatch_file(path, username)¶ Dispatch the file. This must always return a
FileOverlay. Even if the file must not be accessed, or does not exist. In this case themodesmust be emtpy.
-