The Art of Pickling: Binary vs Ascii difficulties

Bengt Richter bokr at oz.net
Fri Oct 15 02:44:24 CEST 2004


On Thu, 14 Oct 2004 16:38:25 -0500, John Hunter <jdhunter at ace.bsd.uchicago.edu> wrote:

>>>>>> "Andrew" == Andrew Dalke <adalke at mindspring.com> writes:
>
>    Andrew> Standards wonk that I am, I was curious about this.  I've
>
>Well, if you are a standards wonk and emacs user, you might have fun
>with this little bit of python and emacs code.  If you place rfc.py in
>your PATH
>
>#!/usr/bin/env python
># Print an RFC indicated by a command line arg to stdout
>#   > rfc.py 822
>
>import urllib, sys
>
>try: n = int(sys.argv[1])
>except:
>    print 'Example usage: %s 822' % sys.argv[0] 
>    sys.exit(1)
>
>print urllib.urlopen('http://www.ietf.org/rfc/rfc%d.txt' % n).read()
>
>
>and add this function to your .emacs
>
>;;** RFC
>(defun rfc (num)
>  "Insert RFC indicated by num into buffer *RFC<num>*"
>  (interactive "sRFC: ")
>  (shell-command 
>    (concat "rfc.py " num)
>    (concat "*RFC" num "*")))
>
>
>You can get rfc's in your emacs buffer by doing
>
>  M-x rfc ENTER 20 ENTER
>
>And now back you our regularly scheduled work day.
>
Thanks. For win32 users with gvim I've modified it a little ...

---< vrfc.py >---------------------------------------
# vrfc.py
# to use in gvim on win32, put this file somewhere
# and put a vrfc.cmd file in one of your %PATH% directories
# (e.g. c:\util here) running python with a full path to this
# script (vrfc.py), e.g.,
# +--< vrfc.cmd >------------+
# |@python c:\util\vrfc.py %1|
# +--------------------------+
# (This cmd file is necessary on NT4 and some other windows platforms
# in order for the output to be pipe-able back into gvim (or anytwhere else)).
# Then you can insert an rfc into your current gvim editing using
# :r!vrfc n
# where n is the rfc number
# Form form feeds are converted to underline separators 78 chars wide
# and \r's if any are stripped for normalized output, in case.
#
import urllib, sys
try: n = int(sys.argv[1])
except:
    print 'Example usage: python %s 822' % sys.argv[0] 
    sys.exit(1)
s = urllib.urlopen('http://www.ietf.org/rfc/rfc%d.txt' % n).read()
s = s.replace('\r','')
s = s.replace('\x0c','_'*78+'\n')
sys.stdout.write(s)
sys.stdout.close()
--------------------------------------------------------
;-)

Regards,
Bengt Richter



More information about the Python-list mailing list