MCPcopy Index your code
hub / github.com/pyload/pyload / Socket

Class Socket

module/remote/thriftbackend/Socket.py:44–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42 return self.recv(buff)
43
44class Socket(TSocket):
45 def __init__(self, host='localhost', port=7228, ssl=False):
46 TSocket.__init__(self, host, port)
47 self.ssl = ssl
48
49 def open(self):
50 if self.ssl:
51 SSL = __import__("OpenSSL", globals(), locals(), "SSL", -1).SSL
52 WantReadError = SSL.WantReadError
53 ctx = SSL.Context(SSL.SSLv23_METHOD)
54 c = SSL.Connection(ctx, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
55 c.set_connect_state()
56 self.handle = SecureSocketConnection(c)
57 else:
58 self.handle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
59
60 #errno 104 connection reset
61
62 self.handle.settimeout(self._timeout)
63 self.handle.connect((self.host, self.port))
64
65 def read(self, sz):
66 try:
67 buff = self.handle.recv(sz)
68 except socket.error, e:
69 if (e.args[0] == errno.ECONNRESET and
70 (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
71 # freebsd and Mach don't follow POSIX semantic of recv
72 # and fail with ECONNRESET if peer performed shutdown.
73 # See corresponding comment and code in TSocket::read()
74 # in lib/cpp/src/transport/TSocket.cpp.
75 self.close()
76 # Trigger the check to raise the END_OF_FILE exception below.
77 buff = ''
78 else:
79 raise
80 except Exception, e:
81 # SSL connection was closed
82 if e.args == (-1, 'Unexpected EOF'):
83 buff = ''
84 elif e.args == ([('SSL routines', 'SSL23_GET_CLIENT_HELLO', 'unknown protocol')],):
85 #a socket not using ssl tried to connect
86 buff = ''
87 else:
88 raise
89
90 if not len(buff):
91 raise TTransportException(type=TTransportException.END_OF_FILE, message='TSocket read 0 bytes')
92 return buff
93
94
95class ServerSocket(TServerSocket, Socket):

Callers 3

createConnectionMethod · 0.90
ThriftTest.pyFile · 0.90
acceptMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected