scrapli 2.0.0a2__py3-none-musllinux_1_1_x86_64.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.
scrapli/transport.py ADDED
@@ -0,0 +1,401 @@
1
+ """scrapli.transport"""
2
+
3
+ from ctypes import c_char_p, c_int
4
+ from dataclasses import dataclass, field
5
+ from enum import Enum
6
+
7
+ from scrapli.exceptions import OptionsException
8
+ from scrapli.ffi_mapping import LibScrapliMapping
9
+ from scrapli.ffi_types import (
10
+ DriverPointer,
11
+ to_c_string,
12
+ )
13
+
14
+
15
+ class TransportKind(str, Enum):
16
+ """
17
+ Enum representing the transport kind
18
+
19
+ Args:
20
+ N/A
21
+
22
+ Returns:
23
+ None
24
+
25
+ Raises:
26
+ N/A
27
+
28
+ """
29
+
30
+ BIN = "bin"
31
+ SSH2 = "ssh2"
32
+ TELNET = "telnet"
33
+ TEST = "test_"
34
+
35
+
36
+ @dataclass
37
+ class BinOptions:
38
+ """
39
+ Options holds bin transport options to pass to the ffi layer.
40
+
41
+ Args:
42
+ bin: path to binary to use for the transport
43
+ extra_open_args: extra args to pass to the binary
44
+ override_open_args: override all "normal" scrapli args with these args
45
+ ssh_config_path: path to ssh config file
46
+ known_hosts_path: path to known hosts file
47
+ enable_strict_key: enable ssh strict key checking
48
+ term_height: set the terminal height
49
+ term_width: set the terminal width
50
+
51
+ Returns:
52
+ None
53
+
54
+ Raises:
55
+ N/A
56
+
57
+ """
58
+
59
+ bin: str | None = None
60
+ extra_open_args: list[str] | None = None
61
+ override_open_args: list[str] | None = None
62
+ ssh_config_path: str | None = None
63
+ known_hosts_path: str | None = None
64
+ enable_strict_key: bool | None = None
65
+ term_height: int | None = None
66
+ term_width: int | None = None
67
+
68
+ _bin: c_char_p | None = field(init=False, default=None, repr=False)
69
+ _extra_open_args: c_char_p | None = field(init=False, default=None, repr=False)
70
+ _override_open_args: c_char_p | None = field(init=False, default=None, repr=False)
71
+ _ssh_config_path: c_char_p | None = field(init=False, default=None, repr=False)
72
+ _known_hosts_path: c_char_p | None = field(init=False, default=None, repr=False)
73
+
74
+ def apply( # noqa: C901, PLR0912
75
+ self, ffi_mapping: LibScrapliMapping, ptr: DriverPointer
76
+ ) -> None:
77
+ """
78
+ Applies the options to the given driver pointer.
79
+
80
+ Should not be called directly/by users.
81
+
82
+ Args:
83
+ ffi_mapping: the handle to the ffi mapping singleton
84
+ ptr: the pointer to the underlying cli or netconf object
85
+
86
+ Returns:
87
+ None
88
+
89
+ Raises:
90
+ OptionsException: if any option apply returns a non-zero return code.
91
+
92
+ """
93
+ if self.bin is not None:
94
+ self._bin = to_c_string(self.bin)
95
+
96
+ status = ffi_mapping.options_mapping.transport_bin.set_bin(ptr, self._bin)
97
+ if status != 0:
98
+ raise OptionsException("failed to set bin transport bin")
99
+
100
+ if self.extra_open_args is not None:
101
+ self._extra_open_args = to_c_string(" ".join(self.extra_open_args))
102
+
103
+ status = ffi_mapping.options_mapping.transport_bin.set_extra_open_args(
104
+ ptr, self._extra_open_args
105
+ )
106
+ if status != 0:
107
+ raise OptionsException("failed to set bin transport extra open args")
108
+
109
+ if self.override_open_args is not None:
110
+ self._override_open_args = to_c_string(" ".join(self.override_open_args))
111
+
112
+ status = ffi_mapping.options_mapping.transport_bin.set_override_open_args(
113
+ ptr, self._override_open_args
114
+ )
115
+ if status != 0:
116
+ raise OptionsException("failed to set bin transport override open args")
117
+
118
+ if self.ssh_config_path is not None:
119
+ self._ssh_config_path = to_c_string(self.ssh_config_path)
120
+
121
+ status = ffi_mapping.options_mapping.transport_bin.set_ssh_config_path(
122
+ ptr, self._ssh_config_path
123
+ )
124
+ if status != 0:
125
+ raise OptionsException("failed to set bin transport ssh config path")
126
+
127
+ if self.known_hosts_path is not None:
128
+ self._known_hosts_path = to_c_string(self.known_hosts_path)
129
+
130
+ status = ffi_mapping.options_mapping.transport_bin.set_known_hosts_path(
131
+ ptr, self._known_hosts_path
132
+ )
133
+ if status != 0:
134
+ raise OptionsException("failed to set bin transport ssh known hosts path")
135
+
136
+ if self.enable_strict_key is not None:
137
+ status = ffi_mapping.options_mapping.transport_bin.set_enable_strict_key(ptr)
138
+ if status != 0:
139
+ raise OptionsException("failed to set bin transport enable strict key")
140
+
141
+ if self.term_height is not None:
142
+ status = ffi_mapping.options_mapping.transport_bin.set_term_height(
143
+ ptr, c_int(self.term_height)
144
+ )
145
+ if status != 0:
146
+ raise OptionsException("failed to set bin transport term height")
147
+
148
+ if self.term_width is not None:
149
+ status = ffi_mapping.options_mapping.transport_bin.set_term_width(
150
+ ptr, c_int(self.term_width)
151
+ )
152
+ if status != 0:
153
+ raise OptionsException("failed to set bin transport term width")
154
+
155
+
156
+ @dataclass
157
+ class Ssh2Options:
158
+ """
159
+ Options holds ssh2 transport options to pass to the ffi layer.
160
+
161
+ Args:
162
+ libssh2_trace: enable libssh2 tracing
163
+
164
+ Returns:
165
+ None
166
+
167
+ Raises:
168
+ N/A
169
+
170
+ """
171
+
172
+ libssh2_trace: bool | None = None
173
+
174
+ def apply(self, ffi_mapping: LibScrapliMapping, ptr: DriverPointer) -> None:
175
+ """
176
+ Applies the options to the given driver pointer.
177
+
178
+ Should not be called directly/by users.
179
+
180
+ Args:
181
+ ffi_mapping: the handle to the ffi mapping singleton
182
+ ptr: the pointer to the underlying cli or netconf object
183
+
184
+ Returns:
185
+ None
186
+
187
+ Raises:
188
+ OptionsException: if any option apply returns a non-zero return code.
189
+
190
+ """
191
+ if self.libssh2_trace is not None:
192
+ status = ffi_mapping.options_mapping.transport_ssh2.set_libssh2_trace(ptr)
193
+ if status != 0:
194
+ raise OptionsException("failed to set ssh2 transport trace")
195
+
196
+
197
+ @dataclass
198
+ class TelnetOptions:
199
+ """
200
+ Options holds telnet transport options to pass to the ffi layer.
201
+
202
+ Args:
203
+ N/A
204
+
205
+ Returns:
206
+ None
207
+
208
+ Raises:
209
+ N/A
210
+
211
+ """
212
+
213
+ def apply(self, ffi_mapping: LibScrapliMapping, ptr: DriverPointer) -> None:
214
+ """
215
+ Applies the options to the given driver pointer.
216
+
217
+ Should not be called directly/by users.
218
+
219
+ Args:
220
+ ffi_mapping: the handle to the ffi mapping singleton
221
+ ptr: the pointer to the underlying cli or netconf object
222
+
223
+ Returns:
224
+ None
225
+
226
+ Raises:
227
+ OptionsException: if any option apply returns a non-zero return code.
228
+
229
+ """
230
+ _, _ = ffi_mapping, ptr
231
+
232
+
233
+ @dataclass
234
+ class TestOptions:
235
+ """
236
+ Options holds test transport options to pass to the ffi layer.
237
+
238
+ Args:
239
+ f: the file to load/read for the transport
240
+
241
+ Returns:
242
+ None
243
+
244
+ Raises:
245
+ N/A
246
+
247
+ """
248
+
249
+ f: str | None = None
250
+
251
+ _f: c_char_p | None = field(init=False, default=None, repr=False)
252
+
253
+ def apply(self, ffi_mapping: LibScrapliMapping, ptr: DriverPointer) -> None:
254
+ """
255
+ Applies the options to the given driver pointer.
256
+
257
+ Should not be called directly/by users.
258
+
259
+ Args:
260
+ ffi_mapping: the handle to the ffi mapping singleton
261
+ ptr: the pointer to the underlying cli or netconf object
262
+
263
+ Returns:
264
+ None
265
+
266
+ Raises:
267
+ OptionsException: if any option apply returns a non-zero return code.
268
+
269
+ """
270
+ if self.f is not None:
271
+ self._f = to_c_string(self.f)
272
+
273
+ status = ffi_mapping.options_mapping.transport_test.set_f(ptr, self._f)
274
+ if status != 0:
275
+ raise OptionsException("failed to set test transport f")
276
+
277
+
278
+ @dataclass
279
+ class Options:
280
+ """
281
+ Options holds transport options to pass to the ffi layer.
282
+
283
+ Only one flavor of transport options can be set at a time. The active option determines the
284
+ transport to be used for the connection.
285
+
286
+ Args:
287
+ bin: the bin transport options
288
+ ssh2: the ssh2 transport options
289
+ telnet: the telnet transport options
290
+ test: the test transport options
291
+
292
+ Returns:
293
+ None
294
+
295
+ Raises:
296
+ N/A
297
+
298
+ """
299
+
300
+ bin: BinOptions | None = None
301
+ ssh2: Ssh2Options | None = None
302
+ telnet: TelnetOptions | None = None
303
+ test: TestOptions | None = None
304
+
305
+ _transport_kind: bytes | None = field(init=False, default=None, repr=False)
306
+
307
+ def __post_init__(self) -> None:
308
+ _set_fields = [f for f in [self.bin, self.ssh2, self.telnet, self.test] if f is not None]
309
+
310
+ if len(_set_fields) == 0:
311
+ self.bin = BinOptions()
312
+
313
+ return
314
+
315
+ if len(_set_fields) == 1:
316
+ return
317
+
318
+ raise OptionsException("more than one transport set")
319
+
320
+ def apply(self, ffi_mapping: LibScrapliMapping, ptr: DriverPointer) -> None:
321
+ """
322
+ Applies the options to the given driver pointer.
323
+
324
+ Should not be called directly/by users.
325
+
326
+ Args:
327
+ ffi_mapping: the handle to the ffi mapping singleton
328
+ ptr: the pointer to the underlying cli or netconf object
329
+
330
+ Returns:
331
+ None
332
+
333
+ Raises:
334
+ OptionsException: if any option apply returns a non-zero return code.
335
+
336
+ """
337
+ if self.bin:
338
+ self.bin.apply(ffi_mapping, ptr)
339
+ elif self.ssh2:
340
+ self.ssh2.apply(ffi_mapping, ptr)
341
+ elif self.telnet:
342
+ self.telnet.apply(ffi_mapping, ptr)
343
+ elif self.test:
344
+ self.test.apply(ffi_mapping, ptr)
345
+
346
+ def get_transport_kind(self) -> bytes:
347
+ """
348
+ Returns the encoded name of the selected transport kind
349
+
350
+ Should not be called directly/by users.
351
+
352
+ Args:
353
+ N/A
354
+
355
+ Returns:
356
+ bytes: the encoded name of the selected transport kind
357
+
358
+ Raises:
359
+ OptionsException: if any option apply returns a non-zero return code.
360
+
361
+ """
362
+ if self.bin:
363
+ self._transport_kind = TransportKind.BIN.encode(encoding="utf-8")
364
+ elif self.ssh2:
365
+ self._transport_kind = TransportKind.SSH2.encode(encoding="utf-8")
366
+ elif self.telnet:
367
+ self._transport_kind = TransportKind.TELNET.encode(encoding="utf-8")
368
+ else:
369
+ self._transport_kind = TransportKind.TEST.encode(encoding="utf-8")
370
+
371
+ return self._transport_kind
372
+
373
+ def __repr__(self) -> str:
374
+ """
375
+ Magic repr method for Options object
376
+
377
+ Args:
378
+ N/A
379
+
380
+ Returns:
381
+ str: repr for Options object
382
+
383
+ Raises:
384
+ N/A
385
+
386
+ """
387
+ if self.bin:
388
+ return (
389
+ # it will probably be "canonical" to import Options as SessionOptions, so we'll make
390
+ # the repr do that too
391
+ f"Transport{self.__class__.__name__}("
392
+ f"bin={self.bin!r}, "
393
+ )
394
+
395
+ if self.ssh2:
396
+ return f"Transport{self.__class__.__name__}(" f"ssh2={self.ssh2!r}, "
397
+
398
+ if self.telnet:
399
+ return f"Transport{self.__class__.__name__}(" f"telnet={self.telnet!r}, "
400
+
401
+ return f"Transport{self.__class__.__name__}(" f"test={self.test!r}, "
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: scrapli
3
+ Version: 2.0.0a2
4
+ Summary: Fast, flexible, sync/async, Python 3.10+ screen scraping client specifically for network devices
5
+ Author-email: Carl Montanari <carl.r.montanari@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Changelog, https://carlmontanari.github.io/scrapli/changelog
8
+ Project-URL: Docs, https://carlmontanari.github.io/scrapli/
9
+ Project-URL: Homepage, https://github.com/carlmontanari/scrapli
10
+ Keywords: netconf,network,ssh,telnet,async
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: dev
24
+ Requires-Dist: nox==2025.5.1; extra == "dev"
25
+ Requires-Dist: black<26.0.0,>=25.1.0; extra == "dev"
26
+ Requires-Dist: isort<7.0.0,>=6.0.1; extra == "dev"
27
+ Requires-Dist: ruff<1.0.0,>=0.11.8; extra == "dev"
28
+ Requires-Dist: mypy<2.0.0,>=1.15.0; extra == "dev"
29
+ Requires-Dist: pytest<9.0.0,>=8.3.5; extra == "dev"
30
+ Requires-Dist: pytest-cov<7.0.0,>=6.1.1; extra == "dev"
31
+ Requires-Dist: pytest-asyncio<1.0.0,>=0.26.0; extra == "dev"
32
+ Requires-Dist: pyats>=20.2; extra == "dev"
33
+ Requires-Dist: genie>=20.2; extra == "dev"
34
+ Requires-Dist: ntc-templates<8.0.0,>=1.1.0; extra == "dev"
35
+ Requires-Dist: textfsm<2.0.0,>=1.1.0; extra == "dev"
36
+ Provides-Extra: full
37
+ Requires-Dist: ntc-templates<8.0.0,>=1.1.0; extra == "full"
38
+ Requires-Dist: textfsm<2.0.0,>=1.1.0; extra == "full"
39
+ Requires-Dist: pyats>=20.2; extra == "full"
40
+ Requires-Dist: genie>=20.2; extra == "full"
41
+ Provides-Extra: textfsm
42
+ Requires-Dist: ntc-templates<8.0.0,>=1.1.0; extra == "textfsm"
43
+ Requires-Dist: textfsm<2.0.0,>=1.1.0; extra == "textfsm"
44
+ Provides-Extra: genie
45
+ Requires-Dist: pyats>=20.2; extra == "genie"
46
+ Requires-Dist: genie>=20.2; extra == "genie"
47
+ Dynamic: license-file
48
+
49
+ <p center><a href=""><img src=https://github.com/carlmontanari/scrapli/blob/main/scrapli.svg?sanitize=true/></a></p>
@@ -0,0 +1,35 @@
1
+ scrapli/__init__.py,sha256=qcOX4L_nCkch_3r5etnPI3XlktJTdsqBHyBuJhNBdPk,929
2
+ scrapli/auth.py,sha256=LMYD31AMK0pyTa0RQo9I3ap3F1onmDylb2zQsHl6zrw,7907
3
+ scrapli/cli.py,sha256=-WzN7uHnkgmmH6vdINp9Tr5rVAmoecSqvvpiWxY5dog,48186
4
+ scrapli/cli_decorators.py,sha256=Mj1BfouFiAWb2bbVvhBgc9qqJou6mf-ClvK3Ngy1dJA,4412
5
+ scrapli/cli_parse.py,sha256=b9l2w7TSKpHwNGumCsENvRO1R4NMKnOe5v2vfrweTUA,5171
6
+ scrapli/cli_result.py,sha256=YkgAJ4LiEOiC46376EZjbRqoZzERyVmtwbU8VQ7Nl84,4914
7
+ scrapli/exceptions.py,sha256=RNU720WL6efW_4Pdjruzp0M-Se-zQR3mFcsrzscvaPA,1524
8
+ scrapli/ffi.py,sha256=QgPj1OK8t2swrt_T1nwRHR92DTwhBC_E4r5s6wOCHTI,2149
9
+ scrapli/ffi_mapping.py,sha256=7tnL1mwBYc1dlSH6l2YG_a_5_6BaXmFZiMY1SkE9nOw,5017
10
+ scrapli/ffi_mapping_cli.py,sha256=lIy4mD5MH0DT2fxgDH0WAG5zlsK5UXrzDh817q2VQRY,18503
11
+ scrapli/ffi_mapping_netconf.py,sha256=zPciAB6gP_Zy8d6pwW6MnrSvrp0i5fg4HKgQ_PHqggg,44314
12
+ scrapli/ffi_mapping_options.py,sha256=X2Y-B_K1e2f7aSbJ5pNktT3X7tDpdu_RZ1TX-ba75nI,27557
13
+ scrapli/ffi_types.py,sha256=ZG9LqeNQ34FR4KGCEj4S0Al9qEMCIc8306Xfe8YTOUk,3230
14
+ scrapli/helper.py,sha256=hiVHcczqFqhF0qAyiBn0mioL_fsI2pszCoM9VS_KYsw,1628
15
+ scrapli/netconf.py,sha256=rf0YpTCZLVYkx3DZY2lCPg3dKZ_lgUG_JtfSfF2ts1Q,83819
16
+ scrapli/netconf_decorators.py,sha256=C5yk5Gq7OD_V1g6rVOi8qzeA5MQHEI3B2IUXxyj0IIU,4464
17
+ scrapli/netconf_result.py,sha256=JHvNa5KX6gEf5iwJxCc9Hlcg5ljhRWkd0aoGaXAtYPw,1174
18
+ scrapli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ scrapli/session.py,sha256=8f3XvpZ-4-uw4uuRBVtQMbo8Ftzwu99uCwDL9_UQkO8,4275
20
+ scrapli/transport.py,sha256=v_S4td5kezlUwqANwZh5pQhxgW2jEPCvCe97C8e0fmA,11313
21
+ scrapli/definitions/__init__.py,sha256=d-XZBK_ZjN4Sy6SmhJL-T4imYY_UioM8gSiX-PKVDuE,26
22
+ scrapli/definitions/arista_eos.yaml,sha256=ZR3BmdmGScJobQQZfW7gwOLj5wGxdpZ1omgraw9KgCc,1714
23
+ scrapli/definitions/cisco_iosxe.yaml,sha256=nnqi8qQmFmKX4BgnuLMJqj0hAyqkVRmSfmDLsJKBFaA,1699
24
+ scrapli/definitions/cisco_iosxr.yaml,sha256=hkxQe9sMyCx3Eo9BDSxHD1MWG6yxHl6EHnyjSTjD-_I,1317
25
+ scrapli/definitions/cisco_nxos.yaml,sha256=ih_FiqkBJk3pgGou29DGN0tjrdkF_qqH5bJOa-V1SXg,1889
26
+ scrapli/definitions/juniper_junos.yaml,sha256=bWErL-XgxwwnZv4R9MsSZFLla0VnVhrHqDQ3pZJ9-1I,2491
27
+ scrapli/definitions/nokia_srlinux.yaml,sha256=2TrpoVCIwi-E_IzTsuQjmKBR4lSz_24c2mhhwv6e1ec,1042
28
+ scrapli/lib/__init__.py,sha256=emX2ZjmnwMNIozlcKNDDXr_4zlryoLD8h2fM-CO3KZY,18
29
+ scrapli/lib/libscrapli.0.0.1-alpha.10.dylib,sha256=-oOvGZigabVog8nUl9dajxGR8JqW1ZWHAJj-spKErVM,12922712
30
+ scrapli/lib/libscrapli.so.0.0.1-alpha.10,sha256=-oOvGZigabVog8nUl9dajxGR8JqW1ZWHAJj-spKErVM,12922712
31
+ scrapli-2.0.0a2.dist-info/licenses/LICENSE,sha256=IeyhkG2h_dAvJ7nAF0S4GSUg045jwI27YADV_KSJi50,1071
32
+ scrapli-2.0.0a2.dist-info/METADATA,sha256=LIVee3xM1hOhkQb4R7JB0adJsPeRD0E5oJFwWWDmtJs,2286
33
+ scrapli-2.0.0a2.dist-info/WHEEL,sha256=BXbYIxXHYdKtYAyKXk1gb2W8ojCiOA3TA7MJVQikKKo,108
34
+ scrapli-2.0.0a2.dist-info/top_level.txt,sha256=piC9TaaPt0z-1Ryrs69hDvsIQkmE5ceDAAW5donUvsI,8
35
+ scrapli-2.0.0a2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-musllinux_1_1_x86_64
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Carl Montanari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ scrapli