mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
Add sys.getandroidapilevel()
Issue #28740: Add sys.getandroidapilevel(): return the build time API version of Android as an integer. Function only available on Android.
This commit is contained in:
parent
edfe8869c8
commit
d6958ac6c0
5 changed files with 44 additions and 2 deletions
|
|
@ -404,6 +404,15 @@ always available.
|
||||||
.. versionadded:: 3.4
|
.. versionadded:: 3.4
|
||||||
|
|
||||||
|
|
||||||
|
.. function:: getandroidapilevel()
|
||||||
|
|
||||||
|
Return the build time API version of Android as an integer.
|
||||||
|
|
||||||
|
Availability: Android.
|
||||||
|
|
||||||
|
.. versionadded:: 3.7
|
||||||
|
|
||||||
|
|
||||||
.. function:: getcheckinterval()
|
.. function:: getcheckinterval()
|
||||||
|
|
||||||
Return the interpreter's "check interval"; see :func:`setcheckinterval`.
|
Return the interpreter's "check interval"; see :func:`setcheckinterval`.
|
||||||
|
|
|
||||||
|
|
@ -766,8 +766,13 @@ requires_lzma = unittest.skipUnless(lzma, 'requires lzma')
|
||||||
|
|
||||||
is_jython = sys.platform.startswith('java')
|
is_jython = sys.platform.startswith('java')
|
||||||
|
|
||||||
_ANDROID_API_LEVEL = sysconfig.get_config_var('ANDROID_API_LEVEL')
|
try:
|
||||||
is_android = (_ANDROID_API_LEVEL is not None and _ANDROID_API_LEVEL > 0)
|
# constant used by requires_android_level()
|
||||||
|
_ANDROID_API_LEVEL = sys.getandroidapilevel()
|
||||||
|
is_android = True
|
||||||
|
except AttributeError:
|
||||||
|
# sys.getandroidapilevel() is only available on Android
|
||||||
|
is_android = False
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
|
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
|
||||||
|
|
|
||||||
|
|
@ -826,6 +826,13 @@ class SysModuleTest(unittest.TestCase):
|
||||||
rc, stdout, stderr = assert_python_ok('-c', code)
|
rc, stdout, stderr = assert_python_ok('-c', code)
|
||||||
self.assertEqual(stdout.rstrip(), b'True')
|
self.assertEqual(stdout.rstrip(), b'True')
|
||||||
|
|
||||||
|
@unittest.skipUnless(hasattr(sys, 'getandroidapilevel'),
|
||||||
|
'need sys.getandroidapilevel()')
|
||||||
|
def test_getandroidapilevel(self):
|
||||||
|
level = sys.getandroidapilevel()
|
||||||
|
self.assertIsInstance(level, int)
|
||||||
|
self.assertGreater(level, 0)
|
||||||
|
|
||||||
|
|
||||||
@test.support.cpython_only
|
@test.support.cpython_only
|
||||||
class SizeofTest(unittest.TestCase):
|
class SizeofTest(unittest.TestCase):
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #28740: Add sys.getandroidapilevel(): return the build time API version
|
||||||
|
of Android as an integer. Function only available on Android.
|
||||||
|
|
||||||
- Issue #26273: Add new :data:`socket.TCP_CONGESTION` (Linux 2.6.13) and
|
- Issue #26273: Add new :data:`socket.TCP_CONGESTION` (Linux 2.6.13) and
|
||||||
:data:`socket.TCP_USER_TIMEOUT` (Linux 2.6.37) constants. Patch written by
|
:data:`socket.TCP_USER_TIMEOUT` (Linux 2.6.37) constants. Patch written by
|
||||||
Omar Sandoval.
|
Omar Sandoval.
|
||||||
|
|
|
||||||
|
|
@ -1363,6 +1363,20 @@ PyDoc_STRVAR(is_finalizing_doc,
|
||||||
Return True if Python is exiting.");
|
Return True if Python is exiting.");
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ANDROID_API_LEVEL
|
||||||
|
PyDoc_STRVAR(getandroidapilevel_doc,
|
||||||
|
"getandroidapilevel()\n\
|
||||||
|
\n\
|
||||||
|
Return the build time API version of Android as an integer.");
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
sys_getandroidapilevel(PyObject *self)
|
||||||
|
{
|
||||||
|
return PyLong_FromLong(ANDROID_API_LEVEL);
|
||||||
|
}
|
||||||
|
#endif /* ANDROID_API_LEVEL */
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef sys_methods[] = {
|
static PyMethodDef sys_methods[] = {
|
||||||
/* Might as well keep this in alphabetic order */
|
/* Might as well keep this in alphabetic order */
|
||||||
{"callstats", (PyCFunction)sys_callstats, METH_NOARGS,
|
{"callstats", (PyCFunction)sys_callstats, METH_NOARGS,
|
||||||
|
|
@ -1447,6 +1461,10 @@ static PyMethodDef sys_methods[] = {
|
||||||
METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc},
|
METH_VARARGS | METH_KEYWORDS, set_asyncgen_hooks_doc},
|
||||||
{"get_asyncgen_hooks", sys_get_asyncgen_hooks, METH_NOARGS,
|
{"get_asyncgen_hooks", sys_get_asyncgen_hooks, METH_NOARGS,
|
||||||
get_asyncgen_hooks_doc},
|
get_asyncgen_hooks_doc},
|
||||||
|
#ifdef ANDROID_API_LEVEL
|
||||||
|
{"getandroidapilevel", (PyCFunction)sys_getandroidapilevel, METH_NOARGS,
|
||||||
|
getandroidapilevel_doc},
|
||||||
|
#endif
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue