Because the curses API is so large, some functions aren't supported in the
Python interface, not because they're difficult to implement, but because no one
has needed them yet. Feel free to add them and then submit a patch. Also, we
-don't yet have support for the menus or panels libraries associated with
+don't yet have support for the menu library associated with
ncurses; feel free to add that.
If you write an interesting little program, feel free to contribute it as
reading. Instances support iteration in the same way as normal :class:`file`
instances.
+ :class:`BZ2File` supports the :keyword:`with` statement.
+
+ .. versionchanged:: 2.7
+ Support for the :keyword:`with` statement was added.
+
.. method:: close()
.. function:: cmpfiles(dir1, dir2, common[, shallow])
- Returns three lists of file names: *match*, *mismatch*, *errors*. *match*
- contains the list of files match in both directories, *mismatch* includes the
- names of those that don't, and *errros* lists the names of files which could not
- be compared. Files may be listed in *errors* because the user may lack
- permission to read them or many other reasons, but always that the comparison
- could not be done for some reason.
-
- The *common* parameter is a list of file names found in both directories. The
- *shallow* parameter has the same meaning and default value as for
+ Compare the files in the two directories *dir1* and *dir2* whose names are
+ given by *common*.
+
+ Returns three lists of file names: *match*, *mismatch*,
+ *errors*. *match* contains the list of files that match, *mismatch* contains
+ the names of those that don't, and *errors* lists the names of files which
+ could not be compared. Files are listed in *errors* if they don't exist in
+ one of the directories, the user lacks permission to read them or if the
+ comparison could not be done for some other reason.
+
+ The *shallow* parameter has the same meaning and default value as for
:func:`filecmp.cmp`.
+ For example, ``cmpfiles('a', 'b', ['c', 'd/e'])`` will compare ``a/c`` with
+ ``b/c`` and ``a/d/e`` with ``b/d/e``. ``'c'`` and ``'d/e'`` will each be in
+ one of the three returned lists.
+
+
Example::
>>> import filecmp
``9`` is slowest and produces the most compression. The default is ``9``.
The *mtime* argument is an optional numeric timestamp to be written to
- the stream when compressing. All :program:`gzip`compressed streams are
+ the stream when compressing. All :program:`gzip` compressed streams are
required to contain a timestamp. If omitted or ``None``, the current
time is used. This module ignores the timestamp when decompressing;
however, some programs, such as :program:`gunzip`\ , make use of it.
writing as *fileobj*, and retrieve the resulting memory buffer using the
:class:`StringIO` object's :meth:`getvalue` method.
+ :class:`GzipFile` supports the :keyword:`with` statement.
+
+ .. versionchanged:: 2.7
+ Support for the :keyword:`with` statement was added.
+
.. function:: open(filename[, mode[, compresslevel]])
import mmap
# write a simple example file
- with open("hello.txt", "w") as f:
+ with open("hello.txt", "wb") as f:
f.write("Hello Python!\n")
- with open("hello.txt", "r+") as f:
+ with open("hello.txt", "r+b") as f:
# memory-map the file, size 0 means whole file
map = mmap.mmap(f.fileno(), 0)
# read content via standard file methods
+------------+-----------------------------------------------------+-------+
| ``'o'`` | Signed octal value. | \(1) |
+------------+-----------------------------------------------------+-------+
-| ``'u'`` | Obselete type -- it is identical to ``'d'``. | \(7) |
+| ``'u'`` | Obsolete type -- it is identical to ``'d'``. | \(7) |
+------------+-----------------------------------------------------+-------+
| ``'x'`` | Signed hexadecimal (lowercase). | \(2) |
+------------+-----------------------------------------------------+-------+
.. function:: unpack_from(fmt, buffer[,offset=0])
- Unpack the *buffer* according to tthe given format. The result is a tuple even
+ Unpack the *buffer* according to the given format. The result is a tuple even
if it contains exactly one item. The *buffer* must contain at least the amount
of data required by the format (``len(buffer[offset:])`` must be at least
``calcsize(fmt)``).
If the name is used as the target of a function or class statement, this
will be true.
+ For example::
+
+ >>> table = symtable.symtable("def some_func(): pass", "string", "exec")
+ >>> table.lookup("some_func").is_namespace()
+ True
+
Note that a single name can be bound to multiple objects. If the result
is ``True``, the name may also be bound to other objects, like an int or
list, that does not introduce a new namespace.
:class:`struct_time`, or having elements of the wrong type, a :exc:`TypeError`
is raised.
+* Use the following functions to convert between time representations:
+
+ +-------------------------+-------------------------+-------------------------+
+ | From | To | Use |
+ +=========================+=========================+=========================+
+ | seconds since the epoch | :class:`struct_time` in | :func:`gmtime` |
+ | | UTC | |
+ +-------------------------+-------------------------+-------------------------+
+ | seconds since the epoch | :class:`struct_time` in | :func:`localtime` |
+ | | local time | |
+ +-------------------------+-------------------------+-------------------------+
+ | :class:`struct_time` in | seconds since the epoch | :func:`calendar.timegm` |
+ | UTC | | |
+ +-------------------------+-------------------------+-------------------------+
+ | :class:`struct_time` in | seconds since the epoch | :func:`mktime` |
+ | local time | | |
+ +-------------------------+-------------------------+-------------------------+
+
+
The module defines the following functions and data items:
The expression is evaluated, and it should result in an object that supports the
context management protocol (that is, has :meth:`__enter__` and :meth:`__exit__`
-methods.
+methods).
The object's :meth:`__enter__` is called before *with-block* is executed and
therefore can run set-up code. It also may return a value that is bound to the
Optional `strict' argument when false adds a bunch of commonly found, but
non-standard types.
"""
- init()
+ if not inited:
+ init()
return guess_type(url, strict)
Optional `strict' argument when false adds a bunch of commonly found,
but non-standard types.
"""
- init()
+ if not inited:
+ init()
return guess_all_extensions(type, strict)
def guess_extension(type, strict=True):
Optional `strict' argument when false adds a bunch of commonly found,
but non-standard types.
"""
- init()
+ if not inited:
+ init()
return guess_extension(type, strict)
def add_type(type, ext, strict=True):
list of standard types, else to the list of non-standard
types.
"""
- init()
+ if not inited:
+ init()
return add_type(type, ext, strict)
- configparser now defaults to using an ordered dictionary.
+- Issue #5401: Fixed a performance problem in mimetypes when ``from mimetypes
+ import guess_extension`` was used.
+
- Issue #1733986: Fixed mmap crash in accessing elements of second map object
with same tagname but larger size than first map. (Windows)
Permissions History
-------------------
-- Tarek Ziadé as given SVN access on Decmeber 21 2008 by NCN,
+- Chris Withers was given SVN access on March 8 2009 by MvL,
+ after recommendation by GvR.
+
+- Tarek Ziadé was given SVN access on December 21 2008 by NCN,
for maintenance of distutils.
- Hirokazu Yamamoto was given SVN access on August 12 2008 by MvL,
size = va.len + vb.len;
if (size < 0) {
- return PyErr_NoMemory();
+ PyErr_NoMemory();
goto done;
}
static void
bytes_dealloc(PyByteArrayObject *self)
{
- if (self->ob_exports > 0) {
- PyErr_SetString(PyExc_SystemError,
+ if (self->ob_exports > 0) {
+ PyErr_SetString(PyExc_SystemError,
"deallocated bytearray object has exported buffers");
- PyErr_Print();
- }
+ PyErr_Print();
+ }
if (self->ob_bytes != 0) {
PyMem_Free(self->ob_bytes);
}