3535DF_EXISTS = 0x8000
3636
3737def zero_terminate (s ):
38- """Truncate a string at the first NUL ('\0 ') character, if any."""
39-
40- i = s .find (b'\0 ' )
41- if i == - 1 :
42- return s
43- return s [:i ]
38+ """Truncate a string at the first NUL ('\0 ') character, if any."""
39+
40+ i = s .find (b'\0 ' )
41+ if i == - 1 :
42+ return s
43+ return s [:i ]
4444
4545# mode, ???, length, created,
4646# fat_cluster, parent_entry, modified, attr,
@@ -54,84 +54,84 @@ def zero_terminate(s):
5454# Use the new Struct object if available
5555#
5656if hasattr (struct , "Struct" ):
57- _dirent_struct = struct .Struct (_dirent_fmt )
58- _tod_struct = struct .Struct (_tod_fmt )
59-
60- def unpack_tod (s ):
61- return _tod_struct .unpack (s )
62-
63- def pack_tod (tod ):
64- return _tod_struct .pack (tod )
65-
66- def unpack_dirent (s ):
67- ent = _dirent_struct .unpack (s )
68- ent = list (ent )
69- ent [3 ] = _tod_struct .unpack (ent [3 ])
70- ent [6 ] = _tod_struct .unpack (ent [6 ])
71- ent [8 ] = zero_terminate (ent [8 ]).decode ("ascii" )
72- return ent
73-
74- def pack_dirent (ent ):
75- ent = list (ent )
76- ent [3 ] = _tod_struct .pack (* ent [3 ])
77- ent [6 ] = _tod_struct .pack (* ent [6 ])
78- ent [8 ] = ent [8 ].encode ("ascii" )
79- return _dirent_struct .pack (* ent )
57+ _dirent_struct = struct .Struct (_dirent_fmt )
58+ _tod_struct = struct .Struct (_tod_fmt )
59+
60+ def unpack_tod (s ):
61+ return _tod_struct .unpack (s )
62+
63+ def pack_tod (tod ):
64+ return _tod_struct .pack (tod )
65+
66+ def unpack_dirent (s ):
67+ ent = _dirent_struct .unpack (s )
68+ ent = list (ent )
69+ ent [3 ] = _tod_struct .unpack (ent [3 ])
70+ ent [6 ] = _tod_struct .unpack (ent [6 ])
71+ ent [8 ] = zero_terminate (ent [8 ]).decode ("ascii" )
72+ return ent
73+
74+ def pack_dirent (ent ):
75+ ent = list (ent )
76+ ent [3 ] = _tod_struct .pack (* ent [3 ])
77+ ent [6 ] = _tod_struct .pack (* ent [6 ])
78+ ent [8 ] = ent [8 ].encode ("ascii" )
79+ return _dirent_struct .pack (* ent )
8080else :
81- def unpack_tod (s ):
82- return struct .unpack (_tod_fmt , s )
83-
84- def pack_tod (tod ):
85- return struct .pack (_tod_fmt , tod )
86-
87- def unpack_dirent (s ):
88- # mode, ???, length, created,
89- # fat_cluster, parent_entry, modified, attr,
90- # name
91- ent = struct .unpack (_dirent_fmt , s )
92- ent = list (ent )
93- ent [3 ] = struct .unpack (_tod_fmt , ent [3 ])
94- ent [6 ] = struct .unpack (_tod_fmt , ent [6 ])
95- ent [8 ] = zero_terminate (ent [8 ])
96- return ent
97-
98- def pack_dirent (ent ):
99- ent = list (ent )
100- ent [3 ] = struct .pack (_tod_fmt , * ent [3 ])
101- ent [6 ] = struct .pack (_tod_fmt , * ent [6 ])
102- ent [8 ] = ent [8 ].encode ("ascii" )
103- return struct .pack (_dirent_fmt , * ent )
81+ def unpack_tod (s ):
82+ return struct .unpack (_tod_fmt , s )
83+
84+ def pack_tod (tod ):
85+ return struct .pack (_tod_fmt , tod )
86+
87+ def unpack_dirent (s ):
88+ # mode, ???, length, created,
89+ # fat_cluster, parent_entry, modified, attr,
90+ # name
91+ ent = struct .unpack (_dirent_fmt , s )
92+ ent = list (ent )
93+ ent [3 ] = struct .unpack (_tod_fmt , ent [3 ])
94+ ent [6 ] = struct .unpack (_tod_fmt , ent [6 ])
95+ ent [8 ] = zero_terminate (ent [8 ])
96+ return ent
97+
98+ def pack_dirent (ent ):
99+ ent = list (ent )
100+ ent [3 ] = struct .pack (_tod_fmt , * ent [3 ])
101+ ent [6 ] = struct .pack (_tod_fmt , * ent [6 ])
102+ ent [8 ] = ent [8 ].encode ("ascii" )
103+ return struct .pack (_dirent_fmt , * ent )
104104
105105def time_to_tod (when ):
106- """Convert a Python time value to a ToD tuple"""
107-
108- tm = time .gmtime (when + 9 * 3600 )
109- return (tm .tm_sec , tm .tm_min , tm .tm_hour ,
110- tm .tm_mday , tm .tm_mon , tm .tm_year )
106+ """Convert a Python time value to a ToD tuple"""
107+
108+ tm = time .gmtime (when + 9 * 3600 )
109+ return (tm .tm_sec , tm .tm_min , tm .tm_hour ,
110+ tm .tm_mday , tm .tm_mon , tm .tm_year )
111111
112112def tod_to_time (tod ):
113- """Convert a ToD tuple to a Python time value."""
114-
115- try :
116- month = tod [4 ]
117- if month == 0 :
118- month = 1
119- return calendar .timegm ((tod [5 ], month , tod [3 ],
120- tod [2 ], tod [1 ], tod [0 ],
121- None , None , 0 )) - 9 * 3600
122- except ValueError :
123- return 0
124-
113+ """Convert a ToD tuple to a Python time value."""
114+
115+ try :
116+ month = tod [4 ]
117+ if month == 0 :
118+ month = 1
119+ return calendar .timegm ((tod [5 ], month , tod [3 ],
120+ tod [2 ], tod [1 ], tod [0 ],
121+ None , None , 0 )) - 9 * 3600
122+ except ValueError :
123+ return 0
124+
125125def tod_now ():
126- """Get the current time as a ToD tuple."""
127- return time_to_tod (time .time ())
126+ """Get the current time as a ToD tuple."""
127+ return time_to_tod (time .time ())
128128
129129def tod_from_file (filename ):
130- return time_to_tod (os .stat (filename ).st_mtime )
130+ return time_to_tod (os .stat (filename ).st_mtime )
131131
132132def mode_is_file (mode ):
133- return (mode & (DF_FILE | DF_DIR | DF_EXISTS )) == (DF_FILE | DF_EXISTS )
133+ return (mode & (DF_FILE | DF_DIR | DF_EXISTS )) == (DF_FILE | DF_EXISTS )
134134
135135def mode_is_dir (mode ):
136- return (mode & (DF_FILE | DF_DIR | DF_EXISTS )) == (DF_DIR | DF_EXISTS )
136+ return (mode & (DF_FILE | DF_DIR | DF_EXISTS )) == (DF_DIR | DF_EXISTS )
137137
0 commit comments