|
5 | 5 | from importlib.metadata import version, PackageNotFoundError |
6 | 6 |
|
7 | 7 | from .client import Client |
| 8 | +from snap7.clib.client import ClibClient |
8 | 9 | from .server import Server |
| 10 | +from snap7.clib.server import ClibServer |
9 | 11 | from .logo import Logo |
10 | 12 | from .partner import Partner |
| 13 | +from snap7.clib.partner import ClibPartner |
11 | 14 | from .util.db import Row, DB |
12 | 15 | from .type import Area, Block, WordLen, SrvEvent, SrvArea |
13 | 16 |
|
14 | | -# Pure Python client and server implementation |
| 17 | +# Pure Python implementations |
15 | 18 | try: |
16 | | - from .native_client import Client as PureClient |
17 | | - from .native_server import Server as PureServer |
| 19 | + from .native.wire_client import WireClient as PureClient |
| 20 | + from snap7.native.server import Server as PureServer |
| 21 | + from snap7.native.partner import Partner as PurePartner |
18 | 22 | _PURE_PYTHON_AVAILABLE = True |
19 | 23 | except ImportError: |
20 | 24 | _PURE_PYTHON_AVAILABLE = False |
21 | 25 | PureClient = None # type: ignore |
22 | 26 | PureServer = None # type: ignore |
23 | | - |
24 | | -__all__ = ["Client", "Server", "Logo", "Partner", "Row", "DB", "Area", "Block", "WordLen", "SrvEvent", "SrvArea"] |
| 27 | + PurePartner = None # type: ignore |
| 28 | + |
| 29 | +__all__ = [ |
| 30 | + "Client", |
| 31 | + "ClibClient", |
| 32 | + "Server", |
| 33 | + "ClibServer", |
| 34 | + "Logo", |
| 35 | + "Partner", |
| 36 | + "ClibPartner", |
| 37 | + "Row", |
| 38 | + "DB", |
| 39 | + "Area", |
| 40 | + "Block", |
| 41 | + "WordLen", |
| 42 | + "SrvEvent", |
| 43 | + "SrvArea", |
| 44 | +] |
25 | 45 |
|
26 | 46 | # Add pure Python implementations to exports if available |
27 | 47 | if _PURE_PYTHON_AVAILABLE: |
28 | | - __all__.extend(["PureClient", "PureServer"]) |
29 | | - |
30 | | - |
31 | | -def get_client(pure_python: bool = False): |
32 | | - """ |
33 | | - Get a client instance using the specified backend. |
34 | | - |
35 | | - Args: |
36 | | - pure_python: If True, use pure Python implementation. |
37 | | - If False (default), use ctypes wrapper around Snap7 C library. |
38 | | - |
39 | | - Returns: |
40 | | - Client instance using the requested backend. |
41 | | - |
42 | | - Raises: |
43 | | - ImportError: If pure Python backend is requested but not available. |
44 | | - |
45 | | - Examples: |
46 | | - >>> # Use default ctypes backend |
47 | | - >>> client = snap7.get_client() |
48 | | - |
49 | | - >>> # Use pure Python backend |
50 | | - >>> client = snap7.get_client(pure_python=True) |
51 | | - """ |
52 | | - if pure_python: |
53 | | - if not _PURE_PYTHON_AVAILABLE: |
54 | | - raise ImportError( |
55 | | - "Pure Python client is not available. " |
56 | | - "This may be due to missing dependencies in the native module." |
57 | | - ) |
58 | | - return PureClient() |
59 | | - else: |
60 | | - return Client() |
61 | | - |
62 | | - |
63 | | -def get_server(pure_python: bool = False): |
64 | | - """ |
65 | | - Get a server instance using the specified backend. |
66 | | - |
67 | | - Args: |
68 | | - pure_python: If True, use pure Python implementation. |
69 | | - If False (default), use ctypes wrapper around Snap7 C library. |
70 | | - |
71 | | - Returns: |
72 | | - Server instance using the requested backend. |
73 | | - |
74 | | - Raises: |
75 | | - ImportError: If pure Python backend is requested but not available. |
76 | | - |
77 | | - Examples: |
78 | | - >>> # Use default ctypes backend |
79 | | - >>> server = snap7.get_server() |
80 | | - |
81 | | - >>> # Use pure Python backend |
82 | | - >>> server = snap7.get_server(pure_python=True) |
83 | | - """ |
84 | | - if pure_python: |
85 | | - if not _PURE_PYTHON_AVAILABLE: |
86 | | - raise ImportError( |
87 | | - "Pure Python server is not available. " |
88 | | - "This may be due to missing dependencies in the native module." |
89 | | - ) |
90 | | - return PureServer() |
91 | | - else: |
92 | | - return Server() |
93 | | - |
94 | | - |
95 | | -# Add to exports |
96 | | -__all__.extend(["get_client", "get_server"]) |
| 48 | + __all__.extend(["PureClient", "PureServer", "PurePartner"]) |
97 | 49 |
|
98 | 50 | try: |
99 | 51 | __version__ = version("python-snap7") |
|
0 commit comments