summaryrefslogtreecommitdiff
path: root/doc/sample_html/cogapp_cogapp.html
blob: df5b4345abab893c961ec29f36b3513c30347ac2 (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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for cogapp\cogapp</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>cogapp\cogapp</b> :
            <span class='pc_cov'>51%</span>
        </h1>
        <h2 class='stats'>
            387 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>219 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>3 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>168 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>26 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='pln'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='stm run hide_run'>7</p>
<p class='stm run hide_run'>8</p>
<p class='pln'>9</p>
<p class='pln'>10</p>
<p class='stm run hide_run'>11</p>
<p class='stm run hide_run'>12</p>
<p class='stm run hide_run'>13</p>
<p class='stm mis'>14</p>
<p class='stm mis'>15</p>
<p class='stm mis'>16</p>
<p class='pln'>17</p>
<p class='stm run hide_run'>18</p>
<p class='pln'>19</p>
<p class='stm run hide_run'>20</p>
<p class='pln'>21</p>
<p class='stm run hide_run'>22</p>
<p class='pln'>23</p>
<p class='pln'>24</p>
<p class='pln'>25</p>
<p class='pln'>26</p>
<p class='pln'>27</p>
<p class='pln'>28</p>
<p class='pln'>29</p>
<p class='pln'>30</p>
<p class='pln'>31</p>
<p class='pln'>32</p>
<p class='pln'>33</p>
<p class='pln'>34</p>
<p class='pln'>35</p>
<p class='pln'>36</p>
<p class='pln'>37</p>
<p class='pln'>38</p>
<p class='pln'>39</p>
<p class='pln'>40</p>
<p class='pln'>41</p>
<p class='pln'>42</p>
<p class='pln'>43</p>
<p class='pln'>44</p>
<p class='pln'>45</p>
<p class='pln'>46</p>
<p class='pln'>47</p>
<p class='pln'>48</p>
<p class='pln'>49</p>
<p class='stm run hide_run'>50</p>
<p class='pln'>51</p>
<p class='stm run hide_run'>52</p>
<p class='pln'>53</p>
<p class='pln'>54</p>
<p class='stm run hide_run'>55</p>
<p class='stm par run hide_run'>56</p>
<p class='stm run hide_run'>57</p>
<p class='pln'>58</p>
<p class='stm mis'>59</p>
<p class='pln'>60</p>
<p class='stm run hide_run'>61</p>
<p class='pln'>62</p>
<p class='pln'>63</p>
<p class='exc'>64</p>
<p class='pln'>65</p>
<p class='stm run hide_run'>66</p>
<p class='pln'>67</p>
<p class='pln'>68</p>
<p class='exc'>69</p>
<p class='pln'>70</p>
<p class='stm run hide_run'>71</p>
<p class='pln'>72</p>
<p class='pln'>73</p>
<p class='exc'>74</p>
<p class='pln'>75</p>
<p class='stm run hide_run'>76</p>
<p class='pln'>77</p>
<p class='pln'>78</p>
<p class='stm run hide_run'>79</p>
<p class='stm run hide_run'>80</p>
<p class='stm run hide_run'>81</p>
<p class='pln'>82</p>
<p class='stm run hide_run'>83</p>
<p class='pln'>84</p>
<p class='pln'>85</p>
<p class='stm par run hide_run'>86</p>
<p class='stm run hide_run'>87</p>
<p class='stm par run hide_run'>88</p>
<p class='stm mis'>89</p>
<p class='pln'>90</p>
<p class='stm run hide_run'>91</p>
<p class='pln'>92</p>
<p class='pln'>93</p>
<p class='stm run hide_run'>94</p>
<p class='stm run hide_run'>95</p>
<p class='stm run hide_run'>96</p>
<p class='stm run hide_run'>97</p>
<p class='pln'>98</p>
<p class='stm run hide_run'>99</p>
<p class='stm run hide_run'>100</p>
<p class='pln'>101</p>
<p class='stm run hide_run'>102</p>
<p class='stm run hide_run'>103</p>
<p class='pln'>104</p>
<p class='stm run hide_run'>105</p>
<p class='pln'>106</p>
<p class='pln'>107</p>
<p class='pln'>108</p>
<p class='pln'>109</p>
<p class='pln'>110</p>
<p class='stm run hide_run'>111</p>
<p class='stm run hide_run'>112</p>
<p class='stm run hide_run'>113</p>
<p class='stm run hide_run'>114</p>
<p class='pln'>115</p>
<p class='stm run hide_run'>116</p>
<p class='pln'>117</p>
<p class='stm run hide_run'>118</p>
<p class='pln'>119</p>
<p class='stm run hide_run'>120</p>
<p class='pln'>121</p>
<p class='stm run hide_run'>122</p>
<p class='stm run hide_run'>123</p>
<p class='stm run hide_run'>124</p>
<p class='pln'>125</p>
<p class='pln'>126</p>
<p class='stm run hide_run'>127</p>
<p class='stm run hide_run'>128</p>
<p class='pln'>129</p>
<p class='pln'>130</p>
<p class='stm run hide_run'>131</p>
<p class='stm run hide_run'>132</p>
<p class='stm run hide_run'>133</p>
<p class='stm run hide_run'>134</p>
<p class='pln'>135</p>
<p class='stm run hide_run'>136</p>
<p class='stm run hide_run'>137</p>
<p class='pln'>138</p>
<p class='pln'>139</p>
<p class='pln'>140</p>
<p class='pln'>141</p>
<p class='stm run hide_run'>142</p>
<p class='stm run hide_run'>143</p>
<p class='pln'>144</p>
<p class='stm run hide_run'>145</p>
<p class='pln'>146</p>
<p class='stm run hide_run'>147</p>
<p class='stm mis'>148</p>
<p class='pln'>149</p>
<p class='stm run hide_run'>150</p>
<p class='pln'>151</p>
<p class='pln'>152</p>
<p class='stm run hide_run'>153</p>
<p class='stm run hide_run'>154</p>
<p class='stm run hide_run'>155</p>
<p class='stm run hide_run'>156</p>
<p class='stm par run hide_run'>157</p>
<p class='stm run hide_run'>158</p>
<p class='stm run hide_run'>159</p>
<p class='stm run hide_run'>160</p>
<p class='stm run hide_run'>161</p>
<p class='stm run hide_run'>162</p>
<p class='pln'>163</p>
<p class='stm run hide_run'>164</p>
<p class='pln'>165</p>
<p class='pln'>166</p>
<p class='stm run hide_run'>167</p>
<p class='stm run hide_run'>168</p>
<p class='pln'>169</p>
<p class='stm run hide_run'>170</p>
<p class='pln'>171</p>
<p class='pln'>172</p>
<p class='pln'>173</p>
<p class='pln'>174</p>
<p class='pln'>175</p>
<p class='stm mis'>176</p>
<p class='pln'>177</p>
<p class='pln'>178</p>
<p class='stm run hide_run'>179</p>
<p class='pln'>180</p>
<p class='pln'>181</p>
<p class='stm run hide_run'>182</p>
<p class='stm run hide_run'>183</p>
<p class='stm run hide_run'>184</p>
<p class='pln'>185</p>
<p class='stm run hide_run'>186</p>
<p class='stm run hide_run'>187</p>
<p class='stm run hide_run'>188</p>
<p class='stm run hide_run'>189</p>
<p class='stm run hide_run'>190</p>
<p class='pln'>191</p>
<p class='stm run hide_run'>192</p>
<p class='stm run hide_run'>193</p>
<p class='pln'>194</p>
<p class='pln'>195</p>
<p class='stm run hide_run'>196</p>
<p class='pln'>197</p>
<p class='pln'>198</p>
<p class='stm run hide_run'>199</p>
<p class='pln'>200</p>
<p class='stm run hide_run'>201</p>
<p class='stm run hide_run'>202</p>
<p class='stm run hide_run'>203</p>
<p class='stm run hide_run'>204</p>
<p class='stm run hide_run'>205</p>
<p class='stm run hide_run'>206</p>
<p class='stm run hide_run'>207</p>
<p class='stm run hide_run'>208</p>
<p class='stm run hide_run'>209</p>
<p class='stm run hide_run'>210</p>
<p class='stm run hide_run'>211</p>
<p class='stm run hide_run'>212</p>
<p class='stm run hide_run'>213</p>
<p class='stm run hide_run'>214</p>
<p class='pln'>215</p>
<p class='stm run hide_run'>216</p>
<p class='pln'>217</p>
<p class='pln'>218</p>
<p class='stm mis'>219</p>
<p class='pln'>220</p>
<p class='stm run hide_run'>221</p>
<p class='pln'>222</p>
<p class='pln'>223</p>
<p class='stm mis'>224</p>
<p class='pln'>225</p>
<p class='stm run hide_run'>226</p>
<p class='pln'>227</p>
<p class='pln'>228</p>
<p class='stm mis'>229</p>
<p class='stm mis'>230</p>
<p class='pln'>231</p>
<p class='stm run hide_run'>232</p>
<p class='pln'>233</p>
<p class='stm mis'>234</p>
<p class='stm mis'>235</p>
<p class='stm mis'>236</p>
<p class='stm mis'>237</p>
<p class='pln'>238</p>
<p class='pln'>239</p>
<p class='stm mis'>240</p>
<p class='stm mis'>241</p>
<p class='stm mis'>242</p>
<p class='stm mis'>243</p>
<p class='stm mis'>244</p>
<p class='stm mis'>245</p>
<p class='stm mis'>246</p>
<p class='stm mis'>247</p>
<p class='stm mis'>248</p>
<p class='stm mis'>249</p>
<p class='stm mis'>250</p>
<p class='stm mis'>251</p>
<p class='stm mis'>252</p>
<p class='stm mis'>253</p>
<p class='stm mis'>254</p>
<p class='stm mis'>255</p>
<p class='stm mis'>256</p>
<p class='stm mis'>257</p>
<p class='stm mis'>258</p>
<p class='stm mis'>259</p>
<p class='stm mis'>260</p>
<p class='stm mis'>261</p>
<p class='stm mis'>262</p>
<p class='stm mis'>263</p>
<p class='stm mis'>264</p>
<p class='stm mis'>265</p>
<p class='stm mis'>266</p>
<p class='stm mis'>267</p>
<p class='stm mis'>268</p>
<p class='stm mis'>269</p>
<p class='pln'>270</p>
<p class='pln'>271</p>
<p class='pln'>272</p>
<p class='stm mis'>273</p>
<p class='pln'>274</p>
<p class='stm run hide_run'>275</p>
<p class='pln'>276</p>
<p class='pln'>277</p>
<p class='stm mis'>278</p>
<p class='stm mis'>279</p>
<p class='pln'>280</p>
<p class='stm mis'>281</p>
<p class='stm mis'>282</p>
<p class='pln'>283</p>
<p class='pln'>284</p>
<p class='stm run hide_run'>285</p>
<p class='pln'>286</p>
<p class='pln'>287</p>
<p class='stm run hide_run'>288</p>
<p class='stm run hide_run'>289</p>
<p class='stm run hide_run'>290</p>
<p class='stm run hide_run'>291</p>
<p class='stm run hide_run'>292</p>
<p class='stm run hide_run'>293</p>
<p class='stm run hide_run'>294</p>
<p class='pln'>295</p>
<p class='stm run hide_run'>296</p>
<p class='stm run hide_run'>297</p>
<p class='pln'>298</p>
<p class='stm run hide_run'>299</p>
<p class='pln'>300</p>
<p class='stm run hide_run'>301</p>
<p class='stm mis'>302</p>
<p class='pln'>303</p>
<p class='stm run hide_run'>304</p>
<p class='stm run hide_run'>305</p>
<p class='pln'>306</p>
<p class='stm run hide_run'>307</p>
<p class='stm run hide_run'>308</p>
<p class='pln'>309</p>
<p class='pln'>310</p>
<p class='stm run hide_run'>311</p>
<p class='stm run hide_run'>312</p>
<p class='pln'>313</p>
<p class='stm run hide_run'>314</p>
<p class='pln'>315</p>
<p class='pln'>316</p>
<p class='pln'>317</p>
<p class='stm run hide_run'>318</p>
<p class='stm run hide_run'>319</p>
<p class='stm run hide_run'>320</p>
<p class='pln'>321</p>
<p class='stm run hide_run'>322</p>
<p class='pln'>323</p>
<p class='pln'>324</p>
<p class='pln'>325</p>
<p class='pln'>326</p>
<p class='stm run hide_run'>327</p>
<p class='stm run hide_run'>328</p>
<p class='stm run hide_run'>329</p>
<p class='pln'>330</p>
<p class='stm par run hide_run'>331</p>
<p class='pln'>332</p>
<p class='stm mis'>333</p>
<p class='stm mis'>334</p>
<p class='stm par run hide_run'>335</p>
<p class='pln'>336</p>
<p class='stm mis'>337</p>
<p class='stm mis'>338</p>
<p class='pln'>339</p>
<p class='stm run hide_run'>340</p>
<p class='stm run hide_run'>341</p>
<p class='pln'>342</p>
<p class='stm run hide_run'>343</p>
<p class='pln'>344</p>
<p class='stm run hide_run'>345</p>
<p class='stm run hide_run'>346</p>
<p class='pln'>347</p>
<p class='pln'>348</p>
<p class='stm par run hide_run'>349</p>
<p class='stm run hide_run'>350</p>
<p class='pln'>351</p>
<p class='pln'>352</p>
<p class='stm run hide_run'>353</p>
<p class='pln'>354</p>
<p class='pln'>355</p>
<p class='stm run hide_run'>356</p>
<p class='stm run hide_run'>357</p>
<p class='pln'>358</p>
<p class='stm run hide_run'>359</p>
<p class='stm par run hide_run'>360</p>
<p class='stm mis'>361</p>
<p class='pln'>362</p>
<p class='stm par run hide_run'>363</p>
<p class='stm mis'>364</p>
<p class='pln'>365</p>
<p class='stm run hide_run'>366</p>
<p class='stm run hide_run'>367</p>
<p class='stm run hide_run'>368</p>
<p class='stm run hide_run'>369</p>
<p class='stm par run hide_run'>370</p>
<p class='stm run hide_run'>371</p>
<p class='pln'>372</p>
<p class='pln'>373</p>
<p class='stm run hide_run'>374</p>
<p class='stm run hide_run'>375</p>
<p class='stm run hide_run'>376</p>
<p class='stm run hide_run'>377</p>
<p class='stm run hide_run'>378</p>
<p class='pln'>379</p>
<p class='pln'>380</p>
<p class='pln'>381</p>
<p class='stm run hide_run'>382</p>
<p class='stm run hide_run'>383</p>
<p class='stm run hide_run'>384</p>
<p class='stm run hide_run'>385</p>
<p class='stm run hide_run'>386</p>
<p class='pln'>387</p>
<p class='pln'>388</p>
<p class='stm run hide_run'>389</p>
<p class='stm run hide_run'>390</p>
<p class='pln'>391</p>
<p class='pln'>392</p>
<p class='stm run hide_run'>393</p>
<p class='pln'>394</p>
<p class='pln'>395</p>
<p class='stm run hide_run'>396</p>
<p class='stm par run hide_run'>397</p>
<p class='stm mis'>398</p>
<p class='pln'>399</p>
<p class='stm par run hide_run'>400</p>
<p class='stm mis'>401</p>
<p class='pln'>402</p>
<p class='stm par run hide_run'>403</p>
<p class='stm run hide_run'>404</p>
<p class='stm run hide_run'>405</p>
<p class='stm run hide_run'>406</p>
<p class='stm par run hide_run'>407</p>
<p class='stm mis'>408</p>
<p class='pln'>409</p>
<p class='pln'>410</p>
<p class='pln'>411</p>
<p class='stm par run hide_run'>412</p>
<p class='stm run hide_run'>413</p>
<p class='stm run hide_run'>414</p>
<p class='pln'>415</p>
<p class='stm run hide_run'>416</p>
<p class='pln'>417</p>
<p class='pln'>418</p>
<p class='pln'>419</p>
<p class='stm run hide_run'>420</p>
<p class='stm run hide_run'>421</p>
<p class='stm par run hide_run'>422</p>
<p class='stm mis'>423</p>
<p class='pln'>424</p>
<p class='stm par run hide_run'>425</p>
<p class='stm mis'>426</p>
<p class='pln'>427</p>
<p class='stm run hide_run'>428</p>
<p class='stm run hide_run'>429</p>
<p class='stm run hide_run'>430</p>
<p class='pln'>431</p>
<p class='stm par run hide_run'>432</p>
<p class='pln'>433</p>
<p class='stm mis'>434</p>
<p class='pln'>435</p>
<p class='pln'>436</p>
<p class='pln'>437</p>
<p class='pln'>438</p>
<p class='stm run hide_run'>439</p>
<p class='stm par run hide_run'>440</p>
<p class='stm run hide_run'>441</p>
<p class='stm run hide_run'>442</p>
<p class='stm run hide_run'>443</p>
<p class='stm run hide_run'>444</p>
<p class='stm run hide_run'>445</p>
<p class='stm run hide_run'>446</p>
<p class='pln'>447</p>
<p class='stm run hide_run'>448</p>
<p class='pln'>449</p>
<p class='pln'>450</p>
<p class='stm run hide_run'>451</p>
<p class='stm par run hide_run'>452</p>
<p class='stm mis'>453</p>
<p class='stm mis'>454</p>
<p class='stm mis'>455</p>
<p class='stm mis'>456</p>
<p class='pln'>457</p>
<p class='pln'>458</p>
<p class='stm mis'>459</p>
<p class='pln'>460</p>
<p class='pln'>461</p>
<p class='stm mis'>462</p>
<p class='stm mis'>463</p>
<p class='pln'>464</p>
<p class='pln'>465</p>
<p class='pln'>466</p>
<p class='stm par run hide_run'>467</p>
<p class='stm mis'>468</p>
<p class='pln'>469</p>
<p class='stm par run hide_run'>470</p>
<p class='stm run hide_run'>471</p>
<p class='stm run hide_run'>472</p>
<p class='pln'>473</p>
<p class='stm par run hide_run'>474</p>
<p class='stm mis'>475</p>
<p class='pln'>476</p>
<p class='stm par run hide_run'>477</p>
<p class='stm mis'>478</p>
<p class='stm par run hide_run'>479</p>
<p class='stm mis'>480</p>
<p class='pln'>481</p>
<p class='pln'>482</p>
<p class='pln'>483</p>
<p class='stm run hide_run'>484</p>
<p class='pln'>485</p>
<p class='stm run hide_run'>486</p>
<p class='pln'>487</p>
<p class='pln'>488</p>
<p class='pln'>489</p>
<p class='stm par run hide_run'>490</p>
<p class='pln'>491</p>
<p class='stm mis'>492</p>
<p class='stm mis'>493</p>
<p class='stm run hide_run'>494</p>
<p class='pln'>495</p>
<p class='stm run hide_run'>496</p>
<p class='pln'>497</p>
<p class='pln'>498</p>
<p class='pln'>499</p>
<p class='stm run hide_run'>500</p>
<p class='stm run hide_run'>501</p>
<p class='stm run hide_run'>502</p>
<p class='stm run hide_run'>503</p>
<p class='pln'>504</p>
<p class='stm run hide_run'>505</p>
<p class='pln'>506</p>
<p class='pln'>507</p>
<p class='stm mis'>508</p>
<p class='pln'>509</p>
<p class='stm mis'>510</p>
<p class='pln'>511</p>
<p class='stm mis'>512</p>
<p class='stm mis'>513</p>
<p class='stm mis'>514</p>
<p class='stm mis'>515</p>
<p class='pln'>516</p>
<p class='pln'>517</p>
<p class='stm mis'>518</p>
<p class='stm mis'>519</p>
<p class='stm mis'>520</p>
<p class='stm mis'>521</p>
<p class='pln'>522</p>
<p class='stm run hide_run'>523</p>
<p class='stm mis'>524</p>
<p class='stm mis'>525</p>
<p class='pln'>526</p>
<p class='stm run hide_run'>527</p>
<p class='stm mis'>528</p>
<p class='stm mis'>529</p>
<p class='stm mis'>530</p>
<p class='pln'>531</p>
<p class='stm run hide_run'>532</p>
<p class='stm mis'>533</p>
<p class='stm mis'>534</p>
<p class='pln'>535</p>
<p class='stm run hide_run'>536</p>
<p class='pln'>537</p>
<p class='pln'>538</p>
<p class='pln'>539</p>
<p class='stm mis'>540</p>
<p class='pln'>541</p>
<p class='stm mis'>542</p>
<p class='stm mis'>543</p>
<p class='pln'>544</p>
<p class='pln'>545</p>
<p class='stm mis'>546</p>
<p class='pln'>547</p>
<p class='pln'>548</p>
<p class='pln'>549</p>
<p class='stm mis'>550</p>
<p class='stm mis'>551</p>
<p class='stm mis'>552</p>
<p class='pln'>553</p>
<p class='pln'>554</p>
<p class='stm mis'>555</p>
<p class='stm mis'>556</p>
<p class='stm mis'>557</p>
<p class='pln'>558</p>
<p class='pln'>559</p>
<p class='stm mis'>560</p>
<p class='stm mis'>561</p>
<p class='pln'>562</p>
<p class='stm mis'>563</p>
<p class='stm mis'>564</p>
<p class='stm mis'>565</p>
<p class='stm mis'>566</p>
<p class='stm mis'>567</p>
<p class='stm mis'>568</p>
<p class='stm mis'>569</p>
<p class='stm mis'>570</p>
<p class='stm mis'>571</p>
<p class='pln'>572</p>
<p class='pln'>573</p>
<p class='pln'>574</p>
<p class='pln'>575</p>
<p class='pln'>576</p>
<p class='stm mis'>577</p>
<p class='stm mis'>578</p>
<p class='pln'>579</p>
<p class='stm mis'>580</p>
<p class='pln'>581</p>
<p class='stm mis'>582</p>
<p class='pln'>583</p>
<p class='stm run hide_run'>584</p>
<p class='pln'>585</p>
<p class='pln'>586</p>
<p class='stm mis'>587</p>
<p class='stm mis'>588</p>
<p class='stm mis'>589</p>
<p class='stm mis'>590</p>
<p class='pln'>591</p>
<p class='stm mis'>592</p>
<p class='stm mis'>593</p>
<p class='stm mis'>594</p>
<p class='pln'>595</p>
<p class='stm mis'>596</p>
<p class='stm mis'>597</p>
<p class='stm mis'>598</p>
<p class='stm mis'>599</p>
<p class='pln'>600</p>
<p class='stm run hide_run'>601</p>
<p class='pln'>602</p>
<p class='pln'>603</p>
<p class='stm mis'>604</p>
<p class='stm mis'>605</p>
<p class='pln'>606</p>
<p class='stm mis'>607</p>
<p class='stm mis'>608</p>
<p class='pln'>609</p>
<p class='stm mis'>610</p>
<p class='stm mis'>611</p>
<p class='stm mis'>612</p>
<p class='stm mis'>613</p>
<p class='pln'>614</p>
<p class='stm mis'>615</p>
<p class='pln'>616</p>
<p class='stm mis'>617</p>
<p class='pln'>618</p>
<p class='stm run hide_run'>619</p>
<p class='pln'>620</p>
<p class='pln'>621</p>
<p class='pln'>622</p>
<p class='pln'>623</p>
<p class='stm mis'>624</p>
<p class='pln'>625</p>
<p class='pln'>626</p>
<p class='stm mis'>627</p>
<p class='stm mis'>628</p>
<p class='stm mis'>629</p>
<p class='pln'>630</p>
<p class='stm mis'>631</p>
<p class='stm mis'>632</p>
<p class='pln'>633</p>
<p class='stm mis'>634</p>
<p class='stm mis'>635</p>
<p class='stm mis'>636</p>
<p class='pln'>637</p>
<p class='stm mis'>638</p>
<p class='stm mis'>639</p>
<p class='stm mis'>640</p>
<p class='pln'>641</p>
<p class='stm mis'>642</p>
<p class='pln'>643</p>
<p class='stm run hide_run'>644</p>
<p class='pln'>645</p>
<p class='pln'>646</p>
<p class='pln'>647</p>
<p class='stm mis'>648</p>
<p class='stm mis'>649</p>
<p class='stm mis'>650</p>
<p class='stm mis'>651</p>
<p class='stm mis'>652</p>
<p class='stm mis'>653</p>
<p class='stm mis'>654</p>
<p class='stm mis'>655</p>
<p class='stm mis'>656</p>
<p class='stm mis'>657</p>
<p class='stm mis'>658</p>
<p class='stm mis'>659</p>
<p class='stm mis'>660</p>
<p class='stm mis'>661</p>
<p class='stm mis'>662</p>
<p class='stm mis'>663</p>
<p class='pln'>664</p>
<p class='pln'>665</p>
<p class='pln'>666</p>
<p class='pln'>667</p>
<p class='pln'>668</p>
<p class='pln'>669</p>
<p class='pln'>670</p>
<p class='pln'>671</p>
<p class='pln'>672</p>
<p class='pln'>673</p>
<p class='pln'>674</p>
<p class='pln'>675</p>
<p class='pln'>676</p>
<p class='pln'>677</p>
<p class='pln'>678</p>
<p class='pln'>679</p>
<p class='pln'>680</p>
<p class='pln'>681</p>
<p class='pln'>682</p>
<p class='pln'>683</p>
<p class='pln'>684</p>
<p class='pln'>685</p>
<p class='pln'>686</p>
<p class='pln'>687</p>
<p class='pln'>688</p>
<p class='pln'>689</p>
<p class='pln'>690</p>
<p class='pln'>691</p>
<p class='pln'>692</p>
<p class='pln'>693</p>
<p class='pln'>694</p>
<p class='pln'>695</p>
<p class='pln'>696</p>
<p class='pln'>697</p>
<p class='pln'>698</p>
<p class='pln'>699</p>
<p class='pln'>700</p>
<p class='pln'>701</p>
<p class='pln'>702</p>
<p class='pln'>703</p>
<p class='pln'>704</p>
<p class='pln'>705</p>
<p class='pln'>706</p>
<p class='pln'>707</p>
<p class='pln'>708</p>
<p class='pln'>709</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='str'>&quot;&quot;&quot; Cog code generation tool.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; http://nedbatchelder.com/code/cog</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; </span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Copyright 2004-2009, Ned Batchelder.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>copy</span><span class='op'>,</span> <span class='nam'>getopt</span><span class='op'>,</span> <span class='nam'>imp</span><span class='op'>,</span> <span class='nam'>os</span><span class='op'>,</span> <span class='nam'>re</span><span class='op'>,</span> <span class='nam'>shlex</span><span class='op'>,</span> <span class='nam'>string</span><span class='op'>,</span> <span class='nam'>sys</span><span class='op'>,</span> <span class='nam'>traceback</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>from</span> <span class='nam'>cStringIO</span> <span class='key'>import</span> <span class='nam'>StringIO</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># The recommended way to compute md5&#39;s changed in Python 2.5</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>hashlib</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>hash_factory</span> <span class='op'>=</span> <span class='nam'>hashlib</span><span class='op'>.</span><span class='nam'>md5</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>md5</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>hash_factory</span> <span class='op'>=</span> <span class='nam'>md5</span><span class='op'>.</span><span class='nam'>new</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>__all__</span> <span class='op'>=</span> <span class='op'>[</span><span class='str'>&#39;Cog&#39;</span><span class='op'>,</span> <span class='str'>&#39;CogUsageError&#39;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>__version__</span> <span class='op'>=</span> <span class='str'>&#39;2.2&#39;</span>&nbsp; &nbsp; &nbsp;&nbsp; <span class='com'># History at the end of the file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>usage</span> <span class='op'>=</span> <span class='str'>&quot;&quot;&quot;\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>cog - generate code with inlined Python code.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>cog [OPTIONS] [INFILE | @FILELIST] ...</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>INFILE is the name of an input file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>FILELIST is the name of a text file containing file names or</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; other @FILELISTs.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>OPTIONS:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -c&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Checksum the output to protect it against accidental change.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -d&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Delete the generator code from the output file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -D name=val Define a global string available to your generator code.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -e&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Warn if a file has no cog code in it.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -I PATH&nbsp; &nbsp;&nbsp; Add PATH to the list of directories for data files and modules.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -o OUTNAME&nbsp; Write the output to OUTNAME.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -r&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Replace the input file with the output.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -s STRING&nbsp;&nbsp; Suffix all generated output lines with STRING.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -U&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write the output with Unix newlines (only LF line-endings).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -w CMD&nbsp; &nbsp; &nbsp; Use CMD if the output file needs to be made writable.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A %s in the CMD will be filled with the filename.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -x&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Excise all the generated output without running the generators.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -z&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The [[[end]]] marker can be omitted, and is assumed at eof.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -v&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print the version of cog and exit.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; -h&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print this help.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Other package modules</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>from</span> <span class='nam'>whiteutils</span> <span class='key'>import</span> <span class='op'>*</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='nam'>Exception</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Any exception raised by Cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>,</span> <span class='nam'>file</span><span class='op'>=</span><span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='num'>0</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>59</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>file</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Exception</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='str'>&quot;%s(%d): %s&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>file</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Exception</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='nam'>CogError</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; An error in usage of command-line arguments in cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='exc'>&nbsp; &nbsp; <span class='key'>pass</span>&nbsp; &nbsp; <span class='com'>#pragma: no cover</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>CogInternalError</span><span class='op'>(</span><span class='nam'>CogError</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; An error in the coding of Cog. Should never happen.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='exc'>&nbsp; &nbsp; <span class='key'>pass</span>&nbsp; &nbsp; <span class='com'>#pragma: no cover</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>CogGeneratedError</span><span class='op'>(</span><span class='nam'>CogError</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; An error raised by a user&#39;s cog generator.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='exc'>&nbsp; &nbsp; <span class='key'>pass</span>&nbsp; &nbsp; <span class='com'>#pragma: no cover</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>Redirectable</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; An object with its own stdout and stderr files.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span> <span class='op'>=</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>stdout</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span> <span class='op'>=</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>stderr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>setOutput</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>stdout</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>stderr</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Assign new files for standard out and/or standard error.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>88</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>stdout</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span> <span class='op'>=</span> <span class='nam'>stdout</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>89</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>stderr</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span> <span class='op'>=</span> <span class='nam'>stderr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>CogGenerator</span><span class='op'>(</span><span class='nam'>Redirectable</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; A generator pulled from a source file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Redirectable</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>markers</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>lines</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>parseMarker</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>markers</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>parseLine</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>lines</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>.</span><span class='nam'>strip</span><span class='op'>(</span><span class='str'>&#39;\n&#39;</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>getCode</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Extract the executable Python code from the generator.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># If the markers and lines all have the same prefix</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># (end-of-line comment chars, for example),</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># then remove it from all the lines.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>prefIn</span> <span class='op'>=</span> <span class='nam'>commonPrefix</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>markers</span> <span class='op'>+</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>lines</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>prefIn</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>markers</span> <span class='op'>=</span> <span class='op'>[</span> <span class='nam'>l</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='nam'>prefIn</span><span class='op'>,</span> <span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span> <span class='key'>for</span> <span class='nam'>l</span> <span class='key'>in</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>markers</span> <span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>lines</span> <span class='op'>=</span> <span class='op'>[</span> <span class='nam'>l</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='nam'>prefIn</span><span class='op'>,</span> <span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span> <span class='key'>for</span> <span class='nam'>l</span> <span class='key'>in</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>lines</span> <span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>reindentBlock</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>lines</span><span class='op'>,</span> <span class='str'>&#39;&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>evaluate</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>cog</span><span class='op'>,</span> <span class='nam'>globals</span><span class='op'>,</span> <span class='nam'>fname</span><span class='op'>=</span><span class='str'>&#39;cog generator&#39;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># figure out the right whitespace prefix for the output</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>prefOut</span> <span class='op'>=</span> <span class='nam'>whitePrefix</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>markers</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>intext</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>getCode</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>intext</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># In Python 2.2, the last line has to end in a newline.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>intext</span> <span class='op'>=</span> <span class='str'>&quot;import cog\n&quot;</span> <span class='op'>+</span> <span class='nam'>intext</span> <span class='op'>+</span> <span class='str'>&quot;\n&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>code</span> <span class='op'>=</span> <span class='nam'>compile</span><span class='op'>(</span><span class='nam'>intext</span><span class='op'>,</span> <span class='nam'>str</span><span class='op'>(</span><span class='nam'>fname</span><span class='op'>)</span><span class='op'>,</span> <span class='str'>&#39;exec&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Make sure the &quot;cog&quot; module has our state.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>cog</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>msg</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>msg</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>cog</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>out</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>out</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>cog</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>outl</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>outl</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>cog</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>error</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>error</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>outstring</span> <span class='op'>=</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>eval</span><span class='op'>(</span><span class='nam'>code</span><span class='op'>,</span> <span class='nam'>globals</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We need to make sure that the last line in the output</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># ends with a newline, or it will be joined to the</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># end-output line, ruining cog&#39;s idempotency.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>outstring</span> <span class='key'>and</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>outstring</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='op'>!=</span> <span class='str'>&#39;\n&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>outstring</span> <span class='op'>+=</span> <span class='str'>&#39;\n&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>reindentBlock</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>outstring</span><span class='op'>,</span> <span class='nam'>prefOut</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>msg</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>s</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>,</span> <span class='str'>&quot;Message: &quot;</span><span class='op'>+</span><span class='nam'>s</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>out</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sOut</span><span class='op'>=</span><span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='nam'>dedent</span><span class='op'>=</span><span class='nam'>False</span><span class='op'>,</span> <span class='nam'>trimblanklines</span><span class='op'>=</span><span class='nam'>False</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; The cog.out function.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>trimblanklines</span> <span class='key'>and</span> <span class='op'>(</span><span class='str'>&#39;\n&#39;</span> <span class='key'>in</span> <span class='nam'>sOut</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lines</span> <span class='op'>=</span> <span class='nam'>sOut</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='str'>&#39;\n&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>lines</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>strip</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>==</span> <span class='str'>&#39;&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>lines</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>159</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>lines</span> <span class='key'>and</span> <span class='nam'>lines</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>strip</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>==</span> <span class='str'>&#39;&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>lines</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sOut</span> <span class='op'>=</span> <span class='str'>&#39;\n&#39;</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='nam'>lines</span><span class='op'>)</span><span class='op'>+</span><span class='str'>&#39;\n&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>dedent</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sOut</span> <span class='op'>=</span> <span class='nam'>reindentBlock</span><span class='op'>(</span><span class='nam'>sOut</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>outstring</span> <span class='op'>+=</span> <span class='nam'>sOut</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>outl</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sOut</span><span class='op'>=</span><span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kw</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; The cog.outl function.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>out</span><span class='op'>(</span><span class='nam'>sOut</span><span class='op'>,</span> <span class='op'>**</span><span class='nam'>kw</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>out</span><span class='op'>(</span><span class='str'>&#39;\n&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>error</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>=</span><span class='str'>&#39;Error raised by cog generator.&#39;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; The cog.error function.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Instead of raising standard python errors, cog generators can use</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this function.&nbsp; It will display the error without a scary Python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; traceback.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogGeneratedError</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>NumberedFileReader</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; A decorator for files that counts the readline()&#39;s called.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>f</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>f</span> <span class='op'>=</span> <span class='nam'>f</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>n</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>readline</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>f</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>l</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>n</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>l</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>linenumber</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>n</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>CogOptions</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Options for a run of cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Defaults for argument values.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>args</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>includePath</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>defines</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bShowVersion</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sMakeWritableCmd</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bReplace</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bNoGenerate</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputName</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bWarnEmpty</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bHashOutput</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bDeleteCode</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bEofCanBeEnd</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sSuffix</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bNewlines</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__cmp__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>other</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Comparison operator for tests to use.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>__dict__</span><span class='op'>.</span><span class='nam'>__cmp__</span><span class='op'>(</span><span class='nam'>other</span><span class='op'>.</span><span class='nam'>__dict__</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>clone</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Make a clone of these options, for further refinement.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>copy</span><span class='op'>.</span><span class='nam'>deepcopy</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>addToIncludePath</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>dirs</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Add directories to the include path.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>dirs</span> <span class='op'>=</span> <span class='nam'>dirs</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='nam'>os</span><span class='op'>.</span><span class='nam'>pathsep</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>includePath</span><span class='op'>.</span><span class='nam'>extend</span><span class='op'>(</span><span class='nam'>dirs</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>parseArgs</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>argv</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Parse the command line arguments.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>opts</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>args</span> <span class='op'>=</span> <span class='nam'>getopt</span><span class='op'>.</span><span class='nam'>getopt</span><span class='op'>(</span><span class='nam'>argv</span><span class='op'>,</span> <span class='str'>&#39;cdD:eI:o:rs:Uvw:xz&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>getopt</span><span class='op'>.</span><span class='nam'>error</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='nam'>msg</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Handle the command line arguments.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>o</span><span class='op'>,</span> <span class='nam'>a</span> <span class='key'>in</span> <span class='nam'>opts</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-c&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bHashOutput</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-d&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bDeleteCode</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-D&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>a</span><span class='op'>.</span><span class='nam'>count</span><span class='op'>(</span><span class='str'>&#39;=&#39;</span><span class='op'>)</span> <span class='op'>&lt;</span> <span class='num'>1</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='str'>&quot;-D takes a name=value argument&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>name</span><span class='op'>,</span> <span class='nam'>value</span> <span class='op'>=</span> <span class='nam'>a</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='str'>&#39;=&#39;</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>[</span><span class='nam'>name</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>value</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-e&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bWarnEmpty</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-I&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>addToIncludePath</span><span class='op'>(</span><span class='nam'>a</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-o&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputName</span> <span class='op'>=</span> <span class='nam'>a</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-r&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bReplace</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-s&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sSuffix</span> <span class='op'>=</span> <span class='nam'>a</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-U&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bNewlines</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-v&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bShowVersion</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-w&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sMakeWritableCmd</span> <span class='op'>=</span> <span class='nam'>a</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-x&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bNoGenerate</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>o</span> <span class='op'>==</span> <span class='str'>&#39;-z&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bEofCanBeEnd</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Since getopt.getopt is given a list of possible flags,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># this is an internal error.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogInternalError</span><span class='op'>(</span><span class='str'>&quot;Don&#39;t understand argument %s&quot;</span> <span class='op'>%</span> <span class='nam'>o</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>validate</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Does nothing if everything is OK, raises CogError&#39;s if it&#39;s not.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bReplace</span> <span class='key'>and</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bDeleteCode</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='str'>&quot;Can&#39;t use -d with -r (or you would delete all your source!)&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>bReplace</span> <span class='key'>and</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputName</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='str'>&quot;Can&#39;t use -o with -r (they are opposites)&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>Cog</span><span class='op'>(</span><span class='nam'>Redirectable</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; The Cog engine.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>Redirectable</span><span class='op'>.</span><span class='nam'>__init__</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sBeginSpec</span> <span class='op'>=</span> <span class='str'>&#39;[[[cog&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndSpec</span> <span class='op'>=</span> <span class='str'>&#39;]]]&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndOutput</span> <span class='op'>=</span> <span class='str'>&#39;[[[end]]]&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>reEndOutput</span> <span class='op'>=</span> <span class='nam'>re</span><span class='op'>.</span><span class='nam'>compile</span><span class='op'>(</span><span class='str'>r&#39;\[\[\[end]]](?P&lt;hashsect&gt; *\(checksum: (?P&lt;hash&gt;[a-f0-9]+)\))&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndFormat</span> <span class='op'>=</span> <span class='str'>&#39;[[[end]]] (checksum: %s)&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span> <span class='op'>=</span> <span class='nam'>CogOptions</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputMode</span> <span class='op'>=</span> <span class='str'>&#39;w&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>installCogModule</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>showWarning</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>msg</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>,</span> <span class='str'>&quot;Warning:&quot;</span><span class='op'>,</span> <span class='nam'>msg</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>isBeginSpecLine</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>s</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sBeginSpec</span><span class='op'>)</span> <span class='op'>&gt;=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>isEndSpecLine</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>s</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndSpec</span><span class='op'>)</span> <span class='op'>&gt;=</span> <span class='num'>0</span> <span class='key'>and</span> <span class='xx'>\</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndOutputLine</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>isEndOutputLine</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>s</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndOutput</span><span class='op'>)</span> <span class='op'>&gt;=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>installCogModule</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Magic mumbo-jumbo so that imported Python modules</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; can say &quot;import cog&quot; and get our state.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span> <span class='op'>=</span> <span class='nam'>imp</span><span class='op'>.</span><span class='nam'>new_module</span><span class='op'>(</span><span class='str'>&#39;cog&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>path</span> <span class='op'>=</span> <span class='op'>[</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>modules</span><span class='op'>[</span><span class='str'>&#39;cog&#39;</span><span class='op'>]</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>processFile</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>fIn</span><span class='op'>,</span> <span class='nam'>fOut</span><span class='op'>,</span> <span class='nam'>fname</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>globals</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Process an input file object to an output file object.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fIn and fOut can be file objects, or file names.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sFileIn</span> <span class='op'>=</span> <span class='nam'>fname</span> <span class='key'>or</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sFileOut</span> <span class='op'>=</span> <span class='nam'>fname</span> <span class='key'>or</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fInToClose</span> <span class='op'>=</span> <span class='nam'>fOutToClose</span> <span class='op'>=</span> <span class='nam'>None</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Convert filenames to files.</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>333</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>isinstance</span><span class='op'>(</span><span class='nam'>fIn</span><span class='op'>,</span> <span class='nam'>basestring</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Open the input file.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sFileIn</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fIn</span> <span class='op'>=</span> <span class='nam'>fInToClose</span> <span class='op'>=</span> <span class='nam'>open</span><span class='op'>(</span><span class='nam'>fIn</span><span class='op'>,</span> <span class='str'>&#39;r&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>337</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>isinstance</span><span class='op'>(</span><span class='nam'>fOut</span><span class='op'>,</span> <span class='nam'>basestring</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Open the output file.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sFileOut</span> <span class='op'>=</span> <span class='nam'>fOut</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span> <span class='op'>=</span> <span class='nam'>fOutToClose</span> <span class='op'>=</span> <span class='nam'>open</span><span class='op'>(</span><span class='nam'>fOut</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputMode</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fIn</span> <span class='op'>=</span> <span class='nam'>NumberedFileReader</span><span class='op'>(</span><span class='nam'>fIn</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bSawCog</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>inFile</span> <span class='op'>=</span> <span class='nam'>sFileIn</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>outFile</span> <span class='op'>=</span> <span class='nam'>sFileOut</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># The globals dict we&#39;ll use for this file.</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>353</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>globals</span> <span class='key'>is</span> <span class='nam'>None</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>globals</span> <span class='op'>=</span> <span class='op'>{</span><span class='op'>}</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># If there are any global defines, put them in the globals.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>globals</span><span class='op'>.</span><span class='nam'>update</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># loop over generator chunks</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>l</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Find the next spec begin</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>l</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isBeginSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>361</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Unexpected &#39;%s&#39;&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndSpec</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>364</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndOutputLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Unexpected &#39;%s&#39;&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndOutput</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>l</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>374</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bDeleteCode</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># l is the begin spec</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gen</span> <span class='op'>=</span> <span class='nam'>CogGenerator</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gen</span><span class='op'>.</span><span class='nam'>setOutput</span><span class='op'>(</span><span class='nam'>stdout</span><span class='op'>=</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gen</span><span class='op'>.</span><span class='nam'>parseMarker</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>firstLineNum</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>firstLineNum</span> <span class='op'>=</span> <span class='nam'>firstLineNum</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># If the spec begin is also a spec end, then process the single</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># line of code inside.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>beg</span> <span class='op'>=</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sBeginSpec</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>end</span> <span class='op'>=</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndSpec</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>beg</span> <span class='op'>&gt;</span> <span class='nam'>end</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Cog code markers inverted&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>firstLineNum</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sCode</span> <span class='op'>=</span> <span class='nam'>l</span><span class='op'>[</span><span class='nam'>beg</span><span class='op'>+</span><span class='nam'>len</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>sBeginSpec</span><span class='op'>)</span><span class='op'>:</span><span class='nam'>end</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>strip</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gen</span><span class='op'>.</span><span class='nam'>parseLine</span><span class='op'>(</span><span class='nam'>sCode</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Deal with an ordinary code block.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Get all the lines in the spec</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>l</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>398</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isBeginSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Unexpected &#39;%s&#39;&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sBeginSpec</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>401</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndOutputLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Unexpected &#39;%s&#39;&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndOutput</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>405</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bDeleteCode</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gen</span><span class='op'>.</span><span class='nam'>parseLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>408</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>l</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;Cog block begun but never ended.&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>firstLineNum</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>414</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bDeleteCode</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>gen</span><span class='op'>.</span><span class='nam'>parseMarker</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Eat all the lines in the output section.&nbsp; While reading past</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># them, compute the md5 hash of the old output.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>hasher</span> <span class='op'>=</span> <span class='nam'>hash_factory</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>l</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndOutputLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>423</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isBeginSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Unexpected &#39;%s&#39;&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sBeginSpec</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>426</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>isEndSpecLine</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Unexpected &#39;%s&#39;&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndSpec</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>hasher</span><span class='op'>.</span><span class='nam'>update</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>curHash</span> <span class='op'>=</span> <span class='nam'>hasher</span><span class='op'>.</span><span class='nam'>hexdigest</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>434</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>l</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bEofCanBeEnd</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We reached end of file before we found the end output line.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Missing &#39;%s&#39; before end of file.&quot;</span> <span class='op'>%</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndOutput</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Write the output of the spec to be the new output if we&#39;re </span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># supposed to generate code.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>hasher</span> <span class='op'>=</span> <span class='nam'>hash_factory</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>446</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bNoGenerate</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sFile</span> <span class='op'>=</span> <span class='str'>&quot;%s+%d&quot;</span> <span class='op'>%</span> <span class='op'>(</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>firstLineNum</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sGen</span> <span class='op'>=</span> <span class='nam'>gen</span><span class='op'>.</span><span class='nam'>evaluate</span><span class='op'>(</span><span class='nam'>cog</span><span class='op'>=</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>globals</span><span class='op'>=</span><span class='nam'>globals</span><span class='op'>,</span> <span class='nam'>fname</span><span class='op'>=</span><span class='nam'>sFile</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sGen</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>suffixLines</span><span class='op'>(</span><span class='nam'>sGen</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>hasher</span><span class='op'>.</span><span class='nam'>update</span><span class='op'>(</span><span class='nam'>sGen</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>sGen</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>newHash</span> <span class='op'>=</span> <span class='nam'>hasher</span><span class='op'>.</span><span class='nam'>hexdigest</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bSawCog</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Write the ending output line</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>hashMatch</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>reEndOutput</span><span class='op'>.</span><span class='nam'>search</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>453</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bHashOutput</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>hashMatch</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>oldHash</span> <span class='op'>=</span> <span class='nam'>hashMatch</span><span class='op'>.</span><span class='nam'>groupdict</span><span class='op'>(</span><span class='op'>)</span><span class='op'>[</span><span class='str'>&#39;hash&#39;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>oldHash</span> <span class='op'>!=</span> <span class='nam'>curHash</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Output has been edited! Delete old checksum to unprotect.&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>file</span><span class='op'>=</span><span class='nam'>sFileIn</span><span class='op'>,</span> <span class='nam'>line</span><span class='op'>=</span><span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>linenumber</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Create a new end line with the correct hash.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>endpieces</span> <span class='op'>=</span> <span class='nam'>l</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='nam'>hashMatch</span><span class='op'>.</span><span class='nam'>group</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># There was no old hash, but we want a new hash.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>endpieces</span> <span class='op'>=</span> <span class='nam'>l</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndOutput</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>sEndFormat</span> <span class='op'>%</span> <span class='nam'>newHash</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='nam'>endpieces</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We don&#39;t want hashes output, so if there was one, get rid of</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># it.</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>468</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>hashMatch</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>l</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='nam'>hashMatch</span><span class='op'>.</span><span class='nam'>groupdict</span><span class='op'>(</span><span class='op'>)</span><span class='op'>[</span><span class='str'>&#39;hashsect&#39;</span><span class='op'>]</span><span class='op'>,</span> <span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>472</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bDeleteCode</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOut</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>l</span> <span class='op'>=</span> <span class='nam'>fIn</span><span class='op'>.</span><span class='nam'>readline</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>475</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>bSawCog</span> <span class='key'>and</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bWarnEmpty</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>showWarning</span><span class='op'>(</span><span class='str'>&quot;no cog code found in %s&quot;</span> <span class='op'>%</span> <span class='nam'>sFileIn</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>478</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>fInToClose</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fInToClose</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>480</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>fOutToClose</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOutToClose</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># A regex for non-empty lines, used by suffixLines.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>reNonEmptyLines</span> <span class='op'>=</span> <span class='nam'>re</span><span class='op'>.</span><span class='nam'>compile</span><span class='op'>(</span><span class='str'>&quot;^\s*\S+.*$&quot;</span><span class='op'>,</span> <span class='nam'>re</span><span class='op'>.</span><span class='nam'>MULTILINE</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>suffixLines</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>text</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Add suffixes to the lines in text, if our options desire it.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text is many lines, as a single string.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>492</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sSuffix</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Find all non-blank lines, and add the suffix to the end.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>repl</span> <span class='op'>=</span> <span class='str'>r&quot;\g&lt;0&gt;&quot;</span> <span class='op'>+</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sSuffix</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='str'>&#39;\\&#39;</span><span class='op'>,</span> <span class='str'>&#39;\\\\&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>text</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>reNonEmptyLines</span><span class='op'>.</span><span class='nam'>sub</span><span class='op'>(</span><span class='nam'>repl</span><span class='op'>,</span> <span class='nam'>text</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>text</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>processString</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sInput</span><span class='op'>,</span> <span class='nam'>fname</span><span class='op'>=</span><span class='nam'>None</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Process sInput as the text to cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return the cogged output as a string.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOld</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='nam'>sInput</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fNew</span> <span class='op'>=</span> <span class='nam'>StringIO</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processFile</span><span class='op'>(</span><span class='nam'>fOld</span><span class='op'>,</span> <span class='nam'>fNew</span><span class='op'>,</span> <span class='nam'>fname</span><span class='op'>=</span><span class='nam'>fname</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>fNew</span><span class='op'>.</span><span class='nam'>getvalue</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>replaceFile</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sOldPath</span><span class='op'>,</span> <span class='nam'>sNewText</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Replace file sOldPath with the contents sNewText</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>access</span><span class='op'>(</span><span class='nam'>sOldPath</span><span class='op'>,</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>W_OK</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Need to ensure we can write.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sMakeWritableCmd</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Use an external command to make the file writable.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>cmd</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sMakeWritableCmd</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='str'>&#39;%s&#39;</span><span class='op'>,</span> <span class='nam'>sOldPath</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>os</span><span class='op'>.</span><span class='nam'>popen</span><span class='op'>(</span><span class='nam'>cmd</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>access</span><span class='op'>(</span><span class='nam'>sOldPath</span><span class='op'>,</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>W_OK</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Couldn&#39;t make %s writable&quot;</span> <span class='op'>%</span> <span class='nam'>sOldPath</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Can&#39;t write!</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogError</span><span class='op'>(</span><span class='str'>&quot;Can&#39;t overwrite %s&quot;</span> <span class='op'>%</span> <span class='nam'>sOldPath</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>f</span> <span class='op'>=</span> <span class='nam'>open</span><span class='op'>(</span><span class='nam'>sOldPath</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputMode</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>f</span><span class='op'>.</span><span class='nam'>write</span><span class='op'>(</span><span class='nam'>sNewText</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>f</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>saveIncludePath</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>savedInclude</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>includePath</span><span class='op'>[</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>savedSysPath</span> <span class='op'>=</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>path</span><span class='op'>[</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>restoreIncludePath</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>includePath</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>savedInclude</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>includePath</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>savedSysPath</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>addToIncludePath</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>includePath</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>cogmodule</span><span class='op'>.</span><span class='nam'>path</span><span class='op'>.</span><span class='nam'>extend</span><span class='op'>(</span><span class='nam'>includePath</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>path</span><span class='op'>.</span><span class='nam'>extend</span><span class='op'>(</span><span class='nam'>includePath</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>processOneFile</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sFile</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Process one filename through cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>saveIncludePath</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>addToIncludePath</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>includePath</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Since we know where the input file came from,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># push its directory onto the include path.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>addToIncludePath</span><span class='op'>(</span><span class='op'>[</span><span class='nam'>os</span><span class='op'>.</span><span class='nam'>path</span><span class='op'>.</span><span class='nam'>dirname</span><span class='op'>(</span><span class='nam'>sFile</span><span class='op'>)</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Set the file output mode based on whether we want \n or native</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># line endings.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputMode</span> <span class='op'>=</span> <span class='str'>&#39;w&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bNewlines</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>sOutputMode</span> <span class='op'>=</span> <span class='str'>&#39;wb&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># How we process the file depends on where the output is going.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sOutputName</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processFile</span><span class='op'>(</span><span class='nam'>sFile</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sOutputName</span><span class='op'>,</span> <span class='nam'>sFile</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bReplace</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We want to replace the cog file with the output,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># but only if they differ.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>,</span> <span class='str'>&quot;Cogging %s&quot;</span> <span class='op'>%</span> <span class='nam'>sFile</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bNeedNewline</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOldFile</span> <span class='op'>=</span> <span class='nam'>open</span><span class='op'>(</span><span class='nam'>sFile</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sOldText</span> <span class='op'>=</span> <span class='nam'>fOldFile</span><span class='op'>.</span><span class='nam'>read</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>fOldFile</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sNewText</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processString</span><span class='op'>(</span><span class='nam'>sOldText</span><span class='op'>,</span> <span class='nam'>fname</span><span class='op'>=</span><span class='nam'>sFile</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>sOldText</span> <span class='op'>!=</span> <span class='nam'>sNewText</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>,</span> <span class='str'>&quot;&nbsp; (changed)&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>bNeedNewline</span> <span class='op'>=</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>replaceFile</span><span class='op'>(</span><span class='nam'>sFile</span><span class='op'>,</span> <span class='nam'>sNewText</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># The try-finally block is so we can print a partial line</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># with the name of the file, and print (changed) on the</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># same line, but also make sure to break the line before</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># any traceback.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>bNeedNewline</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processFile</span><span class='op'>(</span><span class='nam'>sFile</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>,</span> <span class='nam'>sFile</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>finally</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>restoreIncludePath</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>processFileList</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>sFileList</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Process the files in a file list.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>flist</span> <span class='op'>=</span> <span class='nam'>open</span><span class='op'>(</span><span class='nam'>sFileList</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lines</span> <span class='op'>=</span> <span class='nam'>flist</span><span class='op'>.</span><span class='nam'>readlines</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>flist</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>l</span> <span class='key'>in</span> <span class='nam'>lines</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Use shlex to parse the line like a shell.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lex</span> <span class='op'>=</span> <span class='nam'>shlex</span><span class='op'>.</span><span class='nam'>shlex</span><span class='op'>(</span><span class='nam'>l</span><span class='op'>,</span> <span class='nam'>posix</span><span class='op'>=</span><span class='nam'>True</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lex</span><span class='op'>.</span><span class='nam'>whitespace_split</span> <span class='op'>=</span> <span class='nam'>True</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lex</span><span class='op'>.</span><span class='nam'>commenters</span> <span class='op'>=</span> <span class='str'>&#39;#&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># No escapes, so that backslash can be part of the path</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>lex</span><span class='op'>.</span><span class='nam'>escape</span> <span class='op'>=</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>args</span> <span class='op'>=</span> <span class='nam'>list</span><span class='op'>(</span><span class='nam'>lex</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>args</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processArguments</span><span class='op'>(</span><span class='nam'>args</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>processArguments</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>args</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Process one command-line.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>saved_options</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>clone</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>parseArgs</span><span class='op'>(</span><span class='nam'>args</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>validate</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>args</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;@&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>sOutputName</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='str'>&quot;Can&#39;t use -o with @file&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processFileList</span><span class='op'>(</span><span class='nam'>args</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processOneFile</span><span class='op'>(</span><span class='nam'>args</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span> <span class='op'>=</span> <span class='nam'>saved_options</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>callableMain</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>argv</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; All of command-line cog, but in a callable form.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; This is used by main.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; argv is the equivalent of sys.argv.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>argv0</span> <span class='op'>=</span> <span class='nam'>argv</span><span class='op'>.</span><span class='nam'>pop</span><span class='op'>(</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Provide help if asked for anywhere in the command line.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='str'>&#39;-?&#39;</span> <span class='key'>in</span> <span class='nam'>argv</span> <span class='key'>or</span> <span class='str'>&#39;-h&#39;</span> <span class='key'>in</span> <span class='nam'>argv</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>,</span> <span class='nam'>usage</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>parseArgs</span><span class='op'>(</span><span class='nam'>argv</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>validate</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>bShowVersion</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stdout</span><span class='op'>,</span> <span class='str'>&quot;Cog version %s&quot;</span> <span class='op'>%</span> <span class='nam'>__version__</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>args</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>a</span> <span class='key'>in</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>options</span><span class='op'>.</span><span class='nam'>args</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>processArguments</span><span class='op'>(</span><span class='op'>[</span><span class='nam'>a</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>CogUsageError</span><span class='op'>(</span><span class='str'>&quot;No files to process&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>main</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>,</span> <span class='nam'>argv</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot; Handle the command-line execution for cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>callableMain</span><span class='op'>(</span><span class='nam'>argv</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>CogUsageError</span><span class='op'>,</span> <span class='nam'>err</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>,</span> <span class='nam'>err</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>,</span> <span class='str'>&quot;(for help use -?)&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>2</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>CogGeneratedError</span><span class='op'>,</span> <span class='nam'>err</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>,</span> <span class='str'>&quot;Error: %s&quot;</span> <span class='op'>%</span> <span class='nam'>err</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>3</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>CogError</span><span class='op'>,</span> <span class='nam'>err</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>print</span> <span class='op'>&gt;&gt;</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>,</span> <span class='nam'>err</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>traceback</span><span class='op'>.</span><span class='nam'>print_exc</span><span class='op'>(</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>stderr</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># History:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20040210: First public version.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20040220: Text preceding the start and end marker are removed from Python lines.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; -v option on the command line shows the version.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20040311: Make sure the last line of output is properly ended with a newline.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20040605: Fixed some blank line handling in cog.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Fixed problems with assigning to xml elements in handyxml.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20040621: Changed all line-ends to LF from CRLF.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20041002: Refactor some option handling to simplify unittesting the options.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20041118: cog.out and cog.outl have optional string arguments.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20041119: File names weren&#39;t being properly passed around for warnings, etc.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20041122: Added cog.firstLineNum: a property with the line number of the [[[cog line.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Added cog.inFile and cog.outFile: the names of the input and output file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20041218: Single-line cog generators, with start marker and end marker on</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; the same line.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20041230: Keep a single globals dict for all the code fragments in a single</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; file so they can share state.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050206: Added the -x switch to remove all generated output.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050218: Now code can be on the marker lines as well.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050219: Added -c switch to checksum the output so that edits can be</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; detected before they are obliterated.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050521: Added cog.error, contributed by Alexander Belchenko.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050720: Added code deletion and settable globals contributed by Blake Winton.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050724: Many tweaks to improve code coverage.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050726: Error messages are now printed with no traceback.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Code can no longer appear on the marker lines,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; except for single-line style.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; -z allows omission of the [[[end]]] marker, and it will be assumed</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; at the end of the file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050729: Refactor option parsing into a separate class, in preparation for</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; future features.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050805: The cogmodule.path wasn&#39;t being properly maintained.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050808: Added the -D option to define a global value.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050810: The %s in the -w command is dealt with more robustly.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Added the -s option to suffix output lines with a marker.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20050817: Now @files can have arguments on each line to change the cog&#39;s</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; behavior for that line.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20051006: Version 2.0</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20080521: -U options lets you create Unix newlines on Windows.&nbsp; Thanks,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Alexander Belchenko.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20080522: It&#39;s now ok to have -d with output to stdout, and now we validate</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; the args after each line of an @file.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># 20090520: Use hashlib where it&#39;s available, to avoid a warning.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Use the builtin compile() instead of compiler, for Jython.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Explicitly close files we opened, Jython likes this.</span><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>