@@ -26,25 +26,27 @@ class RenPyArchive:
2626 self .key = key
2727 self .verbose = verbose
2828
29- if file != None :
29+ if file is not None :
3030 self .load (file )
3131 else :
3232 self .version = version
3333
3434 def __del__ (self ):
35- if self .handle != None :
35+ if self .handle is not None :
3636 self .handle .close ()
3737
3838 # Determine archive version.
3939 def get_version (self ):
4040 self .handle .seek (0 )
4141 magic = self .handle .readline ().decode ('utf-8' )
42+
4243 if magic .startswith (self .RPA3_MAGIC ):
4344 return 3
4445 elif magic .startswith (self .RPA2_MAGIC ):
4546 return 2
4647 elif self .file .endswith ('.rpi' ):
4748 return 1
49+
4850 raise ValueError ('the given file is not a valid Ren\' Py archive, or an unsupported version' )
4951
5052 # Extract file indexes from opened archive.
@@ -53,17 +55,17 @@ class RenPyArchive:
5355 indexes = None
5456
5557 if self .version == 2 or self .version == 3 :
56- # Fetch metadata
58+ # Fetch metadata.
5759 metadata = self .handle .readline ()
5860 offset = int (metadata [8 :24 ], 16 )
5961 if self .version == 3 :
6062 self .key = int (metadata [25 :33 ], 16 )
6163
62- # Load in indexes
64+ # Load in indexes.
6365 self .handle .seek (offset )
6466 indexes = pickle .loads (self .handle .read ().decode ('zlib' ))
6567
66- # Deobfuscate indexes
68+ # Deobfuscate indexes.
6769 if self .version == 3 :
6870 obfuscated_indexes = indexes
6971 indexes = {}
@@ -111,12 +113,12 @@ class RenPyArchive:
111113 def read (self , filename ):
112114 filename = self .convert_filename (filename )
113115
114- # Check if the file exists in our indexes
116+ # Check if the file exists in our indexes.
115117 if not filename in self .files and not filename in self .indexes :
116118 raise IOError (errno .ENOENT , 'the requested file {0} does not exist in the given Ren\' Py archive' .format (filename ))
117119
118- # If it's in our opened archive index, and our archive handle isn't valid, something is obviously wrong
119- if not filename in self .files and filename in self .indexes and self .handle == None :
120+ # If it's in our opened archive index, and our archive handle isn't valid, something is obviously wrong.
121+ if not filename in self .files and filename in self .indexes and self .handle is None :
120122 raise IOError (errno .ENOENT , 'the requested file {0} does not exist in the given Ren\' Py archive' .format (filename ))
121123
122124 # Check our simplified internal indexes first, in case someone wants to read a file they added before without saving, for some unholy reason.
@@ -138,7 +140,7 @@ class RenPyArchive:
138140
139141 # Modify a file in archive or internal storage.
140142 def change (self , filename , contents ):
141- # Our 'change' is basically removing the file from our indexes first, and then re-add it.
143+ # Our 'change' is basically removing the file from our indexes first, and then re-adding it.
142144 self .remove (filename )
143145 self .add (filename , contents )
144146
@@ -165,7 +167,7 @@ class RenPyArchive:
165167
166168 # Load archive.
167169 def load (self , filename ):
168- if self .handle != None :
170+ if self .handle is not None :
169171 self .handle .close ()
170172 self .file = filename
171173 self .files = {}
@@ -175,20 +177,20 @@ class RenPyArchive:
175177
176178 # Save current state into a new file, merging archive and internal storage, rebuilding indexes, and optionally saving in another format version.
177179 def save (self , filename = None ):
178- if filename == None :
180+ if filename is None :
179181 filename = self .file
180- if filename == None :
182+ if filename is None :
181183 raise ValueError ('no target file found for saving archive' )
182184 if self .version != 2 and self .version != 3 :
183185 raise ValueError ('saving is only supported for version 2 and 3 archives' )
184186
185187 self .verbose_print ('Rebuilding archive index...' )
186- # Fill our own files structure with the files added or changed in this session
188+ # Fill our own files structure with the files added or changed in this session.
187189 files = self .files
188- # First, read files from the current archive into our files structure
190+ # First, read files from the current archive into our files structure.
189191 for file in self .indexes .keys ():
190192 content = self .read (file )
191- # Remove from indexes array once read, add to our own array
193+ # Remove from indexes array once read, add to our own array.
192194 del self .indexes [file ]
193195 files [file ] = content
194196
@@ -232,7 +234,7 @@ class RenPyArchive:
232234 # We're done, close it.
233235 archive .close ()
234236
235- # Reload the file in our inner database
237+ # Reload the file in our inner database.
236238 self .load (filename )
237239
238240if __name__ == "__main__" :
@@ -264,20 +266,20 @@ if __name__ == "__main__":
264266 parser .add_argument ('-V' , '--version' , action = 'version' , version = 'rpatool v0.8' , help = 'Show version information.' )
265267 arguments = parser .parse_args ()
266268
267- # Determine RPA version
269+ # Determine RPA version.
268270 if arguments .two :
269271 version = 2
270272 else :
271273 version = 3
272274
273- # Determine RPAv3 key
274- if 'key' in arguments and arguments .key != None :
275+ # Determine RPAv3 key.
276+ if 'key' in arguments and arguments .key is not None :
275277 key = int (arguments .key , 16 )
276278 else :
277279 key = 0xDEADBEEF
278280
279- # Determine padding bytes
280- if 'padding' in arguments and arguments .padding != None :
281+ # Determine padding bytes.
282+ if 'padding' in arguments and arguments .padding is not None :
281283 padding = int (arguments .padding )
282284 else :
283285 padding = 0
@@ -288,7 +290,7 @@ if __name__ == "__main__":
288290 output = arguments .archive
289291 else :
290292 archive = arguments .archive
291- if 'outfile' in arguments and arguments .outfile != None :
293+ if 'outfile' in arguments and arguments .outfile is not None :
292294 output = arguments .outfile
293295 else :
294296 # Default output directory for extraction is the current directory.
@@ -298,7 +300,7 @@ if __name__ == "__main__":
298300 output = arguments .archive
299301
300302 # Normalize files.
301- if len (arguments .files ) > 0 and type (arguments .files [0 ]) == list :
303+ if len (arguments .files ) > 0 and isinstance (arguments .files [0 ], list ) :
302304 arguments .files = arguments .files [0 ]
303305
304306 try :
0 commit comments