robotframework-platynui 0.0.1__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.
- PlatynUI/ButtonKeywords.py +9 -0
- PlatynUI/TextKeywords.py +7 -0
- PlatynUI/__about__.py +4 -0
- PlatynUI/__init__.py +34 -0
- PlatynUI/core/__init__.py +13 -0
- PlatynUI/core/adapter.py +152 -0
- PlatynUI/core/adapterfactory.py +51 -0
- PlatynUI/core/adapterproxy.py +168 -0
- PlatynUI/core/contextbase.py +586 -0
- PlatynUI/core/exceptions.py +77 -0
- PlatynUI/core/internal/__init__.py +0 -0
- PlatynUI/core/internal/decorator.py +148 -0
- PlatynUI/core/locatorbase.py +197 -0
- PlatynUI/core/locatorscope.py +17 -0
- PlatynUI/core/predicate.py +15 -0
- PlatynUI/core/settings.py +63 -0
- PlatynUI/core/strategies/__init__.py +1 -0
- PlatynUI/core/strategies/strategies.py +26 -0
- PlatynUI/core/strategybase.py +8 -0
- PlatynUI/core/strategyimpl.py +102 -0
- PlatynUI/core/technology.py +25 -0
- PlatynUI/core/types.py +421 -0
- PlatynUI/core/wait_for.py +47 -0
- PlatynUI/core/weight_calculator.py +110 -0
- PlatynUI/py.typed +0 -0
- PlatynUI/robot/__init__.py +0 -0
- PlatynUI/robot/reporting.py +74 -0
- PlatynUI/technology/__init__.py +0 -0
- PlatynUI/technology/uiautomation/.gitignore +1 -0
- PlatynUI/technology/uiautomation/__init__.py +4 -0
- PlatynUI/technology/uiautomation/core/adapterfactory.py +88 -0
- PlatynUI/technology/uiautomation/core/displaydevice.py +23 -0
- PlatynUI/technology/uiautomation/core/impls/__init__.py +2 -0
- PlatynUI/technology/uiautomation/core/impls/control.py +31 -0
- PlatynUI/technology/uiautomation/core/impls/window.py +83 -0
- PlatynUI/technology/uiautomation/core/keyboarddevice.py +21 -0
- PlatynUI/technology/uiautomation/core/loader.py +117 -0
- PlatynUI/technology/uiautomation/core/mousedevice.py +29 -0
- PlatynUI/technology/uiautomation/core/technology.py +61 -0
- PlatynUI/technology/uiautomation/core/uiaadapter.py +197 -0
- PlatynUI/technology/uiautomation/core/uiabase.py +19 -0
- PlatynUI/technology/uiautomation/desktop.py +11 -0
- PlatynUI/technology/uiautomation/locator.py +435 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Core.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.Core.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Microsoft.Xaml.Behaviors.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.deps.json +266 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.exe +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.runtimeconfig.json +19 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/System.ComponentModel.Composition.dll +0 -0
- PlatynUI/technology/uiautomation/spy/__init__.py +0 -0
- PlatynUI/technology/uiautomation/spy/__main__.py +24 -0
- PlatynUI/ui/__init__.py +65 -0
- PlatynUI/ui/application.py +27 -0
- PlatynUI/ui/buttons.py +82 -0
- PlatynUI/ui/combobox.py +149 -0
- PlatynUI/ui/container.py +9 -0
- PlatynUI/ui/control.py +49 -0
- PlatynUI/ui/core/__init__.py +3 -0
- PlatynUI/ui/core/devices/__init__.py +6 -0
- PlatynUI/ui/core/devices/basedisplaydevice.py +25 -0
- PlatynUI/ui/core/devices/basekeyboarddevice.py +64 -0
- PlatynUI/ui/core/devices/basemousedevice.py +30 -0
- PlatynUI/ui/core/devices/basescreendevice.py +16 -0
- PlatynUI/ui/core/devices/displaydevice.py +113 -0
- PlatynUI/ui/core/devices/inputdevice.py +24 -0
- PlatynUI/ui/core/devices/keyboarddevice.py +279 -0
- PlatynUI/ui/core/devices/keyboardproxy.py +69 -0
- PlatynUI/ui/core/devices/mousebutton.py +11 -0
- PlatynUI/ui/core/devices/mousedevice.py +279 -0
- PlatynUI/ui/core/devices/mouseproxy.py +178 -0
- PlatynUI/ui/core/ui_technology.py +31 -0
- PlatynUI/ui/core/window_manager.py +59 -0
- PlatynUI/ui/desktopbase.py +56 -0
- PlatynUI/ui/dialog.py +10 -0
- PlatynUI/ui/edit.py +48 -0
- PlatynUI/ui/element.py +265 -0
- PlatynUI/ui/graphic.py +14 -0
- PlatynUI/ui/header.py +33 -0
- PlatynUI/ui/item.py +100 -0
- PlatynUI/ui/lists.py +37 -0
- PlatynUI/ui/menus.py +42 -0
- PlatynUI/ui/orientation.py +9 -0
- PlatynUI/ui/pane.py +14 -0
- PlatynUI/ui/proxies/__init__.py +4 -0
- PlatynUI/ui/proxies/standardproxies.py +391 -0
- PlatynUI/ui/scrollbar.py +9 -0
- PlatynUI/ui/strategies/__init__.py +19 -0
- PlatynUI/ui/strategies/activatable.py +27 -0
- PlatynUI/ui/strategies/application.py +28 -0
- PlatynUI/ui/strategies/closeable.py +22 -0
- PlatynUI/ui/strategies/control.py +16 -0
- PlatynUI/ui/strategies/editable.py +13 -0
- PlatynUI/ui/strategies/element.py +65 -0
- PlatynUI/ui/strategies/expandable.py +27 -0
- PlatynUI/ui/strategies/hasnativewindowhandle.py +14 -0
- PlatynUI/ui/strategies/hasorientation.py +15 -0
- PlatynUI/ui/strategies/maximizeable.py +27 -0
- PlatynUI/ui/strategies/minimizeable.py +27 -0
- PlatynUI/ui/strategies/movable.py +14 -0
- PlatynUI/ui/strategies/resizable.py +13 -0
- PlatynUI/ui/strategies/restorable.py +13 -0
- PlatynUI/ui/strategies/selectable.py +27 -0
- PlatynUI/ui/strategies/text.py +55 -0
- PlatynUI/ui/strategies/title.py +14 -0
- PlatynUI/ui/strategies/toggleable.py +23 -0
- PlatynUI/ui/strategies/value.py +15 -0
- PlatynUI/ui/table.py +56 -0
- PlatynUI/ui/tabs.py +28 -0
- PlatynUI/ui/text.py +14 -0
- PlatynUI/ui/togglestate.py +12 -0
- PlatynUI/ui/tree.py +99 -0
- PlatynUI/ui/unknown.py +9 -0
- PlatynUI/ui/window.py +177 -0
- robotframework_platynui-0.0.1.dist-info/METADATA +49 -0
- robotframework_platynui-0.0.1.dist-info/RECORD +122 -0
- robotframework_platynui-0.0.1.dist-info/WHEEL +4 -0
- robotframework_platynui-0.0.1.dist-info/entry_points.txt +2 -0
- robotframework_platynui-0.0.1.dist-info/licenses/LICENSE.txt +73 -0
PlatynUI/TextKeywords.py
ADDED
PlatynUI/__about__.py
ADDED
PlatynUI/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024-present Daniel Biehl <dbiehl@live.de>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from robot.api.deco import library
|
|
7
|
+
from robotlibcore import DynamicCore, keyword
|
|
8
|
+
|
|
9
|
+
from PlatynUI.technology.uiautomation import Locator
|
|
10
|
+
|
|
11
|
+
from .ButtonKeywords import ButtonKeywords
|
|
12
|
+
from .core.contextbase import ContextBase, ContextFactory
|
|
13
|
+
from .core.locatorbase import LocatorBase
|
|
14
|
+
from .TextKeywords import TextKeywords
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def convert_locator(value) -> ContextBase: # type: ignore
|
|
18
|
+
if isinstance(value, ContextBase):
|
|
19
|
+
return value
|
|
20
|
+
|
|
21
|
+
if isinstance(value, LocatorBase):
|
|
22
|
+
return ContextFactory.create_context(value)
|
|
23
|
+
|
|
24
|
+
return ContextFactory.create_context(Locator(path=value))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@library(converters={ContextBase: convert_locator})
|
|
28
|
+
class PlatynUI(DynamicCore):
|
|
29
|
+
def __init__(self) -> None:
|
|
30
|
+
super().__init__([ButtonKeywords(), TextKeywords()])
|
|
31
|
+
|
|
32
|
+
@keyword
|
|
33
|
+
def blah(self) -> None:
|
|
34
|
+
print("blah")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .adapter import *
|
|
2
|
+
from .adapterfactory import *
|
|
3
|
+
from .adapterproxy import *
|
|
4
|
+
from .contextbase import *
|
|
5
|
+
from .exceptions import *
|
|
6
|
+
from .locatorbase import *
|
|
7
|
+
from .locatorscope import *
|
|
8
|
+
from .settings import *
|
|
9
|
+
from .strategybase import *
|
|
10
|
+
from .strategyimpl import *
|
|
11
|
+
from .technology import *
|
|
12
|
+
from .types import *
|
|
13
|
+
from .wait_for import *
|
PlatynUI/core/adapter.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from abc import ABCMeta, abstractmethod
|
|
3
|
+
from typing import Any, Dict, List, Optional, Set, Type, TypeVar, overload
|
|
4
|
+
|
|
5
|
+
from .exceptions import AdapterNotSupportsStrategyError, NotAStrategyTypeError
|
|
6
|
+
from .strategybase import StrategyBase
|
|
7
|
+
from .strategyimpl import StrategyImplFactory
|
|
8
|
+
from .technology import Technology
|
|
9
|
+
|
|
10
|
+
__all__ = ["Adapter", "TStrategyBase"]
|
|
11
|
+
|
|
12
|
+
TStrategyBase = TypeVar("TStrategyBase", bound=StrategyBase)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Adapter(StrategyBase, metaclass=ABCMeta):
|
|
16
|
+
"""
|
|
17
|
+
the base adapter
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
super().__init__()
|
|
22
|
+
self._strategy_cache: Dict[str, StrategyBase] = {}
|
|
23
|
+
|
|
24
|
+
strategy_name = "io.platynui.Adapter"
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def valid(self) -> bool:
|
|
29
|
+
"""
|
|
30
|
+
get true if the adapter is valid at this time
|
|
31
|
+
:return:
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def id(self) -> str:
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def name(self) -> str:
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def class_name(self) -> str:
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def tag_name(self) -> str:
|
|
51
|
+
return ""
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def role(self) -> str:
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
@abstractmethod
|
|
60
|
+
def supported_roles(self) -> Set[str]:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def type(self) -> str:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def supported_types(self) -> Set[str]:
|
|
71
|
+
pass
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
@abstractmethod
|
|
75
|
+
def framework_id(self) -> str:
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def runtime_id(self) -> str:
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def supported_strategies(self) -> Set[str]:
|
|
85
|
+
if self.valid:
|
|
86
|
+
return {
|
|
87
|
+
m.strategy_name
|
|
88
|
+
for m in inspect.getmro(type(self))
|
|
89
|
+
if hasattr(m, "strategy_name") and m.strategy_name is not None
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return set()
|
|
93
|
+
|
|
94
|
+
@overload
|
|
95
|
+
def get_strategy(self, strategy_type: Type[TStrategyBase]) -> TStrategyBase: ...
|
|
96
|
+
|
|
97
|
+
@overload
|
|
98
|
+
def get_strategy(self, strategy_type: Type[TStrategyBase], raise_exception: bool) -> Optional[TStrategyBase]: ...
|
|
99
|
+
|
|
100
|
+
def get_strategy(self, strategy_type: Type[TStrategyBase], raise_exception: bool = True) -> Optional[TStrategyBase]:
|
|
101
|
+
if hasattr(strategy_type, "strategy_name"):
|
|
102
|
+
strategy_name = getattr(strategy_type, "strategy_name")
|
|
103
|
+
|
|
104
|
+
if strategy_name in self._strategy_cache:
|
|
105
|
+
result = self._strategy_cache[strategy_name]
|
|
106
|
+
if isinstance(result, strategy_type):
|
|
107
|
+
return result
|
|
108
|
+
|
|
109
|
+
if strategy_name is not None:
|
|
110
|
+
result1 = self
|
|
111
|
+
if isinstance(result1, strategy_type):
|
|
112
|
+
self._strategy_cache[strategy_name] = result1
|
|
113
|
+
return result1
|
|
114
|
+
|
|
115
|
+
result2 = StrategyImplFactory.find_strategy_impl_for(self, strategy_type)
|
|
116
|
+
if result2 is not None:
|
|
117
|
+
self._strategy_cache[strategy_name] = result2
|
|
118
|
+
return result2
|
|
119
|
+
|
|
120
|
+
if raise_exception:
|
|
121
|
+
raise AdapterNotSupportsStrategyError(
|
|
122
|
+
"adapter not supports the %s strategy" % strategy_name
|
|
123
|
+
if strategy_name is not None
|
|
124
|
+
else repr(strategy_type)
|
|
125
|
+
)
|
|
126
|
+
return None
|
|
127
|
+
|
|
128
|
+
if raise_exception:
|
|
129
|
+
raise NotAStrategyTypeError("type %s is not a strategy type" % repr(strategy_type))
|
|
130
|
+
|
|
131
|
+
return None
|
|
132
|
+
|
|
133
|
+
def supports_strategy(self, strategy_type: Type[TStrategyBase]) -> bool:
|
|
134
|
+
return self.get_strategy(strategy_type, False) is not None
|
|
135
|
+
|
|
136
|
+
@property
|
|
137
|
+
@abstractmethod
|
|
138
|
+
def technology(self) -> Technology: ...
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
@abstractmethod
|
|
142
|
+
def parent(self) -> Optional["Adapter"]: ...
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
@abstractmethod
|
|
146
|
+
def children(self) -> List["Adapter"]: ...
|
|
147
|
+
|
|
148
|
+
def __eq__(self, other: Any) -> bool:
|
|
149
|
+
if isinstance(other, Adapter):
|
|
150
|
+
return self.runtime_id == other.runtime_id
|
|
151
|
+
|
|
152
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import TYPE_CHECKING, List, Optional, Type, overload
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from .adapter import Adapter
|
|
6
|
+
from .contextbase import ContextBase
|
|
7
|
+
from .locatorbase import LocatorBase
|
|
8
|
+
|
|
9
|
+
__all__ = ["AdapterFactory"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AdapterFactory(ABC):
|
|
13
|
+
|
|
14
|
+
@overload
|
|
15
|
+
def get_adapter(
|
|
16
|
+
self,
|
|
17
|
+
locator: "LocatorBase",
|
|
18
|
+
parent: Optional["ContextBase"] = None,
|
|
19
|
+
context_type: Optional[Type["ContextBase"]] = None,
|
|
20
|
+
) -> "Adapter":
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
@overload
|
|
24
|
+
def get_adapter(
|
|
25
|
+
self,
|
|
26
|
+
locator: "LocatorBase",
|
|
27
|
+
parent: Optional["ContextBase"] = None,
|
|
28
|
+
context_type: Optional[Type["ContextBase"]] = None,
|
|
29
|
+
raise_error: bool = True,
|
|
30
|
+
) -> Optional["Adapter"]:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def get_adapter(
|
|
35
|
+
self,
|
|
36
|
+
locator: "LocatorBase",
|
|
37
|
+
parent: Optional["ContextBase"] = None,
|
|
38
|
+
context_type: Optional[Type["ContextBase"]] = None,
|
|
39
|
+
raise_error: bool = True,
|
|
40
|
+
) -> Optional["Adapter"]:
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
@abstractmethod
|
|
44
|
+
def get_children_adapters(
|
|
45
|
+
self,
|
|
46
|
+
parent: Optional["ContextBase"],
|
|
47
|
+
context_type: Optional[Type["ContextBase"]],
|
|
48
|
+
locator: "LocatorBase",
|
|
49
|
+
raise_error: bool = True,
|
|
50
|
+
) -> List["Adapter"]:
|
|
51
|
+
pass
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
from typing import Any, Callable, Dict, List, Optional, Set, Type, TypeVar, cast, overload
|
|
2
|
+
|
|
3
|
+
from .adapter import Adapter, TStrategyBase
|
|
4
|
+
from .strategybase import StrategyBase
|
|
5
|
+
from .technology import Technology
|
|
6
|
+
from .weight_calculator import WeightCalculator
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"AdapterProxy",
|
|
10
|
+
"adapter_proxy_for",
|
|
11
|
+
"AdapterProxyFactory",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AdapterProxy(Adapter):
|
|
16
|
+
def __init__(self, adapter: Adapter):
|
|
17
|
+
self._adapter = adapter
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def adapter(self) -> Adapter:
|
|
21
|
+
return self._adapter
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def valid(self) -> bool:
|
|
25
|
+
return self.adapter.valid
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def id(self) -> str:
|
|
29
|
+
return self.adapter.id
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def name(self) -> str:
|
|
33
|
+
return self.adapter.name
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def class_name(self) -> str:
|
|
37
|
+
return self.adapter.class_name
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def tag_name(self) -> str:
|
|
41
|
+
return self.adapter.tag_name
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def role(self) -> str:
|
|
45
|
+
return self.adapter.role
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def supported_roles(self) -> Set[str]:
|
|
49
|
+
return self.adapter.supported_roles
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def type(self) -> str:
|
|
53
|
+
return self.adapter.type
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def supported_types(self) -> Set[str]:
|
|
57
|
+
return self.adapter.supported_types
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def framework_id(self) -> str:
|
|
61
|
+
return self.adapter.framework_id
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def runtime_id(self) -> Any:
|
|
65
|
+
return self.adapter.runtime_id
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def technology(self) -> Technology:
|
|
69
|
+
return self.adapter.technology
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def _self_implemented_strategies(self) -> Set[str]:
|
|
73
|
+
return set(
|
|
74
|
+
[
|
|
75
|
+
getattr(i, "strategy_name")
|
|
76
|
+
for i in type(self).mro()
|
|
77
|
+
if issubclass(i, StrategyBase) and i != StrategyBase and hasattr(i, "strategy_name")
|
|
78
|
+
]
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def supported_strategies(self) -> Set[str]:
|
|
83
|
+
return self._self_implemented_strategies.union(self.adapter.supported_strategies)
|
|
84
|
+
|
|
85
|
+
@overload
|
|
86
|
+
def get_strategy(self, strategy_type: Type[TStrategyBase]) -> TStrategyBase: ...
|
|
87
|
+
|
|
88
|
+
@overload
|
|
89
|
+
def get_strategy(self, strategy_type: Type[TStrategyBase], raise_exception: bool) -> Optional[TStrategyBase]: ...
|
|
90
|
+
|
|
91
|
+
def get_strategy(self, strategy_type: Type[TStrategyBase], raise_exception: bool = True) -> Optional[TStrategyBase]:
|
|
92
|
+
if hasattr(strategy_type, "strategy_name"):
|
|
93
|
+
if strategy_type.strategy_name is not None:
|
|
94
|
+
if strategy_type.strategy_name in self._self_implemented_strategies:
|
|
95
|
+
return cast(strategy_type, self) # type: ignore
|
|
96
|
+
|
|
97
|
+
return self.adapter.get_strategy(strategy_type, raise_exception)
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def parent(self) -> Optional["Adapter"]:
|
|
101
|
+
return self.adapter.parent
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def children(self) -> List["Adapter"]:
|
|
105
|
+
return self.adapter.children
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
TAdapter = TypeVar("TAdapter", bound=Adapter)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class AdapterProxyFactory:
|
|
112
|
+
class Entry:
|
|
113
|
+
def __init__(self, proxy_type: Type[AdapterProxy], criterias: Dict[str, object]):
|
|
114
|
+
self.proxy_type = proxy_type
|
|
115
|
+
self.criterias = criterias
|
|
116
|
+
|
|
117
|
+
registered_adapters: List[Entry] = []
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def register_proxy(cls, adapter_cls: Type[AdapterProxy], criterias: Dict[str, Any]) -> None:
|
|
121
|
+
cls.registered_adapters.append(AdapterProxyFactory.Entry(adapter_cls, criterias.copy()))
|
|
122
|
+
|
|
123
|
+
@classmethod
|
|
124
|
+
def find_proxy_for(cls, adapter: TAdapter) -> TAdapter:
|
|
125
|
+
weights = []
|
|
126
|
+
calculator = WeightCalculator(adapter)
|
|
127
|
+
|
|
128
|
+
for e in cls.registered_adapters:
|
|
129
|
+
weights.append((calculator.calculate(e.criterias), e.proxy_type))
|
|
130
|
+
|
|
131
|
+
if len(weights) > 0:
|
|
132
|
+
last = sorted(weights, key=lambda x: x[0])[-1]
|
|
133
|
+
|
|
134
|
+
if last[0] > 0:
|
|
135
|
+
return cast(TAdapter, last[1](adapter))
|
|
136
|
+
|
|
137
|
+
return adapter
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def adapter_proxy_for(
|
|
141
|
+
role: Optional[str] = None,
|
|
142
|
+
framework_id: Optional[str] = None,
|
|
143
|
+
class_name: Optional[str] = None,
|
|
144
|
+
tag_name: Optional[str] = None,
|
|
145
|
+
properties: Optional[Dict[str, str]] = None,
|
|
146
|
+
technology: Optional[Type[Any]] = None,
|
|
147
|
+
native_properties: Optional[Dict[str, str]] = None,
|
|
148
|
+
**decorator_kwargs: Any,
|
|
149
|
+
) -> Callable[[Type[AdapterProxy]], Type[AdapterProxy]]:
|
|
150
|
+
|
|
151
|
+
def decorator(cls: Type[AdapterProxy]) -> Type[AdapterProxy]:
|
|
152
|
+
|
|
153
|
+
AdapterProxyFactory.register_proxy(
|
|
154
|
+
cls,
|
|
155
|
+
{
|
|
156
|
+
"role": role,
|
|
157
|
+
"framework_id": framework_id,
|
|
158
|
+
"class_name": class_name,
|
|
159
|
+
"tag_name": tag_name,
|
|
160
|
+
"technology": technology,
|
|
161
|
+
"properties": properties,
|
|
162
|
+
"native_properties": native_properties,
|
|
163
|
+
**decorator_kwargs,
|
|
164
|
+
},
|
|
165
|
+
)
|
|
166
|
+
return cls
|
|
167
|
+
|
|
168
|
+
return decorator
|