pelican-webdav-client 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ build/
2
+ dist/
3
+ *.egg-info/
4
+ __pycache__/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .venv/
8
+ uv.lock
@@ -0,0 +1,43 @@
1
+ # Copyright (C) 2026, Pelican Project, Morgridge Institute for Research
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you
4
+ # may not use this file except in compliance with the License. You may
5
+ # obtain a copy of the License at
6
+
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ repos:
16
+ - repo: https://github.com/pre-commit/pre-commit-hooks
17
+ rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # frozen: v6.0.0
18
+ hooks:
19
+ - id: trailing-whitespace
20
+ - id: end-of-file-fixer
21
+ - id: check-yaml
22
+ - repo: https://github.com/astral-sh/ruff-pre-commit
23
+ rev: 25bcf95026b96e2dd3c0aec3090c3d6ef6ca2e6c # frozen: v0.17.3
24
+ hooks:
25
+ - id: ruff-check
26
+ args: ["--fix"]
27
+ - id: ruff-format
28
+ - repo: https://github.com/RobertCraigie/pyright-python
29
+ rev: 1aa6dfeb849ae43fb6f16fc17228bcbd358a19c3 # frozen: v1.1.414
30
+ hooks:
31
+ - id: pyright
32
+ pass_filenames: false
33
+ additional_dependencies:
34
+ - aiohttp
35
+ - repo: https://github.com/zizmorcore/zizmor-pre-commit
36
+ rev: c92afdf2c6ca336aaa8f39e2bd8d48f62dbd8e1f # frozen: v1.31.1
37
+ hooks:
38
+ - id: zizmor
39
+ files: "^\\.github"
40
+ args: [--persona=pedantic]
41
+
42
+ # Global exclusion for all hooks: a scratch example against a live federation
43
+ exclude: ^example_test\.py$
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.5
2
+ Name: pelican-webdav-client
3
+ Version: 0.1.0
4
+ Summary: A PROPFIND-only asynchronous WebDAV client for the Pelican Platform
5
+ Project-URL: Source, https://github.com/PelicanPlatform/pelican-webdav-client
6
+ Project-URL: Pelican-Source, https://github.com/PelicanPlatform/pelican
7
+ Project-URL: Bug-Reports, https://github.com/PelicanPlatform/pelican-webdav-client/issues
8
+ Author-email: Pelican Platform Developers <info@pelicanplatform.org>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: aiohttp,pelican,propfind,webdav
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: 3.15
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: aiohttp<4,>=3.9.4
25
+ Description-Content-Type: text/markdown
26
+
27
+ # pelican-webdav-client
28
+
29
+ An asynchronous WebDAV client for the [Pelican Platform](https://github.com/PelicanPlatform/pelican) that speaks `PROPFIND` and nothing else.
30
+
31
+ It exists to serve [PelicanFS](https://github.com/PelicanPlatform/pelicanfs), which uses WebDAV only to list collections and to tell objects from collections. It does not upload, download, copy, move, delete or lock anything. If you need those, use a general-purpose WebDAV client.
32
+
33
+ - Built on `aiohttp`, with no other runtime dependencies
34
+ - XML is parsed with the standard library, and documents that carry a DTD are rejected
35
+ - Requires Python 3.11 or later
36
+ - Fully typed (`py.typed`)
37
+
38
+ ## Installation
39
+
40
+ ```sh
41
+ pip install pelican-webdav-client
42
+ ```
43
+
44
+ ## Quick start
45
+
46
+ ```python
47
+ import asyncio
48
+
49
+ from pelican_webdav_client import Client, NotFoundError
50
+
51
+
52
+ async def main() -> None:
53
+ async with Client("https://origin.example.org", token="...") as client:
54
+ for resource in await client.list("/namespace/collection"):
55
+ print(resource.name, resource.is_collection, resource.size, resource.modified)
56
+
57
+ try:
58
+ info = await client.stat("/namespace/collection/file.txt")
59
+ except NotFoundError:
60
+ print("no such object")
61
+ else:
62
+ print(info.path, info.size, info.content_type)
63
+
64
+
65
+ asyncio.run(main())
66
+ ```
67
+
68
+ ## The client
69
+
70
+ ```python
71
+ Client(
72
+ base_url: str,
73
+ *,
74
+ token: str | None = None,
75
+ ssl: bool | ssl.SSLContext = True,
76
+ session: aiohttp.ClientSession | None = None,
77
+ timeout: aiohttp.ClientTimeout | None = None,
78
+ )
79
+ ```
80
+
81
+ | Argument | Meaning |
82
+ |------------|---------|
83
+ | `base_url` | The server, as an absolute URL, plus any path prefix the resources live under. |
84
+ | `token` | Sent as `Authorization: Bearer <token>` on every request. |
85
+ | `ssl` | Passed to aiohttp unchanged: `True` verifies certificates, `False` skips verification, or pass your own `ssl.SSLContext` (for example, one that trusts a private CA). |
86
+ | `session` | An aiohttp session to send requests through. If you pass one in, you own it and the client leaves it open. If you don't, the client creates its own on first use and closes it in `close()`. |
87
+ | `timeout` | An `aiohttp.ClientTimeout` for each request. Defaults to the session's timeout. |
88
+
89
+ `Client` is an async context manager, and leaving the `async with` block calls `close()`.
90
+
91
+ ### Methods
92
+
93
+ | Method | Returns | What it does |
94
+ |--------|---------|--------------|
95
+ | `list(path)` | `list[Resource]` | The members of the collection at `path`, without the collection itself. Sends `Depth: 1` to the collection's slash form, so a trailing slash on `path` is optional. |
96
+ | `stat(path)` | `Resource` | What the server says about the resource at `path`. Raises `NotFoundError` on a 404, and also when the reply doesn't describe `path`. |
97
+ | `is_collection(path)` | `bool` | Shorthand for `(await stat(path)).is_collection`. |
98
+ | `exists(path)` | `bool` | Judged from the status code alone: a 404 gives `False`, any success gives `True`, and any other error raises. Unlike `stat`, it doesn't care what the body says. |
99
+ | `propfind(path, *, depth=0)` | `list[Resource]` | The raw result: every resource the server describes in the reply, including the target itself. `depth` is `0`, `1` or `"infinity"`. |
100
+ | `url(path)` | `yarl.URL` | The URL a request for `path` is sent to. |
101
+
102
+ Every method reads or releases its response before it returns or raises, so the client never holds a connection open between calls.
103
+
104
+ ### Paths
105
+
106
+ - **Paths go in decoded.** Pass paths as the server should see them, and the client percent-encodes them. `"a b"` is sent as `a%20b`, and a `%` in a path is a literal percent sign (`"100%"` is sent as `100%25`). A missing leading slash is added for you.
107
+ - **Paths are relative to `base_url`.** The client adds `base_url`'s path prefix to each request and strips it from each `Resource.path` it returns. If you root the client at an origin's data endpoint, you can work entirely in namespace paths. A resource the server reports outside the prefix keeps its full path.
108
+ - **Trailing slashes matter.** Pelican origins answer a collection's slash form and reject an object's. `stat`, `exists`, `is_collection` and `propfind` send `path` exactly as given, while `list` always adds the slash.
109
+ - **Redirects are followed.** The reply is matched against the URL that finally answered, so a server that redirects one form of a URL to another still gets a correct `stat` or `list`.
110
+
111
+ ## `Resource`
112
+
113
+ A frozen dataclass describing one entry in a `PROPFIND` reply.
114
+
115
+ | Field | Type | Notes |
116
+ |-------|------|-------|
117
+ | `path` | `str` | Decoded and relative to `base_url`. Collections end in `/` and nothing else does. |
118
+ | `name` | `str` | The final path component, or `""` for the root (a property). |
119
+ | `is_collection` | `bool` | From `DAV:resourcetype`. |
120
+ | `size` | `int \| None` | From `DAV:getcontentlength`. It is always `None` for a collection, and `None` when the server sent no usable length. |
121
+ | `modified` | `datetime \| None` | From `DAV:getlastmodified`, as a timezone-aware datetime. RFC 1123 and ISO 8601 dates are both accepted, and a date with no zone is taken as UTC. |
122
+ | `content_type` | `str \| None` | From `DAV:getcontenttype`. |
123
+
124
+ The parser only reads properties from `propstat` blocks with a 2xx status. It accepts `href`s that are relative, path-absolute or full URLs.
125
+
126
+ ## Errors
127
+
128
+ ```
129
+ WebDavError
130
+ ├── ResponseError the server answered with a 4xx or 5xx status
131
+ │ ├── UnauthorizedError 401
132
+ │ ├── ForbiddenError 403
133
+ │ ├── NotFoundError 404, or a stat() reply that doesn't describe the path
134
+ │ └── MethodNotAllowedError 405
135
+ └── InvalidResponseError a successful reply whose body is not a DAV:multistatus document
136
+ ```
137
+
138
+ A `ResponseError` has `method`, `url`, `status`, `reason` and `body` attributes (`body` is the decoded response body, where servers usually explain themselves). An `InvalidResponseError` has `method`, `url` and `message`.
139
+
140
+ Transport failures such as refused connections, TLS errors and timeouts are not wrapped. They reach you as aiohttp's own exceptions.
141
+
142
+ ## Logging
143
+
144
+ Requests and response statuses are logged at `DEBUG` level to the `pelican_webdav_client.client` logger. Tokens are never logged.
145
+
146
+ ## Development
147
+
148
+ ```sh
149
+ git clone https://github.com/PelicanPlatform/pelican-webdav-client
150
+ cd pelican-webdav-client
151
+ python -m venv .venv && source .venv/bin/activate
152
+ pip install -e . --group dev
153
+ pytest
154
+ ```
155
+
156
+ The tests run against a local [`pytest-httpserver`](https://github.com/csernazs/pytest-httpserver), so they need no network access and no Pelican federation. Pytest is set to fail on any warning, which means an unclosed session or connection fails the test that leaked it.
157
+
158
+ Linting, formatting and type checking (ruff, pyright and zizmor for the workflows) run through pre-commit:
159
+
160
+ ```sh
161
+ pre-commit install
162
+ pre-commit run --all-files
163
+ ```
164
+
165
+ CI runs the same hooks, then runs the test suite on Python 3.11 through 3.15 on Linux, and on 3.11 and 3.15 on macOS and Windows.
166
+
167
+ ## License
168
+
169
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,143 @@
1
+ # pelican-webdav-client
2
+
3
+ An asynchronous WebDAV client for the [Pelican Platform](https://github.com/PelicanPlatform/pelican) that speaks `PROPFIND` and nothing else.
4
+
5
+ It exists to serve [PelicanFS](https://github.com/PelicanPlatform/pelicanfs), which uses WebDAV only to list collections and to tell objects from collections. It does not upload, download, copy, move, delete or lock anything. If you need those, use a general-purpose WebDAV client.
6
+
7
+ - Built on `aiohttp`, with no other runtime dependencies
8
+ - XML is parsed with the standard library, and documents that carry a DTD are rejected
9
+ - Requires Python 3.11 or later
10
+ - Fully typed (`py.typed`)
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ pip install pelican-webdav-client
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```python
21
+ import asyncio
22
+
23
+ from pelican_webdav_client import Client, NotFoundError
24
+
25
+
26
+ async def main() -> None:
27
+ async with Client("https://origin.example.org", token="...") as client:
28
+ for resource in await client.list("/namespace/collection"):
29
+ print(resource.name, resource.is_collection, resource.size, resource.modified)
30
+
31
+ try:
32
+ info = await client.stat("/namespace/collection/file.txt")
33
+ except NotFoundError:
34
+ print("no such object")
35
+ else:
36
+ print(info.path, info.size, info.content_type)
37
+
38
+
39
+ asyncio.run(main())
40
+ ```
41
+
42
+ ## The client
43
+
44
+ ```python
45
+ Client(
46
+ base_url: str,
47
+ *,
48
+ token: str | None = None,
49
+ ssl: bool | ssl.SSLContext = True,
50
+ session: aiohttp.ClientSession | None = None,
51
+ timeout: aiohttp.ClientTimeout | None = None,
52
+ )
53
+ ```
54
+
55
+ | Argument | Meaning |
56
+ |------------|---------|
57
+ | `base_url` | The server, as an absolute URL, plus any path prefix the resources live under. |
58
+ | `token` | Sent as `Authorization: Bearer <token>` on every request. |
59
+ | `ssl` | Passed to aiohttp unchanged: `True` verifies certificates, `False` skips verification, or pass your own `ssl.SSLContext` (for example, one that trusts a private CA). |
60
+ | `session` | An aiohttp session to send requests through. If you pass one in, you own it and the client leaves it open. If you don't, the client creates its own on first use and closes it in `close()`. |
61
+ | `timeout` | An `aiohttp.ClientTimeout` for each request. Defaults to the session's timeout. |
62
+
63
+ `Client` is an async context manager, and leaving the `async with` block calls `close()`.
64
+
65
+ ### Methods
66
+
67
+ | Method | Returns | What it does |
68
+ |--------|---------|--------------|
69
+ | `list(path)` | `list[Resource]` | The members of the collection at `path`, without the collection itself. Sends `Depth: 1` to the collection's slash form, so a trailing slash on `path` is optional. |
70
+ | `stat(path)` | `Resource` | What the server says about the resource at `path`. Raises `NotFoundError` on a 404, and also when the reply doesn't describe `path`. |
71
+ | `is_collection(path)` | `bool` | Shorthand for `(await stat(path)).is_collection`. |
72
+ | `exists(path)` | `bool` | Judged from the status code alone: a 404 gives `False`, any success gives `True`, and any other error raises. Unlike `stat`, it doesn't care what the body says. |
73
+ | `propfind(path, *, depth=0)` | `list[Resource]` | The raw result: every resource the server describes in the reply, including the target itself. `depth` is `0`, `1` or `"infinity"`. |
74
+ | `url(path)` | `yarl.URL` | The URL a request for `path` is sent to. |
75
+
76
+ Every method reads or releases its response before it returns or raises, so the client never holds a connection open between calls.
77
+
78
+ ### Paths
79
+
80
+ - **Paths go in decoded.** Pass paths as the server should see them, and the client percent-encodes them. `"a b"` is sent as `a%20b`, and a `%` in a path is a literal percent sign (`"100%"` is sent as `100%25`). A missing leading slash is added for you.
81
+ - **Paths are relative to `base_url`.** The client adds `base_url`'s path prefix to each request and strips it from each `Resource.path` it returns. If you root the client at an origin's data endpoint, you can work entirely in namespace paths. A resource the server reports outside the prefix keeps its full path.
82
+ - **Trailing slashes matter.** Pelican origins answer a collection's slash form and reject an object's. `stat`, `exists`, `is_collection` and `propfind` send `path` exactly as given, while `list` always adds the slash.
83
+ - **Redirects are followed.** The reply is matched against the URL that finally answered, so a server that redirects one form of a URL to another still gets a correct `stat` or `list`.
84
+
85
+ ## `Resource`
86
+
87
+ A frozen dataclass describing one entry in a `PROPFIND` reply.
88
+
89
+ | Field | Type | Notes |
90
+ |-------|------|-------|
91
+ | `path` | `str` | Decoded and relative to `base_url`. Collections end in `/` and nothing else does. |
92
+ | `name` | `str` | The final path component, or `""` for the root (a property). |
93
+ | `is_collection` | `bool` | From `DAV:resourcetype`. |
94
+ | `size` | `int \| None` | From `DAV:getcontentlength`. It is always `None` for a collection, and `None` when the server sent no usable length. |
95
+ | `modified` | `datetime \| None` | From `DAV:getlastmodified`, as a timezone-aware datetime. RFC 1123 and ISO 8601 dates are both accepted, and a date with no zone is taken as UTC. |
96
+ | `content_type` | `str \| None` | From `DAV:getcontenttype`. |
97
+
98
+ The parser only reads properties from `propstat` blocks with a 2xx status. It accepts `href`s that are relative, path-absolute or full URLs.
99
+
100
+ ## Errors
101
+
102
+ ```
103
+ WebDavError
104
+ ├── ResponseError the server answered with a 4xx or 5xx status
105
+ │ ├── UnauthorizedError 401
106
+ │ ├── ForbiddenError 403
107
+ │ ├── NotFoundError 404, or a stat() reply that doesn't describe the path
108
+ │ └── MethodNotAllowedError 405
109
+ └── InvalidResponseError a successful reply whose body is not a DAV:multistatus document
110
+ ```
111
+
112
+ A `ResponseError` has `method`, `url`, `status`, `reason` and `body` attributes (`body` is the decoded response body, where servers usually explain themselves). An `InvalidResponseError` has `method`, `url` and `message`.
113
+
114
+ Transport failures such as refused connections, TLS errors and timeouts are not wrapped. They reach you as aiohttp's own exceptions.
115
+
116
+ ## Logging
117
+
118
+ Requests and response statuses are logged at `DEBUG` level to the `pelican_webdav_client.client` logger. Tokens are never logged.
119
+
120
+ ## Development
121
+
122
+ ```sh
123
+ git clone https://github.com/PelicanPlatform/pelican-webdav-client
124
+ cd pelican-webdav-client
125
+ python -m venv .venv && source .venv/bin/activate
126
+ pip install -e . --group dev
127
+ pytest
128
+ ```
129
+
130
+ The tests run against a local [`pytest-httpserver`](https://github.com/csernazs/pytest-httpserver), so they need no network access and no Pelican federation. Pytest is set to fail on any warning, which means an unclosed session or connection fails the test that leaked it.
131
+
132
+ Linting, formatting and type checking (ruff, pyright and zizmor for the workflows) run through pre-commit:
133
+
134
+ ```sh
135
+ pre-commit install
136
+ pre-commit run --all-files
137
+ ```
138
+
139
+ CI runs the same hooks, then runs the test suite on Python 3.11 through 3.15 on Linux, and on 3.11 and 3.15 on macOS and Windows.
140
+
141
+ ## License
142
+
143
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,109 @@
1
+ [build-system]
2
+ requires = ["hatchling >=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pelican-webdav-client"
7
+ version = "0.1.0"
8
+ description = "A PROPFIND-only asynchronous WebDAV client for the Pelican Platform"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ authors = [
13
+ { name = "Pelican Platform Developers", email = "info@pelicanplatform.org" }
14
+ ]
15
+ keywords = ["pelican", "webdav", "propfind", "aiohttp"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Framework :: AsyncIO",
19
+ "Intended Audience :: Science/Research",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Programming Language :: Python :: 3.15",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ ]
29
+
30
+ requires-python = ">=3.11"
31
+ dependencies = [
32
+ "aiohttp >=3.9.4,<4",
33
+ ]
34
+
35
+ [project.urls]
36
+ Source = "https://github.com/PelicanPlatform/pelican-webdav-client"
37
+ Pelican-Source = "https://github.com/PelicanPlatform/pelican"
38
+ Bug-Reports = "https://github.com/PelicanPlatform/pelican-webdav-client/issues"
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ exclude = ["/.github"]
42
+
43
+ [dependency-groups]
44
+ testing = [
45
+ "pytest>=9",
46
+ "pytest-httpserver",
47
+ "trustme",
48
+ ]
49
+ dev = [{ include-group = "testing" }]
50
+
51
+ [tool.uv]
52
+ exclude-newer = "3 days"
53
+
54
+ [tool.pytest]
55
+ minversion = "9.0"
56
+ addopts = ["-ra", "--showlocals", "--import-mode=importlib"]
57
+ strict = true
58
+ filterwarnings = ["error"]
59
+ log_level = "INFO"
60
+ testpaths = ["test"]
61
+
62
+ [tool.ruff]
63
+ line-length = 200
64
+ # A scratch example against a live federation, not part of the package
65
+ exclude = ["example_test.py"]
66
+ show-fixes = true
67
+
68
+ [tool.ruff.lint]
69
+ extend-select = [
70
+ "E", # pycodestyle errors
71
+ "F", # pyflakes
72
+ "W", # pycodestyle warnings
73
+ "ANN", # flake8-annotations
74
+ "ARG", # flake8-unused-arguments
75
+ "B", # flake8-bugbear
76
+ "C4", # flake8-comprehensions
77
+ "EM", # flake8-errmsg
78
+ "EXE", # flake8-executable
79
+ "FURB", # refurb
80
+ "G", # flake8-logging-format
81
+ "I", # isort
82
+ "ICN", # flake8-import-conventions
83
+ "ISC", # flake8-implicit-str-concat
84
+ "LOG", # flake8-logging
85
+ "PERF", # perflint
86
+ "PGH", # pygrep-hooks
87
+ "PIE", # flake8-pie
88
+ "PL", # pylint
89
+ "PT", # flake8-pytest-style
90
+ "PTH", # flake8-use-pathlib
91
+ "RET", # flake8-return
92
+ "RSE", # flake8-raise
93
+ "RUF", # Ruff-specific
94
+ "SIM", # flake8-simplify
95
+ "T20", # flake8-print
96
+ "UP", # pyupgrade
97
+ "YTT", # flake8-2020
98
+ ]
99
+ ignore = [
100
+ "ANN401", # The expat callbacks and the error "message" take whatever the caller hands them
101
+ "PLR09", # Too many <...>
102
+ "PLR2004", # Magic value used in comparison
103
+ ]
104
+
105
+ [tool.ruff.lint.flake8-unused-arguments]
106
+ ignore-variadic-names = true
107
+
108
+ [tool.ruff.lint.per-file-ignores]
109
+ "test/**" = ["ANN", "ARG001", "PLC0415", "T20"]