-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedparse_debug_output.html
3990 lines (3988 loc) · 325 KB
/
feedparse_debug_output.html
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
<html>
<head>
<style>
body {
margin: 30px;
}
table {
border: solid 1px;
}
.bozo {
background: pink;
padding: 2px;
margin-bottom: 15px;
}
.type {
color: gray;
font-size: 11px;
}
</style>
</head>
<body>
<div class="bozo">text/html; charset=UTF-8 is not an XML media type</div>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.bozo | int" valign=top>bozo<br/><span class="type">int</span></td><td valign=top>1</td>
<tr><td title="f.bozo_exception | NonXMLContentType" valign=top>bozo_exception<br/><span class="type">NonXMLContentType</span></td><td valign=top>NonXMLContentType('text/html; charset=UTF-8 is not an XML media
<br/>type',)</td>
<tr><td title="f.encoding | str" valign=top>encoding<br/><span class="type">str</span></td><td valign=top>'UTF-8'</td>
<tr><td title="f.etag | str" valign=top>etag<br/><span class="type">str</span></td><td valign=top>'"461a1217-20a2-4258-8597-cdfd30a5c37e"'</td>
<tr><td title="f.feed | FeedParserDict" valign=top>feed<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.author | unicode" valign=top>author<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
<tr><td title="f.feed.author_detail | FeedParserDict" valign=top>author_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.author_detail.name | unicode" valign=top>name<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
</table>
</td>
<tr><td title="f.feed.generator | unicode" valign=top>generator<br/><span class="type">unicode</span></td><td valign=top>u'Blogger'</td>
<tr><td title="f.feed.generator_detail | FeedParserDict" valign=top>generator_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.generator_detail.href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com' <a href="http://www.blogger.com">[link]</a></td>
<tr><td title="f.feed.generator_detail.name | unicode" valign=top>name<br/><span class="type">unicode</span></td><td valign=top>u'Blogger'</td>
<tr><td title="f.feed.generator_detail.version | unicode" valign=top>version<br/><span class="type">unicode</span></td><td valign=top>u'7.00'</td>
</table>
</td>
<tr><td title="f.feed.id | unicode" valign=top>id<br/><span class="type">unicode</span></td><td valign=top>u'tag:blogger.com,1999:blog-4259015877647291249'</td>
<tr><td title="f.feed.itemsperpage | unicode" valign=top>itemsperpage<br/><span class="type">unicode</span></td><td valign=top>u'25'</td>
<tr><td title="f.feed.link | unicode" valign=top>link<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/' <a href="http://defcraft.blogspot.com/">[link]</a></td>
<tr><td title="f.feed.links | list" valign=top>links<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.links[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.links[0].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/' <a href="http://defcraft.blogspot.com/">[link]</a></td>
<tr><td title="f.feed.links[0].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'alternate'</td>
<tr><td title="f.feed.links[0].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.feed.links[1] | FeedParserDict" valign=top>[1]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.links[1].href | str" valign=top>href<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.feed.links[1].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'http://schemas.google.com/g/2005#feed' <a href="http://schemas.google.com/g/2005#feed">[link]</a></td>
<tr><td title="f.feed.links[1].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.feed.links[2] | FeedParserDict" valign=top>[2]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.links[2].href | str" valign=top>href<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.feed.links[2].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'self'</td>
<tr><td title="f.feed.links[2].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.feed.startindex | unicode" valign=top>startindex<br/><span class="type">unicode</span></td><td valign=top>u'1'</td>
<tr><td title="f.feed.title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'defcraft'</td>
<tr><td title="f.feed.title_detail | FeedParserDict" valign=top>title_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.feed.title_detail.base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.feed.title_detail.language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.feed.title_detail.type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/plain'</td>
<tr><td title="f.feed.title_detail.value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'defcraft'</td>
</table>
</td>
<tr><td title="f.feed.totalresults | unicode" valign=top>totalresults<br/><span class="type">unicode</span></td><td valign=top>u'19'</td>
<tr><td title="f.feed.updated | unicode" valign=top>updated<br/><span class="type">unicode</span></td><td valign=top>u'2007-07-24T06:19:34.182-07:00'</td>
<tr><td title="f.feed.updated_parsed | struct_time" valign=top>updated_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 7, 24, 6, 19, 34, 1, 205, 0)</td>
</table>
</td>
<tr><td title="f.headers | dict" valign=top>headers<br/><span class="type">dict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.headers.cache-control | str" valign=top>cache-control<br/><span class="type">str</span></td><td valign=top>'max-age=0 private'</td>
<tr><td title="f.headers.content-type | str" valign=top>content-type<br/><span class="type">str</span></td><td valign=top>'text/html; charset=UTF-8'</td>
<tr><td title="f.headers.date | str" valign=top>date<br/><span class="type">str</span></td><td valign=top>'Thu, 26 Jul 2007 13:53:26 GMT'</td>
<tr><td title="f.headers.etag | str" valign=top>etag<br/><span class="type">str</span></td><td valign=top>'"461a1217-20a2-4258-8597-cdfd30a5c37e"'</td>
<tr><td title="f.headers.last-modified | str" valign=top>last-modified<br/><span class="type">str</span></td><td valign=top>'Tue, 24 Jul 2007 13:19:34 GMT'</td>
<tr><td title="f.headers.server | str" valign=top>server<br/><span class="type">str</span></td><td valign=top>'GFE/1.3'</td>
<tr><td title="f.headers.transfer-encoding | str" valign=top>transfer-encoding<br/><span class="type">str</span></td><td valign=top>'chunked'</td>
</table>
</td>
<tr><td title="f.href | str" valign=top>href<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.namespaces | dict" valign=top>namespaces<br/><span class="type">dict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.namespaces. | unicode" valign=top><br/><span class="type">unicode</span></td><td valign=top>u'http://www.w3.org/2005/Atom' <a href="http://www.w3.org/2005/Atom">[link]</a></td>
<tr><td title="f.namespaces.openSearch | unicode" valign=top>openSearch<br/><span class="type">unicode</span></td><td valign=top>u'http://a9.com/-/spec/opensearchrss/1.0/' <a href="http://a9.com/-/spec/opensearchrss/1.0/">[link]</a></td>
</table>
</td>
<tr><td title="f.status | int" valign=top>status<br/><span class="type">int</span></td><td valign=top>200</td>
<tr><td title="f.updated | struct_time" valign=top>updated<br/><span class="type">struct_time</span></td><td valign=top>(2007, 7, 24, 13, 19, 34, 1, 205, 0)</td>
<tr><td title="f.version | str" valign=top>version<br/><span class="type">str</span></td><td valign=top>'atom10'</td>
<tr><td title="f.entries | list" valign=top>entries<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].author | unicode" valign=top>author<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
<tr><td title="f.entries[0].author_detail | FeedParserDict" valign=top>author_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].author_detail.name | unicode" valign=top>name<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
</table>
</td>
<tr><td title="f.entries[0].content | list" valign=top>content<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].content[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].content[0].base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[0].content[0].language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[0].content[0].type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/html'</td>
<tr><td title="f.entries[0].content[0].value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'<p>\nI can still remember my left pinky hurting badly,
<br/>from\npressing the Control key to invoke commands in Emacs.\nBut then
<br/>I swapped Shift & Control. And I\'ve been \nhappy ever since.
<br/>Shift is in a perfect location\n(not too far below like Control)\nand
<br/>is on both sides of the keyboard -- this even\non the worst keyboards
<br/>that I had to endure while\nin college.\n</p>\n\n<p>Now,
<br/>some things break when you do this.\nControl-Space sets the mark (and
<br/>still\ndoes), but Shift-Space doesn\'t -- it\nsimply inserts a space.
<br/>Control-G can break\nout of infinite loops in Emacs Lisp --
<br/>Shift-g\ncan\'t do that (unless you modify the quit_char\nin
<br/>src/keyboard.c before building Emacs). Also,\ntyping upcase or
<br/>capitilized characters are a\nbit harder -- especially because I move
<br/>my\nentire hand off the keyboard to hit the Control\nkey -- no more
<br/>use of the pinky in unnatural\npositions! And when you cut-n-paste,
<br/>upper\ncase characters run commands!! (Although,\nI haven\'t needed
<br/>it, this shouldn\'t be too hard\nto overcome -- you can setup things
<br/>so that\na keypress swaps Control & Shift, and then\npastes the
<br/>contents of the clipboard, \nand the re-swaps them
<br/>again.)\n\n</p>\n\n\n<p>\nDespite the problems, this has
<br/>been worth\nit for me. And here is the code for all this.\nI think
<br/>this is all the code -- I haven\'t really looked at\nit since I wrote
<br/>it about 6 years ago. This\nworks on both Windows and Linux (I think,
<br/>this will\nreally work everywhere...):\n</p>\n\n<pre
<br/>class="codebox">\n;;; control becomes shift and vice-versa. when
<br/>this happens certain\n;;; things are broken: c-space sets mark,
<br/>however shift-space doesn\'t\n;;; anymore. for esc, use alt (press
<br/>this with the thumb, which\n;;; doesn\'t do *anything* except hit the
<br/>damn space bar) plus the key.\n;;; expriment: 04:29PM Friday November
<br/>23 2001. hopefully, things\n;;; will be much easier this way.\n;;; to
<br/>do: change esc-c-f to esc-F. also need to be careful about\n;;; esc-
<br/>ctrl- like esc-ctrl-. and esc-ctrl-backspace. how to\n;;; fix these.
<br/>also since i usually type a lowercase word and want to\n;;; upcase or
<br/>capatilize it afterwards, make those commands default to the\n;;;
<br/>previous word.\n\n;;; Another idea: make keyboard-translate-table
<br/>buffer local so that\n;;; in certain modes, like gnus, we can operate
<br/>normally (or maybe\n;;; change it during an entry and exit
<br/>hook.\n\n(defun keyboard-translate-swap (a b)\n (keyboard-translate a
<br/>b)\n (keyboard-translate b a))\n\n(defvar previous-keyboard-
<br/>translate-table nil)\n\n(defun normalize-keyboard ()\n
<br/>(interactive)\n (setq previous-keyboard-translate-table keyboard-
<br/>translate-table\n keyboard-translate-table nil))\n\n(defun
<br/>revert-keyboard ()\n (interactive)\n (setq keyboard-translate-table
<br/>previous-keyboard-translate-table))\n\n;;; Emacs Manual, "Translating
<br/>Input Events"\n(setq keyboard-translate-table\n (make-char-table
<br/>\'keyboard-translate-table nil))\n\n;;; Swap Control- and uppercase
<br/>letters.\n(let ((ctrl 1) (upcase-beg (1- ?A)) (letters 26))\n (while
<br/>(<= ctrl letters)\n (keyboard-translate-swap ctrl (+ upcase-beg
<br/>ctrl))\n (setq ctrl (1+ ctrl))))\n\n</pre>\n\n<p>And
<br/>this piece of code quickly upcases or capitalizes the previous word
<br/>that\nyou just typed. I have it bound to F6:\n</p>\n\n<pre
<br/>class="codebox">\n(defvar my-correct-case-last-arg nil)\n\n(defun
<br/>my-correct-case (arg)\n (interactive "p")\n (let ((fn (cond ((eq
<br/>last-command \'my-correct-case)\n (setq arg my-
<br/>correct-case-last-arg)\n \'capitalize-word)\n
<br/>(t (setq my-correct-case-last-arg arg)\n \'upcase-
<br/>word))))\n (save-excursion\n (funcall fn (-
<br/>arg)))))\n\n</pre>\n\n<p>\nThese days I run Emacs via
<br/>Putty from a Windows machine.\nThis is how I cut-n-paste in Putty --
<br/>when you right click\non the terminal, Putty sends the contents of the
<br/>clipboard\nto the terminal. There are 2 parts to this: the Emacs
<br/>part\nand the shell part. First, I have to suspend Emacs and\ngo to
<br/>the shell, where is type the alias c:\n</p>\n\n<pre
<br/>class="codebox">\nalias c=\'echo Hit Ctrl-C to end; cat &gt;
<br/>~/x\'\n</pre>\n\n<p>Next, back in Emacs, I hit F10 -- this
<br/>function is bound \nto that key:\n</p>\n\n<pre
<br/>class="codebox">\n(defun my-paste ()\n (interactive)\n (if (not
<br/>(file-exists-p "~/x"))\n (message "~/x doesn\'t exist")\n
<br/>(insert-file-contents "~/x")\n (message "Pasted contents of
<br/>~/x")))\n\n</pre>'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[0].id | unicode" valign=top>id<br/><span class="type">unicode</span></td><td valign=top>u'tag:blogger.com,1999:blog-4259015877647291249.post-79334019218633513
<br/>91'</td>
<tr><td title="f.entries[0].link | unicode" valign=top>link<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/2007/07/my-dot-emacs-shift-to-
<br/>control.html' <a href="http://defcraft.blogspot.com/2007/07/my-dot-emacs-shift-to-control.html">[link]</a></td>
<tr><td title="f.entries[0].links | list" valign=top>links<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].links[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].links[0].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/2007/07/my-dot-emacs-shift-to-
<br/>control.html' <a href="http://defcraft.blogspot.com/2007/07/my-dot-emacs-shift-to-control.html">[link]</a></td>
<tr><td title="f.entries[0].links[0].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'alternate'</td>
<tr><td title="f.entries[0].links[0].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'my dot emacs: Shift to Control'</td>
<tr><td title="f.entries[0].links[0].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[0].links[1] | FeedParserDict" valign=top>[1]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].links[1].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/comment.g?blogID=4259015877647291249&post
<br/>ID=7933401921863351391' <a href="http://www.blogger.com/comment.g?blogID=4259015877647291249&postID=7933401921863351391">[link]</a></td>
<tr><td title="f.entries[0].links[1].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[0].links[1].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'0 Comments'</td>
<tr><td title="f.entries[0].links[1].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[0].links[2] | FeedParserDict" valign=top>[2]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].links[2].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/7933401921863351391/comments/defa
<br/>ult' <a href="http://defcraft.blogspot.com/feeds/7933401921863351391/comments/default">[link]</a></td>
<tr><td title="f.entries[0].links[2].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[0].links[2].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'Post Comments'</td>
<tr><td title="f.entries[0].links[2].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[0].links[3] | FeedParserDict" valign=top>[3]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].links[3].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/posts/default/7933401921863351391
<br/>' <a href="http://defcraft.blogspot.com/feeds/posts/default/7933401921863351391">[link]</a></td>
<tr><td title="f.entries[0].links[3].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'self'</td>
<tr><td title="f.entries[0].links[3].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[0].links[4] | FeedParserDict" valign=top>[4]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].links[4].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/feeds/4259015877647291249/posts/default/79334
<br/>01921863351391' <a href="http://www.blogger.com/feeds/4259015877647291249/posts/default/7933401921863351391">[link]</a></td>
<tr><td title="f.entries[0].links[4].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'edit'</td>
<tr><td title="f.entries[0].links[4].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[0].published | unicode" valign=top>published<br/><span class="type">unicode</span></td><td valign=top>u'2007-07-24T06:11:00.000-07:00'</td>
<tr><td title="f.entries[0].published_parsed | struct_time" valign=top>published_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 7, 24, 6, 11, 0, 1, 205, 0)</td>
<tr><td title="f.entries[0].subtitle | unicode" valign=top>subtitle<br/><span class="type">unicode</span></td><td valign=top>u'<p>\nI can still remember my left pinky hurting badly,
<br/>from\npressing the Control key to invoke commands in Emacs.\nBut then
<br/>I swapped Shift & Control. And I\'ve been \nhappy ever since.
<br/>Shift is in a perfect location\n(not too far below like Control)\nand
<br/>is on both sides of the keyboard -- this even\non the worst keyboards
<br/>that I had to endure while\nin college.\n</p>\n\n<p>Now,
<br/>some things break when you do this.\nControl-Space sets the mark (and
<br/>still\ndoes), but Shift-Space doesn\'t -- it\nsimply inserts a space.
<br/>Control-G can break\nout of infinite loops in Emacs Lisp --
<br/>Shift-g\ncan\'t do that (unless you modify the quit_char\nin
<br/>src/keyboard.c before building Emacs). Also,\ntyping upcase or
<br/>capitilized characters are a\nbit harder -- especially because I move
<br/>my\nentire hand off the keyboard to hit the Control\nkey -- no more
<br/>use of the pinky in unnatural\npositions! And when you cut-n-paste,
<br/>upper\ncase characters run commands!! (Although,\nI haven\'t needed
<br/>it, this shouldn\'t be too hard\nto overcome -- you can setup things
<br/>so that\na keypress swaps Control & Shift, and then\npastes the
<br/>contents of the clipboard, \nand the re-swaps them
<br/>again.)\n\n</p>\n\n\n<p>\nDespite the problems, this has
<br/>been worth\nit for me. And here is the code for all this.\nI think
<br/>this is all the code -- I haven\'t really looked at\nit since I wrote
<br/>it about 6 years ago. This\nworks on both Windows and Linux (I think,
<br/>this will\nreally work everywhere...):\n</p>\n\n<pre
<br/>class="codebox">\n;;; control becomes shift and vice-versa. when
<br/>this happens certain\n;;; things are broken: c-space sets mark,
<br/>however shift-space doesn\'t\n;;; anymore. for esc, use alt (press
<br/>this with the thumb, which\n;;; doesn\'t do *anything* except hit the
<br/>damn space bar) plus the key.\n;;; expriment: 04:29PM Friday November
<br/>23 2001. hopefully, things\n;;; will be much easier this way.\n;;; to
<br/>do: change esc-c-f to esc-F. also need to be careful about\n;;; esc-
<br/>ctrl- like esc-ctrl-. and esc-ctrl-backspace. how to\n;;; fix these.
<br/>also since i usually type a lowercase word and want to\n;;; upcase or
<br/>capatilize it afterwards, make those commands default to the\n;;;
<br/>previous word.\n\n;;; Another idea: make keyboard-translate-table
<br/>buffer local so that\n;;; in certain modes, like gnus, we can operate
<br/>normally (or maybe\n;;; change it during an entry and exit
<br/>hook.\n\n(defun keyboard-translate-swap (a b)\n (keyboard-translate a
<br/>b)\n (keyboard-translate b a))\n\n(defvar previous-keyboard-
<br/>translate-table nil)\n\n(defun normalize-keyboard ()\n
<br/>(interactive)\n (setq previous-keyboard-translate-table keyboard-
<br/>translate-table\n keyboard-translate-table nil))\n\n(defun
<br/>revert-keyboard ()\n (interactive)\n (setq keyboard-translate-table
<br/>previous-keyboard-translate-table))\n\n;;; Emacs Manual, "Translating
<br/>Input Events"\n(setq keyboard-translate-table\n (make-char-table
<br/>\'keyboard-translate-table nil))\n\n;;; Swap Control- and uppercase
<br/>letters.\n(let ((ctrl 1) (upcase-beg (1- ?A)) (letters 26))\n (while
<br/>(<= ctrl letters)\n (keyboard-translate-swap ctrl (+ upcase-beg
<br/>ctrl))\n (setq ctrl (1+ ctrl))))\n\n</pre>\n\n<p>And
<br/>this piece of code quickly upcases or capitalizes the previous word
<br/>that\nyou just typed. I have it bound to F6:\n</p>\n\n<pre
<br/>class="codebox">\n(defvar my-correct-case-last-arg nil)\n\n(defun
<br/>my-correct-case (arg)\n (interactive "p")\n (let ((fn (cond ((eq
<br/>last-command \'my-correct-case)\n (setq arg my-
<br/>correct-case-last-arg)\n \'capitalize-word)\n
<br/>(t (setq my-correct-case-last-arg arg)\n \'upcase-
<br/>word))))\n (save-excursion\n (funcall fn (-
<br/>arg)))))\n\n</pre>\n\n<p>\nThese days I run Emacs via
<br/>Putty from a Windows machine.\nThis is how I cut-n-paste in Putty --
<br/>when you right click\non the terminal, Putty sends the contents of the
<br/>clipboard\nto the terminal. There are 2 parts to this: the Emacs
<br/>part\nand the shell part. First, I have to suspend Emacs and\ngo to
<br/>the shell, where is type the alias c:\n</p>\n\n<pre
<br/>class="codebox">\nalias c=\'echo Hit Ctrl-C to end; cat &gt;
<br/>~/x\'\n</pre>\n\n<p>Next, back in Emacs, I hit F10 -- this
<br/>function is bound \nto that key:\n</p>\n\n<pre
<br/>class="codebox">\n(defun my-paste ()\n (interactive)\n (if (not
<br/>(file-exists-p "~/x"))\n (message "~/x doesn\'t exist")\n
<br/>(insert-file-contents "~/x")\n (message "Pasted contents of
<br/>~/x")))\n\n</pre>'</td>
<tr><td title="f.entries[0].tags | list" valign=top>tags<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].tags[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].tags[0].label | NoneType" valign=top>label<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[0].tags[0].scheme | unicode" valign=top>scheme<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/atom/ns#' <a href="http://www.blogger.com/atom/ns#">[link]</a></td>
<tr><td title="f.entries[0].tags[0].term | unicode" valign=top>term<br/><span class="type">unicode</span></td><td valign=top>u'emacs'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[0].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'my dot emacs: Shift to Control'</td>
<tr><td title="f.entries[0].title_detail | FeedParserDict" valign=top>title_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[0].title_detail.base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[0].title_detail.language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[0].title_detail.type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/plain'</td>
<tr><td title="f.entries[0].title_detail.value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'my dot emacs: Shift to Control'</td>
</table>
</td>
<tr><td title="f.entries[0].updated | unicode" valign=top>updated<br/><span class="type">unicode</span></td><td valign=top>u'2007-07-24T06:19:34.210-07:00'</td>
<tr><td title="f.entries[0].updated_parsed | struct_time" valign=top>updated_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 7, 24, 6, 19, 34, 1, 205, 0)</td>
</table>
</td>
<tr><td title="f.entries[1] | FeedParserDict" valign=top>[1]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].author | unicode" valign=top>author<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
<tr><td title="f.entries[1].author_detail | FeedParserDict" valign=top>author_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].author_detail.name | unicode" valign=top>name<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
</table>
</td>
<tr><td title="f.entries[1].content | list" valign=top>content<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].content[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].content[0].base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[1].content[0].language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[1].content[0].type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/html'</td>
<tr><td title="f.entries[1].content[0].value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'Firefox <a
<br/>href="http://www.greasespot.net/">Greasemonkey</a> hack:
<br/><a href="http://defcraft.org/%7Esri/myGM-hacks/sri-goog-
<br/>amazon.user.js">sri-goog-amazon.user.js</a>. (make sure you
<br/>know what you\'re doing if you install this...)\n\nSelect a piece of
<br/>text with your mouse and hit one of these
<br/>keys:\n\n<ul><li><span>ALT-A</span>: searches
<br/>Amazon.com for the selected text, in a background
<br/>tab\n</li><li><span>ALT-G</span>: does the
<br/>above with Google.com\n</li></ul>Also, without any
<br/>selection, ALT-A and ALT-G will take you to Amazon.com &amp;
<br/>Google.com respectively.'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[1].id | unicode" valign=top>id<br/><span class="type">unicode</span></td><td valign=top>u'tag:blogger.com,1999:blog-4259015877647291249.post-86265933447275708
<br/>21'</td>
<tr><td title="f.entries[1].link | unicode" valign=top>link<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/2007/07/firefox-greasemonkey-hack.html' <a href="http://defcraft.blogspot.com/2007/07/firefox-greasemonkey-hack.html">[link]</a></td>
<tr><td title="f.entries[1].links | list" valign=top>links<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].links[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].links[0].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/2007/07/firefox-greasemonkey-hack.html' <a href="http://defcraft.blogspot.com/2007/07/firefox-greasemonkey-hack.html">[link]</a></td>
<tr><td title="f.entries[1].links[0].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'alternate'</td>
<tr><td title="f.entries[1].links[0].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'Firefox Greasemonkey hack'</td>
<tr><td title="f.entries[1].links[0].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[1].links[1] | FeedParserDict" valign=top>[1]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].links[1].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/comment.g?blogID=4259015877647291249&post
<br/>ID=8626593344727570821' <a href="http://www.blogger.com/comment.g?blogID=4259015877647291249&postID=8626593344727570821">[link]</a></td>
<tr><td title="f.entries[1].links[1].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[1].links[1].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'0 Comments'</td>
<tr><td title="f.entries[1].links[1].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[1].links[2] | FeedParserDict" valign=top>[2]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].links[2].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/8626593344727570821/comments/defa
<br/>ult' <a href="http://defcraft.blogspot.com/feeds/8626593344727570821/comments/default">[link]</a></td>
<tr><td title="f.entries[1].links[2].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[1].links[2].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'Post Comments'</td>
<tr><td title="f.entries[1].links[2].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[1].links[3] | FeedParserDict" valign=top>[3]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].links[3].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/posts/default/8626593344727570821
<br/>' <a href="http://defcraft.blogspot.com/feeds/posts/default/8626593344727570821">[link]</a></td>
<tr><td title="f.entries[1].links[3].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'self'</td>
<tr><td title="f.entries[1].links[3].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[1].links[4] | FeedParserDict" valign=top>[4]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].links[4].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/feeds/4259015877647291249/posts/default/86265
<br/>93344727570821' <a href="http://www.blogger.com/feeds/4259015877647291249/posts/default/8626593344727570821">[link]</a></td>
<tr><td title="f.entries[1].links[4].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'edit'</td>
<tr><td title="f.entries[1].links[4].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[1].published | unicode" valign=top>published<br/><span class="type">unicode</span></td><td valign=top>u'2007-07-05T04:41:00.000-07:00'</td>
<tr><td title="f.entries[1].published_parsed | struct_time" valign=top>published_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 7, 5, 4, 41, 0, 3, 186, 0)</td>
<tr><td title="f.entries[1].subtitle | unicode" valign=top>subtitle<br/><span class="type">unicode</span></td><td valign=top>u'Firefox <a
<br/>href="http://www.greasespot.net/">Greasemonkey</a> hack:
<br/><a href="http://defcraft.org/%7Esri/myGM-hacks/sri-goog-
<br/>amazon.user.js">sri-goog-amazon.user.js</a>. (make sure you
<br/>know what you\'re doing if you install this...)\n\nSelect a piece of
<br/>text with your mouse and hit one of these
<br/>keys:\n\n<ul><li><span>ALT-A</span>: searches
<br/>Amazon.com for the selected text, in a background
<br/>tab\n</li><li><span>ALT-G</span>: does the
<br/>above with Google.com\n</li></ul>Also, without any
<br/>selection, ALT-A and ALT-G will take you to Amazon.com &amp;
<br/>Google.com respectively.'</td>
<tr><td title="f.entries[1].tags | list" valign=top>tags<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].tags[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].tags[0].label | NoneType" valign=top>label<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[1].tags[0].scheme | unicode" valign=top>scheme<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/atom/ns#' <a href="http://www.blogger.com/atom/ns#">[link]</a></td>
<tr><td title="f.entries[1].tags[0].term | unicode" valign=top>term<br/><span class="type">unicode</span></td><td valign=top>u'firefox'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[1].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'Firefox Greasemonkey hack'</td>
<tr><td title="f.entries[1].title_detail | FeedParserDict" valign=top>title_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[1].title_detail.base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[1].title_detail.language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[1].title_detail.type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/plain'</td>
<tr><td title="f.entries[1].title_detail.value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'Firefox Greasemonkey hack'</td>
</table>
</td>
<tr><td title="f.entries[1].updated | unicode" valign=top>updated<br/><span class="type">unicode</span></td><td valign=top>u'2007-07-05T04:58:59.753-07:00'</td>
<tr><td title="f.entries[1].updated_parsed | struct_time" valign=top>updated_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 7, 5, 4, 58, 59, 3, 186, 0)</td>
</table>
</td>
<tr><td title="f.entries[2] | FeedParserDict" valign=top>[2]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].author | unicode" valign=top>author<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
<tr><td title="f.entries[2].author_detail | FeedParserDict" valign=top>author_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].author_detail.name | unicode" valign=top>name<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
</table>
</td>
<tr><td title="f.entries[2].content | list" valign=top>content<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].content[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].content[0].base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[2].content[0].language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[2].content[0].type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/html'</td>
<tr><td title="f.entries[2].content[0].value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'<p>I can never remember the syntax for <a
<br/>href="http://docs.python.org/lib/module-
<br/>time.html">strftime</a> -- so I wrote a little helper for it:
<br/><a href="http://defcraft.org/~sri/hacks/pycmds/strftime_helper.py"&
<br/>gt;strftime_helper.py</a>, which uses <a href="http://defcraf
<br/>t.org/~sri/hacks/pycmds/pii.py">pii.py</a> (see previous
<br/>post, <a href="http://defcraft.blogspot.com/2007/06/extending-
<br/>pythons-interactive.html">Extending Python\'s Interactive
<br/>Interpreter</a>). Here is an interactive session with
<br/>it:\n</p>\n\n<pre
<br/>class="codebox">\n&gt;&gt;&gt; pd\n====================
<br/>===========================================================\n= pd help
<br/>=\n\nlocalet, localed, localedt - Locale Time, Locale Date, Locale
<br/>Date & Time\nhh24, hh, mm, ss, am, pm - 24-Hour, Hour, Minute,
<br/>Second, Am, Pm\ndow, dom, doy - Day Of {Week, Month,
<br/>& Year} respectively\nswoy, mwoy - Week Of Year
<br/>considering either Sunday or Monday\n
<br/>as first day of week\nyy, yyyy - Year without
<br/>century & Year with century\ntz -
<br/>Timezone\nmon..sun, monday..sunday - Weekday in Abbrev or Long
<br/>form\njan..dec, january..december - Month in Abbrev or Long form\n\n?
<br/>localet hh24:mm:ss, pm\n2007-06-22 19:36:53 formats to\n19:36:53
<br/>19:36:53, PM\n\'%X %H:%M:%S, %p\'\n? jun dom, yyyy (it\'s a
<br/>sunday)\n2007-06-22 19:38:51 formats to\nJun 22, 2007 (it\'s a
<br/>Friday)\n"%b %d, %Y (it\'s a %A)"\n? [ENTER] or
<br/>Control-D\n&gt;&gt;&gt; _\n"%b %d, %Y (it\'s a
<br/>%A)"\n\n</pre>\n\n\n<p><span>Things to
<br/>note:</span>\n<ul>\n<li>although the new format
<br/>directives are easier to remember (<span>dom</span> of day
<br/>of the month, any of <span>mon</span>,
<br/><span>tue</span>, <span>wed</span>, ...,
<br/><span>sun</span> for a short weekday name, any of
<br/><span>january</span>, <span>feburary</span>,
<br/>..., <span> december </span>for a long month name,
<br/><span>tz</span> for timezone), a help screen is printed
<br/>out each time you type
<br/><span>pd</span></li>\n<li>you end the
<br/>interactive session with <span>pd</span> by hitting
<br/>Ctrl-D or by passing it a empty line. The <span>_</span>
<br/>variable will be set to the result of pd: the actual format control
<br/>that strftime interprets\n</li>\n</ul>\n<p>Given
<br/>Python\'s friendliness to newbies, there should be a newbie.py
<br/>supplied with the standard distribution that "simplifies" many such
<br/>tasks for newbies...\n</p>'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[2].id | unicode" valign=top>id<br/><span class="type">unicode</span></td><td valign=top>u'tag:blogger.com,1999:blog-4259015877647291249.post-67250224534059181
<br/>05'</td>
<tr><td title="f.entries[2].link | unicode" valign=top>link<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/2007/06/strftime-helper.html' <a href="http://defcraft.blogspot.com/2007/06/strftime-helper.html">[link]</a></td>
<tr><td title="f.entries[2].links | list" valign=top>links<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].links[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].links[0].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/2007/06/strftime-helper.html' <a href="http://defcraft.blogspot.com/2007/06/strftime-helper.html">[link]</a></td>
<tr><td title="f.entries[2].links[0].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'alternate'</td>
<tr><td title="f.entries[2].links[0].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'strftime helper'</td>
<tr><td title="f.entries[2].links[0].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[2].links[1] | FeedParserDict" valign=top>[1]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].links[1].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/comment.g?blogID=4259015877647291249&post
<br/>ID=6725022453405918105' <a href="http://www.blogger.com/comment.g?blogID=4259015877647291249&postID=6725022453405918105">[link]</a></td>
<tr><td title="f.entries[2].links[1].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[2].links[1].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'0 Comments'</td>
<tr><td title="f.entries[2].links[1].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[2].links[2] | FeedParserDict" valign=top>[2]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].links[2].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/6725022453405918105/comments/defa
<br/>ult' <a href="http://defcraft.blogspot.com/feeds/6725022453405918105/comments/default">[link]</a></td>
<tr><td title="f.entries[2].links[2].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[2].links[2].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'Post Comments'</td>
<tr><td title="f.entries[2].links[2].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[2].links[3] | FeedParserDict" valign=top>[3]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].links[3].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/posts/default/6725022453405918105
<br/>' <a href="http://defcraft.blogspot.com/feeds/posts/default/6725022453405918105">[link]</a></td>
<tr><td title="f.entries[2].links[3].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'self'</td>
<tr><td title="f.entries[2].links[3].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[2].links[4] | FeedParserDict" valign=top>[4]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].links[4].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/feeds/4259015877647291249/posts/default/67250
<br/>22453405918105' <a href="http://www.blogger.com/feeds/4259015877647291249/posts/default/6725022453405918105">[link]</a></td>
<tr><td title="f.entries[2].links[4].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'edit'</td>
<tr><td title="f.entries[2].links[4].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[2].published | unicode" valign=top>published<br/><span class="type">unicode</span></td><td valign=top>u'2007-06-22T16:33:00.000-07:00'</td>
<tr><td title="f.entries[2].published_parsed | struct_time" valign=top>published_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 6, 22, 16, 33, 0, 4, 173, 0)</td>
<tr><td title="f.entries[2].subtitle | unicode" valign=top>subtitle<br/><span class="type">unicode</span></td><td valign=top>u'<p>I can never remember the syntax for <a
<br/>href="http://docs.python.org/lib/module-
<br/>time.html">strftime</a> -- so I wrote a little helper for it:
<br/><a href="http://defcraft.org/~sri/hacks/pycmds/strftime_helper.py"&
<br/>gt;strftime_helper.py</a>, which uses <a href="http://defcraf
<br/>t.org/~sri/hacks/pycmds/pii.py">pii.py</a> (see previous
<br/>post, <a href="http://defcraft.blogspot.com/2007/06/extending-
<br/>pythons-interactive.html">Extending Python\'s Interactive
<br/>Interpreter</a>). Here is an interactive session with
<br/>it:\n</p>\n\n<pre
<br/>class="codebox">\n&gt;&gt;&gt; pd\n====================
<br/>===========================================================\n= pd help
<br/>=\n\nlocalet, localed, localedt - Locale Time, Locale Date, Locale
<br/>Date & Time\nhh24, hh, mm, ss, am, pm - 24-Hour, Hour, Minute,
<br/>Second, Am, Pm\ndow, dom, doy - Day Of {Week, Month,
<br/>& Year} respectively\nswoy, mwoy - Week Of Year
<br/>considering either Sunday or Monday\n
<br/>as first day of week\nyy, yyyy - Year without
<br/>century & Year with century\ntz -
<br/>Timezone\nmon..sun, monday..sunday - Weekday in Abbrev or Long
<br/>form\njan..dec, january..december - Month in Abbrev or Long form\n\n?
<br/>localet hh24:mm:ss, pm\n2007-06-22 19:36:53 formats to\n19:36:53
<br/>19:36:53, PM\n\'%X %H:%M:%S, %p\'\n? jun dom, yyyy (it\'s a
<br/>sunday)\n2007-06-22 19:38:51 formats to\nJun 22, 2007 (it\'s a
<br/>Friday)\n"%b %d, %Y (it\'s a %A)"\n? [ENTER] or
<br/>Control-D\n&gt;&gt;&gt; _\n"%b %d, %Y (it\'s a
<br/>%A)"\n\n</pre>\n\n\n<p><span>Things to
<br/>note:</span>\n<ul>\n<li>although the new format
<br/>directives are easier to remember (<span>dom</span> of day
<br/>of the month, any of <span>mon</span>,
<br/><span>tue</span>, <span>wed</span>, ...,
<br/><span>sun</span> for a short weekday name, any of
<br/><span>january</span>, <span>feburary</span>,
<br/>..., <span> december </span>for a long month name,
<br/><span>tz</span> for timezone), a help screen is printed
<br/>out each time you type
<br/><span>pd</span></li>\n<li>you end the
<br/>interactive session with <span>pd</span> by hitting
<br/>Ctrl-D or by passing it a empty line. The <span>_</span>
<br/>variable will be set to the result of pd: the actual format control
<br/>that strftime interprets\n</li>\n</ul>\n<p>Given
<br/>Python\'s friendliness to newbies, there should be a newbie.py
<br/>supplied with the standard distribution that "simplifies" many such
<br/>tasks for newbies...\n</p>'</td>
<tr><td title="f.entries[2].tags | list" valign=top>tags<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].tags[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].tags[0].label | NoneType" valign=top>label<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[2].tags[0].scheme | unicode" valign=top>scheme<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/atom/ns#' <a href="http://www.blogger.com/atom/ns#">[link]</a></td>
<tr><td title="f.entries[2].tags[0].term | unicode" valign=top>term<br/><span class="type">unicode</span></td><td valign=top>u'python'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[2].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'strftime helper'</td>
<tr><td title="f.entries[2].title_detail | FeedParserDict" valign=top>title_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[2].title_detail.base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[2].title_detail.language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[2].title_detail.type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/plain'</td>
<tr><td title="f.entries[2].title_detail.value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'strftime helper'</td>
</table>
</td>
<tr><td title="f.entries[2].updated | unicode" valign=top>updated<br/><span class="type">unicode</span></td><td valign=top>u'2007-06-22T17:04:52.114-07:00'</td>
<tr><td title="f.entries[2].updated_parsed | struct_time" valign=top>updated_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 6, 22, 17, 4, 52, 4, 173, 0)</td>
</table>
</td>
<tr><td title="f.entries[3] | FeedParserDict" valign=top>[3]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].author | unicode" valign=top>author<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
<tr><td title="f.entries[3].author_detail | FeedParserDict" valign=top>author_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].author_detail.name | unicode" valign=top>name<br/><span class="type">unicode</span></td><td valign=top>u'sri'</td>
</table>
</td>
<tr><td title="f.entries[3].content | list" valign=top>content<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].content[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].content[0].base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[3].content[0].language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[3].content[0].type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/html'</td>
<tr><td title="f.entries[3].content[0].value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u'<p>[The code for all this is here: <a href="http://defcraft
<br/>.org/~sri/hacks/pii.py">pii.py</a>]\n</p>\n\n<p>&
<br/>lt;span>Update:</span> I\'ve only tried this under Linux; the
<br/>special commands doesn\'t seem to work under IDLE. Also, you need to
<br/>execfile pii.py, and not import it...</p>\n\n<p>I\'ve
<br/>written some code to help the interactive interpreter accept simple
<br/>commands. Commands like "ls" and those like "cd ~/tmp". Commands
<br/>without arguments -- simple commands -- can be Python objects. But for
<br/>those with arguments (special commands), we need a little magic: when
<br/>there is a space between a command and its argument ("cd ~/tmp"),
<br/>Python raises a SyntaxError. And the SyntaxError contains the
<br/>problematic line:\n</p>\n<pre
<br/>class="codebox">\n&gt;&gt;&gt; try:\n... eval(\'a
<br/>b\')\n... except SyntaxError, s:\n... print repr(s.text)\n...\n\'a
<br/>b\'\n</pre>\n\n<p>\nSo we simply "catch" the error and
<br/>extract the command that needs to be executed and execute it. The two
<br/>hook functions, <a href="http://docs.python.org/lib/module-
<br/>sys.html">sys.displayhook</a> and <a
<br/>href="http://docs.python.org/lib/module-
<br/>sys.html">sys.excepthook</a> are necessary to make this
<br/>happen. sys.displayhook is needed to display the simple commands
<br/>& sys.excepthook is needed to extract out the special commands and
<br/>run them. We replace both the hooks like so:\n</p>\n\n<pre
<br/>class="codebox">\ndef mydisplayhook(value):\n if value is not
<br/>None:\n # this\'ll only invoke simplecmds (or\n # cmds
<br/>that install themselves in\n # __builtins__) -- the specialcmds
<br/>are\n # executed in myexcepthook\n if isinstance(value,
<br/>SimpleCmd):\n out = value()\n if out:\n
<br/>print out\n else:\n __builtins__._ = value\n
<br/>print repr(value)\nsys.displayhook = mydisplayhook\n\ndef
<br/>myexcepthook(type, value, tb):\n # imports giving rise to
<br/>syntaxerror shouldn\'t\n # be considered a s cmds\n if type is
<br/>SyntaxError and value.filename==\'&lt;stdin&gt;\':\n #
<br/>might be a cmd of ours\n line = value.text\n # if user
<br/>is entering a multiline expr\n # (line[0]!=\' \') -- they
<br/>indent everything\n # other than first line -- don\'t
<br/>consider\n # that a cmd\n if line and line[0] not in \'
<br/>\\t\':\n cmd = value.text.split()[0]\n if cmd in
<br/>specialcmds:\n fn = specialcmds[cmd]\n
<br/>arg = line[len(cmd):]\n fn(arg)\n
<br/>return\n traceback.print_exception(type, value, tb)\nsys.excepthook
<br/>= myexcepthook\n</pre>\n\n<p>\nTwo
<br/>points:\n<ul><li>Special commands receive a single string
<br/>-- it is up to the command to split it into multiple arguments, if
<br/>necessary</li>\n<li>also, simple commands sit in the
<br/>__builtins__ namespace, so even if you replace it, you can get it back
<br/>by saying "del command-
<br/>name")</li>\n</ul>\n</p>\n<p>\nHere is the
<br/>whole thing. It sits in my <a href="http://docs.python.org/tut/node
<br/>4.html#SECTION004240000000000000000">pythonrc </a> file. You
<br/>can download it <a href="http://defcraft.org/~sri/hacks/pii.py">
<br/>here</a>.\n</p>\n\n<pre class="codebox">\nimport
<br/>sys, os, datetime, traceback, commands\n\n\nspecialcmds = {}\nallcmds
<br/>= []\n\nclass CmdMeta(type):\n def __init__(cls, name, bases,
<br/>dict):\n super(CmdMeta, cls).__init__(cls, name, bases, dict)\n
<br/>if name == \'Cmd\': return\n simplecmds = {}\n specials
<br/>= {}\n inst = cls()\n inst.install(specials,
<br/>simplecmds)\n for k in simplecmds:\n
<br/>setattr(__builtins__, k, SimpleCmd(simplecmds[k]))\n
<br/>allcmds.append((name, cls, inst, simplecmds, specials))\n
<br/>specialcmds.update(specials)\n\nclass Cmd(object):\n __metaclass__
<br/>= CmdMeta\n\nclass SimpleCmd(object):\n def __init__(self, func):\n
<br/>self.func = func\n def __call__(self):\n result =
<br/>self.func()\n if result:\n return str(result)\n\ndef
<br/>myexcepthook(type, value, tb):\n # imports giving rise to
<br/>syntaxerror shouldn\'t\n # be considered as cmds\n if type is
<br/>SyntaxError and value.filename==\'&lt;stdin&gt;\':\n #
<br/>might be a cmd of ours\n line = value.text\n # if user
<br/>is entering a multiline expr\n # (line[0]!=\' \') -- they
<br/>indent everything\n # other than first line -- don\'t
<br/>consider\n # that a cmd\n if line and line[0] not in \'
<br/>\\t\':\n cmd = value.text.split()[0]\n if cmd in
<br/>specialcmds:\n fn = specialcmds[cmd]\n
<br/>arg = line[len(cmd):]\n fn(arg)\n
<br/>return\n traceback.print_exception(type, value, tb)\nsys.excepthook
<br/>= myexcepthook\n\n\n# reloading this file shouldn\'t mess up prev
<br/>value\ntry:\n __builtins__._\nexcept AttributeError:\n
<br/>__builtins__._ = None\n\n\ndef mydisplayhook(value):\n if value is
<br/>not None:\n # this\'ll only invoke simplecmds (or\n #
<br/>cmds that install themselves in\n # __builtins__) -- the
<br/>specialcmds are\n # executed in myexcepthook\n if
<br/>isinstance(value, SimpleCmd):\n out = value()\n
<br/>if out:\n print out\n else:\n
<br/>__builtins__._ = value\n print repr(value)\nsys.displayhook
<br/>= mydisplayhook\n</pre>\n\n\n<p>And here are some
<br/>commands:</p>\n\n<pre class="codebox">\n#\n#
<br/>Commands:\n#\nclass MyCmds(Cmd):\n def install(self, specialcmds,
<br/>simplecmds):\n simplecmds[\'cmds\'] = self.allcmds\n def
<br/>doc(self, x):\n return getattr(x, \'__doc__\') or \'(no
<br/>doc)\'\n def allcmds(self):\n "prints out all the cmds"\n
<br/>print "all commands\\n", 65*\'=\'\n cmds = []\n for
<br/>(name, cls, inst, simplecmds, specialcmds) in allcmds:\n
<br/>simple = set(simplecmds.keys())\n specials =
<br/>set(specialcmds.keys())\n both = simple & specials\n
<br/>simple -= both\n specials -= both\n for k in
<br/>both:\n cmds.append((k, \'both\',
<br/>self.doc(simplecmds[k])))\n for k in specials:\n
<br/>cmds.append((k, \'special\', self.doc(specialcmds[k])))\n
<br/>for k in sorted(simple):\n cmds.append((k, \'simple\',
<br/>self.doc(simplecmds[k])))\n cmds.sort()\n for x in
<br/>cmds:\n print \'%-6s %-7s %s\' % x\n \n\nclass
<br/>MyReload(Cmd):\n def install(self, specialcmds, simplecmds):\n
<br/>simplecmds[\'rl\'] = self.doit\n def doit(self):\n "reloads
<br/>your pythonrc startup file"\n path =
<br/>os.environ.get(\'PYTHONSTARTUP\')\n if not path:\n
<br/>print "can\'t find your pythonstartup"\n else:\n
<br/>execfile(path, globals())\n\n\nclass MyPwd(Cmd):\n def
<br/>install(self, specialcmds, simplecmds):\n simplecmds[\'pwd\'] =
<br/>simplecmds[\'cwd\'] = self.getcwd\n def getcwd(self):\n
<br/>"prints the current working directory"\n return
<br/>os.getcwd()\n\nclass MyCD(Cmd):\n def __init__(self):\n
<br/>self.popdirs = []\n def install(self, specialcmds, simplecmds):\n
<br/>simplecmds[\'popd\'] = self.popd\n simplecmds[\'cd\'] =
<br/>specialcmds[\'cd\'] = self.cd\n def popd(self):\n "changes
<br/>back to directory from which we came"\n if self.popdirs:\n
<br/>self.cd(self.popdirs.pop(), False)\n else:\n print
<br/>\'nothing to pop back to\'\n def cd(self, dir=None, insert=True):\n
<br/>"changes to a given directory or user home; resolves ~ to user home"\n
<br/>if not dir:\n import user\n dir = user.home\n
<br/>dir = os.path.expanduser(dir.strip())\n if not
<br/>os.path.isdir(dir):\n print \'not a dir:\', dir\n
<br/>else:\n if insert:\n
<br/>self.popdirs.append(os.getcwd())\n os.chdir(dir)\n
<br/>print \'changed to\', dir\n\nclass MyHelp(Cmd):\n def install(self,
<br/>specialcmds, simplecmds):\n specialcmds[\'h\'] = self.help\n
<br/>def help(self, x):\n "prints help to a given thing"\n
<br/>help(x.strip())\n\nclass MyLs(Cmd):\n def install(self,
<br/>specialcmds, simplecmds):\n specialcmds[\'ls\'] = self.ls\n
<br/>simplecmds[\'ls\'] = self.ls\n def ls(self, dir=\'\'):\n
<br/>"""run the unix command \'ls -l\'"""\n dir =
<br/>os.path.expanduser(dir.strip() or \'.\')\n print
<br/>commands.getoutput(\'ls -l %s\' % dir)\n\n</pre>'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[3].id | unicode" valign=top>id<br/><span class="type">unicode</span></td><td valign=top>u'tag:blogger.com,1999:blog-4259015877647291249.post-50516228810267031
<br/>74'</td>
<tr><td title="f.entries[3].link | str" valign=top>link<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/2007/06/extending-pythons-
<br/>interactive.html' <a href="http://defcraft.blogspot.com/2007/06/extending-pythons-interactive.html">[link]</a></td>
<tr><td title="f.entries[3].links | list" valign=top>links<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].links[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].links[0].href | str" valign=top>href<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/2007/06/extending-pythons-
<br/>interactive.html' <a href="http://defcraft.blogspot.com/2007/06/extending-pythons-interactive.html">[link]</a></td>
<tr><td title="f.entries[3].links[0].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'alternate'</td>
<tr><td title="f.entries[3].links[0].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u"Extending Python's Interactive Interpreter"</td>
<tr><td title="f.entries[3].links[0].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[3].links[1] | FeedParserDict" valign=top>[1]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].links[1].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/comment.g?blogID=4259015877647291249&post
<br/>ID=5051622881026703174' <a href="http://www.blogger.com/comment.g?blogID=4259015877647291249&postID=5051622881026703174">[link]</a></td>
<tr><td title="f.entries[3].links[1].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[3].links[1].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'0 Comments'</td>
<tr><td title="f.entries[3].links[1].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'text/html'</td>
</table>
</td>
<tr><td title="f.entries[3].links[2] | FeedParserDict" valign=top>[2]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].links[2].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/5051622881026703174/comments/defa
<br/>ult' <a href="http://defcraft.blogspot.com/feeds/5051622881026703174/comments/default">[link]</a></td>
<tr><td title="f.entries[3].links[2].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'replies'</td>
<tr><td title="f.entries[3].links[2].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u'Post Comments'</td>
<tr><td title="f.entries[3].links[2].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[3].links[3] | FeedParserDict" valign=top>[3]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].links[3].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://defcraft.blogspot.com/feeds/posts/default/5051622881026703174
<br/>' <a href="http://defcraft.blogspot.com/feeds/posts/default/5051622881026703174">[link]</a></td>
<tr><td title="f.entries[3].links[3].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'self'</td>
<tr><td title="f.entries[3].links[3].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
<tr><td title="f.entries[3].links[4] | FeedParserDict" valign=top>[4]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].links[4].href | unicode" valign=top>href<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/feeds/4259015877647291249/posts/default/50516
<br/>22881026703174' <a href="http://www.blogger.com/feeds/4259015877647291249/posts/default/5051622881026703174">[link]</a></td>
<tr><td title="f.entries[3].links[4].rel | unicode" valign=top>rel<br/><span class="type">unicode</span></td><td valign=top>u'edit'</td>
<tr><td title="f.entries[3].links[4].type | unicode" valign=top>type<br/><span class="type">unicode</span></td><td valign=top>u'application/atom+xml'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[3].published | unicode" valign=top>published<br/><span class="type">unicode</span></td><td valign=top>u'2007-06-17T01:04:00.001-07:00'</td>
<tr><td title="f.entries[3].published_parsed | struct_time" valign=top>published_parsed<br/><span class="type">struct_time</span></td><td valign=top>(2007, 6, 17, 1, 4, 0, 6, 168, 0)</td>
<tr><td title="f.entries[3].subtitle | unicode" valign=top>subtitle<br/><span class="type">unicode</span></td><td valign=top>u'<p>[The code for all this is here: <a href="http://defcraft
<br/>.org/~sri/hacks/pii.py">pii.py</a>]\n</p>\n\n<p>&
<br/>lt;span>Update:</span> I\'ve only tried this under Linux; the
<br/>special commands doesn\'t seem to work under IDLE. Also, you need to
<br/>execfile pii.py, and not import it...</p>\n\n<p>I\'ve
<br/>written some code to help the interactive interpreter accept simple
<br/>commands. Commands like "ls" and those like "cd ~/tmp". Commands
<br/>without arguments -- simple commands -- can be Python objects. But for
<br/>those with arguments (special commands), we need a little magic: when
<br/>there is a space between a command and its argument ("cd ~/tmp"),
<br/>Python raises a SyntaxError. And the SyntaxError contains the
<br/>problematic line:\n</p>\n<pre
<br/>class="codebox">\n&gt;&gt;&gt; try:\n... eval(\'a
<br/>b\')\n... except SyntaxError, s:\n... print repr(s.text)\n...\n\'a
<br/>b\'\n</pre>\n\n<p>\nSo we simply "catch" the error and
<br/>extract the command that needs to be executed and execute it. The two
<br/>hook functions, <a href="http://docs.python.org/lib/module-
<br/>sys.html">sys.displayhook</a> and <a
<br/>href="http://docs.python.org/lib/module-
<br/>sys.html">sys.excepthook</a> are necessary to make this
<br/>happen. sys.displayhook is needed to display the simple commands
<br/>& sys.excepthook is needed to extract out the special commands and
<br/>run them. We replace both the hooks like so:\n</p>\n\n<pre
<br/>class="codebox">\ndef mydisplayhook(value):\n if value is not
<br/>None:\n # this\'ll only invoke simplecmds (or\n # cmds
<br/>that install themselves in\n # __builtins__) -- the specialcmds
<br/>are\n # executed in myexcepthook\n if isinstance(value,
<br/>SimpleCmd):\n out = value()\n if out:\n
<br/>print out\n else:\n __builtins__._ = value\n
<br/>print repr(value)\nsys.displayhook = mydisplayhook\n\ndef
<br/>myexcepthook(type, value, tb):\n # imports giving rise to
<br/>syntaxerror shouldn\'t\n # be considered a s cmds\n if type is
<br/>SyntaxError and value.filename==\'&lt;stdin&gt;\':\n #
<br/>might be a cmd of ours\n line = value.text\n # if user
<br/>is entering a multiline expr\n # (line[0]!=\' \') -- they
<br/>indent everything\n # other than first line -- don\'t
<br/>consider\n # that a cmd\n if line and line[0] not in \'
<br/>\\t\':\n cmd = value.text.split()[0]\n if cmd in
<br/>specialcmds:\n fn = specialcmds[cmd]\n
<br/>arg = line[len(cmd):]\n fn(arg)\n
<br/>return\n traceback.print_exception(type, value, tb)\nsys.excepthook
<br/>= myexcepthook\n</pre>\n\n<p>\nTwo
<br/>points:\n<ul><li>Special commands receive a single string
<br/>-- it is up to the command to split it into multiple arguments, if
<br/>necessary</li>\n<li>also, simple commands sit in the
<br/>__builtins__ namespace, so even if you replace it, you can get it back
<br/>by saying "del command-
<br/>name")</li>\n</ul>\n</p>\n<p>\nHere is the
<br/>whole thing. It sits in my <a href="http://docs.python.org/tut/node
<br/>4.html#SECTION004240000000000000000">pythonrc </a> file. You
<br/>can download it <a href="http://defcraft.org/~sri/hacks/pii.py">
<br/>here</a>.\n</p>\n\n<pre class="codebox">\nimport
<br/>sys, os, datetime, traceback, commands\n\n\nspecialcmds = {}\nallcmds
<br/>= []\n\nclass CmdMeta(type):\n def __init__(cls, name, bases,
<br/>dict):\n super(CmdMeta, cls).__init__(cls, name, bases, dict)\n
<br/>if name == \'Cmd\': return\n simplecmds = {}\n specials
<br/>= {}\n inst = cls()\n inst.install(specials,
<br/>simplecmds)\n for k in simplecmds:\n
<br/>setattr(__builtins__, k, SimpleCmd(simplecmds[k]))\n
<br/>allcmds.append((name, cls, inst, simplecmds, specials))\n
<br/>specialcmds.update(specials)\n\nclass Cmd(object):\n __metaclass__
<br/>= CmdMeta\n\nclass SimpleCmd(object):\n def __init__(self, func):\n
<br/>self.func = func\n def __call__(self):\n result =
<br/>self.func()\n if result:\n return str(result)\n\ndef
<br/>myexcepthook(type, value, tb):\n # imports giving rise to
<br/>syntaxerror shouldn\'t\n # be considered as cmds\n if type is
<br/>SyntaxError and value.filename==\'&lt;stdin&gt;\':\n #
<br/>might be a cmd of ours\n line = value.text\n # if user
<br/>is entering a multiline expr\n # (line[0]!=\' \') -- they
<br/>indent everything\n # other than first line -- don\'t
<br/>consider\n # that a cmd\n if line and line[0] not in \'
<br/>\\t\':\n cmd = value.text.split()[0]\n if cmd in
<br/>specialcmds:\n fn = specialcmds[cmd]\n
<br/>arg = line[len(cmd):]\n fn(arg)\n
<br/>return\n traceback.print_exception(type, value, tb)\nsys.excepthook
<br/>= myexcepthook\n\n\n# reloading this file shouldn\'t mess up prev
<br/>value\ntry:\n __builtins__._\nexcept AttributeError:\n
<br/>__builtins__._ = None\n\n\ndef mydisplayhook(value):\n if value is
<br/>not None:\n # this\'ll only invoke simplecmds (or\n #
<br/>cmds that install themselves in\n # __builtins__) -- the
<br/>specialcmds are\n # executed in myexcepthook\n if
<br/>isinstance(value, SimpleCmd):\n out = value()\n
<br/>if out:\n print out\n else:\n
<br/>__builtins__._ = value\n print repr(value)\nsys.displayhook
<br/>= mydisplayhook\n</pre>\n\n\n<p>And here are some
<br/>commands:</p>\n\n<pre class="codebox">\n#\n#
<br/>Commands:\n#\nclass MyCmds(Cmd):\n def install(self, specialcmds,
<br/>simplecmds):\n simplecmds[\'cmds\'] = self.allcmds\n def
<br/>doc(self, x):\n return getattr(x, \'__doc__\') or \'(no
<br/>doc)\'\n def allcmds(self):\n "prints out all the cmds"\n
<br/>print "all commands\\n", 65*\'=\'\n cmds = []\n for
<br/>(name, cls, inst, simplecmds, specialcmds) in allcmds:\n
<br/>simple = set(simplecmds.keys())\n specials =
<br/>set(specialcmds.keys())\n both = simple & specials\n
<br/>simple -= both\n specials -= both\n for k in
<br/>both:\n cmds.append((k, \'both\',
<br/>self.doc(simplecmds[k])))\n for k in specials:\n
<br/>cmds.append((k, \'special\', self.doc(specialcmds[k])))\n
<br/>for k in sorted(simple):\n cmds.append((k, \'simple\',
<br/>self.doc(simplecmds[k])))\n cmds.sort()\n for x in
<br/>cmds:\n print \'%-6s %-7s %s\' % x\n \n\nclass
<br/>MyReload(Cmd):\n def install(self, specialcmds, simplecmds):\n
<br/>simplecmds[\'rl\'] = self.doit\n def doit(self):\n "reloads
<br/>your pythonrc startup file"\n path =
<br/>os.environ.get(\'PYTHONSTARTUP\')\n if not path:\n
<br/>print "can\'t find your pythonstartup"\n else:\n
<br/>execfile(path, globals())\n\n\nclass MyPwd(Cmd):\n def
<br/>install(self, specialcmds, simplecmds):\n simplecmds[\'pwd\'] =
<br/>simplecmds[\'cwd\'] = self.getcwd\n def getcwd(self):\n
<br/>"prints the current working directory"\n return
<br/>os.getcwd()\n\nclass MyCD(Cmd):\n def __init__(self):\n
<br/>self.popdirs = []\n def install(self, specialcmds, simplecmds):\n
<br/>simplecmds[\'popd\'] = self.popd\n simplecmds[\'cd\'] =
<br/>specialcmds[\'cd\'] = self.cd\n def popd(self):\n "changes
<br/>back to directory from which we came"\n if self.popdirs:\n
<br/>self.cd(self.popdirs.pop(), False)\n else:\n print
<br/>\'nothing to pop back to\'\n def cd(self, dir=None, insert=True):\n
<br/>"changes to a given directory or user home; resolves ~ to user home"\n
<br/>if not dir:\n import user\n dir = user.home\n
<br/>dir = os.path.expanduser(dir.strip())\n if not
<br/>os.path.isdir(dir):\n print \'not a dir:\', dir\n
<br/>else:\n if insert:\n
<br/>self.popdirs.append(os.getcwd())\n os.chdir(dir)\n
<br/>print \'changed to\', dir\n\nclass MyHelp(Cmd):\n def install(self,
<br/>specialcmds, simplecmds):\n specialcmds[\'h\'] = self.help\n
<br/>def help(self, x):\n "prints help to a given thing"\n
<br/>help(x.strip())\n\nclass MyLs(Cmd):\n def install(self,
<br/>specialcmds, simplecmds):\n specialcmds[\'ls\'] = self.ls\n
<br/>simplecmds[\'ls\'] = self.ls\n def ls(self, dir=\'\'):\n
<br/>"""run the unix command \'ls -l\'"""\n dir =
<br/>os.path.expanduser(dir.strip() or \'.\')\n print
<br/>commands.getoutput(\'ls -l %s\' % dir)\n\n</pre>'</td>
<tr><td title="f.entries[3].tags | list" valign=top>tags<br/><span class="type">list</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].tags[0] | FeedParserDict" valign=top>[0]<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].tags[0].label | NoneType" valign=top>label<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[3].tags[0].scheme | unicode" valign=top>scheme<br/><span class="type">unicode</span></td><td valign=top>u'http://www.blogger.com/atom/ns#' <a href="http://www.blogger.com/atom/ns#">[link]</a></td>
<tr><td title="f.entries[3].tags[0].term | unicode" valign=top>term<br/><span class="type">unicode</span></td><td valign=top>u'python'</td>
</table>
</td>
</table>
</td>
<tr><td title="f.entries[3].title | unicode" valign=top>title<br/><span class="type">unicode</span></td><td valign=top>u"Extending Python's Interactive Interpreter"</td>
<tr><td title="f.entries[3].title_detail | FeedParserDict" valign=top>title_detail<br/><span class="type">FeedParserDict</span></td><td valign=top>
<table cellspacing=2 cellpadding=2>
<tr><td title="f.entries[3].title_detail.base | str" valign=top>base<br/><span class="type">str</span></td><td valign=top>'http://defcraft.blogspot.com/feeds/posts/default' <a href="http://defcraft.blogspot.com/feeds/posts/default">[link]</a></td>
<tr><td title="f.entries[3].title_detail.language | NoneType" valign=top>language<br/><span class="type">NoneType</span></td><td valign=top>None</td>
<tr><td title="f.entries[3].title_detail.type | str" valign=top>type<br/><span class="type">str</span></td><td valign=top>'text/plain'</td>
<tr><td title="f.entries[3].title_detail.value | unicode" valign=top>value<br/><span class="type">unicode</span></td><td valign=top>u"Extending Python's Interactive Interpreter"</td>
</table>