Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
socket.socket Class Reference
Inheritance diagram for socket.socket:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def __enter__
def __exit__
def __repr__
def dup
def accept
def makefile
def close

Private Member Functions

def _decref_socketios
def _real_close

Private Attributes

 _io_refs
 _closed

Static Private Attributes

list __slots__ = ["__weakref__", "_io_refs", "_closed"]

Detailed Description

A subclass of _socket.socket adding the makefile() method.

Definition at line 87 of file socket.py.


Constructor & Destructor Documentation

def socket.socket.__init__ (   self,
  family = AF_INET,
  type = SOCK_STREAM,
  proto = 0,
  fileno = None 
)

Definition at line 93 of file socket.py.

00093 
00094     def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
00095         _socket.socket.__init__(self, family, type, proto, fileno)
00096         self._io_refs = 0
00097         self._closed = False

Here is the caller graph for this function:


Member Function Documentation

def socket.socket.__enter__ (   self)

Definition at line 98 of file socket.py.

00098 
00099     def __enter__(self):
00100         return self

def socket.socket.__exit__ (   self,
  args 
)

Definition at line 101 of file socket.py.

00101 
00102     def __exit__(self, *args):
00103         if not self._closed:
00104             self.close()

Here is the caller graph for this function:

def socket.socket.__repr__ (   self)
Wrap __repr__() to reveal the real class name.

Definition at line 105 of file socket.py.

00105 
00106     def __repr__(self):
00107         """Wrap __repr__() to reveal the real class name."""
00108         s = _socket.socket.__repr__(self)
00109         if s.startswith("<socket object"):
00110             s = "<%s.%s%s%s" % (self.__class__.__module__,
00111                                 self.__class__.__name__,
00112                                 getattr(self, '_closed', False) and " [closed] " or "",
00113                                 s[7:])
00114         return s

Here is the call graph for this function:

def socket.socket._decref_socketios (   self) [private]

Definition at line 184 of file socket.py.

00184 
00185     def _decref_socketios(self):
00186         if self._io_refs > 0:
00187             self._io_refs -= 1
00188         if self._closed:
00189             self.close()

def socket.socket._real_close (   self,
  _ss = _socket.socket 
) [private]

Definition at line 190 of file socket.py.

00190 
00191     def _real_close(self, _ss=_socket.socket):
00192         # This function should not reference any globals. See issue #808164.
00193         _ss.close(self)

Here is the caller graph for this function:

def socket.socket.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).

Reimplemented in ssl.SSLSocket.

Definition at line 125 of file socket.py.

00125 
00126     def accept(self):
00127         """accept() -> (socket object, address info)
00128 
00129         Wait for an incoming connection.  Return a new socket
00130         representing the connection, and the address of the client.
00131         For IP sockets, the address info is a pair (hostaddr, port).
00132         """
00133         fd, addr = self._accept()
00134         sock = socket(self.family, self.type, self.proto, fileno=fd)
00135         # Issue #7995: if no default timeout is set and the listening
00136         # socket had a (non-zero) timeout, force the new socket in blocking
00137         # mode to override platform-specific socket flags inheritance.
00138         if getdefaulttimeout() is None and self.gettimeout():
00139             sock.setblocking(True)
00140         return sock, addr

Here is the call graph for this function:

def socket.socket.close (   self)

Definition at line 194 of file socket.py.

00194 
00195     def close(self):
00196         # This function should not reference any globals. See issue #808164.
00197         self._closed = True
00198         if self._io_refs <= 0:
00199             self._real_close()

Here is the call graph for this function:

Here is the caller graph for this function:

def socket.socket.dup (   self)
dup() -> socket object

Return a new socket object connected to the same system resource.

Reimplemented in ssl.SSLSocket.

Definition at line 115 of file socket.py.

00115 
00116     def dup(self):
00117         """dup() -> socket object
00118 
00119         Return a new socket object connected to the same system resource.
00120         """
00121         fd = dup(self.fileno())
00122         sock = self.__class__(self.family, self.type, self.proto, fileno=fd)
00123         sock.settimeout(self.gettimeout())
00124         return sock

Here is the call graph for this function:

Here is the caller graph for this function:

def socket.socket.makefile (   self,
  mode = "r",
  buffering = None,
  encoding = None,
  errors = None,
  newline = None 
)
makefile(...) -> an I/O stream connected to the socket

The arguments are as for io.open() after the filename,
except the only mode characters supported are 'r', 'w' and 'b'.
The semantics are similar too.  (XXX refactor to share code?)

Definition at line 142 of file socket.py.

00142 
00143                  encoding=None, errors=None, newline=None):
00144         """makefile(...) -> an I/O stream connected to the socket
00145 
00146         The arguments are as for io.open() after the filename,
00147         except the only mode characters supported are 'r', 'w' and 'b'.
00148         The semantics are similar too.  (XXX refactor to share code?)
00149         """
00150         for c in mode:
00151             if c not in {"r", "w", "b"}:
00152                 raise ValueError("invalid mode %r (only r, w, b allowed)")
00153         writing = "w" in mode
00154         reading = "r" in mode or not writing
00155         assert reading or writing
00156         binary = "b" in mode
00157         rawmode = ""
00158         if reading:
00159             rawmode += "r"
00160         if writing:
00161             rawmode += "w"
00162         raw = SocketIO(self, rawmode)
00163         self._io_refs += 1
00164         if buffering is None:
00165             buffering = -1
00166         if buffering < 0:
00167             buffering = io.DEFAULT_BUFFER_SIZE
00168         if buffering == 0:
00169             if not binary:
00170                 raise ValueError("unbuffered streams must be binary")
00171             return raw
00172         if reading and writing:
00173             buffer = io.BufferedRWPair(raw, raw, buffering)
00174         elif reading:
00175             buffer = io.BufferedReader(raw, buffering)
00176         else:
00177             assert writing
00178             buffer = io.BufferedWriter(raw, buffering)
00179         if binary:
00180             return buffer
00181         text = io.TextIOWrapper(buffer, encoding, errors, newline)
00182         text.mode = mode
00183         return text

Here is the caller graph for this function:


Member Data Documentation

list socket.socket.__slots__ = ["__weakref__", "_io_refs", "_closed"] [static, private]

Definition at line 91 of file socket.py.

Reimplemented in ssl.SSLSocket.

Definition at line 96 of file socket.py.

Definition at line 95 of file socket.py.


The documentation for this class was generated from the following file: