-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyNUTClient needs telnetlib
which is deprecated
#2183
Comments
telnetlib
which will is deprecatedtelnetlib
which is deprecated
side notes: while playing with Home Assistant NUT addon, I'm thinking about improving a bit pyNUT... :D |
Although I currently have no time to work on this (again), I'd like to point anyone who does to this repo. I've deprecated it a month or so ago. But the implementation of |
We just started development on Fedora 41 which will ship with Python 3.13. So it would be nice to see this addressed relatively soon. The above comment seems promising. Also FWIW: |
Took some time to investigate telnetlib3, but it seems too great a paradigm change. With original PyNUT code, we open a client connection to the NUT server once, and in different methods post this or that request and parse replies. With telnetlib3+asyncio, it seems that each interaction must be a completely (pre-)defined I/O loop, so a separate connection, login, query, response, exit for each bit of work. Lots of avoidable extra server stress too, I guess. Also it seems to need separate annotations for the methods, so it is not as easy as "if mode==1 ... elif mode==3..." Libs like pexpect seem to require actually calling a |
I won't be able to dedicate much time to it, so PRs are welcome from someone who knows modern Python (and the other alternative libs) better :) Ideally, with dual-targeted code (so it runs on old systems too), but a separate same-API module like PyNUT3 is also an option if not avoidable... ( |
It seems that one recommended approach per https://discuss.python.org/t/pep-594-take-2-removing-dead-batteries-from-the-standard-library/13508/59 is to just copy Although examples at one of the recommended replacements, https://github.com/knipknap/exscript/ / https://exscript.readthedocs.io/en/latest/ seem to be conceptually similar to what PyNUT worked like. |
hello guys, please try my alternative to telnetlib: https://github.com/AlaBouali/xtelnet
Why should I use xtelnet? |
Just a heads up that Python 3.13b2 has now landed in Fedora Rawhide so NUT is failing to build. |
@opoplawski : thanks. WDYT : would making a private copy of the telnetlib module from original recent Python distribution be a decent stop-gap solution (try/except to import locally if not available globally)? Their migration docs seem to suggest as much... |
Yes, it would be acceptable. Though I fear that it might become the permanent solution... |
Might... maybe a better one would be to just go socket programming (same as done in C) - we do not need the full power of telnet/ssh here... |
…pstools#2183] Signed-off-by: Jim Klimov <[email protected]>
With PR #2501 merged, we now have at least that, a stashed copy. Not perfect, so keeping this ticket open to track a desire for simpler code to work with that socket layer, but good enough to keep on walking. @opoplawski : can you please check if this passes for builds on systems with "too new" a version of Python? |
So, just applying that PR to 2.8.2 I get:
Another comment would be to call out that presumably that file is under the Python license rather than the GPL. If I try to build from git master I get an autoreconf failure:
This is with autoconf 2.72. |
Thanks for testing, oddly this passed here so will check what happens. Probably I've not chopped enough pieces from the local python (some Looking at the errors, I see some of my mistakes:
...and presumably yours for the build from git master: did you |
…etworkupstools#2183] Avoid confusion for out-of-tree builds Signed-off-by: Jim Klimov <[email protected]>
…netlib_py*, and in those separate tests of stock telnetlib from fallback nut_telnetlib [networkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
…t their module search paths and versions [networkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
…capability probing [networkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
…r not) [networkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
…s#2183] Signed-off-by: Jim Klimov <[email protected]>
…stools#2183] Signed-off-by: Jim Klimov <[email protected]>
…ols#2183] Signed-off-by: Jim Klimov <[email protected]>
Comments should have got addressed by #2505 |
…etworkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
That looks good to me. A release at this point would be very helpful for us. Thanks! |
Thanks for the check-up! I have some fixes in progress to wrap up, but will try to not delay too much about a release then. |
Is it helpful if I start working on a Python library migration from telnetlib to asyncio? I am developing my own custom connection library for this application https://gitlab.com/mkswap/UPSMonitor, but if possible I would prefer to work on the official one. |
If that ultimately works, why not. So far the libs I looked at were quite aimed at proper (perhaps even interactive-ish) telnet/ssh communication sessions, with all the handling for terminal emulation, sending keypresses, etc. What NUT bindings need is much smaller in scale, and can be seen in C and now C++ client lib implementations - open a socket, send/receive bytes in one true encoding, parse the replies into language types (dict/list/str/int/... here). So overheads of switching to alternative libraries, balanced vs. the little time I have to spare and benefit of going from one thing that works to another that also works as much, proved to be a blocker for me - path of least resistance, ain't broken don't fix, bang for buck, and all that. One other wish is for new NUT releases to keep working on older systems - some may have no Python3 builds packaged for them. Currently UI client code is split by tech (QT vs GTK) and language syntax nuances, but the library source works for both python 2 and 3. Ideally a rewrite would keep that capability (at least at Can always start another version too though, but would cause headaches to adapt any downstreams... |
…e to install nut_telnetlib.py along with PyNUT.py file [networkupstools#2183, networkupstools#2501, networkupstools#2505] Deliver nut_telnetlib.py with Python 3.13 that lacks its own. Some use-cases did ensure its presence, but not all cases yet. Signed-off-by: Jim Klimov <[email protected]>
+1 about switching to simpler socket instead of telnet. Why did PyNUTClient ever use a telnetlib at all? Even the nut docs themselves say:
I've been doing this myself in a small simple logger I threw together to log some values from my ups and haven't noticed any issues. Only been running a week though. |
From my reading of sources - a legacy of historic choice. Just some layer to send and get strings, with no need for specifically telnet bells and whistles (terminals, escapes, etc.), without socket programming involved on the side of PyNUT(Client) developer. Also it was in core Python, so no extra deps needed either. As PoCs tend to go, there are no temporary solutions - and so we're stuck with that "good-enough" for life. PRs are still welcome to replace with some thinner layer that does the job. |
Would it be possible to just switch all the I'll try and remember to give this a test tomorrow. |
No idea OTOH and no time to research in short-term future. Thanks for giving it a look :) |
Didn't have a chance to work on it yesterday but it seems the change really was as minimal as I guessed. At least based on my limited testing with no issues so far anyway. I have put it in PR #2792. |
… for "socket" instead of "telnetlib" module [networkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
FWIW, current state of the module should be uploaded to https://test.pypi.org/project/pynutclient/2.8.2.2132/ now, so can be tested as a standalone module. |
Raised in #2181 discussion - after Python-3.13 we will need another implementation for the layer of text-based interaction over TCP in Python.
The text was updated successfully, but these errors were encountered: