Utils
utils
Base64ToBytes(data)
Converts a base64 encoded string to bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
str
|
The base64 encoded string to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The decoded bytes. |
BytesToBase64(data)
Converts a byte array to a base64 encoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
The byte array to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The base64 encoded string. |
DetectStringType(value)
Detects the type of a string value. Possible types are: "url", "int", "float", "bool", "list", "dict", "tuple", "hex", "binary", "string".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
str
|
The string value to detect the type of. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The type of the string value. |
GetDictValue(dictionary, key, defaultValue=None)
Retrieves the value associated with the given key from the dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary |
dict
|
The dictionary to retrieve the value from. |
required |
key |
str
|
The key to look for in the dictionary. |
required |
defaultValue |
object
|
The default value to return if the key is not found. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
The value associated with the key if found, otherwise the defaultValue. |
GetURLBytes(url)
Retrieves the content of a URL as bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
The URL to retrieve the content from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The content of the URL as bytes. |
GetURLJson(url)
Sends a GET request to the specified URL and returns the response as a JSON object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
The URL to send the GET request to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The JSON response from the URL. |
Raises:
| Type | Description |
|---|---|
RequestException
|
If an error occurs while making the request. |
GetURLText(url)
Retrieves the text content of a given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
The URL to retrieve the text from. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The text content of the URL. |
Raises:
| Type | Description |
|---|---|
RequestException
|
If an error occurs while making the request. |
ReadFromPath(path)
Reads the contents of a file from the given path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The contents of the file as bytes. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
IOError
|
If there is an error reading the file. |
ReadFromPathBase64(path)
Reads the contents of a file at the given path and returns the base64-encoded data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The base64-encoded data read from the file. |
SanitizeURL(url)
Sanitizes a URL by removing any whitespace characters, converting dropbox links to direct download links, and blocking any blacklisted urls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
The URL to sanitize. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The sanitized URL. |
SaveToPath(data, path)
Saves the given data to the specified path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
The data to be saved. |
required | |
path |
The path where the data will be saved. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
getRootPath(defaultPath='/root')
Returns the root path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaultPath |
str
|
The default root path. Defaults to "/root". |
'/root'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The root path. |
make_archive(source, destination)
Create an archive file from a source directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
str
|
The path to the source directory. |
required |
destination |
str
|
The path to the destination archive file. |
required |
Returns:
| Type | Description |
|---|---|
|
None |