oaknut-afs 10.0.1__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.
- oaknut_afs-10.0.1/LICENSE +21 -0
- oaknut_afs-10.0.1/PKG-INFO +38 -0
- oaknut_afs-10.0.1/README.md +11 -0
- oaknut_afs-10.0.1/pyproject.toml +54 -0
- oaknut_afs-10.0.1/setup.cfg +4 -0
- oaknut_afs-10.0.1/src/oaknut/afs/__init__.py +95 -0
- oaknut_afs-10.0.1/src/oaknut/afs/access.py +198 -0
- oaknut_afs-10.0.1/src/oaknut/afs/afs.py +814 -0
- oaknut_afs-10.0.1/src/oaknut/afs/allocator.py +341 -0
- oaknut_afs-10.0.1/src/oaknut/afs/bitmap.py +415 -0
- oaknut_afs-10.0.1/src/oaknut/afs/cli.py +232 -0
- oaknut_afs-10.0.1/src/oaknut/afs/directory.py +951 -0
- oaknut_afs-10.0.1/src/oaknut/afs/exceptions.py +201 -0
- oaknut_afs-10.0.1/src/oaknut/afs/host_import.py +143 -0
- oaknut_afs-10.0.1/src/oaknut/afs/info_sector.py +276 -0
- oaknut_afs-10.0.1/src/oaknut/afs/libraries/__init__.py +116 -0
- oaknut_afs-10.0.1/src/oaknut/afs/map_sector.py +551 -0
- oaknut_afs-10.0.1/src/oaknut/afs/merge.py +148 -0
- oaknut_afs-10.0.1/src/oaknut/afs/passwords.py +424 -0
- oaknut_afs-10.0.1/src/oaknut/afs/path.py +371 -0
- oaknut_afs-10.0.1/src/oaknut/afs/types.py +168 -0
- oaknut_afs-10.0.1/src/oaknut/afs/wfsinit/__init__.py +37 -0
- oaknut_afs-10.0.1/src/oaknut/afs/wfsinit/driver.py +265 -0
- oaknut_afs-10.0.1/src/oaknut/afs/wfsinit/layout.py +63 -0
- oaknut_afs-10.0.1/src/oaknut/afs/wfsinit/partition.py +264 -0
- oaknut_afs-10.0.1/src/oaknut_afs.egg-info/PKG-INFO +38 -0
- oaknut_afs-10.0.1/src/oaknut_afs.egg-info/SOURCES.txt +53 -0
- oaknut_afs-10.0.1/src/oaknut_afs.egg-info/dependency_links.txt +1 -0
- oaknut_afs-10.0.1/src/oaknut_afs.egg-info/entry_points.txt +2 -0
- oaknut_afs-10.0.1/src/oaknut_afs.egg-info/requires.txt +3 -0
- oaknut_afs-10.0.1/src/oaknut_afs.egg-info/top_level.txt +1 -0
- oaknut_afs-10.0.1/tests/test_access.py +118 -0
- oaknut_afs-10.0.1/tests/test_afs_large_objects.py +111 -0
- oaknut_afs-10.0.1/tests/test_afs_read.py +179 -0
- oaknut_afs-10.0.1/tests/test_afs_write.py +147 -0
- oaknut_afs-10.0.1/tests/test_allocator.py +338 -0
- oaknut_afs-10.0.1/tests/test_bitmap.py +391 -0
- oaknut_afs-10.0.1/tests/test_chain_expanding_write.py +79 -0
- oaknut_afs-10.0.1/tests/test_cli.py +101 -0
- oaknut_afs-10.0.1/tests/test_directory_growth.py +195 -0
- oaknut_afs-10.0.1/tests/test_directory_read.py +322 -0
- oaknut_afs-10.0.1/tests/test_directory_write.py +359 -0
- oaknut_afs-10.0.1/tests/test_info_sector.py +242 -0
- oaknut_afs-10.0.1/tests/test_initialise.py +124 -0
- oaknut_afs-10.0.1/tests/test_libraries_and_host_import.py +82 -0
- oaknut_afs-10.0.1/tests/test_map_chain.py +219 -0
- oaknut_afs-10.0.1/tests/test_map_sector.py +348 -0
- oaknut_afs-10.0.1/tests/test_merge.py +123 -0
- oaknut_afs-10.0.1/tests/test_merge_bugs.py +129 -0
- oaknut_afs-10.0.1/tests/test_passwords.py +121 -0
- oaknut_afs-10.0.1/tests/test_passwords_write.py +130 -0
- oaknut_afs-10.0.1/tests/test_path.py +141 -0
- oaknut_afs-10.0.1/tests/test_quota_enforcement.py +68 -0
- oaknut_afs-10.0.1/tests/test_repartition.py +123 -0
- oaknut_afs-10.0.1/tests/test_round_trip_stability.py +135 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Smallshire
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oaknut-afs
|
|
3
|
+
Version: 10.0.1
|
|
4
|
+
Summary: Acorn Level 3 File Server (AFS) filesystem support — the private on-disc format WFSINIT prepares in the tail of an old-map ADFS disc
|
|
5
|
+
Author-email: Robert Smallshire <robert@smallshire.org.uk>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rob-smallshire/oaknut
|
|
8
|
+
Project-URL: Repository, https://github.com/rob-smallshire/oaknut
|
|
9
|
+
Project-URL: Issues, https://github.com/rob-smallshire/oaknut/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Filesystems
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: oaknut-file>=10.0
|
|
24
|
+
Requires-Dist: oaknut-discimage>=10.0
|
|
25
|
+
Requires-Dist: oaknut-adfs>=10.0
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# oaknut-afs
|
|
29
|
+
|
|
30
|
+
Python library for reading and writing Acorn Level 3 File Server (AFS)
|
|
31
|
+
disc partitions — the private on-disc filesystem that the Level 3 File
|
|
32
|
+
Server serves to BBC Micro, Master, and Archimedes clients over Econet.
|
|
33
|
+
|
|
34
|
+
AFS (identified by the `AFS0` magic in its info sectors) coexists with
|
|
35
|
+
ADFS on the same disc: WFSINIT — or oaknut's `initialise()` — shrinks
|
|
36
|
+
the ADFS partition and carves an AFS region out of the tail cylinders.
|
|
37
|
+
|
|
38
|
+
Part of the [oaknut](https://github.com/rob-smallshire/oaknut) monorepo.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# oaknut-afs
|
|
2
|
+
|
|
3
|
+
Python library for reading and writing Acorn Level 3 File Server (AFS)
|
|
4
|
+
disc partitions — the private on-disc filesystem that the Level 3 File
|
|
5
|
+
Server serves to BBC Micro, Master, and Archimedes clients over Econet.
|
|
6
|
+
|
|
7
|
+
AFS (identified by the `AFS0` magic in its info sectors) coexists with
|
|
8
|
+
ADFS on the same disc: WFSINIT — or oaknut's `initialise()` — shrinks
|
|
9
|
+
the ADFS partition and carves an AFS region out of the tail cylinders.
|
|
10
|
+
|
|
11
|
+
Part of the [oaknut](https://github.com/rob-smallshire/oaknut) monorepo.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "oaknut-afs"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
authors = [{ name = "Robert Smallshire", email = "robert@smallshire.org.uk" }]
|
|
9
|
+
description = "Acorn Level 3 File Server (AFS) filesystem support — the private on-disc format WFSINIT prepares in the tail of an old-map ADFS disc"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
requires-python = ">=3.11"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: System :: Filesystems",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"oaknut-file>=10.0",
|
|
28
|
+
"oaknut-discimage>=10.0",
|
|
29
|
+
"oaknut-adfs>=10.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
oaknut-afs-disc = "oaknut.afs.cli:main"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/rob-smallshire/oaknut"
|
|
37
|
+
Repository = "https://github.com/rob-smallshire/oaknut"
|
|
38
|
+
Issues = "https://github.com/rob-smallshire/oaknut/issues"
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
test = [
|
|
42
|
+
"pytest>=8.0",
|
|
43
|
+
]
|
|
44
|
+
dev = [
|
|
45
|
+
"bump-my-version>=0.28.0",
|
|
46
|
+
"pre-commit>=3.0",
|
|
47
|
+
{include-group = "test"},
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.dynamic]
|
|
51
|
+
version = { attr = "oaknut.afs.__version__" }
|
|
52
|
+
|
|
53
|
+
[tool.setuptools.packages.find]
|
|
54
|
+
where = ["src"]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Acorn Level 3 File Server (AFS) filesystem support.
|
|
2
|
+
|
|
3
|
+
The Level 3 File Server's private on-disc filesystem, identified by
|
|
4
|
+
the ``AFS0`` magic in its info sectors. An AFS region occupies the
|
|
5
|
+
tail cylinders of an old-map ADFS hard-disc image; the ADFS partition
|
|
6
|
+
at the front of the disc coexists with it.
|
|
7
|
+
|
|
8
|
+
The ``A`` in ``AFS0`` most likely stands for *Acorn File Server*,
|
|
9
|
+
though no primary source spells it out — the ``0`` is a format version.
|
|
10
|
+
|
|
11
|
+
The full public API — read, write, merge, initialise, and CLI — is
|
|
12
|
+
implemented. See ``docs/afs-implementation-plan.md`` for the design
|
|
13
|
+
and ``docs/afs-onwire.md`` for the on-disc format specification.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__version__ = "10.0.1"
|
|
17
|
+
|
|
18
|
+
from oaknut.afs.access import AFSAccess
|
|
19
|
+
from oaknut.afs.afs import AFS, AFSNotPresentError
|
|
20
|
+
from oaknut.afs.allocator import Allocator
|
|
21
|
+
from oaknut.afs.exceptions import (
|
|
22
|
+
AFSAccessDeniedError,
|
|
23
|
+
AFSAlreadyPartitionedError,
|
|
24
|
+
AFSBrokenDirectoryError,
|
|
25
|
+
AFSBrokenMapError,
|
|
26
|
+
AFSDirectoryEntryExistsError,
|
|
27
|
+
AFSDirectoryEntryNotFoundError,
|
|
28
|
+
AFSDirectoryFullError,
|
|
29
|
+
AFSDirectoryNotEmptyError,
|
|
30
|
+
AFSDiscNotCompactedError,
|
|
31
|
+
AFSError,
|
|
32
|
+
AFSFileLockedError,
|
|
33
|
+
AFSFormatError,
|
|
34
|
+
AFSHostImportError,
|
|
35
|
+
AFSInfoSectorError,
|
|
36
|
+
AFSInsufficientADFSSpaceError,
|
|
37
|
+
AFSInsufficientSpaceError,
|
|
38
|
+
AFSMergeConflictError,
|
|
39
|
+
AFSNewMapNotSupportedError,
|
|
40
|
+
AFSPathError,
|
|
41
|
+
AFSQuotaExceededError,
|
|
42
|
+
AFSRepartitionError,
|
|
43
|
+
)
|
|
44
|
+
from oaknut.afs.host_import import import_host_tree
|
|
45
|
+
from oaknut.afs.libraries import SHIPPED_LIBRARIES, emplace_library
|
|
46
|
+
from oaknut.afs.merge import merge
|
|
47
|
+
from oaknut.afs.passwords import PasswordsFile, UserRecord
|
|
48
|
+
from oaknut.afs.path import AFSPath
|
|
49
|
+
from oaknut.afs.types import (
|
|
50
|
+
AfsDate,
|
|
51
|
+
Cylinder,
|
|
52
|
+
Geometry,
|
|
53
|
+
Sector,
|
|
54
|
+
SystemInternalName,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
__all__ = [
|
|
58
|
+
"AFS",
|
|
59
|
+
"AFSAccess",
|
|
60
|
+
"AFSNotPresentError",
|
|
61
|
+
"AFSPath",
|
|
62
|
+
"Allocator",
|
|
63
|
+
"SHIPPED_LIBRARIES",
|
|
64
|
+
"emplace_library",
|
|
65
|
+
"PasswordsFile",
|
|
66
|
+
"UserRecord",
|
|
67
|
+
"import_host_tree",
|
|
68
|
+
"merge",
|
|
69
|
+
"AFSAccessDeniedError",
|
|
70
|
+
"AFSAlreadyPartitionedError",
|
|
71
|
+
"AFSBrokenDirectoryError",
|
|
72
|
+
"AFSBrokenMapError",
|
|
73
|
+
"AFSDirectoryEntryExistsError",
|
|
74
|
+
"AFSDirectoryEntryNotFoundError",
|
|
75
|
+
"AFSDirectoryFullError",
|
|
76
|
+
"AFSDirectoryNotEmptyError",
|
|
77
|
+
"AFSDiscNotCompactedError",
|
|
78
|
+
"AFSError",
|
|
79
|
+
"AFSFileLockedError",
|
|
80
|
+
"AFSFormatError",
|
|
81
|
+
"AFSHostImportError",
|
|
82
|
+
"AFSInfoSectorError",
|
|
83
|
+
"AFSInsufficientADFSSpaceError",
|
|
84
|
+
"AFSInsufficientSpaceError",
|
|
85
|
+
"AFSMergeConflictError",
|
|
86
|
+
"AFSNewMapNotSupportedError",
|
|
87
|
+
"AFSPathError",
|
|
88
|
+
"AFSQuotaExceededError",
|
|
89
|
+
"AFSRepartitionError",
|
|
90
|
+
"AfsDate",
|
|
91
|
+
"Cylinder",
|
|
92
|
+
"Geometry",
|
|
93
|
+
"Sector",
|
|
94
|
+
"SystemInternalName",
|
|
95
|
+
]
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""AFS on-disc access byte.
|
|
2
|
+
|
|
3
|
+
The Level 3 File Server stores an object's access attributes in a
|
|
4
|
+
single byte at offset 20 of its directory entry (see
|
|
5
|
+
``docs/afs-onwire.md`` §Directory entry). The bit layout **differs**
|
|
6
|
+
from the standard Acorn attribute byte used by client-side NFS/ANFS
|
|
7
|
+
clients and by ``oaknut.file.Access``. Per ``Uade01.asm:257-275`` and
|
|
8
|
+
Beebmaster's PDF:
|
|
9
|
+
|
|
10
|
+
==== =========================
|
|
11
|
+
Bit Meaning
|
|
12
|
+
==== =========================
|
|
13
|
+
0 Public read
|
|
14
|
+
1 Public write
|
|
15
|
+
2 Owner read
|
|
16
|
+
3 Owner write
|
|
17
|
+
4 Locked
|
|
18
|
+
5 Directory type (1 = dir)
|
|
19
|
+
6-7 Unused on disc
|
|
20
|
+
==== =========================
|
|
21
|
+
|
|
22
|
+
Masks from the ROM:
|
|
23
|
+
|
|
24
|
+
- ``ACCMSK = 0x1F`` — bits 0–4 (locked + all R/W bits)
|
|
25
|
+
- ``TLAMSK = 0x3F`` — type + locked + all R/W bits
|
|
26
|
+
- ``RWMSK = 0x0F`` — owner + public R/W only
|
|
27
|
+
|
|
28
|
+
The access string form used by Econet clients (``"LR/WR"``, ``"LWR/R"``,
|
|
29
|
+
``"D/"``, etc.) is the same form users see in ``*EX`` listings and is
|
|
30
|
+
documented in the Beebmaster PDF's "Example Access Strings" table. This
|
|
31
|
+
module parses and formats that string.
|
|
32
|
+
|
|
33
|
+
Conversions to and from the wire-format ``oaknut.file.Access`` (which
|
|
34
|
+
uses a different bit layout) are provided so that ``host_bridge``
|
|
35
|
+
metadata round-trips correctly.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
from enum import IntFlag
|
|
41
|
+
|
|
42
|
+
# ---------------------------------------------------------------------------
|
|
43
|
+
# Bit positions — the on-disc layout.
|
|
44
|
+
# ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
_BIT_PUBLIC_READ = 0x01
|
|
47
|
+
_BIT_PUBLIC_WRITE = 0x02
|
|
48
|
+
_BIT_OWNER_READ = 0x04
|
|
49
|
+
_BIT_OWNER_WRITE = 0x08
|
|
50
|
+
_BIT_LOCKED = 0x10
|
|
51
|
+
_BIT_DIRECTORY = 0x20
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class AFSAccess(IntFlag):
|
|
55
|
+
"""On-disc AFS access byte.
|
|
56
|
+
|
|
57
|
+
The integer value of any combination is the byte stored in the
|
|
58
|
+
``DRACCS`` field of a directory entry — it may be written straight
|
|
59
|
+
into a ``SectorsView`` without further translation::
|
|
60
|
+
|
|
61
|
+
entry_bytes[20] = int(AFSAccess.from_string("LR/R"))
|
|
62
|
+
|
|
63
|
+
Composable with ``|``::
|
|
64
|
+
|
|
65
|
+
AFSAccess.OWNER_READ | AFSAccess.OWNER_WRITE | AFSAccess.PUBLIC_READ
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
PUBLIC_READ = _BIT_PUBLIC_READ
|
|
69
|
+
PUBLIC_WRITE = _BIT_PUBLIC_WRITE
|
|
70
|
+
OWNER_READ = _BIT_OWNER_READ
|
|
71
|
+
OWNER_WRITE = _BIT_OWNER_WRITE
|
|
72
|
+
LOCKED = _BIT_LOCKED
|
|
73
|
+
DIRECTORY = _BIT_DIRECTORY
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_byte(cls, value: int) -> AFSAccess:
|
|
77
|
+
"""Build an ``AFSAccess`` from a raw access byte.
|
|
78
|
+
|
|
79
|
+
Unknown bits (6 and 7) are silently ignored, matching the
|
|
80
|
+
server's tolerance for junk in the unused bits.
|
|
81
|
+
"""
|
|
82
|
+
return cls(value & 0x3F)
|
|
83
|
+
|
|
84
|
+
def to_byte(self) -> int:
|
|
85
|
+
"""Return the raw access byte suitable for on-disc storage."""
|
|
86
|
+
return int(self) & 0x3F
|
|
87
|
+
|
|
88
|
+
# -----------------------------------------------------------------
|
|
89
|
+
# String form — "LWR/WR" style
|
|
90
|
+
# -----------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
def to_string(self) -> str:
|
|
93
|
+
"""Format as the human-readable ``"owner/public"`` string.
|
|
94
|
+
|
|
95
|
+
Directory objects render as ``"D/"`` or ``"DL/"`` — consistent
|
|
96
|
+
with the server's ``*EX`` listings and with the Beebmaster PDF.
|
|
97
|
+
"""
|
|
98
|
+
if self & AFSAccess.DIRECTORY:
|
|
99
|
+
owner = "D"
|
|
100
|
+
if self & AFSAccess.LOCKED:
|
|
101
|
+
owner += "L"
|
|
102
|
+
return f"{owner}/"
|
|
103
|
+
|
|
104
|
+
owner = ""
|
|
105
|
+
if self & AFSAccess.LOCKED:
|
|
106
|
+
owner += "L"
|
|
107
|
+
if self & AFSAccess.OWNER_WRITE:
|
|
108
|
+
owner += "W"
|
|
109
|
+
if self & AFSAccess.OWNER_READ:
|
|
110
|
+
owner += "R"
|
|
111
|
+
|
|
112
|
+
public = ""
|
|
113
|
+
if self & AFSAccess.PUBLIC_WRITE:
|
|
114
|
+
public += "W"
|
|
115
|
+
if self & AFSAccess.PUBLIC_READ:
|
|
116
|
+
public += "R"
|
|
117
|
+
|
|
118
|
+
return f"{owner}/{public}"
|
|
119
|
+
|
|
120
|
+
@classmethod
|
|
121
|
+
def from_string(cls, text: str) -> AFSAccess:
|
|
122
|
+
"""Parse an ``"owner/public"`` access string.
|
|
123
|
+
|
|
124
|
+
Accepts the forms in the Beebmaster PDF's "Example Access
|
|
125
|
+
Strings" table:
|
|
126
|
+
|
|
127
|
+
- ``"/"`` — no access at all (byte 0x00)
|
|
128
|
+
- ``"L/"`` — locked, otherwise no access
|
|
129
|
+
- ``"LR/R"``, ``"LWR/WR"``, ``"WR/R"``, ``"R/"`` …
|
|
130
|
+
- ``"D/"``, ``"DL/"`` — directories (the access bits are ignored
|
|
131
|
+
for directories per the PDF; the server only honours locked)
|
|
132
|
+
|
|
133
|
+
Letters may appear in any order within each side, but the
|
|
134
|
+
forward slash is mandatory. Upper/lower case is accepted;
|
|
135
|
+
whitespace is not.
|
|
136
|
+
"""
|
|
137
|
+
if "/" not in text:
|
|
138
|
+
raise ValueError(f"AFSAccess.from_string: missing '/' in {text!r}")
|
|
139
|
+
|
|
140
|
+
owner, public = text.split("/", 1)
|
|
141
|
+
owner = owner.upper()
|
|
142
|
+
public = public.upper()
|
|
143
|
+
|
|
144
|
+
result = cls(0)
|
|
145
|
+
|
|
146
|
+
# Directory: the 'D' prefix is recognised even though directories
|
|
147
|
+
# don't strictly use the R/W bits.
|
|
148
|
+
if "D" in owner:
|
|
149
|
+
result |= cls.DIRECTORY
|
|
150
|
+
# Directories may only be locked or unlocked; the server
|
|
151
|
+
# ignores R/W on a directory.
|
|
152
|
+
if "L" in owner:
|
|
153
|
+
result |= cls.LOCKED
|
|
154
|
+
_reject_unexpected(owner, "DL", text)
|
|
155
|
+
if public:
|
|
156
|
+
raise ValueError(
|
|
157
|
+
f"AFSAccess.from_string: directories take no public access bits, got {text!r}"
|
|
158
|
+
)
|
|
159
|
+
return result
|
|
160
|
+
|
|
161
|
+
# File access.
|
|
162
|
+
if "L" in owner:
|
|
163
|
+
result |= cls.LOCKED
|
|
164
|
+
if "W" in owner:
|
|
165
|
+
result |= cls.OWNER_WRITE
|
|
166
|
+
if "R" in owner:
|
|
167
|
+
result |= cls.OWNER_READ
|
|
168
|
+
_reject_unexpected(owner, "LWR", text)
|
|
169
|
+
|
|
170
|
+
if "W" in public:
|
|
171
|
+
result |= cls.PUBLIC_WRITE
|
|
172
|
+
if "R" in public:
|
|
173
|
+
result |= cls.PUBLIC_READ
|
|
174
|
+
_reject_unexpected(public, "WR", text)
|
|
175
|
+
|
|
176
|
+
return result
|
|
177
|
+
|
|
178
|
+
# -----------------------------------------------------------------
|
|
179
|
+
# Type-checking helpers
|
|
180
|
+
# -----------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def is_directory(self) -> bool:
|
|
184
|
+
return bool(self & AFSAccess.DIRECTORY)
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def is_locked(self) -> bool:
|
|
188
|
+
return bool(self & AFSAccess.LOCKED)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _reject_unexpected(segment: str, allowed: str, original: str) -> None:
|
|
192
|
+
allowed_set = set(allowed)
|
|
193
|
+
unexpected = [c for c in segment if c not in allowed_set]
|
|
194
|
+
if unexpected:
|
|
195
|
+
raise ValueError(
|
|
196
|
+
f"AFSAccess.from_string: unexpected character(s) "
|
|
197
|
+
f"{''.join(unexpected)!r} in {original!r} (allowed: {allowed!r})"
|
|
198
|
+
)
|