ctxsync 0.8.0__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.
@@ -0,0 +1,134 @@
1
+ from datetime import datetime
2
+
3
+ from ctxsync.configmanager import BaseConfigManager
4
+
5
+
6
+ class InMemoryConfigManager(BaseConfigManager):
7
+ """
8
+ A configuration manager that stores configuration settings entirely in memory.
9
+
10
+ This class provides an in-memory implementation of the BaseConfigManager, meaning that
11
+ all configuration data is stored in Python dictionaries and does not persist between
12
+ program runs.
13
+ """
14
+
15
+ def __init__(self):
16
+ """
17
+ Initializes the in-memory configuration manager with default settings.
18
+ """
19
+ super().__init__()
20
+ self.session_keys = {}
21
+
22
+ def _load_global_config(self):
23
+ """
24
+ Loads the global configuration settings.
25
+
26
+ Since this is an in-memory implementation, this method doesn't load from any external source.
27
+ Instead, it relies on the initial in-memory defaults or previous modifications made during runtime.
28
+ """
29
+ # No action needed for in-memory implementation
30
+ pass
31
+
32
+ def _load_local_config(self):
33
+ """
34
+ Loads the local configuration settings.
35
+
36
+ Since this is an in-memory implementation, this method doesn't load from any external source.
37
+ """
38
+ # No action needed for in-memory implementation
39
+ pass
40
+
41
+ def _save_global_config(self):
42
+ """
43
+ Saves the global configuration settings.
44
+
45
+ Since this is an in-memory implementation, this method doesn't save to any external destination.
46
+ """
47
+ # No action needed for in-memory implementation
48
+ pass
49
+
50
+ def _save_local_config(self):
51
+ """
52
+ Saves the local configuration settings.
53
+
54
+ Since this is an in-memory implementation, this method doesn't save to any external destination.
55
+ """
56
+ # No action needed for in-memory implementation
57
+ pass
58
+
59
+ def set(self, key, value, local=False):
60
+ """
61
+ Sets a configuration value in the in-memory store.
62
+
63
+ Args:
64
+ key (str): The key of the configuration setting to set.
65
+ value: The value to associate with the given key.
66
+ local (bool): Whether to set the configuration in the local context.
67
+ If False, the setting is stored in the global context.
68
+ Default is False.
69
+ """
70
+ if local:
71
+ self.local_config[key] = value
72
+ else:
73
+ self.global_config[key] = value
74
+
75
+ def get(self, key, default=None):
76
+ """
77
+ Retrieves a configuration value from the in-memory store.
78
+
79
+ Args:
80
+ key (str): The key of the configuration setting to retrieve.
81
+ default: The default value to return if the key is not found.
82
+ Default is None.
83
+
84
+ Returns:
85
+ The value associated with the given key, or the default value if the key
86
+ does not exist.
87
+ """
88
+ return self.local_config.get(key, self.global_config.get(key, default))
89
+
90
+ def _find_local_config_dir(self):
91
+ """
92
+ Finds the local configuration directory.
93
+
94
+ Returns:
95
+ None: Since this is an in-memory implementation, there is no local configuration directory.
96
+ """
97
+ return None
98
+
99
+ def set_session_key(self, provider, session_key, expiry):
100
+ self.session_keys[provider] = {"session_key": session_key, "expiry": expiry}
101
+
102
+ def get_session_key(self, provider):
103
+ if provider in self.session_keys:
104
+ data = self.session_keys[provider]
105
+ if datetime.now() < data["expiry"]:
106
+ return data["session_key"], data["expiry"]
107
+ return None, None
108
+
109
+ def load_from_file_config(self, file_config_manager):
110
+ self.global_config = file_config_manager.global_config.copy()
111
+ self.local_config = file_config_manager.local_config.copy()
112
+
113
+ # Copy session keys
114
+ if hasattr(file_config_manager, "session_keys"):
115
+ self.session_keys = file_config_manager.session_keys.copy()
116
+ else:
117
+ # If FileConfigManager doesn't have session_keys attribute,
118
+ # we need to manually copy the session keys
119
+ for provider in file_config_manager.get_providers_with_session_keys():
120
+ session_key, expiry = file_config_manager.get_session_key(provider)
121
+ if session_key and expiry:
122
+ self.set_session_key(provider, session_key, expiry)
123
+
124
+ def get_active_provider(self):
125
+ """
126
+ Retrieves the active provider from the local configuration.
127
+
128
+ Returns:
129
+ str: The name of the active provider, or None if not set.
130
+ """
131
+ return self.local_config.get("active_provider")
132
+
133
+ def get_local_path(self):
134
+ return "."
ctxsync/exceptions.py ADDED
@@ -0,0 +1,22 @@
1
+ class ConfigurationError(Exception):
2
+ """
3
+ Exception raised when there's an issue with the application's configuration.
4
+
5
+ This exception should be raised to indicate problems such as missing required configuration options,
6
+ invalid values, or issues loading configuration files. It helps in distinguishing configuration-related
7
+ errors from other types of exceptions.
8
+ """
9
+
10
+ pass
11
+
12
+
13
+ class ProviderError(Exception):
14
+ """
15
+ Exception raised when there's an issue with a provider operation.
16
+
17
+ This exception is used to signal failures in operations related to external service providers,
18
+ such as authentication failures, data retrieval errors, or actions that cannot be completed as requested.
19
+ It allows for more granular error handling that is specific to provider interactions.
20
+ """
21
+
22
+ pass
@@ -0,0 +1,38 @@
1
+ # src/ctxsync/provider_factory.py
2
+
3
+ from .providers.base_provider import BaseProvider
4
+ from .providers.claude_ai import ClaudeAIProvider
5
+
6
+
7
+ def get_provider(config=None, provider_name=None) -> BaseProvider:
8
+ """
9
+ Retrieve an instance of a provider class based on the provider name.
10
+
11
+ This function serves as a factory to instantiate provider classes. It maintains a registry of available
12
+ providers. If a provider name is not specified, it returns a list of available provider names. If a provider
13
+ name is specified but not found in the registry, it raises a ValueError.
14
+
15
+ Args:
16
+ config: for testing
17
+ provider_name (str, optional): The name of the provider to retrieve. If None, returns a list of available
18
+ provider names.
19
+
20
+ Returns:
21
+ BaseProvider: An instance of the requested provider class.
22
+
23
+ Raises:
24
+ ValueError: If the specified provider_name is not found in the registry of providers.
25
+ """
26
+ providers = {
27
+ "claude.ai": ClaudeAIProvider,
28
+ # Add other providers here as they are implemented
29
+ }
30
+
31
+ if provider_name is None:
32
+ return list(providers.keys())
33
+
34
+ provider_class = providers.get(provider_name)
35
+ if provider_class is None:
36
+ raise ValueError(f"Unsupported provider: {provider_name}")
37
+
38
+ return provider_class(config)
File without changes