summaryrefslogtreecommitdiff
path: root/debian/patches/py3_support
blob: 88baca973324b5bf49ddddf03e34f73e2a3c8ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
--- a/srp/_srp.c
+++ b/srp/_srp.c
@@ -895,7 +895,7 @@ static void ver_dealloc( PyVerifier * se
     if ( self->bytes_s != NULL )
         free( (char *)self->bytes_s );
         
-    self->ob_type->tp_free( (PyObject *) self );
+    Py_TYPE(self)->tp_free( (PyObject *) self );
 }
 
 
@@ -903,7 +903,7 @@ static void usr_dealloc( PyUser * self )
 {
     if ( self->usr != NULL )
         srp_user_delete( self->usr );
-    self->ob_type->tp_free( (PyObject *) self );
+    Py_TYPE(self)->tp_free( (PyObject *) self );
 }
 
 
--- a/srp/test_srp.py
+++ b/srp/test_srp.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import print_function
 
 import unittest
 import os.path
@@ -7,18 +8,19 @@ import sys
 import time
 import thread
 
+
 this_dir = os.path.dirname( os.path.abspath(__file__) )
-    
+
 build_dir = os.path.join( os.path.dirname(this_dir), 'build' )
 
 if not os.path.exists( build_dir ):
-    print 'Please run "python setup.py build" prior to running tests'
+    print('Please run "python setup.py build" prior to running tests')
     sys.exit(1)
-    
+
 plat_dirs = [ d for d in os.listdir('build') if d.startswith('lib') ]
 
 if not len(plat_dirs) == 1:
-    print 'Unexpected build result... aborting'
+    print('Unexpected build result... aborting')
 
 plat_dir = os.path.join( build_dir, plat_dirs[0] )
 
@@ -33,7 +35,7 @@ import srp._ctsrp as _ctsrp
 try:
     import srp._srp as _srp
 except ImportError:
-    print 'Failed to import srp._srp. Aborting tests'
+    print('Failed to import srp._srp. Aborting tests')
     sys.exit(1)
 
 
@@ -62,17 +64,17 @@ class SRPTests( unittest.TestCase ):
 
         usr      = User( username, password, hash_alg, ng_type, n_hex, g_hex )
         uname, A = usr.start_authentication()
-    
+
         # username, A => server
         svr      = Verifier( uname, _s, _v, A, hash_alg, ng_type, n_hex, g_hex )
         s,B      = svr.get_challenge()
-        
+
         # s,B => client
         M        = usr.process_challenge( s, B )
-        
+
         # M => server
         HAMK     = svr.verify_session( M )
-    
+
         # HAMK => client
         usr.verify_session( HAMK )
 
@@ -143,24 +145,24 @@ password = 'testpassword'
 NLEFT = 0
 
 def do_auth( mod, hash_alg, ng_type, _s, _v ):
-    
+
     usr      = mod.User( username, password, hash_alg, ng_type)
     uname, A = usr.start_authentication()
-    
+
     # username, A => server
     svr      = mod.Verifier( uname, _s, _v, A, hash_alg, ng_type)
     s,B      = svr.get_challenge()
-    
+
     # s,B => client
     M        = usr.process_challenge( s, B )
-    
+
     # M => server
     HAMK     = svr.verify_session( M )
-    
+
     # HAMK => client
     usr.verify_session( HAMK )
-    
-    if not svr.authenticated() or not usr.authenticated(): 
+
+    if not svr.authenticated() or not usr.authenticated():
         raise Exception('Authentication failed!')
 
 
@@ -169,7 +171,7 @@ def performance_test( mod, hash_alg, ng_
     _s, _v = srp.create_salted_verification_key( username, password, hash_alg, ng_type )
 
     NLEFT = niter
-    
+
     def test_thread():
         global NLEFT
         while NLEFT > 0:
@@ -188,75 +190,78 @@ def performance_test( mod, hash_alg, ng_
 
 
 def get_param_str( mod, hash_alg, ng_type ):
-    
+
     m = { 'srp._pysrp' : 'Python',
           'srp._ctsrp' : 'ctypes',
           'srp._srp'   : 'C     ' }
-    
+
     cfg = '%s, %s, %d:' % (m[mod.__name__], hash_map[hash_alg], prime_map[ng_type])
 
     return cfg
 
-    
+
 def param_test( mod, hash_alg, ng_type, niter=10 ):
     duration = performance_test( mod, hash_alg, ng_type, niter )
     cfg = get_param_str( mod, hash_alg, ng_type )
-    print '   ', cfg.ljust(20), '%.6f' % (duration/niter)
+    print('   ', cfg.ljust(20), '%.6f' % (duration/niter))
     return duration/niter
-    
+
 
 def print_default_timings():
-    print '*'*60
-    print 'Default Parameter Timings:'
+    print('*'*60)
+    print('Default Parameter Timings:')
     py_time = param_test( _pysrp, srp.SHA1, srp.NG_2048 )
     ct_time = param_test( _ctsrp, srp.SHA1, srp.NG_2048 )
     c_time  = param_test( _srp,   srp.SHA1, srp.NG_2048 )
-    print ''
-    print 'Performance increases: '
-    print '   ctypes-module : ', py_time/ct_time
-    print '   C-module      : ', py_time/c_time
+    print('')
+    print('Performance increases: ')
+    print('   ctypes-module : ', py_time/ct_time)
+    print('   C-module      : ', py_time/c_time)
 
 
 def print_performance_table():
     ng_types = [ srp.NG_1024, srp.NG_2048, srp.NG_4096, srp.NG_8192 ]
     hash_types = [ srp.SHA1, srp.SHA224, srp.SHA256, srp.SHA384, srp.SHA512 ]
 
-    print '*'*60
-    print 'Hash Algorithm vs Prime Number performance table'
-    print ''
-    print '       |',
+    print('*'*60)
+    print('Hash Algorithm vs Prime Number performance table')
+    print('')
+    print('       |')
     for ng in ng_types:
-        print ('NG_%d' % prime_map[ng]).rjust(12),
-    print ''
-    print '-'*60
+        print ('NG_%d' % prime_map[ng]).rjust(12)
+    print('')
+    print('-'*60)
 
     for hash_alg in hash_types:
 
-        print '%s |' % hash_map[hash_alg],
+        print('%s |' % hash_map[hash_alg],)
         for ng in ng_types:
-            print '{0:>12f}'.format(performance_test(_srp, hash_alg, ng) / 10),
-        print ''
+            print('{0:>12f}'.format(
+                performance_test(_srp, hash_alg, ng) / 10))
+        print('')
 
 
 def print_thread_performance():
-    print '*'*60
-    print 'Thread Performance Test:'
+    print('*'*60)
+    print('Thread Performance Test:')
     niter = 100
     for nthreads in range(1,11):
-        print '   Thread Count {0:>2}: {1:8f}'.format(nthreads, performance_test(_srp, srp.SHA1, srp.NG_2048, niter, nthreads)/niter)
+        print('   Thread Count {0:>2}: {1:8f}'.format(
+            nthreads, performance_test(
+                _srp, srp.SHA1, srp.NG_2048, niter, nthreads)/niter))
 
 
-print '*'*60
-print '*'
-print '* Testing Implementation'
-print '*'
+print('*'*60)
+print('*')
+print('* Testing Implementation')
+print('*')
 suite = unittest.TestLoader().loadTestsFromTestCase(SRPTests)
 unittest.TextTestRunner(verbosity=1).run(suite)
 
-print '*'*60
-print '*'
-print '* Performance Testing'
-print '*'
+print('*'*60)
+print('*')
+print('* Performance Testing')
+print('*')
 print_thread_performance()
 print_performance_table()
 print_default_timings()
@@ -264,5 +269,3 @@ print_default_timings()
 
 # Pause briefly to ensure no background threads are still executing
 time.sleep(0.1)
-
-