diff options
author | kali <kali@leap.se> | 2012-08-21 04:29:03 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2012-08-21 04:29:03 +0900 |
commit | bb7c03a2d7244beff71ae610c012f525496daeb9 (patch) | |
tree | ef3840e9760322e246d60f3d7f02682e0380292d /src | |
parent | 1abd35337a186e7ab1bab414c0a3809b8583b5a3 (diff) |
udstelnet to its own file
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/eip/udstelnet.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/leap/eip/udstelnet.py b/src/leap/eip/udstelnet.py new file mode 100644 index 00000000..18e927c2 --- /dev/null +++ b/src/leap/eip/udstelnet.py @@ -0,0 +1,38 @@ +import os +import socket +import telnetlib + +from leap.eip import exceptions as eip_exceptions + + +class UDSTelnet(telnetlib.Telnet): + """ + a telnet-alike class, that can listen + on unix domain sockets + """ + + def open(self, host, port=23, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): + """Connect to a host. If port is 'unix', it + will open a connection over unix docmain sockets. + + The optional second argument is the port number, which + defaults to the standard telnet port (23). + + Don't try to reopen an already connected instance. + """ + self.eof = 0 + self.host = host + self.port = port + self.timeout = timeout + + if self.port == "unix": + # unix sockets spoken + if not os.path.exists(self.host): + raise eip_exceptions.MissingSocketError + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + try: + self.sock.connect(self.host) + except socket.error: + raise eip_exceptions.ConnectionRefusedError + else: + self.sock = socket.create_connection((host, port), timeout) |