mcpcn-office-powerpoint-mcp-server 2.1.1__py3-none-any.whl → 2.1.2__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.
utils/core_utils.py CHANGED
@@ -1,55 +1,55 @@
1
- """
2
- Core utility functions for PowerPoint MCP Server.
3
- Basic operations and error handling.
4
- """
5
- from typing import Any, Callable, List, Tuple, Optional
6
-
7
-
8
- def try_multiple_approaches(operation_name: str, approaches: List[Tuple[Callable, str]]) -> Tuple[Any, Optional[str]]:
9
- """
10
- Try multiple approaches to perform an operation, returning the first successful result.
11
-
12
- Args:
13
- operation_name: Name of the operation for error reporting
14
- approaches: List of (approach_func, description) tuples to try
15
-
16
- Returns:
17
- Tuple of (result, None) if any approach succeeded, or (None, error_messages) if all failed
18
- """
19
- error_messages = []
20
-
21
- for approach_func, description in approaches:
22
- try:
23
- result = approach_func()
24
- return result, None
25
- except Exception as e:
26
- error_messages.append(f"{description}: {str(e)}")
27
-
28
- return None, f"Failed to {operation_name} after trying multiple approaches: {'; '.join(error_messages)}"
29
-
30
-
31
- def safe_operation(operation_name: str, operation_func: Callable, error_message: Optional[str] = None, *args, **kwargs) -> Tuple[Any, Optional[str]]:
32
- """
33
- Execute an operation safely with standard error handling.
34
-
35
- Args:
36
- operation_name: Name of the operation for error reporting
37
- operation_func: Function to execute
38
- error_message: Custom error message (optional)
39
- *args, **kwargs: Arguments to pass to the operation function
40
-
41
- Returns:
42
- A tuple (result, error) where error is None if operation was successful
43
- """
44
- try:
45
- result = operation_func(*args, **kwargs)
46
- return result, None
47
- except ValueError as e:
48
- error_msg = error_message or f"Invalid input for {operation_name}: {str(e)}"
49
- return None, error_msg
50
- except TypeError as e:
51
- error_msg = error_message or f"Type error in {operation_name}: {str(e)}"
52
- return None, error_msg
53
- except Exception as e:
54
- error_msg = error_message or f"Failed to execute {operation_name}: {str(e)}"
1
+ """
2
+ Core utility functions for PowerPoint MCP Server.
3
+ Basic operations and error handling.
4
+ """
5
+ from typing import Any, Callable, List, Tuple, Optional
6
+
7
+
8
+ def try_multiple_approaches(operation_name: str, approaches: List[Tuple[Callable, str]]) -> Tuple[Any, Optional[str]]:
9
+ """
10
+ Try multiple approaches to perform an operation, returning the first successful result.
11
+
12
+ Args:
13
+ operation_name: Name of the operation for error reporting
14
+ approaches: List of (approach_func, description) tuples to try
15
+
16
+ Returns:
17
+ Tuple of (result, None) if any approach succeeded, or (None, error_messages) if all failed
18
+ """
19
+ error_messages = []
20
+
21
+ for approach_func, description in approaches:
22
+ try:
23
+ result = approach_func()
24
+ return result, None
25
+ except Exception as e:
26
+ error_messages.append(f"{description}: {str(e)}")
27
+
28
+ return None, f"Failed to {operation_name} after trying multiple approaches: {'; '.join(error_messages)}"
29
+
30
+
31
+ def safe_operation(operation_name: str, operation_func: Callable, error_message: Optional[str] = None, *args, **kwargs) -> Tuple[Any, Optional[str]]:
32
+ """
33
+ Execute an operation safely with standard error handling.
34
+
35
+ Args:
36
+ operation_name: Name of the operation for error reporting
37
+ operation_func: Function to execute
38
+ error_message: Custom error message (optional)
39
+ *args, **kwargs: Arguments to pass to the operation function
40
+
41
+ Returns:
42
+ A tuple (result, error) where error is None if operation was successful
43
+ """
44
+ try:
45
+ result = operation_func(*args, **kwargs)
46
+ return result, None
47
+ except ValueError as e:
48
+ error_msg = error_message or f"Invalid input for {operation_name}: {str(e)}"
49
+ return None, error_msg
50
+ except TypeError as e:
51
+ error_msg = error_message or f"Type error in {operation_name}: {str(e)}"
52
+ return None, error_msg
53
+ except Exception as e:
54
+ error_msg = error_message or f"Failed to execute {operation_name}: {str(e)}"
55
55
  return None, error_msg