Python-checkins
Threads by month
- ----- 2024 -----
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
July 2022
- 1 participants
- 572 discussions
https://github.com/python/cpython/commit/ab444b7fc632d9ed25210aff6c45776c8c…
commit: ab444b7fc632d9ed25210aff6c45776c8c5f3554
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2022-07-31T14:11:35-07:00
summary:
IDLE: Fix docs URL in the About window (GH-28417)
(cherry picked from commit 0f17a754d925345d67beff18897d86780436c506)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
files:
M Lib/idlelib/help_about.py
diff --git a/Lib/idlelib/help_about.py b/Lib/idlelib/help_about.py
index 9cb3ba78c50eb..a0085a40b980e 100644
--- a/Lib/idlelib/help_about.py
+++ b/Lib/idlelib/help_about.py
@@ -91,8 +91,9 @@ def create_widgets(self):
email = Label(frame_background, text='email: idle-dev(a)python.org',
justify=LEFT, fg=self.fg, bg=self.bg)
email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
- docs = Label(frame_background, text="https://docs.python.org/"
- f"{version[:version.rindex('.')]}/library/idle.html",
+ docs_url = ("https://docs.python.org/%d.%d/library/idle.html" %
+ sys.version_info[:2])
+ docs = Label(frame_background, text=docs_url,
justify=LEFT, fg=self.fg, bg=self.bg)
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
docs.bind("<Button-1>", lambda event: webbrowser.open(docs['text']))
1
0
https://github.com/python/cpython/commit/03fed0ade40af6877ed0d8289c05c46e98…
commit: 03fed0ade40af6877ed0d8289c05c46e985b66ec
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2022-07-31T14:09:11-07:00
summary:
IDLE: Fix docs URL in the About window (GH-28417)
(cherry picked from commit 0f17a754d925345d67beff18897d86780436c506)
Co-authored-by: Serhiy Storchaka <storchaka(a)gmail.com>
files:
M Lib/idlelib/help_about.py
diff --git a/Lib/idlelib/help_about.py b/Lib/idlelib/help_about.py
index c59f494599806..710f2ac71074b 100644
--- a/Lib/idlelib/help_about.py
+++ b/Lib/idlelib/help_about.py
@@ -91,8 +91,9 @@ def create_widgets(self):
email = Label(frame_background, text='email: idle-dev(a)python.org',
justify=LEFT, fg=self.fg, bg=self.bg)
email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
- docs = Label(frame_background, text="https://docs.python.org/"
- f"{version[:version.rindex('.')]}/library/idle.html",
+ docs_url = ("https://docs.python.org/%d.%d/library/idle.html" %
+ sys.version_info[:2])
+ docs = Label(frame_background, text=docs_url,
justify=LEFT, fg=self.fg, bg=self.bg)
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
docs.bind("<Button-1>", lambda event: webbrowser.open(docs['text']))
1
0
https://github.com/python/cpython/commit/0f17a754d925345d67beff18897d867804…
commit: 0f17a754d925345d67beff18897d86780436c506
branch: main
author: Serhiy Storchaka <storchaka(a)gmail.com>
committer: terryjreedy <tjreedy(a)udel.edu>
date: 2022-07-31T16:47:28-04:00
summary:
IDLE: Fix docs URL in the About window (#28417)
files:
M Lib/idlelib/help_about.py
diff --git a/Lib/idlelib/help_about.py b/Lib/idlelib/help_about.py
index 9cb3ba78c50eb..a0085a40b980e 100644
--- a/Lib/idlelib/help_about.py
+++ b/Lib/idlelib/help_about.py
@@ -91,8 +91,9 @@ def create_widgets(self):
email = Label(frame_background, text='email: idle-dev(a)python.org',
justify=LEFT, fg=self.fg, bg=self.bg)
email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
- docs = Label(frame_background, text="https://docs.python.org/"
- f"{version[:version.rindex('.')]}/library/idle.html",
+ docs_url = ("https://docs.python.org/%d.%d/library/idle.html" %
+ sys.version_info[:2])
+ docs = Label(frame_background, text=docs_url,
justify=LEFT, fg=self.fg, bg=self.bg)
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
docs.bind("<Button-1>", lambda event: webbrowser.open(docs['text']))
1
0
31 Jul '22
https://github.com/python/cpython/commit/06b5f78d64763dfd05aa0cc8b3419de9e9…
commit: 06b5f78d64763dfd05aa0cc8b3419de9e9c2ab50
branch: 3.11
author: Christian Heimes <christian(a)python.org>
committer: tiran <christian(a)python.org>
date: 2022-07-31T18:19:32+02:00
summary:
[3.11] gh-95174: WASI: skip missing sockets functions (GH-95179) (GH-95308)
Co-authored-by: Christian Heimes <christian(a)python.org>
Co-authored-by: Pablo Galindo Salgado <Pablogsal(a)gmail.com>
files:
A Misc/NEWS.d/next/Build/2022-07-23-21-39-09.gh-issue-95174.7cYMZR.rst
M Lib/test/test_socket.py
M Modules/addrinfo.h
M Modules/getaddrinfo.c
M Modules/getnameinfo.c
M Modules/socketmodule.c
M PC/pyconfig.h
M Tools/wasm/config.site-wasm32-wasi
M configure
M configure.ac
M pyconfig.h.in
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index a2938cd834ac1..72e3394df2d64 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -956,6 +956,19 @@ def testWindowsSpecificConstants(self):
socket.IPPROTO_L2TP
socket.IPPROTO_SCTP
+ @unittest.skipIf(support.is_wasi, "WASI is missing these methods")
+ def test_socket_methods(self):
+ # socket methods that depend on a configure HAVE_ check. They should
+ # be present on all platforms except WASI.
+ names = [
+ "_accept", "bind", "connect", "connect_ex", "getpeername",
+ "getsockname", "listen", "recvfrom", "recvfrom_into", "sendto",
+ "setsockopt", "shutdown"
+ ]
+ for name in names:
+ if not hasattr(socket.socket, name):
+ self.fail(f"socket method {name} is missing")
+
@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test')
def test3542SocketOptions(self):
diff --git a/Misc/NEWS.d/next/Build/2022-07-23-21-39-09.gh-issue-95174.7cYMZR.rst b/Misc/NEWS.d/next/Build/2022-07-23-21-39-09.gh-issue-95174.7cYMZR.rst
new file mode 100644
index 0000000000000..72ce183ac8329
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-07-23-21-39-09.gh-issue-95174.7cYMZR.rst
@@ -0,0 +1 @@
+Python now skips missing :mod:`socket` functions and methods on WASI. WASI can only create sockets from existing fd / accept and has no netdb.
diff --git a/Modules/addrinfo.h b/Modules/addrinfo.h
index c3c86248dd436..66e5a795f86f1 100644
--- a/Modules/addrinfo.h
+++ b/Modules/addrinfo.h
@@ -162,7 +162,9 @@ struct sockaddr_storage {
#ifdef __cplusplus
extern "C" {
#endif
+#ifdef ENABLE_IPV6
extern void freehostent(struct hostent *);
+#endif
#ifdef __cplusplus
}
#endif
diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c
index 5aaa6e7c8144f..0b4620ed683de 100644
--- a/Modules/getaddrinfo.c
+++ b/Modules/getaddrinfo.c
@@ -61,6 +61,9 @@
# define FAITH
#endif
+#ifdef HAVE_NETDB_H
+#define HAVE_GETADDRINFO 1
+
#define SUCCESS 0
#define GAI_ANY 0
#define YES 1
@@ -636,3 +639,5 @@ get_addr(hostname, af, res, pai, port0)
*res = NULL;
return error;
}
+
+#endif // HAVE_NETDB_H
diff --git a/Modules/getnameinfo.c b/Modules/getnameinfo.c
index db3e8eedd217c..335021f79bafe 100644
--- a/Modules/getnameinfo.c
+++ b/Modules/getnameinfo.c
@@ -48,6 +48,9 @@
#include "addrinfo.h"
#endif
+#ifdef HAVE_NETDB_H
+#define HAVE_GETNAMEINFO 1
+
#define SUCCESS 0
#define YES 1
#define NO 0
@@ -211,3 +214,4 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
}
return SUCCESS;
}
+#endif // HAVE_NETDB_H
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 7240739c7b3ba..14af496a45f47 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -227,7 +227,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\
#define HAVE_INET_PTON
#include <netdb.h>
-#endif
+#endif // __sgi
/* Solaris fails to define this variable at all. */
#if (defined(__sun) && defined(__SVR4)) && !defined(INET_ADDRSTRLEN)
@@ -256,7 +256,9 @@ shutdown(how) -- shut down traffic in one or both directions\n\
#ifndef MS_WINDOWS
/* Non-MS WINDOWS includes */
-# include <netdb.h>
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
# include <unistd.h>
/* Headers needed for inet_ntoa() and inet_addr() */
@@ -436,10 +438,11 @@ remove_unusable_flags(PyObject *m)
#define freeaddrinfo fake_freeaddrinfo
#include "getaddrinfo.c"
#endif
+
#if !defined(HAVE_GETNAMEINFO)
#define getnameinfo fake_getnameinfo
#include "getnameinfo.c"
-#endif
+#endif // HAVE_GETNAMEINFO
#ifdef MS_WINDOWS
#define SOCKETCLOSE closesocket
@@ -620,6 +623,7 @@ set_error(void)
}
+#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME) || defined (HAVE_GETHOSTBYADDR)
static PyObject *
set_herror(int h_error)
{
@@ -637,8 +641,10 @@ set_herror(int h_error)
return NULL;
}
+#endif
+#ifdef HAVE_GETADDRINFO
static PyObject *
set_gaierror(int error)
{
@@ -662,6 +668,7 @@ set_gaierror(int error)
return NULL;
}
+#endif
/* Function to perform the setting of socket blocking mode
internally. block = (1 | 0). */
@@ -1043,6 +1050,7 @@ static PyThread_type_lock netdb_lock;
#endif
+#ifdef HAVE_GETADDRINFO
/* Convert a string specifying a host name or one of a few symbolic
names to a numeric IP address. This usually calls gethostbyname()
to do the work; the names "" and "<broadcast>" are special.
@@ -1199,7 +1207,7 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int
return -1;
}
}
-
+#endif // HAVE_GETADDRINFO
/* Convert IPv4 sockaddr to a Python str. */
@@ -1594,6 +1602,7 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
}
}
+#if defined(HAVE_BIND) || defined(HAVE_CONNECTTO) || defined(CMSG_LEN)
/* Helper for getsockaddrarg: bypass IDNA for ASCII-only host names
(in particular, numeric IP addresses). */
struct maybe_idna {
@@ -2388,6 +2397,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
}
}
+#endif // defined(HAVE_BIND) || defined(HAVE_CONNECTTO) || defined(CMSG_LEN)
/* Get the address length according to the socket object's address family.
@@ -2678,6 +2688,7 @@ struct sock_accept {
SOCKET_T result;
};
+#if defined(HAVE_ACCEPT) || defined(HAVE_ACCEPT4)
#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
/* accept4() is available on Linux 2.6.28+ and glibc 2.10 */
static int accept4_works = -1;
@@ -2791,6 +2802,8 @@ PyDoc_STRVAR(accept_doc,
Wait for an incoming connection. Return a new socket file descriptor\n\
representing the connection, and the address of the client.\n\
For IP sockets, the address info is a pair (hostaddr, port).");
+#endif // defined(HAVE_ACCEPT) || defined(HAVE_ACCEPT4)
+
/* s.setblocking(flag) method. Argument:
False -- non-blocking mode; same as settimeout(0)
@@ -2955,6 +2968,7 @@ Returns the timeout in seconds (float) associated with socket\n\
operations. A timeout of None indicates that timeouts on socket\n\
operations are disabled.");
+#ifdef HAVE_SETSOCKOPT
/* s.setsockopt() method.
With an integer third argument, sets an integer optval with optlen=4.
With None as third argument and an integer fourth argument, set
@@ -3044,7 +3058,7 @@ setsockopt(level, option, None, optlen: int)\n\
Set a socket option. See the Unix manual for level and option.\n\
The value argument can either be an integer, a string buffer, or\n\
None, optlen.");
-
+#endif
/* s.getsockopt() method.
With two arguments, retrieves an integer option.
@@ -3118,6 +3132,7 @@ If a nonzero buffersize argument is given, the return value is a\n\
string of that length; otherwise it is an integer.");
+#ifdef HAVE_BIND
/* s.bind(sockaddr) method */
static PyObject *
@@ -3149,6 +3164,7 @@ PyDoc_STRVAR(bind_doc,
Bind the socket to a local address. For IP sockets, the address is a\n\
pair (host, port); the host must refer to the local host. For raw packet\n\
sockets the address is a tuple (ifname, proto [,pkttype [,hatype [,addr]]])");
+#endif
/* s.close() method.
@@ -3201,6 +3217,7 @@ Close the socket object without closing the underlying file descriptor.\n\
The object cannot be used after this call, but the file descriptor\n\
can be reused for other purposes. The file descriptor is returned.");
+#ifdef HAVE_CONNECT
static int
sock_connect_impl(PySocketSockObject *s, void* Py_UNUSED(data))
{
@@ -3348,6 +3365,7 @@ PyDoc_STRVAR(connect_ex_doc,
\n\
This is like connect(address), but returns an error code (the errno value)\n\
instead of raising an exception when an error occurs.");
+#endif // HAVE_CONNECT
/* s.fileno() method */
@@ -3364,6 +3382,7 @@ PyDoc_STRVAR(fileno_doc,
Return the integer file descriptor of the socket.");
+#ifdef HAVE_GETSOCKNAME
/* s.getsockname() method */
static PyObject *
@@ -3391,6 +3410,7 @@ PyDoc_STRVAR(getsockname_doc,
Return the address of the local endpoint. The format depends on the\n\
address family. For IPv4 sockets, the address info is a pair\n\
(hostaddr, port).");
+#endif
#ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */
@@ -3424,6 +3444,7 @@ info is a pair (hostaddr, port).");
#endif /* HAVE_GETPEERNAME */
+#ifdef HAVE_LISTEN
/* s.listen(n) method */
static PyObject *
@@ -3456,6 +3477,7 @@ Enable a server to accept connections. If backlog is specified, it must be\n\
at least 0 (if it is lower, it is set to 0); it specifies the number of\n\
unaccepted connections that the system will allow before refusing new\n\
connections. If not specified, a default reasonable value is chosen.");
+#endif
struct sock_recv {
char *cbuf;
@@ -3632,6 +3654,7 @@ struct sock_recvfrom {
Py_ssize_t result;
};
+#ifdef HAVE_RECVFROM
static int
sock_recvfrom_impl(PySocketSockObject *s, void *data)
{
@@ -3804,6 +3827,7 @@ PyDoc_STRVAR(recvfrom_into_doc,
"recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\
\n\
Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info.");
+#endif
/* The sendmsg() and recvmsg[_into]() methods require a working
CMSG_LEN(). See the comment near get_CMSG_LEN(). */
@@ -4270,6 +4294,7 @@ until all data is sent. If an error occurs, it's impossible\n\
to tell how much data has been sent.");
+#ifdef HAVE_SENDTO
struct sock_sendto {
char *buf;
Py_ssize_t len;
@@ -4362,6 +4387,7 @@ PyDoc_STRVAR(sendto_doc,
\n\
Like send(data, flags) but allows specifying the destination address.\n\
For IP sockets, the address is a pair (hostaddr, port).");
+#endif
/* The sendmsg() and recvmsg[_into]() methods require a working
@@ -4925,16 +4951,22 @@ socket.fromshare().");
/* List of methods for socket objects */
static PyMethodDef sock_methods[] = {
+#if defined(HAVE_ACCEPT) || defined(HAVE_ACCEPT4)
{"_accept", (PyCFunction)sock_accept, METH_NOARGS,
accept_doc},
+#endif
+#ifdef HAVE_BIND
{"bind", (PyCFunction)sock_bind, METH_O,
bind_doc},
+#endif
{"close", (PyCFunction)sock_close, METH_NOARGS,
sock_close_doc},
+#ifdef HAVE_CONNECT
{"connect", (PyCFunction)sock_connect, METH_O,
connect_doc},
{"connect_ex", (PyCFunction)sock_connect_ex, METH_O,
connect_ex_doc},
+#endif
{"detach", (PyCFunction)sock_detach, METH_NOARGS,
detach_doc},
{"fileno", (PyCFunction)sock_fileno, METH_NOARGS,
@@ -4943,8 +4975,10 @@ static PyMethodDef sock_methods[] = {
{"getpeername", (PyCFunction)sock_getpeername,
METH_NOARGS, getpeername_doc},
#endif
+#ifdef HAVE_GETSOCKNAME
{"getsockname", (PyCFunction)sock_getsockname,
METH_NOARGS, getsockname_doc},
+#endif
{"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS,
getsockopt_doc},
#if defined(MS_WINDOWS) && defined(SIO_RCVALL)
@@ -4955,22 +4989,28 @@ static PyMethodDef sock_methods[] = {
{"share", (PyCFunction)sock_share, METH_VARARGS,
sock_share_doc},
#endif
+#ifdef HAVE_LISTEN
{"listen", (PyCFunction)sock_listen, METH_VARARGS,
listen_doc},
+#endif
{"recv", (PyCFunction)sock_recv, METH_VARARGS,
recv_doc},
{"recv_into", _PyCFunction_CAST(sock_recv_into), METH_VARARGS | METH_KEYWORDS,
recv_into_doc},
+#ifdef HAVE_RECVFROM
{"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS,
recvfrom_doc},
{"recvfrom_into", _PyCFunction_CAST(sock_recvfrom_into), METH_VARARGS | METH_KEYWORDS,
recvfrom_into_doc},
+#endif
{"send", (PyCFunction)sock_send, METH_VARARGS,
send_doc},
{"sendall", (PyCFunction)sock_sendall, METH_VARARGS,
sendall_doc},
+#ifdef HAVE_SENDTO
{"sendto", (PyCFunction)sock_sendto, METH_VARARGS,
sendto_doc},
+#endif
{"setblocking", (PyCFunction)sock_setblocking, METH_O,
setblocking_doc},
{"getblocking", (PyCFunction)sock_getblocking, METH_NOARGS,
@@ -4979,8 +5019,10 @@ static PyMethodDef sock_methods[] = {
settimeout_doc},
{"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS,
gettimeout_doc},
+#ifdef HAVE_SETSOCKOPT
{"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS,
setsockopt_doc},
+#endif
#ifdef HAVE_SHUTDOWN
{"shutdown", (PyCFunction)sock_shutdown, METH_O,
shutdown_doc},
@@ -5116,6 +5158,16 @@ static int sock_cloexec_works = -1;
/*ARGSUSED*/
+#ifndef HAVE_SOCKET
+#define socket stub_socket
+static int
+socket(int domain, int type, int protocol)
+{
+ errno = ENOTSUP;
+ return INVALID_SOCKET;
+}
+#endif
+
/*[clinic input]
_socket.socket.__init__ as sock_initobj
family: int = -1
@@ -5202,6 +5254,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
socklen_t addrlen = sizeof(sock_addr_t);
memset(&addrbuf, 0, addrlen);
+#ifdef HAVE_GETSOCKNAME
if (getsockname(fd, SAS2SA(&addrbuf), &addrlen) == 0) {
if (family == -1) {
family = SAS2SA(&addrbuf)->sa_family;
@@ -5220,6 +5273,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
return -1;
}
}
+#endif // HAVE_GETSOCKNAME
#ifdef SO_TYPE
if (type == -1) {
int tmp;
@@ -5398,6 +5452,7 @@ static PyTypeObject sock_type = {
};
+#ifdef HAVE_GETHOSTNAME
/* Python interface to gethostname(). */
/*ARGSUSED*/
@@ -5461,6 +5516,7 @@ PyDoc_STRVAR(gethostname_doc,
"gethostname() -> string\n\
\n\
Return the current host name.");
+#endif
#ifdef HAVE_SETHOSTNAME
PyDoc_STRVAR(sethostname_doc,
@@ -5504,6 +5560,7 @@ extern int sethostname(const char *, size_t);
}
#endif
+#ifdef HAVE_GETADDRINFO
/* Python interface to gethostbyname(name). */
/*ARGSUSED*/
@@ -5531,8 +5588,10 @@ PyDoc_STRVAR(gethostbyname_doc,
"gethostbyname(host) -> address\n\
\n\
Return the IP address (a string of the form '255.255.255.255') for a host.");
+#endif
+#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME) || defined (HAVE_GETHOSTBYADDR)
static PyObject*
sock_decode_hostname(const char *name)
{
@@ -5674,8 +5733,9 @@ gethost_common(struct hostent *h, struct sockaddr *addr, size_t alen, int af)
Py_XDECREF(addr_list);
return rtn_tuple;
}
+#endif
-
+#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME)
/* Python interface to gethostbyname_ex(name). */
/*ARGSUSED*/
@@ -5748,8 +5808,9 @@ PyDoc_STRVAR(ghbn_ex_doc,
\n\
Return the true host name, a list of aliases, and a list of IP addresses,\n\
for a host. The host argument is a string giving a host name or IP number.");
+#endif
-
+#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR)
/* Python interface to gethostbyaddr(IP). */
/*ARGSUSED*/
@@ -5844,8 +5905,9 @@ PyDoc_STRVAR(gethostbyaddr_doc,
\n\
Return the true host name, a list of aliases, and a list of IP addresses,\n\
for a host. The host argument is a string giving a host name or IP number.");
+#endif
-
+#ifdef HAVE_GETSERVBYNAME
/* Python interface to getservbyname(name).
This only returns the port number, since the other info is already
known or not useful (like the list of aliases). */
@@ -5879,8 +5941,9 @@ PyDoc_STRVAR(getservbyname_doc,
Return a port number from a service name and protocol name.\n\
The optional protocol name, if given, should be 'tcp' or 'udp',\n\
otherwise any protocol will match.");
+#endif
-
+#ifdef HAVE_GETSERVBYPORT
/* Python interface to getservbyport(port).
This only returns the service name, since the other info is already
known or not useful (like the list of aliases). */
@@ -5921,7 +5984,9 @@ PyDoc_STRVAR(getservbyport_doc,
Return the service name from a port number and protocol name.\n\
The optional protocol name, if given, should be 'tcp' or 'udp',\n\
otherwise any protocol will match.");
+#endif
+#ifdef HAVE_GETPROTOBYNAME
/* Python interface to getprotobyname(name).
This only returns the protocol number, since the other info is
already known or not useful (like the list of aliases). */
@@ -5948,6 +6013,7 @@ PyDoc_STRVAR(getprotobyname_doc,
"getprotobyname(name) -> integer\n\
\n\
Return the protocol number for the named protocol. (Rarely used.)");
+#endif
static PyObject *
socket_close(PyObject *self, PyObject *fdobj)
@@ -6317,6 +6383,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
#endif
}
+#ifdef HAVE_INET_NTOA
PyDoc_STRVAR(inet_ntoa_doc,
"inet_ntoa(packed_ip) -> ip_address_string\n\
\n\
@@ -6345,6 +6412,7 @@ socket_inet_ntoa(PyObject *self, PyObject *args)
SUPPRESS_DEPRECATED_CALL
return PyUnicode_FromString(inet_ntoa(packed_addr));
}
+#endif // HAVE_INET_NTOA
#ifdef HAVE_INET_PTON
@@ -6456,6 +6524,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
#endif /* HAVE_INET_PTON */
+#ifdef HAVE_GETADDRINFO
/* Python interface to getaddrinfo(host, port). */
/*ARGSUSED*/
@@ -6583,7 +6652,9 @@ PyDoc_STRVAR(getaddrinfo_doc,
-> list of (family, type, proto, canonname, sockaddr)\n\
\n\
Resolve host and port into addrinfo struct.");
+#endif // HAVE_GETADDRINFO
+#ifdef HAVE_GETNAMEINFO
/* Python interface to getnameinfo(sa, flags). */
/*ARGSUSED*/
@@ -6684,7 +6755,7 @@ PyDoc_STRVAR(getnameinfo_doc,
"getnameinfo(sockaddr, flags) --> (host, port)\n\
\n\
Get host and port for a sockaddr.");
-
+#endif // HAVE_GETNAMEINFO
/* Python API to getting and setting the default timeout value. */
@@ -6940,24 +7011,38 @@ range of values.");
/* List of functions exported by this module. */
static PyMethodDef socket_methods[] = {
+#ifdef HAVE_GETADDRINFO
{"gethostbyname", socket_gethostbyname,
METH_VARARGS, gethostbyname_doc},
+#endif
+#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME)
{"gethostbyname_ex", socket_gethostbyname_ex,
METH_VARARGS, ghbn_ex_doc},
+#endif
+#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR)
{"gethostbyaddr", socket_gethostbyaddr,
METH_VARARGS, gethostbyaddr_doc},
+#endif
+#ifdef HAVE_GETHOSTNAME
{"gethostname", socket_gethostname,
METH_NOARGS, gethostname_doc},
+#endif
#ifdef HAVE_SETHOSTNAME
{"sethostname", socket_sethostname,
METH_VARARGS, sethostname_doc},
#endif
+#ifdef HAVE_GETSERVBYNAME
{"getservbyname", socket_getservbyname,
METH_VARARGS, getservbyname_doc},
+#endif
+#ifdef HAVE_GETSERVBYPORT
{"getservbyport", socket_getservbyport,
METH_VARARGS, getservbyport_doc},
+#endif
+#ifdef HAVE_GETPROTOBYNAME
{"getprotobyname", socket_getprotobyname,
METH_VARARGS, getprotobyname_doc},
+#endif
{"close", socket_close,
METH_O, close_doc},
#ifndef NO_DUP
@@ -6978,18 +7063,24 @@ static PyMethodDef socket_methods[] = {
METH_O, htonl_doc},
{"inet_aton", socket_inet_aton,
METH_VARARGS, inet_aton_doc},
+#ifdef HAVE_INET_NTOA
{"inet_ntoa", socket_inet_ntoa,
METH_VARARGS, inet_ntoa_doc},
+#endif
#ifdef HAVE_INET_PTON
{"inet_pton", socket_inet_pton,
METH_VARARGS, inet_pton_doc},
{"inet_ntop", socket_inet_ntop,
METH_VARARGS, inet_ntop_doc},
#endif
+#ifdef HAVE_GETADDRINFO
{"getaddrinfo", _PyCFunction_CAST(socket_getaddrinfo),
METH_VARARGS | METH_KEYWORDS, getaddrinfo_doc},
+#endif
+#ifdef HAVE_GETNAMEINFO
{"getnameinfo", socket_getnameinfo,
METH_VARARGS, getnameinfo_doc},
+#endif
{"getdefaulttimeout", socket_getdefaulttimeout,
METH_NOARGS, getdefaulttimeout_doc},
{"setdefaulttimeout", socket_setdefaulttimeout,
@@ -7498,7 +7589,9 @@ PyInit__socket(void)
/* SOCK_RAW is marked as optional in the POSIX specification */
PyModule_AddIntMacro(m, SOCK_RAW);
#endif
+#ifdef SOCK_SEQPACKET
PyModule_AddIntMacro(m, SOCK_SEQPACKET);
+#endif
#if defined(SOCK_RDM)
PyModule_AddIntMacro(m, SOCK_RDM);
#endif
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index f1673a168ffb3..959b851ddcc97 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -678,8 +678,25 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define to 1 if you have the `erfc' function. */
#define HAVE_ERFC 1
-/* Define if you have the 'inet_pton' function. */
+// netdb.h functions (provided by winsock.h)
+#define HAVE_GETHOSTNAME 1
+#define HAVE_GETHOSTBYADDR 1
+#define HAVE_GETHOSTBYNAME 1
+#define HAVE_GETPROTOBYNAME 1
+#define HAVE_GETSERVBYNAME 1
+#define HAVE_GETSERVBYPORT 1
+// sys/socket.h functions (provided by winsock.h)
#define HAVE_INET_PTON 1
+#define HAVE_INET_NTOA 1
+#define HAVE_ACCEPT 1
+#define HAVE_BIND 1
+#define HAVE_CONNECT 1
+#define HAVE_GETSOCKNAME 1
+#define HAVE_LISTEN 1
+#define HAVE_RECVFROM 1
+#define HAVE_SENDTO 1
+#define HAVE_SETSOCKOPT 1
+#define HAVE_SOCKET 1
/* Define to 1 if you have the `dup' function. */
#define HAVE_DUP 1
diff --git a/Tools/wasm/config.site-wasm32-wasi b/Tools/wasm/config.site-wasm32-wasi
index f151b7bc5ab0c..237fa8b55624c 100644
--- a/Tools/wasm/config.site-wasm32-wasi
+++ b/Tools/wasm/config.site-wasm32-wasi
@@ -44,3 +44,7 @@ ac_cv_func_fchmod=no
# Disable AF_UNIX and AF_PACKET support, see socketmodule.h.
ac_cv_header_sys_un_h=no
ac_cv_header_netpacket_packet_h=no
+
+# disable accept for WASM runtimes without sock_accept
+#ac_cv_func_accept=no
+#ac_cv_func_accept4=no
diff --git a/configure b/configure
index 39f7cd8eaec0a..66915270750b2 100755
--- a/configure
+++ b/configure
@@ -8960,8 +8960,9 @@ $as_echo "#define STDC_HEADERS 1" >>confdefs.h
# checks for header files
for ac_header in \
alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
- ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/memfd.h linux/random.h linux/soundcard.h \
- linux/tipc.h linux/wait.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
+ ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/memfd.h \
+ linux/random.h linux/soundcard.h \
+ linux/tipc.h linux/wait.h netdb.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \
sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \
sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/poll.h \
@@ -14314,7 +14315,6 @@ done
fi
-
# Check for enable-ipv6
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if --enable-ipv6 is specified" >&5
@@ -14957,7 +14957,7 @@ for ac_func in \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
- getgrnam_r getgrouplist getgroups getitimer getloadavg getlogin \
+ getgrnam_r getgrouplist getgroups gethostname getitimer getloadavg getlogin \
getpeername getpgid getpid getppid getpriority _getpty \
getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \
getspnam getuid getwd if_nameindex initgroups kill killpg lchown linkat \
@@ -16764,6 +16764,8 @@ fi
+
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for hstrerror" >&5
$as_echo_n "checking for hstrerror... " >&6; }
if ${ac_cv_func_hstrerror+:} false; then :
@@ -16800,6 +16802,188 @@ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyname" >&5
+$as_echo_n "checking for getservbyname... " >&6; }
+if ${ac_cv_func_getservbyname+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <netdb.h>
+int
+main ()
+{
+void *x=getservbyname
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_getservbyname=yes
+else
+ ac_cv_func_getservbyname=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getservbyname" >&5
+$as_echo "$ac_cv_func_getservbyname" >&6; }
+ if test "x$ac_cv_func_getservbyname" = xyes; then :
+
+$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5
+$as_echo_n "checking for getservbyport... " >&6; }
+if ${ac_cv_func_getservbyport+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <netdb.h>
+int
+main ()
+{
+void *x=getservbyport
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_getservbyport=yes
+else
+ ac_cv_func_getservbyport=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getservbyport" >&5
+$as_echo "$ac_cv_func_getservbyport" >&6; }
+ if test "x$ac_cv_func_getservbyport" = xyes; then :
+
+$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5
+$as_echo_n "checking for gethostbyname... " >&6; }
+if ${ac_cv_func_gethostbyname+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <netdb.h>
+int
+main ()
+{
+void *x=gethostbyname
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_gethostbyname=yes
+else
+ ac_cv_func_gethostbyname=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_gethostbyname" >&5
+$as_echo "$ac_cv_func_gethostbyname" >&6; }
+ if test "x$ac_cv_func_gethostbyname" = xyes; then :
+
+$as_echo "#define HAVE_GETHOSTBYNAME 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5
+$as_echo_n "checking for gethostbyaddr... " >&6; }
+if ${ac_cv_func_gethostbyaddr+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <netdb.h>
+int
+main ()
+{
+void *x=gethostbyaddr
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_gethostbyaddr=yes
+else
+ ac_cv_func_gethostbyaddr=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_gethostbyaddr" >&5
+$as_echo "$ac_cv_func_gethostbyaddr" >&6; }
+ if test "x$ac_cv_func_gethostbyaddr" = xyes; then :
+
+$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5
+$as_echo_n "checking for getprotobyname... " >&6; }
+if ${ac_cv_func_getprotobyname+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <netdb.h>
+int
+main ()
+{
+void *x=getprotobyname
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_getprotobyname=yes
+else
+ ac_cv_func_getprotobyname=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getprotobyname" >&5
+$as_echo "$ac_cv_func_getprotobyname" >&6; }
+ if test "x$ac_cv_func_getprotobyname" = xyes; then :
+
+$as_echo "#define HAVE_GETPROTOBYNAME 1" >>confdefs.h
+
+fi
+
+
+
+
+
+
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_aton" >&5
$as_echo_n "checking for inet_aton... " >&6; }
@@ -16842,6 +17026,46 @@ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa" >&5
+$as_echo_n "checking for inet_ntoa... " >&6; }
+if ${ac_cv_func_inet_ntoa+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=inet_ntoa
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_inet_ntoa=yes
+else
+ ac_cv_func_inet_ntoa=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_inet_ntoa" >&5
+$as_echo "$ac_cv_func_inet_ntoa" >&6; }
+ if test "x$ac_cv_func_inet_ntoa" = xyes; then :
+
+$as_echo "#define HAVE_INET_NTOA 1" >>confdefs.h
+
+fi
+
+
+
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_pton" >&5
$as_echo_n "checking for inet_pton... " >&6; }
@@ -16883,6 +17107,416 @@ fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getpeername" >&5
+$as_echo_n "checking for getpeername... " >&6; }
+if ${ac_cv_func_getpeername+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=getpeername
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_getpeername=yes
+else
+ ac_cv_func_getpeername=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getpeername" >&5
+$as_echo "$ac_cv_func_getpeername" >&6; }
+ if test "x$ac_cv_func_getpeername" = xyes; then :
+
+$as_echo "#define HAVE_GETPEERNAME 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getsockname" >&5
+$as_echo_n "checking for getsockname... " >&6; }
+if ${ac_cv_func_getsockname+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=getsockname
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_getsockname=yes
+else
+ ac_cv_func_getsockname=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getsockname" >&5
+$as_echo "$ac_cv_func_getsockname" >&6; }
+ if test "x$ac_cv_func_getsockname" = xyes; then :
+
+$as_echo "#define HAVE_GETSOCKNAME 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for accept" >&5
+$as_echo_n "checking for accept... " >&6; }
+if ${ac_cv_func_accept+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=accept
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_accept=yes
+else
+ ac_cv_func_accept=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_accept" >&5
+$as_echo "$ac_cv_func_accept" >&6; }
+ if test "x$ac_cv_func_accept" = xyes; then :
+
+$as_echo "#define HAVE_ACCEPT 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bind" >&5
+$as_echo_n "checking for bind... " >&6; }
+if ${ac_cv_func_bind+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=bind
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_bind=yes
+else
+ ac_cv_func_bind=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_bind" >&5
+$as_echo "$ac_cv_func_bind" >&6; }
+ if test "x$ac_cv_func_bind" = xyes; then :
+
+$as_echo "#define HAVE_BIND 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for connect" >&5
+$as_echo_n "checking for connect... " >&6; }
+if ${ac_cv_func_connect+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=connect
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_connect=yes
+else
+ ac_cv_func_connect=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_connect" >&5
+$as_echo "$ac_cv_func_connect" >&6; }
+ if test "x$ac_cv_func_connect" = xyes; then :
+
+$as_echo "#define HAVE_CONNECT 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for listen" >&5
+$as_echo_n "checking for listen... " >&6; }
+if ${ac_cv_func_listen+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=listen
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_listen=yes
+else
+ ac_cv_func_listen=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_listen" >&5
+$as_echo "$ac_cv_func_listen" >&6; }
+ if test "x$ac_cv_func_listen" = xyes; then :
+
+$as_echo "#define HAVE_LISTEN 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for recvfrom" >&5
+$as_echo_n "checking for recvfrom... " >&6; }
+if ${ac_cv_func_recvfrom+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=recvfrom
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_recvfrom=yes
+else
+ ac_cv_func_recvfrom=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_recvfrom" >&5
+$as_echo "$ac_cv_func_recvfrom" >&6; }
+ if test "x$ac_cv_func_recvfrom" = xyes; then :
+
+$as_echo "#define HAVE_RECVFROM 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sendto" >&5
+$as_echo_n "checking for sendto... " >&6; }
+if ${ac_cv_func_sendto+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=sendto
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_sendto=yes
+else
+ ac_cv_func_sendto=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_sendto" >&5
+$as_echo "$ac_cv_func_sendto" >&6; }
+ if test "x$ac_cv_func_sendto" = xyes; then :
+
+$as_echo "#define HAVE_SENDTO 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for setsockopt" >&5
+$as_echo_n "checking for setsockopt... " >&6; }
+if ${ac_cv_func_setsockopt+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=setsockopt
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_setsockopt=yes
+else
+ ac_cv_func_setsockopt=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_setsockopt" >&5
+$as_echo "$ac_cv_func_setsockopt" >&6; }
+ if test "x$ac_cv_func_setsockopt" = xyes; then :
+
+$as_echo "#define HAVE_SETSOCKOPT 1" >>confdefs.h
+
+fi
+
+
+
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket" >&5
+$as_echo_n "checking for socket... " >&6; }
+if ${ac_cv_func_socket+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main ()
+{
+void *x=socket
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_func_socket=yes
+else
+ ac_cv_func_socket=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_socket" >&5
+$as_echo "$ac_cv_func_socket" >&6; }
+ if test "x$ac_cv_func_socket" = xyes; then :
+
+$as_echo "#define HAVE_SOCKET 1" >>confdefs.h
+
+fi
+
+
+
+
# On some systems, setgroups is in unistd.h, on others, in grp.h
diff --git a/configure.ac b/configure.ac
index 60daab58d24b8..443637962def9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2626,8 +2626,9 @@ AC_DEFINE(STDC_HEADERS, 1, [Define to 1 if you have the ANSI C header files.])
# checks for header files
AC_CHECK_HEADERS([ \
alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \
- ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/memfd.h linux/random.h linux/soundcard.h \
- linux/tipc.h linux/wait.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
+ ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/memfd.h \
+ linux/random.h linux/soundcard.h \
+ linux/tipc.h linux/wait.h netdb.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \
sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \
sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \
sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/poll.h \
@@ -4156,7 +4157,6 @@ if test "$posix_threads" = "yes"; then
AC_CHECK_FUNCS(pthread_getcpuclockid)
fi
-
# Check for enable-ipv6
AH_TEMPLATE(ENABLE_IPV6, [Define if --enable-ipv6 is specified])
AC_MSG_CHECKING([if --enable-ipv6 is specified])
@@ -4541,7 +4541,7 @@ AC_CHECK_FUNCS([ \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
- getgrnam_r getgrouplist getgroups getitimer getloadavg getlogin \
+ getgrnam_r getgrouplist getgroups gethostname getitimer getloadavg getlogin \
getpeername getpgid getpid getppid getpriority _getpty \
getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \
getspnam getuid getwd if_nameindex initgroups kill killpg lchown linkat \
@@ -4784,21 +4784,39 @@ PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [
])
])
-PY_CHECK_FUNC([hstrerror], [#include <netdb.h>])
+dnl PY_CHECK_NETDB_FUNC(FUNCTION)
+AC_DEFUN([PY_CHECK_NETDB_FUNC], [PY_CHECK_FUNC([$1], [#include <netdb.h>])])
-PY_CHECK_FUNC([inet_aton], [
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-])
+PY_CHECK_NETDB_FUNC([hstrerror])
+dnl not available in WASI yet
+PY_CHECK_NETDB_FUNC([getservbyname])
+PY_CHECK_NETDB_FUNC([getservbyport])
+PY_CHECK_NETDB_FUNC([gethostbyname])
+PY_CHECK_NETDB_FUNC([gethostbyaddr])
+PY_CHECK_NETDB_FUNC([getprotobyname])
-PY_CHECK_FUNC([inet_pton], [
+dnl PY_CHECK_SOCKET_FUNC(FUNCTION)
+AC_DEFUN([PY_CHECK_SOCKET_FUNC], [PY_CHECK_FUNC([$1], [
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-])
+])])
+
+PY_CHECK_SOCKET_FUNC([inet_aton])
+PY_CHECK_SOCKET_FUNC([inet_ntoa])
+PY_CHECK_SOCKET_FUNC([inet_pton])
+dnl not available in WASI yet
+PY_CHECK_SOCKET_FUNC([getpeername])
+PY_CHECK_SOCKET_FUNC([getsockname])
+PY_CHECK_SOCKET_FUNC([accept])
+PY_CHECK_SOCKET_FUNC([bind])
+PY_CHECK_SOCKET_FUNC([connect])
+PY_CHECK_SOCKET_FUNC([listen])
+PY_CHECK_SOCKET_FUNC([recvfrom])
+PY_CHECK_SOCKET_FUNC([sendto])
+PY_CHECK_SOCKET_FUNC([setsockopt])
+PY_CHECK_SOCKET_FUNC([socket])
# On some systems, setgroups is in unistd.h, on others, in grp.h
PY_CHECK_FUNC([setgroups], [
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 4aaa32c8b4336..dcbe703e77aec 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -51,6 +51,9 @@
/* Define if getpgrp() must be called as getpgrp(0). */
#undef GETPGRP_HAVE_ARG
+/* Define if you have the 'accept' function. */
+#undef HAVE_ACCEPT
+
/* Define to 1 if you have the `accept4' function. */
#undef HAVE_ACCEPT4
@@ -81,6 +84,9 @@
/* Define to 1 if you have the `atanh' function. */
#undef HAVE_ATANH
+/* Define if you have the 'bind' function. */
+#undef HAVE_BIND
+
/* Define to 1 if you have the `bind_textdomain_codeset' function. */
#undef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -160,6 +166,9 @@
/* Define to 1 if you have the <conio.h> header file. */
#undef HAVE_CONIO_H
+/* Define if you have the 'connect' function. */
+#undef HAVE_CONNECT
+
/* Define to 1 if you have the `copy_file_range' function. */
#undef HAVE_COPY_FILE_RANGE
@@ -468,6 +477,9 @@
/* Define to 1 if you have the `getgroups' function. */
#undef HAVE_GETGROUPS
+/* Define if you have the 'gethostbyaddr' function. */
+#undef HAVE_GETHOSTBYADDR
+
/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME
@@ -483,6 +495,9 @@
/* Define this if you have the 6-arg version of gethostbyname_r(). */
#undef HAVE_GETHOSTBYNAME_R_6_ARG
+/* Define to 1 if you have the `gethostname' function. */
+#undef HAVE_GETHOSTNAME
+
/* Define to 1 if you have the `getitimer' function. */
#undef HAVE_GETITIMER
@@ -498,7 +513,7 @@
/* Define if you have the 'getpagesize' function. */
#undef HAVE_GETPAGESIZE
-/* Define to 1 if you have the `getpeername' function. */
+/* Define if you have the 'getpeername' function. */
#undef HAVE_GETPEERNAME
/* Define to 1 if you have the `getpgid' function. */
@@ -516,6 +531,9 @@
/* Define to 1 if you have the `getpriority' function. */
#undef HAVE_GETPRIORITY
+/* Define if you have the 'getprotobyname' function. */
+#undef HAVE_GETPROTOBYNAME
+
/* Define to 1 if you have the `getpwent' function. */
#undef HAVE_GETPWENT
@@ -543,9 +561,18 @@
/* Define to 1 if you have the `getrusage' function. */
#undef HAVE_GETRUSAGE
+/* Define if you have the 'getservbyname' function. */
+#undef HAVE_GETSERVBYNAME
+
+/* Define if you have the 'getservbyport' function. */
+#undef HAVE_GETSERVBYPORT
+
/* Define to 1 if you have the `getsid' function. */
#undef HAVE_GETSID
+/* Define if you have the 'getsockname' function. */
+#undef HAVE_GETSOCKNAME
+
/* Define to 1 if you have the `getspent' function. */
#undef HAVE_GETSPENT
@@ -580,6 +607,9 @@
/* Define if you have the 'inet_aton' function. */
#undef HAVE_INET_ATON
+/* Define if you have the 'inet_ntoa' function. */
+#undef HAVE_INET_NTOA
+
/* Define if you have the 'inet_pton' function. */
#undef HAVE_INET_PTON
@@ -712,6 +742,9 @@
/* Define to 1 if you have the <linux/wait.h> header file. */
#undef HAVE_LINUX_WAIT_H
+/* Define if you have the 'listen' function. */
+#undef HAVE_LISTEN
+
/* Define to 1 if you have the `lockf' function. */
#undef HAVE_LOCKF
@@ -793,6 +826,9 @@
/* Define to 1 if you have the <netcan/can.h> header file. */
#undef HAVE_NETCAN_CAN_H
+/* Define to 1 if you have the <netdb.h> header file. */
+#undef HAVE_NETDB_H
+
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
@@ -914,6 +950,9 @@
/* Define to 1 if you have the `realpath' function. */
#undef HAVE_REALPATH
+/* Define if you have the 'recvfrom' function. */
+#undef HAVE_RECVFROM
+
/* Define to 1 if you have the `renameat' function. */
#undef HAVE_RENAMEAT
@@ -983,6 +1022,9 @@
/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE
+/* Define if you have the 'sendto' function. */
+#undef HAVE_SENDTO
+
/* Define to 1 if you have the `setegid' function. */
#undef HAVE_SETEGID
@@ -1031,6 +1073,9 @@
/* Define to 1 if you have the `setsid' function. */
#undef HAVE_SETSID
+/* Define if you have the 'setsockopt' function. */
+#undef HAVE_SETSOCKOPT
+
/* Define to 1 if you have the `setuid' function. */
#undef HAVE_SETUID
@@ -1094,6 +1139,9 @@
/* struct sockaddr_storage (sys/socket.h) */
#undef HAVE_SOCKADDR_STORAGE
+/* Define if you have the 'socket' function. */
+#undef HAVE_SOCKET
+
/* Define if you have the 'socketpair' function. */
#undef HAVE_SOCKETPAIR
1
0
bpo-45445: Revert "bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)" (GH-94745)
by miss-islington 31 Jul '22
by miss-islington 31 Jul '22
31 Jul '22
https://github.com/python/cpython/commit/147a9a8be79fb5666e264175e3047d6d67…
commit: 147a9a8be79fb5666e264175e3047d6d67b50254
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: miss-islington <31488909+miss-islington(a)users.noreply.github.com>
date: 2022-07-31T08:58:02-07:00
summary:
bpo-45445: Revert "bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)" (GH-94745)
(cherry picked from commit aa37ffda29ac48fb2df5a7029ba2e626ecc45850)
Co-authored-by: Pablo Galindo Salgado <Pablogsal(a)gmail.com>
files:
M Doc/library/sys.rst
M Lib/test/test_audit.py
M Lib/test/test_cmd_line.py
M Lib/test/test_embed.py
M Programs/_testembed.c
M Python/initconfig.c
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index e10efb10ff5a8..1ac529ada1ce8 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -1778,13 +1778,13 @@ always available.
.. code-block:: shell-session
- $ ./python -Xpycache_prefix=some_path -Xdev
+ $ ./python -Xa=b -Xc
Python 3.2a3+ (py3k, Oct 16 2010, 20:14:50)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys._xoptions
- {'pycache_prefix': 'some_path', 'dev': True}
+ {'a': 'b', 'c': True}
.. impl-detail::
diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py
index a7ff038c0936e..18426f27a2e32 100644
--- a/Lib/test/test_audit.py
+++ b/Lib/test/test_audit.py
@@ -20,7 +20,7 @@ class AuditTest(unittest.TestCase):
@support.requires_subprocess()
def do_test(self, *args):
with subprocess.Popen(
- [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
+ [sys.executable, "-X utf8", AUDIT_TESTS_PY, *args],
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
@@ -35,7 +35,7 @@ def do_test(self, *args):
def run_python(self, *args):
events = []
with subprocess.Popen(
- [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
+ [sys.executable, "-X utf8", AUDIT_TESTS_PY, *args],
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 83a357fe6b37d..037606d755f90 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -108,17 +108,8 @@ def get_xoptions(*args):
opts = get_xoptions()
self.assertEqual(opts, {})
- opts = get_xoptions('-Xno_debug_ranges', '-Xdev=1234')
- self.assertEqual(opts, {'no_debug_ranges': True, 'dev': '1234'})
-
- @unittest.skipIf(interpreter_requires_environment(),
- 'Cannot run -E tests when PYTHON env vars are required.')
- def test_unknown_xoptions(self):
- rc, out, err = assert_python_failure('-X', 'blech')
- self.assertIn(b'Unknown value for option -X', err)
- msg = b'Fatal Python error: Unknown value for option -X (see --help-xoptions)'
- self.assertEqual(err.splitlines().count(msg), 1)
- self.assertEqual(b'', out)
+ opts = get_xoptions('-Xa', '-Xb=c,d=e')
+ self.assertEqual(opts, {'a': True, 'b': 'c,d=e'})
def test_showrefcount(self):
def run_python(*args):
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index de3354b6b5950..90022db0c51c3 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -284,7 +284,7 @@ def test_pre_initialization_sys_options(self):
"test_pre_initialization_sys_options", env=env)
expected_output = (
"sys.warnoptions: ['once', 'module', 'default']\n"
- "sys._xoptions: {'dev': '2', 'utf8': '1'}\n"
+ "sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}\n"
"warnings.filters[:3]: ['default', 'module', 'once']\n"
)
self.assertIn(expected_output, out)
@@ -842,14 +842,15 @@ def test_init_from_config(self):
'argv': ['-c', 'arg2'],
'orig_argv': ['python3',
'-W', 'cmdline_warnoption',
- '-X', 'dev',
+ '-X', 'cmdline_xoption',
'-c', 'pass',
'arg2'],
'parse_argv': 2,
'xoptions': [
- 'dev=3',
- 'utf8',
- 'dev',
+ 'config_xoption1=3',
+ 'config_xoption2=',
+ 'config_xoption3',
+ 'cmdline_xoption',
],
'warnoptions': [
'cmdline_warnoption',
@@ -1077,8 +1078,9 @@ def test_init_sys_add(self):
config = {
'faulthandler': 1,
'xoptions': [
- 'dev',
- 'utf8',
+ 'config_xoption',
+ 'cmdline_xoption',
+ 'sysadd_xoption',
'faulthandler',
],
'warnoptions': [
@@ -1088,12 +1090,9 @@ def test_init_sys_add(self):
],
'orig_argv': ['python3',
'-W', 'ignore:::cmdline_warnoption',
- '-X', 'utf8'],
+ '-X', 'cmdline_xoption'],
}
- preconfig = {'utf8_mode': 1}
- self.check_all_configs("test_init_sys_add", config,
- expected_preconfig=preconfig,
- api=API_PYTHON)
+ self.check_all_configs("test_init_sys_add", config, api=API_PYTHON)
def test_init_run_main(self):
code = ('import _testinternalcapi, json; '
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 6b43d53403014..f84445690eb8f 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -279,7 +279,7 @@ static int test_pre_initialization_sys_options(void)
* relying on the caller to keep the passed in strings alive.
*/
const wchar_t *static_warnoption = L"once";
- const wchar_t *static_xoption = L"utf8=1";
+ const wchar_t *static_xoption = L"also_not_an_option=2";
size_t warnoption_len = wcslen(static_warnoption);
size_t xoption_len = wcslen(static_xoption);
wchar_t *dynamic_once_warnoption = \
@@ -298,7 +298,7 @@ static int test_pre_initialization_sys_options(void)
PySys_AddWarnOption(L"module");
PySys_AddWarnOption(L"default");
_Py_EMBED_PREINIT_CHECK("Checking PySys_AddXOption\n");
- PySys_AddXOption(L"dev=2");
+ PySys_AddXOption(L"not_an_option=1");
PySys_AddXOption(dynamic_xoption);
/* Delete the dynamic options early */
@@ -591,7 +591,7 @@ static int test_init_from_config(void)
L"-W",
L"cmdline_warnoption",
L"-X",
- L"dev",
+ L"cmdline_xoption",
L"-c",
L"pass",
L"arg2",
@@ -599,9 +599,10 @@ static int test_init_from_config(void)
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
- wchar_t* xoptions[2] = {
- L"dev=3",
- L"utf8",
+ wchar_t* xoptions[3] = {
+ L"config_xoption1=3",
+ L"config_xoption2=",
+ L"config_xoption3",
};
config_set_wide_string_list(&config, &config.xoptions,
Py_ARRAY_LENGTH(xoptions), xoptions);
@@ -1425,6 +1426,7 @@ static int test_init_read_set(void)
static int test_init_sys_add(void)
{
+ PySys_AddXOption(L"sysadd_xoption");
PySys_AddXOption(L"faulthandler");
PySys_AddWarnOption(L"ignore:::sysadd_warnoption");
@@ -1436,14 +1438,14 @@ static int test_init_sys_add(void)
L"-W",
L"ignore:::cmdline_warnoption",
L"-X",
- L"utf8",
+ L"cmdline_xoption",
};
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
PyStatus status;
status = PyWideStringList_Append(&config.xoptions,
- L"dev");
+ L"config_xoption");
if (PyStatus_Exception(status)) {
goto fail;
}
diff --git a/Python/initconfig.c b/Python/initconfig.c
index d31385039932b..3980b2140a0af 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -2046,49 +2046,6 @@ _PyConfig_InitImportConfig(PyConfig *config)
return config_init_import(config, 1);
}
-// List of known xoptions to validate against the provided ones. Note that all
-// options are listed, even if they are only available if a specific macro is
-// set, like -X showrefcount which requires a debug build. In this case unknown
-// options are silently ignored.
-const wchar_t* known_xoptions[] = {
- L"faulthandler",
- L"showrefcount",
- L"tracemalloc",
- L"importtime",
- L"dev",
- L"utf8",
- L"pycache_prefix",
- L"warn_default_encoding",
- L"no_debug_ranges",
- L"frozen_modules",
- NULL,
-};
-
-static const wchar_t*
-_Py_check_xoptions(const PyWideStringList *xoptions, const wchar_t **names)
-{
- for (Py_ssize_t i=0; i < xoptions->length; i++) {
- const wchar_t *option = xoptions->items[i];
- size_t len;
- wchar_t *sep = wcschr(option, L'=');
- if (sep != NULL) {
- len = (sep - option);
- }
- else {
- len = wcslen(option);
- }
- int found = 0;
- for (const wchar_t** name = names; *name != NULL; name++) {
- if (wcsncmp(option, *name, len) == 0 && (*name)[len] == L'\0') {
- found = 1;
- }
- }
- if (found == 0) {
- return option;
- }
- }
- return NULL;
-}
static PyStatus
config_read(PyConfig *config, int compute_path_config)
@@ -2104,11 +2061,6 @@ config_read(PyConfig *config, int compute_path_config)
}
/* -X options */
- const wchar_t* option = _Py_check_xoptions(&config->xoptions, known_xoptions);
- if (option != NULL) {
- return PyStatus_Error("Unknown value for option -X (see --help-xoptions)");
- }
-
if (config_get_xoption(config, L"showrefcount")) {
config->show_ref_count = 1;
}
1
0
[3.11] gh-95174: Handle missing dup() and constants in WASI (GH-95229) (GH-95272)
by pablogsal 31 Jul '22
by pablogsal 31 Jul '22
31 Jul '22
https://github.com/python/cpython/commit/db13c0c1b8bc8c15d920a94ca008aabea4…
commit: db13c0c1b8bc8c15d920a94ca008aabea4037697
branch: 3.11
author: Christian Heimes <christian(a)python.org>
committer: pablogsal <Pablogsal(a)gmail.com>
date: 2022-07-31T16:39:41+01:00
summary:
[3.11] gh-95174: Handle missing dup() and constants in WASI (GH-95229) (GH-95272)
Co-authored-by: Christian Heimes <christian(a)python.org>
files:
A Misc/NEWS.d/next/Build/2022-07-25-08-59-35.gh-issue-95174.g8woUW.rst
M Modules/clinic/posixmodule.c.h
M Modules/errnomodule.c
M Modules/posixmodule.c
M Modules/selectmodule.c
M Modules/socketmodule.c
M PC/pyconfig.h
M Python/dup2.c
M Python/fileutils.c
M configure
M configure.ac
M pyconfig.h.in
diff --git a/Misc/NEWS.d/next/Build/2022-07-25-08-59-35.gh-issue-95174.g8woUW.rst b/Misc/NEWS.d/next/Build/2022-07-25-08-59-35.gh-issue-95174.g8woUW.rst
new file mode 100644
index 0000000000000..05f29955072c5
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-07-25-08-59-35.gh-issue-95174.g8woUW.rst
@@ -0,0 +1,2 @@
+Python now detects missing ``dup`` function in WASI and works around some
+missing :mod:`errno`, :mod:`select`, and :mod:`socket` constants.
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index aaf3bf33b5352..ca2699b4e366a 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -4691,6 +4691,8 @@ os_dup(PyObject *module, PyObject *arg)
return return_value;
}
+#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
+
PyDoc_STRVAR(os_dup2__doc__,
"dup2($module, /, fd, fd2, inheritable=True)\n"
"--\n"
@@ -4746,6 +4748,8 @@ os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn
return return_value;
}
+#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
+
#if defined(HAVE_LOCKF)
PyDoc_STRVAR(os_lockf__doc__,
@@ -9123,6 +9127,10 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na
#define OS_TCSETPGRP_METHODDEF
#endif /* !defined(OS_TCSETPGRP_METHODDEF) */
+#ifndef OS_DUP2_METHODDEF
+ #define OS_DUP2_METHODDEF
+#endif /* !defined(OS_DUP2_METHODDEF) */
+
#ifndef OS_LOCKF_METHODDEF
#define OS_LOCKF_METHODDEF
#endif /* !defined(OS_LOCKF_METHODDEF) */
@@ -9370,4 +9378,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=2a53748bcf001a3f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3032d9c5c3aaa165 input=a9049054013a1b77]*/
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index bf6766e02349c..0516e7367050c 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -280,6 +280,10 @@ errno_exec(PyObject *module)
#ifdef ENOANO
add_errcode("ENOANO", ENOANO, "No anode");
#endif
+#if defined(__wasi__) && !defined(ESHUTDOWN)
+ // WASI SDK 16 does not have ESHUTDOWN, shutdown results in EPIPE.
+ #define ESHUTDOWN EPIPE
+#endif
#ifdef ESHUTDOWN
add_errcode("ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown");
#else
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index f97013fa7a9d0..378032501f9e8 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -9346,7 +9346,9 @@ os_dup_impl(PyObject *module, int fd)
return _Py_dup(fd);
}
-
+// dup2() is either provided by libc or dup2.c with AC_REPLACE_FUNCS().
+// dup2.c provides working dup2() if and only if F_DUPFD is available.
+#if (defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))
/*[clinic input]
os.dup2 -> int
fd: int
@@ -9446,6 +9448,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
return res;
}
+#endif
#ifdef HAVE_LOCKF
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 5c36eaaedeb70..4eea928a2683a 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -63,6 +63,11 @@ extern void bzero(void *, int);
# define SOCKET int
#endif
+// WASI SDK 16 does not have POLLPRIO, define as no-op
+#if defined(__wasi__) && !defined(POLLPRI)
+# define POLLPRI 0
+#endif
+
typedef struct {
PyObject *close;
PyTypeObject *poll_Type;
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 4e936e29a7cd9..7240739c7b3ba 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -7650,6 +7650,10 @@ PyInit__socket(void)
PyModule_AddIntMacro(m, MSG_EOR);
#endif
#ifdef MSG_TRUNC
+ // workaround for https://github.com/WebAssembly/wasi-libc/issues/305
+ #if defined(__wasi__) && !defined(__WASI_RIFLAGS_RECV_DATA_TRUNCATED)
+ # define __WASI_RIFLAGS_RECV_DATA_TRUNCATED 2
+ #endif
PyModule_AddIntMacro(m, MSG_TRUNC);
#endif
#ifdef MSG_CTRUNC
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index f71d5fe00d575..f1673a168ffb3 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -681,6 +681,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
/* Define if you have the 'inet_pton' function. */
#define HAVE_INET_PTON 1
+/* Define to 1 if you have the `dup' function. */
+#define HAVE_DUP 1
+
/* framework name */
#define _PYTHONFRAMEWORK ""
diff --git a/Python/dup2.c b/Python/dup2.c
index 7c6bbfce11dbf..a1df049209916 100644
--- a/Python/dup2.c
+++ b/Python/dup2.c
@@ -11,6 +11,7 @@
* Return fd2 if all went well; return BADEXIT otherwise.
*/
+#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
@@ -20,12 +21,17 @@ int
dup2(int fd1, int fd2)
{
if (fd1 != fd2) {
+#ifdef F_DUPFD
if (fcntl(fd1, F_GETFL) < 0)
return BADEXIT;
if (fcntl(fd2, F_GETFL) >= 0)
close(fd2);
if (fcntl(fd1, F_DUPFD, fd2) < 0)
return BADEXIT;
+#else
+ errno = ENOTSUP;
+ return BADEXIT;
+#endif
}
return fd2;
}
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 4f7f8944a72da..27924261f4396 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -2379,7 +2379,7 @@ _Py_dup(int fd)
return -1;
}
-#else
+#elif HAVE_DUP
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
fd = dup(fd);
@@ -2396,6 +2396,10 @@ _Py_dup(int fd)
_Py_END_SUPPRESS_IPH
return -1;
}
+#else
+ errno = ENOTSUP;
+ PyErr_SetFromErrno(PyExc_OSError);
+ return -1;
#endif
return fd;
}
diff --git a/configure b/configure
index 19316baa6ee12..39f7cd8eaec0a 100755
--- a/configure
+++ b/configure
@@ -14953,7 +14953,7 @@ fi
# checks for library functions
for ac_func in \
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
- copy_file_range ctermid dup3 execv explicit_bzero explicit_memset \
+ copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
diff --git a/configure.ac b/configure.ac
index f1fa570556235..60daab58d24b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4537,7 +4537,7 @@ fi
# checks for library functions
AC_CHECK_FUNCS([ \
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
- copy_file_range ctermid dup3 execv explicit_bzero explicit_memset \
+ copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 01928cbb33ad5..4aaa32c8b4336 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -278,6 +278,9 @@
/* Define to 1 if you have the `dlopen' function. */
#undef HAVE_DLOPEN
+/* Define to 1 if you have the `dup' function. */
+#undef HAVE_DUP
+
/* Define to 1 if you have the `dup2' function. */
#undef HAVE_DUP2
1
0
bpo-45445: Revert "bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)" (#94745)
by pablogsal 31 Jul '22
by pablogsal 31 Jul '22
31 Jul '22
https://github.com/python/cpython/commit/aa37ffda29ac48fb2df5a7029ba2e626ec…
commit: aa37ffda29ac48fb2df5a7029ba2e626ecc45850
branch: main
author: Pablo Galindo Salgado <Pablogsal(a)gmail.com>
committer: pablogsal <Pablogsal(a)gmail.com>
date: 2022-07-31T16:33:56+01:00
summary:
bpo-45445: Revert "bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)" (#94745)
files:
M Doc/library/sys.rst
M Lib/test/test_audit.py
M Lib/test/test_cmd_line.py
M Lib/test/test_embed.py
M Programs/_testembed.c
M Python/initconfig.c
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index e7ad6a6c67bd1..632ce627d86f9 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -1780,13 +1780,13 @@ always available.
.. code-block:: shell-session
- $ ./python -Xpycache_prefix=some_path -Xdev
+ $ ./python -Xa=b -Xc
Python 3.2a3+ (py3k, Oct 16 2010, 20:14:50)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys._xoptions
- {'pycache_prefix': 'some_path', 'dev': True}
+ {'a': 'b', 'c': True}
.. impl-detail::
diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py
index a7ff038c0936e..18426f27a2e32 100644
--- a/Lib/test/test_audit.py
+++ b/Lib/test/test_audit.py
@@ -20,7 +20,7 @@ class AuditTest(unittest.TestCase):
@support.requires_subprocess()
def do_test(self, *args):
with subprocess.Popen(
- [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
+ [sys.executable, "-X utf8", AUDIT_TESTS_PY, *args],
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
@@ -35,7 +35,7 @@ def do_test(self, *args):
def run_python(self, *args):
events = []
with subprocess.Popen(
- [sys.executable, "-Xutf8", AUDIT_TESTS_PY, *args],
+ [sys.executable, "-X utf8", AUDIT_TESTS_PY, *args],
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index bc52bbdb0f94d..64469763957a5 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -105,17 +105,8 @@ def get_xoptions(*args):
opts = get_xoptions()
self.assertEqual(opts, {})
- opts = get_xoptions('-Xno_debug_ranges', '-Xdev=1234')
- self.assertEqual(opts, {'no_debug_ranges': True, 'dev': '1234'})
-
- @unittest.skipIf(interpreter_requires_environment(),
- 'Cannot run -E tests when PYTHON env vars are required.')
- def test_unknown_xoptions(self):
- rc, out, err = assert_python_failure('-X', 'blech')
- self.assertIn(b'Unknown value for option -X', err)
- msg = b'Fatal Python error: Unknown value for option -X (see --help-xoptions)'
- self.assertEqual(err.splitlines().count(msg), 1)
- self.assertEqual(b'', out)
+ opts = get_xoptions('-Xa', '-Xb=c,d=e')
+ self.assertEqual(opts, {'a': True, 'b': 'c,d=e'})
def test_showrefcount(self):
def run_python(*args):
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index c7e5663566b06..c546bb08e297c 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -283,7 +283,7 @@ def test_pre_initialization_sys_options(self):
"test_pre_initialization_sys_options", env=env)
expected_output = (
"sys.warnoptions: ['once', 'module', 'default']\n"
- "sys._xoptions: {'dev': '2', 'utf8': '1'}\n"
+ "sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}\n"
"warnings.filters[:3]: ['default', 'module', 'once']\n"
)
self.assertIn(expected_output, out)
@@ -841,14 +841,15 @@ def test_init_from_config(self):
'argv': ['-c', 'arg2'],
'orig_argv': ['python3',
'-W', 'cmdline_warnoption',
- '-X', 'dev',
+ '-X', 'cmdline_xoption',
'-c', 'pass',
'arg2'],
'parse_argv': 2,
'xoptions': [
- 'dev=3',
- 'utf8',
- 'dev',
+ 'config_xoption1=3',
+ 'config_xoption2=',
+ 'config_xoption3',
+ 'cmdline_xoption',
],
'warnoptions': [
'cmdline_warnoption',
@@ -1076,8 +1077,9 @@ def test_init_sys_add(self):
config = {
'faulthandler': 1,
'xoptions': [
- 'dev',
- 'utf8',
+ 'config_xoption',
+ 'cmdline_xoption',
+ 'sysadd_xoption',
'faulthandler',
],
'warnoptions': [
@@ -1087,12 +1089,9 @@ def test_init_sys_add(self):
],
'orig_argv': ['python3',
'-W', 'ignore:::cmdline_warnoption',
- '-X', 'utf8'],
+ '-X', 'cmdline_xoption'],
}
- preconfig = {'utf8_mode': 1}
- self.check_all_configs("test_init_sys_add", config,
- expected_preconfig=preconfig,
- api=API_PYTHON)
+ self.check_all_configs("test_init_sys_add", config, api=API_PYTHON)
def test_init_run_main(self):
code = ('import _testinternalcapi, json; '
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 6b43d53403014..f84445690eb8f 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -279,7 +279,7 @@ static int test_pre_initialization_sys_options(void)
* relying on the caller to keep the passed in strings alive.
*/
const wchar_t *static_warnoption = L"once";
- const wchar_t *static_xoption = L"utf8=1";
+ const wchar_t *static_xoption = L"also_not_an_option=2";
size_t warnoption_len = wcslen(static_warnoption);
size_t xoption_len = wcslen(static_xoption);
wchar_t *dynamic_once_warnoption = \
@@ -298,7 +298,7 @@ static int test_pre_initialization_sys_options(void)
PySys_AddWarnOption(L"module");
PySys_AddWarnOption(L"default");
_Py_EMBED_PREINIT_CHECK("Checking PySys_AddXOption\n");
- PySys_AddXOption(L"dev=2");
+ PySys_AddXOption(L"not_an_option=1");
PySys_AddXOption(dynamic_xoption);
/* Delete the dynamic options early */
@@ -591,7 +591,7 @@ static int test_init_from_config(void)
L"-W",
L"cmdline_warnoption",
L"-X",
- L"dev",
+ L"cmdline_xoption",
L"-c",
L"pass",
L"arg2",
@@ -599,9 +599,10 @@ static int test_init_from_config(void)
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
- wchar_t* xoptions[2] = {
- L"dev=3",
- L"utf8",
+ wchar_t* xoptions[3] = {
+ L"config_xoption1=3",
+ L"config_xoption2=",
+ L"config_xoption3",
};
config_set_wide_string_list(&config, &config.xoptions,
Py_ARRAY_LENGTH(xoptions), xoptions);
@@ -1425,6 +1426,7 @@ static int test_init_read_set(void)
static int test_init_sys_add(void)
{
+ PySys_AddXOption(L"sysadd_xoption");
PySys_AddXOption(L"faulthandler");
PySys_AddWarnOption(L"ignore:::sysadd_warnoption");
@@ -1436,14 +1438,14 @@ static int test_init_sys_add(void)
L"-W",
L"ignore:::cmdline_warnoption",
L"-X",
- L"utf8",
+ L"cmdline_xoption",
};
config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
config.parse_argv = 1;
PyStatus status;
status = PyWideStringList_Append(&config.xoptions,
- L"dev");
+ L"config_xoption");
if (PyStatus_Exception(status)) {
goto fail;
}
diff --git a/Python/initconfig.c b/Python/initconfig.c
index d29c69345a2bb..70f0363297f3e 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -2061,49 +2061,6 @@ _PyConfig_InitImportConfig(PyConfig *config)
return config_init_import(config, 1);
}
-// List of known xoptions to validate against the provided ones. Note that all
-// options are listed, even if they are only available if a specific macro is
-// set, like -X showrefcount which requires a debug build. In this case unknown
-// options are silently ignored.
-const wchar_t* known_xoptions[] = {
- L"faulthandler",
- L"showrefcount",
- L"tracemalloc",
- L"importtime",
- L"dev",
- L"utf8",
- L"pycache_prefix",
- L"warn_default_encoding",
- L"no_debug_ranges",
- L"frozen_modules",
- NULL,
-};
-
-static const wchar_t*
-_Py_check_xoptions(const PyWideStringList *xoptions, const wchar_t **names)
-{
- for (Py_ssize_t i=0; i < xoptions->length; i++) {
- const wchar_t *option = xoptions->items[i];
- size_t len;
- wchar_t *sep = wcschr(option, L'=');
- if (sep != NULL) {
- len = (sep - option);
- }
- else {
- len = wcslen(option);
- }
- int found = 0;
- for (const wchar_t** name = names; *name != NULL; name++) {
- if (wcsncmp(option, *name, len) == 0 && (*name)[len] == L'\0') {
- found = 1;
- }
- }
- if (found == 0) {
- return option;
- }
- }
- return NULL;
-}
static PyStatus
config_read(PyConfig *config, int compute_path_config)
@@ -2119,11 +2076,6 @@ config_read(PyConfig *config, int compute_path_config)
}
/* -X options */
- const wchar_t* option = _Py_check_xoptions(&config->xoptions, known_xoptions);
- if (option != NULL) {
- return PyStatus_Error("Unknown value for option -X (see --help-xoptions)");
- }
-
if (config_get_xoption(config, L"showrefcount")) {
config->show_ref_count = 1;
}
1
0
[3.10] bpo-46053: Fix OSS audio support on NetBSD (GH-30065). (GH-95477)
by serhiy-storchaka 31 Jul '22
by serhiy-storchaka 31 Jul '22
31 Jul '22
https://github.com/python/cpython/commit/ae2496245774fd196948f61a064dd2c541…
commit: ae2496245774fd196948f61a064dd2c5410ed34f
branch: 3.10
author: Thomas Klausner <tk(a)giga.or.at>
committer: serhiy-storchaka <storchaka(a)gmail.com>
date: 2022-07-31T11:19:09+03:00
summary:
[3.10] bpo-46053: Fix OSS audio support on NetBSD (GH-30065). (GH-95477)
(cherry picked from commit 2e7e3c4c109928870c1e33d8af36b78e92895594)
Co-authored-by: Thomas Klausner <tk(a)giga.or.at>
files:
A Misc/NEWS.d/next/Library/2022-02-06-12-59-32.bpo-46053.sHFo3S.rst
M Modules/ossaudiodev.c
M setup.py
diff --git a/Misc/NEWS.d/next/Library/2022-02-06-12-59-32.bpo-46053.sHFo3S.rst b/Misc/NEWS.d/next/Library/2022-02-06-12-59-32.bpo-46053.sHFo3S.rst
new file mode 100644
index 0000000000000..ce375885792e8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-06-12-59-32.bpo-46053.sHFo3S.rst
@@ -0,0 +1 @@
+Fix OSS audio support on NetBSD.
diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c
index b22bd42dcaa6f..74960c0ad2478 100644
--- a/Modules/ossaudiodev.c
+++ b/Modules/ossaudiodev.c
@@ -1212,16 +1212,36 @@ PyInit_ossaudiodev(void)
/* Expose all the ioctl numbers for masochists who like to do this
stuff directly. */
+#ifdef SNDCTL_COPR_HALT
_EXPORT_INT(m, SNDCTL_COPR_HALT);
+#endif
+#ifdef SNDCTL_COPR_LOAD
_EXPORT_INT(m, SNDCTL_COPR_LOAD);
+#endif
+#ifdef SNDCTL_COPR_RCODE
_EXPORT_INT(m, SNDCTL_COPR_RCODE);
+#endif
+#ifdef SNDCTL_COPR_RCVMSG
_EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
+#endif
+#ifdef SNDCTL_COPR_RDATA
_EXPORT_INT(m, SNDCTL_COPR_RDATA);
+#endif
+#ifdef SNDCTL_COPR_RESET
_EXPORT_INT(m, SNDCTL_COPR_RESET);
+#endif
+#ifdef SNDCTL_COPR_RUN
_EXPORT_INT(m, SNDCTL_COPR_RUN);
+#endif
+#ifdef SNDCTL_COPR_SENDMSG
_EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
+#endif
+#ifdef SNDCTL_COPR_WCODE
_EXPORT_INT(m, SNDCTL_COPR_WCODE);
+#endif
+#ifdef SNDCTL_COPR_WDATA
_EXPORT_INT(m, SNDCTL_COPR_WDATA);
+#endif
#ifdef SNDCTL_DSP_BIND_CHANNEL
_EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
#endif
@@ -1268,46 +1288,104 @@ PyInit_ossaudiodev(void)
_EXPORT_INT(m, SNDCTL_DSP_STEREO);
_EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
_EXPORT_INT(m, SNDCTL_DSP_SYNC);
+#ifdef SNDCTL_FM_4OP_ENABLE
_EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
+#endif
+#ifdef SNDCTL_FM_LOAD_INSTR
_EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
+#endif
+#ifdef SNDCTL_MIDI_INFO
_EXPORT_INT(m, SNDCTL_MIDI_INFO);
+#endif
+#ifdef SNDCTL_MIDI_MPUCMD
_EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
+#endif
+#ifdef SNDCTL_MIDI_MPUMODE
_EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
+#endif
+#ifdef SNDCTL_MIDI_PRETIME
_EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
+#endif
+#ifdef SNDCTL_SEQ_CTRLRATE
_EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
+#endif
+#ifdef SNDCTL_SEQ_GETINCOUNT
_EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
+#endif
+#ifdef SNDCTL_SEQ_GETOUTCOUNT
_EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
+#endif
#ifdef SNDCTL_SEQ_GETTIME
_EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
#endif
+#ifdef SNDCTL_SEQ_NRMIDIS
_EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
+#endif
+#ifdef SNDCTL_SEQ_NRSYNTHS
_EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
+#endif
+#ifdef SNDCTL_SEQ_OUTOFBAND
_EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
+#endif
+#ifdef SNDCTL_SEQ_PANIC
_EXPORT_INT(m, SNDCTL_SEQ_PANIC);
+#endif
+#ifdef SNDCTL_SEQ_PERCMODE
_EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
+#endif
+#ifdef SNDCTL_SEQ_RESET
_EXPORT_INT(m, SNDCTL_SEQ_RESET);
+#endif
+#ifdef SNDCTL_SEQ_RESETSAMPLES
_EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
+#endif
+#ifdef SNDCTL_SEQ_SYNC
_EXPORT_INT(m, SNDCTL_SEQ_SYNC);
+#endif
+#ifdef SNDCTL_SEQ_TESTMIDI
_EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
+#endif
+#ifdef SNDCTL_SEQ_THRESHOLD
_EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
+#endif
#ifdef SNDCTL_SYNTH_CONTROL
_EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
#endif
#ifdef SNDCTL_SYNTH_ID
_EXPORT_INT(m, SNDCTL_SYNTH_ID);
#endif
+#ifdef SNDCTL_SYNTH_INFO
_EXPORT_INT(m, SNDCTL_SYNTH_INFO);
+#endif
+#ifdef SNDCTL_SYNTH_MEMAVL
_EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
+#endif
#ifdef SNDCTL_SYNTH_REMOVESAMPLE
_EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
#endif
+#ifdef SNDCTL_TMR_CONTINUE
_EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
+#endif
+#ifdef SNDCTL_TMR_METRONOME
_EXPORT_INT(m, SNDCTL_TMR_METRONOME);
+#endif
+#ifdef SNDCTL_TMR_SELECT
_EXPORT_INT(m, SNDCTL_TMR_SELECT);
+#endif
+#ifdef SNDCTL_TMR_SOURCE
_EXPORT_INT(m, SNDCTL_TMR_SOURCE);
+#endif
+#ifdef SNDCTL_TMR_START
_EXPORT_INT(m, SNDCTL_TMR_START);
+#endif
+#ifdef SNDCTL_TMR_STOP
_EXPORT_INT(m, SNDCTL_TMR_STOP);
+#endif
+#ifdef SNDCTL_TMR_TEMPO
_EXPORT_INT(m, SNDCTL_TMR_TEMPO);
+#endif
+#ifdef SNDCTL_TMR_TIMEBASE
_EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
+#endif
return m;
}
diff --git a/setup.py b/setup.py
index 4894adfc8215c..85a2b26357db4 100644
--- a/setup.py
+++ b/setup.py
@@ -1663,6 +1663,9 @@ def detect_platform_specific_exts(self):
# Platform-specific libraries
if HOST_PLATFORM.startswith(('linux', 'freebsd', 'gnukfreebsd')):
self.add(Extension('ossaudiodev', ['ossaudiodev.c']))
+ elif HOST_PLATFORM.startswith(('netbsd')):
+ self.add(Extension('ossaudiodev', ['ossaudiodev.c'],
+ libraries=["ossaudio"]))
elif not AIX:
self.missing.append('ossaudiodev')
1
0
[3.10] gh-94635: Add Reference, How-to, and Explanation headings to sqlite3 docs (GH-94636) (#95483)
by erlend-aasland 31 Jul '22
by erlend-aasland 31 Jul '22
31 Jul '22
https://github.com/python/cpython/commit/6765a784a7d3f0b96410baeb34ccd35047…
commit: 6765a784a7d3f0b96410baeb34ccd350474bf051
branch: 3.10
author: Erlend Egeberg Aasland <erlend.aasland(a)protonmail.com>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2022-07-31T08:47:53+02:00
summary:
[3.10] gh-94635: Add Reference, How-to, and Explanation headings to sqlite3 docs (GH-94636) (#95483)
Co-authored-by: CAM Gerlach <CAM.Gerlach(a)Gerlach.CAM>.
(cherry picked from commit 6c439b978bf55b29f21c595e9375202d63c8208d)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland(a)protonmail.com>
* Fix refs
files:
M Doc/library/sqlite3.rst
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index e68aa4055680e..2b08040a00e64 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -25,6 +25,15 @@ The sqlite3 module was written by Gerhard Häring. It provides an SQL interface
compliant with the DB-API 2.0 specification described by :pep:`249`, and
requires SQLite 3.7.15 or newer.
+This document includes four main sections:
+
+* :ref:`sqlite3-tutorial` teaches how to use the sqlite3 module.
+* :ref:`sqlite3-reference` describes the classes and functions this module
+ defines.
+* :ref:`sqlite3-howtos` details how to handle specific tasks.
+* :ref:`sqlite3-explanation` provides in-depth background on
+ transaction control.
+
.. _sqlite3-tutorial:
@@ -136,10 +145,15 @@ both styles:
PEP written by Marc-André Lemburg.
+.. _sqlite3-reference:
+
+Reference
+---------
+
.. _sqlite3-module-contents:
Module functions and constants
-------------------------------
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. data:: apilevel
@@ -375,8 +389,8 @@ Module functions and constants
.. _sqlite3-connection-objects:
-Connection Objects
-------------------
+Connection objects
+^^^^^^^^^^^^^^^^^^
.. class:: Connection
@@ -773,8 +787,8 @@ Connection Objects
.. _sqlite3-cursor-objects:
-Cursor Objects
---------------
+Cursor objects
+^^^^^^^^^^^^^^
A ``Cursor`` object represents a `database cursor`_
which is used to execute SQL statements,
@@ -950,8 +964,8 @@ Cursor Objects
.. _sqlite3-row-objects:
-Row Objects
------------
+Row objects
+^^^^^^^^^^^
.. class:: Row
@@ -1013,8 +1027,8 @@ Now we plug :class:`Row` in::
35.14
-PrepareProtocol Objects
------------------------
+PrepareProtocol objects
+^^^^^^^^^^^^^^^^^^^^^^^
.. class:: PrepareProtocol
@@ -1026,7 +1040,7 @@ PrepareProtocol Objects
.. _sqlite3-exceptions:
Exceptions
-----------
+^^^^^^^^^^
The exception hierarchy is defined by the DB-API 2.0 (:pep:`249`).
@@ -1101,11 +1115,7 @@ The exception hierarchy is defined by the DB-API 2.0 (:pep:`249`).
.. _sqlite3-types:
SQLite and Python types
------------------------
-
-
-Introduction
-^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^^^
SQLite natively supports the following types: ``NULL``, ``INTEGER``,
``REAL``, ``TEXT``, ``BLOB``.
@@ -1145,10 +1155,18 @@ This is how SQLite types are converted to Python types by default:
+-------------+----------------------------------------------+
The type system of the :mod:`sqlite3` module is extensible in two ways: you can
-store additional Python types in an SQLite database via object adaptation, and
-you can let the :mod:`sqlite3` module convert SQLite types to different Python
-types via converters.
+store additional Python types in an SQLite database via
+:ref:`object adapters <sqlite3-adapters>`,
+and you can let the ``sqlite3`` module convert SQLite types to
+Python types via :ref:`converters <sqlite3-converters>`.
+
+
+.. _sqlite3-howtos:
+How-to guides
+-------------
+
+.. _sqlite3-adapters:
Using adapters to store custom Python types in SQLite databases
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1192,6 +1210,8 @@ This function can then be registered using :func:`register_adapter`.
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
+.. _sqlite3-converters:
+
Converting SQLite values to custom Python types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1264,7 +1284,7 @@ timestamp converter.
.. _sqlite3-adapter-converter-recipes:
-Adapter and Converter Recipes
+Adapter and converter recipes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This section shows recipes for common adapters and converters.
@@ -1307,83 +1327,6 @@ This section shows recipes for common adapters and converters.
sqlite3.register_converter("timestamp", convert_timestamp)
-.. _sqlite3-controlling-transactions:
-
-Controlling Transactions
-------------------------
-
-The ``sqlite3`` module does not adhere to the transaction handling recommended
-by :pep:`249`.
-
-If the connection attribute :attr:`~Connection.isolation_level`
-is not :const:`None`,
-new transactions are implicitly opened before
-:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
-``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements.
-Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
-to respectively commit and roll back pending transactions.
-You can choose the underlying `SQLite transaction behaviour`_ —
-that is, whether and what type of ``BEGIN`` statements ``sqlite3``
-implicitly executes –
-via the :attr:`~Connection.isolation_level` attribute.
-
-If :attr:`~Connection.isolation_level` is set to :const:`None`,
-no transactions are implicitly opened at all.
-This leaves the underlying SQLite library in `autocommit mode`_,
-but also allows the user to perform their own transaction handling
-using explicit SQL statements.
-The underlying SQLite library autocommit mode can be queried using the
-:attr:`~Connection.in_transaction` attribute.
-
-The :meth:`~Cursor.executescript` method implicitly commits
-any pending transaction before execution of the given SQL script,
-regardless of the value of :attr:`~Connection.isolation_level`.
-
-.. versionchanged:: 3.6
- :mod:`sqlite3` used to implicitly commit an open transaction before DDL
- statements. This is no longer the case.
-
-.. _autocommit mode:
- https://www.sqlite.org/lang_transaction.html#implicit_versus_explicit_trans…
-
-.. _SQLite transaction behaviour:
- https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusi…
-
-
-.. _sqlite3-uri-tricks:
-
-SQLite URI tricks
------------------
-
-Some useful URI tricks include:
-
-* Open a database in read-only mode::
-
- con = sqlite3.connect("file:template.db?mode=ro", uri=True)
-
-* Do not implicitly create a new database file if it does not already exist;
- will raise :exc:`~sqlite3.OperationalError` if unable to create a new file::
-
- con = sqlite3.connect("file:nosuchdb.db?mode=rw", uri=True)
-
-* Create a shared named in-memory database::
-
- con1 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
- con2 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
- con1.execute("create table t(t)")
- con1.execute("insert into t values(28)")
- con1.commit()
- rows = con2.execute("select * from t").fetchall()
-
-More information about this feature, including a list of parameters,
-can be found in the `SQLite URI documentation`_.
-
-.. _SQLite URI documentation: https://www.sqlite.org/uri.html
-
-Using :mod:`sqlite3` efficiently
---------------------------------
-
-
.. _sqlite3-connection-shortcuts:
Using connection shortcut methods
@@ -1401,6 +1344,8 @@ directly using only a single call on the :class:`Connection` object.
.. literalinclude:: ../includes/sqlite3/shortcut_methods.py
+.. _sqlite3-columns-by-name:
+
Accessing columns by name instead of by index
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1436,3 +1381,82 @@ the context manager is a no-op.
nor closes the connection.
.. literalinclude:: ../includes/sqlite3/ctx_manager.py
+
+
+.. _sqlite3-uri-tricks:
+
+Working with SQLite URIs
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Some useful URI tricks include:
+
+* Open a database in read-only mode::
+
+ con = sqlite3.connect("file:template.db?mode=ro", uri=True)
+
+* Do not implicitly create a new database file if it does not already exist;
+ will raise :exc:`~sqlite3.OperationalError` if unable to create a new file::
+
+ con = sqlite3.connect("file:nosuchdb.db?mode=rw", uri=True)
+
+* Create a shared named in-memory database::
+
+ con1 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
+ con2 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
+ con1.execute("create table t(t)")
+ con1.execute("insert into t values(28)")
+ con1.commit()
+ rows = con2.execute("select * from t").fetchall()
+
+More information about this feature, including a list of parameters,
+can be found in the `SQLite URI documentation`_.
+
+.. _SQLite URI documentation: https://www.sqlite.org/uri.html
+
+
+.. _sqlite3-explanation:
+
+Explanation
+-----------
+
+.. _sqlite3-controlling-transactions:
+
+Transaction control
+^^^^^^^^^^^^^^^^^^^
+
+The ``sqlite3`` module does not adhere to the transaction handling recommended
+by :pep:`249`.
+
+If the connection attribute :attr:`~Connection.isolation_level`
+is not :const:`None`,
+new transactions are implicitly opened before
+:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
+``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements.
+Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
+to respectively commit and roll back pending transactions.
+You can choose the underlying `SQLite transaction behaviour`_ —
+that is, whether and what type of ``BEGIN`` statements ``sqlite3``
+implicitly executes –
+via the :attr:`~Connection.isolation_level` attribute.
+
+If :attr:`~Connection.isolation_level` is set to :const:`None`,
+no transactions are implicitly opened at all.
+This leaves the underlying SQLite library in `autocommit mode`_,
+but also allows the user to perform their own transaction handling
+using explicit SQL statements.
+The underlying SQLite library autocommit mode can be queried using the
+:attr:`~Connection.in_transaction` attribute.
+
+The :meth:`~Cursor.executescript` method implicitly commits
+any pending transaction before execution of the given SQL script,
+regardless of the value of :attr:`~Connection.isolation_level`.
+
+.. versionchanged:: 3.6
+ :mod:`sqlite3` used to implicitly commit an open transaction before DDL
+ statements. This is no longer the case.
+
+.. _autocommit mode:
+ https://www.sqlite.org/lang_transaction.html#implicit_versus_explicit_trans…
+
+.. _SQLite transaction behaviour:
+ https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusi…
1
0
[3.11] gh-94635: Add Reference, How-to, and Explanation headings to sqlite3 docs (GH-94636) (#95482)
by erlend-aasland 31 Jul '22
by erlend-aasland 31 Jul '22
31 Jul '22
https://github.com/python/cpython/commit/c7ac8b65884a79e6a976811bca10527613…
commit: c7ac8b65884a79e6a976811bca10527613b1396a
branch: 3.11
author: Erlend Egeberg Aasland <erlend.aasland(a)protonmail.com>
committer: erlend-aasland <erlend.aasland(a)protonmail.com>
date: 2022-07-31T08:48:13+02:00
summary:
[3.11] gh-94635: Add Reference, How-to, and Explanation headings to sqlite3 docs (GH-94636) (#95482)
Co-authored-by: CAM Gerlach <CAM.Gerlach(a)Gerlach.CAM>.
(cherry picked from commit 6c439b978bf55b29f21c595e9375202d63c8208d)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland(a)protonmail.com>
* Fix refs
files:
M Doc/library/sqlite3.rst
diff --git a/Doc/library/sqlite3.rst b/Doc/library/sqlite3.rst
index 9437bafa5a281..332e3b0b79a1e 100644
--- a/Doc/library/sqlite3.rst
+++ b/Doc/library/sqlite3.rst
@@ -25,6 +25,15 @@ The sqlite3 module was written by Gerhard Häring. It provides an SQL interface
compliant with the DB-API 2.0 specification described by :pep:`249`, and
requires SQLite 3.7.15 or newer.
+This document includes four main sections:
+
+* :ref:`sqlite3-tutorial` teaches how to use the sqlite3 module.
+* :ref:`sqlite3-reference` describes the classes and functions this module
+ defines.
+* :ref:`sqlite3-howtos` details how to handle specific tasks.
+* :ref:`sqlite3-explanation` provides in-depth background on
+ transaction control.
+
.. _sqlite3-tutorial:
@@ -136,10 +145,15 @@ both styles:
PEP written by Marc-André Lemburg.
+.. _sqlite3-reference:
+
+Reference
+---------
+
.. _sqlite3-module-contents:
Module functions and constants
-------------------------------
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. data:: apilevel
@@ -411,8 +425,8 @@ Module functions and constants
.. _sqlite3-connection-objects:
-Connection Objects
-------------------
+Connection objects
+^^^^^^^^^^^^^^^^^^
.. class:: Connection
@@ -972,8 +986,8 @@ Connection Objects
.. _sqlite3-cursor-objects:
-Cursor Objects
---------------
+Cursor objects
+^^^^^^^^^^^^^^
A ``Cursor`` object represents a `database cursor`_
which is used to execute SQL statements,
@@ -1149,8 +1163,8 @@ Cursor Objects
.. _sqlite3-row-objects:
-Row Objects
------------
+Row objects
+^^^^^^^^^^^
.. class:: Row
@@ -1212,8 +1226,10 @@ Now we plug :class:`Row` in::
35.14
-Blob Objects
-------------
+.. _sqlite3-blob-objects:
+
+Blob objects
+^^^^^^^^^^^^
.. versionadded:: 3.11
@@ -1264,8 +1280,8 @@ Blob Objects
end).
-PrepareProtocol Objects
------------------------
+PrepareProtocol objects
+^^^^^^^^^^^^^^^^^^^^^^^
.. class:: PrepareProtocol
@@ -1277,7 +1293,7 @@ PrepareProtocol Objects
.. _sqlite3-exceptions:
Exceptions
-----------
+^^^^^^^^^^
The exception hierarchy is defined by the DB-API 2.0 (:pep:`249`).
@@ -1364,16 +1380,10 @@ The exception hierarchy is defined by the DB-API 2.0 (:pep:`249`).
``NotSupportedError`` is a subclass of :exc:`DatabaseError`.
-.. _sqlite3-blob-objects:
-
.. _sqlite3-types:
SQLite and Python types
------------------------
-
-
-Introduction
-^^^^^^^^^^^^
+^^^^^^^^^^^^^^^^^^^^^^^
SQLite natively supports the following types: ``NULL``, ``INTEGER``,
``REAL``, ``TEXT``, ``BLOB``.
@@ -1413,10 +1423,18 @@ This is how SQLite types are converted to Python types by default:
+-------------+----------------------------------------------+
The type system of the :mod:`sqlite3` module is extensible in two ways: you can
-store additional Python types in an SQLite database via object adaptation, and
-you can let the :mod:`sqlite3` module convert SQLite types to different Python
-types via converters.
+store additional Python types in an SQLite database via
+:ref:`object adapters <sqlite3-adapters>`,
+and you can let the ``sqlite3`` module convert SQLite types to
+Python types via :ref:`converters <sqlite3-converters>`.
+
+.. _sqlite3-howtos:
+
+How-to guides
+-------------
+
+.. _sqlite3-adapters:
Using adapters to store custom Python types in SQLite databases
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1460,6 +1478,8 @@ This function can then be registered using :func:`register_adapter`.
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
+.. _sqlite3-converters:
+
Converting SQLite values to custom Python types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1532,7 +1552,7 @@ timestamp converter.
.. _sqlite3-adapter-converter-recipes:
-Adapter and Converter Recipes
+Adapter and converter recipes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This section shows recipes for common adapters and converters.
@@ -1575,83 +1595,6 @@ This section shows recipes for common adapters and converters.
sqlite3.register_converter("timestamp", convert_timestamp)
-.. _sqlite3-controlling-transactions:
-
-Controlling Transactions
-------------------------
-
-The ``sqlite3`` module does not adhere to the transaction handling recommended
-by :pep:`249`.
-
-If the connection attribute :attr:`~Connection.isolation_level`
-is not :const:`None`,
-new transactions are implicitly opened before
-:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
-``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements.
-Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
-to respectively commit and roll back pending transactions.
-You can choose the underlying `SQLite transaction behaviour`_ —
-that is, whether and what type of ``BEGIN`` statements ``sqlite3``
-implicitly executes –
-via the :attr:`~Connection.isolation_level` attribute.
-
-If :attr:`~Connection.isolation_level` is set to :const:`None`,
-no transactions are implicitly opened at all.
-This leaves the underlying SQLite library in `autocommit mode`_,
-but also allows the user to perform their own transaction handling
-using explicit SQL statements.
-The underlying SQLite library autocommit mode can be queried using the
-:attr:`~Connection.in_transaction` attribute.
-
-The :meth:`~Cursor.executescript` method implicitly commits
-any pending transaction before execution of the given SQL script,
-regardless of the value of :attr:`~Connection.isolation_level`.
-
-.. versionchanged:: 3.6
- :mod:`sqlite3` used to implicitly commit an open transaction before DDL
- statements. This is no longer the case.
-
-.. _autocommit mode:
- https://www.sqlite.org/lang_transaction.html#implicit_versus_explicit_trans…
-
-.. _SQLite transaction behaviour:
- https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusi…
-
-
-.. _sqlite3-uri-tricks:
-
-SQLite URI tricks
------------------
-
-Some useful URI tricks include:
-
-* Open a database in read-only mode::
-
- con = sqlite3.connect("file:template.db?mode=ro", uri=True)
-
-* Do not implicitly create a new database file if it does not already exist;
- will raise :exc:`~sqlite3.OperationalError` if unable to create a new file::
-
- con = sqlite3.connect("file:nosuchdb.db?mode=rw", uri=True)
-
-* Create a shared named in-memory database::
-
- con1 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
- con2 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
- con1.execute("create table t(t)")
- con1.execute("insert into t values(28)")
- con1.commit()
- rows = con2.execute("select * from t").fetchall()
-
-More information about this feature, including a list of parameters,
-can be found in the `SQLite URI documentation`_.
-
-.. _SQLite URI documentation: https://www.sqlite.org/uri.html
-
-Using :mod:`sqlite3` efficiently
---------------------------------
-
-
.. _sqlite3-connection-shortcuts:
Using connection shortcut methods
@@ -1669,6 +1612,8 @@ directly using only a single call on the :class:`Connection` object.
.. literalinclude:: ../includes/sqlite3/shortcut_methods.py
+.. _sqlite3-columns-by-name:
+
Accessing columns by name instead of by index
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1704,3 +1649,82 @@ the context manager is a no-op.
nor closes the connection.
.. literalinclude:: ../includes/sqlite3/ctx_manager.py
+
+
+.. _sqlite3-uri-tricks:
+
+Working with SQLite URIs
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Some useful URI tricks include:
+
+* Open a database in read-only mode::
+
+ con = sqlite3.connect("file:template.db?mode=ro", uri=True)
+
+* Do not implicitly create a new database file if it does not already exist;
+ will raise :exc:`~sqlite3.OperationalError` if unable to create a new file::
+
+ con = sqlite3.connect("file:nosuchdb.db?mode=rw", uri=True)
+
+* Create a shared named in-memory database::
+
+ con1 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
+ con2 = sqlite3.connect("file:mem1?mode=memory&cache=shared", uri=True)
+ con1.execute("create table t(t)")
+ con1.execute("insert into t values(28)")
+ con1.commit()
+ rows = con2.execute("select * from t").fetchall()
+
+More information about this feature, including a list of parameters,
+can be found in the `SQLite URI documentation`_.
+
+.. _SQLite URI documentation: https://www.sqlite.org/uri.html
+
+
+.. _sqlite3-explanation:
+
+Explanation
+-----------
+
+.. _sqlite3-controlling-transactions:
+
+Transaction control
+^^^^^^^^^^^^^^^^^^^
+
+The ``sqlite3`` module does not adhere to the transaction handling recommended
+by :pep:`249`.
+
+If the connection attribute :attr:`~Connection.isolation_level`
+is not :const:`None`,
+new transactions are implicitly opened before
+:meth:`~Cursor.execute` and :meth:`~Cursor.executemany` executes
+``INSERT``, ``UPDATE``, ``DELETE``, or ``REPLACE`` statements.
+Use the :meth:`~Connection.commit` and :meth:`~Connection.rollback` methods
+to respectively commit and roll back pending transactions.
+You can choose the underlying `SQLite transaction behaviour`_ —
+that is, whether and what type of ``BEGIN`` statements ``sqlite3``
+implicitly executes –
+via the :attr:`~Connection.isolation_level` attribute.
+
+If :attr:`~Connection.isolation_level` is set to :const:`None`,
+no transactions are implicitly opened at all.
+This leaves the underlying SQLite library in `autocommit mode`_,
+but also allows the user to perform their own transaction handling
+using explicit SQL statements.
+The underlying SQLite library autocommit mode can be queried using the
+:attr:`~Connection.in_transaction` attribute.
+
+The :meth:`~Cursor.executescript` method implicitly commits
+any pending transaction before execution of the given SQL script,
+regardless of the value of :attr:`~Connection.isolation_level`.
+
+.. versionchanged:: 3.6
+ :mod:`sqlite3` used to implicitly commit an open transaction before DDL
+ statements. This is no longer the case.
+
+.. _autocommit mode:
+ https://www.sqlite.org/lang_transaction.html#implicit_versus_explicit_trans…
+
+.. _SQLite transaction behaviour:
+ https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusi…
1
0