Skip to main content

parsers.py

Source: sunholo/utils/parsers.py

Functions

contains_url(message_data)

Check if the provided text contains a URL.

Args: message_data (str): The text to check.

Returns: bool: True if the text contains a URL, False otherwise.

Example:

text = "Visit us at https://example.com for more details."
has_url = contains_url(text)
print(has_url) # True

extract_urls(text)

Extract all URLs from the provided text.

Args: text (str): The text to extract URLs from.

Returns: list[str]: A list of URLs found in the text.

Example:

text = "Check out https://example.com and http://another.com."
urls = extract_urls(text)
print(urls) # ['https://example.com', 'http://another.com']

remove_whitespace(page_content: str)

Remove newline, carriage return, tab characters, and double spaces from the provided string.

Args: page_content (str): The string to clean.

Returns: str: The cleaned string.

Example:

raw_text = "Hello,
world! This is an example."
cleaned_text = remove_whitespace(raw_text)
print(cleaned_text) # Outputs 'Hello, world! This is an example.'

check_kwargs_support(func)

Check if the function 'func' accepts arbitrary keyword arguments (**kwargs).

Args: func (callable): The function to check.

Returns: bool: True if **kwargs is accepted, False otherwise.

get_clean_website_name(url: str)

No docstring available.

compute_sha1_from_content(content)

Compute the SHA-1 hash of the provided content.

Args: content (bytes): The content to hash.

Returns: str: The SHA-1 hash of the content.

Example:

content = b"Hello, world!"
content_hash = compute_sha1_from_content(content)
print(content_hash) # Outputs the SHA-1 hash of the content

compute_sha1_from_file(file_path)

Compute the SHA-1 hash of a file.

Args: file_path (str): The path to the file.

Returns: str: The SHA-1 hash of the file.

Example:

file_path = 'path/to/file.txt'
file_hash = compute_sha1_from_file(file_path)
print(file_hash) # Outputs the SHA-1 hash of the file

escape_braces(text)

Escapes single braces in the text by converting them to double braces.

Args: text (str): The input string containing single braces.

Returns: str: The modified string with single braces converted to double braces.

sanitize_cloudrun_name(name: str) -> str

Sanitizes the project name to be a valid Cloud Run service name.

  • Converts to lowercase.
  • Replaces invalid characters with hyphens.
  • Ensures the name starts with a letter.
  • Trims the name to be less than 64 characters.
  • Removes trailing hyphens.

Args: name (str): The original project name.

Returns: str: The sanitized project name.

validate_extension_id(ext_id)

Ensures the passed string fits the criteria for an extension ID. If not, changes it so it will be.

Criteria:

  • Length should be 4-63 characters.
  • Valid characters are lowercase letters, numbers, and hyphens ("-").
  • Should start with a number or a lowercase letter.

Args: ext_id (str): The extension ID to validate and correct.

Returns: str: The validated and corrected extension ID.

Sunholo Multivac

Get in touch to see if we can help with your GenAI project.

Contact us

Other Links

Sunholo Multivac - GenAIOps

Copyright ©

Holosun ApS 2024