Line | |
---|
1 | """ |
---|
2 | Ported to Python 3. |
---|
3 | """ |
---|
4 | |
---|
5 | import os.path |
---|
6 | from allmydata.util import base32 |
---|
7 | |
---|
8 | # Backwards compatibility. |
---|
9 | from allmydata.interfaces import DataTooLargeError # noqa: F401 |
---|
10 | |
---|
11 | class UnknownContainerVersionError(Exception): |
---|
12 | def __init__(self, filename, version): |
---|
13 | self.filename = filename |
---|
14 | self.version = version |
---|
15 | |
---|
16 | def __str__(self): |
---|
17 | return "sharefile {!r} had unexpected version {!r}".format( |
---|
18 | self.filename, |
---|
19 | self.version, |
---|
20 | ) |
---|
21 | |
---|
22 | class UnknownMutableContainerVersionError(UnknownContainerVersionError): |
---|
23 | pass |
---|
24 | |
---|
25 | class UnknownImmutableContainerVersionError(UnknownContainerVersionError): |
---|
26 | pass |
---|
27 | |
---|
28 | def si_b2a(storageindex): |
---|
29 | return base32.b2a(storageindex) |
---|
30 | |
---|
31 | def si_a2b(ascii_storageindex): |
---|
32 | return base32.a2b(ascii_storageindex) |
---|
33 | |
---|
34 | def si_to_human_readable(storageindex: bytes) -> str: |
---|
35 | """Create human-readable string of storage index.""" |
---|
36 | return str(base32.b2a(storageindex), "ascii") |
---|
37 | |
---|
38 | def storage_index_to_dir(storageindex): |
---|
39 | """Convert storage index to directory path. |
---|
40 | |
---|
41 | Returns native string. |
---|
42 | """ |
---|
43 | sia = si_b2a(storageindex) |
---|
44 | sia = sia.decode("ascii") |
---|
45 | return os.path.join(sia[:2], sia) |
---|
Note: See
TracBrowser
for help on using the repository browser.