How does Robot's Telnet library work?

590 views Asked by At

I've been taking a look at Robot's Telnet library(https://github.com/robotframework/robotframework/blob/master/src/robot/libraries/Telnet.py) and I haven't found an answer in the documentation to this question.

I get that The Telnet object handles opening and closing of TelnetConnections, and stores the current connection. But when something like write is called, how does Robot know to call Telnet._conn.write()?

For example:

Open connection  192.254.64.3
Open connection  192.254.64.4
Write            This goes to the second IP
1

There are 1 answers

1
janne On BEST ANSWER

Telnet library uses some introspection magic, supported by RF dynamic library interface.

When Telnet library is taken into use, get_keyword_names is called. This inspects also the TelnetConnection class for it's own methods and registers these as keywords. During execution RF calls e.g. Telnet.write, which is handled by the __getattr__ method, which in turn calls the corresponding method of the underlying TelnetConnection.

This whole mechanism is implemented in lines 308-240.