~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Jelmer Vernooij
  • Date: 2012-03-15 02:42:48 UTC
  • mto: This revision was merged to the branch mainline in revision 6510.
  • Revision ID: jelmer@samba.org-20120315024248-7nyk2zxc52i1u8gj
extention -> extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
# Written by Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
17
17
 
18
18
"""Bzrlib specific gzip tunings. We plan to feed these to the upstream gzip."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
from cStringIO import StringIO
21
23
 
22
24
# make GzipFile faster:
27
29
import zlib
28
30
 
29
31
# we want a \n preserved, break on \n only splitlines.
30
 
import bzrlib
 
32
from bzrlib import symbol_versioning
31
33
 
32
34
__all__ = ["GzipFile", "bytes_to_gzip"]
33
35
 
118
120
    Yes, its only 1.6 seconds, but they add up.
119
121
    """
120
122
 
 
123
    def __init__(self, *args, **kwargs):
 
124
        symbol_versioning.warn(
 
125
            symbol_versioning.deprecated_in((2, 3, 0))
 
126
            % 'bzrlib.tuned_gzip.GzipFile',
 
127
            DeprecationWarning, stacklevel=2)
 
128
        gzip.GzipFile.__init__(self, *args, **kwargs)
 
129
 
121
130
    def _add_read_data(self, data):
122
131
        # 4169 calls in 183
123
132
        # temp var for len(data) and switch to +='s.
395
404
        # (4 seconds to 1 seconds for the sample upgrades I was testing).
396
405
        self.write(''.join(lines))
397
406
 
 
407
    if sys.version_info > (2, 7):
 
408
        # As of Python 2.7 the crc32 must be positive when close is called
 
409
        def close(self):
 
410
            if self.fileobj is None:
 
411
                return
 
412
            if self.mode == gzip.WRITE:
 
413
                self.crc &= 0xFFFFFFFFL
 
414
            gzip.GzipFile.close(self)
398
415