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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
|
--- grizzled/collections/dict.py.orig 2010-05-10 02:09:09 UTC
+++ grizzled/collections/dict.py
@@ -64,7 +64,7 @@ class OrderedDict(dict):
def __str__(self):
s = '{'
sep = ''
- for k, v in self.iteritems():
+ for k, v in self.items():
s += sep
if type(k) == str:
s += "'%s'" % k
@@ -98,7 +98,7 @@ class OrderedDict(dict):
yield key
def update(self, d):
- for key, value in d.iteritems():
+ for key, value in d.items():
self[key] = value
def pop(self, key, default=None):
@@ -165,7 +165,7 @@ class LRUList(object):
self.clear()
def __str__(self):
- return '[' + ', '.join([str(tup) for tup in self.items()]) + ']'
+ return '[' + ', '.join([str(tup) for tup in list(self.items())]) + ']'
def __repr__(self):
return self.__class__.__name__ + ':' + str(self)
@@ -177,20 +177,20 @@ class LRUList(object):
entry = self.head
while entry:
yield entry.key
- entry = entry.next
+ entry = entry.__next__
def keys(self):
return [k for k in self]
def items(self):
result = []
- for key, value in self.iteritems():
+ for key, value in self.items():
result.append((key, value))
return result
def values(self):
result = []
- for key, value in self.iteritems():
+ for key, value in self.items():
result.append(value)
return result
@@ -198,7 +198,7 @@ class LRUList(object):
entry = self.head
while entry:
yield (entry.key, entry.value)
- entry = entry.next
+ entry = entry.__next__
def iterkeys(self):
self.__iter__()
@@ -207,12 +207,12 @@ class LRUList(object):
entry = self.head
while entry:
yield entry.value
- entry = entry.next
+ entry = entry.__next__
def clear(self):
while self.head:
cur = self.head
- next = self.head.next
+ next = self.head.__next__
cur.next = cur.previous = cur.key = cur.value = None
self.head = next
@@ -220,14 +220,14 @@ class LRUList(object):
self.size = 0
def remove(self, entry):
- if entry.next:
+ if entry.__next__:
entry.next.previous = entry.previous
if entry.previous:
- entry.previous.next = entry.next
+ entry.previous.next = entry.__next__
if entry == self.head:
- self.head = entry.next
+ self.head = entry.__next__
if entry == self.tail:
self.tail = entry.previous
@@ -309,11 +309,11 @@ class LRUDict(dict):
max_capacity : int
The maximum size of the dictionary
"""
- if kw.has_key('max_capacity'):
+ if 'max_capacity' in kw:
self.__max_capacity = kw['max_capacity']
del kw['max_capacity']
else:
- self.__max_capacity = sys.maxint
+ self.__max_capacity = sys.maxsize
dict.__init__(self)
self.__removal_listeners = {}
@@ -411,7 +411,7 @@ class LRUDict(dict):
"""
Clear all removal and ejection listeners from the list of listeners.
"""
- for key in self.__removal_listeners.keys():
+ for key in list(self.__removal_listeners.keys()):
del self.__removal_listeners[key]
def __setitem__(self, key, value):
@@ -431,7 +431,7 @@ class LRUDict(dict):
def __str__(self):
s = '{'
sep = ''
- for k, v in self.iteritems():
+ for k, v in self.items():
s += sep
if type(k) == str:
s += "'%s'" % k
@@ -462,25 +462,25 @@ class LRUDict(dict):
return value
def keys(self):
- return self.__lru_queue.keys()
+ return list(self.__lru_queue.keys())
def items(self):
- return self.__lru_queue.items()
+ return list(self.__lru_queue.items())
def values(self):
- return self.__lru_queue.values()
+ return list(self.__lru_queue.values())
def iteritems(self):
- return self.__lru_queue.iteritems()
+ return iter(self.__lru_queue.items())
def iterkeys(self):
- return self.__lru_queue.iterkeys()
+ return iter(self.__lru_queue.keys())
def itervalues(self):
- return self.__lru_queue.itervalues()
+ return iter(self.__lru_queue.values())
def update(self, d):
- for key, value in d.iteritems():
+ for key, value in d.items():
self[key] = value
def pop(self, key, default=None):
@@ -507,7 +507,7 @@ class LRUDict(dict):
:raise KeyError: empty dictionary
"""
if len(self) == 0:
- raise KeyError, 'Attempted popitem() on empty dictionary'
+ raise KeyError('Attempted popitem() on empty dictionary')
lru_entry = self.__lru_queue.remove_tail()
dict.__delitem__(self, lru_entry.key)
@@ -553,7 +553,7 @@ class LRUDict(dict):
def __notify_listeners(self, ejecting, key_value_pairs):
if self.__removal_listeners:
for key, value in key_value_pairs:
- for func, func_data in self.__removal_listeners.items():
+ for func, func_data in list(self.__removal_listeners.items()):
on_eject_only, args = func_data
if (not on_eject_only) or ejecting:
func(key, value, *args)
--- grizzled/collections/tuple.py.orig 2010-05-10 02:09:26 UTC
+++ grizzled/collections/tuple.py
@@ -76,7 +76,7 @@ def _local_namedtuple(typename, fieldnames, verbose=Fa
# generating informative error messages and preventing template injection
# attacks.
- if isinstance(fieldnames, basestring):
+ if isinstance(fieldnames, str):
# names separated by whitespace and/or commas
fieldnames = fieldnames.replace(',', ' ').split()
@@ -138,13 +138,13 @@ def _local_namedtuple(typename, fieldnames, verbose=Fa
template += ' %s = property(itemgetter(%d))\n' % (name, i)
if verbose:
- print template
+ print(template)
# Execute the template string in a temporary namespace
namespace = dict(itemgetter=_itemgetter)
try:
- exec template in namespace
- except SyntaxError, e:
+ exec(template, namespace)
+ except SyntaxError as e:
raise SyntaxError(e.message + ':\n' + template)
result = namespace[typename]
--- grizzled/config.py.orig 2010-05-10 02:06:31 UTC
+++ grizzled/config.py
@@ -169,15 +169,15 @@ That will preprocess the enhanced configuration file,
that is suitable for parsing by the standard Python ``config`` module.
'''
-from __future__ import absolute_import
+
__docformat__ = "restructuredtext en"
# ---------------------------------------------------------------------------
# Imports
# ---------------------------------------------------------------------------
-import ConfigParser
+import configparser
import logging
import string
import os
@@ -200,8 +200,8 @@ __all__ = ['Configuration', 'preprocess',
# ---------------------------------------------------------------------------
log = logging.getLogger('grizzled.config')
-NoOptionError = ConfigParser.NoOptionError
-NoSectionError = ConfigParser.NoSectionError
+NoOptionError = configparser.NoOptionError
+NoSectionError = configparser.NoSectionError
# ---------------------------------------------------------------------------
# Constants
@@ -250,7 +250,7 @@ class NoVariableError(ExceptionWithMessage):
"""
pass
-class Configuration(ConfigParser.SafeConfigParser):
+class Configuration(configparser.SafeConfigParser):
"""
Configuration file parser. See the module documentation for details.
"""
@@ -279,7 +279,7 @@ class Configuration(ConfigParser.SafeConfigParser):
substitute a non-existent variable. Otherwise, simple
substitute an empty value.
"""
- ConfigParser.SafeConfigParser.__init__(self, defaults)
+ configparser.SafeConfigParser.__init__(self, defaults)
self.__permit_includes = permit_includes
self.__use_ordered_sections = use_ordered_sections
self.__strict_substitution = strict_substitution
@@ -294,7 +294,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:rtype: dict
:return: the instance-wide defaults, or ``None`` if there aren't any
"""
- return ConfigParser.SafeConfigParser.defaults(self)
+ return configparser.SafeConfigParser.defaults(self)
@property
def sections(self):
@@ -305,7 +305,7 @@ class Configuration(ConfigParser.SafeConfigParser):
Returns a list of sections.
"""
- return ConfigParser.SafeConfigParser.sections(self)
+ return configparser.SafeConfigParser.sections(self)
def add_section(self, section):
"""
@@ -318,7 +318,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise DuplicateSectionError: section already exists
"""
- ConfigParser.SafeConfigParser.add_section(self, section)
+ configparser.SafeConfigParser.add_section(self, section)
def has_section(self, section):
"""
@@ -333,7 +333,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:return: ``True`` if the section exists in the configuration, ``False``
if not.
"""
- return ConfigParser.SafeConfigParser.has_section(self, section)
+ return configparser.SafeConfigParser.has_section(self, section)
def options(self, section):
"""
@@ -348,7 +348,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoSectionError: no such section
"""
- return ConfigParser.SafeConfigParser.options(self, section)
+ return configparser.SafeConfigParser.options(self, section)
def has_option(self, section, option):
"""
@@ -364,7 +364,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:return: ``True`` if the section exists in the configuration and
has the specified option, ``False`` if not.
"""
- return ConfigParser.SafeConfigParser.has_option(self, section, option)
+ return configparser.SafeConfigParser.has_option(self, section, option)
def read(self, filenames):
"""
@@ -398,7 +398,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:rtype: list
:return: list of successfully parsed filenames or URLs
"""
- if isinstance(filenames, basestring):
+ if isinstance(filenames, str):
filenames = [filenames]
newFilenames = []
@@ -446,9 +446,9 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoOptionError: no such option in the section
"""
def do_get(section, option):
- val = ConfigParser.SafeConfigParser.get(self, section, option)
+ val = configparser.SafeConfigParser.get(self, section, option)
if len(val.strip()) == 0:
- raise ConfigParser.NoOptionError(option, section)
+ raise configparser.NoOptionError(option, section)
return val
if optional:
@@ -477,7 +477,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoOptionError: no such option in the section
"""
def do_get(section, option):
- return ConfigParser.SafeConfigParser.getint(self, section, option)
+ return configparser.SafeConfigParser.getint(self, section, option)
if optional:
return self.__get_optional(do_xget, section, option)
@@ -505,7 +505,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoOptionError: no such option in the section
"""
def do_get(section, option):
- return ConfigParser.SafeConfigParser.getfloat(self, section, option)
+ return configparser.SafeConfigParser.getfloat(self, section, option)
if optional:
return self.__get_optional(do_get, section, option)
@@ -538,7 +538,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise ValueError: non-boolean value encountered
'''
def do_get(section, option):
- return ConfigParser.SafeConfigParser.getboolean(self,
+ return configparser.SafeConfigParser.getboolean(self,
section,
option)
@@ -572,7 +572,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoOptionError: no such option in the section
'''
def do_get(section, option):
- value = ConfigParser.SafeConfigParser.get(self, section, option)
+ value = configparser.SafeConfigParser.get(self, section, option)
return value.split(sep)
if optional:
@@ -667,7 +667,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoSectionError: no such section
"""
- return ConfigParser.SafeConfigParser.items(self, section)
+ return configparser.SafeConfigParser.items(self, section)
def set(self, section, option, value):
"""
@@ -684,7 +684,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoSectionError: no such section
"""
- ConfigParser.SafeConfigParser.set(self, section, option, value)
+ configparser.SafeConfigParser.set(self, section, option, value)
def write(self, fileobj):
"""
@@ -698,7 +698,7 @@ class Configuration(ConfigParser.SafeConfigParser):
fileobj : file
file-like object to which to write the configuration
"""
- ConfigParser.SafeConfigParser.write(self, fileobj)
+ configparser.SafeConfigParser.write(self, fileobj)
def remove_section(self, section):
"""
@@ -711,7 +711,7 @@ class Configuration(ConfigParser.SafeConfigParser):
:raise NoSectionError: no such section
"""
- ConfigParser.SafeConfigParser.remove_section(self, section)
+ configparser.SafeConfigParser.remove_section(self, section)
def optionxform(self, option_name):
"""
@@ -728,9 +728,9 @@ class Configuration(ConfigParser.SafeConfigParser):
def __get_optional(self, func, section, option):
try:
return func(section, option)
- except ConfigParser.NoOptionError:
+ except configparser.NoOptionError:
return None
- except ConfigParser.NoSectionError:
+ except configparser.NoSectionError:
return None
def __preprocess(self, fp, name):
@@ -755,7 +755,7 @@ class Configuration(ConfigParser.SafeConfigParser):
# Parse the resulting file into a local ConfigParser instance.
- parsedConfig = ConfigParser.SafeConfigParser()
+ parsedConfig = configparser.SafeConfigParser()
if self.__use_ordered_sections:
parsedConfig._sections = OrderedDict()
@@ -853,15 +853,15 @@ class _ConfigDict(dict):
except KeyError:
result = default
- except ConfigParser.NoSectionError:
+ except configparser.NoSectionError:
result = default
- except ConfigParser.NoOptionError:
+ except configparser.NoOptionError:
result = default
if not result:
if self.__strict_substitution:
- raise NoVariableError, 'No such variable: "%s"' % key
+ raise NoVariableError('No such variable: "%s"' % key)
else:
result = ''
@@ -888,7 +888,7 @@ class _ConfigDict(dict):
if section == 'env':
result = os.environ[option]
if len(result) == 0:
- raise KeyError, option
+ raise KeyError(option)
elif section == 'program':
result = self.__value_from_program_section(option)
@@ -968,6 +968,6 @@ if __name__ == '__main__':
for var in sys.argv[2:]:
(section, option) = var.split(':')
val = config.get(section, option, optional=True)
- print '%s=%s' % (var, val)
+ print('%s=%s' % (var, val))
else:
config.write(sys.stdout)
--- grizzled/db/__init__.py.orig 2009-10-24 15:46:15 UTC
+++ grizzled/db/__init__.py
@@ -149,8 +149,8 @@ def add_driver(key, driver_class, force=False):
try:
drivers[key]
if not force:
- raise ValueError, 'A DB driver named "%s" is already installed' %\
- key
+ raise ValueError('A DB driver named "%s" is already installed' %\
+ key)
except KeyError:
pass
@@ -170,7 +170,7 @@ def get_drivers():
:rtype: list
:return: list of ``DBDriver`` class names
"""
- return [str(d) for d in drivers.values()]
+ return [str(d) for d in list(drivers.values())]
def get_driver_names():
"""
@@ -178,7 +178,7 @@ def get_driver_names():
Each of the returned names may be used as the first parameter to
the ``get_driver()`` function.
"""
- return drivers.keys()
+ return list(drivers.keys())
def get_driver(driver_name):
"""
@@ -197,9 +197,9 @@ def get_driver(driver_name):
try:
o = drivers[driver_name]
if type(o) == str:
- exec 'd = %s()' % o
+ exec('d = %s()' % o)
else:
d = o()
return d
except KeyError:
- raise ValueError, 'Unknown driver name: "%s"' % driver_name
+ raise ValueError('Unknown driver name: "%s"' % driver_name)
--- grizzled/db/base.py.orig 2009-10-24 15:45:34 UTC
+++ grizzled/db/base.py
@@ -118,9 +118,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__cursor.close()
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def execute(self, statement, parameters=None):
@@ -152,9 +152,9 @@ class Cursor(object):
self.__rowcount = -1
self.__description = self.__cursor.description
return result
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
except:
raise Error(sys.exc_info()[1])
@@ -181,9 +181,9 @@ class Cursor(object):
self.__rowcount = self.__cursor.rowcount
self.__description = self.__cursor.description
return result
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
executeMany = executemany
@@ -202,9 +202,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__cursor.fetchone()
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def fetchall(self):
@@ -221,9 +221,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__cursor.fetchall()
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
fetchAll = fetchall
@@ -247,9 +247,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
self.__cursor.fetchmany(n)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
fetchMany = fetchmany
@@ -277,9 +277,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__driver.get_rdbms_metadata(self.__cursor)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def get_table_metadata(self, table):
@@ -321,9 +321,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__driver.get_table_metadata(table, self.__cursor)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def get_index_metadata(self, table):
@@ -355,9 +355,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__driver.get_index_metadata(table, self.__cursor)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def get_tables(self):
@@ -376,9 +376,9 @@ class Cursor(object):
dbi = self.__driver.get_import()
try:
return self.__driver.get_tables(self.__cursor)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
class DB(object):
@@ -403,9 +403,9 @@ class DB(object):
dbi = driver.get_import()
for attr in ['BINARY', 'NUMBER', 'STRING', 'DATETIME', 'ROWID']:
try:
- exec 'self.%s = dbi.%s' % (attr, attr)
+ exec('self.%s = dbi.%s' % (attr, attr))
except AttributeError:
- exec 'self.%s = 0' % attr
+ exec('self.%s = 0' % attr)
def paramstyle(self):
"""
@@ -607,9 +607,9 @@ class DB(object):
dbi = self.__driver.get_import()
try:
return Cursor(self.__db.cursor(), self.__driver)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def commit(self):
@@ -622,9 +622,9 @@ class DB(object):
dbi = self.__driver.get_import()
try:
self.__db.commit()
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def rollback(self):
@@ -637,9 +637,9 @@ class DB(object):
dbi = self.__driver.get_import()
try:
self.__db.rollback()
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
def close(self):
@@ -652,9 +652,9 @@ class DB(object):
dbi = self.__driver.get_import()
try:
self.__db.close()
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
class DBDriver(object):
@@ -734,9 +734,9 @@ class DBDriver(object):
password=password,
database=database)
return DB(self.__db, self)
- except dbi.Warning, val:
+ except dbi.Warning as val:
raise Warning(val)
- except dbi.Error, val:
+ except dbi.Error as val:
raise Error(val)
@abstract
@@ -958,7 +958,7 @@ class DBDriver(object):
:raise Error: bad table name
"""
if not self._is_valid_table(cursor, table_name):
- raise Error, 'No such table: "%s"' % table_name
+ raise Error('No such table: "%s"' % table_name)
def _is_valid_table(self, cursor, table_name):
"""
--- grizzled/db/dummydb.py.orig 2009-10-24 15:45:33 UTC
+++ grizzled/db/dummydb.py
@@ -37,13 +37,13 @@ class DummyCursor(object):
return None
def fetchone(self):
- raise ValueError, "No results"
+ raise ValueError("No results")
def fetchall(self):
- raise ValueError, "No results"
+ raise ValueError("No results")
def fetchmany(self, n):
- raise ValueError, "No results"
+ raise ValueError("No results")
class DummyDB(object):
@@ -66,7 +66,7 @@ class DummyDriver(DBDriver):
"""Dummy database driver, for testing."""
def get_import(self):
- import dummydb
+ from . import dummydb
return dummydb
def get_display_name(self):
--- grizzled/decorators.py.orig 2010-05-10 02:06:50 UTC
+++ grizzled/decorators.py
@@ -177,5 +177,5 @@ if __name__ == '__main__':
try:
b.foo()
assert False
- except NotImplementedError, ex:
- print ex.message
+ except NotImplementedError as ex:
+ print(ex.message)
--- grizzled/file/__init__.py.orig 2010-05-10 02:04:49 UTC
+++ grizzled/file/__init__.py
@@ -2,8 +2,8 @@
This module contains file- and path-related methods, classes, and modules.
"""
-from __future__ import with_statement, absolute_import
+
__docformat__ = "restructuredtext en"
# ---------------------------------------------------------------------------
@@ -79,7 +79,7 @@ def list_recursively(dir):
but is not a directory.
"""
if not _os.path.isdir(dir):
- raise ValueError, "%s is not a directory." % dir
+ raise ValueError("%s is not a directory." % dir)
for f in _os.listdir(dir):
if _os.path.isdir(f):
@@ -135,7 +135,7 @@ def copy(files, target_dir, create_target=False):
_os.mkdir(target_dir)
if _os.path.exists(target_dir) and (not _os.path.isdir(target_dir)):
- raise OSError, 'Cannot copy files to non-directory "%s"' % target_dir
+ raise OSError('Cannot copy files to non-directory "%s"' % target_dir)
for f in files:
targetFile = _os.path.join(target_dir, _os.path.basename(f))
@@ -167,7 +167,7 @@ def touch(files, times=None):
for f in files:
if _os.path.exists(f):
if not _os.path.isfile(f):
- raise OSError, "Can't touch non-file \"%s\"" % f
+ raise OSError("Can't touch non-file \"%s\"" % f)
_os.utime(f, times)
else:
--- grizzled/file/includer.py.orig 2010-05-10 02:05:02 UTC
+++ grizzled/file/includer.py
@@ -89,8 +89,8 @@ import sys
import re
import tempfile
import atexit
-import urllib2
-import urlparse
+import urllib.request, urllib.error, urllib.parse
+import urllib.parse
import grizzled.exception
from grizzled.file import unlink_quietly
@@ -179,7 +179,7 @@ class Includer(object):
self.__name = name
if output == None:
- from cStringIO import StringIO
+ from io import StringIO
output = StringIO()
self.__maxnest = max_nest_level
@@ -198,7 +198,7 @@ class Includer(object):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
"""A file object is its own iterator.
:rtype: string
@@ -302,15 +302,15 @@ class Includer(object):
def truncate(self, size=None):
"""Not supported, since ``Includer`` objects are read-only."""
- raise IncludeError, 'Includers are read-only file objects.'
+ raise IncludeError('Includers are read-only file objects.')
def write(self, s):
"""Not supported, since ``Includer`` objects are read-only."""
- raise IncludeError, 'Includers are read-only file objects.'
+ raise IncludeError('Includers are read-only file objects.')
def writelines(self, iterable):
"""Not supported, since ``Includer`` objects are read-only."""
- raise IncludeError, 'Includers are read-only file objects.'
+ raise IncludeError('Includers are read-only file objects.')
def flush(self):
"""No-op."""
@@ -333,8 +333,8 @@ class Includer(object):
match = self.__include_pattern.search(line)
if match:
if self.__nested >= self.__maxnest:
- raise IncludeError, 'Exceeded maximum include recursion ' \
- 'depth of %d' % self.__maxnest
+ raise IncludeError('Exceeded maximum include recursion ' \
+ 'depth of %d' % self.__maxnest)
inc_name = match.group(1)
logging.debug('Found include directive: %s' % line[:-1])
@@ -351,12 +351,12 @@ class Includer(object):
is_url = False
openFunc = None
- parsed_url = urlparse.urlparse(name_to_open)
+ parsed_url = urllib.parse.urlparse(name_to_open)
# Account for Windows drive letters.
if (parsed_url.scheme != '') and (len(parsed_url.scheme) > 1):
- openFunc = urllib2.urlopen
+ openFunc = urllib.request.urlopen
is_url = True
else:
@@ -365,8 +365,8 @@ class Includer(object):
if enclosing_file_is_url:
# Use the parent URL as the base URL.
- name_to_open = urlparse.urljoin(enclosing_file, name_to_open)
- open_func = urllib2.urlopen
+ name_to_open = urllib.parse.urljoin(enclosing_file, name_to_open)
+ open_func = urllib.request.urlopen
is_url = True
elif not os.path.isabs(name_to_open):
@@ -391,8 +391,8 @@ class Includer(object):
log.debug('Opening "%s"' % name_to_open)
f = open_func(name_to_open)
except:
- raise IncludeError, 'Unable to open "%s" as a file or a URL' %\
- name_to_open
+ raise IncludeError('Unable to open "%s" as a file or a URL' %\
+ name_to_open)
return (f, is_url, name_to_open)
# ---------------------------------------------------------------------------
@@ -441,7 +441,7 @@ def preprocess(file_or_url, output=None, temp_suffix='
def _complain_if_closed(closed):
if closed:
- raise IncludeError, "I/O operation on closed file"
+ raise IncludeError("I/O operation on closed file")
# ---------------------------------------------------------------------------
# Main program (for testing)
@@ -453,21 +453,21 @@ if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, format=format)
for file in sys.argv[1:]:
- import cStringIO as StringIO
+ import io as StringIO
out = StringIO.StringIO()
preprocess(file, output=out)
header = 'File: %s, via preprocess()'
sep = '-' * len(header)
- print '\n%s\n%s\n%s\n' % (sep, header, sep)
+ print('\n%s\n%s\n%s\n' % (sep, header, sep))
for line in out.readlines():
sys.stdout.write(line)
- print sep
+ print(sep)
inc = Includer(file)
header = 'File: %s, via Includer'
sep = '-' * len(header)
- print '\n%s\n%s\n%s\n' % (sep, header, sep)
+ print('\n%s\n%s\n%s\n' % (sep, header, sep))
for line in inc:
sys.stdout.write(line)
- print '%s' % sep
+ print('%s' % sep)
--- grizzled/history.py.orig 2010-05-10 02:07:04 UTC
+++ grizzled/history.py
@@ -19,8 +19,8 @@ To get the appropriate History implementation for the
simply call the ``get_history()`` factory method.
"""
-from __future__ import with_statement
+
__docformat__ = "restructuredtext en"
# ---------------------------------------------------------------------------
@@ -90,16 +90,16 @@ def get_history(verbose=True):
result = None
if _have_pyreadline:
if verbose:
- print 'Using pyreadline for history management.'
+ print('Using pyreadline for history management.')
result = PyReadlineHistory()
elif _have_readline:
if verbose:
- print 'Using readline for history management.'
+ print('Using readline for history management.')
result = ReadlineHistory()
else:
- print 'WARNING: Readline unavailable. There will be no history.'
+ print('WARNING: Readline unavailable. There will be no history.')
result = DummyHistory()
result.max_length = DEFAULT_MAXLENGTH
@@ -132,7 +132,7 @@ class History(object):
Where to dump the history.
"""
for i in range(1, self.total + 1):
- print >> out, '%4d: %s' % (i, self.get_item(i))
+ print('%4d: %s' % (i, self.get_item(i)), file=out)
def get_last_matching_item(self, command_name):
"""
--- grizzled/io/__init__.py.orig 2009-10-24 15:48:25 UTC
+++ grizzled/io/__init__.py
@@ -4,8 +4,8 @@
Input/Output utility methods and classes.
"""
-from __future__ import absolute_import
+
__docformat__ = "restructuredtext en"
# ---------------------------------------------------------------------------
@@ -201,7 +201,7 @@ class PushbackFile(object):
:raise NotImplementedError: unconditionally
"""
- raise NotImplementedError, 'PushbackFile is read-only'
+ raise NotImplementedError('PushbackFile is read-only')
def pushback(self, s):
"""
@@ -271,7 +271,7 @@ class PushbackFile(object):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
"""A file object is its own iterator.
:rtype: str
@@ -296,7 +296,7 @@ class PushbackFile(object):
:raise NotImplementedError: unconditionally
"""
- raise NotImplementedError, 'PushbackFile is read-only'
+ raise NotImplementedError('PushbackFile is read-only')
def truncate(self, size=-1):
"""
@@ -310,7 +310,7 @@ class PushbackFile(object):
:raise NotImplementedError: unconditionally
"""
- raise NotImplementedError, 'PushbackFile is read-only'
+ raise NotImplementedError('PushbackFile is read-only')
def tell(self):
"""
@@ -323,7 +323,7 @@ class PushbackFile(object):
:raise NotImplementedError: unconditionally
"""
- raise NotImplementedError, 'PushbackFile is not seekable'
+ raise NotImplementedError('PushbackFile is not seekable')
def seek(self, offset, whence=os.SEEK_SET):
"""
@@ -338,7 +338,7 @@ class PushbackFile(object):
:raise NotImplementedError: unconditionally
"""
- raise NotImplementedError, 'PushbackFile is not seekable'
+ raise NotImplementedError('PushbackFile is not seekable')
def fileno(self):
"""
--- grizzled/io/filelock.py.orig 2009-10-24 15:46:23 UTC
+++ grizzled/io/filelock.py
@@ -88,8 +88,7 @@ class FileLock(object):
self.lock = cls(fd)
except KeyError:
- raise NotImplementedError, \
- '''Don't know how to lock files on "%s" systems.''' % os.name
+ raise NotImplementedError('''Don't know how to lock files on "%s" systems.''' % os.name)
def acquire(self, no_wait=False):
"""
--- grizzled/net/ftp/parse.py.orig 2009-10-24 15:52:59 UTC
+++ grizzled/net/ftp/parse.py
@@ -226,10 +226,10 @@ class FTPListDataParser(object):
elif c == 'r':
result.try_retr = True
elif c == 's':
- result.size = long(buf[i+1:j])
+ result.size = int(buf[i+1:j])
elif c == 'm':
result.mtime_type = MTIME_TYPE.LOCAL
- result.mtime = long(buf[i+1:j])
+ result.mtime = int(buf[i+1:j])
elif c == 'i':
result.id_type = ID_TYPE.FULL
result.id = buf[i+1:j-i-1]
@@ -290,7 +290,7 @@ class FTPListDataParser(object):
elif state == 4: # getting tentative size
try:
- size = long(buf[i:j])
+ size = int(buf[i:j])
except ValueError:
pass
state = 5
@@ -300,25 +300,25 @@ class FTPListDataParser(object):
if month >= 0:
state = 6
else:
- size = long(buf[i:j])
+ size = int(buf[i:j])
elif state == 6: # have size and month
- mday = long(buf[i:j])
+ mday = int(buf[i:j])
state = 7
elif state == 7: # have size, month, mday
if (j - i == 4) and (buf[i+1] == ':'):
- hour = long(buf[i])
- minute = long(buf[i+2:i+4])
+ hour = int(buf[i])
+ minute = int(buf[i+2:i+4])
result.mtime_type = MTIME_TYPE.REMOTE_MINUTE
result.mtime = self._guess_time(month, mday, hour, minute)
elif (j - i == 5) and (buf[i+2] == ':'):
- hour = long(buf[i:i+2])
- minute = long(buf[i+3:i+5])
+ hour = int(buf[i:i+2])
+ minute = int(buf[i+3:i+5])
result.mtime_type = MTIME_TYPE.REMOTE_MINUTE
result.mtime = self._guess_time(month, mday, hour, minute)
elif j - i >= 4:
- year = long(buf[i:j])
+ year = int(buf[i:j])
result.mtimetype = MTIME_TYPE.REMOTE_DAY
result.mtime = self._get_mtime(year, month, mday)
else:
@@ -383,7 +383,7 @@ class FTPListDataParser(object):
j = i
j = buf.index('-', j)
- mday = long(buf[i:j])
+ mday = int(buf[i:j])
j = _skip(buf, j, '-')
i = j
@@ -395,13 +395,13 @@ class FTPListDataParser(object):
j = _skip(buf, j, '-')
i = j
j = buf.index(' ', j)
- year = long(buf[i:j])
+ year = int(buf[i:j])
j = _skip(buf, j, ' ')
i = j
j = buf.index(':', j)
- hour = long(buf[i:j])
+ hour = int(buf[i:j])
j = _skip(buf, j, ':')
i = j
@@ -410,7 +410,7 @@ class FTPListDataParser(object):
if j == buflen:
raise IndexError # abort, abort!
- minute = long(buf[i:j])
+ minute = int(buf[i:j])
result.mtimetype = MTIME_TYPE.REMOTE_MINUTE
result.mtime = self._get_mtime(year, month, mday, hour, minute)
@@ -434,17 +434,17 @@ class FTPListDataParser(object):
result = FTPListData(buf)
j = buf.index('-', j)
- month = long(buf[i:j])
+ month = int(buf[i:j])
j = _skip(buf, j, '-')
i = j
j = buf.index('-', j)
- mday = long(buf[i:j])
+ mday = int(buf[i:j])
j = _skip(buf, j, '-')
i = j
j = buf.index(' ', j)
- year = long(buf[i:j])
+ year = int(buf[i:j])
if year < 50:
year += 2000
if year < 1000:
@@ -453,14 +453,14 @@ class FTPListDataParser(object):
j = _skip(buf, j, ' ')
i = j
j = buf.index(':', j)
- hour = long(buf[i:j])
+ hour = int(buf[i:j])
j = _skip(buf, j, ':')
i = j
while not (buf[j] in 'AP'):
j += 1
if j == buflen:
raise IndexError
- minute = long(buf[i:j])
+ minute = int(buf[i:j])
if buf[j] == 'A':
j += 1
@@ -486,7 +486,7 @@ class FTPListDataParser(object):
i = j
j = buf.index(' ', j)
- result.size = long(buf[i:j])
+ result.size = int(buf[i:j])
result.try_retr = True
j = _skip(buf, j, ' ')
@@ -560,7 +560,7 @@ if __name__ == '__main__':
{'line': '-rw-r--r-- 1 root other 531 Jan 29 03:26 README',
'type': 'Unix',
'size': 531,
- 'time': (current_year, 1, 29, 03, 26, 0, 0, 0, -1),
+ 'time': (current_year, 1, 29, 0o3, 26, 0, 0, 0, -1),
'name': 'README',
'try_cwd': False},
@@ -632,7 +632,7 @@ if __name__ == '__main__':
'type': 'MultiNet/VMS',
'size': 0,
# Doesn't parse the seconds
- 'time': (1996, 1, 29, 03, 33, 0, 0, 0, -1),
+ 'time': (1996, 1, 29, 0o3, 33, 0, 0, 0, -1),
'name': 'CII-MANUAL.TEX',
'try_cwd': False},
@@ -655,7 +655,7 @@ if __name__ == '__main__':
{'line': '04-14-99 03:47PM 589 readme.htm',
'type': 'MS-DOS',
'size': 589,
- 'time': (1999, 04, 14, 15, 47, 0, 0, 0, -1),
+ 'time': (1999, 0o4, 14, 15, 47, 0, 0, 0, -1),
'name': 'readme.htm',
'try_cwd': False},
]
@@ -671,7 +671,7 @@ if __name__ == '__main__':
for test in test_data:
line = test['line']
prefix = 'Test %d (%s)' % (i, test['type'])
- print '%s: "%s"' % (prefix, test['name'])
+ print('%s: "%s"' % (prefix, test['name']))
result = parser.parse_line(line)
assertEquals(result.raw_line, line, prefix)
assertEquals(result.size, test['size'], prefix)
--- grizzled/os.py.orig 2010-05-10 02:08:04 UTC
+++ grizzled/os.py
@@ -11,8 +11,8 @@ The ``grizzled.os`` module contains some operating sys
classes. It is a conceptual extension of the standard Python ``os`` module.
"""
-from __future__ import absolute_import
+
__docformat__ = "restructuredtext en"
# ---------------------------------------------------------------------------
@@ -270,8 +270,8 @@ def daemonize(no_close=False, pidfile=None):
def __fork():
try:
return _os.fork()
- except OSError, e:
- raise DaemonError, ('Cannot fork', e.errno, e.strerror)
+ except OSError as e:
+ raise DaemonError('Cannot fork', e.errno, e.strerror)
def __redirect_file_descriptors():
import resource # POSIX resource information
@@ -306,8 +306,7 @@ def daemonize(no_close=False, pidfile=None):
if _os.name != 'posix':
import errno
- raise DaemonError, \
- ('daemonize() is only supported on Posix-compliant systems.',
+ raise DaemonError('daemonize() is only supported on Posix-compliant systems.',
errno.ENOSYS, _os.strerror(errno.ENOSYS))
try:
@@ -358,8 +357,8 @@ def daemonize(no_close=False, pidfile=None):
except DaemonError:
raise
- except OSError, e:
- raise DaemonError, ('Unable to daemonize()', e.errno, e.strerror)
+ except OSError as e:
+ raise DaemonError('Unable to daemonize()', e.errno, e.strerror)
# ---------------------------------------------------------------------------
# Main program (for testing)
--- grizzled/system.py.orig 2010-05-10 02:07:54 UTC
+++ grizzled/system.py
@@ -10,8 +10,8 @@ provide information about the Python system (the Pytho
etc.). It is a conceptual extension of the standard Python ``sys`` module.
"""
-from __future__ import absolute_import
+
__docformat__ = "restructuredtext en"
# ---------------------------------------------------------------------------
@@ -95,7 +95,7 @@ def python_version(version):
tokens = version.split('.')
if len(tokens) > 3:
- raise ValueError, err
+ raise ValueError(err)
major = int(tokens[0])
minor = micro = serial = 0
@@ -104,7 +104,7 @@ def python_version(version):
if len(tokens) > 1:
match = RELEASE_LEVEL_RE.match(tokens[1])
if not match:
- raise ValueError, err
+ raise ValueError(err)
minor = int(match.group(1))
rl = match.group(2)
@@ -115,12 +115,12 @@ def python_version(version):
if len(tokens) > 2:
match = RELEASE_LEVEL_RE.match(tokens[2])
if not match:
- raise ValueError, err
+ raise ValueError(err)
micro = int(match.group(1))
rl2 = match.group(2)
if rl and rl2:
- raise ValueError, err
+ raise ValueError(err)
if rl2:
release_level = rl2[0]
serial = int(rl2[1:])
@@ -128,7 +128,7 @@ def python_version(version):
try:
release_level = RELEASE_LEVELS[release_level]
except KeyError:
- raise ValueError, err
+ raise ValueError(err)
return (major << 24) |\
(minor << 16) |\
@@ -160,9 +160,8 @@ def split_python_version(version=None):
release_level_string = RELEASE_LEVEL_NAMES.get(release_level, None)
if not release_level_string:
- raise ValueError, \
- 'Bad release level 0x%x in version 0x%08x' %\
- (release_level, version)
+ raise ValueError('Bad release level 0x%x in version 0x%08x' %\
+ (release_level, version))
return (major, minor, micro, release_level_string, serial)
@@ -208,15 +207,13 @@ def ensure_version(min_version):
elif type(min_version) == int:
pass
else:
- raise TypeError, \
- 'version %s is not a string or an integer' % min_version
+ raise TypeError('version %s is not a string or an integer' % min_version)
if _sys.hexversion < min_version:
- raise RuntimeError, \
- 'This program requires Python version "%s" or better, but ' \
+ raise RuntimeError('This program requires Python version "%s" or better, but ' \
'the current Python version is "%s".' %\
(python_version_string(min_version),
- python_version_string(sys.hexversion))
+ python_version_string(sys.hexversion)))
def class_for_name(class_name):
@@ -238,7 +235,7 @@ def class_for_name(class_name):
if len(tokens) > 1:
package = '.'.join(tokens[:-1])
class_name = tokens[-1]
- exec 'from %s import %s' % (package, class_name)
+ exec('from %s import %s' % (package, class_name))
return eval(class_name)
--- grizzled/text/__init__.py.orig 2009-10-24 15:46:33 UTC
+++ grizzled/text/__init__.py
@@ -10,7 +10,7 @@ __docformat__ = "restructuredtext en"
# Imports
# ---------------------------------------------------------------------------
-from StringIO import StringIO
+from io import StringIO
# ---------------------------------------------------------------------------
# Exports
@@ -117,10 +117,10 @@ def hexdump(source, out, width=16, start=0, limit=None
if length == 0:
if repeat_count and (not show_repeats):
if repeat_count > 1:
- print >> out, REPEAT_FORMAT % (repeat_count - 1)
+ print(REPEAT_FORMAT % (repeat_count - 1), file=out)
elif repeat_count == 1:
- print >> out, lastline
- print >> out, lastline
+ print(lastline, file=out)
+ print(lastline, file=out)
break
else:
@@ -132,9 +132,9 @@ def hexdump(source, out, width=16, start=0, limit=None
else:
if repeat_count and (not show_repeats):
if repeat_count == 1:
- print >> out, lastline
+ print(lastline, file=out)
else:
- print >> out, REPEAT_FORMAT % (repeat_count - 1)
+ print(REPEAT_FORMAT % (repeat_count - 1), file=out)
repeat_count = 0
# Build output line.
@@ -149,7 +149,7 @@ def hexdump(source, out, width=16, start=0, limit=None
line = "%06x: %-*s %s" % (pos, hex_field_width, hex, asc)
if show_buf:
- print >> out, line
+ print(line, file=out)
pos = pos + length
lastbuf = buf
@@ -214,4 +214,4 @@ def str2bool(s):
'off' : False,
'on' : True}[s.lower()]
except KeyError:
- raise ValueError, 'Unrecognized boolean string: "%s"' % s
+ raise ValueError('Unrecognized boolean string: "%s"' % s)
--- test/collections/TestLRUDict.py.orig 2008-09-10 01:27:50 UTC
+++ test/collections/TestLRUDict.py
@@ -25,68 +25,68 @@ class TestLRUDict(object):
def test1(self):
lru = LRUDict(max_capacity=5)
- print "Adding 'a' and 'b'"
+ print("Adding 'a' and 'b'")
lru['a'] = 'A'
lru['b'] = 'b'
- print lru
- print lru.keys()
- assert lru.keys() == ['b', 'a']
- assert lru.values() == ['b', 'A']
+ print(lru)
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['b', 'a']
+ assert list(lru.values()) == ['b', 'A']
- print "Adding 'c'"
+ print("Adding 'c'")
lru['c'] = 'c'
- print lru
- print lru.keys()
- assert lru.keys() == ['c', 'b', 'a']
+ print(lru)
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['c', 'b', 'a']
- print "Updating 'a'"
+ print("Updating 'a'")
lru['a'] = 'a'
- print lru
- print lru.keys()
- assert lru.keys() == ['a', 'c', 'b']
+ print(lru)
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['a', 'c', 'b']
- print "Adding 'd' and 'e'"
+ print("Adding 'd' and 'e'")
lru['d'] = 'd'
lru['e'] = 'e'
- print lru
- print lru.keys()
- assert lru.keys() == ['e', 'd', 'a', 'c', 'b']
+ print(lru)
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['e', 'd', 'a', 'c', 'b']
- print "Accessing 'b'"
+ print("Accessing 'b'")
assert lru['b'] == 'b'
- print lru
- print lru.keys()
- assert lru.keys() == ['b', 'e', 'd', 'a', 'c']
+ print(lru)
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['b', 'e', 'd', 'a', 'c']
- print "Adding 'f'"
+ print("Adding 'f'")
lru['f'] = 'f'
# Should knock 'c' out of the list
- print lru
- print lru.keys()
- assert lru.keys() == ['f', 'b', 'e', 'd', 'a']
+ print(lru)
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['f', 'b', 'e', 'd', 'a']
def on_remove(key, value, the_list):
- print 'on_remove("%s")' % key
+ print('on_remove("%s")' % key)
the_list.append(key)
- print 'Reducing capacity. Should result in eviction.'
+ print('Reducing capacity. Should result in eviction.')
ejected = []
lru.add_ejection_listener(on_remove, ejected)
lru.max_capacity = 3
ejected.sort()
- print 'ejected=%s' % ejected
+ print('ejected=%s' % ejected)
assert ejected == ['a', 'd']
- print lru.keys()
- assert lru.keys() == ['f', 'b', 'e']
+ print(list(lru.keys()))
+ assert list(lru.keys()) == ['f', 'b', 'e']
- print 'Testing popitem()'
+ print('Testing popitem()')
key, value = lru.popitem()
- print lru
- print lru.keys()
+ print(lru)
+ print(list(lru.keys()))
assert key == 'e'
- assert lru.keys() == ['f', 'b']
+ assert list(lru.keys()) == ['f', 'b']
- print 'Clearing dictionary'
+ print('Clearing dictionary')
lru.clear_listeners()
lru.clear()
del lru
@@ -95,12 +95,12 @@ class TestLRUDict(object):
lru[key] = key
def testBig(self):
- print 'Putting 10000 entries in a new LRU cache'
+ print('Putting 10000 entries in a new LRU cache')
lru = LRUDict(max_capacity=10000)
for i in range(0, lru.max_capacity):
lru[i] = i
assert len(lru) == lru.max_capacity
- print 'Adding one more'
+ print('Adding one more')
assert len(lru) == lru.max_capacity
- print iter(lru).next()
+ print(next(iter(lru)))
--- test/file/Test.py.orig 2008-09-10 01:27:50 UTC
+++ test/file/Test.py
@@ -7,7 +7,7 @@
# ---------------------------------------------------------------------------
from grizzled.file import *
-from cStringIO import StringIO
+from io import StringIO
import os
import tempfile
import atexit
@@ -36,7 +36,7 @@ class TestFilePackage(object):
def testRecursivelyRemove(self):
path = tempfile.mkdtemp()
- print 'Created directory "%s"' % path
+ print('Created directory "%s"' % path)
# Create some files underneath
--- test/io/TestPushback.py.orig 2008-09-10 01:27:50 UTC
+++ test/io/TestPushback.py
@@ -7,7 +7,7 @@
# ---------------------------------------------------------------------------
from grizzled.io import *
-from cStringIO import StringIO
+from io import StringIO
import os
import tempfile
import atexit
@@ -31,24 +31,24 @@ ghi
pb = PushbackFile(f)
s = pb.readline()
- print s
+ print(s)
assert s == 'abc\n'
pb.pushback(s)
s = pb.readline()
- print s
+ print(s)
assert s == 'abc\n'
s = pb.read(1)
- print s
+ print(s)
assert s == 'd'
s = pb.readline()
- print s
+ print(s)
assert s == 'ef\n'
s = pb.read(-1)
- print s
+ print(s)
assert s == 'ghi\n'
s = pb.readline()
assert s == ''
pb.pushback('foobar')
s = pb.readline()
- print s
+ print(s)
assert s == 'foobar'
\ No newline at end of file
--- test/text/TestStr2Bool.py.orig 2008-09-10 01:27:50 UTC
+++ test/text/TestStr2Bool.py
@@ -31,7 +31,7 @@ class TestStr2Bool(object):
('1', True,)):
for s2 in (s, s.upper(), s.capitalize()):
val = str2bool(s2)
- print '"%s" -> %s. Expected=%s' % (s2, expected, val)
+ print('"%s" -> %s. Expected=%s' % (s2, expected, val))
assert val == expected, \
'"%s" does not produce expected %s' % (s2, expected)
|