Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/gzip.rst

    r2 r391  
    44.. module:: gzip
    55   :synopsis: Interfaces for gzip compression and decompression using file objects.
     6
     7**Source code:** :source:`Lib/gzip.py`
     8
     9--------------
    610
    711This module provides a simple interface to compress and decompress files just
     
    1923:program:`compress` and :program:`pack`, are not supported by this module.
    2024
    21 For other archive formats, see the :mod:`bz2`, :mod:`zipfile`, and
    22 :mod:`tarfile` modules.
    23 
    2425The module defines the following items:
    2526
    2627
    27 .. class:: GzipFile([filename[, mode[, compresslevel[, fileobj]]]])
     28.. class:: GzipFile([filename[, mode[, compresslevel[, fileobj[, mtime]]]]])
    2829
    2930   Constructor for the :class:`GzipFile` class, which simulates most of the methods
     
    3334
    3435   The new class instance is based on *fileobj*, which can be a regular file, a
    35    :class:`StringIO` object, or any other object which simulates a file.  It
     36   :class:`~StringIO.StringIO` object, or any other object which simulates a file.  It
    3637   defaults to ``None``, in which case *filename* is opened to provide a file
    3738   object.
    3839
    3940   When *fileobj* is not ``None``, the *filename* argument is only used to be
    40    included in the :program:`gzip` file header, which may includes the original
     41   included in the :program:`gzip` file header, which may include the original
    4142   filename of the uncompressed file.  It defaults to the filename of *fileobj*, if
    4243   discernible; otherwise, it defaults to the empty string, and in this case the
     
    4950   in binary mode for cross-platform portability.
    5051
    51    The *compresslevel* argument is an integer from ``1`` to ``9`` controlling the
    52    level of compression; ``1`` is fastest and produces the least compression, and
    53    ``9`` is slowest and produces the most compression.  The default is ``9``.
     52   The *compresslevel* argument is an integer from ``0`` to ``9`` controlling
     53   the level of compression; ``1`` is fastest and produces the least
     54   compression, and ``9`` is slowest and produces the most compression. ``0``
     55   is no compression. The default is ``9``.
     56
     57   The *mtime* argument is an optional numeric timestamp to be written to
     58   the stream when compressing.  All :program:`gzip` compressed streams are
     59   required to contain a timestamp.  If omitted or ``None``, the current
     60   time is used.  This module ignores the timestamp when decompressing;
     61   however, some programs, such as :program:`gunzip`\ , make use of it.
     62   The format of the timestamp is the same as that of the return value of
     63   ``time.time()`` and of the ``st_mtime`` attribute of the object returned
     64   by ``os.stat()``.
    5465
    5566   Calling a :class:`GzipFile` object's :meth:`close` method does not close
    5667   *fileobj*, since you might wish to append more material after the compressed
    57    data.  This also allows you to pass a :class:`StringIO` object opened for
     68   data.  This also allows you to pass a :class:`~StringIO.StringIO` object opened for
    5869   writing as *fileobj*, and retrieve the resulting memory buffer using the
    59    :class:`StringIO` object's :meth:`getvalue` method.
     70   :class:`StringIO` object's :meth:`~StringIO.StringIO.getvalue` method.
     71
     72   :class:`GzipFile` supports iteration and the :keyword:`with` statement.
     73
     74   .. versionchanged:: 2.7
     75      Support for the :keyword:`with` statement was added.
     76
     77   .. versionchanged:: 2.7
     78      Support for zero-padded files was added.
     79
     80   .. versionadded:: 2.7
     81      The *mtime* argument.
    6082
    6183
     
    7597
    7698   import gzip
    77    f = gzip.open('/home/joe/file.txt.gz', 'rb')
     99   f = gzip.open('file.txt.gz', 'rb')
    78100   file_content = f.read()
    79101   f.close()
     
    83105   import gzip
    84106   content = "Lots of content here"
    85    f = gzip.open('/home/joe/file.txt.gz', 'wb')
     107   f = gzip.open('file.txt.gz', 'wb')
    86108   f.write(content)
    87109   f.close()
     
    90112
    91113   import gzip
    92    f_in = open('/home/joe/file.txt', 'rb')
    93    f_out = gzip.open('/home/joe/file.txt.gz', 'wb')
     114   f_in = open('file.txt', 'rb')
     115   f_out = gzip.open('file.txt.gz', 'wb')
    94116   f_out.writelines(f_in)
    95117   f_out.close()
Note: See TracChangeset for help on using the changeset viewer.