archival: avoid touching deprecated gzip name attribute
authorMads Kiilerich <madski@unity3d.com>
Thu, 03 Jan 2013 21:07:04 +0100
changeset 18302 16c642a6f07d
parent 18301 49ad7030ecc4
child 18303 4d1671b39168
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
mercurial/archival.py
--- a/mercurial/archival.py	Thu Jan 03 21:07:04 2013 +0100
+++ b/mercurial/archival.py	Thu Jan 03 21:07:04 2013 +0100
@@ -74,8 +74,11 @@
         def _write_gzip_header(self):
             self.fileobj.write('\037\213')             # magic header
             self.fileobj.write('\010')                 # compression method
-            # Python 2.6 deprecates self.filename
-            fname = getattr(self, 'name', None) or self.filename
+            # Python 2.6 introduced self.name and deprecated self.filename
+            try:
+                fname = self.name
+            except AttributeError:
+                fname = self.filename
             if fname and fname.endswith('.gz'):
                 fname = fname[:-3]
             flags = 0