From: Juergen H. <jh...@we...> - 2001-05-31 00:49:06
|
pydent is a tool that takes valid python source and indents it canonically (i.e. using no TABs and 4 spaces per indent level). While doing this, it tries to keep as much of the original formatting as possible, for example additional indenting on continued lines. It also removes trailing whitespace, including any whitespace on empty lines. I tested it by running it over the standard lib of 2.0 (which surfaced some funny formatting :), but it could use some heavy testing on as much source code as possible. Get it from http://sourceforge.net/cvs/?group_id=9021 (no tarball yet). As an example, this is the diff for zipfile.py in the 2.0 standard lib after running pydent over it (fixed some 2-space indents): --- zipfile.bak Wed May 30 23:50:43 2001 +++ zipfile.py Thu May 31 00:05:04 2001 @@ -75,12 +75,12 @@ dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2] dostime = dt[3] << 11 | dt[4] << 5 | dt[5] / 2 if self.flag_bits & 0x08: - # Set these to zero because we write them after the file data - CRC = compress_size = file_size = 0 + # Set these to zero because we write them after the file data + CRC = compress_size = file_size = 0 else: - CRC = self.CRC - compress_size = self.compress_size - file_size = self.file_size + CRC = self.CRC + compress_size = self.compress_size + file_size = self.file_size header = struct.pack(structFileHeader, stringFileHeader, self.extract_version, self.reserved, self.flag_bits, self.compress_type, dostime, dosdate, CRC, @@ -278,14 +278,14 @@ date_time = mtime[0:6] # Create ZipInfo instance to store file information if arcname is None: - zinfo = ZipInfo(filename, date_time) + zinfo = ZipInfo(filename, date_time) else: - zinfo = ZipInfo(arcname, date_time) + zinfo = ZipInfo(arcname, date_time) zinfo.external_attr = st[0] << 16 # Unix attributes if compress_type is None: - zinfo.compress_type = self.compression + zinfo.compress_type = self.compression else: - zinfo.compress_type = compress_type + zinfo.compress_type = compress_type self._writecheck(zinfo) fp = open(filename, "rb") zinfo.flag_bits = 0x08 @@ -344,9 +344,9 @@ zinfo.file_offset = self.fp.tell() # Start of file bytes self.fp.write(bytes) if zinfo.flag_bits & 0x08: - # Write CRC and file sizes after the file data - self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size, - zinfo.file_size)) + # Write CRC and file sizes after the file data + self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size, + zinfo.file_size)) self.filelist.append(zinfo) self.NameToInfo[zinfo.filename] = zinfo |