|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import re |
|
from typing import List |
|
|
|
_LOCAL_FILE_ID_PREFIX = "file-local-" |
|
_REMOTE_FILE_ID_PREFIX = "file-remote-" |
|
_UUID_PATTERN = r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" |
|
_LOCAL_FILE_ID_PATTERN = _LOCAL_FILE_ID_PREFIX + _UUID_PATTERN |
|
_REMOTE_FILE_ID_PATTERN = _REMOTE_FILE_ID_PREFIX + _UUID_PATTERN |
|
|
|
_compiled_local_file_id_pattern = re.compile(_LOCAL_FILE_ID_PATTERN) |
|
_compiled_remote_file_id_pattern = re.compile(_REMOTE_FILE_ID_PATTERN) |
|
|
|
|
|
def build_local_file_id_from_uuid(uuid: str) -> str: |
|
return _LOCAL_FILE_ID_PREFIX + uuid |
|
|
|
|
|
def build_remote_file_id_from_uuid(uuid: str) -> str: |
|
return _REMOTE_FILE_ID_PREFIX + uuid |
|
|
|
|
|
def is_file_id(str_: str) -> bool: |
|
return is_local_file_id(str_) or is_remote_file_id(str_) |
|
|
|
|
|
def is_local_file_id(str_: str) -> bool: |
|
return _compiled_local_file_id_pattern.fullmatch(str_) is not None |
|
|
|
|
|
def is_remote_file_id(str_: str) -> bool: |
|
return _compiled_remote_file_id_pattern.fullmatch(str_) is not None |
|
|
|
|
|
def extract_file_ids(str_: str) -> List[str]: |
|
return extract_local_file_ids(str_) + extract_remote_file_ids(str_) |
|
|
|
|
|
def extract_local_file_ids(str_: str) -> List[str]: |
|
return _compiled_local_file_id_pattern.findall(str_) |
|
|
|
|
|
def extract_remote_file_ids(str_: str) -> List[str]: |
|
return _compiled_remote_file_id_pattern.findall(str_) |
|
|