@@ -55,31 +55,34 @@ def setup(workdir):
5555    # Creating working directory and populating it with test files 
5656    RNPDIR  =  path .join (WORKDIR , '.rnp' )
5757    GPGDIR  =  path .join (WORKDIR , '.gpg' )
58-     os .mkdir (RNPDIR , 0700 )
59-     os .mkdir (GPGDIR , 0700 )
58+     os .mkdir (RNPDIR , 0o700 )
59+     os .mkdir (GPGDIR , 0o700 )
6060
6161    # Generating key 
6262    pipe  =  pswd_pipe (PASSWORD )
63-     params  =  ['--homedir' , RNPDIR , '--pass-fd' , str (pipe ), '--userid' , 'performance@rnp' , '--generate-key' ]
63+     params  =  ['--homedir' , RNPDIR , '--pass-fd' , str (pipe ), '--userid' , 'performance@rnp' ,
64+               '--generate-key' ]
6465    # Run key generation 
6566    ret , out , err  =  run_proc (RNPK , params )
6667    os .close (pipe )
6768
6869    # Importing keys to GnuPG so it can build trustdb and so on 
69-     ret , out , err  =  run_proc (GPG , ['--batch' , '--passphrase' , '' , '--homedir' , GPGDIR , '--import' , path .join (RNPDIR , 'pubring.gpg' ), path .join (RNPDIR , 'secring.gpg' )])
70+     ret , out , err  =  run_proc (GPG , ['--batch' , '--passphrase' , '' , '--homedir' , GPGDIR ,
71+                                    '--import' , path .join (RNPDIR , 'pubring.gpg' ),
72+                                    path .join (RNPDIR , 'secring.gpg' )])
7073
7174    # Generating small file for tests 
72-     SMALLSIZE  =  3312 ; 
73-     st  =  'lorem ipsum dol '  *  (SMALLSIZE / 16 )
75+     SMALLSIZE  =  3312 
76+     st  =  'lorem ipsum dol '  *  (SMALLSIZE //  16 + 1 )
7477    with  open (path .join (WORKDIR , SMALLFILE ), 'w+' ) as  small_file :
7578        small_file .write (st )
7679
7780    # Generating large file for tests 
78-     print   'Generating large file of size {}' .format (size_to_readable (LARGESIZE ))
81+     print ( 'Generating large file of size {}' .format (size_to_readable (LARGESIZE ) ))
7982
80-     st  =  '0123456789ABCDEF'  *  (1024 / 16 )
83+     st  =  '0123456789ABCDEF'  *  (1024 //  16 )
8184    with  open (path .join (WORKDIR , LARGEFILE ), 'w' ) as  fd :
82-         for  i  in  range (0 , LARGESIZE  /  1024   -   1 ):
85+         for  i  in  range (0 , LARGESIZE  //   1024 ):
8386            fd .write (st )
8487
8588def  run_iterated (iterations , func , src , dst , * args ):
@@ -96,28 +99,34 @@ def run_iterated(iterations, func, src, dst, *args):
9699    return  res 
97100
98101def  rnp_symencrypt_file (src , dst , cipher , zlevel  =  6 , zalgo  =  'zip' , armor  =  False ):
99-     params  =  ['--homedir' , RNPDIR , '--password' , PASSWORD , '--cipher' , cipher , '-z' , str (zlevel ), '--'  +  zalgo , '-c' , src , '--output' , dst ]
102+     params  =  ['--homedir' , RNPDIR , '--password' , PASSWORD , '--cipher' , cipher ,
103+               '-z' , str (zlevel ), '--'  +  zalgo , '-c' , src , '--output' , dst ]
100104    if  armor :
101105        params  +=  ['--armor' ]
102106    ret  =  run_proc_fast (RNP , params )
103107    if  ret  !=  0 :
104108        raise_err ('rnp symmetric encryption failed' )
105109
106110def  rnp_decrypt_file (src , dst ):
107-     ret  =  run_proc_fast (RNP , ['--homedir' , RNPDIR , '--password' , PASSWORD , '--decrypt' , src , '--output' , dst ])
111+     ret  =  run_proc_fast (RNP , ['--homedir' , RNPDIR , '--password' , PASSWORD , '--decrypt' , src ,
112+                               '--output' , dst ])
108113    if  ret  !=  0 :
109114        raise_err ('rnp decryption failed' )
110115
111116def  gpg_symencrypt_file (src , dst , cipher  =  'AES' , zlevel  =  6 , zalgo  =  1 , armor  =  False ):
112-     params  =  ['--homedir' , GPGDIR , '-c' , '-z' , str (zlevel ), '--s2k-count' , '524288' , '--compress-algo' , str (zalgo ), '--batch' , '--passphrase' , PASSWORD , '--cipher-algo' , cipher , '--output' , dst , src ]
117+     params  =  ['--homedir' , GPGDIR , '-c' , '-z' , str (zlevel ), '--s2k-count' , '524288' ,
118+               '--compress-algo' , str (zalgo ), '--batch' , '--passphrase' , PASSWORD ,
119+               '--cipher-algo' , cipher , '--output' , dst , src ]
113120    if  armor :
114121        params .insert (2 , '--armor' )
115122    ret  =  run_proc_fast (GPG , params )
116123    if  ret  !=  0 :
117124        raise_err ('gpg symmetric encryption failed for cipher '  +  cipher )
118125
119126def  gpg_decrypt_file (src , dst , keypass ):
120-     ret  =  run_proc_fast (GPG , ['--homedir' , GPGDIR , '--pinentry-mode=loopback' , '--batch' , '--yes' , '--passphrase' , keypass , '--trust-model' , 'always' , '-o' , dst , '-d' , src ])
127+     ret  =  run_proc_fast (GPG , ['--homedir' , GPGDIR , '--pinentry-mode=loopback' , '--batch' ,
128+                               '--yes' , '--passphrase' , keypass , '--trust-model' , 'always' ,
129+                               '-o' , dst , '-d' , src ])
121130    if  ret  !=  0 :
122131        raise_err ('gpg decryption failed' )
123132
@@ -132,27 +141,33 @@ def print_test_results(fsize, rnptime, gpgtime, operation):
132141
133142        if  rnpruns  >=  gpgruns :
134143            percents  =  (rnpruns  -  gpgruns ) /  gpgruns  *  100 
135-             logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (operation , percents , runstr ))
144+             logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (
145+                 operation , percents , runstr ))
136146        else :
137147            percents  =  (gpgruns  -  rnpruns ) /  gpgruns  *  100 
138-             logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (operation , percents , runstr ))
148+             logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (
149+                 operation , percents , runstr ))
139150    else :
140151        rnpspeed  =  fsize  /  1024.0  /  1024.0  /  rnptime 
141152        gpgspeed  =  fsize  /  1024.0  /  1024.0  /  gpgtime 
142153        spdstr  =  '{:.2f} MB/sec vs {:.2f} MB/sec' .format (rnpspeed , gpgspeed )
143154
144155        if  rnpspeed  >=  gpgspeed :
145156            percents  =  (rnpspeed  -  gpgspeed ) /  gpgspeed  *  100 
146-             logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (operation , percents , spdstr ))
157+             logging .info ('{:<30}: RNP is {:>3.0f}% FASTER then GnuPG ({})' .format (
158+                 operation , percents , spdstr ))
147159        else :
148160            percents  =  (gpgspeed  -  rnpspeed ) /  gpgspeed  *  100 
149-             logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (operation , percents , spdstr ))
161+             logging .info ('{:<30}: RNP is {:>3.0f}% SLOWER then GnuPG ({})' .format (
162+                 operation , percents , spdstr ))
150163
151164def  get_file_params (filetype ):
152165    if  filetype  ==  'small' :
153-         infile , outfile , iterations , fsize  =  (SMALLFILE , SMALLFILE  +  '.gpg' , SMALL_ITERATIONS , SMALLSIZE )
166+         infile , outfile , iterations , fsize  =  (SMALLFILE , SMALLFILE  +  '.gpg' ,
167+                                               SMALL_ITERATIONS , SMALLSIZE )
154168    else :
155-         infile , outfile , iterations , fsize  =  (LARGEFILE , LARGEFILE  +  '.gpg' , LARGE_ITERATIONS , LARGESIZE )
169+         infile , outfile , iterations , fsize  =  (LARGEFILE , LARGEFILE  +  '.gpg' ,
170+                                               LARGE_ITERATIONS , LARGESIZE )
156171
157172    infile  =  path .join (WORKDIR , infile )
158173    rnpout  =  path .join (WORKDIR , outfile  +  '.rnp' )
@@ -172,8 +187,10 @@ def small_file_symmetric_encryption(self):
172187        ''' 
173188        infile , rnpout , gpgout , iterations , fsize  =  get_file_params ('small' )
174189        for  armor  in  [False , True ]:
175-             tmrnp  =  run_iterated (iterations , rnp_symencrypt_file , infile , rnpout , 'AES128' , 0 , 'zip' , armor )
176-             tmgpg  =  run_iterated (iterations , gpg_symencrypt_file , infile , gpgout , 'AES128' , 0 , 1 , armor )
190+             tmrnp  =  run_iterated (iterations , rnp_symencrypt_file , infile , rnpout ,
191+                                  'AES128' , 0 , 'zip' , armor )
192+             tmgpg  =  run_iterated (iterations , gpg_symencrypt_file , infile , gpgout ,
193+                                  'AES128' , 0 , 1 , armor )
177194            testname  =  'ENCRYPT-SMALL-{}' .format ('ARMOR'  if  armor  else  'BINARY' )
178195            print_test_results (fsize , tmrnp , tmgpg , testname )
179196
@@ -183,8 +200,10 @@ def large_file_symmetric_encryption(self):
183200        ''' 
184201        infile , rnpout , gpgout , iterations , fsize  =  get_file_params ('large' )
185202        for  cipher  in  ['AES128' , 'AES192' , 'AES256' , 'TWOFISH' , 'BLOWFISH' , 'CAST5' , 'CAMELLIA128' , 'CAMELLIA192' , 'CAMELLIA256' ]:
186-             tmrnp  =  run_iterated (iterations , rnp_symencrypt_file , infile , rnpout , cipher , 0 , 'zip' , False )
187-             tmgpg  =  run_iterated (iterations , gpg_symencrypt_file , infile , gpgout , cipher , 0 , 1 , False )
203+             tmrnp  =  run_iterated (iterations , rnp_symencrypt_file , infile , rnpout ,
204+                                  cipher , 0 , 'zip' , False )
205+             tmgpg  =  run_iterated (iterations , gpg_symencrypt_file , infile , gpgout ,
206+                                  cipher , 0 , 1 , False )
188207            testname  =  'ENCRYPT-{}-BINARY' .format (cipher )
189208            print_test_results (fsize , tmrnp , tmgpg , testname )
190209
@@ -193,7 +212,8 @@ def large_file_armored_encryption(self):
193212        Large file armored encryption 
194213        ''' 
195214        infile , rnpout , gpgout , iterations , fsize  =  get_file_params ('large' )
196-         tmrnp  =  run_iterated (iterations , rnp_symencrypt_file , infile , rnpout , 'AES128' , 0 , 'zip' , True )
215+         tmrnp  =  run_iterated (iterations , rnp_symencrypt_file , infile , rnpout ,
216+                              'AES128' , 0 , 'zip' , True )
197217        tmgpg  =  run_iterated (iterations , gpg_symencrypt_file , infile , gpgout , 'AES128' , 0 , 1 , True )
198218        print_test_results (fsize , tmrnp , tmgpg , 'ENCRYPT-LARGE-ARMOR' )
199219
@@ -217,7 +237,8 @@ def large_file_symmetric_decryption(self):
217237        ''' 
218238        infile , rnpout , gpgout , iterations , fsize  =  get_file_params ('large' )
219239        inenc  =  infile  +  '.enc' 
220-         for  cipher  in  ['AES128' , 'AES192' , 'AES256' , 'TWOFISH' , 'BLOWFISH' , 'CAST5' , 'CAMELLIA128' , 'CAMELLIA192' , 'CAMELLIA256' ]:
240+         for  cipher  in  ['AES128' , 'AES192' , 'AES256' , 'TWOFISH' , 'BLOWFISH' , 'CAST5' ,
241+                        'CAMELLIA128' , 'CAMELLIA192' , 'CAMELLIA256' ]:
221242            gpg_symencrypt_file (infile , inenc , cipher , 0 , 1 , False )
222243            tmrnp  =  run_iterated (iterations , rnp_decrypt_file , inenc , rnpout )
223244            tmgpg  =  run_iterated (iterations , gpg_decrypt_file , inenc , gpgout , PASSWORD )
@@ -266,11 +287,14 @@ def large_file_armored_decryption(self):
266287                      help = "Name of the comma-separated benchmarks to run" , metavar = "benchmarks" )
267288    parser .add_argument ("-w" , "--workdir" , dest = "workdir" ,
268289                      help = "Working directory to use" , metavar = "workdir" )
269-     parser .add_argument ("-l" , "--list" , help = "Print list of available benchmarks and exit" , action = "store_true" )
290+     parser .add_argument ("-l" , "--list" , help = "Print list of available benchmarks and exit" ,
291+                         action = "store_true" )
270292    args  =  parser .parse_args ()
271293
272294    # get list of benchamrks to run 
273-     bench_methods  =  [ x [0 ] for  x  in  inspect .getmembers (Benchmark ,predicate = inspect .ismethod ) if  not  x [0 ].startswith ("_" ) ]
295+     bench_methods  =  [ x [0 ] for  x  in  inspect .getmembers (Benchmark ,
296+             predicate = lambda  x : inspect .ismethod (x ) or  inspect .isfunction (x ))]
297+     print (bench_methods )
274298
275299    if  args .list :
276300        for  name  in  bench_methods :
0 commit comments