本文整理匯總了Python中_socket.socket方法的典型用法代碼示例。如果您正苦於以下問題:Python _socket.socket方法的具體用法?Python _socket.socket怎麽用?Python _socket.socket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類_socket
的用法示例。
在下文中一共展示了_socket.socket方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: socketpair
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def socketpair(family=None, type=SOCK_STREAM, proto=0):
"""socketpair([family[, type[, proto]]]) -> (socket object, socket object)
Create a pair of socket objects from the sockets returned by the platform
socketpair() function.
The arguments are the same as for socket() except the default family is
AF_UNIX if defined on the platform; otherwise, the default is AF_INET.
"""
if family is None:
try:
family = AF_UNIX
except NameError:
family = AF_INET
a, b = _socket.socketpair(family, type, proto)
a = socket(family, type, proto, a.detach())
b = socket(family, type, proto, b.detach())
return a, b
示例2: readinto
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def readinto(self, b):
"""Read up to len(b) bytes into the writable buffer *b* and return
the number of bytes read. If the socket is non-blocking and no bytes
are available, None is returned.
If *b* is non-empty, a 0 return value indicates that the connection
was shutdown at the other end.
"""
self._checkClosed()
self._checkReadable()
if self._timeout_occurred:
raise IOError("cannot read from timed out object")
while True:
try:
return self._sock.recv_into(b)
except timeout:
self._timeout_occurred = True
raise
# except InterruptedError:
# continue
except error as e:
if e.args[0] in _blocking_errnos:
return None
raise
示例3: testHostnameRes
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def testHostnameRes(self):
# Testing hostname resolution mechanisms
hostname = socket.gethostname()
try:
ip = socket.gethostbyname(hostname)
except socket.error:
# Probably name lookup wasn't set up right; skip this test
self.skipTest('name lookup failure')
self.assertTrue(ip.find('.') >= 0, "Error resolving host to ip.")
try:
hname, aliases, ipaddrs = socket.gethostbyaddr(ip)
except socket.error:
# Probably a similar problem as above; skip this test
self.skipTest('address lookup failure')
all_host_names = [hostname, hname] + aliases
fqhn = socket.getfqdn(ip)
if not fqhn in all_host_names:
self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names)))
示例4: __init__
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
_socket.socket.__init__(self, family, type, proto, fileno)
self._io_refs = 0
self._closed = False
示例5: __repr__
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def __repr__(self):
"""Wrap __repr__() to reveal the real class name."""
s = _socket.socket.__repr__(self)
if s.startswith("<socket object"):
s = "<%s.%s%s%s" % (self.__class__.__module__,
self.__class__.__name__,
getattr(self, '_closed', False) and " [closed] " or "",
s[7:])
return s
示例6: __getstate__
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def __getstate__(self):
raise TypeError("Cannot serialize socket object")
示例7: dup
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def dup(self):
"""dup() -> socket object
Return a new socket object connected to the same system resource.
"""
fd = dup(self.fileno())
sock = self.__class__(self.family, self.type, self.proto, fileno=fd)
sock.settimeout(self.gettimeout())
return sock
示例8: accept
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def accept(self):
"""accept() -> (socket object, address info)
Wait for an incoming connection. Return a new socket
representing the connection, and the address of the client.
For IP sockets, the address info is a pair (hostaddr, port).
"""
fd, addr = self._accept()
sock = socket(self.family, self.type, self.proto, fileno=fd)
# Issue #7995: if no default timeout is set and the listening
# socket had a (non-zero) timeout, force the new socket in blocking
# mode to override platform-specific socket flags inheritance.
if getdefaulttimeout() is None and self.gettimeout():
sock.setblocking(True)
return sock, addr
示例9: _real_close
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def _real_close(self, _ss=_socket.socket):
# This function should not reference any globals. See issue #808164.
_ss.close(self)
示例10: detach
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def detach(self):
"""detach() -> file descriptor
Close the socket object without closing the underlying file descriptor.
The object cannot be used after this call, but the file descriptor
can be reused for other purposes. The file descriptor is returned.
"""
self._closed = True
return super().detach()
示例11: fromfd
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def fromfd(fd, family, type, proto=0):
""" fromfd(fd, family, type[, proto]) -> socket object
Create a socket object from a duplicate of the given file
descriptor. The remaining arguments are the same as for socket().
"""
nfd = dup(fd)
return socket(family, type, proto, nfd)
示例12: fromshare
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def fromshare(info):
""" fromshare(info) -> socket object
Create a socket object from a the bytes object returned by
socket.share(pid).
"""
return socket(0, 0, 0, info)
示例13: write
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def write(self, b):
"""Write the given bytes or bytearray object *b* to the socket
and return the number of bytes written. This can be less than
len(b) if not all data could be written. If the socket is
non-blocking and no bytes could be written None is returned.
"""
self._checkClosed()
self._checkWritable()
try:
return self._sock.send(b)
except error as e:
# XXX what about EINTR?
if e.args[0] in _blocking_errnos:
return None
raise
示例14: readable
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def readable(self):
"""True if the SocketIO is open for reading.
"""
if self.closed:
raise ValueError("I/O operation on closed socket.")
return self._reading
示例15: writable
# 需要導入模塊: import _socket [as 別名]
# 或者: from _socket import socket [as 別名]
def writable(self):
"""True if the SocketIO is open for writing.
"""
if self.closed:
raise ValueError("I/O operation on closed socket.")
return self._writing