2024-05-08 16:52:39 -03:00
|
|
|
:mod:`!socket` --- Low-level networking interface
|
|
|
|
=================================================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. module:: socket
|
|
|
|
:synopsis: Low-level networking interface.
|
|
|
|
|
2016-06-11 16:02:54 -03:00
|
|
|
**Source code:** :source:`Lib/socket.py`
|
|
|
|
|
|
|
|
--------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This module provides access to the BSD *socket* interface. It is available on
|
2014-03-01 08:53:28 -04:00
|
|
|
all modern Unix systems, Windows, MacOS, and probably additional platforms.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Some behavior may be platform dependent, since calls are made to the operating
|
|
|
|
system socket APIs.
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
|
|
|
|
.. include:: ../includes/wasm-notavail.rst
|
|
|
|
|
2023-05-04 07:04:41 -03:00
|
|
|
.. index:: pair: object; socket
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The Python interface is a straightforward transliteration of the Unix system
|
|
|
|
call and library interface for sockets to Python's object-oriented style: the
|
2023-11-27 10:36:54 -04:00
|
|
|
:func:`~socket.socket` function returns a :dfn:`socket object` whose methods implement
|
2007-08-15 11:28:22 -03:00
|
|
|
the various socket system calls. Parameter types are somewhat higher-level than
|
|
|
|
in the C interface: as with :meth:`read` and :meth:`write` operations on Python
|
|
|
|
files, buffer allocation on receive operations is automatic, and buffer length
|
|
|
|
is implicit on send operations.
|
|
|
|
|
|
|
|
|
2011-01-02 18:12:22 -04:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
Module :mod:`socketserver`
|
|
|
|
Classes that simplify writing network servers.
|
|
|
|
|
|
|
|
Module :mod:`ssl`
|
|
|
|
A TLS/SSL wrapper for socket objects.
|
|
|
|
|
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
Socket families
|
|
|
|
---------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
Depending on the system and the build options, various socket families
|
|
|
|
are supported by this module.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-12-16 09:46:36 -04:00
|
|
|
The address format required by a particular socket object is automatically
|
|
|
|
selected based on the address family specified when the socket object was
|
|
|
|
created. Socket addresses are represented as follows:
|
|
|
|
|
|
|
|
- The address of an :const:`AF_UNIX` socket bound to a file system node
|
|
|
|
is represented as a string, using the file system encoding and the
|
|
|
|
``'surrogateescape'`` error handler (see :pep:`383`). An address in
|
2015-03-20 04:00:36 -03:00
|
|
|
Linux's abstract namespace is returned as a :term:`bytes-like object` with
|
2011-12-16 09:46:36 -04:00
|
|
|
an initial null byte; note that sockets in this namespace can
|
|
|
|
communicate with normal file system sockets, so programs intended to
|
|
|
|
run on Linux may need to deal with both types of address. A string or
|
2015-03-20 04:00:36 -03:00
|
|
|
bytes-like object can be used for either type of address when
|
2011-12-16 09:46:36 -04:00
|
|
|
passing it as an argument.
|
|
|
|
|
2020-12-17 13:25:55 -04:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Previously, :const:`AF_UNIX` socket paths were assumed to use UTF-8
|
|
|
|
encoding.
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2020-12-17 13:25:55 -04:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
Writable :term:`bytes-like object` is now accepted.
|
2015-03-20 04:00:36 -03:00
|
|
|
|
2016-09-07 15:01:23 -03:00
|
|
|
.. _host_port:
|
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
- A pair ``(host, port)`` is used for the :const:`AF_INET` address family,
|
2021-07-26 19:11:55 -03:00
|
|
|
where *host* is a string representing either a hostname in internet domain
|
2010-12-12 16:57:12 -04:00
|
|
|
notation like ``'daring.cwi.nl'`` or an IPv4 address like ``'100.50.200.5'``,
|
2012-06-13 19:37:09 -03:00
|
|
|
and *port* is an integer.
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2018-07-28 07:03:23 -03:00
|
|
|
- For IPv4 addresses, two special forms are accepted instead of a host
|
|
|
|
address: ``''`` represents :const:`INADDR_ANY`, which is used to bind to all
|
|
|
|
interfaces, and the string ``'<broadcast>'`` represents
|
|
|
|
:const:`INADDR_BROADCAST`. This behavior is not compatible with IPv6,
|
|
|
|
therefore, you may want to avoid these if you intend to support IPv6 with your
|
|
|
|
Python programs.
|
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
- For :const:`AF_INET6` address family, a four-tuple ``(host, port, flowinfo,
|
2020-02-26 10:33:57 -04:00
|
|
|
scope_id)`` is used, where *flowinfo* and *scope_id* represent the ``sin6_flowinfo``
|
2010-12-12 16:57:12 -04:00
|
|
|
and ``sin6_scope_id`` members in :const:`struct sockaddr_in6` in C. For
|
2020-02-26 10:33:57 -04:00
|
|
|
:mod:`socket` module methods, *flowinfo* and *scope_id* can be omitted just for
|
|
|
|
backward compatibility. Note, however, omission of *scope_id* can cause problems
|
2010-12-12 16:57:12 -04:00
|
|
|
in manipulating scoped IPv6 addresses.
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2018-02-12 15:47:42 -04:00
|
|
|
.. versionchanged:: 3.7
|
2020-02-26 10:33:57 -04:00
|
|
|
For multicast addresses (with *scope_id* meaningful) *address* may not contain
|
|
|
|
``%scope_id`` (or ``zone id``) part. This information is superfluous and may
|
2018-02-12 15:47:42 -04:00
|
|
|
be safely omitted (recommended).
|
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
- :const:`AF_NETLINK` sockets are represented as pairs ``(pid, groups)``.
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
- Linux-only support for TIPC is available using the :const:`AF_TIPC`
|
|
|
|
address family. TIPC is an open, non-IP based networked protocol designed
|
|
|
|
for use in clustered computer environments. Addresses are represented by a
|
|
|
|
tuple, and the fields depend on the address type. The general tuple form is
|
|
|
|
``(addr_type, v1, v2, v3 [, scope])``, where:
|
Merged revisions 80605-80609,80642-80646,80651-80652,80674,80684-80686,80748,80852,80854,80870,80872-80873,80907,80915-80916,80951-80952,80976-80977,80985,81038-81040,81042,81053,81070,81104-81105,81114,81125,81245,81285,81402,81463,81516,81562-81563,81567,81593,81635,81680-81681,81684,81801,81888,81931-81933,81939-81942,81963,81984,81991,82120,82188,82264-82267 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80605 | andrew.kuchling | 2010-04-28 19:22:16 -0500 (Wed, 28 Apr 2010) | 1 line
Add various items
........
r80606 | andrew.kuchling | 2010-04-28 20:44:30 -0500 (Wed, 28 Apr 2010) | 6 lines
Fix doubled 'the'.
Markup fixes to use :exc:, :option: in a few places.
(Glitch: unittest.main's -c ends up a link to the Python
interpreter's -c option. Should we skip using :option: for that
switch, or disable the auto-linking somehow?)
........
r80607 | andrew.kuchling | 2010-04-28 20:45:41 -0500 (Wed, 28 Apr 2010) | 1 line
Add various unittest items
........
r80608 | benjamin.peterson | 2010-04-28 22:18:05 -0500 (Wed, 28 Apr 2010) | 1 line
update pypy description
........
r80609 | benjamin.peterson | 2010-04-28 22:30:59 -0500 (Wed, 28 Apr 2010) | 1 line
update pypy url
........
r80642 | andrew.kuchling | 2010-04-29 19:49:09 -0500 (Thu, 29 Apr 2010) | 1 line
Always add space after RFC; reword paragraph
........
r80643 | andrew.kuchling | 2010-04-29 19:52:31 -0500 (Thu, 29 Apr 2010) | 6 lines
Reword paragraph to make its meaning clearer.
Antoine Pitrou: is my version of the paragraph still correct?
R. David Murray: is this more understandable than the previous version?
........
r80644 | andrew.kuchling | 2010-04-29 20:02:15 -0500 (Thu, 29 Apr 2010) | 1 line
Fix typos
........
r80645 | andrew.kuchling | 2010-04-29 20:32:47 -0500 (Thu, 29 Apr 2010) | 1 line
Markup fix; clarify by adding 'in that order'
........
r80646 | andrew.kuchling | 2010-04-29 20:33:40 -0500 (Thu, 29 Apr 2010) | 1 line
Add various items; rearrange unittest section a bit
........
r80651 | andrew.kuchling | 2010-04-30 08:46:55 -0500 (Fri, 30 Apr 2010) | 1 line
Minor grammar re-wording
........
r80652 | andrew.kuchling | 2010-04-30 08:47:34 -0500 (Fri, 30 Apr 2010) | 1 line
Add item
........
r80674 | andrew.kuchling | 2010-04-30 20:19:16 -0500 (Fri, 30 Apr 2010) | 1 line
Add various items
........
r80684 | andrew.kuchling | 2010-05-01 07:05:52 -0500 (Sat, 01 May 2010) | 1 line
Minor grammar fix
........
r80685 | andrew.kuchling | 2010-05-01 07:06:51 -0500 (Sat, 01 May 2010) | 1 line
Describe memoryview
........
r80686 | antoine.pitrou | 2010-05-01 07:16:39 -0500 (Sat, 01 May 2010) | 4 lines
Fix attribution. Travis didn't do much and he did a bad work.
(yes, this is a sensitive subject, sorry)
........
r80748 | andrew.kuchling | 2010-05-03 20:24:22 -0500 (Mon, 03 May 2010) | 1 line
Add some more items; the urlparse change is added twice
........
r80852 | andrew.kuchling | 2010-05-05 20:09:47 -0500 (Wed, 05 May 2010) | 1 line
Reword paragraph; fix filename, which should be pyconfig.h
........
r80854 | andrew.kuchling | 2010-05-05 20:10:56 -0500 (Wed, 05 May 2010) | 1 line
Add various items
........
r80870 | andrew.kuchling | 2010-05-06 09:14:09 -0500 (Thu, 06 May 2010) | 1 line
Describe ElementTree 1.3; rearrange new-module sections; describe dict views as sets; small edits and items
........
r80872 | andrew.kuchling | 2010-05-06 12:21:59 -0500 (Thu, 06 May 2010) | 1 line
Add 2 items; record ideas for two initial sections; clarify wording
........
r80873 | andrew.kuchling | 2010-05-06 12:27:57 -0500 (Thu, 06 May 2010) | 1 line
Change section title; point to unittest2
........
r80907 | andrew.kuchling | 2010-05-06 20:45:14 -0500 (Thu, 06 May 2010) | 1 line
Add a new section on the development plan; add an item
........
r80915 | antoine.pitrou | 2010-05-07 05:15:51 -0500 (Fri, 07 May 2010) | 3 lines
Fix some markup and a class name. Also, wrap a long line.
........
r80916 | andrew.kuchling | 2010-05-07 06:30:47 -0500 (Fri, 07 May 2010) | 1 line
Re-word text
........
r80951 | andrew.kuchling | 2010-05-07 20:15:26 -0500 (Fri, 07 May 2010) | 1 line
Add two items
........
r80952 | andrew.kuchling | 2010-05-07 20:35:55 -0500 (Fri, 07 May 2010) | 1 line
Get accents correct
........
r80976 | andrew.kuchling | 2010-05-08 08:28:03 -0500 (Sat, 08 May 2010) | 1 line
Add logging.dictConfig example; give up on writing a Ttk example
........
r80977 | andrew.kuchling | 2010-05-08 08:29:46 -0500 (Sat, 08 May 2010) | 1 line
Markup fixes
........
r80985 | andrew.kuchling | 2010-05-08 10:39:46 -0500 (Sat, 08 May 2010) | 7 lines
Write summary of the 2.7 release; rewrite the future section some more;
mention PYTHONWARNINGS env. var; tweak some examples for readability.
And with this commit, the "What's New" is done... except for a
complete read-through to polish the text, and fixing any reported errors,
but those tasks can easily wait until after beta2.
........
r81038 | benjamin.peterson | 2010-05-09 16:09:40 -0500 (Sun, 09 May 2010) | 1 line
finish clause
........
r81039 | andrew.kuchling | 2010-05-10 09:18:27 -0500 (Mon, 10 May 2010) | 1 line
Markup fix; re-word a sentence
........
r81040 | andrew.kuchling | 2010-05-10 09:20:12 -0500 (Mon, 10 May 2010) | 1 line
Use title case
........
r81042 | andrew.kuchling | 2010-05-10 10:03:35 -0500 (Mon, 10 May 2010) | 1 line
Link to unittest2 article
........
r81053 | florent.xicluna | 2010-05-10 14:59:22 -0500 (Mon, 10 May 2010) | 2 lines
Add a link on maketrans().
........
r81070 | andrew.kuchling | 2010-05-10 18:13:41 -0500 (Mon, 10 May 2010) | 1 line
Fix typo
........
r81104 | andrew.kuchling | 2010-05-11 19:38:44 -0500 (Tue, 11 May 2010) | 1 line
Revision pass: lots of edits, typo fixes, rearrangements
........
r81105 | andrew.kuchling | 2010-05-11 19:40:47 -0500 (Tue, 11 May 2010) | 1 line
Let's call this done
........
r81114 | andrew.kuchling | 2010-05-12 08:56:07 -0500 (Wed, 12 May 2010) | 1 line
Grammar fix
........
r81125 | andrew.kuchling | 2010-05-12 13:56:48 -0500 (Wed, 12 May 2010) | 1 line
#8696: add documentation for logging.config.dictConfig (PEP 391)
........
r81245 | andrew.kuchling | 2010-05-16 18:31:16 -0500 (Sun, 16 May 2010) | 1 line
Add cross-reference to later section
........
r81285 | vinay.sajip | 2010-05-18 03:16:27 -0500 (Tue, 18 May 2010) | 1 line
Fixed minor typo in ReST markup.
........
r81402 | vinay.sajip | 2010-05-21 12:41:34 -0500 (Fri, 21 May 2010) | 1 line
Updated logging documentation with more dictConfig information.
........
r81463 | georg.brandl | 2010-05-22 03:17:23 -0500 (Sat, 22 May 2010) | 1 line
#8785: less confusing description of regex.find*.
........
r81516 | andrew.kuchling | 2010-05-25 08:34:08 -0500 (Tue, 25 May 2010) | 1 line
Add three items
........
r81562 | andrew.kuchling | 2010-05-27 08:22:53 -0500 (Thu, 27 May 2010) | 1 line
Rewrite wxWidgets section
........
r81563 | andrew.kuchling | 2010-05-27 08:30:09 -0500 (Thu, 27 May 2010) | 1 line
Remove top-level 'General Questions' section, pushing up the questions it contains
........
r81567 | andrew.kuchling | 2010-05-27 16:29:59 -0500 (Thu, 27 May 2010) | 1 line
Add item
........
r81593 | georg.brandl | 2010-05-29 03:46:18 -0500 (Sat, 29 May 2010) | 1 line
#8616: add new turtle demo "nim".
........
r81635 | georg.brandl | 2010-06-01 02:25:23 -0500 (Tue, 01 Jun 2010) | 1 line
Put docs for RegexObject.search() before RegexObject.match() to mirror re.search() and re.match() order.
........
r81680 | vinay.sajip | 2010-06-03 17:34:42 -0500 (Thu, 03 Jun 2010) | 1 line
Issue #8890: Documentation changed to avoid reference to temporary files.
........
r81681 | sean.reifschneider | 2010-06-03 20:51:26 -0500 (Thu, 03 Jun 2010) | 2 lines
Issue8810: Clearing up docstring for tzinfo.utcoffset.
........
r81684 | vinay.sajip | 2010-06-04 08:41:02 -0500 (Fri, 04 Jun 2010) | 1 line
Issue #8890: Documentation changed to avoid reference to temporary files - other cases covered.
........
r81801 | andrew.kuchling | 2010-06-07 08:38:40 -0500 (Mon, 07 Jun 2010) | 1 line
#8875: Remove duplicated paragraph
........
r81888 | andrew.kuchling | 2010-06-10 20:54:58 -0500 (Thu, 10 Jun 2010) | 1 line
Add a few more items
........
r81931 | georg.brandl | 2010-06-12 01:26:54 -0500 (Sat, 12 Jun 2010) | 1 line
Fix punctuation.
........
r81932 | georg.brandl | 2010-06-12 01:28:58 -0500 (Sat, 12 Jun 2010) | 1 line
Document that an existing directory raises in mkdir().
........
r81933 | georg.brandl | 2010-06-12 01:45:33 -0500 (Sat, 12 Jun 2010) | 1 line
Update version in README.
........
r81939 | georg.brandl | 2010-06-12 04:45:01 -0500 (Sat, 12 Jun 2010) | 1 line
Use newer toctree syntax.
........
r81940 | georg.brandl | 2010-06-12 04:45:28 -0500 (Sat, 12 Jun 2010) | 1 line
Add document on how to build.
........
r81941 | georg.brandl | 2010-06-12 04:45:58 -0500 (Sat, 12 Jun 2010) | 1 line
Fix gratuitous indentation.
........
r81942 | georg.brandl | 2010-06-12 04:46:03 -0500 (Sat, 12 Jun 2010) | 1 line
Update README.
........
r81963 | andrew.kuchling | 2010-06-12 15:00:55 -0500 (Sat, 12 Jun 2010) | 1 line
Grammar fix
........
r81984 | georg.brandl | 2010-06-14 10:58:39 -0500 (Mon, 14 Jun 2010) | 1 line
#8993: fix reference.
........
r81991 | andrew.kuchling | 2010-06-14 19:38:58 -0500 (Mon, 14 Jun 2010) | 1 line
Add another bunch of items
........
r82120 | andrew.kuchling | 2010-06-20 16:45:45 -0500 (Sun, 20 Jun 2010) | 1 line
Note that Python 3.x isn't covered; add forward ref. for UTF-8; note error in 2.5 and up
........
r82188 | benjamin.peterson | 2010-06-23 19:02:46 -0500 (Wed, 23 Jun 2010) | 1 line
remove reverted changed
........
r82264 | georg.brandl | 2010-06-27 05:47:47 -0500 (Sun, 27 Jun 2010) | 1 line
Confusing punctuation.
........
r82265 | georg.brandl | 2010-06-27 05:49:23 -0500 (Sun, 27 Jun 2010) | 1 line
Use designated syntax for optional grammar element.
........
r82266 | georg.brandl | 2010-06-27 05:51:44 -0500 (Sun, 27 Jun 2010) | 1 line
Fix URL.
........
r82267 | georg.brandl | 2010-06-27 05:55:38 -0500 (Sun, 27 Jun 2010) | 1 line
Two typos.
........
2010-06-27 19:32:30 -03:00
|
|
|
|
2011-11-29 11:46:38 -04:00
|
|
|
- *addr_type* is one of :const:`TIPC_ADDR_NAMESEQ`, :const:`TIPC_ADDR_NAME`,
|
|
|
|
or :const:`TIPC_ADDR_ID`.
|
|
|
|
- *scope* is one of :const:`TIPC_ZONE_SCOPE`, :const:`TIPC_CLUSTER_SCOPE`, and
|
|
|
|
:const:`TIPC_NODE_SCOPE`.
|
|
|
|
- If *addr_type* is :const:`TIPC_ADDR_NAME`, then *v1* is the server type, *v2* is
|
2010-12-12 16:57:12 -04:00
|
|
|
the port identifier, and *v3* should be 0.
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2011-11-29 11:46:38 -04:00
|
|
|
If *addr_type* is :const:`TIPC_ADDR_NAMESEQ`, then *v1* is the server type, *v2*
|
2010-12-12 16:57:12 -04:00
|
|
|
is the lower port number, and *v3* is the upper port number.
|
|
|
|
|
2011-11-29 11:46:38 -04:00
|
|
|
If *addr_type* is :const:`TIPC_ADDR_ID`, then *v1* is the node, *v2* is the
|
2010-12-12 16:57:12 -04:00
|
|
|
reference, and *v3* should be set to 0.
|
|
|
|
|
2011-10-06 14:47:44 -03:00
|
|
|
- A tuple ``(interface, )`` is used for the :const:`AF_CAN` address family,
|
|
|
|
where *interface* is a string representing a network interface name like
|
|
|
|
``'can0'``. The network interface name ``''`` can be used to receive packets
|
|
|
|
from all network interfaces of this family.
|
|
|
|
|
2017-08-28 05:32:44 -03:00
|
|
|
- :const:`CAN_ISOTP` protocol require a tuple ``(interface, rx_addr, tx_addr)``
|
|
|
|
where both additional parameters are unsigned long integer that represent a
|
|
|
|
CAN identifier (standard or extended).
|
2020-04-29 19:31:19 -03:00
|
|
|
- :const:`CAN_J1939` protocol require a tuple ``(interface, name, pgn, addr)``
|
|
|
|
where additional parameters are 64-bit unsigned integer representing the
|
|
|
|
ECU name, a 32-bit unsigned integer representing the Parameter Group Number
|
|
|
|
(PGN), and an 8-bit integer representing the address.
|
2017-08-28 05:32:44 -03:00
|
|
|
|
2012-02-03 12:44:58 -04:00
|
|
|
- A string or a tuple ``(id, unit)`` is used for the :const:`SYSPROTO_CONTROL`
|
|
|
|
protocol of the :const:`PF_SYSTEM` family. The string is the name of a
|
2022-07-05 06:16:10 -03:00
|
|
|
kernel control using a dynamically assigned ID. The tuple can be used if ID
|
2012-02-03 12:44:58 -04:00
|
|
|
and unit number of the kernel control are known or if a registered ID is
|
|
|
|
used.
|
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2015-09-09 03:47:58 -03:00
|
|
|
- :const:`AF_BLUETOOTH` supports the following protocols and address
|
|
|
|
formats:
|
|
|
|
|
|
|
|
- :const:`BTPROTO_L2CAP` accepts ``(bdaddr, psm)`` where ``bdaddr`` is
|
|
|
|
the Bluetooth address as a string and ``psm`` is an integer.
|
|
|
|
|
|
|
|
- :const:`BTPROTO_RFCOMM` accepts ``(bdaddr, channel)`` where ``bdaddr``
|
|
|
|
is the Bluetooth address as a string and ``channel`` is an integer.
|
|
|
|
|
|
|
|
- :const:`BTPROTO_HCI` accepts ``(device_id,)`` where ``device_id`` is
|
|
|
|
either an integer or a string with the Bluetooth address of the
|
|
|
|
interface. (This depends on your OS; NetBSD and DragonFlyBSD expect
|
|
|
|
a Bluetooth address while everything else expects an integer.)
|
|
|
|
|
|
|
|
.. versionchanged:: 3.2
|
|
|
|
NetBSD and DragonFlyBSD support added.
|
|
|
|
|
|
|
|
- :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is a
|
2015-09-10 23:23:41 -03:00
|
|
|
:class:`bytes` object containing the Bluetooth address in a
|
2015-09-09 03:47:58 -03:00
|
|
|
string format. (ex. ``b'12:23:34:45:56:67'``) This protocol is not
|
|
|
|
supported under FreeBSD.
|
|
|
|
|
2016-09-05 18:54:41 -03:00
|
|
|
- :const:`AF_ALG` is a Linux-only socket based interface to Kernel
|
|
|
|
cryptography. An algorithm socket is configured with a tuple of two to four
|
|
|
|
elements ``(type, name [, feat [, mask]])``, where:
|
|
|
|
|
|
|
|
- *type* is the algorithm type as string, e.g. ``aead``, ``hash``,
|
2016-09-05 19:07:02 -03:00
|
|
|
``skcipher`` or ``rng``.
|
2016-09-05 18:54:41 -03:00
|
|
|
|
|
|
|
- *name* is the algorithm name and operation mode as string, e.g.
|
|
|
|
``sha256``, ``hmac(sha256)``, ``cbc(aes)`` or ``drbg_nopr_ctr_aes256``.
|
|
|
|
|
|
|
|
- *feat* and *mask* are unsigned 32bit integers.
|
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Linux >= 2.6.38.
|
|
|
|
|
|
|
|
Some algorithm types require more recent Kernels.
|
2016-09-05 18:54:41 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.6
|
|
|
|
|
2017-09-06 19:18:10 -03:00
|
|
|
- :const:`AF_VSOCK` allows communication between virtual machines and
|
|
|
|
their hosts. The sockets are represented as a ``(CID, port)`` tuple
|
|
|
|
where the context ID or CID and port are integers.
|
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Linux >= 3.9
|
|
|
|
|
|
|
|
See :manpage:`vsock(7)`
|
2017-09-06 19:18:10 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
2018-09-11 21:32:15 -03:00
|
|
|
- :const:`AF_PACKET` is a low-level interface directly to network devices.
|
2023-11-27 19:42:37 -04:00
|
|
|
The addresses are represented by the tuple
|
2018-09-11 21:32:15 -03:00
|
|
|
``(ifname, proto[, pkttype[, hatype[, addr]]])`` where:
|
|
|
|
|
|
|
|
- *ifname* - String specifying the device name.
|
2022-11-07 10:27:37 -04:00
|
|
|
- *proto* - The Ethernet protocol number.
|
|
|
|
May be :data:`ETH_P_ALL` to capture all protocols,
|
|
|
|
one of the :ref:`ETHERTYPE_* constants <socket-ethernet-types>`
|
|
|
|
or any other Ethernet protocol number.
|
2018-09-11 21:32:15 -03:00
|
|
|
- *pkttype* - Optional integer specifying the packet type:
|
|
|
|
|
|
|
|
- ``PACKET_HOST`` (the default) - Packet addressed to the local host.
|
|
|
|
- ``PACKET_BROADCAST`` - Physical-layer broadcast packet.
|
2021-05-29 19:46:01 -03:00
|
|
|
- ``PACKET_MULTICAST`` - Packet sent to a physical-layer multicast address.
|
2018-09-11 21:32:15 -03:00
|
|
|
- ``PACKET_OTHERHOST`` - Packet to some other host that has been caught by
|
|
|
|
a device driver in promiscuous mode.
|
|
|
|
- ``PACKET_OUTGOING`` - Packet originating from the local host that is
|
|
|
|
looped back to a packet socket.
|
|
|
|
- *hatype* - Optional integer specifying the ARP hardware address type.
|
|
|
|
- *addr* - Optional bytes-like object specifying the hardware physical
|
|
|
|
address, whose interpretation depends on the device.
|
2010-12-12 16:57:12 -04:00
|
|
|
|
2023-10-11 17:24:12 -03:00
|
|
|
.. availability:: Linux >= 2.2.
|
2021-10-21 18:13:37 -03:00
|
|
|
|
2018-09-26 10:47:52 -03:00
|
|
|
- :const:`AF_QIPCRTR` is a Linux-only socket based interface for communicating
|
|
|
|
with services running on co-processors in Qualcomm platforms. The address
|
|
|
|
family is represented as a ``(node, port)`` tuple where the *node* and *port*
|
|
|
|
are non-negative integers.
|
|
|
|
|
2023-10-11 17:24:12 -03:00
|
|
|
.. availability:: Linux >= 4.7.
|
2021-10-21 18:13:37 -03:00
|
|
|
|
2018-09-26 18:20:38 -03:00
|
|
|
.. versionadded:: 3.8
|
2018-09-26 10:47:52 -03:00
|
|
|
|
bpo-37345: Add formal UDPLITE support (GH-14258)
At the moment you can definitely use UDPLITE sockets on Linux systems, but it would be good if this support were formalized such that you can detect support at runtime easily.
At the moment, to make and use a UDPLITE socket requires something like the following code:
```
>>> import socket
>>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136)
>>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136)
>>> a.bind(('localhost', 44444))
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 16)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 32)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 64)
>>> b.sendto(b'test'*256, ('localhost', 44444))
```
If you look at this through Wireshark, you can see that the packets are different in that the checksums and checksum coverages change.
With the pull request that I am submitting momentarily, you could do the following code instead:
```
>>> import socket
>>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
>>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
>>> a.bind(('localhost', 44444))
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(16)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(32)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(64)
>>> b.sendto(b'test'*256, ('localhost', 44444))
```
One can also detect support for UDPLITE just by checking
```
>>> hasattr(socket, 'IPPROTO_UDPLITE')
```
https://bugs.python.org/issue37345
2019-06-24 06:58:56 -03:00
|
|
|
- :const:`IPPROTO_UDPLITE` is a variant of UDP which allows you to specify
|
|
|
|
what portion of a packet is covered with the checksum. It adds two socket
|
|
|
|
options that you can change.
|
|
|
|
``self.setsockopt(IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV, length)`` will
|
|
|
|
change what portion of outgoing packets are covered by the checksum and
|
|
|
|
``self.setsockopt(IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV, length)`` will
|
|
|
|
filter out packets which cover too little of their data. In both cases
|
|
|
|
``length`` should be in ``range(8, 2**16, 8)``.
|
|
|
|
|
|
|
|
Such a socket should be constructed with
|
|
|
|
``socket(AF_INET, SOCK_DGRAM, IPPROTO_UDPLITE)`` for IPv4 or
|
|
|
|
``socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDPLITE)`` for IPv6.
|
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Linux >= 2.6.20, FreeBSD >= 10.1
|
bpo-37345: Add formal UDPLITE support (GH-14258)
At the moment you can definitely use UDPLITE sockets on Linux systems, but it would be good if this support were formalized such that you can detect support at runtime easily.
At the moment, to make and use a UDPLITE socket requires something like the following code:
```
>>> import socket
>>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136)
>>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 136)
>>> a.bind(('localhost', 44444))
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 16)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 32)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.setsockopt(136, 10, 64)
>>> b.sendto(b'test'*256, ('localhost', 44444))
```
If you look at this through Wireshark, you can see that the packets are different in that the checksums and checksum coverages change.
With the pull request that I am submitting momentarily, you could do the following code instead:
```
>>> import socket
>>> a = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
>>> b = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
>>> a.bind(('localhost', 44444))
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(16)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(32)
>>> b.sendto(b'test'*256, ('localhost', 44444))
>>> b.set_send_checksum_coverage(64)
>>> b.sendto(b'test'*256, ('localhost', 44444))
```
One can also detect support for UDPLITE just by checking
```
>>> hasattr(socket, 'IPPROTO_UDPLITE')
```
https://bugs.python.org/issue37345
2019-06-24 06:58:56 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.9
|
|
|
|
|
2022-05-24 17:37:06 -03:00
|
|
|
- :const:`AF_HYPERV` is a Windows-only socket based interface for communicating
|
|
|
|
with Hyper-V hosts and guests. The address family is represented as a
|
|
|
|
``(vm_id, service_id)`` tuple where the ``vm_id`` and ``service_id`` are
|
|
|
|
UUID strings.
|
|
|
|
|
|
|
|
The ``vm_id`` is the virtual machine identifier or a set of known VMID values
|
|
|
|
if the target is not a specific virtual machine. Known VMID constants
|
|
|
|
defined on ``socket`` are:
|
|
|
|
|
|
|
|
- ``HV_GUID_ZERO``
|
|
|
|
- ``HV_GUID_BROADCAST``
|
|
|
|
- ``HV_GUID_WILDCARD`` - Used to bind on itself and accept connections from
|
|
|
|
all partitions.
|
|
|
|
- ``HV_GUID_CHILDREN`` - Used to bind on itself and accept connection from
|
|
|
|
child partitions.
|
|
|
|
- ``HV_GUID_LOOPBACK`` - Used as a target to itself.
|
|
|
|
- ``HV_GUID_PARENT`` - When used as a bind accepts connection from the parent
|
2022-06-21 16:10:45 -03:00
|
|
|
partition. When used as an address target it will connect to the parent partition.
|
2022-05-24 17:37:06 -03:00
|
|
|
|
|
|
|
The ``service_id`` is the service identifier of the registered service.
|
|
|
|
|
|
|
|
.. versionadded:: 3.12
|
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
If you use a hostname in the *host* portion of IPv4/v6 socket address, the
|
|
|
|
program may show a nondeterministic behavior, as Python uses the first address
|
|
|
|
returned from the DNS resolution. The socket address will be resolved
|
|
|
|
differently into an actual IPv4/v6 address, depending on the results from DNS
|
|
|
|
resolution and/or the host configuration. For deterministic behavior use a
|
|
|
|
numeric address in *host* portion.
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
All errors raise exceptions. The normal exceptions for invalid argument types
|
2022-05-19 12:25:58 -03:00
|
|
|
and out-of-memory conditions can be raised. Errors
|
2011-10-12 12:53:43 -03:00
|
|
|
related to socket or address semantics raise :exc:`OSError` or one of its
|
2022-05-19 12:25:58 -03:00
|
|
|
subclasses.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line
Get rid of multi-row cells.
........
r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line
Remove LaTeXy index entry syntax.
........
r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Better cross-referencing in socket and winreg docs.
........
r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface.
........
r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Minor spelling changes to _winreg docs.
........
r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line
Fix code example to have valid syntax so that it can be highlighted.
........
r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric.
........
r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line
#8642: fix wrong function name.
........
r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line
Fix reference direction.
........
r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line
Consolidate deprecation messages.
........
r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line
Fix typo.
........
2010-05-19 17:57:08 -03:00
|
|
|
Non-blocking mode is supported through :meth:`~socket.setblocking`. A
|
|
|
|
generalization of this based on timeouts is supported through
|
|
|
|
:meth:`~socket.settimeout`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
|
|
|
|
Module contents
|
|
|
|
---------------
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
The module :mod:`socket` exports the following elements.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
Exceptions
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. exception:: error
|
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
A deprecated alias of :exc:`OSError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
Following :pep:`3151`, this class was made an alias of :exc:`OSError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2011-02-28 18:38:07 -04:00
|
|
|
.. exception:: herror
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
A subclass of :exc:`OSError`, this exception is raised for
|
2011-02-28 18:38:07 -04:00
|
|
|
address-related errors, i.e. for functions that use *h_errno* in the POSIX
|
|
|
|
C API, including :func:`gethostbyname_ex` and :func:`gethostbyaddr`.
|
|
|
|
The accompanying value is a pair ``(h_errno, string)`` representing an
|
|
|
|
error returned by a library call. *h_errno* is a numeric value, while
|
|
|
|
*string* represents the description of *h_errno*, as returned by the
|
|
|
|
:c:func:`hstrerror` C function.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
This class was made a subclass of :exc:`OSError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. exception:: gaierror
|
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
A subclass of :exc:`OSError`, this exception is raised for
|
2011-02-28 18:38:07 -04:00
|
|
|
address-related errors by :func:`getaddrinfo` and :func:`getnameinfo`.
|
|
|
|
The accompanying value is a pair ``(error, string)`` representing an error
|
|
|
|
returned by a library call. *string* represents the description of
|
|
|
|
*error*, as returned by the :c:func:`gai_strerror` C function. The
|
2023-12-13 03:24:55 -04:00
|
|
|
numeric *error* value will match one of the :const:`!EAI_\*` constants
|
2011-02-28 18:38:07 -04:00
|
|
|
defined in this module.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
This class was made a subclass of :exc:`OSError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. exception:: timeout
|
|
|
|
|
2020-11-20 04:26:07 -04:00
|
|
|
A deprecated alias of :exc:`TimeoutError`.
|
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
A subclass of :exc:`OSError`, this exception is raised when a timeout
|
2011-02-28 18:38:07 -04:00
|
|
|
occurs on a socket which has had timeouts enabled via a prior call to
|
|
|
|
:meth:`~socket.settimeout` (or implicitly through
|
|
|
|
:func:`~socket.setdefaulttimeout`). The accompanying value is a string
|
|
|
|
whose value is currently always "timed out".
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 11:20:53 -03:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
This class was made a subclass of :exc:`OSError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-11-20 04:26:07 -04:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
This class was made an alias of :exc:`TimeoutError`.
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
|
|
|
|
Constants
|
|
|
|
^^^^^^^^^
|
|
|
|
|
2014-10-14 22:56:53 -03:00
|
|
|
The AF_* and SOCK_* constants are now :class:`AddressFamily` and
|
|
|
|
:class:`SocketKind` :class:`.IntEnum` collections.
|
|
|
|
|
|
|
|
.. versionadded:: 3.4
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. data:: AF_UNIX
|
|
|
|
AF_INET
|
|
|
|
AF_INET6
|
|
|
|
|
|
|
|
These constants represent the address (and protocol) families, used for the
|
2023-11-27 10:36:54 -04:00
|
|
|
first argument to :func:`~socket.socket`. If the :const:`AF_UNIX` constant is not
|
2010-12-12 16:57:12 -04:00
|
|
|
defined then this protocol is unsupported. More constants may be available
|
|
|
|
depending on the system.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2023-10-29 16:31:01 -03:00
|
|
|
.. data:: AF_UNSPEC
|
|
|
|
|
|
|
|
:const:`AF_UNSPEC` means that
|
|
|
|
:func:`getaddrinfo` should return socket addresses for any
|
|
|
|
address family (either IPv4, IPv6, or any other) that can be used.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. data:: SOCK_STREAM
|
|
|
|
SOCK_DGRAM
|
|
|
|
SOCK_RAW
|
|
|
|
SOCK_RDM
|
|
|
|
SOCK_SEQPACKET
|
|
|
|
|
|
|
|
These constants represent the socket types, used for the second argument to
|
2023-11-27 10:36:54 -04:00
|
|
|
:func:`~socket.socket`. More constants may be available depending on the system.
|
2010-12-12 16:57:12 -04:00
|
|
|
(Only :const:`SOCK_STREAM` and :const:`SOCK_DGRAM` appear to be generally
|
|
|
|
useful.)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-14 12:05:38 -03:00
|
|
|
.. data:: SOCK_CLOEXEC
|
|
|
|
SOCK_NONBLOCK
|
|
|
|
|
|
|
|
These two constants, if defined, can be combined with the socket types and
|
|
|
|
allow you to set some flags atomically (thus avoiding possible race
|
|
|
|
conditions and the need for separate calls).
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
2022-08-04 04:13:49 -03:00
|
|
|
`Secure File Descriptor Handling <https://udrepper.livejournal.com/20407.html>`_
|
2010-10-14 12:05:38 -03:00
|
|
|
for a more thorough explanation.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.6.27.
|
2010-10-14 12:05:38 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2023-10-29 16:31:01 -03:00
|
|
|
.. _socket-unix-constants:
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. data:: SO_*
|
|
|
|
SOMAXCONN
|
|
|
|
MSG_*
|
|
|
|
SOL_*
|
2011-08-21 22:55:57 -03:00
|
|
|
SCM_*
|
2007-08-15 11:28:22 -03:00
|
|
|
IPPROTO_*
|
|
|
|
IPPORT_*
|
|
|
|
INADDR_*
|
|
|
|
IP_*
|
|
|
|
IPV6_*
|
|
|
|
EAI_*
|
|
|
|
AI_*
|
|
|
|
NI_*
|
|
|
|
TCP_*
|
|
|
|
|
|
|
|
Many constants of these forms, documented in the Unix documentation on sockets
|
|
|
|
and/or the IP protocol, are also defined in the socket module. They are
|
2023-11-27 10:36:54 -04:00
|
|
|
generally used in arguments to the :meth:`~socket.setsockopt` and :meth:`~socket.getsockopt`
|
2007-08-15 11:28:22 -03:00
|
|
|
methods of socket objects. In most cases, only those symbols that are defined
|
|
|
|
in the Unix header files are defined; for a few symbols, default values are
|
|
|
|
provided.
|
|
|
|
|
2016-08-23 22:12:40 -03:00
|
|
|
.. versionchanged:: 3.6
|
2017-01-23 07:30:00 -04:00
|
|
|
``SO_DOMAIN``, ``SO_PROTOCOL``, ``SO_PEERSEC``, ``SO_PASSSEC``,
|
|
|
|
``TCP_USER_TIMEOUT``, ``TCP_CONGESTION`` were added.
|
2016-08-23 22:12:40 -03:00
|
|
|
|
2018-02-26 14:10:36 -04:00
|
|
|
.. versionchanged:: 3.6.5
|
|
|
|
On Windows, ``TCP_FASTOPEN``, ``TCP_KEEPCNT`` appear if run-time Windows
|
|
|
|
supports.
|
|
|
|
|
2017-03-23 00:56:55 -03:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
``TCP_NOTSENT_LOWAT`` was added.
|
|
|
|
|
2018-02-26 14:10:36 -04:00
|
|
|
On Windows, ``TCP_KEEPIDLE``, ``TCP_KEEPINTVL`` appear if run-time Windows
|
|
|
|
supports.
|
|
|
|
|
2021-06-20 17:08:07 -03:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
``IP_RECVTOS`` was added.
|
2021-07-14 19:53:15 -03:00
|
|
|
Added ``TCP_KEEPALIVE``. On MacOS this constant can be used in the same
|
|
|
|
way that ``TCP_KEEPIDLE`` is used on Linux.
|
2021-06-20 17:08:07 -03:00
|
|
|
|
2022-04-27 09:47:17 -03:00
|
|
|
.. versionchanged:: 3.11
|
|
|
|
Added ``TCP_CONNECTION_INFO``. On MacOS this constant can be used in the
|
|
|
|
same way that ``TCP_INFO`` is used on Linux and BSD.
|
|
|
|
|
2022-05-08 20:19:41 -03:00
|
|
|
.. versionchanged:: 3.12
|
|
|
|
Added ``SO_RTABLE`` and ``SO_USER_COOKIE``. On OpenBSD
|
|
|
|
and FreeBSD respectively those constants can be used in the same way that
|
2022-12-08 00:59:37 -04:00
|
|
|
``SO_MARK`` is used on Linux. Also added missing TCP socket options from
|
|
|
|
Linux: ``TCP_MD5SIG``, ``TCP_THIN_LINEAR_TIMEOUTS``, ``TCP_THIN_DUPACK``,
|
|
|
|
``TCP_REPAIR``, ``TCP_REPAIR_QUEUE``, ``TCP_QUEUE_SEQ``,
|
|
|
|
``TCP_REPAIR_OPTIONS``, ``TCP_TIMESTAMP``, ``TCP_CC_INFO``,
|
|
|
|
``TCP_SAVE_SYN``, ``TCP_SAVED_SYN``, ``TCP_REPAIR_WINDOW``,
|
|
|
|
``TCP_FASTOPEN_CONNECT``, ``TCP_ULP``, ``TCP_MD5SIG_EXT``,
|
|
|
|
``TCP_FASTOPEN_KEY``, ``TCP_FASTOPEN_NO_COOKIE``,
|
|
|
|
``TCP_ZEROCOPY_RECEIVE``, ``TCP_INQ``, ``TCP_TX_DELAY``.
|
2023-06-03 12:28:29 -03:00
|
|
|
Added ``IP_PKTINFO``, ``IP_UNBLOCK_SOURCE``, ``IP_BLOCK_SOURCE``,
|
|
|
|
``IP_ADD_SOURCE_MEMBERSHIP``, ``IP_DROP_SOURCE_MEMBERSHIP``.
|
2022-05-08 20:19:41 -03:00
|
|
|
|
2024-02-20 17:08:15 -04:00
|
|
|
.. versionchanged:: 3.13
|
|
|
|
Added ``SO_BINDTOIFINDEX``. On Linux this constant can be used in the
|
|
|
|
same way that ``SO_BINDTODEVICE`` is used, but with the index of a
|
|
|
|
network interface instead of its name.
|
|
|
|
|
2011-10-06 14:47:44 -03:00
|
|
|
.. data:: AF_CAN
|
|
|
|
PF_CAN
|
|
|
|
SOL_CAN_*
|
|
|
|
CAN_*
|
|
|
|
|
|
|
|
Many constants of these forms, documented in the Linux documentation, are
|
|
|
|
also defined in the socket module.
|
|
|
|
|
2022-01-21 03:44:05 -04:00
|
|
|
.. availability:: Linux >= 2.6.25, NetBSD >= 8.
|
2011-10-06 14:47:44 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2022-01-21 03:44:05 -04:00
|
|
|
.. versionchanged:: 3.11
|
|
|
|
NetBSD support was added.
|
|
|
|
|
2013-02-05 14:42:01 -04:00
|
|
|
.. data:: CAN_BCM
|
|
|
|
CAN_BCM_*
|
|
|
|
|
|
|
|
CAN_BCM, in the CAN protocol family, is the broadcast manager (BCM) protocol.
|
|
|
|
Broadcast manager constants, documented in the Linux documentation, are also
|
|
|
|
defined in the socket module.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.6.25.
|
2013-02-05 14:42:01 -04:00
|
|
|
|
2019-07-31 05:47:16 -03:00
|
|
|
.. note::
|
|
|
|
The :data:`CAN_BCM_CAN_FD_FRAME` flag is only available on Linux >= 4.8.
|
|
|
|
|
2013-02-05 14:42:01 -04:00
|
|
|
.. versionadded:: 3.4
|
2011-10-06 14:47:44 -03:00
|
|
|
|
2015-04-13 18:48:40 -03:00
|
|
|
.. data:: CAN_RAW_FD_FRAMES
|
|
|
|
|
|
|
|
Enables CAN FD support in a CAN_RAW socket. This is disabled by default.
|
|
|
|
This allows your application to send both CAN and CAN FD frames; however,
|
2019-05-28 15:35:26 -03:00
|
|
|
you must accept both CAN and CAN FD frames when reading from the socket.
|
2015-04-13 18:48:40 -03:00
|
|
|
|
|
|
|
This constant is documented in the Linux documentation.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 3.6.
|
2015-04-13 18:48:40 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.5
|
|
|
|
|
2020-04-09 09:03:49 -03:00
|
|
|
.. data:: CAN_RAW_JOIN_FILTERS
|
|
|
|
|
|
|
|
Joins the applied CAN filters such that only CAN frames that match all
|
|
|
|
given CAN filters are passed to user space.
|
|
|
|
|
|
|
|
This constant is documented in the Linux documentation.
|
|
|
|
|
|
|
|
.. availability:: Linux >= 4.1.
|
|
|
|
|
|
|
|
.. versionadded:: 3.9
|
|
|
|
|
2017-08-28 05:32:44 -03:00
|
|
|
.. data:: CAN_ISOTP
|
|
|
|
|
|
|
|
CAN_ISOTP, in the CAN protocol family, is the ISO-TP (ISO 15765-2) protocol.
|
|
|
|
ISO-TP constants, documented in the Linux documentation.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.6.25.
|
2017-08-28 05:32:44 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
2020-04-29 19:31:19 -03:00
|
|
|
.. data:: CAN_J1939
|
|
|
|
|
|
|
|
CAN_J1939, in the CAN protocol family, is the SAE J1939 protocol.
|
|
|
|
J1939 constants, documented in the Linux documentation.
|
|
|
|
|
|
|
|
.. availability:: Linux >= 5.4.
|
|
|
|
|
|
|
|
.. versionadded:: 3.9
|
|
|
|
|
2017-08-28 05:32:44 -03:00
|
|
|
|
2023-05-04 11:57:05 -03:00
|
|
|
.. data:: AF_DIVERT
|
|
|
|
PF_DIVERT
|
|
|
|
|
|
|
|
These two constants, documented in the FreeBSD divert(4) manual page, are
|
|
|
|
also defined in the socket module.
|
|
|
|
|
|
|
|
.. availability:: FreeBSD >= 14.0.
|
|
|
|
|
|
|
|
.. versionadded:: 3.12
|
|
|
|
|
|
|
|
|
2018-09-11 21:32:15 -03:00
|
|
|
.. data:: AF_PACKET
|
|
|
|
PF_PACKET
|
|
|
|
PACKET_*
|
|
|
|
|
|
|
|
Many constants of these forms, documented in the Linux documentation, are
|
|
|
|
also defined in the socket module.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.2.
|
2018-09-11 21:32:15 -03:00
|
|
|
|
|
|
|
|
2022-11-07 10:27:37 -04:00
|
|
|
.. data:: ETH_P_ALL
|
|
|
|
|
|
|
|
:data:`!ETH_P_ALL` can be used in the :class:`~socket.socket`
|
|
|
|
constructor as *proto* for the :const:`AF_PACKET` family in order to
|
|
|
|
capture every packet, regardless of protocol.
|
|
|
|
|
|
|
|
For more information, see the :manpage:`packet(7)` manpage.
|
|
|
|
|
|
|
|
.. availability:: Linux.
|
|
|
|
|
|
|
|
.. versionadded:: 3.12
|
|
|
|
|
|
|
|
|
2011-11-10 14:21:37 -04:00
|
|
|
.. data:: AF_RDS
|
|
|
|
PF_RDS
|
|
|
|
SOL_RDS
|
|
|
|
RDS_*
|
|
|
|
|
|
|
|
Many constants of these forms, documented in the Linux documentation, are
|
|
|
|
also defined in the socket module.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.6.30.
|
2011-11-10 14:21:37 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
2016-06-17 16:52:18 -03:00
|
|
|
.. data:: SIO_RCVALL
|
|
|
|
SIO_KEEPALIVE_VALS
|
|
|
|
SIO_LOOPBACK_FAST_PATH
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
RCVALL_*
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
Constants for Windows' WSAIoctl(). The constants are used as arguments to the
|
2013-10-13 17:09:14 -03:00
|
|
|
:meth:`~socket.socket.ioctl` method of socket objects.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2016-06-17 16:52:18 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
``SIO_LOOPBACK_FAST_PATH`` was added.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-07 13:19:16 -04:00
|
|
|
.. data:: TIPC_*
|
|
|
|
|
|
|
|
TIPC related constants, matching the ones exported by the C socket API. See
|
|
|
|
the TIPC documentation for more information.
|
|
|
|
|
2016-09-05 18:54:41 -03:00
|
|
|
.. data:: AF_ALG
|
|
|
|
SOL_ALG
|
|
|
|
ALG_*
|
|
|
|
|
|
|
|
Constants for Linux Kernel cryptography.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.6.38.
|
2016-09-05 18:54:41 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.6
|
|
|
|
|
2017-09-06 19:18:10 -03:00
|
|
|
|
|
|
|
.. data:: AF_VSOCK
|
|
|
|
IOCTL_VM_SOCKETS_GET_LOCAL_CID
|
|
|
|
VMADDR*
|
|
|
|
SO_VM*
|
|
|
|
|
|
|
|
Constants for Linux host/guest communication.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 4.8.
|
2017-09-06 19:18:10 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
2013-05-21 16:02:04 -03:00
|
|
|
.. data:: AF_LINK
|
|
|
|
|
2021-09-22 14:33:36 -03:00
|
|
|
.. availability:: BSD, macOS.
|
2013-05-21 16:02:04 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.4
|
2008-01-07 13:19:16 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. data:: has_ipv6
|
|
|
|
|
|
|
|
This constant contains a boolean value which indicates if IPv6 is supported on
|
|
|
|
this platform.
|
|
|
|
|
2015-09-11 20:14:57 -03:00
|
|
|
.. data:: BDADDR_ANY
|
|
|
|
BDADDR_LOCAL
|
|
|
|
|
|
|
|
These are string constants containing Bluetooth addresses with special
|
|
|
|
meanings. For example, :const:`BDADDR_ANY` can be used to indicate
|
|
|
|
any address when specifying the binding socket with
|
|
|
|
:const:`BTPROTO_RFCOMM`.
|
|
|
|
|
|
|
|
.. data:: HCI_FILTER
|
|
|
|
HCI_TIME_STAMP
|
|
|
|
HCI_DATA_DIR
|
|
|
|
|
|
|
|
For use with :const:`BTPROTO_HCI`. :const:`HCI_FILTER` is not
|
|
|
|
available for NetBSD or DragonFlyBSD. :const:`HCI_TIME_STAMP` and
|
|
|
|
:const:`HCI_DATA_DIR` are not available for FreeBSD, NetBSD, or
|
|
|
|
DragonFlyBSD.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2018-09-26 10:47:52 -03:00
|
|
|
.. data:: AF_QIPCRTR
|
|
|
|
|
|
|
|
Constant for Qualcomm's IPC router protocol, used to communicate with
|
|
|
|
service providing remote processors.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 4.7.
|
2018-09-26 10:47:52 -03:00
|
|
|
|
2022-03-17 17:40:00 -03:00
|
|
|
.. data:: SCM_CREDS2
|
|
|
|
LOCAL_CREDS
|
|
|
|
LOCAL_CREDS_PERSISTENT
|
|
|
|
|
|
|
|
LOCAL_CREDS and LOCAL_CREDS_PERSISTENT can be used
|
|
|
|
with SOCK_DGRAM, SOCK_STREAM sockets, equivalent to
|
|
|
|
Linux/DragonFlyBSD SO_PASSCRED, while LOCAL_CREDS
|
|
|
|
sends the credentials at first read, LOCAL_CREDS_PERSISTENT
|
|
|
|
sends for each read, SCM_CREDS2 must be then used for
|
|
|
|
the latter for the message type.
|
|
|
|
|
|
|
|
.. versionadded:: 3.11
|
|
|
|
|
|
|
|
.. availability:: FreeBSD.
|
|
|
|
|
2022-05-03 14:33:11 -03:00
|
|
|
.. data:: SO_INCOMING_CPU
|
|
|
|
|
|
|
|
Constant to optimize CPU locality, to be used in conjunction with
|
|
|
|
:data:`SO_REUSEPORT`.
|
|
|
|
|
|
|
|
.. versionadded:: 3.11
|
|
|
|
|
|
|
|
.. availability:: Linux >= 3.9
|
|
|
|
|
2022-05-24 17:37:06 -03:00
|
|
|
.. data:: AF_HYPERV
|
|
|
|
HV_PROTOCOL_RAW
|
|
|
|
HVSOCKET_CONNECT_TIMEOUT
|
|
|
|
HVSOCKET_CONNECT_TIMEOUT_MAX
|
|
|
|
HVSOCKET_CONNECTED_SUSPEND
|
|
|
|
HVSOCKET_ADDRESS_FLAG_PASSTHRU
|
|
|
|
HV_GUID_ZERO
|
|
|
|
HV_GUID_WILDCARD
|
|
|
|
HV_GUID_BROADCAST
|
|
|
|
HV_GUID_CHILDREN
|
|
|
|
HV_GUID_LOOPBACK
|
2023-06-06 13:11:19 -03:00
|
|
|
HV_GUID_PARENT
|
2022-05-24 17:37:06 -03:00
|
|
|
|
|
|
|
Constants for Windows Hyper-V sockets for host/guest communications.
|
|
|
|
|
|
|
|
.. availability:: Windows.
|
|
|
|
|
|
|
|
.. versionadded:: 3.12
|
|
|
|
|
2022-11-07 10:27:37 -04:00
|
|
|
.. _socket-ethernet-types:
|
|
|
|
|
|
|
|
.. data:: ETHERTYPE_ARP
|
|
|
|
ETHERTYPE_IP
|
|
|
|
ETHERTYPE_IPV6
|
|
|
|
ETHERTYPE_VLAN
|
|
|
|
|
|
|
|
`IEEE 802.3 protocol number
|
|
|
|
<https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.txt>`_.
|
|
|
|
constants.
|
|
|
|
|
|
|
|
.. availability:: Linux, FreeBSD, macOS.
|
|
|
|
|
|
|
|
.. versionadded:: 3.12
|
|
|
|
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
Functions
|
|
|
|
^^^^^^^^^
|
|
|
|
|
|
|
|
Creating sockets
|
|
|
|
''''''''''''''''
|
|
|
|
|
|
|
|
The following functions all create :ref:`socket objects <socket-objects>`.
|
|
|
|
|
|
|
|
|
2021-11-13 02:02:04 -04:00
|
|
|
.. class:: socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
|
2013-12-04 16:11:03 -04:00
|
|
|
|
|
|
|
Create a new socket using the given address family, socket type and protocol
|
|
|
|
number. The address family should be :const:`AF_INET` (the default),
|
2018-09-11 21:32:15 -03:00
|
|
|
:const:`AF_INET6`, :const:`AF_UNIX`, :const:`AF_CAN`, :const:`AF_PACKET`,
|
|
|
|
or :const:`AF_RDS`. The socket type should be :const:`SOCK_STREAM` (the
|
|
|
|
default), :const:`SOCK_DGRAM`, :const:`SOCK_RAW` or perhaps one of the other
|
|
|
|
``SOCK_`` constants. The protocol number is usually zero and may be omitted
|
|
|
|
or in the case where the address family is :const:`AF_CAN` the protocol
|
2020-04-29 19:31:19 -03:00
|
|
|
should be one of :const:`CAN_RAW`, :const:`CAN_BCM`, :const:`CAN_ISOTP` or
|
|
|
|
:const:`CAN_J1939`.
|
bpo-28134: Auto-detect socket values from file descriptor (#1349)
Fix socket(fileno=fd) by auto-detecting the socket's family, type,
and proto from the file descriptor. The auto-detection can be overruled
by passing in family, type, and proto explicitly.
Without the fix, all socket except for TCP/IP over IPv4 are basically broken:
>>> s = socket.create_connection(('www.python.org', 443))
>>> s
<socket.socket fd=3, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=6, laddr=('2003:58:bc4a:3b00:56ee:75ff:fe47:ca7b', 59730, 0, 0), raddr=('2a04:4e42:1b::223', 443, 0, 0)>
>>> socket.socket(fileno=s.fileno())
<socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('2003:58:bc4a:3b00::%2550471192', 59730, 0, 2550471192), raddr=('2a04:4e42:1b:0:700c:e70b:ff7f:0%2550471192', 443, 0, 2550471192)>
Signed-off-by: Christian Heimes <christian@python.org>
2018-01-29 17:37:58 -04:00
|
|
|
|
|
|
|
If *fileno* is specified, the values for *family*, *type*, and *proto* are
|
|
|
|
auto-detected from the specified file descriptor. Auto-detection can be
|
|
|
|
overruled by calling the function with explicit *family*, *type*, or *proto*
|
|
|
|
arguments. This only affects how Python represents e.g. the return value
|
|
|
|
of :meth:`socket.getpeername` but not the actual OS resource. Unlike
|
|
|
|
:func:`socket.fromfd`, *fileno* will return the same socket and not a
|
|
|
|
duplicate. This may help close a detached socket using
|
2015-10-08 00:34:01 -03:00
|
|
|
:meth:`socket.close()`.
|
2013-12-04 16:15:24 -04:00
|
|
|
|
|
|
|
The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
|
2013-12-04 16:11:03 -04:00
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.__new__ self,family,type,protocol socket.socket
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
.. versionchanged:: 3.3
|
|
|
|
The AF_CAN family was added.
|
|
|
|
The AF_RDS family was added.
|
|
|
|
|
2013-12-04 16:15:24 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
The CAN_BCM protocol was added.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
The returned socket is now non-inheritable.
|
|
|
|
|
2017-08-28 05:32:44 -03:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
The CAN_ISOTP protocol was added.
|
2013-12-04 16:11:03 -04:00
|
|
|
|
2017-12-18 21:02:54 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
When :const:`SOCK_NONBLOCK` or :const:`SOCK_CLOEXEC`
|
|
|
|
bit flags are applied to *type* they are cleared, and
|
|
|
|
:attr:`socket.type` will not reflect them. They are still passed
|
2022-10-06 22:01:30 -03:00
|
|
|
to the underlying system ``socket()`` call. Therefore,
|
2020-01-15 19:55:13 -04:00
|
|
|
|
|
|
|
::
|
2017-12-18 21:02:54 -04:00
|
|
|
|
|
|
|
sock = socket.socket(
|
|
|
|
socket.AF_INET,
|
|
|
|
socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
|
|
|
|
|
|
|
|
will still create a non-blocking socket on OSes that support
|
|
|
|
``SOCK_NONBLOCK``, but ``sock.type`` will be set to
|
|
|
|
``socket.SOCK_STREAM``.
|
|
|
|
|
2020-04-29 19:31:19 -03:00
|
|
|
.. versionchanged:: 3.9
|
|
|
|
The CAN_J1939 protocol was added.
|
|
|
|
|
2021-03-20 19:04:56 -03:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
The IPPROTO_MPTCP protocol was added.
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
.. function:: socketpair([family[, type[, proto]]])
|
|
|
|
|
|
|
|
Build a pair of connected socket objects using the given address family, socket
|
|
|
|
type, and protocol number. Address family, socket type, and protocol number are
|
2023-11-27 10:36:54 -04:00
|
|
|
as for the :func:`~socket.socket` function above. The default family is :const:`AF_UNIX`
|
2013-12-04 16:11:03 -04:00
|
|
|
if defined on the platform; otherwise, the default is :const:`AF_INET`.
|
|
|
|
|
2013-12-04 16:15:24 -04:00
|
|
|
The newly created sockets are :ref:`non-inheritable <fd_inheritance>`.
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
.. versionchanged:: 3.2
|
|
|
|
The returned socket objects now support the whole socket API, rather
|
|
|
|
than a subset.
|
|
|
|
|
2013-12-04 16:15:24 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
The returned sockets are now non-inheritable.
|
|
|
|
|
2014-10-14 17:22:44 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
Windows support added.
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
|
2022-04-19 14:16:20 -03:00
|
|
|
.. function:: create_connection(address, timeout=GLOBAL_DEFAULT, source_address=None, *, all_errors=False)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2021-07-26 19:11:55 -03:00
|
|
|
Connect to a TCP service listening on the internet *address* (a 2-tuple
|
2012-01-12 03:06:19 -04:00
|
|
|
``(host, port)``), and return the socket object. This is a higher-level
|
|
|
|
function than :meth:`socket.connect`: if *host* is a non-numeric hostname,
|
|
|
|
it will try to resolve it for both :data:`AF_INET` and :data:`AF_INET6`,
|
|
|
|
and then try to connect to all possible addresses in turn until a
|
|
|
|
connection succeeds. This makes it easy to write clients that are
|
|
|
|
compatible to both IPv4 and IPv6.
|
|
|
|
|
|
|
|
Passing the optional *timeout* parameter will set the timeout on the
|
|
|
|
socket instance before attempting to connect. If no *timeout* is
|
|
|
|
supplied, the global default timeout setting returned by
|
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines
Patch #1722225: Support QNX 6.
........
r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line
Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo.
........
r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines
Fix issue2589: there was a potential integer overflow leading to
memory corruption on esoteric platforms and incorrect behavior on
normal platforms.
........
r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines
Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is
passed in. (The assert won't prevent this in non-debug builds).
........
r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line
Fix two typos.
........
r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines
Fixed the semantic of timeout for socket.create_connection and
all the upper level libraries that use it, including urllib2.
Added and fixed some tests, and changed docs correspondingly.
Thanks to John J Lee for the patch and the pusing, :)
........
r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines
Fix typo in testSum
........
r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines
* Mark intermedidate computes values (hi, lo, yr) as volatile.
* Expand comments.
* Swap variable names in the sum_exact code so that x and y
are consistently chosen as the larger and smaller magnitude
values respectively.
........
r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line
Implement heapq in terms of less-than (to match list.sort()).
........
r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines
Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
........
r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines
Fix issue 2782: be less strict about the format string type in strftime.
Accept unicode and anything else ParseTuple "s#" can deal with. This
matches the time.strftime behavior.
........
r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines
Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3.
(I didn't regen configure, since I don't have a working autoconf.)
........
r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line
Issue 3501: Make heapq support both __le__ and __lt__.
........
2008-06-10 14:40:04 -03:00
|
|
|
:func:`getdefaulttimeout` is used.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-01-02 23:28:29 -04:00
|
|
|
If supplied, *source_address* must be a 2-tuple ``(host, port)`` for the
|
|
|
|
socket to bind to as its source address before connecting. If host or port
|
|
|
|
are '' or 0 respectively the OS default behavior will be used.
|
|
|
|
|
2022-04-18 19:15:41 -03:00
|
|
|
When a connection cannot be created, an exception is raised. By default,
|
|
|
|
it is the exception from the last address in the list. If *all_errors*
|
|
|
|
is ``True``, it is an :exc:`ExceptionGroup` containing the errors of all
|
|
|
|
attempts.
|
|
|
|
|
2010-01-02 23:28:29 -04:00
|
|
|
.. versionchanged:: 3.2
|
|
|
|
*source_address* was added.
|
|
|
|
|
2022-04-18 19:15:41 -03:00
|
|
|
.. versionchanged:: 3.11
|
|
|
|
*all_errors* was added.
|
|
|
|
|
|
|
|
|
2019-04-08 23:42:06 -03:00
|
|
|
.. function:: create_server(address, *, family=AF_INET, backlog=None, reuse_port=False, dualstack_ipv6=False)
|
2019-04-08 19:34:02 -03:00
|
|
|
|
|
|
|
Convenience function which creates a TCP socket bound to *address* (a 2-tuple
|
2022-05-20 05:18:02 -03:00
|
|
|
``(host, port)``) and returns the socket object.
|
2019-04-08 19:34:02 -03:00
|
|
|
|
|
|
|
*family* should be either :data:`AF_INET` or :data:`AF_INET6`.
|
2023-01-01 11:06:17 -04:00
|
|
|
*backlog* is the queue size passed to :meth:`socket.listen`; if not specified
|
|
|
|
, a default reasonable value is chosen.
|
2019-04-08 19:34:02 -03:00
|
|
|
*reuse_port* dictates whether to set the :data:`SO_REUSEPORT` socket option.
|
|
|
|
|
|
|
|
If *dualstack_ipv6* is true and the platform supports it the socket will
|
|
|
|
be able to accept both IPv4 and IPv6 connections, else it will raise
|
|
|
|
:exc:`ValueError`. Most POSIX platforms and Windows are supposed to support
|
|
|
|
this functionality.
|
|
|
|
When this functionality is enabled the address returned by
|
|
|
|
:meth:`socket.getpeername` when an IPv4 connection occurs will be an IPv6
|
|
|
|
address represented as an IPv4-mapped IPv6 address.
|
|
|
|
If *dualstack_ipv6* is false it will explicitly disable this functionality
|
|
|
|
on platforms that enable it by default (e.g. Linux).
|
|
|
|
This parameter can be used in conjunction with :func:`has_dualstack_ipv6`:
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
addr = ("", 8080) # all interfaces, port 8080
|
|
|
|
if socket.has_dualstack_ipv6():
|
|
|
|
s = socket.create_server(addr, family=socket.AF_INET6, dualstack_ipv6=True)
|
|
|
|
else:
|
|
|
|
s = socket.create_server(addr)
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
On POSIX platforms the :data:`SO_REUSEADDR` socket option is set in order to
|
|
|
|
immediately reuse previous sockets which were bound on the same *address*
|
|
|
|
and remained in TIME_WAIT state.
|
|
|
|
|
|
|
|
.. versionadded:: 3.8
|
|
|
|
|
|
|
|
.. function:: has_dualstack_ipv6()
|
|
|
|
|
|
|
|
Return ``True`` if the platform supports creating a TCP socket which can
|
|
|
|
handle both IPv4 and IPv6 connections.
|
|
|
|
|
|
|
|
.. versionadded:: 3.8
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-12-04 16:15:24 -04:00
|
|
|
.. function:: fromfd(fd, family, type, proto=0)
|
2013-12-04 16:11:03 -04:00
|
|
|
|
|
|
|
Duplicate the file descriptor *fd* (an integer as returned by a file object's
|
2023-10-23 16:05:56 -03:00
|
|
|
:meth:`~io.IOBase.fileno` method) and build a socket object from the result. Address
|
2023-11-27 10:36:54 -04:00
|
|
|
family, socket type and protocol number are as for the :func:`~socket.socket` function
|
2013-12-04 16:11:03 -04:00
|
|
|
above. The file descriptor should refer to a socket, but this is not checked ---
|
|
|
|
subsequent operations on the object may fail if the file descriptor is invalid.
|
|
|
|
This function is rarely needed, but can be used to get or set socket options on
|
|
|
|
a socket passed to a program as standard input or output (such as a server
|
|
|
|
started by the Unix inet daemon). The socket is assumed to be in blocking mode.
|
|
|
|
|
2013-12-04 16:15:24 -04:00
|
|
|
The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
The returned socket is now non-inheritable.
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
|
|
|
|
.. function:: fromshare(data)
|
|
|
|
|
|
|
|
Instantiate a socket from data obtained from the :meth:`socket.share`
|
|
|
|
method. The socket is assumed to be in blocking mode.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Windows.
|
2013-12-04 16:11:03 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: SocketType
|
|
|
|
|
|
|
|
This is a Python type object that represents the socket object type. It is the
|
|
|
|
same as ``type(socket(...))``.
|
|
|
|
|
|
|
|
|
|
|
|
Other functions
|
|
|
|
'''''''''''''''
|
|
|
|
|
|
|
|
The :mod:`socket` module also offers various network-related services:
|
|
|
|
|
|
|
|
|
2018-01-27 04:54:13 -04:00
|
|
|
.. function:: close(fd)
|
|
|
|
|
|
|
|
Close a socket file descriptor. This is like :func:`os.close`, but for
|
|
|
|
sockets. On some platforms (most noticeable Windows) :func:`os.close`
|
|
|
|
does not work for socket file descriptors.
|
|
|
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
2010-08-17 12:30:23 -03:00
|
|
|
.. function:: getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-05-31 14:04:40 -03:00
|
|
|
Translate the *host*/*port* argument into a sequence of 5-tuples that contain
|
|
|
|
all the necessary arguments for creating a socket connected to that service.
|
|
|
|
*host* is a domain name, a string representation of an IPv4/v6 address
|
|
|
|
or ``None``. *port* is a string service name such as ``'http'``, a numeric
|
|
|
|
port number or ``None``. By passing ``None`` as the value of *host*
|
|
|
|
and *port*, you can pass ``NULL`` to the underlying C API.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-17 12:30:23 -03:00
|
|
|
The *family*, *type* and *proto* arguments can be optionally specified
|
2010-05-31 14:04:40 -03:00
|
|
|
in order to narrow the list of addresses returned. Passing zero as a
|
|
|
|
value for each of these arguments selects the full range of results.
|
|
|
|
The *flags* argument can be one or several of the ``AI_*`` constants,
|
|
|
|
and will influence how results are computed and returned.
|
|
|
|
For example, :const:`AI_NUMERICHOST` will disable domain name resolution
|
|
|
|
and will raise an error if *host* is a domain name.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-05-31 14:04:40 -03:00
|
|
|
The function returns a list of 5-tuples with the following structure:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-17 12:30:23 -03:00
|
|
|
``(family, type, proto, canonname, sockaddr)``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-17 12:30:23 -03:00
|
|
|
In these tuples, *family*, *type*, *proto* are all integers and are
|
2023-11-27 10:36:54 -04:00
|
|
|
meant to be passed to the :func:`~socket.socket` function. *canonname* will be
|
2010-05-31 14:04:40 -03:00
|
|
|
a string representing the canonical name of the *host* if
|
|
|
|
:const:`AI_CANONNAME` is part of the *flags* argument; else *canonname*
|
|
|
|
will be empty. *sockaddr* is a tuple describing a socket address, whose
|
|
|
|
format depends on the returned *family* (a ``(address, port)`` 2-tuple for
|
2020-02-26 10:33:57 -04:00
|
|
|
:const:`AF_INET`, a ``(address, port, flowinfo, scope_id)`` 4-tuple for
|
2010-05-31 14:04:40 -03:00
|
|
|
:const:`AF_INET6`), and is meant to be passed to the :meth:`socket.connect`
|
|
|
|
method.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.getaddrinfo host,port,family,type,protocol socket.getaddrinfo
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2010-05-31 14:04:40 -03:00
|
|
|
The following example fetches address information for a hypothetical TCP
|
2015-06-02 01:19:30 -03:00
|
|
|
connection to ``example.org`` on port 80 (results may differ on your
|
2010-05-31 14:04:40 -03:00
|
|
|
system if IPv6 isn't enabled)::
|
|
|
|
|
2015-06-02 01:19:30 -03:00
|
|
|
>>> socket.getaddrinfo("example.org", 80, proto=socket.IPPROTO_TCP)
|
2021-03-31 01:17:26 -03:00
|
|
|
[(socket.AF_INET6, socket.SOCK_STREAM,
|
2015-06-02 01:19:30 -03:00
|
|
|
6, '', ('2606:2800:220:1:248:1893:25c8:1946', 80, 0, 0)),
|
2021-03-31 01:17:26 -03:00
|
|
|
(socket.AF_INET, socket.SOCK_STREAM,
|
2015-06-02 01:19:30 -03:00
|
|
|
6, '', ('93.184.216.34', 80))]
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-17 12:30:23 -03:00
|
|
|
.. versionchanged:: 3.2
|
2014-02-15 17:39:37 -04:00
|
|
|
parameters can now be passed using keyword arguments.
|
2010-08-17 12:30:23 -03:00
|
|
|
|
2018-02-12 15:47:42 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
for IPv6 multicast addresses, string representing an address will not
|
2020-02-26 10:33:57 -04:00
|
|
|
contain ``%scope_id`` part.
|
2018-02-12 15:47:42 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. function:: getfqdn([name])
|
|
|
|
|
|
|
|
Return a fully qualified domain name for *name*. If *name* is omitted or empty,
|
|
|
|
it is interpreted as the local host. To find the fully qualified name, the
|
Devil merge!
Merged revisions 66561,66564,66580,66610,66614,66618,66624-66625,66628-66629,66643,66645,66660-66665 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66561 | benjamin.peterson | 2008-09-22 17:13:29 -0500 (Mon, 22 Sep 2008) | 1 line
clean up docs for platform's linux_distribution and dist functions
........
r66564 | benjamin.peterson | 2008-09-23 08:32:46 -0500 (Tue, 23 Sep 2008) | 1 line
mention how to override boolean evaluation
........
r66580 | georg.brandl | 2008-09-24 04:47:55 -0500 (Wed, 24 Sep 2008) | 2 lines
Indentation normalization.
........
r66610 | andrew.kuchling | 2008-09-24 12:27:55 -0500 (Wed, 24 Sep 2008) | 1 line
Improve wording
........
r66614 | benjamin.peterson | 2008-09-24 17:11:59 -0500 (Wed, 24 Sep 2008) | 4 lines
#3950 fix missing scale factors in turtle.py
reviewers: Georg, Benjamin
........
r66618 | benjamin.peterson | 2008-09-25 15:35:45 -0500 (Thu, 25 Sep 2008) | 1 line
add a NEWs entry for r66614
........
r66624 | raymond.hettinger | 2008-09-25 18:31:52 -0500 (Thu, 25 Sep 2008) | 1 line
Fix namedtuple bug reported by Glenn Linderman. Template did not form correctly if the field names were input in Unicode.
........
r66625 | benjamin.peterson | 2008-09-25 21:58:36 -0500 (Thu, 25 Sep 2008) | 1 line
add the beginnings of a C-API 2 -> 3 porting guide
........
r66628 | benjamin.peterson | 2008-09-26 15:52:06 -0500 (Fri, 26 Sep 2008) | 1 line
add an 'other options' section
........
r66629 | georg.brandl | 2008-09-26 16:15:21 -0500 (Fri, 26 Sep 2008) | 2 lines
typos.
........
r66643 | andrew.kuchling | 2008-09-27 09:12:33 -0500 (Sat, 27 Sep 2008) | 1 line
Add a last bunch of items
........
r66645 | benjamin.peterson | 2008-09-27 11:23:55 -0500 (Sat, 27 Sep 2008) | 1 line
2to3's api should be considered unstable
........
r66660 | andrew.kuchling | 2008-09-27 17:54:08 -0500 (Sat, 27 Sep 2008) | 1 line
#3510: future-proof text
........
r66661 | benjamin.peterson | 2008-09-27 18:28:43 -0500 (Sat, 27 Sep 2008) | 1 line
clarify a few things
........
r66662 | andrew.kuchling | 2008-09-27 19:15:27 -0500 (Sat, 27 Sep 2008) | 1 line
#1579477: mention necessity to flush output before exec'ing
........
r66663 | andrew.kuchling | 2008-09-27 20:08:47 -0500 (Sat, 27 Sep 2008) | 1 line
#1415508: Document two functions
........
r66664 | benjamin.peterson | 2008-09-27 20:51:36 -0500 (Sat, 27 Sep 2008) | 1 line
better grammar
........
r66665 | benjamin.peterson | 2008-09-27 20:53:29 -0500 (Sat, 27 Sep 2008) | 1 line
note the 2to3 -d could be useful for other refactoring
........
2008-09-27 23:06:32 -03:00
|
|
|
hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the
|
2007-08-15 11:28:22 -03:00
|
|
|
host, if available. The first name which includes a period is selected. In
|
2021-08-26 15:40:28 -03:00
|
|
|
case no fully qualified domain name is available and *name* was provided,
|
|
|
|
it is returned unchanged. If *name* was empty or equal to ``'0.0.0.0'``,
|
|
|
|
the hostname from :func:`gethostname` is returned.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: gethostbyname(hostname)
|
|
|
|
|
|
|
|
Translate a host name to IPv4 address format. The IPv4 address is returned as a
|
|
|
|
string, such as ``'100.50.200.5'``. If the host name is an IPv4 address itself
|
|
|
|
it is returned unchanged. See :func:`gethostbyname_ex` for a more complete
|
|
|
|
interface. :func:`gethostbyname` does not support IPv6 name resolution, and
|
|
|
|
:func:`getaddrinfo` should be used instead for IPv4/v6 dual stack support.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.gethostbyname hostname socket.gethostbyname
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: gethostbyname_ex(hostname)
|
|
|
|
|
|
|
|
Translate a host name to IPv4 address format, extended interface. Return a
|
2023-09-07 07:33:02 -03:00
|
|
|
3-tuple ``(hostname, aliaslist, ipaddrlist)`` where *hostname* is the host's
|
2021-10-05 13:53:35 -03:00
|
|
|
primary host name, *aliaslist* is a (possibly
|
2007-08-15 11:28:22 -03:00
|
|
|
empty) list of alternative host names for the same address, and *ipaddrlist* is
|
|
|
|
a list of IPv4 addresses for the same interface on the same host (often but not
|
|
|
|
always a single address). :func:`gethostbyname_ex` does not support IPv6 name
|
|
|
|
resolution, and :func:`getaddrinfo` should be used instead for IPv4/v6 dual
|
|
|
|
stack support.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.gethostbyname hostname socket.gethostbyname_ex
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: gethostname()
|
|
|
|
|
|
|
|
Return a string containing the hostname of the machine where the Python
|
2008-11-05 17:42:45 -04:00
|
|
|
interpreter is currently executing.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.gethostname "" socket.gethostname
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2008-11-05 17:42:45 -04:00
|
|
|
Note: :func:`gethostname` doesn't always return the fully qualified domain
|
2015-05-18 19:31:00 -03:00
|
|
|
name; use :func:`getfqdn` for that.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: gethostbyaddr(ip_address)
|
|
|
|
|
2023-09-07 07:33:02 -03:00
|
|
|
Return a 3-tuple ``(hostname, aliaslist, ipaddrlist)`` where *hostname* is the
|
2007-08-15 11:28:22 -03:00
|
|
|
primary host name responding to the given *ip_address*, *aliaslist* is a
|
|
|
|
(possibly empty) list of alternative host names for the same address, and
|
|
|
|
*ipaddrlist* is a list of IPv4/v6 addresses for the same interface on the same
|
|
|
|
host (most likely containing only a single address). To find the fully qualified
|
|
|
|
domain name, use the function :func:`getfqdn`. :func:`gethostbyaddr` supports
|
|
|
|
both IPv4 and IPv6.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.gethostbyaddr ip_address socket.gethostbyaddr
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: getnameinfo(sockaddr, flags)
|
|
|
|
|
|
|
|
Translate a socket address *sockaddr* into a 2-tuple ``(host, port)``. Depending
|
2022-07-05 06:16:10 -03:00
|
|
|
on the settings of *flags*, the result can contain a fully qualified domain name
|
2007-08-15 11:28:22 -03:00
|
|
|
or numeric address representation in *host*. Similarly, *port* can contain a
|
|
|
|
string port name or a numeric port number.
|
|
|
|
|
2020-02-26 10:33:57 -04:00
|
|
|
For IPv6 addresses, ``%scope_id`` is appended to the host part if *sockaddr*
|
|
|
|
contains meaningful *scope_id*. Usually this happens for multicast addresses.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2019-04-11 18:13:37 -03:00
|
|
|
For more information about *flags* you can consult :manpage:`getnameinfo(3)`.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.getnameinfo sockaddr socket.getnameinfo
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. function:: getprotobyname(protocolname)
|
|
|
|
|
2021-07-26 19:11:55 -03:00
|
|
|
Translate an internet protocol name (for example, ``'icmp'``) to a constant
|
2023-11-27 10:36:54 -04:00
|
|
|
suitable for passing as the (optional) third argument to the :func:`~socket.socket`
|
2007-08-15 11:28:22 -03:00
|
|
|
function. This is usually only needed for sockets opened in "raw" mode
|
|
|
|
(:const:`SOCK_RAW`); for the normal socket modes, the correct protocol is chosen
|
|
|
|
automatically if the protocol is omitted or zero.
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: getservbyname(servicename[, protocolname])
|
|
|
|
|
2021-07-26 19:11:55 -03:00
|
|
|
Translate an internet service name and protocol name to a port number for that
|
2007-08-15 11:28:22 -03:00
|
|
|
service. The optional protocol name, if given, should be ``'tcp'`` or
|
|
|
|
``'udp'``, otherwise any protocol will match.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.getservbyname servicename,protocolname socket.getservbyname
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: getservbyport(port[, protocolname])
|
|
|
|
|
2021-07-26 19:11:55 -03:00
|
|
|
Translate an internet port number and protocol name to a service name for that
|
2007-08-15 11:28:22 -03:00
|
|
|
service. The optional protocol name, if given, should be ``'tcp'`` or
|
|
|
|
``'udp'``, otherwise any protocol will match.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.getservbyport port,protocolname socket.getservbyport
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: ntohl(x)
|
|
|
|
|
|
|
|
Convert 32-bit positive integers from network to host byte order. On machines
|
|
|
|
where the host byte order is the same as network byte order, this is a no-op;
|
|
|
|
otherwise, it performs a 4-byte swap operation.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: ntohs(x)
|
|
|
|
|
|
|
|
Convert 16-bit positive integers from network to host byte order. On machines
|
|
|
|
where the host byte order is the same as network byte order, this is a no-op;
|
|
|
|
otherwise, it performs a 2-byte swap operation.
|
|
|
|
|
2020-12-31 09:16:50 -04:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
Raises :exc:`OverflowError` if *x* does not fit in a 16-bit unsigned
|
|
|
|
integer.
|
2016-10-02 06:34:40 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: htonl(x)
|
|
|
|
|
|
|
|
Convert 32-bit positive integers from host to network byte order. On machines
|
|
|
|
where the host byte order is the same as network byte order, this is a no-op;
|
|
|
|
otherwise, it performs a 4-byte swap operation.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: htons(x)
|
|
|
|
|
|
|
|
Convert 16-bit positive integers from host to network byte order. On machines
|
|
|
|
where the host byte order is the same as network byte order, this is a no-op;
|
|
|
|
otherwise, it performs a 2-byte swap operation.
|
|
|
|
|
2020-12-31 09:16:50 -04:00
|
|
|
.. versionchanged:: 3.10
|
|
|
|
Raises :exc:`OverflowError` if *x* does not fit in a 16-bit unsigned
|
|
|
|
integer.
|
2016-10-02 06:34:40 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: inet_aton(ip_string)
|
|
|
|
|
|
|
|
Convert an IPv4 address from dotted-quad string format (for example,
|
2008-08-14 08:50:32 -03:00
|
|
|
'123.45.67.89') to 32-bit packed binary format, as a bytes object four characters in
|
2007-08-15 11:28:22 -03:00
|
|
|
length. This is useful when conversing with a program that uses the standard C
|
2022-10-04 20:26:14 -03:00
|
|
|
library and needs objects of type :c:struct:`in_addr`, which is the C type
|
2007-08-15 11:28:22 -03:00
|
|
|
for the 32-bit packed binary this function returns.
|
|
|
|
|
2009-06-04 07:28:36 -03:00
|
|
|
:func:`inet_aton` also accepts strings with less than three dots; see the
|
|
|
|
Unix manual page :manpage:`inet(3)` for details.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
If the IPv4 address string passed to this function is invalid,
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` will be raised. Note that exactly what is valid depends on
|
2010-10-06 07:11:56 -03:00
|
|
|
the underlying C implementation of :c:func:`inet_aton`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-05-04 17:50:30 -03:00
|
|
|
:func:`inet_aton` does not support IPv6, and :func:`inet_pton` should be used
|
2007-08-15 11:28:22 -03:00
|
|
|
instead for IPv4/v6 dual stack support.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: inet_ntoa(packed_ip)
|
|
|
|
|
2015-03-20 04:00:36 -03:00
|
|
|
Convert a 32-bit packed IPv4 address (a :term:`bytes-like object` four
|
|
|
|
bytes in length) to its standard dotted-quad string representation (for example,
|
2008-08-14 08:50:32 -03:00
|
|
|
'123.45.67.89'). This is useful when conversing with a program that uses the
|
2022-10-04 20:26:14 -03:00
|
|
|
standard C library and needs objects of type :c:struct:`in_addr`, which
|
2008-08-14 08:50:32 -03:00
|
|
|
is the C type for the 32-bit packed binary data this function takes as an
|
|
|
|
argument.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
If the byte sequence passed to this function is not exactly 4 bytes in
|
2011-10-12 12:53:43 -03:00
|
|
|
length, :exc:`OSError` will be raised. :func:`inet_ntoa` does not
|
2009-05-04 17:50:30 -03:00
|
|
|
support IPv6, and :func:`inet_ntop` should be used instead for IPv4/v6 dual
|
2008-08-14 08:50:32 -03:00
|
|
|
stack support.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-02-25 15:17:45 -04:00
|
|
|
.. versionchanged:: 3.5
|
2015-03-20 04:00:36 -03:00
|
|
|
Writable :term:`bytes-like object` is now accepted.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: inet_pton(address_family, ip_string)
|
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
Convert an IP address from its family-specific string format to a packed,
|
|
|
|
binary format. :func:`inet_pton` is useful when a library or network protocol
|
2022-10-04 20:26:14 -03:00
|
|
|
calls for an object of type :c:struct:`in_addr` (similar to
|
|
|
|
:func:`inet_aton`) or :c:struct:`in6_addr`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Supported values for *address_family* are currently :const:`AF_INET` and
|
|
|
|
:const:`AF_INET6`. If the IP address string *ip_string* is invalid,
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` will be raised. Note that exactly what is valid depends on
|
2007-08-15 11:28:22 -03:00
|
|
|
both the value of *address_family* and the underlying implementation of
|
2010-10-06 07:11:56 -03:00
|
|
|
:c:func:`inet_pton`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Unix, Windows.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-03-07 22:22:39 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
Windows support added
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. function:: inet_ntop(address_family, packed_ip)
|
|
|
|
|
2015-03-20 04:00:36 -03:00
|
|
|
Convert a packed IP address (a :term:`bytes-like object` of some number of
|
|
|
|
bytes) to its standard, family-specific string representation (for
|
|
|
|
example, ``'7.10.0.5'`` or ``'5aef:2b::8'``).
|
|
|
|
:func:`inet_ntop` is useful when a library or network protocol returns an
|
2022-10-04 20:26:14 -03:00
|
|
|
object of type :c:struct:`in_addr` (similar to :func:`inet_ntoa`) or
|
|
|
|
:c:struct:`in6_addr`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Supported values for *address_family* are currently :const:`AF_INET` and
|
2015-03-20 04:00:36 -03:00
|
|
|
:const:`AF_INET6`. If the bytes object *packed_ip* is not the correct
|
|
|
|
length for the specified address family, :exc:`ValueError` will be raised.
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` is raised for errors from the call to :func:`inet_ntop`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Unix, Windows.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-03-07 22:22:39 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
Windows support added
|
|
|
|
|
2016-02-25 15:17:45 -04:00
|
|
|
.. versionchanged:: 3.5
|
2015-03-20 04:00:36 -03:00
|
|
|
Writable :term:`bytes-like object` is now accepted.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-08-21 22:55:57 -03:00
|
|
|
..
|
|
|
|
XXX: Are sendmsg(), recvmsg() and CMSG_*() available on any
|
|
|
|
non-Unix platforms? The old (obsolete?) 4.2BSD form of the
|
|
|
|
interface, in which struct msghdr has no msg_control or
|
|
|
|
msg_controllen members, is not currently supported.
|
|
|
|
|
|
|
|
.. function:: CMSG_LEN(length)
|
|
|
|
|
|
|
|
Return the total length, without trailing padding, of an ancillary
|
|
|
|
data item with associated data of the given *length*. This value
|
|
|
|
can often be used as the buffer size for :meth:`~socket.recvmsg` to
|
|
|
|
receive a single item of ancillary data, but :rfc:`3542` requires
|
|
|
|
portable applications to use :func:`CMSG_SPACE` and thus include
|
|
|
|
space for padding, even when the item will be the last in the
|
|
|
|
buffer. Raises :exc:`OverflowError` if *length* is outside the
|
|
|
|
permissible range of values.
|
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, not WASI.
|
2022-07-29 11:42:09 -03:00
|
|
|
|
|
|
|
Most Unix platforms.
|
2011-08-21 22:55:57 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: CMSG_SPACE(length)
|
|
|
|
|
|
|
|
Return the buffer size needed for :meth:`~socket.recvmsg` to
|
|
|
|
receive an ancillary data item with associated data of the given
|
|
|
|
*length*, along with any trailing padding. The buffer space needed
|
|
|
|
to receive multiple items is the sum of the :func:`CMSG_SPACE`
|
|
|
|
values for their associated data lengths. Raises
|
|
|
|
:exc:`OverflowError` if *length* is outside the permissible range
|
|
|
|
of values.
|
|
|
|
|
|
|
|
Note that some systems might support ancillary data without
|
|
|
|
providing this function. Also note that setting the buffer size
|
|
|
|
using the results of this function may not precisely limit the
|
|
|
|
amount of ancillary data that can be received, since additional
|
|
|
|
data may be able to fit into the padding area.
|
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, not WASI.
|
2022-07-29 11:42:09 -03:00
|
|
|
|
|
|
|
most Unix platforms.
|
2011-08-21 22:55:57 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. function:: getdefaulttimeout()
|
|
|
|
|
2011-08-14 02:28:57 -03:00
|
|
|
Return the default timeout in seconds (float) for new socket objects. A value
|
2007-08-15 11:28:22 -03:00
|
|
|
of ``None`` indicates that new socket objects have no timeout. When the socket
|
|
|
|
module is first imported, the default is ``None``.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: setdefaulttimeout(timeout)
|
|
|
|
|
2011-08-14 02:28:57 -03:00
|
|
|
Set the default timeout in seconds (float) for new socket objects. When
|
2011-01-05 17:17:36 -04:00
|
|
|
the socket module is first imported, the default is ``None``. See
|
|
|
|
:meth:`~socket.settimeout` for possible values and their respective
|
|
|
|
meanings.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2011-02-28 18:25:22 -04:00
|
|
|
.. function:: sethostname(name)
|
|
|
|
|
2015-11-02 08:10:23 -04:00
|
|
|
Set the machine's hostname to *name*. This will raise an
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` if you don't have enough rights.
|
2011-02-28 18:25:22 -04:00
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.sethostname name socket.sethostname
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Unix.
|
2011-02-28 18:25:22 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
2011-05-15 04:26:45 -03:00
|
|
|
.. function:: if_nameindex()
|
|
|
|
|
2011-05-23 02:47:55 -03:00
|
|
|
Return a list of network interface information
|
|
|
|
(index int, name string) tuples.
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` if the system call fails.
|
2011-05-15 04:26:45 -03:00
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, Windows, not WASI.
|
2011-05-15 04:26:45 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2019-05-29 18:02:37 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
Windows support was added.
|
|
|
|
|
2020-10-19 19:30:58 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
On Windows network interfaces have different names in different contexts
|
|
|
|
(all names are examples):
|
|
|
|
|
|
|
|
* UUID: ``{FB605B73-AAC2-49A6-9A2F-25416AEA0573}``
|
|
|
|
* name: ``ethernet_32770``
|
|
|
|
* friendly name: ``vEthernet (nat)``
|
|
|
|
* description: ``Hyper-V Virtual Ethernet Adapter``
|
|
|
|
|
|
|
|
This function returns names of the second form from the list, ``ethernet_32770``
|
|
|
|
in this example case.
|
|
|
|
|
2011-05-15 04:26:45 -03:00
|
|
|
|
|
|
|
.. function:: if_nametoindex(if_name)
|
|
|
|
|
2011-05-23 02:47:55 -03:00
|
|
|
Return a network interface index number corresponding to an
|
|
|
|
interface name.
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` if no interface with the given name exists.
|
2011-05-15 04:26:45 -03:00
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, Windows, not WASI.
|
2011-05-15 04:26:45 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2019-05-29 18:02:37 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
Windows support was added.
|
|
|
|
|
2020-10-19 19:30:58 -03:00
|
|
|
.. seealso::
|
|
|
|
"Interface name" is a name as documented in :func:`if_nameindex`.
|
|
|
|
|
2011-05-15 04:26:45 -03:00
|
|
|
|
|
|
|
.. function:: if_indextoname(if_index)
|
|
|
|
|
2015-11-02 08:10:23 -04:00
|
|
|
Return a network interface name corresponding to an
|
2011-05-23 02:47:55 -03:00
|
|
|
interface index number.
|
2011-10-12 12:53:43 -03:00
|
|
|
:exc:`OSError` if no interface with the given index exists.
|
2011-05-15 04:26:45 -03:00
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, Windows, not WASI.
|
2011-05-15 04:26:45 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2019-05-29 18:02:37 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
Windows support was added.
|
|
|
|
|
2020-10-19 19:30:58 -03:00
|
|
|
.. seealso::
|
|
|
|
"Interface name" is a name as documented in :func:`if_nameindex`.
|
|
|
|
|
2011-05-15 04:26:45 -03:00
|
|
|
|
2021-04-22 01:08:46 -03:00
|
|
|
.. function:: send_fds(sock, buffers, fds[, flags[, address]])
|
|
|
|
|
|
|
|
Send the list of file descriptors *fds* over an :const:`AF_UNIX` socket *sock*.
|
|
|
|
The *fds* parameter is a sequence of file descriptors.
|
2023-11-27 10:36:54 -04:00
|
|
|
Consult :meth:`~socket.sendmsg` for the documentation of these parameters.
|
2021-04-22 01:08:46 -03:00
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, Windows, not WASI.
|
2022-07-29 11:42:09 -03:00
|
|
|
|
|
|
|
Unix platforms supporting :meth:`~socket.sendmsg`
|
|
|
|
and :const:`SCM_RIGHTS` mechanism.
|
2021-04-22 01:08:46 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.9
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: recv_fds(sock, bufsize, maxfds[, flags])
|
|
|
|
|
|
|
|
Receive up to *maxfds* file descriptors from an :const:`AF_UNIX` socket *sock*.
|
|
|
|
Return ``(msg, list(fds), flags, addr)``.
|
2023-11-27 10:36:54 -04:00
|
|
|
Consult :meth:`~socket.recvmsg` for the documentation of these parameters.
|
2021-04-22 01:08:46 -03:00
|
|
|
|
2024-03-28 05:13:13 -03:00
|
|
|
.. availability:: Unix, Windows, not WASI.
|
2022-07-29 11:42:09 -03:00
|
|
|
|
|
|
|
Unix platforms supporting :meth:`~socket.sendmsg`
|
|
|
|
and :const:`SCM_RIGHTS` mechanism.
|
2021-04-22 01:08:46 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.9
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Any truncated integers at the end of the list of file descriptors.
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _socket-objects:
|
|
|
|
|
|
|
|
Socket Objects
|
|
|
|
--------------
|
|
|
|
|
2013-12-04 16:02:42 -04:00
|
|
|
Socket objects have the following methods. Except for
|
|
|
|
:meth:`~socket.makefile`, these correspond to Unix system calls applicable
|
|
|
|
to sockets.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-04-24 01:24:36 -03:00
|
|
|
.. versionchanged:: 3.2
|
|
|
|
Support for the :term:`context manager` protocol was added. Exiting the
|
|
|
|
context manager is equivalent to calling :meth:`~socket.close`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.accept()
|
|
|
|
|
|
|
|
Accept a connection. The socket must be bound to an address and listening for
|
|
|
|
connections. The return value is a pair ``(conn, address)`` where *conn* is a
|
|
|
|
*new* socket object usable to send and receive data on the connection, and
|
|
|
|
*address* is the address bound to the socket on the other end of the connection.
|
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
The socket is now non-inheritable.
|
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.bind(address)
|
|
|
|
|
|
|
|
Bind the socket to *address*. The socket must not already be bound. (The format
|
|
|
|
of *address* depends on the address family --- see above.)
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.bind self,address socket.socket.bind
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: socket.close()
|
|
|
|
|
2013-12-04 16:02:42 -04:00
|
|
|
Mark the socket closed. The underlying system resource (e.g. a file
|
|
|
|
descriptor) is also closed when all file objects from :meth:`makefile()`
|
|
|
|
are closed. Once that happens, all future operations on the socket
|
|
|
|
object will fail. The remote end will receive no more data (after
|
|
|
|
queued data is flushed).
|
|
|
|
|
|
|
|
Sockets are automatically closed when they are garbage-collected, but
|
|
|
|
it is recommended to :meth:`close` them explicitly, or to use a
|
|
|
|
:keyword:`with` statement around them.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-04-10 21:38:12 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
:exc:`OSError` is now raised if an error occurs when the underlying
|
|
|
|
:c:func:`close` call is made.
|
|
|
|
|
2011-01-02 18:06:53 -04:00
|
|
|
.. note::
|
2014-03-12 20:51:00 -03:00
|
|
|
|
2011-01-02 18:06:53 -04:00
|
|
|
:meth:`close()` releases the resource associated with a connection but
|
|
|
|
does not necessarily close the connection immediately. If you want
|
|
|
|
to close the connection in a timely fashion, call :meth:`shutdown()`
|
|
|
|
before :meth:`close()`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.connect(address)
|
|
|
|
|
|
|
|
Connect to a remote socket at *address*. (The format of *address* depends on the
|
|
|
|
address family --- see above.)
|
|
|
|
|
2015-04-02 06:50:57 -03:00
|
|
|
If the connection is interrupted by a signal, the method waits until the
|
2020-11-20 04:26:07 -04:00
|
|
|
connection completes, or raise a :exc:`TimeoutError` on timeout, if the
|
2015-04-02 06:50:57 -03:00
|
|
|
signal handler doesn't raise an exception and the socket is blocking or has
|
|
|
|
a timeout. For non-blocking sockets, the method raises an
|
|
|
|
:exc:`InterruptedError` exception if the connection is interrupted by a
|
|
|
|
signal (or the exception raised by the signal handler).
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.connect self,address socket.socket.connect
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2015-04-02 06:50:57 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
The method now waits until the connection completes instead of raising an
|
|
|
|
:exc:`InterruptedError` exception if the connection is interrupted by a
|
|
|
|
signal, the signal handler doesn't raise an exception and the socket is
|
|
|
|
blocking or has a timeout (see the :pep:`475` for the rationale).
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.connect_ex(address)
|
|
|
|
|
|
|
|
Like ``connect(address)``, but return an error indicator instead of raising an
|
2010-10-06 07:11:56 -03:00
|
|
|
exception for errors returned by the C-level :c:func:`connect` call (other
|
2007-08-15 11:28:22 -03:00
|
|
|
problems, such as "host not found," can still raise exceptions). The error
|
|
|
|
indicator is ``0`` if the operation succeeded, otherwise the value of the
|
2010-10-06 07:11:56 -03:00
|
|
|
:c:data:`errno` variable. This is useful to support, for example, asynchronous
|
2007-08-15 11:28:22 -03:00
|
|
|
connects.
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.connect self,address socket.socket.connect_ex
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2010-08-09 17:39:54 -03:00
|
|
|
.. method:: socket.detach()
|
|
|
|
|
|
|
|
Put the socket object into closed state without actually closing the
|
|
|
|
underlying file descriptor. The file descriptor is returned, and can
|
|
|
|
be reused for other purposes.
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
|
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
.. method:: socket.dup()
|
|
|
|
|
|
|
|
Duplicate the socket.
|
|
|
|
|
|
|
|
The newly created socket is :ref:`non-inheritable <fd_inheritance>`.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.4
|
|
|
|
The socket is now non-inheritable.
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: socket.fileno()
|
|
|
|
|
2016-06-04 14:20:12 -03:00
|
|
|
Return the socket's file descriptor (a small integer), or -1 on failure. This
|
|
|
|
is useful with :func:`select.select`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Under Windows the small integer returned by this method cannot be used where a
|
|
|
|
file descriptor can be used (such as :func:`os.fdopen`). Unix does not have
|
|
|
|
this limitation.
|
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
.. method:: socket.get_inheritable()
|
|
|
|
|
|
|
|
Get the :ref:`inheritable flag <fd_inheritance>` of the socket's file
|
|
|
|
descriptor or socket's handle: ``True`` if the socket can be inherited in
|
|
|
|
child processes, ``False`` if it cannot.
|
|
|
|
|
|
|
|
.. versionadded:: 3.4
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: socket.getpeername()
|
|
|
|
|
|
|
|
Return the remote address to which the socket is connected. This is useful to
|
|
|
|
find out the port number of a remote IPv4/v6 socket, for instance. (The format
|
|
|
|
of the address returned depends on the address family --- see above.) On some
|
|
|
|
systems this function is not supported.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: socket.getsockname()
|
|
|
|
|
|
|
|
Return the socket's own address. This is useful to find out the port number of
|
|
|
|
an IPv4/v6 socket, for instance. (The format of the address returned depends on
|
|
|
|
the address family --- see above.)
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: socket.getsockopt(level, optname[, buflen])
|
|
|
|
|
|
|
|
Return the value of the given socket option (see the Unix man page
|
2023-12-13 03:24:55 -04:00
|
|
|
:manpage:`getsockopt(2)`). The needed symbolic constants (:ref:`SO_\* etc. <socket-unix-constants>`)
|
2007-08-15 11:28:22 -03:00
|
|
|
are defined in this module. If *buflen* is absent, an integer option is assumed
|
|
|
|
and its integer value is returned by the function. If *buflen* is present, it
|
|
|
|
specifies the maximum length of the buffer used to receive the option in, and
|
2008-08-14 08:50:32 -03:00
|
|
|
this buffer is returned as a bytes object. It is up to the caller to decode the
|
2007-08-15 11:28:22 -03:00
|
|
|
contents of the buffer (see the optional built-in module :mod:`struct` for a way
|
2008-08-14 08:50:32 -03:00
|
|
|
to decode C structures encoded as byte strings).
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2018-01-28 18:27:38 -04:00
|
|
|
.. method:: socket.getblocking()
|
|
|
|
|
|
|
|
Return ``True`` if socket is in blocking mode, ``False`` if in
|
|
|
|
non-blocking.
|
|
|
|
|
2023-06-04 12:59:16 -03:00
|
|
|
This is equivalent to checking ``socket.gettimeout() != 0``.
|
2018-01-28 18:27:38 -04:00
|
|
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
.. method:: socket.gettimeout()
|
|
|
|
|
2011-08-14 02:28:57 -03:00
|
|
|
Return the timeout in seconds (float) associated with socket operations,
|
2011-01-05 17:17:36 -04:00
|
|
|
or ``None`` if no timeout is set. This reflects the last call to
|
|
|
|
:meth:`setblocking` or :meth:`settimeout`.
|
|
|
|
|
|
|
|
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
.. method:: socket.ioctl(control, option)
|
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
:platform: Windows
|
|
|
|
|
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59987 | raymond.hettinger | 2008-01-15 21:52:42 +0100 (Tue, 15 Jan 2008) | 1 line
Refactor if/elif chain for clarity and speed. Remove dependency on subclasses having to implement _empty and _full.
........
r59988 | raymond.hettinger | 2008-01-15 22:22:47 +0100 (Tue, 15 Jan 2008) | 1 line
Fix-up half-written paragraph in the docs
........
r59989 | amaury.forgeotdarc | 2008-01-15 22:25:11 +0100 (Tue, 15 Jan 2008) | 3 lines
test_doctest fails since r59984.
Not sure if these are the correct values, but save_stdout has to be set before its usage...
........
r59992 | andrew.kuchling | 2008-01-16 01:32:03 +0100 (Wed, 16 Jan 2008) | 1 line
Docstring typos
........
r59993 | andrew.kuchling | 2008-01-16 04:17:25 +0100 (Wed, 16 Jan 2008) | 1 line
Add PEP 3141 section
........
r59998 | andrew.kuchling | 2008-01-16 14:01:51 +0100 (Wed, 16 Jan 2008) | 1 line
Markup fix
........
r59999 | georg.brandl | 2008-01-16 17:56:29 +0100 (Wed, 16 Jan 2008) | 2 lines
Fix MSDN library URL. (#1854)
........
r60006 | georg.brandl | 2008-01-16 21:27:56 +0100 (Wed, 16 Jan 2008) | 3 lines
Add Python-specific content to Doc dir. Update configuration file
to work with the newest Sphinx.
........
r60007 | georg.brandl | 2008-01-16 21:29:00 +0100 (Wed, 16 Jan 2008) | 2 lines
Doc build should work with 2.4 now.
........
r60009 | raymond.hettinger | 2008-01-17 00:38:16 +0100 (Thu, 17 Jan 2008) | 1 line
Minor wordsmithing.
........
r60010 | raymond.hettinger | 2008-01-17 00:40:45 +0100 (Thu, 17 Jan 2008) | 1 line
Add queues will alternative fetch orders (priority based and stack based).
........
r60011 | raymond.hettinger | 2008-01-17 00:49:35 +0100 (Thu, 17 Jan 2008) | 1 line
Add news entry.
........
r60013 | raymond.hettinger | 2008-01-17 04:02:14 +0100 (Thu, 17 Jan 2008) | 1 line
Make starmap() match its pure python definition and accept any itertable input (not just tuples).
........
r60015 | gregory.p.smith | 2008-01-17 08:43:20 +0100 (Thu, 17 Jan 2008) | 3 lines
Comply with RFC 3207.
Fixes issue 829951 - http://bugs.python.org/issue829951
........
r60018 | gregory.p.smith | 2008-01-17 09:03:17 +0100 (Thu, 17 Jan 2008) | 2 lines
entry for r60015
........
r60019 | raymond.hettinger | 2008-01-17 09:07:05 +0100 (Thu, 17 Jan 2008) | 1 line
Note versionadded.
........
r60020 | gregory.p.smith | 2008-01-17 09:35:49 +0100 (Thu, 17 Jan 2008) | 8 lines
Fixes (accepts patch) issue1339 - http://bugs.python.org/issue1339
- Factor out the duplication of EHLO/HELO in login() and sendmail() to
a new function, ehlo_or_helo_if_needed().
- Use ehlo_or_helo_if_needed() in starttls()
- Check for the starttls exception in starttls() in the same way as
login() checks for the auth extension.
Contributed by Bill Fenner.
........
r60021 | andrew.kuchling | 2008-01-17 13:00:15 +0100 (Thu, 17 Jan 2008) | 1 line
Revise 3141 section a bit; add some Windows items
........
r60022 | brett.cannon | 2008-01-17 19:45:10 +0100 (Thu, 17 Jan 2008) | 2 lines
Fix a function pointer declaration to silence the compiler.
........
r60024 | raymond.hettinger | 2008-01-17 20:31:38 +0100 (Thu, 17 Jan 2008) | 1 line
Issue #1861: Add read-only attribute listing upcoming events in the order they will be run.
........
r60025 | andrew.kuchling | 2008-01-17 20:49:24 +0100 (Thu, 17 Jan 2008) | 1 line
Correction from Jordan Lewis: halfdelay() uses tenths of a second, not milliseconds
........
r60026 | raymond.hettinger | 2008-01-17 23:27:49 +0100 (Thu, 17 Jan 2008) | 1 line
Add advice on choosing between scheduler and threading.Timer().
........
r60028 | christian.heimes | 2008-01-18 00:01:44 +0100 (Fri, 18 Jan 2008) | 2 lines
Updated new property syntax. An elaborate example for subclassing and the getter was missing.
Added comment about VS 2008 and PGO builds.
........
r60029 | raymond.hettinger | 2008-01-18 00:32:01 +0100 (Fri, 18 Jan 2008) | 1 line
Fix-up Timer() example.
........
r60030 | raymond.hettinger | 2008-01-18 00:56:56 +0100 (Fri, 18 Jan 2008) | 1 line
Fix markup
........
r60031 | raymond.hettinger | 2008-01-18 01:10:42 +0100 (Fri, 18 Jan 2008) | 1 line
clearcache() needs to remove the dict as well as clear it.
........
r60033 | andrew.kuchling | 2008-01-18 03:26:16 +0100 (Fri, 18 Jan 2008) | 1 line
Bump verson
........
r60034 | andrew.kuchling | 2008-01-18 03:42:52 +0100 (Fri, 18 Jan 2008) | 1 line
Typo fix
........
r60035 | christian.heimes | 2008-01-18 08:30:20 +0100 (Fri, 18 Jan 2008) | 3 lines
Coverity issue CID #197
var_decl: Declared variable "stm" without initializer
ninit_use_in_call: Using uninitialized value "stm" (field "stm".tm_zone uninitialized) in call to function "mktime"
........
r60036 | christian.heimes | 2008-01-18 08:45:30 +0100 (Fri, 18 Jan 2008) | 11 lines
Coverity issue CID #167
Event alloc_fn: Called allocation function "metacompile" [model]
Event var_assign: Assigned variable "gr" to storage returned from "metacompile"
gr = metacompile(n);
Event pass_arg: Variable "gr" not freed or pointed-to in function "maketables" [model]
g = maketables(gr);
translatelabels(g);
addfirstsets(g);
Event leaked_storage: Returned without freeing storage "gr"
return g;
........
r60038 | christian.heimes | 2008-01-18 09:04:57 +0100 (Fri, 18 Jan 2008) | 3 lines
Coverity issue CID #182
size_error: Allocating 1 bytes to pointer "children", which needs at least 4 bytes
........
r60041 | christian.heimes | 2008-01-18 09:47:59 +0100 (Fri, 18 Jan 2008) | 4 lines
Coverity issue CID #169
local_ptr_assign_local: Assigning address of stack variable "namebuf" to pointer "filename"
out_of_scope: Variable "namebuf" goes out of scope
use_invalid: Used "filename" pointing to out-of-scope variable "namebuf"
........
r60042 | christian.heimes | 2008-01-18 09:53:45 +0100 (Fri, 18 Jan 2008) | 2 lines
Coverity CID #168
leaked_storage: Returned without freeing storage "fp"
........
2008-01-18 05:56:22 -04:00
|
|
|
The :meth:`ioctl` method is a limited interface to the WSAIoctl system
|
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line
Get rid of multi-row cells.
........
r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line
Remove LaTeXy index entry syntax.
........
r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Better cross-referencing in socket and winreg docs.
........
r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface.
........
r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Minor spelling changes to _winreg docs.
........
r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line
Fix code example to have valid syntax so that it can be highlighted.
........
r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric.
........
r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line
#8642: fix wrong function name.
........
r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line
Fix reference direction.
........
r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line
Consolidate deprecation messages.
........
r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line
Fix typo.
........
2010-05-19 17:57:08 -03:00
|
|
|
interface. Please refer to the `Win32 documentation
|
2016-02-26 14:37:12 -04:00
|
|
|
<https://msdn.microsoft.com/en-us/library/ms741621%28VS.85%29.aspx>`_ for more
|
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line
Get rid of multi-row cells.
........
r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line
Remove LaTeXy index entry syntax.
........
r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Better cross-referencing in socket and winreg docs.
........
r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface.
........
r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Minor spelling changes to _winreg docs.
........
r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line
Fix code example to have valid syntax so that it can be highlighted.
........
r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric.
........
r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line
#8642: fix wrong function name.
........
r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line
Fix reference direction.
........
r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line
Consolidate deprecation messages.
........
r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line
Fix typo.
........
2010-05-19 17:57:08 -03:00
|
|
|
information.
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 74074,74077,74111,74188,74192-74193,74200,74252-74253,74258-74261 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74074 | georg.brandl | 2009-07-18 05:03:10 -0400 (Sat, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74077 | georg.brandl | 2009-07-18 05:43:40 -0400 (Sat, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74111 | benjamin.peterson | 2009-07-20 09:30:10 -0400 (Mon, 20 Jul 2009) | 1 line
remove docs for deprecated -p option
........
r74188 | benjamin.peterson | 2009-07-23 10:25:31 -0400 (Thu, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 12:28:38 -0400 (Fri, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 12:46:38 -0400 (Fri, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74200 | georg.brandl | 2009-07-25 09:02:15 -0400 (Sat, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74252 | georg.brandl | 2009-07-29 12:06:31 -0400 (Wed, 29 Jul 2009) | 1 line
#6593: fix link targets.
........
r74253 | georg.brandl | 2009-07-29 12:09:17 -0400 (Wed, 29 Jul 2009) | 1 line
#6591: add reference to ioctl in fcntl module for platforms other than Windows.
........
r74258 | georg.brandl | 2009-07-29 12:57:05 -0400 (Wed, 29 Jul 2009) | 1 line
Add a link to readline, and mention IPython and bpython.
........
r74259 | georg.brandl | 2009-07-29 13:07:21 -0400 (Wed, 29 Jul 2009) | 1 line
Fix some markup and small factual glitches found by M. Markert.
........
r74260 | georg.brandl | 2009-07-29 13:15:20 -0400 (Wed, 29 Jul 2009) | 1 line
Fix a few markup glitches.
........
r74261 | georg.brandl | 2009-07-29 13:50:25 -0400 (Wed, 29 Jul 2009) | 1 line
Rewrite the section about classes a bit; mostly tidbits, and a larger update to the section about "private" variables to reflect the Pythonic consensus better.
........
2009-07-29 16:54:39 -03:00
|
|
|
On other platforms, the generic :func:`fcntl.fcntl` and :func:`fcntl.ioctl`
|
|
|
|
functions may be used; they accept a socket object as their first argument.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-06-17 16:52:18 -03:00
|
|
|
Currently only the following control codes are supported:
|
|
|
|
``SIO_RCVALL``, ``SIO_KEEPALIVE_VALS``, and ``SIO_LOOPBACK_FAST_PATH``.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.6
|
|
|
|
``SIO_LOOPBACK_FAST_PATH`` was added.
|
|
|
|
|
2014-05-22 15:45:39 -03:00
|
|
|
.. method:: socket.listen([backlog])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2014-05-22 15:45:39 -03:00
|
|
|
Enable a server to accept connections. If *backlog* is specified, it must
|
|
|
|
be at least 0 (if it is lower, it is set to 0); it specifies the number of
|
|
|
|
unaccepted connections that the system will allow before refusing new
|
|
|
|
connections. If not specified, a default reasonable value is chosen.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2014-05-22 15:45:39 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
The *backlog* parameter is now optional.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
|
2010-12-28 07:49:41 -04:00
|
|
|
.. method:: socket.makefile(mode='r', buffering=None, *, encoding=None, \
|
|
|
|
errors=None, newline=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. index:: single: I/O control; buffering
|
|
|
|
|
2010-12-28 07:49:41 -04:00
|
|
|
Return a :term:`file object` associated with the socket. The exact returned
|
|
|
|
type depends on the arguments given to :meth:`makefile`. These arguments are
|
2016-02-18 11:34:00 -04:00
|
|
|
interpreted the same way as by the built-in :func:`open` function, except
|
|
|
|
the only supported *mode* values are ``'r'`` (default), ``'w'`` and ``'b'``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-12-04 16:02:42 -04:00
|
|
|
The socket must be in blocking mode; it can have a timeout, but the file
|
2015-11-01 23:37:02 -04:00
|
|
|
object's internal buffer may end up in an inconsistent state if a timeout
|
2013-12-04 16:02:42 -04:00
|
|
|
occurs.
|
|
|
|
|
|
|
|
Closing the file object returned by :meth:`makefile` won't close the
|
|
|
|
original socket unless all other file objects have been closed and
|
|
|
|
:meth:`socket.close` has been called on the socket object.
|
2010-12-28 07:49:41 -04:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
On Windows, the file-like object created by :meth:`makefile` cannot be
|
|
|
|
used where a file object with a file descriptor is expected, such as the
|
|
|
|
stream arguments of :meth:`subprocess.Popen`.
|
2010-01-04 14:50:53 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.recv(bufsize[, flags])
|
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
Receive data from the socket. The return value is a bytes object representing the
|
2007-08-15 11:28:22 -03:00
|
|
|
data received. The maximum amount of data to be received at once is specified
|
2024-02-20 10:54:33 -04:00
|
|
|
by *bufsize*. A returned empty bytes object indicates that the client has disconnected.
|
|
|
|
See the Unix manual page :manpage:`recv(2)` for the meaning of the optional argument
|
|
|
|
*flags*; it defaults to zero.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
For best match with hardware and network realities, the value of *bufsize*
|
|
|
|
should be a relatively small power of 2, for example, 4096.
|
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.recvfrom(bufsize[, flags])
|
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
Receive data from the socket. The return value is a pair ``(bytes, address)``
|
|
|
|
where *bytes* is a bytes object representing the data received and *address* is the
|
2007-08-15 11:28:22 -03:00
|
|
|
address of the socket sending the data. See the Unix manual page
|
|
|
|
:manpage:`recv(2)` for the meaning of the optional argument *flags*; it defaults
|
|
|
|
to zero. (The format of *address* depends on the address family --- see above.)
|
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2018-02-12 15:47:42 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
For multicast IPv6 address, first item of *address* does not contain
|
2020-02-26 10:33:57 -04:00
|
|
|
``%scope_id`` part anymore. In order to get full IPv6 address use
|
2018-02-12 15:47:42 -04:00
|
|
|
:func:`getnameinfo`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-08-21 22:55:57 -03:00
|
|
|
.. method:: socket.recvmsg(bufsize[, ancbufsize[, flags]])
|
|
|
|
|
|
|
|
Receive normal data (up to *bufsize* bytes) and ancillary data from
|
|
|
|
the socket. The *ancbufsize* argument sets the size in bytes of
|
|
|
|
the internal buffer used to receive the ancillary data; it defaults
|
|
|
|
to 0, meaning that no ancillary data will be received. Appropriate
|
|
|
|
buffer sizes for ancillary data can be calculated using
|
|
|
|
:func:`CMSG_SPACE` or :func:`CMSG_LEN`, and items which do not fit
|
|
|
|
into the buffer might be truncated or discarded. The *flags*
|
|
|
|
argument defaults to 0 and has the same meaning as for
|
|
|
|
:meth:`recv`.
|
|
|
|
|
|
|
|
The return value is a 4-tuple: ``(data, ancdata, msg_flags,
|
|
|
|
address)``. The *data* item is a :class:`bytes` object holding the
|
|
|
|
non-ancillary data received. The *ancdata* item is a list of zero
|
|
|
|
or more tuples ``(cmsg_level, cmsg_type, cmsg_data)`` representing
|
|
|
|
the ancillary data (control messages) received: *cmsg_level* and
|
|
|
|
*cmsg_type* are integers specifying the protocol level and
|
|
|
|
protocol-specific type respectively, and *cmsg_data* is a
|
|
|
|
:class:`bytes` object holding the associated data. The *msg_flags*
|
|
|
|
item is the bitwise OR of various flags indicating conditions on
|
|
|
|
the received message; see your system documentation for details.
|
|
|
|
If the receiving socket is unconnected, *address* is the address of
|
|
|
|
the sending socket, if available; otherwise, its value is
|
|
|
|
unspecified.
|
|
|
|
|
|
|
|
On some systems, :meth:`sendmsg` and :meth:`recvmsg` can be used to
|
|
|
|
pass file descriptors between processes over an :const:`AF_UNIX`
|
|
|
|
socket. When this facility is used (it is often restricted to
|
|
|
|
:const:`SOCK_STREAM` sockets), :meth:`recvmsg` will return, in its
|
|
|
|
ancillary data, items of the form ``(socket.SOL_SOCKET,
|
|
|
|
socket.SCM_RIGHTS, fds)``, where *fds* is a :class:`bytes` object
|
|
|
|
representing the new file descriptors as a binary array of the
|
2022-10-05 15:01:14 -03:00
|
|
|
native C :c:expr:`int` type. If :meth:`recvmsg` raises an
|
2011-08-21 22:55:57 -03:00
|
|
|
exception after the system call returns, it will first attempt to
|
|
|
|
close any file descriptors received via this mechanism.
|
|
|
|
|
|
|
|
Some systems do not indicate the truncated length of ancillary data
|
|
|
|
items which have been only partially received. If an item appears
|
|
|
|
to extend beyond the end of the buffer, :meth:`recvmsg` will issue
|
|
|
|
a :exc:`RuntimeWarning`, and will return the part of it which is
|
|
|
|
inside the buffer provided it has not been truncated before the
|
|
|
|
start of its associated data.
|
|
|
|
|
|
|
|
On systems which support the :const:`SCM_RIGHTS` mechanism, the
|
|
|
|
following function will receive up to *maxfds* file descriptors,
|
|
|
|
returning the message data and a list containing the descriptors
|
|
|
|
(while ignoring unexpected conditions such as unrelated control
|
|
|
|
messages being received). See also :meth:`sendmsg`. ::
|
|
|
|
|
|
|
|
import socket, array
|
|
|
|
|
|
|
|
def recv_fds(sock, msglen, maxfds):
|
|
|
|
fds = array.array("i") # Array of ints
|
|
|
|
msg, ancdata, flags, addr = sock.recvmsg(msglen, socket.CMSG_LEN(maxfds * fds.itemsize))
|
|
|
|
for cmsg_level, cmsg_type, cmsg_data in ancdata:
|
2019-11-26 02:31:09 -04:00
|
|
|
if cmsg_level == socket.SOL_SOCKET and cmsg_type == socket.SCM_RIGHTS:
|
2011-08-21 22:55:57 -03:00
|
|
|
# Append data, ignoring any truncated integers at the end.
|
2019-11-26 02:31:09 -04:00
|
|
|
fds.frombytes(cmsg_data[:len(cmsg_data) - (len(cmsg_data) % fds.itemsize)])
|
2011-08-21 22:55:57 -03:00
|
|
|
return msg, list(fds)
|
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Unix.
|
|
|
|
|
|
|
|
Most Unix platforms.
|
2011-08-21 22:55:57 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2011-08-21 22:55:57 -03:00
|
|
|
|
|
|
|
.. method:: socket.recvmsg_into(buffers[, ancbufsize[, flags]])
|
|
|
|
|
|
|
|
Receive normal data and ancillary data from the socket, behaving as
|
|
|
|
:meth:`recvmsg` would, but scatter the non-ancillary data into a
|
|
|
|
series of buffers instead of returning a new bytes object. The
|
|
|
|
*buffers* argument must be an iterable of objects that export
|
|
|
|
writable buffers (e.g. :class:`bytearray` objects); these will be
|
|
|
|
filled with successive chunks of the non-ancillary data until it
|
|
|
|
has all been written or there are no more buffers. The operating
|
|
|
|
system may set a limit (:func:`~os.sysconf` value ``SC_IOV_MAX``)
|
|
|
|
on the number of buffers that can be used. The *ancbufsize* and
|
|
|
|
*flags* arguments have the same meaning as for :meth:`recvmsg`.
|
|
|
|
|
|
|
|
The return value is a 4-tuple: ``(nbytes, ancdata, msg_flags,
|
|
|
|
address)``, where *nbytes* is the total number of bytes of
|
|
|
|
non-ancillary data written into the buffers, and *ancdata*,
|
|
|
|
*msg_flags* and *address* are the same as for :meth:`recvmsg`.
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
>>> import socket
|
|
|
|
>>> s1, s2 = socket.socketpair()
|
|
|
|
>>> b1 = bytearray(b'----')
|
|
|
|
>>> b2 = bytearray(b'0123456789')
|
|
|
|
>>> b3 = bytearray(b'--------------')
|
|
|
|
>>> s1.send(b'Mary had a little lamb')
|
|
|
|
22
|
|
|
|
>>> s2.recvmsg_into([b1, memoryview(b2)[2:9], b3])
|
|
|
|
(22, [], 0, None)
|
|
|
|
>>> [b1, b2, b3]
|
|
|
|
[bytearray(b'Mary'), bytearray(b'01 had a 9'), bytearray(b'little lamb---')]
|
|
|
|
|
2022-07-29 11:42:09 -03:00
|
|
|
.. availability:: Unix.
|
|
|
|
|
|
|
|
Most Unix platforms.
|
2011-08-21 22:55:57 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: socket.recvfrom_into(buffer[, nbytes[, flags]])
|
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
Receive data from the socket, writing it into *buffer* instead of creating a
|
|
|
|
new bytestring. The return value is a pair ``(nbytes, address)`` where *nbytes* is
|
2007-08-15 11:28:22 -03:00
|
|
|
the number of bytes received and *address* is the address of the socket sending
|
|
|
|
the data. See the Unix manual page :manpage:`recv(2)` for the meaning of the
|
|
|
|
optional argument *flags*; it defaults to zero. (The format of *address*
|
|
|
|
depends on the address family --- see above.)
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: socket.recv_into(buffer[, nbytes[, flags]])
|
|
|
|
|
|
|
|
Receive up to *nbytes* bytes from the socket, storing the data into a buffer
|
2008-08-14 08:50:32 -03:00
|
|
|
rather than creating a new bytestring. If *nbytes* is not specified (or 0),
|
Merged revisions 79307,79408,79430,79533,79542,79579-79580,79585-79587,79607-79608,79622,79717,79820,79822,79828,79862,79875,79923-79924,79941-79943,79945,79947,79951-79952 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r79307 | florent.xicluna | 2010-03-22 17:45:50 -0500 (Mon, 22 Mar 2010) | 2 lines
#7667: Fix doctest failures with non-ASCII paths.
........
r79408 | victor.stinner | 2010-03-24 20:18:38 -0500 (Wed, 24 Mar 2010) | 2 lines
Fix a gcc warning introduced by r79397.
........
r79430 | brian.curtin | 2010-03-25 18:48:54 -0500 (Thu, 25 Mar 2010) | 2 lines
Fix #6538. Markup RegexObject and MatchObject as classes. Patch by Ryan Arana.
........
r79533 | barry.warsaw | 2010-03-31 16:07:16 -0500 (Wed, 31 Mar 2010) | 6 lines
- Issue #8233: When run as a script, py_compile.py optionally takes a single
argument `-` which tells it to read files to compile from stdin. Each line
is read on demand and the named file is compiled immediately. (Original
patch by Piotr O?\197?\188arowski).
........
r79542 | r.david.murray | 2010-03-31 20:28:39 -0500 (Wed, 31 Mar 2010) | 3 lines
A couple small grammar fixes in test.rst, and rewrite the
check_warnings docs to be clearer.
........
r79579 | georg.brandl | 2010-04-02 03:34:41 -0500 (Fri, 02 Apr 2010) | 1 line
Add 2.6.5.
........
r79580 | georg.brandl | 2010-04-02 03:39:09 -0500 (Fri, 02 Apr 2010) | 1 line
#2768: add a note on how to get a file descriptor.
........
r79585 | georg.brandl | 2010-04-02 04:03:18 -0500 (Fri, 02 Apr 2010) | 1 line
Remove col-spanning cells in logging docs.
........
r79586 | georg.brandl | 2010-04-02 04:07:42 -0500 (Fri, 02 Apr 2010) | 1 line
Document PyImport_ExecCodeModuleEx().
........
r79587 | georg.brandl | 2010-04-02 04:11:49 -0500 (Fri, 02 Apr 2010) | 1 line
#8012: clarification in generator glossary entry.
........
r79607 | andrew.kuchling | 2010-04-02 12:48:23 -0500 (Fri, 02 Apr 2010) | 1 line
#6647: document that catch_warnings is not thread-safe
........
r79608 | andrew.kuchling | 2010-04-02 12:54:26 -0500 (Fri, 02 Apr 2010) | 1 line
#6647: add note to two examples
........
r79622 | tarek.ziade | 2010-04-02 16:34:19 -0500 (Fri, 02 Apr 2010) | 1 line
removed documentation on code that was reverted and pushed into distutils2
........
r79717 | antoine.pitrou | 2010-04-03 16:22:38 -0500 (Sat, 03 Apr 2010) | 4 lines
Fix wording / typography, and a slightly misleading statement
(memoryviews don't support complex structures right now)
........
r79820 | benjamin.peterson | 2010-04-05 22:34:09 -0500 (Mon, 05 Apr 2010) | 1 line
ready _sre types
........
r79822 | georg.brandl | 2010-04-06 03:18:15 -0500 (Tue, 06 Apr 2010) | 1 line
#8320: document return value of recv_into().
........
r79828 | georg.brandl | 2010-04-06 09:33:44 -0500 (Tue, 06 Apr 2010) | 1 line
Add JP.
........
r79862 | georg.brandl | 2010-04-06 15:27:59 -0500 (Tue, 06 Apr 2010) | 1 line
Fix syntax.
........
r79875 | mark.dickinson | 2010-04-06 17:18:23 -0500 (Tue, 06 Apr 2010) | 1 line
More NaN consistency doc fixes.
........
r79923 | georg.brandl | 2010-04-10 06:15:24 -0500 (Sat, 10 Apr 2010) | 1 line
#8360: skipTest was added in 2.7.
........
r79924 | georg.brandl | 2010-04-10 06:16:59 -0500 (Sat, 10 Apr 2010) | 1 line
#8346: update version.
........
r79941 | andrew.kuchling | 2010-04-10 20:39:36 -0500 (Sat, 10 Apr 2010) | 1 line
Two grammar fixes
........
r79942 | andrew.kuchling | 2010-04-10 20:40:06 -0500 (Sat, 10 Apr 2010) | 1 line
Punctuation fix
........
r79943 | andrew.kuchling | 2010-04-10 20:40:30 -0500 (Sat, 10 Apr 2010) | 1 line
Add various items
........
r79945 | andrew.kuchling | 2010-04-10 20:40:49 -0500 (Sat, 10 Apr 2010) | 1 line
name correct
........
r79947 | andrew.kuchling | 2010-04-10 20:44:13 -0500 (Sat, 10 Apr 2010) | 1 line
Remove distutils section
........
r79951 | andrew.kuchling | 2010-04-11 07:48:08 -0500 (Sun, 11 Apr 2010) | 1 line
Two typo fixes
........
r79952 | andrew.kuchling | 2010-04-11 07:49:37 -0500 (Sun, 11 Apr 2010) | 1 line
Add two items
........
2010-04-11 13:12:57 -03:00
|
|
|
receive up to the size available in the given buffer. Returns the number of
|
|
|
|
bytes received. See the Unix manual page :manpage:`recv(2)` for the meaning
|
|
|
|
of the optional argument *flags*; it defaults to zero.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
.. method:: socket.send(bytes[, flags])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Send data to the socket. The socket must be connected to a remote socket. The
|
|
|
|
optional *flags* argument has the same meaning as for :meth:`recv` above.
|
|
|
|
Returns the number of bytes sent. Applications are responsible for checking that
|
|
|
|
all data has been sent; if only some of the data was transmitted, the
|
2012-02-09 05:54:17 -04:00
|
|
|
application needs to attempt delivery of the remaining data. For further
|
|
|
|
information on this topic, consult the :ref:`socket-howto`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-08-14 08:50:32 -03:00
|
|
|
.. method:: socket.sendall(bytes[, flags])
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Send data to the socket. The socket must be connected to a remote socket. The
|
|
|
|
optional *flags* argument has the same meaning as for :meth:`recv` above.
|
2008-08-14 08:50:32 -03:00
|
|
|
Unlike :meth:`send`, this method continues to send data from *bytes* until
|
2007-08-15 11:28:22 -03:00
|
|
|
either all data has been sent or an error occurs. ``None`` is returned on
|
|
|
|
success. On error, an exception is raised, and there is no way to determine how
|
|
|
|
much data, if any, was successfully sent.
|
|
|
|
|
2015-04-06 18:16:34 -03:00
|
|
|
.. versionchanged:: 3.5
|
2023-04-04 19:46:46 -03:00
|
|
|
The socket timeout is no longer reset each time data is sent successfully.
|
2015-04-06 18:16:34 -03:00
|
|
|
The socket timeout is now the maximum total duration to send all data.
|
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-09-14 00:32:35 -03:00
|
|
|
.. method:: socket.sendto(bytes, address)
|
|
|
|
socket.sendto(bytes, flags, address)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Send data to the socket. The socket should not be connected to a remote socket,
|
|
|
|
since the destination socket is specified by *address*. The optional *flags*
|
|
|
|
argument has the same meaning as for :meth:`recv` above. Return the number of
|
|
|
|
bytes sent. (The format of *address* depends on the address family --- see
|
|
|
|
above.)
|
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.sendto self,address socket.socket.sendto
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-08-21 22:55:57 -03:00
|
|
|
.. method:: socket.sendmsg(buffers[, ancdata[, flags[, address]]])
|
|
|
|
|
|
|
|
Send normal and ancillary data to the socket, gathering the
|
|
|
|
non-ancillary data from a series of buffers and concatenating it
|
|
|
|
into a single message. The *buffers* argument specifies the
|
2014-12-05 16:25:22 -04:00
|
|
|
non-ancillary data as an iterable of
|
|
|
|
:term:`bytes-like objects <bytes-like object>`
|
2011-08-21 22:55:57 -03:00
|
|
|
(e.g. :class:`bytes` objects); the operating system may set a limit
|
|
|
|
(:func:`~os.sysconf` value ``SC_IOV_MAX``) on the number of buffers
|
|
|
|
that can be used. The *ancdata* argument specifies the ancillary
|
|
|
|
data (control messages) as an iterable of zero or more tuples
|
|
|
|
``(cmsg_level, cmsg_type, cmsg_data)``, where *cmsg_level* and
|
|
|
|
*cmsg_type* are integers specifying the protocol level and
|
|
|
|
protocol-specific type respectively, and *cmsg_data* is a
|
2014-12-05 16:25:22 -04:00
|
|
|
bytes-like object holding the associated data. Note that
|
2011-08-21 22:55:57 -03:00
|
|
|
some systems (in particular, systems without :func:`CMSG_SPACE`)
|
|
|
|
might support sending only one control message per call. The
|
|
|
|
*flags* argument defaults to 0 and has the same meaning as for
|
|
|
|
:meth:`send`. If *address* is supplied and not ``None``, it sets a
|
|
|
|
destination address for the message. The return value is the
|
|
|
|
number of bytes of non-ancillary data sent.
|
|
|
|
|
|
|
|
The following function sends the list of file descriptors *fds*
|
|
|
|
over an :const:`AF_UNIX` socket, on systems which support the
|
|
|
|
:const:`SCM_RIGHTS` mechanism. See also :meth:`recvmsg`. ::
|
|
|
|
|
|
|
|
import socket, array
|
|
|
|
|
|
|
|
def send_fds(sock, msg, fds):
|
|
|
|
return sock.sendmsg([msg], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, array.array("i", fds))])
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: Unix, not WASI.
|
2022-07-29 11:42:09 -03:00
|
|
|
|
|
|
|
Most Unix platforms.
|
2011-08-21 22:55:57 -03:00
|
|
|
|
2019-06-27 14:47:59 -03:00
|
|
|
.. audit-event:: socket.sendmsg self,address socket.socket.sendmsg
|
2019-05-23 12:45:22 -03:00
|
|
|
|
2011-08-21 22:55:57 -03:00
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2015-04-02 06:49:42 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
If the system call is interrupted and the signal handler does not raise
|
|
|
|
an exception, the method now retries the system call instead of raising
|
|
|
|
an :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
|
|
|
|
|
2016-09-05 18:54:41 -03:00
|
|
|
.. method:: socket.sendmsg_afalg([msg], *, op[, iv[, assoclen[, flags]]])
|
|
|
|
|
|
|
|
Specialized version of :meth:`~socket.sendmsg` for :const:`AF_ALG` socket.
|
|
|
|
Set mode, IV, AEAD associated data length and flags for :const:`AF_ALG` socket.
|
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Linux >= 2.6.38.
|
2016-09-05 18:54:41 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.6
|
|
|
|
|
2014-06-10 22:54:30 -03:00
|
|
|
.. method:: socket.sendfile(file, offset=0, count=None)
|
|
|
|
|
|
|
|
Send a file until EOF is reached by using high-performance
|
|
|
|
:mod:`os.sendfile` and return the total number of bytes which were sent.
|
|
|
|
*file* must be a regular file object opened in binary mode. If
|
|
|
|
:mod:`os.sendfile` is not available (e.g. Windows) or *file* is not a
|
|
|
|
regular file :meth:`send` will be used instead. *offset* tells from where to
|
|
|
|
start reading the file. If specified, *count* is the total number of bytes
|
|
|
|
to transmit as opposed to sending the file until EOF is reached. File
|
|
|
|
position is updated on return or also in case of error in which case
|
|
|
|
:meth:`file.tell() <io.IOBase.tell>` can be used to figure out the number of
|
2017-01-14 04:24:20 -04:00
|
|
|
bytes which were sent. The socket must be of :const:`SOCK_STREAM` type.
|
|
|
|
Non-blocking sockets are not supported.
|
2014-06-10 22:54:30 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.5
|
2011-08-21 22:55:57 -03:00
|
|
|
|
2013-08-27 19:53:59 -03:00
|
|
|
.. method:: socket.set_inheritable(inheritable)
|
|
|
|
|
|
|
|
Set the :ref:`inheritable flag <fd_inheritance>` of the socket's file
|
|
|
|
descriptor or socket's handle.
|
|
|
|
|
|
|
|
.. versionadded:: 3.4
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: socket.setblocking(flag)
|
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
Set blocking or non-blocking mode of the socket: if *flag* is false, the
|
|
|
|
socket is set to non-blocking, else to blocking mode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
This method is a shorthand for certain :meth:`~socket.settimeout` calls:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
* ``sock.setblocking(True)`` is equivalent to ``sock.settimeout(None)``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
* ``sock.setblocking(False)`` is equivalent to ``sock.settimeout(0.0)``
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-12-18 21:02:54 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
The method no longer applies :const:`SOCK_NONBLOCK` flag on
|
|
|
|
:attr:`socket.type`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
.. method:: socket.settimeout(value)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
Set a timeout on blocking socket operations. The *value* argument can be a
|
|
|
|
nonnegative floating point number expressing seconds, or ``None``.
|
|
|
|
If a non-zero value is given, subsequent socket operations will raise a
|
|
|
|
:exc:`timeout` exception if the timeout period *value* has elapsed before
|
|
|
|
the operation has completed. If zero is given, the socket is put in
|
|
|
|
non-blocking mode. If ``None`` is given, the socket is put in blocking mode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
For further information, please consult the :ref:`notes on socket timeouts <socket-timeouts>`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-12-18 21:02:54 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
The method no longer toggles :const:`SOCK_NONBLOCK` flag on
|
|
|
|
:attr:`socket.type`.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-09-05 18:54:41 -03:00
|
|
|
.. method:: socket.setsockopt(level, optname, value: int)
|
|
|
|
.. method:: socket.setsockopt(level, optname, value: buffer)
|
2020-08-13 16:41:54 -03:00
|
|
|
:noindex:
|
2016-09-05 18:54:41 -03:00
|
|
|
.. method:: socket.setsockopt(level, optname, None, optlen: int)
|
2020-08-13 16:41:54 -03:00
|
|
|
:noindex:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2023-05-04 05:17:12 -03:00
|
|
|
.. index:: pair: module; struct
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Set the value of the given socket option (see the Unix manual page
|
2023-12-13 03:24:55 -04:00
|
|
|
:manpage:`setsockopt(2)`). The needed symbolic constants are defined in this
|
|
|
|
module (:ref:`!SO_\* etc. <socket-unix-constants>`). The value can be an integer,
|
2016-10-19 10:37:13 -03:00
|
|
|
``None`` or a :term:`bytes-like object` representing a buffer. In the later
|
2016-09-05 18:54:41 -03:00
|
|
|
case it is up to the caller to ensure that the bytestring contains the
|
|
|
|
proper bits (see the optional built-in module :mod:`struct` for a way to
|
2019-10-30 16:37:16 -03:00
|
|
|
encode C structures as bytestrings). When *value* is set to ``None``,
|
|
|
|
*optlen* argument is required. It's equivalent to call :c:func:`setsockopt` C
|
|
|
|
function with ``optval=NULL`` and ``optlen=optlen``.
|
2016-09-05 18:54:41 -03:00
|
|
|
|
2016-02-25 15:17:45 -04:00
|
|
|
.. versionchanged:: 3.5
|
2015-03-20 04:00:36 -03:00
|
|
|
Writable :term:`bytes-like object` is now accepted.
|
|
|
|
|
2016-09-05 18:54:41 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
setsockopt(level, optname, None, optlen: int) form added.
|
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: socket.shutdown(how)
|
|
|
|
|
|
|
|
Shut down one or both halves of the connection. If *how* is :const:`SHUT_RD`,
|
|
|
|
further receives are disallowed. If *how* is :const:`SHUT_WR`, further sends
|
|
|
|
are disallowed. If *how* is :const:`SHUT_RDWR`, further sends and receives are
|
2012-01-29 11:42:54 -04:00
|
|
|
disallowed.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2022-08-02 16:00:41 -03:00
|
|
|
.. availability:: not WASI.
|
|
|
|
|
2012-04-07 08:23:31 -03:00
|
|
|
|
|
|
|
.. method:: socket.share(process_id)
|
|
|
|
|
2013-12-04 16:11:03 -04:00
|
|
|
Duplicate a socket and prepare it for sharing with a target process. The
|
|
|
|
target process must be provided with *process_id*. The resulting bytes object
|
|
|
|
can then be passed to the target process using some form of interprocess
|
|
|
|
communication and the socket can be recreated there using :func:`fromshare`.
|
|
|
|
Once this method has been called, it is safe to close the socket since
|
|
|
|
the operating system has already duplicated it for the target process.
|
2012-04-07 08:23:31 -03:00
|
|
|
|
2018-10-12 11:55:20 -03:00
|
|
|
.. availability:: Windows.
|
2012-04-07 08:23:31 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
|
|
|
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line
Get rid of multi-row cells.
........
r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line
Remove LaTeXy index entry syntax.
........
r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Better cross-referencing in socket and winreg docs.
........
r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface.
........
r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Minor spelling changes to _winreg docs.
........
r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line
Fix code example to have valid syntax so that it can be highlighted.
........
r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric.
........
r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line
#8642: fix wrong function name.
........
r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line
Fix reference direction.
........
r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line
Consolidate deprecation messages.
........
r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line
Fix typo.
........
2010-05-19 17:57:08 -03:00
|
|
|
Note that there are no methods :meth:`read` or :meth:`write`; use
|
|
|
|
:meth:`~socket.recv` and :meth:`~socket.send` without *flags* argument instead.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Socket objects also have these (read-only) attributes that correspond to the
|
2016-12-02 17:13:53 -04:00
|
|
|
values given to the :class:`~socket.socket` constructor.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: socket.family
|
|
|
|
|
|
|
|
The socket family.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: socket.type
|
|
|
|
|
|
|
|
The socket type.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: socket.proto
|
|
|
|
|
|
|
|
The socket protocol.
|
|
|
|
|
|
|
|
|
2011-01-05 17:17:36 -04:00
|
|
|
|
|
|
|
.. _socket-timeouts:
|
|
|
|
|
|
|
|
Notes on socket timeouts
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
A socket object can be in one of three modes: blocking, non-blocking, or
|
|
|
|
timeout. Sockets are by default always created in blocking mode, but this
|
|
|
|
can be changed by calling :func:`setdefaulttimeout`.
|
|
|
|
|
|
|
|
* In *blocking mode*, operations block until complete or the system returns
|
|
|
|
an error (such as connection timed out).
|
|
|
|
|
|
|
|
* In *non-blocking mode*, operations fail (with an error that is unfortunately
|
|
|
|
system-dependent) if they cannot be completed immediately: functions from the
|
2023-04-04 19:46:46 -03:00
|
|
|
:mod:`select` module can be used to know when and whether a socket is available
|
|
|
|
for reading or writing.
|
2011-01-05 17:17:36 -04:00
|
|
|
|
|
|
|
* In *timeout mode*, operations fail if they cannot be completed within the
|
|
|
|
timeout specified for the socket (they raise a :exc:`timeout` exception)
|
|
|
|
or if the system returns an error.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
At the operating system level, sockets in *timeout mode* are internally set
|
|
|
|
in non-blocking mode. Also, the blocking and timeout modes are shared between
|
|
|
|
file descriptors and socket objects that refer to the same network endpoint.
|
|
|
|
This implementation detail can have visible consequences if e.g. you decide
|
|
|
|
to use the :meth:`~socket.fileno()` of a socket.
|
|
|
|
|
|
|
|
Timeouts and the ``connect`` method
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The :meth:`~socket.connect` operation is also subject to the timeout
|
|
|
|
setting, and in general it is recommended to call :meth:`~socket.settimeout`
|
|
|
|
before calling :meth:`~socket.connect` or pass a timeout parameter to
|
|
|
|
:meth:`create_connection`. However, the system network stack may also
|
|
|
|
return a connection timeout error of its own regardless of any Python socket
|
|
|
|
timeout setting.
|
|
|
|
|
|
|
|
Timeouts and the ``accept`` method
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
If :func:`getdefaulttimeout` is not :const:`None`, sockets returned by
|
|
|
|
the :meth:`~socket.accept` method inherit that timeout. Otherwise, the
|
|
|
|
behaviour depends on settings of the listening socket:
|
|
|
|
|
|
|
|
* if the listening socket is in *blocking mode* or in *timeout mode*,
|
|
|
|
the socket returned by :meth:`~socket.accept` is in *blocking mode*;
|
|
|
|
|
|
|
|
* if the listening socket is in *non-blocking mode*, whether the socket
|
|
|
|
returned by :meth:`~socket.accept` is in blocking or non-blocking mode
|
|
|
|
is operating system-dependent. If you want to ensure cross-platform
|
|
|
|
behaviour, it is recommended you manually override this setting.
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _socket-example:
|
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
|
|
|
|
Here are four minimal example programs using the TCP/IP protocol: a server that
|
|
|
|
echoes all data that it receives back (servicing only one client), and a client
|
2023-11-27 10:36:54 -04:00
|
|
|
using it. Note that a server must perform the sequence :func:`~socket.socket`,
|
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line
Get rid of multi-row cells.
........
r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line
Remove LaTeXy index entry syntax.
........
r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Better cross-referencing in socket and winreg docs.
........
r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface.
........
r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Minor spelling changes to _winreg docs.
........
r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line
Fix code example to have valid syntax so that it can be highlighted.
........
r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric.
........
r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line
#8642: fix wrong function name.
........
r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line
Fix reference direction.
........
r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line
Consolidate deprecation messages.
........
r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line
Fix typo.
........
2010-05-19 17:57:08 -03:00
|
|
|
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
|
|
|
|
repeating the :meth:`~socket.accept` to service more than one client), while a
|
2023-11-27 10:36:54 -04:00
|
|
|
client only needs the sequence :func:`~socket.socket`, :meth:`~socket.connect`. Also
|
2012-02-09 05:54:17 -04:00
|
|
|
note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
|
|
|
|
the socket it is listening on but on the new socket returned by
|
Merged revisions 80030,80067,80069,80080-80081,80084,80432-80433,80465-80470,81059,81065-81067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80030 | georg.brandl | 2010-04-13 08:43:54 +0200 (Di, 13 Apr 2010) | 1 line
Get rid of multi-row cells.
........
r80067 | georg.brandl | 2010-04-14 10:53:38 +0200 (Mi, 14 Apr 2010) | 1 line
#5341: typo.
........
r80069 | georg.brandl | 2010-04-14 15:50:31 +0200 (Mi, 14 Apr 2010) | 1 line
Add an x-ref to where the O_ constants are documented and move the SEEK_ constants after lseek().
........
r80080 | georg.brandl | 2010-04-14 21:16:38 +0200 (Mi, 14 Apr 2010) | 1 line
#8399: add note about Windows and O_BINARY.
........
r80081 | georg.brandl | 2010-04-14 23:34:44 +0200 (Mi, 14 Apr 2010) | 1 line
#5250: document __instancecheck__ and __subclasscheck__. I hope the part about the class/metaclass distinction is understandable.
........
r80084 | georg.brandl | 2010-04-14 23:46:45 +0200 (Mi, 14 Apr 2010) | 1 line
Fix missing.
........
r80432 | georg.brandl | 2010-04-24 10:56:58 +0200 (Sa, 24 Apr 2010) | 1 line
Markup fixes.
........
r80433 | georg.brandl | 2010-04-24 11:08:10 +0200 (Sa, 24 Apr 2010) | 1 line
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
........
r80465 | georg.brandl | 2010-04-25 12:29:17 +0200 (So, 25 Apr 2010) | 1 line
Remove LaTeXy index entry syntax.
........
r80466 | georg.brandl | 2010-04-25 12:54:42 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Better cross-referencing in socket and winreg docs.
........
r80467 | georg.brandl | 2010-04-25 12:55:16 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Remove reference to winreg being the fabled high-level registry interface.
........
r80468 | georg.brandl | 2010-04-25 12:55:58 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Minor spelling changes to _winreg docs.
........
r80469 | georg.brandl | 2010-04-25 12:56:41 +0200 (So, 25 Apr 2010) | 1 line
Fix code example to have valid syntax so that it can be highlighted.
........
r80470 | georg.brandl | 2010-04-25 12:57:15 +0200 (So, 25 Apr 2010) | 1 line
Patch from Tim Hatch: Make socket setblocking <-> settimeout examples symmetric.
........
r81059 | georg.brandl | 2010-05-10 23:02:51 +0200 (Mo, 10 Mai 2010) | 1 line
#8642: fix wrong function name.
........
r81065 | georg.brandl | 2010-05-10 23:46:50 +0200 (Mo, 10 Mai 2010) | 1 line
Fix reference direction.
........
r81066 | georg.brandl | 2010-05-10 23:50:57 +0200 (Mo, 10 Mai 2010) | 1 line
Consolidate deprecation messages.
........
r81067 | georg.brandl | 2010-05-10 23:51:33 +0200 (Mo, 10 Mai 2010) | 1 line
Fix typo.
........
2010-05-19 17:57:08 -03:00
|
|
|
:meth:`~socket.accept`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The first two examples support IPv4 only. ::
|
|
|
|
|
|
|
|
# Echo server program
|
|
|
|
import socket
|
|
|
|
|
Merged revisions 62425-62429,62434-62436,62441,62444,62446-62448,62450-62455,62463,62465-62466,62469,62474,62476-62478,62480,62485,62492,62497-62498,62500,62507,62513-62514,62516,62521,62531,62535,62545-62546,62548-62551,62553-62559,62569,62574,62577,62593,62595,62604-62606,62608,62616,62626-62627,62636,62638,62644-62645,62647-62648,62651-62653,62656,62661,62663,62680,62686-62687,62696,62699-62703,62711 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r62425 | andrew.kuchling | 2008-04-21 03:45:57 +0200 (Mon, 21 Apr 2008) | 1 line
Comment typo
................
r62426 | mark.dickinson | 2008-04-21 03:55:50 +0200 (Mon, 21 Apr 2008) | 2 lines
Silence 'r may be used uninitialized' compiler warning.
................
r62427 | andrew.kuchling | 2008-04-21 04:08:00 +0200 (Mon, 21 Apr 2008) | 1 line
Markup fix
................
r62428 | andrew.kuchling | 2008-04-21 04:08:13 +0200 (Mon, 21 Apr 2008) | 1 line
Wording changes
................
r62429 | andrew.kuchling | 2008-04-21 04:14:24 +0200 (Mon, 21 Apr 2008) | 1 line
Add various items
................
r62434 | thomas.heller | 2008-04-21 15:46:55 +0200 (Mon, 21 Apr 2008) | 1 line
Fix typo.
................
r62435 | david.goodger | 2008-04-21 16:40:22 +0200 (Mon, 21 Apr 2008) | 1 line
corrections ("reStructuredText" is one word)
................
r62436 | david.goodger | 2008-04-21 16:43:33 +0200 (Mon, 21 Apr 2008) | 1 line
capitalization
................
r62441 | gregory.p.smith | 2008-04-21 19:46:40 +0200 (Mon, 21 Apr 2008) | 2 lines
explicitly flush after the ... since there wasn't a newline
................
r62444 | jeroen.ruigrok | 2008-04-21 22:15:39 +0200 (Mon, 21 Apr 2008) | 2 lines
Windows x64 also falls under VER_PLATFORM_WIN32_NT.
................
r62446 | gregory.p.smith | 2008-04-21 23:31:08 +0200 (Mon, 21 Apr 2008) | 3 lines
If sys.stdin is not a tty, fall back to default_getpass after printing
a warning instead of failing with a termios.error.
................
r62447 | mark.dickinson | 2008-04-22 00:32:24 +0200 (Tue, 22 Apr 2008) | 8 lines
test_math and test_cmath are failing on the FreeBSD 6.2 trunk buildbot,
apparently because tanh(-0.) loses the sign of zero on that platform.
If true, this is a bug in FreeBSD.
Added a configure test to verify this. I still need to figure out
how best to deal with this failure.
................
r62448 | amaury.forgeotdarc | 2008-04-22 00:35:30 +0200 (Tue, 22 Apr 2008) | 7 lines
Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
It seems to work, but will fail at the first flush.
This causes IDLE to crash when too many warnings are printed.
Will backport.
................
r62450 | benjamin.peterson | 2008-04-22 00:57:00 +0200 (Tue, 22 Apr 2008) | 2 lines
Fix Sphinx warnings
................
r62451 | mark.dickinson | 2008-04-22 02:54:27 +0200 (Tue, 22 Apr 2008) | 3 lines
Make configure test for tanh(-0.) == -0. committed in r62447 actually
work. (The test wasn't properly linked with libm. Sigh.)
................
r62452 | benjamin.peterson | 2008-04-22 04:16:03 +0200 (Tue, 22 Apr 2008) | 2 lines
Various io doc updates
................
r62453 | neal.norwitz | 2008-04-22 07:07:47 +0200 (Tue, 22 Apr 2008) | 1 line
Add Thomas Lee
................
r62454 | gregory.p.smith | 2008-04-22 10:08:41 +0200 (Tue, 22 Apr 2008) | 8 lines
Major improvements:
* Default to using /dev/tty for the password prompt and input before
falling back to sys.stdin and sys.stderr.
* Use sys.stderr instead of sys.stdout.
* print the 'password may be echoed' warning to stream used to display
the prompt rather than always sys.stderr.
* warn() with GetPassWarning when input may be echoed.
................
r62455 | gregory.p.smith | 2008-04-22 10:11:33 +0200 (Tue, 22 Apr 2008) | 2 lines
update the getpass entry
................
r62463 | amaury.forgeotdarc | 2008-04-22 23:14:41 +0200 (Tue, 22 Apr 2008) | 5 lines
Issue #2670: urllib2.build_opener() failed when two handlers
derive the same default base class.
Will backport.
................
r62465 | skip.montanaro | 2008-04-23 00:45:09 +0200 (Wed, 23 Apr 2008) | 3 lines
Factor in documentation changes from issue 1753732.
................
r62466 | gregory.p.smith | 2008-04-23 03:06:42 +0200 (Wed, 23 Apr 2008) | 2 lines
syntax fixup
................
r62469 | benjamin.peterson | 2008-04-23 22:38:06 +0200 (Wed, 23 Apr 2008) | 2 lines
#2673 Fix example typo in optparse docs
................
r62474 | martin.v.loewis | 2008-04-24 11:50:50 +0200 (Thu, 24 Apr 2008) | 2 lines
Add Guilherme Polo.
................
r62476 | martin.v.loewis | 2008-04-24 15:16:36 +0200 (Thu, 24 Apr 2008) | 3 lines
Remove Py_Refcnt, Py_Type, Py_Size, as they were added only
for backwards compatibility, yet 2.5 did not have them at all.
................
r62477 | martin.v.loewis | 2008-04-24 15:17:24 +0200 (Thu, 24 Apr 2008) | 2 lines
Fix typo.
................
r62478 | martin.v.loewis | 2008-04-24 15:18:03 +0200 (Thu, 24 Apr 2008) | 2 lines
Add Jesus Cea.
................
r62480 | amaury.forgeotdarc | 2008-04-24 20:07:05 +0200 (Thu, 24 Apr 2008) | 4 lines
Issue2681: the literal 0o8 was wrongly accepted, and evaluated as float(0.0).
This happened only when 8 is the first digit.
Credits go to Lukas Meuser.
................
r62485 | amaury.forgeotdarc | 2008-04-24 22:10:26 +0200 (Thu, 24 Apr 2008) | 5 lines
Disable gc when running test_trace, or we may record the __del__ of collected objects.
See http://mail.python.org/pipermail/python-checkins/2008-April/068633.html
the extra events perfectly match several calls to socket._fileobject.__del__()
................
r62492 | neal.norwitz | 2008-04-25 05:40:17 +0200 (Fri, 25 Apr 2008) | 1 line
Fix typo (now -> no)
................
r62497 | armin.rigo | 2008-04-25 11:35:18 +0200 (Fri, 25 Apr 2008) | 2 lines
A new crasher.
................
r62498 | thomas.heller | 2008-04-25 17:44:16 +0200 (Fri, 25 Apr 2008) | 1 line
Add from_buffer and from_buffer_copy class methods to ctypes types.
................
r62500 | mark.dickinson | 2008-04-25 18:59:09 +0200 (Fri, 25 Apr 2008) | 3 lines
Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
................
r62507 | benjamin.peterson | 2008-04-25 23:43:56 +0200 (Fri, 25 Apr 2008) | 2 lines
Allow test_import to work when it is invoked directly
................
r62513 | georg.brandl | 2008-04-26 20:31:07 +0200 (Sat, 26 Apr 2008) | 2 lines
#2691: document PyLong (s)size_t APIs, patch by Alexander Belopolsky.
................
r62514 | georg.brandl | 2008-04-26 20:32:17 +0200 (Sat, 26 Apr 2008) | 2 lines
Add missing return type to dealloc.
................
r62516 | alexandre.vassalotti | 2008-04-27 02:52:24 +0200 (Sun, 27 Apr 2008) | 2 lines
Fixed URL of PEP 205 in weakref's module docstring.
................
r62521 | georg.brandl | 2008-04-27 11:39:59 +0200 (Sun, 27 Apr 2008) | 2 lines
#2677: add note that not all functions may accept keyword args.
................
r62531 | georg.brandl | 2008-04-27 19:38:55 +0200 (Sun, 27 Apr 2008) | 2 lines
Use correct XHTML tags.
................
r62535 | benjamin.peterson | 2008-04-27 20:14:39 +0200 (Sun, 27 Apr 2008) | 2 lines
#2700 Document PyNumber_ToBase
................
r62545 | skip.montanaro | 2008-04-27 22:53:57 +0200 (Sun, 27 Apr 2008) | 1 line
minor wording changes, rewrap a few lines
................
r62546 | kurt.kaiser | 2008-04-27 23:07:41 +0200 (Sun, 27 Apr 2008) | 7 lines
Home / Control-A toggles between left margin and end of leading white
space. Patch 1196903 Jeff Shute.
M idlelib/PyShell.py
M idlelib/EditorWindow.py
M idlelib/NEWS.txt
................
r62548 | kurt.kaiser | 2008-04-27 23:38:05 +0200 (Sun, 27 Apr 2008) | 2 lines
Improved AutoCompleteWindow logic. Patch 2062 Tal Einat.
................
r62549 | kurt.kaiser | 2008-04-27 23:52:19 +0200 (Sun, 27 Apr 2008) | 4 lines
Autocompletion of filenames now support alternate separators, e.g. the
'/' char on Windows. Patch 2061 Tal Einat.
................
r62550 | skip.montanaro | 2008-04-28 00:49:56 +0200 (Mon, 28 Apr 2008) | 6 lines
A few small changes:
* The only exception we should catch when trying to import cStringIO is an
ImportError.
* Delete the function signatures embedded in the mk*temp docstrings.
* The tempdir global variable was initialized twice.
................
r62551 | skip.montanaro | 2008-04-28 00:52:02 +0200 (Mon, 28 Apr 2008) | 4 lines
Wrap some long paragraphs and include the default values for optional
function parameters.
................
r62553 | skip.montanaro | 2008-04-28 04:57:23 +0200 (Mon, 28 Apr 2008) | 7 lines
Minor cleanups:
* Avoid creating unused local variables where we can. Where we can't prefix
the unused variables with '_'.
* Avoid shadowing builtins where it won't change the external interface of a
function.
* Use None as default path arg to readmodule and readmodule_ex.
................
r62554 | skip.montanaro | 2008-04-28 04:59:45 +0200 (Mon, 28 Apr 2008) | 6 lines
Correct documentation to match implementation: "Class" instead of
"class_descriptor", "Function" instead of "function_descriptor". Note
default path value for readmodule*. Wrap some long paragraphs. Don't
mention 'inpackage' which isn't part of the public API.
................
r62555 | brett.cannon | 2008-04-28 05:23:50 +0200 (Mon, 28 Apr 2008) | 5 lines
Fix a bug introduced by the warnings rewrite where tracebacks were being
improperly indented.
Closes issue #2699.
................
r62556 | skip.montanaro | 2008-04-28 05:25:37 +0200 (Mon, 28 Apr 2008) | 2 lines
Wrap some long lines.
................
r62557 | skip.montanaro | 2008-04-28 05:27:53 +0200 (Mon, 28 Apr 2008) | 6 lines
Get rid of _test(), _main(), _debug() and _check(). Tests are no longer
needed (better set available in Lib/test/test_robotparser.py). Clean up a
few PEP 8 nits (compound statements on a single line, whitespace around
operators).
................
r62558 | brett.cannon | 2008-04-28 06:50:06 +0200 (Mon, 28 Apr 2008) | 3 lines
Rename the test_traceback_print() function to traceback_print() to prevent
test_capi from automatically calling the function.
................
r62559 | georg.brandl | 2008-04-28 07:16:30 +0200 (Mon, 28 Apr 2008) | 2 lines
Fix markup.
................
r62569 | amaury.forgeotdarc | 2008-04-28 23:07:06 +0200 (Mon, 28 Apr 2008) | 5 lines
test_sundry performs minimal tests (a simple import...) on modules that are not tested otherwise.
Some of them now have tests and can be removed.
Only 70 to go...
................
r62574 | andrew.kuchling | 2008-04-29 04:03:54 +0200 (Tue, 29 Apr 2008) | 1 line
Strip down SSL docs; I'm not managing to get test programs working, so I'll just give a minimal description
................
r62577 | martin.v.loewis | 2008-04-29 08:10:53 +0200 (Tue, 29 Apr 2008) | 2 lines
Add Rodrigo and Heiko.
................
r62593 | nick.coghlan | 2008-04-30 16:23:36 +0200 (Wed, 30 Apr 2008) | 1 line
Update command line usage documentation to reflect 2.6 changes (also includes some minor cleanups). Addresses TODO list issue 2258
................
r62595 | andrew.kuchling | 2008-04-30 18:19:55 +0200 (Wed, 30 Apr 2008) | 1 line
Typo fix
................
r62604 | benjamin.peterson | 2008-04-30 23:03:58 +0200 (Wed, 30 Apr 2008) | 2 lines
make test_support's captured_output a bit more robust when exceptions happen
................
r62605 | georg.brandl | 2008-04-30 23:08:42 +0200 (Wed, 30 Apr 2008) | 2 lines
#1748: use functools.wraps instead of rolling own metadata update.
................
r62606 | benjamin.peterson | 2008-04-30 23:25:55 +0200 (Wed, 30 Apr 2008) | 2 lines
Remove some from __future__ import with_statements
................
r62608 | benjamin.peterson | 2008-05-01 00:03:36 +0200 (Thu, 01 May 2008) | 2 lines
Fix typo in whatsnew
................
r62616 | georg.brandl | 2008-05-01 20:24:32 +0200 (Thu, 01 May 2008) | 2 lines
Fix synopsis.
................
r62626 | brett.cannon | 2008-05-02 04:25:09 +0200 (Fri, 02 May 2008) | 6 lines
Fix a backwards-compatibility mistake where a new optional argument for
warnings.showwarning() was being used. This broke pre-existing replacements for
the function since they didn't support the extra argument.
Closes issue 2705.
................
r62627 | gregory.p.smith | 2008-05-02 09:26:52 +0200 (Fri, 02 May 2008) | 20 lines
This should fix issue2632. A long description of the two competing
problems is in the bug report (one old, one recently introduced trying
to fix the old one). In short:
buffer data during socket._fileobject.read() and readlines() within a
cStringIO object instead of a [] of str()s returned from the recv()
call.
This prevents excessive memory use due to the size parameter being
passed to recv() being grossly larger than the actual size of the data
returned *and* prevents excessive cpu usage due to looping in python
calling recv() with a very tiny size value if min() is used as the
previous memory-use bug "fix" did.
It also documents what the socket._fileobject._rbufsize member is
actually used for.
This is a candidate for back porting to 2.5.
................
r62636 | mark.hammond | 2008-05-02 14:48:15 +0200 (Fri, 02 May 2008) | 2 lines
#2581: Vista UAC/elevation support for bdist_wininst
................
r62638 | facundo.batista | 2008-05-02 19:39:00 +0200 (Fri, 02 May 2008) | 3 lines
Fixed some test structures. Thanks Mark Dickinson.
................
r62644 | ronald.oussoren | 2008-05-02 21:45:11 +0200 (Fri, 02 May 2008) | 7 lines
Fix for issue #2573: Can't change the framework name on OS X builds
This introduces a new configure option: --with-framework-name=NAME
(defaulting to 'Python'). This allows you to install several copies
of the Python framework with different names (such as a normal build
and a debug build).
................
r62645 | ronald.oussoren | 2008-05-02 21:58:56 +0200 (Fri, 02 May 2008) | 2 lines
Finish fix for issue2573, previous patch was incomplete.
................
r62647 | martin.v.loewis | 2008-05-02 23:30:20 +0200 (Fri, 02 May 2008) | 13 lines
Merged revisions 62263-62646 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r62470 | david.wolever | 2008-04-24 02:11:07 +0200 (Do, 24 Apr 2008) | 3 lines
Fixed up and applied the patch for #2431 -- speeding up 2to3 with a lookup table.
........
r62646 | martin.v.loewis | 2008-05-02 23:29:27 +0200 (Fr, 02 Mai 2008) | 2 lines
Fix whitespace.
........
................
r62648 | ronald.oussoren | 2008-05-02 23:42:35 +0200 (Fri, 02 May 2008) | 4 lines
Fix for #1905: PythonLauncher not working correctly on OSX 10.5/Leopard
This fixes both Python Launchar and the terminalcommand module.
................
r62651 | ronald.oussoren | 2008-05-02 23:54:56 +0200 (Fri, 02 May 2008) | 2 lines
Fix for issue #2520 (cannot import macerrors)
................
r62652 | benjamin.peterson | 2008-05-03 00:12:58 +0200 (Sat, 03 May 2008) | 2 lines
capitalization nit for reStructuredText
................
r62653 | brett.cannon | 2008-05-03 03:02:41 +0200 (Sat, 03 May 2008) | 2 lines
Fix some indentation errors.
................
r62656 | brett.cannon | 2008-05-03 05:19:39 +0200 (Sat, 03 May 2008) | 6 lines
Fix the C implementation of 'warnings' to infer the filename of the module that
raised an exception properly when __file__ is not set, __name__ == '__main__',
and sys.argv[0] is a false value.
Closes issue2743.
................
r62661 | amaury.forgeotdarc | 2008-05-03 14:21:13 +0200 (Sat, 03 May 2008) | 8 lines
In test_io, StatefulIncrementalDecoderTest was not part of the test suite.
And of course, the test failed:
a bytearray was used without reason in io.TextIOWrapper.tell().
The difference is that iterating over bytes (i.e. str in python2.6) returns 1-char bytes,
whereas bytearrays yield integers.
This code should still work with python3.0
................
r62663 | benjamin.peterson | 2008-05-03 17:56:42 +0200 (Sat, 03 May 2008) | 2 lines
The compiling struct is now passed around to all AST helpers (see issue 2720)
................
r62680 | benjamin.peterson | 2008-05-03 23:35:18 +0200 (Sat, 03 May 2008) | 2 lines
Moved testing of builtin types out of test_builtin and into type specific modules
................
r62686 | mark.dickinson | 2008-05-04 04:25:46 +0200 (Sun, 04 May 2008) | 4 lines
Make sure that Context traps and flags dictionaries have values 0 and 1
(as documented) rather than True and False.
................
r62687 | benjamin.peterson | 2008-05-04 05:05:49 +0200 (Sun, 04 May 2008) | 2 lines
Fix typo in whatsnew
................
r62696 | georg.brandl | 2008-05-04 11:15:04 +0200 (Sun, 04 May 2008) | 2 lines
#2752: wrong meaning of '' for socket host.
................
r62699 | christian.heimes | 2008-05-04 13:50:53 +0200 (Sun, 04 May 2008) | 1 line
Added note that Python requires at least Win2k SP4
................
r62700 | gerhard.haering | 2008-05-04 14:59:57 +0200 (Sun, 04 May 2008) | 3 lines
SQLite requires 64-bit integers in order to build. So the whole HAVE_LONG_LONG
#ifdefing was useless.
................
r62701 | gerhard.haering | 2008-05-04 15:15:12 +0200 (Sun, 04 May 2008) | 3 lines
Applied sqliterow-richcmp.diff patch from Thomas Heller in Issue2152. The
sqlite3.Row type is now correctly hashable.
................
r62702 | gerhard.haering | 2008-05-04 15:42:44 +0200 (Sun, 04 May 2008) | 5 lines
Implemented feature request 2157: Converter names are cut off at '('
characters. This avoids the common case of something like 'NUMBER(10)' not
being parsed as 'NUMBER', like expected. Also corrected the docs about
converter names being case-sensitive. They aren't any longer.
................
r62703 | georg.brandl | 2008-05-04 17:45:05 +0200 (Sun, 04 May 2008) | 2 lines
#2757: Remove spare newline.
................
r62711 | benjamin.peterson | 2008-05-04 21:10:02 +0200 (Sun, 04 May 2008) | 2 lines
Fix typo in bugs.rst
................
2008-05-04 19:42:01 -03:00
|
|
|
HOST = '' # Symbolic name meaning all available interfaces
|
2007-08-15 11:28:22 -03:00
|
|
|
PORT = 50007 # Arbitrary non-privileged port
|
2016-04-24 01:24:36 -03:00
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
|
|
s.bind((HOST, PORT))
|
|
|
|
s.listen(1)
|
|
|
|
conn, addr = s.accept()
|
|
|
|
with conn:
|
|
|
|
print('Connected by', addr)
|
|
|
|
while True:
|
|
|
|
data = conn.recv(1024)
|
|
|
|
if not data: break
|
|
|
|
conn.sendall(data)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
# Echo client program
|
|
|
|
import socket
|
|
|
|
|
|
|
|
HOST = 'daring.cwi.nl' # The remote host
|
|
|
|
PORT = 50007 # The same port as used by the server
|
2016-04-24 01:24:36 -03:00
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
|
|
s.connect((HOST, PORT))
|
|
|
|
s.sendall(b'Hello, world')
|
|
|
|
data = s.recv(1024)
|
2007-09-04 04:15:32 -03:00
|
|
|
print('Received', repr(data))
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The next two examples are identical to the above two, but support both IPv4 and
|
|
|
|
IPv6. The server side will listen to the first address family available (it
|
|
|
|
should listen to both instead). On most of IPv6-ready systems, IPv6 will take
|
|
|
|
precedence and the server may not accept IPv4 traffic. The client side will try
|
2023-10-05 16:55:44 -03:00
|
|
|
to connect to all the addresses returned as a result of the name resolution, and
|
2007-08-15 11:28:22 -03:00
|
|
|
sends traffic to the first one connected successfully. ::
|
|
|
|
|
|
|
|
# Echo server program
|
|
|
|
import socket
|
|
|
|
import sys
|
|
|
|
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
HOST = None # Symbolic name meaning all available interfaces
|
2007-08-15 11:28:22 -03:00
|
|
|
PORT = 50007 # Arbitrary non-privileged port
|
|
|
|
s = None
|
2008-08-14 08:50:32 -03:00
|
|
|
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
|
|
|
|
socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
|
2007-08-15 11:28:22 -03:00
|
|
|
af, socktype, proto, canonname, sa = res
|
|
|
|
try:
|
2009-01-03 17:26:05 -04:00
|
|
|
s = socket.socket(af, socktype, proto)
|
2011-10-12 12:53:43 -03:00
|
|
|
except OSError as msg:
|
2009-01-03 17:26:05 -04:00
|
|
|
s = None
|
|
|
|
continue
|
2007-08-15 11:28:22 -03:00
|
|
|
try:
|
2009-01-03 17:26:05 -04:00
|
|
|
s.bind(sa)
|
|
|
|
s.listen(1)
|
2011-10-12 12:53:43 -03:00
|
|
|
except OSError as msg:
|
2009-01-03 17:26:05 -04:00
|
|
|
s.close()
|
|
|
|
s = None
|
|
|
|
continue
|
2007-08-15 11:28:22 -03:00
|
|
|
break
|
|
|
|
if s is None:
|
2007-09-04 04:15:32 -03:00
|
|
|
print('could not open socket')
|
2007-08-15 11:28:22 -03:00
|
|
|
sys.exit(1)
|
|
|
|
conn, addr = s.accept()
|
2016-04-24 01:24:36 -03:00
|
|
|
with conn:
|
|
|
|
print('Connected by', addr)
|
|
|
|
while True:
|
|
|
|
data = conn.recv(1024)
|
|
|
|
if not data: break
|
|
|
|
conn.send(data)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
# Echo client program
|
|
|
|
import socket
|
|
|
|
import sys
|
|
|
|
|
|
|
|
HOST = 'daring.cwi.nl' # The remote host
|
|
|
|
PORT = 50007 # The same port as used by the server
|
|
|
|
s = None
|
|
|
|
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM):
|
|
|
|
af, socktype, proto, canonname, sa = res
|
|
|
|
try:
|
2009-01-03 17:26:05 -04:00
|
|
|
s = socket.socket(af, socktype, proto)
|
2011-10-12 12:53:43 -03:00
|
|
|
except OSError as msg:
|
2009-01-03 17:26:05 -04:00
|
|
|
s = None
|
|
|
|
continue
|
2007-08-15 11:28:22 -03:00
|
|
|
try:
|
2009-01-03 17:26:05 -04:00
|
|
|
s.connect(sa)
|
2011-10-12 12:53:43 -03:00
|
|
|
except OSError as msg:
|
2009-01-03 17:26:05 -04:00
|
|
|
s.close()
|
|
|
|
s = None
|
|
|
|
continue
|
2007-08-15 11:28:22 -03:00
|
|
|
break
|
|
|
|
if s is None:
|
2007-09-04 04:15:32 -03:00
|
|
|
print('could not open socket')
|
2007-08-15 11:28:22 -03:00
|
|
|
sys.exit(1)
|
2016-04-24 01:24:36 -03:00
|
|
|
with s:
|
|
|
|
s.sendall(b'Hello, world')
|
|
|
|
data = s.recv(1024)
|
2007-09-04 04:15:32 -03:00
|
|
|
print('Received', repr(data))
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-06 14:47:44 -03:00
|
|
|
The next example shows how to write a very simple network sniffer with raw
|
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r62998 | andrew.kuchling | 2008-05-10 15:51:55 -0400 (Sat, 10 May 2008) | 7 lines
#1858 from Tarek Ziade:
Allow multiple repositories in .pypirc; see http://wiki.python.org/moin/EnhancedPyPI
for discussion.
The patch is slightly revised from Tarek's last patch: I've simplified
the PyPIRCCommand.finalize_options() method to not look at sys.argv.
Tests still pass.
........
r63000 | alexandre.vassalotti | 2008-05-10 15:59:16 -0400 (Sat, 10 May 2008) | 5 lines
Cleaned up io._BytesIO.write().
I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
........
r63002 | brett.cannon | 2008-05-10 16:52:01 -0400 (Sat, 10 May 2008) | 2 lines
Revert r62998 as it broke the build (seems distutils.config is missing).
........
r63014 | andrew.kuchling | 2008-05-10 18:12:38 -0400 (Sat, 10 May 2008) | 1 line
#1858: add distutils.config module
........
r63027 | brett.cannon | 2008-05-10 21:09:32 -0400 (Sat, 10 May 2008) | 2 lines
Flesh out the 3.0 deprecation to suggest using the ctypes module.
........
r63028 | skip.montanaro | 2008-05-10 22:59:30 -0400 (Sat, 10 May 2008) | 4 lines
Copied two versions of the example from the interactive session. Delete
one.
........
r63037 | georg.brandl | 2008-05-11 03:02:17 -0400 (Sun, 11 May 2008) | 2 lines
reload() takes the module itself.
........
r63038 | alexandre.vassalotti | 2008-05-11 03:06:04 -0400 (Sun, 11 May 2008) | 4 lines
Added test framework for handling module renames.
Factored the import guard in test_py3kwarn.TestStdlibRemovals into
a context manager, namely test_support.CleanImport.
........
r63039 | georg.brandl | 2008-05-11 03:06:05 -0400 (Sun, 11 May 2008) | 2 lines
#2742: ``''`` is not converted to NULL in getaddrinfo.
........
r63040 | alexandre.vassalotti | 2008-05-11 03:08:12 -0400 (Sun, 11 May 2008) | 2 lines
Fixed typo in a comment of test_support.CleanImport.
........
r63041 | alexandre.vassalotti | 2008-05-11 03:10:25 -0400 (Sun, 11 May 2008) | 2 lines
Removed a dead line of code.
........
r63043 | georg.brandl | 2008-05-11 04:47:53 -0400 (Sun, 11 May 2008) | 2 lines
#2812: document property.getter/setter/deleter.
........
r63049 | georg.brandl | 2008-05-11 05:06:30 -0400 (Sun, 11 May 2008) | 2 lines
#1153769: document PEP 237 changes to string formatting.
........
r63050 | georg.brandl | 2008-05-11 05:11:40 -0400 (Sun, 11 May 2008) | 2 lines
#2809: elaborate str.split docstring a bit.
........
r63051 | georg.brandl | 2008-05-11 06:13:59 -0400 (Sun, 11 May 2008) | 2 lines
Fix typo.
........
r63052 | georg.brandl | 2008-05-11 06:33:27 -0400 (Sun, 11 May 2008) | 2 lines
#2709: clarification.
........
r63053 | georg.brandl | 2008-05-11 06:42:28 -0400 (Sun, 11 May 2008) | 2 lines
#2659: add ``break_on_hyphens`` to TextWrapper.
........
r63057 | georg.brandl | 2008-05-11 06:59:39 -0400 (Sun, 11 May 2008) | 2 lines
#2741: clarification of value range for address_family.
........
r63058 | georg.brandl | 2008-05-11 07:09:35 -0400 (Sun, 11 May 2008) | 2 lines
#2452: timeout is used for all blocking operations.
........
r63059 | andrew.kuchling | 2008-05-11 09:33:56 -0400 (Sun, 11 May 2008) | 2 lines
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.
........
r63060 | andrew.kuchling | 2008-05-11 10:00:00 -0400 (Sun, 11 May 2008) | 1 line
#1858: re-apply patch for this, adding the missing files
........
r63061 | benjamin.peterson | 2008-05-11 10:13:25 -0400 (Sun, 11 May 2008) | 2 lines
Add the "until" command to pdb
........
r63062 | georg.brandl | 2008-05-11 10:17:13 -0400 (Sun, 11 May 2008) | 2 lines
Add some sentence endings.
........
2008-05-15 21:03:33 -03:00
|
|
|
sockets on Windows. The example requires administrator privileges to modify
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
the interface::
|
|
|
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
# the public network interface
|
|
|
|
HOST = socket.gethostbyname(socket.gethostname())
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
# create a raw socket and bind it to the public interface
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
|
|
|
|
s.bind((HOST, 0))
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
# Include IP headers
|
|
|
|
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2022-06-15 05:36:37 -03:00
|
|
|
# receive all packets
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
|
2009-01-03 17:18:54 -04:00
|
|
|
|
2022-06-15 05:36:37 -03:00
|
|
|
# receive a packet
|
2008-05-13 01:55:24 -03:00
|
|
|
print(s.recvfrom(65565))
|
2009-01-03 17:18:54 -04:00
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
# disabled promiscuous mode
|
Merged revisions 59703-59773 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59704 | christian.heimes | 2008-01-04 04:15:05 +0100 (Fri, 04 Jan 2008) | 1 line
Moved include "Python.h" in front of other imports to silence a warning.
........
r59706 | raymond.hettinger | 2008-01-04 04:22:53 +0100 (Fri, 04 Jan 2008) | 10 lines
Minor fix-ups to named tuples:
* Make the _replace() method respect subclassing.
* Using property() to make _fields read-only wasn't a good idea.
It caused len(Point._fields) to fail.
* Add note to _cast() about length checking and alternative with the star-operator.
........
r59707 | jeffrey.yasskin | 2008-01-04 09:01:23 +0100 (Fri, 04 Jan 2008) | 3 lines
Make math.{floor,ceil}({int,long}) return float again for backwards
compatibility after r59671 made them return integral types.
........
r59709 | christian.heimes | 2008-01-04 14:21:07 +0100 (Fri, 04 Jan 2008) | 1 line
Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
........
r59712 | lars.gustaebel | 2008-01-04 15:00:33 +0100 (Fri, 04 Jan 2008) | 5 lines
Issue #1735: TarFile.extractall() now correctly sets
directory permissions and times.
(will backport to 2.5)
........
r59714 | andrew.kuchling | 2008-01-04 15:47:17 +0100 (Fri, 04 Jan 2008) | 1 line
Update links to bug/patch tracker
........
r59716 | christian.heimes | 2008-01-04 16:23:30 +0100 (Fri, 04 Jan 2008) | 1 line
Added interface to Windows' WSAIoctl and a simple example for a network sniffer.
........
r59717 | christian.heimes | 2008-01-04 16:29:00 +0100 (Fri, 04 Jan 2008) | 1 line
And here is the rest of Hirokazu Yamamoto's patch for VS6.0 support. Thanks Hiro!
........
r59719 | christian.heimes | 2008-01-04 16:34:06 +0100 (Fri, 04 Jan 2008) | 1 line
Reverted last transaction. It's the wrong branch.
........
r59721 | christian.heimes | 2008-01-04 16:48:06 +0100 (Fri, 04 Jan 2008) | 1 line
socket.ioctl is only available on Windows
........
r59722 | andrew.kuchling | 2008-01-04 19:24:41 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59723 | andrew.kuchling | 2008-01-04 19:25:05 +0100 (Fri, 04 Jan 2008) | 1 line
Fix markup
........
r59725 | guido.van.rossum | 2008-01-05 01:59:59 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
and adds errors for -0x.
........
r59726 | guido.van.rossum | 2008-01-05 02:21:57 +0100 (Sat, 05 Jan 2008) | 2 lines
Patch #1698 by Senthil: allow '@' in username when parsed by urlparse.py.
........
r59727 | raymond.hettinger | 2008-01-05 02:35:43 +0100 (Sat, 05 Jan 2008) | 1 line
Improve namedtuple's _cast() method with a docstring, new name, and error-checking.
........
r59728 | raymond.hettinger | 2008-01-05 03:17:24 +0100 (Sat, 05 Jan 2008) | 1 line
Add error-checking to namedtuple's _replace() method.
........
r59730 | fred.drake | 2008-01-05 05:38:38 +0100 (Sat, 05 Jan 2008) | 2 lines
clean up a comment
........
r59731 | jeffrey.yasskin | 2008-01-05 09:47:13 +0100 (Sat, 05 Jan 2008) | 11 lines
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
round included:
* Revert round to its 2.6 behavior (half away from 0).
* Because round, floor, and ceil always return float again, it's no
longer necessary to have them delegate to __xxx___, so I've ripped
that out of their implementations and the Real ABC. This also helps
in implementing types that work in both 2.6 and 3.0: you return int
from the __xxx__ methods, and let it get enabled by the version
upgrade.
* Make pow(-1, .5) raise a ValueError again.
........
r59736 | andrew.kuchling | 2008-01-05 16:13:49 +0100 (Sat, 05 Jan 2008) | 1 line
Fix comment typo
........
r59738 | thomas.heller | 2008-01-05 18:15:44 +0100 (Sat, 05 Jan 2008) | 1 line
Add myself.
........
r59739 | georg.brandl | 2008-01-05 18:49:17 +0100 (Sat, 05 Jan 2008) | 2 lines
Fix C++-style comment.
........
r59742 | georg.brandl | 2008-01-05 20:28:16 +0100 (Sat, 05 Jan 2008) | 2 lines
Remove with_statement future imports from 2.6 docs.
........
r59743 | georg.brandl | 2008-01-05 20:29:45 +0100 (Sat, 05 Jan 2008) | 2 lines
Simplify index entries; fix #1712.
........
r59744 | georg.brandl | 2008-01-05 20:44:22 +0100 (Sat, 05 Jan 2008) | 2 lines
Doc patch #1730 from Robin Stocker; minor corrections mostly to os.rst.
........
r59749 | georg.brandl | 2008-01-05 21:29:13 +0100 (Sat, 05 Jan 2008) | 2 lines
Revert socket.rst to unix-eol.
........
r59750 | georg.brandl | 2008-01-05 21:33:46 +0100 (Sat, 05 Jan 2008) | 2 lines
Set native svn:eol-style property for text files.
........
r59752 | georg.brandl | 2008-01-05 21:46:29 +0100 (Sat, 05 Jan 2008) | 2 lines
#1719: capitalization error in "UuidCreate".
........
r59753 | georg.brandl | 2008-01-05 22:02:25 +0100 (Sat, 05 Jan 2008) | 2 lines
Repair markup.
........
r59754 | georg.brandl | 2008-01-05 22:10:50 +0100 (Sat, 05 Jan 2008) | 2 lines
Use markup.
........
r59757 | christian.heimes | 2008-01-05 22:35:52 +0100 (Sat, 05 Jan 2008) | 1 line
Final adjustments for #1601
........
r59758 | guido.van.rossum | 2008-01-05 23:19:06 +0100 (Sat, 05 Jan 2008) | 3 lines
Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
Fix by John Nagle.
........
r59759 | guido.van.rossum | 2008-01-05 23:20:01 +0100 (Sat, 05 Jan 2008) | 2 lines
Add John Nagle (of issue #1637).
........
r59765 | raymond.hettinger | 2008-01-06 10:02:24 +0100 (Sun, 06 Jan 2008) | 1 line
Small code simplification. Forgot that classmethods can be called from intances.
........
r59766 | martin.v.loewis | 2008-01-06 11:09:48 +0100 (Sun, 06 Jan 2008) | 2 lines
Use vcbuild for VS 2009.
........
r59767 | martin.v.loewis | 2008-01-06 12:03:43 +0100 (Sun, 06 Jan 2008) | 2 lines
Package using VS 2008.
........
r59768 | martin.v.loewis | 2008-01-06 12:13:16 +0100 (Sun, 06 Jan 2008) | 2 lines
Don't try to package msvcr90 for the moment.
........
r59769 | georg.brandl | 2008-01-06 15:17:36 +0100 (Sun, 06 Jan 2008) | 4 lines
#1696393: don't check for '.' and '..' in ntpath.walk since
they aren't returned from os.listdir anymore.
Reported by Michael Haggerty.
........
r59770 | georg.brandl | 2008-01-06 15:27:15 +0100 (Sun, 06 Jan 2008) | 3 lines
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
........
r59771 | georg.brandl | 2008-01-06 15:33:52 +0100 (Sun, 06 Jan 2008) | 2 lines
#1591: Clarify docstring of Popen3.
........
r59772 | georg.brandl | 2008-01-06 16:30:34 +0100 (Sun, 06 Jan 2008) | 2 lines
#1680: fix context manager example function name.
........
r59773 | georg.brandl | 2008-01-06 16:34:57 +0100 (Sun, 06 Jan 2008) | 2 lines
#1755097: document default values for [].sort() and sorted().
........
2008-01-06 12:59:19 -04:00
|
|
|
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
|
2010-12-12 16:57:12 -04:00
|
|
|
|
2017-08-28 05:32:44 -03:00
|
|
|
The next example shows how to use the socket interface to communicate to a CAN
|
2013-02-05 14:42:01 -04:00
|
|
|
network using the raw socket protocol. To use CAN with the broadcast
|
|
|
|
manager protocol instead, open a socket with::
|
|
|
|
|
|
|
|
socket.socket(socket.AF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM)
|
|
|
|
|
|
|
|
After binding (:const:`CAN_RAW`) or connecting (:const:`CAN_BCM`) the socket, you
|
2023-04-04 19:46:46 -03:00
|
|
|
can use the :meth:`socket.send` and :meth:`socket.recv` operations (and
|
2013-02-05 14:42:01 -04:00
|
|
|
their counterparts) on the socket object as usual.
|
|
|
|
|
2017-08-28 05:32:44 -03:00
|
|
|
This last example might require special privileges::
|
2011-10-06 14:47:44 -03:00
|
|
|
|
|
|
|
import socket
|
|
|
|
import struct
|
|
|
|
|
|
|
|
|
2012-03-04 11:17:05 -04:00
|
|
|
# CAN frame packing/unpacking (see 'struct can_frame' in <linux/can.h>)
|
2011-10-06 14:47:44 -03:00
|
|
|
|
|
|
|
can_frame_fmt = "=IB3x8s"
|
2011-10-06 15:27:20 -03:00
|
|
|
can_frame_size = struct.calcsize(can_frame_fmt)
|
2011-10-06 14:47:44 -03:00
|
|
|
|
|
|
|
def build_can_frame(can_id, data):
|
|
|
|
can_dlc = len(data)
|
|
|
|
data = data.ljust(8, b'\x00')
|
|
|
|
return struct.pack(can_frame_fmt, can_id, can_dlc, data)
|
|
|
|
|
|
|
|
def dissect_can_frame(frame):
|
|
|
|
can_id, can_dlc, data = struct.unpack(can_frame_fmt, frame)
|
|
|
|
return (can_id, can_dlc, data[:can_dlc])
|
|
|
|
|
|
|
|
|
2012-03-04 11:17:05 -04:00
|
|
|
# create a raw socket and bind it to the 'vcan0' interface
|
2011-10-06 14:47:44 -03:00
|
|
|
s = socket.socket(socket.AF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
|
|
|
|
s.bind(('vcan0',))
|
|
|
|
|
|
|
|
while True:
|
2011-10-06 15:27:20 -03:00
|
|
|
cf, addr = s.recvfrom(can_frame_size)
|
2011-10-06 14:47:44 -03:00
|
|
|
|
|
|
|
print('Received: can_id=%x, can_dlc=%x, data=%s' % dissect_can_frame(cf))
|
|
|
|
|
|
|
|
try:
|
|
|
|
s.send(cf)
|
2011-10-12 12:53:43 -03:00
|
|
|
except OSError:
|
2011-10-06 14:47:44 -03:00
|
|
|
print('Error sending CAN frame')
|
|
|
|
|
|
|
|
try:
|
|
|
|
s.send(build_can_frame(0x01, b'\x01\x02\x03'))
|
2011-10-12 12:53:43 -03:00
|
|
|
except OSError:
|
2011-10-06 14:47:44 -03:00
|
|
|
print('Error sending CAN frame')
|
2010-12-12 16:57:12 -04:00
|
|
|
|
2011-09-02 15:06:31 -03:00
|
|
|
Running an example several times with too small delay between executions, could
|
|
|
|
lead to this error::
|
|
|
|
|
2011-10-12 12:53:43 -03:00
|
|
|
OSError: [Errno 98] Address already in use
|
2011-09-02 15:06:31 -03:00
|
|
|
|
|
|
|
This is because the previous execution has left the socket in a ``TIME_WAIT``
|
|
|
|
state, and can't be immediately reused.
|
|
|
|
|
|
|
|
There is a :mod:`socket` flag to set, in order to prevent this,
|
2023-07-21 06:40:37 -03:00
|
|
|
:const:`socket.SO_REUSEADDR`::
|
2011-09-02 15:06:31 -03:00
|
|
|
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
|
|
s.bind((HOST, PORT))
|
|
|
|
|
|
|
|
the :data:`SO_REUSEADDR` flag tells the kernel to reuse a local socket in
|
|
|
|
``TIME_WAIT`` state, without waiting for its natural timeout to expire.
|
|
|
|
|
|
|
|
|
2010-12-12 16:57:12 -04:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
For an introduction to socket programming (in C), see the following papers:
|
|
|
|
|
|
|
|
- *An Introductory 4.3BSD Interprocess Communication Tutorial*, by Stuart Sechrest
|
|
|
|
|
|
|
|
- *An Advanced 4.3BSD Interprocess Communication Tutorial*, by Samuel J. Leffler et
|
|
|
|
al,
|
|
|
|
|
|
|
|
both in the UNIX Programmer's Manual, Supplementary Documents 1 (sections
|
|
|
|
PS1:7 and PS1:8). The platform-specific reference material for the various
|
|
|
|
socket-related system calls are also a valuable source of information on the
|
|
|
|
details of socket semantics. For Unix, refer to the manual pages; for Windows,
|
|
|
|
see the WinSock (or Winsock 2) specification. For IPv6-ready APIs, readers may
|
|
|
|
want to refer to :rfc:`3493` titled Basic Socket Interface Extensions for IPv6.
|