Skip to content

Commit

Permalink
Identifier encoding/decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
shsdev committed Jun 1, 2024
1 parent a415432 commit df1f0ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions eatb/utils/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import fnmatch
import shutil
import mimetypes
from urllib.parse import quote, unquote

from eatb.utils.datetime import get_file_ctime_iso_date_str, EU_UI_FORMAT, get_local_datetime_now
from eatb.utils.reporters import default_reporter
Expand Down Expand Up @@ -537,6 +538,25 @@ def hex_encode(char):
mapped_identifier = safe_identifier.translate(translation_table)
return mapped_identifier

def encode_identifier(identifier: str) -> str:
"""
Encode an identifier string for safe inclusion in a URL.
:param identifier: The identifier string to be encoded.
:return: The encoded identifier string.
"""
return quote(to_safe_filename(identifier))


def decode_identifier(encoded_identifier: str) -> str:
"""
Decode an identifier string for safe inclusion in a URL.
:param encoded_identifier: The encoded identifier string to be decoded.
:return: The decoded identifier string.
"""
return from_safe_filename(unquote(encoded_identifier))

class FileBinaryDataChunks(object):
"""
Generator to iteratively read binary chunks of a large file
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Pairtree
#PyICU==2.8
importlib_resources
opf-fido==1.6.1
eark-validator==1.1.1
eark-validator==1.1.1
urllib3==2.2.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="eatb",
version="0.2.3",
version="0.2.4",
author="E-ARK Foundation",
author_email="admin@e-ark-foundation.eu",
license='MIT',
Expand Down

0 comments on commit df1f0ca

Please sign in to comment.