-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into docs/disable-preview
- Loading branch information
Showing
5 changed files
with
43 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Transcoding related utility functions.""" | ||
from typing import Tuple | ||
|
||
TRANSCODING_SEPARATOR = "@" | ||
|
||
|
||
def _transcode_split(element: str) -> Tuple[str, str]: | ||
"""Split the name by the transcoding separator. | ||
If the transcoding part is missing, empty string will be put in. | ||
Returns: | ||
Node input/output name before the transcoding separator, if present. | ||
Raises: | ||
ValueError: Raised if more than one transcoding separator | ||
is present in the name. | ||
""" | ||
split_name = element.split(TRANSCODING_SEPARATOR) | ||
|
||
if len(split_name) > 2: # noqa: PLR2004 | ||
raise ValueError( # pragma: no cover | ||
f"Expected maximum 1 transcoding separator, found {len(split_name) - 1} " | ||
f"instead: '{element}'." | ||
) | ||
if len(split_name) == 1: | ||
split_name.append("") | ||
|
||
return tuple(split_name) # type: ignore | ||
|
||
|
||
def _strip_transcoding(element: str) -> str: | ||
"""Strip out the transcoding separator and anything that follows. | ||
Returns: | ||
Node input/output name before the transcoding separator, if present. | ||
Raises: | ||
ValueError: Raised if more than one transcoding separator | ||
is present in the name. | ||
""" | ||
return _transcode_split(element)[0] |