2020-09-14 18:03:48 +00:00
|
|
|
"""
|
|
|
|
Ported to Python 3.
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
from future.utils import PY2, PY3
|
|
|
|
if PY2:
|
|
|
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
2009-02-18 21:46:55 +00:00
|
|
|
|
2009-02-21 04:03:09 +00:00
|
|
|
import os.path
|
|
|
|
from allmydata.util import base32
|
|
|
|
|
2021-09-24 14:33:26 +00:00
|
|
|
# Backwards compatibility.
|
2021-09-24 16:04:12 +00:00
|
|
|
from allmydata.interfaces import DataTooLargeError # noqa: F401
|
2021-09-24 14:33:26 +00:00
|
|
|
|
2009-03-09 02:02:01 +00:00
|
|
|
class UnknownMutableContainerVersionError(Exception):
|
|
|
|
pass
|
2009-03-09 03:07:32 +00:00
|
|
|
class UnknownImmutableContainerVersionError(Exception):
|
|
|
|
pass
|
2009-02-18 21:46:55 +00:00
|
|
|
|
2009-02-21 04:03:09 +00:00
|
|
|
|
|
|
|
def si_b2a(storageindex):
|
|
|
|
return base32.b2a(storageindex)
|
|
|
|
|
|
|
|
def si_a2b(ascii_storageindex):
|
|
|
|
return base32.a2b(ascii_storageindex)
|
|
|
|
|
|
|
|
def storage_index_to_dir(storageindex):
|
2020-08-19 15:38:59 +00:00
|
|
|
"""Convert storage index to directory path.
|
|
|
|
|
|
|
|
Returns native string.
|
|
|
|
"""
|
2009-02-21 04:03:09 +00:00
|
|
|
sia = si_b2a(storageindex)
|
2020-08-19 15:38:59 +00:00
|
|
|
if PY3:
|
|
|
|
# On Python 3 we expect paths to be unicode.
|
|
|
|
sia = sia.decode("ascii")
|
2009-02-21 04:03:09 +00:00
|
|
|
return os.path.join(sia[:2], sia)
|