diff options
author | kali <kali@leap.se> | 2013-01-31 05:26:18 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2013-01-31 05:30:28 +0900 |
commit | 555210630659018785fdb9d2318081a76b49fb4c (patch) | |
tree | df7a51aaa32d9436a86881f9815d66a0f28773a5 /src/leap/eip/udstelnet.py | |
parent | 00276d12b44630315c19ff2cd0f906eac34d92cf (diff) |
actually merge the release/v0.2.0 branch!
My life has been a lie until this moment...
I had done:
git merge -s ours release/v0.2.0
to avoid deleting the debian folder...
but that left the src untouched...
Now I just rm'd the src folder and did a
git checkout release/v0.2.0 src/
... and merge happy! :)
Diffstat (limited to 'src/leap/eip/udstelnet.py')
-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) |