[imp] replace hasattr usages with getattr in socket shutdowns

bzr revid: xmo@tinyerp.com-20100103141457-uff2ss505npnkoti
This commit is contained in:
Xavier Morel 2010-01-03 15:14:57 +01:00
parent 9ff92fa5e1
commit eca47ce8b6
2 changed files with 5 additions and 9 deletions

View File

@ -137,7 +137,7 @@ class BaseHttpDaemon(threading.Thread, netsvc.Server):
if os.name != 'nt':
try:
self.server.socket.shutdown(
hasattr(socket, 'SHUT_RDWR') and socket.SHUT_RDWR or 2)
getattr(socket, 'SHUT_RDWR', 2)
except socket.error, e:
if e.errno != 57: raise
# OSX, socket shutdowns both sides if any side closes it

View File

@ -42,10 +42,8 @@ class TinySocketClientThread(threading.Thread, netsvc.OpenERPDispatcher):
def __del__(self):
if self.sock:
try:
if hasattr(socket, 'SHUT_RDWR'):
self.socket.shutdown(socket.SHUT_RDWR)
else:
self.socket.shutdown(2)
self.socket.shutdown(
getattr(socket, 'SHUT_RDWR', 2))
except: pass
# That should garbage-collect and close it, too
self.sock = None
@ -131,10 +129,8 @@ class TinySocketServerThread(threading.Thread,netsvc.Server):
for t in self.threads:
t.stop()
try:
if hasattr(socket, 'SHUT_RDWR'):
self.socket.shutdown(socket.SHUT_RDWR)
else:
self.socket.shutdown(2)
self.socket.shutdown(
getattr(socket, 'SHUT_RDWR', 2))
self.socket.close()
except:
return False