From 1c98685e2b41c7821c37ea219be9e565e95ae1ca Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 26 Mar 2019 00:00:13 -0700 Subject: [PATCH 1/3] Add missing docstrings --- Lib/tarfile.py | 53 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 30cecffd1a84d3..234a6e9d300621 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -717,11 +717,32 @@ class TarInfo(object): usually created internally. """ - __slots__ = ("name", "mode", "uid", "gid", "size", "mtime", - "chksum", "type", "linkname", "uname", "gname", - "devmajor", "devminor", - "offset", "offset_data", "pax_headers", "sparse", - "tarfile", "_sparse_structs", "_link_target") + __slots__ = dict( + name = 'Name of the archive member.', + mode = 'Permission bits.', + uid = 'User ID of the user who originally stored this member.', + gid = 'Group ID of the user who originally stored this member.', + size = 'Size in bytes.', + mtime = 'Time of last modification.', + chksum = 'Header checksum', + type = ('File type. type is usually one of these constants: ' + 'REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, ' + 'CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.'), + linkname = ('Name of the target file name, which is only present ' + 'in TarInfo objects of type LNKTYPE and SYMTYPE'), + uname = 'User name.', + gname = 'Group name.', + devmajor = 'Device major number', + devminor = 'Device minor number', + offset = 'The tar header starts here', + offset_data = "The file's data starts here", + pax_headers = ('A dictionary containing key-value pairs of an ' + 'associated pax extended header.'), + sparse = 'Sparse member information', + tarfile = None, + _sparse_structs = None, + _link_target = None, + ) def __init__(self, name=""): """Construct a TarInfo object. name is the optional name @@ -747,10 +768,9 @@ def __init__(self, name=""): self.sparse = None # sparse member information self.pax_headers = {} # pax header information - # In pax headers the "name" and "linkname" field are called - # "path" and "linkpath". @property def path(self): + 'In pax headers, "name" is called "path"' return self.name @path.setter @@ -759,6 +779,7 @@ def path(self, name): @property def linkpath(self): + 'In pax headers, "linkname" is called "linkpath".' return self.linkname @linkpath.setter @@ -1350,24 +1371,42 @@ def _block(self, count): return blocks * BLOCKSIZE def isreg(self): + 'Return True if the Tarinfo object is a regular file.' return self.type in REGULAR_TYPES + def isfile(self): + 'Return True if the Tarinfo object is a regular file.' return self.isreg() + def isdir(self): + 'Return True if it is a directory.' return self.type == DIRTYPE + def issym(self): + 'Return True if it is a symbolic link.' return self.type == SYMTYPE + def islnk(self): + 'Return True if it is a hard link.' return self.type == LNKTYPE + def ischr(self): + 'Return True if it is a character device.' return self.type == CHRTYPE + def isblk(self): + 'Return True if it is a block device.' return self.type == BLKTYPE + def isfifo(self): + 'Return True if it is a FIFO.' return self.type == FIFOTYPE + def issparse(self): return self.sparse is not None + def isdev(self): + 'Return True if it is one of character device, block device or FIFO.' return self.type in (CHRTYPE, BLKTYPE, FIFOTYPE) # class TarInfo From d56f4a2e1d43ab6a026ce464d4da26eabee5027e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 26 Mar 2019 00:13:28 -0700 Subject: [PATCH 2/3] Markup for __slots__ wasn't visible in the HTML view --- Lib/pydoc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 0cf3d3359624a4..86ccfe041f6675 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -997,8 +997,8 @@ def docdata(self, object, name=None, mod=None, cl=None): if name: push('
%s
\n' % name) - if object.__doc__ is not None: - doc = self.markup(getdoc(object), self.preformat) + doc = self.markup(getdoc(object), self.preformat) + if doc: push('
%s
\n' % doc) push('
\n') From ff9993d53ba060fda358d12a1f12f83e11eebc1c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 26 Mar 2019 21:36:31 -0700 Subject: [PATCH 3/3] Consistent periods at the end of each phrase --- Lib/tarfile.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 234a6e9d300621..2c06f9160c658a 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -724,21 +724,21 @@ class TarInfo(object): gid = 'Group ID of the user who originally stored this member.', size = 'Size in bytes.', mtime = 'Time of last modification.', - chksum = 'Header checksum', + chksum = 'Header checksum.', type = ('File type. type is usually one of these constants: ' 'REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, ' 'CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.'), linkname = ('Name of the target file name, which is only present ' - 'in TarInfo objects of type LNKTYPE and SYMTYPE'), + 'in TarInfo objects of type LNKTYPE and SYMTYPE.'), uname = 'User name.', gname = 'Group name.', - devmajor = 'Device major number', - devminor = 'Device minor number', - offset = 'The tar header starts here', - offset_data = "The file's data starts here", + devmajor = 'Device major number.', + devminor = 'Device minor number.', + offset = 'The tar header starts here.', + offset_data = "The file's data starts here.", pax_headers = ('A dictionary containing key-value pairs of an ' 'associated pax extended header.'), - sparse = 'Sparse member information', + sparse = 'Sparse member information.', tarfile = None, _sparse_structs = None, _link_target = None, @@ -770,7 +770,7 @@ def __init__(self, name=""): @property def path(self): - 'In pax headers, "name" is called "path"' + 'In pax headers, "name" is called "path".' return self.name @path.setter