当前位置: 首页>>代码示例>>Python>>正文


Python socket.__init__函数代码示例

本文整理汇总了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
开发者ID:Zekom,项目名称:pypyjs,代码行数:27,代码来源:ssl.py

示例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
开发者ID:BartoszCichecki,项目名称:onlinepython,代码行数:30,代码来源:ssl.py

示例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()
开发者ID:RP7,项目名称:R7-OCM,代码行数:27,代码来源:udp_client.py

示例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
开发者ID:ToM-Korn,项目名称:sublime-text-2-plugin,代码行数:25,代码来源:ssl.py

示例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
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:30,代码来源:ssl.py

示例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
开发者ID:KrishMunot,项目名称:pyston,代码行数:33,代码来源:ssl.py

示例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')
开发者ID:chidea,项目名称:rebauth,代码行数:25,代码来源:ServerSocket.py

示例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
开发者ID:maximerobin,项目名称:Ufwi,代码行数:30,代码来源:ssl.py

示例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
开发者ID:akkakks,项目名称:backport_ssl,代码行数:48,代码来源:ssl.py

示例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            
开发者ID:avnergoncalves,项目名称:VinerOn,代码行数:16,代码来源:vsocket.py

示例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
开发者ID:gorakhargosh,项目名称:pypy,代码行数:17,代码来源:ssl.py

示例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)
开发者ID:roolebo,项目名称:pyroute2,代码行数:17,代码来源:rawsocket.py

示例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
开发者ID:lsowen,项目名称:pySchannelSSL,代码行数:45,代码来源:sslsocket.py

示例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
开发者ID:planetlab,项目名称:sfa,代码行数:43,代码来源:ssl_socket.py

示例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)
开发者ID:svinota,项目名称:pyroute2,代码行数:20,代码来源:rawsocket.py


注:本文中的socket.socket.__init__函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。