Mercurial > hg > mercurial-source
comparison mercurial/archival.py @ 18302:16c642a6f07d
archival: avoid touching deprecated gzip name attribute
The existing workaround didn't work when no filename was specified.
If running in a context with warnings enabled and subsecond mtime it gave a
warning:
DeprecationWarning: use the name attribute
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 03 Jan 2013 21:07:04 +0100 |
parents | 49ad7030ecc4 |
children | 87923db0ecff |
comparison
equal
deleted
inserted
replaced
18301:49ad7030ecc4 | 18302:16c642a6f07d |
---|---|
72 gzip.GzipFile.__init__(self, *args, **kw) | 72 gzip.GzipFile.__init__(self, *args, **kw) |
73 | 73 |
74 def _write_gzip_header(self): | 74 def _write_gzip_header(self): |
75 self.fileobj.write('\037\213') # magic header | 75 self.fileobj.write('\037\213') # magic header |
76 self.fileobj.write('\010') # compression method | 76 self.fileobj.write('\010') # compression method |
77 # Python 2.6 deprecates self.filename | 77 # Python 2.6 introduced self.name and deprecated self.filename |
78 fname = getattr(self, 'name', None) or self.filename | 78 try: |
79 fname = self.name | |
80 except AttributeError: | |
81 fname = self.filename | |
79 if fname and fname.endswith('.gz'): | 82 if fname and fname.endswith('.gz'): |
80 fname = fname[:-3] | 83 fname = fname[:-3] |
81 flags = 0 | 84 flags = 0 |
82 if fname: | 85 if fname: |
83 flags = gzip.FNAME | 86 flags = gzip.FNAME |