diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2007-02-13 16:09:24 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2007-02-13 16:09:24 (GMT) |
commit | 5b1a7857023d15a2f51467c765bade1d6f349c5e (patch) | |
tree | 49ddffe1b8cb6fa0ab0386234a996869bc487ae1 /Lib/gzip.py | |
parent | b1cc1d407b2eed5063a4c384411416cd7e302081 (diff) | |
download | cpython-5b1a7857023d15a2f51467c765bade1d6f349c5e.zip cpython-5b1a7857023d15a2f51467c765bade1d6f349c5e.tar.gz cpython-5b1a7857023d15a2f51467c765bade1d6f349c5e.tar.bz2 |
Patch #1647484: Renamed GzipFile's filename attribute to name. The
filename attribute is still accessible as a property that emits a
DeprecationWarning.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r-- | Lib/gzip.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index c37d5a1..ea3656f 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -106,7 +106,7 @@ class GzipFile: self._new_member = True self.extrabuf = "" self.extrasize = 0 - self.filename = filename + self.name = filename # Starts small, scales exponentially self.min_readsize = 100 @@ -127,14 +127,20 @@ class GzipFile: if self.mode == WRITE: self._write_gzip_header() + @property + def filename(self): + import warnings + warnings.warn("use the name attribute", DeprecationWarning) + if self.mode == WRITE and self.name[-3:] != ".gz": + return self.name + ".gz" + return self.name + def __repr__(self): s = repr(self.fileobj) return '<gzip ' + s[1:-1] + ' ' + hex(id(self)) + '>' def _init_write(self, filename): - if filename[-3:] != '.gz': - filename = filename + '.gz' - self.filename = filename + self.name = filename self.crc = zlib.crc32("") self.size = 0 self.writebuf = [] @@ -143,16 +149,15 @@ class GzipFile: def _write_gzip_header(self): self.fileobj.write('\037\213') # magic header self.fileobj.write('\010') # compression method - fname = self.filename[:-3] flags = 0 - if fname: + if self.name: flags = FNAME self.fileobj.write(chr(flags)) write32u(self.fileobj, long(time.time())) self.fileobj.write('\002') self.fileobj.write('\377') - if fname: - self.fileobj.write(fname + '\000') + if self.name: + self.fileobj.write(self.name + '\000') def _init_read(self): self.crc = zlib.crc32("") |