1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17- ''' Commandline scripts.
17+ """ Commandline scripts.
1818
1919These scripts are called by the executables defined in setup.py.
20- '''
20+ """
21+
22+ from __future__ import with_statement
2123
2224import abc
2325import sys
3032HASH_METHODS = sorted (rsa .pkcs1 .HASH_METHODS .keys ())
3133
3234def keygen ():
33- ''' Key generator.'''
35+ """ Key generator."""
3436
3537 # Parse the CLI options
3638 parser = OptionParser (usage = 'usage: %prog [options] keysize' ,
@@ -86,7 +88,7 @@ def keygen():
8688
8789
8890class CryptoOperation (object ):
89- ''' CLI callable that operates with input, output, and a key.'''
91+ """ CLI callable that operates with input, output, and a key."""
9092
9193 __metaclass__ = abc .ABCMeta
9294
@@ -112,15 +114,15 @@ def __init__(self):
112114
113115 @abc .abstractmethod
114116 def perform_operation (self , indata , key , cli_args = None ):
115- ''' Performs the program's operation.
117+ """ Performs the program's operation.
116118
117119 Implement in a subclass.
118120
119121 :returns: the data to write to the output.
120- '''
122+ """
121123
122124 def __call__ (self ):
123- ''' Runs the program.'''
125+ """ Runs the program."""
124126
125127 (cli , cli_args ) = self .parse_cli ()
126128
@@ -135,10 +137,10 @@ def __call__(self):
135137 self .write_outfile (outdata , cli .output )
136138
137139 def parse_cli (self ):
138- ''' Parse the CLI options
140+ """ Parse the CLI options
139141
140142 :returns: (cli_opts, cli_args)
141- '''
143+ """
142144
143145 parser = OptionParser (usage = self .usage , description = self .description )
144146
@@ -160,7 +162,7 @@ def parse_cli(self):
160162 return (cli , cli_args )
161163
162164 def read_key (self , filename , keyform ):
163- ''' Reads a public or private key.'''
165+ """ Reads a public or private key."""
164166
165167 print >> sys .stderr , 'Reading %s key from %s' % (self .keyname , filename )
166168 with open (filename ) as keyfile :
@@ -169,7 +171,7 @@ def read_key(self, filename, keyform):
169171 return self .key_class .load_pkcs1 (keydata , keyform )
170172
171173 def read_infile (self , inname ):
172- ''' Read the input file'''
174+ """ Read the input file"""
173175
174176 if inname :
175177 print >> sys .stderr , 'Reading input from %s' % inname
@@ -180,7 +182,7 @@ def read_infile(self, inname):
180182 return sys .stdin .read ()
181183
182184 def write_outfile (self , outdata , outname ):
183- ''' Write the output file'''
185+ """ Write the output file"""
184186
185187 if outname :
186188 print >> sys .stderr , 'Writing output to %s' % outname
@@ -191,7 +193,7 @@ def write_outfile(self, outdata, outname):
191193 sys .stdout .write (outdata )
192194
193195class EncryptOperation (CryptoOperation ):
194- ''' Encrypts a file.'''
196+ """ Encrypts a file."""
195197
196198 keyname = 'public'
197199 description = ('Encrypts a file. The file must be shorter than the key '
@@ -203,12 +205,12 @@ class EncryptOperation(CryptoOperation):
203205
204206
205207 def perform_operation (self , indata , pub_key , cli_args = None ):
206- ''' Encrypts files.'''
208+ """ Encrypts files."""
207209
208210 return rsa .encrypt (indata , pub_key )
209211
210212class DecryptOperation (CryptoOperation ):
211- ''' Decrypts a file.'''
213+ """ Decrypts a file."""
212214
213215 keyname = 'private'
214216 description = ('Decrypts a file. The original file must be shorter than '
@@ -220,12 +222,12 @@ class DecryptOperation(CryptoOperation):
220222 key_class = rsa .PrivateKey
221223
222224 def perform_operation (self , indata , priv_key , cli_args = None ):
223- ''' Decrypts files.'''
225+ """ Decrypts files."""
224226
225227 return rsa .decrypt (indata , priv_key )
226228
227229class SignOperation (CryptoOperation ):
228- ''' Signs a file.'''
230+ """ Signs a file."""
229231
230232 keyname = 'private'
231233 usage = 'usage: %%prog [options] private_key hash_method'
@@ -241,7 +243,7 @@ class SignOperation(CryptoOperation):
241243 'to stdout if this option is not present.' )
242244
243245 def perform_operation (self , indata , priv_key , cli_args ):
244- ''' Decrypts files.'''
246+ """ Decrypts files."""
245247
246248 hash_method = cli_args [1 ]
247249 if hash_method not in HASH_METHODS :
@@ -251,7 +253,7 @@ def perform_operation(self, indata, priv_key, cli_args):
251253 return rsa .sign (indata , priv_key , hash_method )
252254
253255class VerifyOperation (CryptoOperation ):
254- ''' Verify a signature.'''
256+ """ Verify a signature."""
255257
256258 keyname = 'public'
257259 usage = 'usage: %%prog [options] private_key signature_file'
@@ -265,7 +267,7 @@ class VerifyOperation(CryptoOperation):
265267 has_output = False
266268
267269 def perform_operation (self , indata , pub_key , cli_args ):
268- ''' Decrypts files.'''
270+ """ Decrypts files."""
269271
270272 signature_file = cli_args [1 ]
271273
@@ -281,21 +283,21 @@ def perform_operation(self, indata, pub_key, cli_args):
281283
282284
283285class BigfileOperation (CryptoOperation ):
284- ''' CryptoOperation that doesn't read the entire file into memory.'''
286+ """ CryptoOperation that doesn't read the entire file into memory."""
285287
286288 def __init__ (self ):
287289 CryptoOperation .__init__ (self )
288290
289291 self .file_objects = []
290292
291293 def __del__ (self ):
292- ''' Closes any open file handles.'''
294+ """ Closes any open file handles."""
293295
294296 for fobj in self .file_objects :
295297 fobj .close ()
296298
297299 def __call__ (self ):
298- ''' Runs the program.'''
300+ """ Runs the program."""
299301
300302 (cli , cli_args ) = self .parse_cli ()
301303
@@ -310,7 +312,7 @@ def __call__(self):
310312 self .perform_operation (infile , outfile , key , cli_args )
311313
312314 def get_infile (self , inname ):
313- ''' Returns the input file object'''
315+ """ Returns the input file object"""
314316
315317 if inname :
316318 print >> sys .stderr , 'Reading input from %s' % inname
@@ -323,7 +325,7 @@ def get_infile(self, inname):
323325 return fobj
324326
325327 def get_outfile (self , outname ):
326- ''' Returns the output file object'''
328+ """ Returns the output file object"""
327329
328330 if outname :
329331 print >> sys .stderr , 'Will write output to %s' % outname
@@ -336,7 +338,7 @@ def get_outfile(self, outname):
336338 return fobj
337339
338340class EncryptBigfileOperation (BigfileOperation ):
339- ''' Encrypts a file to VARBLOCK format.'''
341+ """ Encrypts a file to VARBLOCK format."""
340342
341343 keyname = 'public'
342344 description = ('Encrypts a file to an encrypted VARBLOCK file. The file '
@@ -347,12 +349,12 @@ class EncryptBigfileOperation(BigfileOperation):
347349 operation_progressive = 'encrypting'
348350
349351 def perform_operation (self , infile , outfile , pub_key , cli_args = None ):
350- ''' Encrypts files to VARBLOCK.'''
352+ """ Encrypts files to VARBLOCK."""
351353
352354 return rsa .bigfile .encrypt_bigfile (infile , outfile , pub_key )
353355
354356class DecryptBigfileOperation (BigfileOperation ):
355- ''' Decrypts a file in VARBLOCK format.'''
357+ """ Decrypts a file in VARBLOCK format."""
356358
357359 keyname = 'private'
358360 description = ('Decrypts an encrypted VARBLOCK file that was encrypted '
@@ -363,7 +365,7 @@ class DecryptBigfileOperation(BigfileOperation):
363365 key_class = rsa .PrivateKey
364366
365367 def perform_operation (self , infile , outfile , priv_key , cli_args = None ):
366- ''' Decrypts a VARBLOCK file.'''
368+ """ Decrypts a VARBLOCK file."""
367369
368370 return rsa .bigfile .decrypt_bigfile (infile , outfile , priv_key )
369371
0 commit comments