本文整理汇总了Python中socket.socket.__init__函数的典型用法代码示例。如果您正苦于以下问题:Python __init__函数的具体用法?Python __init__怎么用?Python __init__使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了__init__函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True, ciphers=None):
socket.__init__(self, _sock=sock._sock)
# "close" the original socket: it is not usable any more.
# this only calls _drop(), which should not actually call
# the operating system's close() because the reference
# counter is greater than 1 (we hold one too).
sock.close()
if ciphers is None and ssl_version != _SSLv2_IF_EXISTS:
ciphers = _DEFAULT_CIPHERS
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error, e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._connected = False
self._sslobj = None
示例2: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True, ciphers=None):
# Can't use sock.type as other flags (such as SOCK_NONBLOCK) get
# mixed in.
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
raise NotImplementedError("only stream sockets are supported")
socket.__init__(self, _sock=sock._sock)
# "close" the original socket: it is not usable any more. which should
# not actually call the operating system's close() because the
# reference counter is greater than 1 (we hold one too).
sock._sock._drop()
if ciphers is None and ssl_version != _SSLv2_IF_EXISTS:
ciphers = _DEFAULT_CIPHERS
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error, e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._connected = False
self._sslobj = None
示例3: __init__
def __init__(self,ip,port):
self.port = port
self.ip = ip
self.host = (ip,port)
socket.__init__(self, AF_INET, SOCK_DGRAM)
self.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
self.tx_en = 0
self.rx_en = 0
self.tx_s = 0
self.rx_s = 0
self.tx_thread = threading.Thread(target = self.tx, name = 'tx')
self.rx_thread = threading.Thread(target = self.rx, name = 'rx')
self.rx_cnt = 0
self.tx_cnt = 0
self.rx_time = 0
self.rx_offset = 0
self.tx_time = 0
self.tx_offset = 0
self.data = (c_uint*0x100)()
memset(byref(self.data),0,0x400)
self.length = 1920000
self.rd = (c_uint*self.length)()
self.mutex = threading.Lock()
示例4: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True):
socket.__init__(self, _sock=sock._sock)
# The initializer for socket overrides the methods send(), recv(), etc.
# in the instancce, which we don't need -- but we want to provide the
# methods defined in SSLSocket.
for attr in _delegate_methods:
try:
delattr(self, attr)
except AttributeError:
pass
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error, e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._sslobj = None
示例5: __init__
def __init__(self, sock, keyfile = None, certfile = None, server_side = False, cert_reqs = CERT_NONE, ssl_version = PROTOCOL_SSLv23, ca_certs = None, do_handshake_on_connect = True, suppress_ragged_eofs = True, ciphers = None):
socket.__init__(self, _sock=sock._sock)
for attr in _delegate_methods:
try:
delattr(self, attr)
except AttributeError:
pass
if certfile and not keyfile:
keyfile = certfile
try:
socket.getpeername(self)
except socket_error as e:
if e.errno != errno.ENOTCONN:
raise
self._sslobj = None
else:
self._sslobj = _ssl.sslwrap(self._sock, server_side, keyfile, certfile, cert_reqs, ssl_version, ca_certs, ciphers)
if do_handshake_on_connect:
self.do_handshake()
self.keyfile = keyfile
self.certfile = certfile
self.cert_reqs = cert_reqs
self.ssl_version = ssl_version
self.ca_certs = ca_certs
self.ciphers = ciphers
self.do_handshake_on_connect = do_handshake_on_connect
self.suppress_ragged_eofs = suppress_ragged_eofs
self._makefile_refs = 0
示例6: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True, ciphers=None):
# Can't use sock.type as other flags (such as SOCK_NONBLOCK) get
# mixed in.
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
raise NotImplementedError("only stream sockets are supported")
socket.__init__(self, _sock=sock._sock)
# The initializer for socket overrides the methods send(), recv(), etc.
# in the instancce, which we don't need -- but we want to provide the
# methods defined in SSLSocket.
for attr in _delegate_methods:
try:
delattr(self, attr)
except AttributeError:
pass
if ciphers is None and ssl_version != _SSLv2_IF_EXISTS:
ciphers = _DEFAULT_CIPHERS
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error, e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._connected = False
self._sslobj = None
示例7: __init__
def __init__(self,db):
self._ipcPath=db.getSettingPath()
SocketlikeIPC.__init__(self, self._ipcPath)
# super(type(self),self).__init__(self._ipcPath)
# if super(type(self),self)._connect():
if SocketlikeIPC._connect(self):
print('IPC connect succeed. Welcome back, administrator.')
return
print('IPC failed. proceeding with TCP.')
super(type(self)) #unbound
socket.__init__(self)
try:
socket.connect(self,('racu.idea.sh', PortEnum.MAIN_SERVER.value))
lastPin = db.getConfig()
print('lastPin =', lastPin, len(lastPin))
pinmsg = int.to_bytes(SocketEnum.PIN.value, 1, 'big') + int.to_bytes(lastPin[0]) if 10**3<=lastPin['lastPIN']<10**4 else b''
msg = ''
# while not msg:
socket.sendall(self,pinmsg)
msg = socket.recv(self)
if not msg:
print('main server connect error')
return
except:
print('main server connect error')
示例8: __init__
def __init__(self, sock, keyfile=None, certfile=None):
socket.__init__(self, _sock=sock._sock)
# the initializer for socket trashes the methods (tsk, tsk), so...
self.send = lambda data, flags=0: SSLSocket.send(self, data, flags)
self.sendto = lambda data, addr, flags=0: SSLSocket.sendto(self, data, addr, flags)
self.recv = lambda buflen=1024, flags=0: SSLSocket.recv(self, buflen, flags)
self.recvfrom = lambda addr, buflen=1024, flags=0: SSLSocket.recvfrom(self, addr, buflen, flags)
self.recv_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recv_into(self, buffer, nbytes, flags)
self.recvfrom_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recvfrom_into(self, buffer, nbytes, flags)
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error:
# no, no connection yet
self._sslobj = None
else:
# yes, create the SSL object
self._sslobj = _ssl.ssl(self._sock, keyfile, certfile)
timeout = self.gettimeout()
try:
self.settimeout(None)
self.do_handshake()
finally:
self.settimeout(timeout)
self.keyfile = keyfile
self.certfile = certfile
self._makefile_refs = 0
示例9: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True, ciphers=None, server_hostname=None):
socket.__init__(self, _sock=sock._sock)
# The initializer for socket overrides the methods send(), recv(), etc.
# in the instancce, which we don't need -- but we want to provide the
# methods defined in SSLSocket.
for attr in _delegate_methods:
try:
delattr(self, attr)
except AttributeError:
pass
if ciphers is None and ssl_version != _SSLv2_IF_EXISTS:
ciphers = _DEFAULT_CIPHERS
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error as e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._connected = False
self._sslobj = None
else:
# yes, create the SSL object
self._connected = True
self._sslobj = _ssl.sslwrap(self._sock, server_side,
keyfile, certfile,
cert_reqs, ssl_version, ca_certs,
ciphers, server_hostname)
if do_handshake_on_connect:
self.do_handshake()
self.keyfile = keyfile
self.certfile = certfile
self.cert_reqs = cert_reqs
self.ssl_version = ssl_version
self.ca_certs = ca_certs
self.ciphers = ciphers
self.server_hostname = server_hostname
self.do_handshake_on_connect = do_handshake_on_connect
self.suppress_ragged_eofs = suppress_ragged_eofs
self._makefile_refs = 0
示例10: __init__
def __init__(self):
socket.__init__(self, AF_INET, SOCK_DGRAM)
self.__pacotes_recebidos_lk = thread.allocate_lock()
self.__pacotes_recebidos = []
self.__pacotes_confirmar_lk = thread.allocate_lock()
self.__pacotes_confirmar = {}
self.__vusuarios_lk = thread.allocate_lock()
self.__vusuarios = {}
self.ALLOWED = 0
self.DENIED = 1
self.PASSED = 2
示例11: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True, ciphers=None):
socket.__init__(self, _sock=sock._sock)
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error, e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._sslobj = None
示例12: __init__
def __init__(self, ifname, bpf=None):
self.ifname = ifname
# lookup the interface details
with IPRoute() as ip:
for link in ip.get_links():
if link.get_attr("IFLA_IFNAME") == ifname:
break
else:
raise IOError(2, "Link not found")
self.l2addr = link.get_attr("IFLA_ADDRESS")
self.ifindex = link["index"]
# bring up the socket
socket.__init__(self, AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))
socket.bind(self, (self.ifname, ETH_P_ALL))
if bpf:
fstring, self.fprog = compile_bpf(bpf)
socket.setsockopt(self, SOL_SOCKET, SO_ATTACH_FILTER, fstring)
示例13: __init__
def __init__(self, sock, server_hostname=None, client_certificate=None, context=None, **kwargs):
server_side = False
do_handshake_on_connect = True
self._client_certificate = client_certificate
self._sslobj = context
connected = False
if sock is not None:
socket.__init__(self,
family=sock.family,
type=sock.type,
proto=sock.proto,
fileno=sock.fileno())
self.settimeout(sock.gettimeout())
# see if it's connected
try:
sock.getpeername()
except socket_error as e:
if e.errno != errno.ENOTCONN:
raise
else:
connected = True
sock.detach()
self._connected = connected
if connected:
try:
if self._sslobj is None:
self._sslobj = SSLContext()
self._sslobj._wrap_socket(self,
server_side,
server_hostname=server_hostname,
client_certificate=self._client_certificate)
if do_handshake_on_connect:
timeout = self.gettimeout()
if timeout == 0.0:
# non-blocking
raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
self.do_handshake()
except socket_error as x:
self.close()
raise x
示例14: __init__
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True):
socket.__init__(self, _sock=sock._sock)
# the initializer for socket trashes the methods (tsk, tsk), so...
self.send = lambda data, flags=0: SSLSocket.send(self, data, flags)
self.sendto = lambda data, addr, flags=0: SSLSocket.sendto(self, data, addr, flags)
self.recv = lambda buflen=1024, flags=0: SSLSocket.recv(self, buflen, flags)
self.recvfrom = lambda addr, buflen=1024, flags=0: SSLSocket.recvfrom(self, addr, buflen, flags)
self.recv_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recv_into(self, buffer, nbytes, flags)
self.recvfrom_into = lambda buffer, nbytes=None, flags=0: SSLSocket.recvfrom_into(self, buffer, nbytes, flags)
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except:
# no, no connection yet
self._sslobj = None
else:
# yes, create the SSL object
self._sslobj = _ssl.sslwrap(self._sock, server_side,
keyfile, certfile,
cert_reqs, ssl_version, ca_certs)
if do_handshake_on_connect:
timeout = self.gettimeout()
try:
if timeout == 0:
self.settimeout(None)
self.do_handshake()
finally:
self.settimeout(timeout)
self.keyfile = keyfile
self.certfile = certfile
self.cert_reqs = cert_reqs
self.ssl_version = ssl_version
self.ca_certs = ca_certs
self.do_handshake_on_connect = do_handshake_on_connect
self.suppress_ragged_eofs = suppress_ragged_eofs
self._makefile_refs = 0
示例15: __init__
def __init__(self, ifname, bpf=None):
self.ifname = ifname
# lookup the interface details
with IPRoute() as ip:
for link in ip.get_links():
if link.get_attr('IFLA_IFNAME') == ifname:
break
else:
raise IOError(2, 'Link not found')
self.l2addr = link.get_attr('IFLA_ADDRESS')
self.ifindex = link['index']
# bring up the socket
socket.__init__(self, AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))
socket.bind(self, (self.ifname, ETH_P_ALL))
if bpf:
self.clear_buffer()
fstring, self.fprog = compile_bpf(bpf)
socket.setsockopt(self, SOL_SOCKET, SO_ATTACH_FILTER, fstring)
else:
self.clear_buffer(remove_total_filter=True)