hippius 0.1.12__py3-none-any.whl → 0.1.14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hippius_sdk/utils.py DELETED
@@ -1,87 +0,0 @@
1
- """
2
- Utility functions for the Hippius SDK.
3
- """
4
-
5
- import os
6
- import math
7
- from typing import Dict, Any, Union, List, Optional
8
-
9
-
10
- def ensure_directory_exists(directory_path: str) -> None:
11
- """
12
- Create a directory if it doesn't exist.
13
-
14
- Args:
15
- directory_path: Path to the directory to ensure exists
16
- """
17
- if not os.path.exists(directory_path):
18
- os.makedirs(directory_path, exist_ok=True)
19
-
20
-
21
- def format_size(size_bytes: int) -> str:
22
- """
23
- Format a size in bytes to a human-readable string.
24
-
25
- Args:
26
- size_bytes: Size in bytes
27
-
28
- Returns:
29
- str: Human-readable size (e.g., "1.23 MB")
30
- """
31
- if size_bytes == 0:
32
- return "0 B"
33
-
34
- size_names = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
35
- i = int(math.floor(math.log(size_bytes, 1024)))
36
- if i >= len(size_names):
37
- i = len(size_names) - 1
38
- p = math.pow(1024, i)
39
- s = round(size_bytes / p, 2)
40
- return f"{s} {size_names[i]}"
41
-
42
-
43
- def deep_merge(target: Dict[str, Any], source: Dict[str, Any]) -> Dict[str, Any]:
44
- """
45
- Deep merge two dictionaries, with source taking precedence over target.
46
-
47
- Args:
48
- target: Target dictionary to merge into
49
- source: Source dictionary to merge from
50
-
51
- Returns:
52
- Dict[str, Any]: Merged dictionary
53
- """
54
- for key, value in source.items():
55
- if key in target and isinstance(target[key], dict) and isinstance(value, dict):
56
- target[key] = deep_merge(target[key], value)
57
- else:
58
- target[key] = value
59
- return target
60
-
61
-
62
- def parse_comma_separated(value: Optional[str]) -> List[str]:
63
- """
64
- Parse a comma-separated string into a list.
65
-
66
- Args:
67
- value: Comma-separated string or None
68
-
69
- Returns:
70
- List[str]: List of stripped values, or empty list if value is None
71
- """
72
- if not value:
73
- return []
74
- return [item.strip() for item in value.split(",") if item.strip()]
75
-
76
-
77
- def is_valid_url(url: str) -> bool:
78
- """
79
- Basic check if a string is a valid URL.
80
-
81
- Args:
82
- url: URL to check
83
-
84
- Returns:
85
- bool: True if valid URL, False otherwise
86
- """
87
- return url.startswith(("http://", "https://", "ws://", "wss://"))