cpython/Doc/library/platform.rst

276 lines
8.9 KiB
ReStructuredText
Raw Normal View History

Merged revisions 73286,73294,73296,73459,73462-73463,73544,73576-73577,73595-73596,73693-73694,73704-73705,73707,73713,73937-73940,73945,73951,73979 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r73286 | georg.brandl | 2009-06-08 09:57:35 +0200 (Mo, 08 Jun 2009) | 1 line Remove period from end of headings. ........ r73294 | georg.brandl | 2009-06-08 15:34:52 +0200 (Mo, 08 Jun 2009) | 1 line #6194: O_SHLOCK/O_EXLOCK are not really more platform independent than lockf(). ........ r73296 | georg.brandl | 2009-06-08 18:03:41 +0200 (Mo, 08 Jun 2009) | 1 line #6238: add fillchar to string.just function family. ........ r73459 | raymond.hettinger | 2009-06-17 03:43:47 +0200 (Mi, 17 Jun 2009) | 1 line Add usage note. ........ r73462 | georg.brandl | 2009-06-17 11:36:21 +0200 (Mi, 17 Jun 2009) | 1 line #6295: clarify blocking behavior of getch(). ........ r73463 | georg.brandl | 2009-06-17 11:43:31 +0200 (Mi, 17 Jun 2009) | 1 line #6255: document PyInt_FromSize_t. ........ r73544 | georg.brandl | 2009-06-24 08:41:19 +0200 (Mi, 24 Jun 2009) | 1 line #6332: fix word dupes throughout the source. ........ r73576 | benjamin.peterson | 2009-06-27 01:37:06 +0200 (Sa, 27 Jun 2009) | 1 line document is_declared_global() ........ r73577 | benjamin.peterson | 2009-06-27 16:16:23 +0200 (Sa, 27 Jun 2009) | 1 line link to extensive generator docs in the reference manual ........ r73595 | ezio.melotti | 2009-06-28 01:45:39 +0200 (So, 28 Jun 2009) | 1 line stmt and setup can contain multiple statements, see #5896 ........ r73596 | ezio.melotti | 2009-06-28 02:07:45 +0200 (So, 28 Jun 2009) | 1 line Fixed a wrong apostrophe ........ r73693 | jesse.noller | 2009-06-29 20:20:34 +0200 (Mo, 29 Jun 2009) | 1 line Bug 5906: add a documentation note for unix daemons vs. multiprocessing daemons ........ r73694 | jesse.noller | 2009-06-29 20:24:26 +0200 (Mo, 29 Jun 2009) | 1 line Issue 5740: multiprocessing.connection.* authkey fixes ........ r73704 | georg.brandl | 2009-06-30 18:15:43 +0200 (Di, 30 Jun 2009) | 1 line #6376: fix copy-n-paste oversight. ........ r73705 | georg.brandl | 2009-06-30 18:17:28 +0200 (Di, 30 Jun 2009) | 1 line #6374: add a bit of explanation about shell=True on Windows. ........ r73707 | georg.brandl | 2009-06-30 18:35:11 +0200 (Di, 30 Jun 2009) | 1 line #6371: fix link targets. ........ r73713 | ezio.melotti | 2009-07-01 00:56:16 +0200 (Mi, 01 Jul 2009) | 1 line Fixed a backslash that was not supposed to be there ........ r73937 | georg.brandl | 2009-07-11 12:12:36 +0200 (Sa, 11 Jul 2009) | 1 line Fix style. ........ r73938 | georg.brandl | 2009-07-11 12:14:54 +0200 (Sa, 11 Jul 2009) | 1 line #6446: fix import_spam() function to use correct error and reference handling. ........ r73939 | georg.brandl | 2009-07-11 12:18:10 +0200 (Sa, 11 Jul 2009) | 1 line #6448: clarify docs for find_module(). ........ r73940 | georg.brandl | 2009-07-11 12:37:38 +0200 (Sa, 11 Jul 2009) | 1 line #6430: add note about size of "u" type. ........ r73945 | georg.brandl | 2009-07-11 12:51:31 +0200 (Sa, 11 Jul 2009) | 1 line #6456: clarify the meaning of constants used as arguments to nl_langinfo(). ........ r73951 | georg.brandl | 2009-07-11 16:23:38 +0200 (Sa, 11 Jul 2009) | 2 lines array.array is actually a class. ........ r73979 | benjamin.peterson | 2009-07-12 18:56:54 +0200 (So, 12 Jul 2009) | 1 line add versionadded ........
2009-10-27 11:29:22 -03:00
:mod:`platform` --- Access to underlying platform's identifying data
=====================================================================
2007-08-15 11:28:01 -03:00
.. module:: platform
:synopsis: Retrieves as much platform identifying data as possible.
.. moduleauthor:: Marc-Andre Lemburg <mal@egenix.com>
.. sectionauthor:: Bjorn Pettersen <bpettersen@corp.fairisaac.com>
.. versionadded:: 2.3
.. note::
Specific platforms listed alphabetically, with Linux included in the Unix
section.
Cross Platform
--------------
.. function:: architecture(executable=sys.executable, bits='', linkage='')
Queries the given executable (defaults to the Python interpreter binary) for
various architecture information.
Returns a tuple ``(bits, linkage)`` which contain information about the bit
architecture and the linkage format used for the executable. Both values are
returned as strings.
Values that cannot be determined are returned as given by the parameter presets.
If bits is given as ``''``, the :cfunc:`sizeof(pointer)` (or
:cfunc:`sizeof(long)` on Python version < 1.5.2) is used as indicator for the
supported pointer size.
The function relies on the system's :file:`file` command to do the actual work.
This is available on most if not all Unix platforms and some non-Unix platforms
and then only if the executable points to the Python interpreter. Reasonable
defaults are used when the above needs are not met.
.. function:: machine()
Returns the machine type, e.g. ``'i386'``. An empty string is returned if the
value cannot be determined.
.. function:: node()
Returns the computer's network name (may not be fully qualified!). An empty
string is returned if the value cannot be determined.
.. function:: platform(aliased=0, terse=0)
Returns a single string identifying the underlying platform with as much useful
information as possible.
The output is intended to be *human readable* rather than machine parseable. It
may look different on different platforms and this is intended.
If *aliased* is true, the function will use aliases for various platforms that
report system names which differ from their common names, for example SunOS will
be reported as Solaris. The :func:`system_alias` function is used to implement
this.
Setting *terse* to true causes the function to return only the absolute minimum
information needed to identify the platform.
.. function:: processor()
Returns the (real) processor name, e.g. ``'amdk6'``.
An empty string is returned if the value cannot be determined. Note that many
platforms do not provide this information or simply return the same value as for
:func:`machine`. NetBSD does this.
.. function:: python_build()
Returns a tuple ``(buildno, builddate)`` stating the Python build number and
date as strings.
.. function:: python_compiler()
Returns a string identifying the compiler used for compiling Python.
.. function:: python_branch()
Returns a string identifying the Python implementation SCM branch.
.. versionadded:: 2.6
.. function:: python_implementation()
Returns a string identifying the Python implementation. Possible return values
Merged revisions 75363,75365,75376,75392,75394,75403,75418,75484,75572,75580,75590,75592,75594-75596,75600,75602-75603,75605-75607,75610-75613,75616-75617,75623,75627,75647 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75363 | georg.brandl | 2009-10-11 20:31:23 +0200 (So, 11 Okt 2009) | 1 line Add the Python FAQ lists to the documentation. Copied from sandbox/faq. Many thanks to AMK for the preparation work. ........ r75365 | georg.brandl | 2009-10-11 22:16:16 +0200 (So, 11 Okt 2009) | 1 line Fix broken links found by "make linkcheck". scipy.org seems to be done right now, so I could not verify links going there. ........ r75376 | benjamin.peterson | 2009-10-12 03:26:07 +0200 (Mo, 12 Okt 2009) | 1 line platform we don't care about ........ r75392 | andrew.kuchling | 2009-10-13 18:11:49 +0200 (Di, 13 Okt 2009) | 1 line Various link, textual, and markup fixes ........ r75394 | georg.brandl | 2009-10-13 20:10:59 +0200 (Di, 13 Okt 2009) | 1 line Fix markup. ........ r75403 | georg.brandl | 2009-10-14 17:57:46 +0200 (Mi, 14 Okt 2009) | 1 line #7126: os.environ changes *do* take effect in subprocesses started with os.system(). ........ r75418 | georg.brandl | 2009-10-14 20:48:32 +0200 (Mi, 14 Okt 2009) | 1 line #7116: str.join() takes an iterable. ........ r75484 | georg.brandl | 2009-10-18 09:58:12 +0200 (So, 18 Okt 2009) | 1 line Fix missing word. ........ r75572 | benjamin.peterson | 2009-10-20 23:55:17 +0200 (Di, 20 Okt 2009) | 1 line clarify buffer arg #7178 ........ r75580 | georg.brandl | 2009-10-21 09:15:59 +0200 (Mi, 21 Okt 2009) | 1 line #7170: fix explanation about non-weakrefable builtin types. ........ r75590 | benjamin.peterson | 2009-10-22 04:36:47 +0200 (Do, 22 Okt 2009) | 1 line rewrite to be nice to other implementations ........ r75592 | georg.brandl | 2009-10-22 09:05:48 +0200 (Do, 22 Okt 2009) | 1 line Fix punctuation. ........ r75594 | georg.brandl | 2009-10-22 09:56:02 +0200 (Do, 22 Okt 2009) | 1 line Fix markup. ........ r75595 | georg.brandl | 2009-10-22 09:56:56 +0200 (Do, 22 Okt 2009) | 1 line Fix duplicate target. ........ r75596 | georg.brandl | 2009-10-22 10:05:04 +0200 (Do, 22 Okt 2009) | 1 line Add a new directive marking up implementation details and start using it. ........ r75600 | georg.brandl | 2009-10-22 13:01:46 +0200 (Do, 22 Okt 2009) | 1 line Make it more robust. ........ r75602 | georg.brandl | 2009-10-22 13:28:06 +0200 (Do, 22 Okt 2009) | 1 line Document new directive. ........ r75603 | georg.brandl | 2009-10-22 13:28:23 +0200 (Do, 22 Okt 2009) | 1 line Allow short form with text as argument. ........ r75605 | georg.brandl | 2009-10-22 13:48:10 +0200 (Do, 22 Okt 2009) | 1 line Use "impl-detail" directive where applicable. ........ r75606 | georg.brandl | 2009-10-22 17:00:06 +0200 (Do, 22 Okt 2009) | 1 line #6324: membership test tries iteration via __iter__. ........ r75607 | georg.brandl | 2009-10-22 17:04:09 +0200 (Do, 22 Okt 2009) | 1 line #7088: document new functions in signal as Unix-only. ........ r75610 | georg.brandl | 2009-10-22 17:27:24 +0200 (Do, 22 Okt 2009) | 1 line Reorder __slots__ fine print and add a clarification. ........ r75611 | georg.brandl | 2009-10-22 17:42:32 +0200 (Do, 22 Okt 2009) | 1 line #7035: improve docs of the various <method>_errors() functions, and give them docstrings. ........ r75612 | georg.brandl | 2009-10-22 17:52:15 +0200 (Do, 22 Okt 2009) | 1 line #7156: document curses as Unix-only. ........ r75613 | georg.brandl | 2009-10-22 17:54:35 +0200 (Do, 22 Okt 2009) | 1 line #6977: getopt does not support optional option arguments. ........ r75616 | georg.brandl | 2009-10-22 18:17:05 +0200 (Do, 22 Okt 2009) | 1 line Add proper references. ........ r75617 | georg.brandl | 2009-10-22 18:20:55 +0200 (Do, 22 Okt 2009) | 1 line Make printout margin important. ........ r75623 | georg.brandl | 2009-10-23 10:14:44 +0200 (Fr, 23 Okt 2009) | 1 line #7188: fix optionxform() docs. ........ r75627 | fred.drake | 2009-10-23 15:04:51 +0200 (Fr, 23 Okt 2009) | 2 lines add further note about what's passed to optionxform ........ r75647 | georg.brandl | 2009-10-24 12:04:19 +0200 (Sa, 24 Okt 2009) | 1 line Fix markup. ........
2009-10-27 12:08:27 -03:00
are: 'CPython', 'IronPython', 'Jython'.
2007-08-15 11:28:01 -03:00
.. versionadded:: 2.6
.. function:: python_revision()
Returns a string identifying the Python implementation SCM revision.
.. versionadded:: 2.6
.. function:: python_version()
Returns the Python version as string ``'major.minor.patchlevel'``
Note that unlike the Python ``sys.version``, the returned value will always
include the patchlevel (it defaults to 0).
.. function:: python_version_tuple()
Returns the Python version as tuple ``(major, minor, patchlevel)`` of strings.
Note that unlike the Python ``sys.version``, the returned value will always
include the patchlevel (it defaults to ``'0'``).
.. function:: release()
Returns the system's release, e.g. ``'2.2.0'`` or ``'NT'`` An empty string is
returned if the value cannot be determined.
.. function:: system()
Returns the system/OS name, e.g. ``'Linux'``, ``'Windows'``, or ``'Java'``. An
empty string is returned if the value cannot be determined.
.. function:: system_alias(system, release, version)
Returns ``(system, release, version)`` aliased to common marketing names used
for some systems. It also does some reordering of the information in some cases
where it would otherwise cause confusion.
.. function:: version()
Returns the system's release version, e.g. ``'#3 on degas'``. An empty string is
returned if the value cannot be determined.
.. function:: uname()
Fairly portable uname interface. Returns a tuple of strings ``(system, node,
release, version, machine, processor)`` identifying the underlying platform.
Note that unlike the :func:`os.uname` function this also returns possible
processor information as additional tuple entry.
Entries which cannot be determined are set to ``''``.
Java Platform
-------------
.. function:: java_ver(release='', vendor='', vminfo=('','',''), osinfo=('','',''))
Merged revisions 72558,72745,72750,72876,73042,73045-73048,73069,73089,73163,73186,73213,73215,73217,73257-73258,73260 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r72558 | benjamin.peterson | 2009-05-11 01:52:09 +0200 (Mo, 11 Mai 2009) | 1 line sys.setdefaultencoding() strikes me as a bad example ........ r72745 | benjamin.peterson | 2009-05-17 16:16:29 +0200 (So, 17 Mai 2009) | 1 line ignore .rst files in sphinx its self ........ r72750 | benjamin.peterson | 2009-05-17 18:59:27 +0200 (So, 17 Mai 2009) | 1 line chop off slash ........ r72876 | benjamin.peterson | 2009-05-23 22:59:09 +0200 (Sa, 23 Mai 2009) | 1 line remove mention of old ctypes version ........ r73042 | benjamin.peterson | 2009-05-30 05:10:52 +0200 (Sa, 30 Mai 2009) | 1 line no fdatasync on macos ........ r73045 | georg.brandl | 2009-05-30 09:26:04 +0200 (Sa, 30 Mai 2009) | 1 line #6146: fix markup bug. ........ r73046 | georg.brandl | 2009-05-30 09:31:25 +0200 (Sa, 30 Mai 2009) | 1 line Use preferred form of raising exceptions. ........ r73047 | georg.brandl | 2009-05-30 12:33:23 +0200 (Sa, 30 Mai 2009) | 1 line Fix some more small markup problems. ........ r73048 | georg.brandl | 2009-05-30 12:34:25 +0200 (Sa, 30 Mai 2009) | 1 line Fix markup problem. ........ r73069 | benjamin.peterson | 2009-05-31 02:42:42 +0200 (So, 31 Mai 2009) | 1 line fix signature ........ r73089 | andrew.kuchling | 2009-06-01 02:14:19 +0200 (Mo, 01 Jun 2009) | 1 line The class for regexes isn't called RegexObject any more; correct the text ........ r73163 | georg.brandl | 2009-06-03 09:25:35 +0200 (Mi, 03 Jun 2009) | 1 line Use the preferred form of raise statements in the docs. ........ r73186 | georg.brandl | 2009-06-03 23:21:09 +0200 (Mi, 03 Jun 2009) | 1 line #6174: fix indentation in code example. ........ r73213 | georg.brandl | 2009-06-04 12:15:57 +0200 (Do, 04 Jun 2009) | 1 line #5967: note that the C slicing APIs do not support negative indices. ........ r73215 | georg.brandl | 2009-06-04 12:22:31 +0200 (Do, 04 Jun 2009) | 1 line #6176: fix man page section for flock(2). ........ r73217 | georg.brandl | 2009-06-04 12:27:21 +0200 (Do, 04 Jun 2009) | 1 line #6175: document that inet_aton supports alternate input formats with less than three dots. ........ r73257 | georg.brandl | 2009-06-06 19:50:05 +0200 (Sa, 06 Jun 2009) | 1 line #6211: elaborate a bit on ways to call the function. ........ r73258 | georg.brandl | 2009-06-06 19:51:31 +0200 (Sa, 06 Jun 2009) | 1 line #6204: use a real reference instead of "see later". ........ r73260 | georg.brandl | 2009-06-06 20:21:58 +0200 (Sa, 06 Jun 2009) | 1 line #6224: s/JPython/Jython/, and remove one link to a module nine years old. ........
2009-10-27 11:19:50 -03:00
Version interface for Jython.
2007-08-15 11:28:01 -03:00
Returns a tuple ``(release, vendor, vminfo, osinfo)`` with *vminfo* being a
tuple ``(vm_name, vm_release, vm_vendor)`` and *osinfo* being a tuple
``(os_name, os_version, os_arch)``. Values which cannot be determined are set to
the defaults given as parameters (which all default to ``''``).
Windows Platform
----------------
.. function:: win32_ver(release='', version='', csd='', ptype='')
Get additional version information from the Windows Registry and return a tuple
``(version, csd, ptype)`` referring to version number, CSD level and OS type
(multi/single processor).
As a hint: *ptype* is ``'Uniprocessor Free'`` on single processor NT machines
and ``'Multiprocessor Free'`` on multi processor machines. The *'Free'* refers
to the OS version being free of debugging code. It could also state *'Checked'*
which means the OS version uses debugging code, i.e. code that checks arguments,
ranges, etc.
.. note::
Note: this function works best with Mark Hammond's
:mod:`win32all` package installed, but also on Python 2.3 and
later (support for this was added in Python 2.6). It obviously
only runs on Win32 compatible platforms.
2007-08-15 11:28:01 -03:00
Win95/98 specific
^^^^^^^^^^^^^^^^^
.. function:: popen(cmd, mode='r', bufsize=None)
Portable :func:`popen` interface. Find a working popen implementation
preferring :func:`win32pipe.popen`. On Windows NT, :func:`win32pipe.popen`
should work; on Windows 9x it hangs due to bugs in the MS C library.
Mac OS Platform
---------------
.. function:: mac_ver(release='', versioninfo=('','',''), machine='')
Get Mac OS version information and return it as tuple ``(release, versioninfo,
machine)`` with *versioninfo* being a tuple ``(version, dev_stage,
non_release_version)``.
Entries which cannot be determined are set to ``''``. All tuple entries are
strings.
Documentation for the underlying :cfunc:`gestalt` API is available online at
http://www.rgaros.nl/gestalt/.
Unix Platforms
--------------
.. function:: dist(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...))
2007-08-15 11:28:01 -03:00
This is an old version of the functionality now provided by
:func:`linux_distribution`. For new code, please use the
:func:`linux_distribution`.
The only difference between the two is that ``dist()`` always
returns the short name of the distribution taken from the
``supported_dists`` parameter.
.. deprecated:: 2.6
2007-08-15 11:28:01 -03:00
.. function:: linux_distribution(distname='', version='', id='', supported_dists=('SuSE','debian','redhat','mandrake',...), full_distribution_name=1)
Tries to determine the name of the Linux OS distribution name.
``supported_dists`` may be given to define the set of Linux distributions to
look for. It defaults to a list of currently supported Linux distributions
identified by their release file name.
If ``full_distribution_name`` is true (default), the full distribution read
from the OS is returned. Otherwise the short name taken from
``supported_dists`` is used.
Returns a tuple ``(distname,version,id)`` which defaults to the args given as
parameters. ``id`` is the item in parentheses after the version number. It
is usually the version codename.
2007-08-15 11:28:01 -03:00
.. versionadded:: 2.6
2007-08-15 11:28:01 -03:00
.. function:: libc_ver(executable=sys.executable, lib='', version='', chunksize=2048)
Tries to determine the libc version against which the file executable (defaults
to the Python interpreter) is linked. Returns a tuple of strings ``(lib,
version)`` which default to the given parameters in case the lookup fails.
Note that this function has intimate knowledge of how different libc versions
2008-02-22 08:31:45 -04:00
add symbols to the executable is probably only usable for executables compiled
2007-08-15 11:28:01 -03:00
using :program:`gcc`.
The file is read and scanned in chunks of *chunksize* bytes.