source: trunk/src/allmydata/storage/common.py

Last change on this file was 53084f7, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-27T23:49:07Z

remove more Python2 compatibility

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"""
2Ported to Python 3.
3"""
4
5import os.path
6from allmydata.util import base32
7
8# Backwards compatibility.
9from allmydata.interfaces import DataTooLargeError  # noqa: F401
10
11class 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
22class UnknownMutableContainerVersionError(UnknownContainerVersionError):
23    pass
24
25class UnknownImmutableContainerVersionError(UnknownContainerVersionError):
26    pass
27
28def si_b2a(storageindex):
29    return base32.b2a(storageindex)
30
31def si_a2b(ascii_storageindex):
32    return base32.a2b(ascii_storageindex)
33
34def si_to_human_readable(storageindex: bytes) -> str:
35    """Create human-readable string of storage index."""
36    return str(base32.b2a(storageindex), "ascii")
37
38def 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.