dropboxdol.shared_folder#
Read a public Dropbox shared-folder link with no token, through its folder download.
A shared-folder link (https://www.dropbox.com/scl/fo/...) with dl=1 downloads the
whole folder as one zip, and its Content-Disposition names the folder. That needs no
app key or access token, unlike dropboxdol.DropboxLinkReaderWithToken; the
cost is a whole-folder download per refresh, so for a large folder the token-based
reader stays the better choice (i2mint/dropboxdol#8).
>>> download_url("https://www.dropbox.com/scl/fo/abc/xyz?rlkey=k&dl=0")
'https://www.dropbox.com/scl/fo/abc/xyz?rlkey=k&dl=1'
DropboxSharedFolderZip(url) is a Mapping[str, bytes] of the files in the folder,
keyed by their path inside it; shared_folder_name(url) is the folder’s name.
Every request goes through one http(url) callable (default: urllib, following
redirects only to Dropbox’s own https hosts), so tests and other clients plug in there.
Module Attributes
Hosts a shared-folder link may name. |
|
Path prefixes of shared-folder links ( |
|
Domains a download may be redirected to (the host itself or a subdomain of it). |
|
Default ceiling for the download and for the files it holds, uncompressed. |
|
Default ceiling for the number of entries in the zip (each costs memory before any read). |
Functions
|
The shared-folder link with |
|
The shared folder's name: its download's file name without |
|
GET |
Classes
|
The files of a public Dropbox shared folder, |
Exceptions
A shared-folder link that cannot be read (not a folder link, not shared, too big). |
- dropboxdol.shared_folder.DFLT_MAX_BYTES = 4294967296#
Default ceiling for the download and for the files it holds, uncompressed.
- dropboxdol.shared_folder.DFLT_MAX_MEMBERS = 100000#
Default ceiling for the number of entries in the zip (each costs memory before any read).
- dropboxdol.shared_folder.DOWNLOAD_DOMAINS = ('dropbox.com', 'dropboxusercontent.com')#
Domains a download may be redirected to (the host itself or a subdomain of it).
- dropboxdol.shared_folder.DROPBOX_FOLDER_PATHS = ('/scl/fo/', '/sh/')#
Path prefixes of shared-folder links (
scl/fotoday,shfor older links).
- dropboxdol.shared_folder.DROPBOX_HOSTS = ('dropbox.com', 'www.dropbox.com')#
Hosts a shared-folder link may name.
- class dropboxdol.shared_folder.DropboxSharedFolderZip(url, *, include=None, cache_dir=None, max_bytes=4294967296, max_members=100000, http=<function urlopen_dropbox>)[source]#
Bases:
MappingThe files of a public Dropbox shared folder,
{path inside the folder: bytes}, read from the folder’s zip download, with no token.The zip is downloaded once, on first use: into
cache_dir(then reused by later instances, untilrefresh()), or into an anonymous temporary file that goes away with the object. Folder entries and paths that would leave the folder are not keys. The download, and the files it holds once uncompressed, may not exceedmax_bytes(SharedFolderErrorotherwise).- Parameters:
url (
str) – The shared-folder link (https://www.dropbox.com/scl/fo/...).include (
Optional[Callable[[str],bool]]) –include(path) -> bool: which files are keys (default: all), e.g.lambda p: p.endswith(".mp3"). It may not read this store. Excluded files do not count towardmax_bytesonce the zip is here.cache_dir – A folder to keep the zip in, named from the link’s hash.
max_bytes (
int) – Ceiling for the download and for the included files’ total size.max_members (
int) – Ceiling for the number of entries in the zip.http (
Callable) –http(url)returning a response (a context manager with.headersand.read(n)). Defaulturlopen_dropbox().
Use it as a context manager (or call
close()) to release the open zip. Reads are thread-safe; iterating while another thread callsrefresh()is not (the keys may come from one download and the values from the next).
- exception dropboxdol.shared_folder.SharedFolderError[source]#
Bases:
ValueErrorA shared-folder link that cannot be read (not a folder link, not shared, too big).
- dropboxdol.shared_folder.download_url(url)[source]#
The shared-folder link with
dl=1(its zip download). Refuses anything but an https Dropbox shared-folder link, so a caller cannot be made to fetch another host.>>> download_url("https://dropbox.com/sh/abc/def?dl=0&raw=1") 'https://dropbox.com/sh/abc/def?dl=1' >>> download_url("https://example.com/scl/fo/abc") Traceback (most recent call last): ... dropboxdol.shared_folder.SharedFolderError: not a Dropbox shared-folder link (https://www.dropbox.com/scl/fo/...): 'https://example.com/scl/fo/abc'
- Return type:
- dropboxdol.shared_folder.shared_folder_name(url, *, http=<function urlopen_dropbox>)[source]#
The shared folder’s name: its download’s file name without
.zip. Only the response headers are read, not the body.""when Dropbox names none. The name comes from the server: it is reduced to a plain name (no folder part), but treat it as untrusted text.- Return type: