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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
--- dal/dbapi/db_row.py.orig 2008-07-25 06:05:12 UTC
+++ dal/dbapi/db_row.py
@@ -275,11 +275,11 @@ class MetaFields(type):
for f in fields:
if type(f) is not str:
- raise TypeError, 'Field names must be ASCII strings'
+ raise TypeError('Field names must be ASCII strings')
if not f:
- raise ValueError, 'Field names cannot be empty'
+ raise ValueError('Field names cannot be empty')
if f in field_names:
- raise ValueError, 'Field names must be unique: %s' % f
+ raise ValueError('Field names must be unique: %s' % f)
slots.append(f)
field_names[f] = 1
@@ -313,7 +313,7 @@ class IMetaFields(MetaFields):
try:
ifields = tuple( [ f.lower() for f in fields ] )
except AttributeError:
- raise TypeError, 'Field names must be ASCII strings'
+ raise TypeError('Field names must be ASCII strings')
super(IMetaFields,cls).build_properties(cls, ifields, field_dict)
field_dict['__fields__'] = tuple(fields)
@@ -459,7 +459,7 @@ except ImportError:
super(IFieldsBase, self).__setattr__(key.lower(),None)
-class Fields(FieldsBase):
+class Fields(FieldsBase, metaclass=MetaFields):
'''Fields:
A tuple-like base-class that gains properties to allow access to
@@ -469,12 +469,10 @@ class Fields(FieldsBase):
is case-sensitive, though case-insensitive objects may be created by
inheriting from the IFields base-class.
'''
-
- __metaclass__ = MetaFields
__slots__ = ()
-class IFields(IFieldsBase):
+class IFields(IFieldsBase, metaclass=IMetaFields):
'''IFields:
A tuple-like base-class that gains properties to allow access to
@@ -484,8 +482,6 @@ class IFields(IFieldsBase):
is case-insensitive, though case-sensitive objects may be created by
inheriting from the Fields base-class.
'''
-
- __metaclass__ = IMetaFields
__slots__ = ()
@@ -513,7 +509,7 @@ except ImportError:
try:
return getattr(self.fields,key)
except AttributeError:
- raise KeyError,key
+ raise KeyError(key)
return self.fields.__getitem__(key)
def __setitem__(self, key, value):
@@ -521,7 +517,7 @@ except ImportError:
try:
setattr(self.fields,key,value)
except AttributeError:
- raise KeyError,key
+ raise KeyError(key)
else:
self.fields.__setitem__(key,value)
@@ -530,7 +526,7 @@ except ImportError:
try:
delattr(self.fields,key)
except AttributeError:
- raise KeyError,key
+ raise KeyError(key)
else:
self.fields.__delitem__(key)
@@ -544,7 +540,7 @@ except ImportError:
self.fields.__delslice__(i, j)
def __hash__(self):
- raise NotImplementedError,'Row objects are not hashable'
+ raise NotImplementedError('Row objects are not hashable')
def __len__(self):
return len(self.fields)
@@ -622,7 +618,7 @@ class Row(RowBase):
def items(self):
'''r.items() -> tuple of r's (field, value) pairs, as 2-tuples'''
- return zip(self.keys(),self.fields)
+ return list(zip(list(self.keys()),self.fields))
def get(self, key, default=None):
if not isinstance(key, str):
@@ -638,14 +634,14 @@ class Row(RowBase):
def dict(self):
'''r.dict() -> dictionary mapping r's fields to its values'''
- return dict(self.items())
+ return dict(list(self.items()))
def copy(self):
'''r.copy() -> a shallow copy of r'''
return type(self)(self)
def __hash__(self):
- raise NotImplementedError,'Row objects are not hashable'
+ raise NotImplementedError('Row objects are not hashable')
class IRow(Row):
@@ -662,7 +658,7 @@ class IRow(Row):
def has_key(self, key):
if isinstance(key, str):
key = key.lower()
- return super(IRow, self).has_key(key)
+ return key in super(IRow, self)
class MetaRowBase(type):
@@ -789,7 +785,7 @@ class NullRow(type(Nothing)):
return 0
def __ne__(self, other):
return 1
- def __nonzero__(self):
+ def __bool__(self):
return 0
@@ -802,21 +798,21 @@ def test(cls):
assert d['c']==d[2]==d.fields.c==d.fields[2]==3
assert len(d) == 3
- assert d.has_key('a')
- assert d.has_key('B')
- assert d.has_key('c')
+ assert 'a' in d
+ assert 'B' in d
+ assert 'c' in d
assert 'd' not in d
assert 1 in d
assert 2 in d
assert 3 in d
assert 4 not in d
- assert not d.has_key(4)
- assert not d.has_key('d')
+ assert 4 not in d
+ assert 'd' not in d
assert d[-1] == 3
assert d[1:3] == (2,3)
- assert d.keys() == ('a','B','c')
- assert d.items() == [('a', 1), ('B', 2), ('c', 3)]
+ assert list(d.keys()) == ('a','B','c')
+ assert list(d.items()) == [('a', 1), ('B', 2), ('c', 3)]
assert d.dict() == {'a': 1, 'c': 3, 'B': 2}
assert d.copy() == d
assert d == d.copy()
@@ -849,19 +845,19 @@ def test(cls):
try:
d[4]
- raise AssertionError, 'Illegal index not caught'
+ raise AssertionError('Illegal index not caught')
except IndexError:
pass
try:
d['f']
- raise AssertionError, 'Illegal key not caught'
+ raise AssertionError('Illegal key not caught')
except KeyError:
pass
try:
d.fields.f
- raise AssertionError, 'Illegal attribute not caught'
+ raise AssertionError('Illegal attribute not caught')
except AttributeError:
pass
@@ -874,14 +870,14 @@ def test_insensitive(cls):
assert d['b']==d['B']==d[1]==d.fields.B==d.fields.b==d.fields[1]==2
assert d['c']==d['C']==d[2]==d.fields.C==d.fields.c==d.fields[2]==3
- assert d.has_key('a')
- assert d.has_key('A')
- assert d.has_key('b')
- assert d.has_key('B')
- assert d.has_key('c')
- assert d.has_key('C')
- assert not d.has_key('d')
- assert not d.has_key('D')
+ assert 'a' in d
+ assert 'A' in d
+ assert 'b' in d
+ assert 'B' in d
+ assert 'c' in d
+ assert 'C' in d
+ assert 'd' not in d
+ assert 'D' not in d
assert 1 in d
assert 2 in d
@@ -975,37 +971,37 @@ def test_rw(cls):
try:
d['g'] = 'illegal'
- raise AssertionError,'Illegal setitem'
+ raise AssertionError('Illegal setitem')
except KeyError:
pass
try:
del d['g']
- raise AssertionError,'Illegal delitem'
+ raise AssertionError('Illegal delitem')
except KeyError:
pass
try:
d[5] = 'illegal'
- raise AssertionError,'Illegal setitem'
+ raise AssertionError('Illegal setitem')
except IndexError:
pass
try:
del d[5]
- raise AssertionError,'Illegal delitem'
+ raise AssertionError('Illegal delitem')
except IndexError:
pass
try:
d.fields.g = 'illegal'
- raise AssertionError,'Illegal setattr'
+ raise AssertionError('Illegal setattr')
except AttributeError:
pass
try:
del d.fields.g
- raise AssertionError,'Illegal delattr'
+ raise AssertionError('Illegal delattr')
except AttributeError:
pass
@@ -1066,25 +1062,25 @@ def test_incomplete(cls):
try:
d['B']
- raise AssertionError,'Illegal getitem: "%s"' % d['B']
+ raise AssertionError('Illegal getitem: "%s"' % d['B'])
except KeyError:
pass
try:
d['c']
- raise AssertionError,'Illegal getitem'
+ raise AssertionError('Illegal getitem')
except KeyError:
pass
try:
d.fields.b
- raise AssertionError,'Illegal getattr'
+ raise AssertionError('Illegal getattr')
except AttributeError:
pass
try:
d.fields.c
- raise AssertionError,'Illegal getattr'
+ raise AssertionError('Illegal getattr')
except AttributeError:
pass
@@ -1121,12 +1117,12 @@ if __name__ == '__main__':
gc.collect()
new_objects = len(gc.get_objects()) - orig_objects
if new_objects >= N:
- print "WARNING: Detected memory leak of %d objects." % new_objects
+ print("WARNING: Detected memory leak of %d objects." % new_objects)
if sys.version_info >= (2,2,2):
- print " Please notify jacobs@theopalgroup.com immediately."
+ print(" Please notify jacobs@theopalgroup.com immediately.")
else:
- print " You are running a Python older than 2.2.1 or older. Several"
- print " memory leaks in the core interepreter were fixed in version"
- print " 2.2.2, so we strongly recommend upgrading."
+ print(" You are running a Python older than 2.2.1 or older. Several")
+ print(" memory leaks in the core interepreter were fixed in version")
+ print(" 2.2.2, so we strongly recommend upgrading.")
- print 'Tests passed'
+ print('Tests passed')
--- dal/dbapi/dbapi.py.orig 2008-10-16 05:52:44 UTC
+++ dal/dbapi/dbapi.py
@@ -83,9 +83,9 @@ print cs.fetchone()[0]
__revision__ = 0.1
-import dbtime
-import dbexceptions
-import paramstyles
+from . import dbtime
+from . import dbexceptions
+from . import paramstyles
class MWrapper(object):
"""Wraps DBAPI2 driver."""
@@ -149,10 +149,10 @@ class MWrapper(object):
assert dtmodname in ('py', 'mx', 'native')
if dtmodname == 'py':
if not dbtime.have_datetime:
- raise Exception, 'datetime module not available.'
+ raise Exception('datetime module not available.')
elif dtmodname == 'mx':
if not dbtime.have_mxDateTime:
- raise Exception, 'mx.DateTime module not available.'
+ raise Exception('mx.DateTime module not available.')
self.__dtmod = dtmodname
dtmod = property(__getDtMod, __setDtMod)
@@ -162,7 +162,7 @@ class MWrapper(object):
def __setUseDbRow(self, use_db_row):
if use_db_row:
- import db_row
+ from . import db_row
globals()['db_row'] = db_row
self.__use_db_row = use_db_row
@@ -265,7 +265,7 @@ class Cursor(object):
def __setDbRow(self, use_db_row):
"""Set value of use_db_row for cursor."""
if use_db_row:
- import db_row
+ from . import db_row
globals()['db_row'] = db_row
self.__use_db_row = use_db_row
@@ -406,7 +406,7 @@ class Cursor(object):
elif self._mwrapper._convert_bool and typelist[i] == self._driver.BOOLEAN:
boolpos.append(i)
# loop through data to make changes
- for i in xrange(len(results)):
+ for i in range(len(results)):
set = results[i]
# make datetime objects
if len(datepos) > 0 or len(boolpos) > 0:
--- dal/dbapi/dbtime.py.orig 2008-10-03 11:24:17 UTC
+++ dal/dbapi/dbtime.py
@@ -98,7 +98,7 @@ def mx2pydt(mxdt):
else:
return mx2pydtdelta(mxdt)
else:
- raise Exception, 'Not a mx datetime type.'
+ raise Exception('Not a mx datetime type.')
# Python datetime to mx.DateTime conversion functions
@@ -148,7 +148,7 @@ def py2mxdt(pydt):
elif type(pydt) == datetime.timedelta:
return py2mxdtdelta(pydt)
else:
- raise Exception, 'Not a Python datetime type.'
+ raise Exception('Not a Python datetime type.')
# Date and Time constructors
@@ -160,7 +160,7 @@ def construct_date(dtpref, year, month, day):
return mx.DateTime.Date(year, month, day)
else:
# what exception should be raised here?
- raise Exception, 'Improper DATETIME set.'
+ raise Exception('Improper DATETIME set.')
def construct_time(dtpref, hour, minute, second):
"""Creates time object for preferred type."""
@@ -170,7 +170,7 @@ def construct_time(dtpref, hour, minute, second):
return mx.DateTime.Time(hour, minute, second)
else:
# what exception should be raised here?
- raise Exception, 'Improper DATETIME set.'
+ raise Exception('Improper DATETIME set.')
def construct_timestamp(dtpref, year, month, day, hour, minute, second):
"""Creates timestamp object for preferred type."""
@@ -180,7 +180,7 @@ def construct_timestamp(dtpref, year, month, day, hour
return mx.DateTime.DateTime(year, month, day, hour, minute, second)
else:
# what exception should be raised here?
- raise Exception, 'Improper DATETIME set.'
+ raise Exception('Improper DATETIME set.')
def construct_datefromticks(dtpref, ticks):
"""Creates date object for preferred type and ticks."""
@@ -190,7 +190,7 @@ def construct_datefromticks(dtpref, ticks):
return mx.DateTime.DateFromTicks(ticks)
else:
# what exception should be raised here?
- raise Exception, 'Improper DATETIME set.'
+ raise Exception('Improper DATETIME set.')
def construct_timefromticks(dtpref, ticks):
"""Creates time object for preferred type and ticks."""
@@ -200,7 +200,7 @@ def construct_timefromticks(dtpref, ticks):
return mx.DateTime.TimeFromTicks(ticks)
else:
# what exception should be raised here?
- raise Exception, 'Improper DATETIME set.'
+ raise Exception('Improper DATETIME set.')
def construct_timestampfromticks(dtpref, ticks):
"""Creates timestamp object for preferred type and ticks."""
@@ -210,7 +210,7 @@ def construct_timestampfromticks(dtpref, ticks):
return mx.DateTime.localtime(ticks)
else:
# what exception should be raised here?
- raise Exception, 'Improper DATETIME set.'
+ raise Exception('Improper DATETIME set.')
# Other functions
@@ -250,25 +250,25 @@ def dtsubnative(dtpref, dbmod, params):
# not a datetime field
pass
else:
- raise ValueError, 'dbpref value not known.'
+ raise ValueError('dbpref value not known.')
return nparam
def convert_dparams(dparams):
# Convert dictionary of parameters.
- for key, value in dparams.items():
+ for key, value in list(dparams.items()):
dparams[key] = convertdt(value)
return dparams
if type(params) == dict:
params = convert_dparams(params)
elif type(params) == list:
- for key in xrange(len(params)):
+ for key in range(len(params)):
if type(params[key]) == dict:
params[key] = convert_dparams(params[key])
else:
params[key] = convertdt(params[key])
else:
- raise ValueError, 'params should be list or dict.'
+ raise ValueError('params should be list or dict.')
return params
def native2pref(nativedt, pref, dt_type=None, conv_func=None):
@@ -283,7 +283,7 @@ def native2pref(nativedt, pref, dt_type=None, conv_fun
elif dto_class == 'mx' and pref == 'py':
return mx2pydt(dto)
else:
- raise Exception, 'unknown dto_class/pref combination'
+ raise Exception('unknown dto_class/pref combination')
if isinstance(nativedt, datetime.datetime) and nativedt.tzinfo == None and server_tzinfo != None and local_tzinfo != None:
nativedt = datetime.datetime(nativedt.year, nativedt.month, nativedt.day, nativedt.hour, nativedt.minute, nativedt.second, nativedt.microsecond, server_tzinfo).astimezone(local_tzinfo)
# what type of object is this?
@@ -428,5 +428,5 @@ def main():
assert pydtd.microseconds == mxdtd_msec
if __name__ == '__main__':
- for i in xrange(1000):
+ for i in range(1000):
main()
--- dal/dbapi/dtuple.py.orig 2008-07-25 06:05:12 UTC
+++ dal/dbapi/dtuple.py
@@ -48,7 +48,7 @@ class TupleDescriptor:
"""
self.desc = tuple(desc)
### validate the names?
- self.names = map(lambda x: x[0], desc)
+ self.names = [x[0] for x in desc]
self.namemap = { }
for i in range(len(self.names)):
self.namemap[self.names[i]] = i
@@ -145,7 +145,7 @@ class DatabaseTuple:
def __setattr__(self, name, value):
'Simulate attribute-access via column names'
### need to redirect into a db update
- raise TypeError, "can't assign to this subscripted object"
+ raise TypeError("can't assign to this subscripted object")
def __getitem__(self, key):
'Simulate indexed (tuple/list) and mapping-style access'
@@ -157,9 +157,9 @@ class DatabaseTuple:
'Simulate indexed (tuple/list) and mapping-style access'
if type(key) == type(1):
### need to redirect into a db update of elem #key
- raise TypeError, "can't assign to this subscripted object"
+ raise TypeError("can't assign to this subscripted object")
### need to redirect into a db update of elem named key
- raise TypeError, "can't assign to this subscripted object"
+ raise TypeError("can't assign to this subscripted object")
def __len__(self):
return len(self._data_)
@@ -171,7 +171,7 @@ class DatabaseTuple:
def __setslice__(self, i, j, list):
'Simulate list/tuple slicing access'
### need to redirect into a db update of elems
- raise TypeError, "can't assign to this subscripted object"
+ raise TypeError("can't assign to this subscripted object")
def _keys_(self):
"Simulate mapping's methods"
@@ -183,7 +183,7 @@ class DatabaseTuple:
def _items_(self):
"Simulate mapping's methods"
- return self.asMapping().items()
+ return list(self.asMapping().items())
def _count_(self, item):
"Simulate list's methods"
@@ -214,7 +214,7 @@ class DatabaseTuple:
def asMapping(self):
'Return the "tuple" as a real mapping'
value = { }
- for name, idx in self._desc_.namemap.items():
+ for name, idx in list(self._desc_.namemap.items()):
value[name] = self._data_[idx]
return value
@@ -224,4 +224,4 @@ class DatabaseTuple:
def asList(self):
'Return the "list" as a real mapping'
- return map(None, self._data_)
+ return list(self._data_)
--- dal/dbapi/paramstyles.py.orig 2008-07-25 06:05:12 UTC
+++ dal/dbapi/paramstyles.py
@@ -256,7 +256,7 @@ def segmentize( string ):
if current_segment != '':
segments.append(current_segment)
if quoted:
- raise SegmentizeError, 'Unmatched quotes in string'
+ raise SegmentizeError('Unmatched quotes in string')
return segments
@@ -334,7 +334,7 @@ def convert( from_paramstyle, to_paramstyle, query, pa
try:
convert_function = CONVERSION_MATRIX[from_paramstyle][to_paramstyle]
except KeyError:
- raise NotImplementedError, 'Unsupported paramstyle conversion: %s to %s' % (from_paramstyle, to_paramstyle)
+ raise NotImplementedError('Unsupported paramstyle conversion: %s to %s' % (from_paramstyle, to_paramstyle))
new_query, new_params = convert_function(query, params)
@@ -362,25 +362,25 @@ if __name__ == '__main__':
}
indent = 4
width = 16
- print ''
- print '[ PARAMSTYLE TRANSLATIONS ]'
- print ''
+ print('')
+ print('[ PARAMSTYLE TRANSLATIONS ]')
+ print('')
for from_paramstyle in PARAMSTYLES['all']:
query = tests[from_paramstyle][0]
params = tests[from_paramstyle][1]
- print ''
- print '%s[ %s ]' % (' ' * indent, from_paramstyle.upper())
- print ''
+ print('')
+ print('%s[ %s ]' % (' ' * indent, from_paramstyle.upper()))
+ print('')
label = 'query'
- print '%s%s%s: %s' % (' ' * indent, label, '.' * (width + indent - len(label)), query)
+ print('%s%s%s: %s' % (' ' * indent, label, '.' * (width + indent - len(label)), query))
label = 'paramstyle'
- print '%s%s%s: %s' % (' ' * indent, label, '.' * (width + indent - len(label)), from_paramstyle)
- print ''
+ print('%s%s%s: %s' % (' ' * indent, label, '.' * (width + indent - len(label)), from_paramstyle))
+ print('')
for to_paramstyle in PARAMSTYLES['all']:
converted_query, converted_params = convert(from_paramstyle, to_paramstyle, query, params)
label = '%s_query' % (to_paramstyle)
- print '%s%s%s: %s' % (' ' * indent * 2, label, '.' * (width - len(label)), converted_query)
+ print('%s%s%s: %s' % (' ' * indent * 2, label, '.' * (width - len(label)), converted_query))
label = '%s_params' % (to_paramstyle)
- print '%s%s%s: %s' % (' ' * indent * 2, label, '.' * (width - len(label)), converted_params)
- print ''
+ print('%s%s%s: %s' % (' ' * indent * 2, label, '.' * (width - len(label)), converted_params))
+ print('')
|