socket: Add some comments; a bit more obvious variable naming

This commit is contained in:
Yury Selivanov 2014-07-15 12:26:06 -04:00
parent 1607065f4d
commit 17d4d6f66f
1 changed files with 7 additions and 5 deletions

View File

@ -20,19 +20,21 @@ class socket:
def __init__(self, *args, _from_sock=None, **kwargs): def __init__(self, *args, _from_sock=None, **kwargs):
if _from_sock: if _from_sock:
sock = None own_sock = None
self._sock = _from_sock self._sock = _from_sock
else: else:
sock = std_socket(*args, **kwargs) own_sock = std_socket(*args, **kwargs)
self._sock = sock self._sock = own_sock
try: try:
self._sock.setblocking(False) self._sock.setblocking(False)
self._loop = asyncio.get_event_loop() self._loop = asyncio.get_event_loop()
assert isinstance(self._loop, GreenUnixSelectorLoop), \ assert isinstance(self._loop, GreenUnixSelectorLoop), \
'GreenUnixSelectorLoop event loop is required' 'GreenUnixSelectorLoop event loop is required'
except: except:
if sock is not None: if own_sock is not None:
sock.close() # An unexpected error has occurred. Close the
# socket object if it was created in __init__.
own_sock.close()
raise raise
@classmethod @classmethod