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
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 theTelnetConnection
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 underlyingTelnetConnection
.This whole mechanism is implemented in lines 308-240.