Skip to content
Snippets Groups Projects
Commit b6b789f1 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Socket constructor improved

a satella Socket can be constructed directly from another satella Socket
parent 9495f7c7
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,12 @@ class Socket(FileDescriptorChannel): ...@@ -19,8 +19,12 @@ class Socket(FileDescriptorChannel):
""" """
def __init__(self, socket): def __init__(self, socket):
"""@type socket: native network socket or L{Socket}"""
FileDescriptorChannel.__init__(self) FileDescriptorChannel.__init__(self)
self.socket = socket if isinstance(socket, Socket):
self.socket = socket.socket
else:
self.socket = socket
self.active = True self.active = True
self.blocking = True self.blocking = True
self.timeout = None self.timeout = None
......
...@@ -186,3 +186,11 @@ class SocketsTest(unittest.TestCase): ...@@ -186,3 +186,11 @@ class SocketsTest(unittest.TestCase):
self.assertEquals(cs.pkdata, 'Yes') self.assertEquals(cs.pkdata, 'Yes')
self.assertEquals(cs.data, 'Yes') self.assertEquals(cs.data, 'Yes')
sck.close() sck.close()
def test_reassignment(self):
"""Tests creating a satella socket from a satella socket
instead of a native socket"""
sck = socket(AF_INET, SOCK_STREAM)
sock = Socket(sck)
sock = Socket(sock)
self.assertEquals(sock.socket, sck)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment