-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use proper xpaths, convert types
- Loading branch information
1 parent
48781b0
commit 62455b8
Showing
2 changed files
with
53 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-FileCopyrightText: 2024-present linuxdaemon <linuxdaemon.irc@gmail.com> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
from typing import Union | ||
|
||
|
||
def to_str(text: Union[str, bytes, bytearray, memoryview]) -> str: | ||
"""Convert bytes, bytearray, memoryview, or str to str. | ||
Args: | ||
text: Input value | ||
Returns: | ||
decoded output | ||
Examples: | ||
>>> to_str("aaa") | ||
'aaa' | ||
>>> to_str(b'bb') | ||
'bb' | ||
>>> to_str(memoryview(b'bb')) | ||
'bb' | ||
>>> to_str(bytearray(b'cc')) | ||
'cc' | ||
""" | ||
if isinstance(text, (bytes, bytearray)): | ||
return text.decode() | ||
|
||
if isinstance(text, memoryview): | ||
return to_str(text.tobytes()) | ||
|
||
return text |