Kaydet (Commit) 7a2dba2a authored tarafından Guido van Rossum's avatar Guido van Rossum

* ext.tex: documentation for extending, reference counts, and embedding

  (formerly ../misc/{EXTENDING,REFCNT,EMBEDDING}).  Also affects Makefile.
* text2latex.py: script to do part of the conversion from an plain ASCI
  text file (in my particular style) to LaTeX.
  (Chapter/section/subsection headers, and verbatim sections.)
* partparse.py, texipre.dat, fix.el, Makefile: Minor cleanup of latex ->
  info conversion process (at least it works again, and with less
  debugging output).  Removed fix.sh.
* lib1.tex (section{Built-in Functions}): adapt description of str() and
  repr() to new situation.
* lib3.tex (Module os): added exec*() variants.
* lib3.tex (Module posix): added execve().
* lib2.tex (Module array): documented reality; remove typecode and
itemsize, add byteswap, rename read/write to fromfile/tofile, and
re-alphabetized.
* lib1.tex (Built-in Functions): renamed bagof() to filter().
üst c6004117
......@@ -26,6 +26,14 @@ lib:
latex lib
dvips lib >lib.ps
ext:
touch ext.ind
latex ext
./fix_hack ext.idx
makeindex ext
latex ext
dvips ext >ext.ps
qua:
latex qua
bibtex qua
......@@ -33,19 +41,27 @@ qua:
latex qua
dvips qua >qua.ps
libinfo:
@echo This may take a while...
python -c 'import partparse; partparse.main()' lib[1-5].tex
sh fix.sh
lib.texi: lib1.tex lib2.tex lib3.tex lib4.tex lib5.tex texipre.dat texipost.dat
python partparse.py -o @lib.texi lib[1-5].tex
mv @lib.texi lib.texi
.PRECIOUS: lib.texi
python-lib.info: lib.texi
emacs -batch -l fix.el -f save-buffer -kill
makeinfo +footnote-style end +fill-column 72 +paragraph-indent 0 \
lib.texi
lib.info: python-lib.info
# This target is very local to CWI... (first make libinfo)
libwww:
texi2html -d @out.texi /usr/local/ftp.cwi.nl/pub/www/texinfo/python
# This target is very local to CWI...
libwww: lib.texi
texi2html -d lib.texi /usr/local/ftp.cwi.nl/pub/www/texinfo/python
clean:
rm -f @* *~ *.aux *.idx *.ilg *.ind *.log *.toc *.blg *.bbl *.pyc
# Sources: .tex, .bib, .sty
# Useful results: .dvi, .ps
# Useful results: .dvi, .ps, .texi, .info
clobber: clean
rm -f *.dvi *.ps *.info *.info-[0-9]*
rm -f *.dvi *.ps *.texi *.info *.info-[0-9]*
This diff is collapsed.
This diff is collapsed.
; load the new texinfo package (2.xx) if not installed by default
(setq load-path
(cons "/ufs/jh/lib/emacs/texinfo-2.14" load-path))
(find-file "@out.texi")
; (setq load-path
; (cons "/ufs/jh/lib/emacs/texinfo-2.14" load-path))
(find-file "lib.texi")
(texinfo-all-menus-update t)
(texinfo-all-menus-update t)
......@@ -77,8 +77,7 @@ the language, see the @cite{Python Tutorial}. The @cite{Python
Reference Manual} gives a more formal definition of the language.
(These manuals are not yet available in INFO or Texinfo format.)
This version corresponds roughly to Python version 0.9.9 (yet to be
released).
This version corresponds roughly to Python version 1.0 (yet to be released).
@end ifinfo
......
......@@ -14,7 +14,7 @@
# -jh
import sys, string, regex
import sys, string, regex, getopt, os
# Different parse modes for phase 1
MODE_REGULAR = 0
......@@ -270,21 +270,21 @@ comment_stopcodes = [CC_ENDLINE]
# gather all characters together, specified by a list of catcodes
def code2string(cc, codelist):
print 'code2string: codelist = ' + pcl(codelist),
##print 'code2string: codelist = ' + pcl(codelist),
result = ''
for catagory in codelist:
if cc[catagory]:
result = result + cc[catagory]
print 'result = ' + `result`
for category in codelist:
if cc[category]:
result = result + cc[category]
##print 'result = ' + `result`
return result
# automatically generate all characters of catcode other, being the
# complement set in the ASCII range (128 characters)
def make_other_codes(cc):
otherchars = range(128) # could be made 256, no problem
for catagory in all_but_other_codes:
if cc[catagory]:
for c in cc[catagory]:
otherchars = range(256) # could be made 256, no problem
for category in all_but_other_codes:
if cc[category]:
for c in cc[category]:
otherchars[ord(c)] = None
result = ''
for i in otherchars:
......@@ -294,12 +294,12 @@ def make_other_codes(cc):
# catcode dump (which characters have which catcodes).
def dump_cc(name, cc):
print '\t' + name
print '=' * (8+len(name))
##print '\t' + name
##print '=' * (8+len(name))
if len(cc) != 16:
raise TypeError, 'cc not good cat class'
for i in range(16):
print pc(i) + '\t' + `cc[i]`
## for i in range(16):
## print pc(i) + '\t' + `cc[i]`
# In the beginning,....
......@@ -707,7 +707,7 @@ def handlecs(buf, where, curpmode, lvl, result, end):
if x2 == end:
raise error, 'premature end of command.' + lle(lvl, buf, where)
delimchar = buf[x2]
print 'VERB: delimchar ' + `delimchar`
##print 'VERB: delimchar ' + `delimchar`
pos = regex.compile(un_re(delimchar)).search(buf, x2 + 1)
if pos < 0:
raise error, 'end of \'verb\' argument (' + \
......@@ -877,7 +877,7 @@ for_texi = ('emph', 'var', 'strong', 'code', 'kbd', 'key', 'dfn', 'samp', \
# try to remove macros and return flat text
def flattext(buf, pp):
pp = crcopy(pp)
print '---> FLATTEXT ' + `pp`
##print '---> FLATTEXT ' + `pp`
wobj = Wobj().init()
i, length = 0, len(pp)
......@@ -942,7 +942,7 @@ def flattext(buf, pp):
pass
dumpit(buf, wobj.write, pp)
print 'FLATTEXT: RETURNING ' + `wobj.data`
##print 'FLATTEXT: RETURNING ' + `wobj.data`
return wobj.data
# try to generate node names (a bit shorter than the chapter title)
......@@ -950,7 +950,7 @@ def flattext(buf, pp):
def invent_node_names(text):
words = string.split(text)
print 'WORDS ' + `words`
##print 'WORDS ' + `words`
if len(words) == 2 \
and string.lower(words[0]) == 'built-in' \
......@@ -1268,7 +1268,7 @@ def changeit(buf, pp):
elif ch.chtype == chunk_type(IF):
# \if...
flag, negate, data = ch.data
print 'IF: flag, negate = ' + `flag, negate`
##print 'IF: flag, negate = ' + `flag, negate`
if flag not in flags.keys():
raise error, 'unknown flag ' + `flag`
......@@ -1533,7 +1533,7 @@ def changeit(buf, pp):
('exception', 'object'):
command = 'vindex'
else:
print 'WARNING: can\'t catagorize ' + `idxsi` + ' for \'ttindex\' command'
print 'WARNING: can\'t categorize ' + `idxsi` + ' for \'ttindex\' command'
command = 'cindex'
if not cat_class:
......@@ -1670,7 +1670,7 @@ def changeit(buf, pp):
text = flattext(buf, cp1)
if text[-1] == '.':
text = text[:-1]
print 'FLATTEXT:', `text`
## print 'FLATTEXT:', `text`
if text in hist.nodenames:
print 'WARNING: node name ' + `text` + ' already used'
out.doublenodes.append(text)
......@@ -2058,7 +2058,7 @@ def dumpit(buf, wm, pp):
wm('\n')
elif ch.chtype == chunk_type(COMMENT):
print 'COMMENT: previous chunk =', pp[i-2]
## print 'COMMENT: previous chunk =', pp[i-2]
if pp[i-2].chtype == chunk_type(PLAIN):
print 'PLAINTEXT =', `s(buf, pp[i-2].data)`
if s(buf, ch.data) and \
......@@ -2083,55 +2083,47 @@ def dumpit(buf, wm, pp):
from posix import popen
def main():
buf = open(sys.argv[1], 'r').read()
restargs = sys.argv[2:]
w, pp = parseit(buf)
startchange()
## try:
while 1:
outfile = None
headerfile = 'texipre.dat'
trailerfile = 'texipost.dat'
try:
opts, args = getopt.getopt(sys.argv[1:], 'o:h:t:')
except getopt.error:
args = []
if not args:
print 'usage: partparse [-o outfile] [-h headerfile]',
print '[-t trailerfile] file ...'
sys.exit(2)
for opt, arg in opts:
if opt == '-o': outfile = arg
if opt == '-h': headerfile = arg
if opt == '-t': trailerfile = arg
if not outfile:
root, ext = os.path.splitext(args[0])
outfile = root + '.texi'
if outfile in args:
print 'will not overwrite input file', outfile
sys.exit(2)
outf = open(outfile, 'w')
outf.write(open(headerfile, 'r').read())
for file in args:
if len(args) > 1: print '='*20, file, '='*20
buf = open(file, 'r').read()
w, pp = parseit(buf)
startchange()
changeit(buf, pp)
## pass
break
## finally:
while 1:
outf = open('@out.texi', 'w')
preamble = open('texipre.dat', 'r')
while 1:
l = preamble.readline()
if not l:
preamble.close()
break
outf.write(l)
dumpit(buf, outf.write, pp)
while restargs:
del buf, pp
buf = open(restargs[0], 'r').read()
del restargs[0]
w, pp = parseit(buf)
startchange()
changeit(buf, pp)
dumpit(buf, outf.write, pp)
outf.write(open(trailerfile, 'r').read())
postamble = open('texipost.dat', 'r')
while 1:
l = postamble.readline()
if not l:
postamble.close()
break
outf.write(l)
outf.close()
outf.close()
## pass
break
main()
......@@ -583,10 +583,12 @@ class, then \verb\x[i]\ is equivalent to \verb\x.__getitem__(i)\.
(The reverse is not true --- if \verb\x\ is a list object,
\verb\x.__getitem__(i)\ is not equivalent to \verb\x[i]\.)
Except for \verb\__repr__\ and \verb\__cmp__\, attempts to execute an
Except for \verb\__repr__\, \verb\__str__\ and \verb\__cmp__\,
attempts to execute an
operation raise an exception when no appropriate method is defined.
For \verb\__repr__\ and \verb\__cmp__\, the traditional
interpretations are used in this case.
For \verb\__str__\, the \verb\__repr__\ method is used.
\subsection{Special methods for any type}
......@@ -612,8 +614,12 @@ reference is deleted. Also note that it is not guaranteed that
the interpreter exits.
\item[\tt __repr__(self)]
Called by the \verb\print\ statement and conversions (reverse quotes) to
compute the string representation of an object.
Called by the \verb\repr()\ built-in function and by conversions
(reverse quotes) to compute the string representation of an object.
\item[\tt __str__(self)]
Called by the \verb\str()\ built-in function and by the \verb\print\
statement compute the string representation of an object.
\item[\tt __cmp__(self, other)]
Called by all comparison operations. Should return -1 if
......
......@@ -583,10 +583,12 @@ class, then \verb\x[i]\ is equivalent to \verb\x.__getitem__(i)\.
(The reverse is not true --- if \verb\x\ is a list object,
\verb\x.__getitem__(i)\ is not equivalent to \verb\x[i]\.)
Except for \verb\__repr__\ and \verb\__cmp__\, attempts to execute an
Except for \verb\__repr__\, \verb\__str__\ and \verb\__cmp__\,
attempts to execute an
operation raise an exception when no appropriate method is defined.
For \verb\__repr__\ and \verb\__cmp__\, the traditional
interpretations are used in this case.
For \verb\__str__\, the \verb\__repr__\ method is used.
\subsection{Special methods for any type}
......@@ -612,8 +614,12 @@ reference is deleted. Also note that it is not guaranteed that
the interpreter exits.
\item[\tt __repr__(self)]
Called by the \verb\print\ statement and conversions (reverse quotes) to
compute the string representation of an object.
Called by the \verb\repr()\ built-in function and by conversions
(reverse quotes) to compute the string representation of an object.
\item[\tt __str__(self)]
Called by the \verb\str()\ built-in function and by the \verb\print\
statement compute the string representation of an object.
\item[\tt __cmp__(self, other)]
Called by all comparison operations. Should return -1 if
......
......@@ -77,8 +77,7 @@ the language, see the @cite{Python Tutorial}. The @cite{Python
Reference Manual} gives a more formal definition of the language.
(These manuals are not yet available in INFO or Texinfo format.)
This version corresponds roughly to Python version 0.9.9 (yet to be
released).
This version corresponds roughly to Python version 1.0 (yet to be released).
@end ifinfo
......
import os
import sys
import regex
import string
import getopt
def main():
process(sys.stdin, sys.stdout)
dashes = regex.compile('^-+[ \t]*$')
equals = regex.compile('^=+[ \t]*$')
stars = regex.compile('^\*+[ \t]*$')
blank = regex.compile('^[ \t]*$')
indented = regex.compile('^\( *\t\| \)[ \t]*[^ \t]')
def process(fi, fo):
inverbatim = 0
line = '\n'
nextline = fi.readline()
while nextline:
prevline = line
line = nextline
nextline = fi.readline()
fmt = None
if dashes.match(nextline) >= 0:
fmt = '\\subsection{%s}\n'
elif equals.match(nextline) >= 0:
fmt = '\\section{%s}\n'
elif stars.match(nextline) >= 0:
fmt = '\\chapter{%s}\n'
if fmt:
nextline = '\n'
line = fmt % string.strip(line)
elif inverbatim:
if blank.match(line) >= 0 and \
indented.match(nextline) < 0:
inverbatim = 0
fo.write('\\end{verbatim}\n')
else:
if indented.match(line) >= 0 and \
blank.match(prevline) >= 0:
inverbatim = 1
fo.write('\\begin{verbatim}\n')
if inverbatim:
line = string.expandtabs(line, 4)
fo.write(line)
#main()
process(open('ext.tex', 'r'), sys.stdout)
; load the new texinfo package (2.xx) if not installed by default
(setq load-path
(cons "/ufs/jh/lib/emacs/texinfo-2.14" load-path))
(find-file "@out.texi")
; (setq load-path
; (cons "/ufs/jh/lib/emacs/texinfo-2.14" load-path))
(find-file "lib.texi")
(texinfo-all-menus-update t)
(texinfo-all-menus-update t)
......@@ -14,7 +14,7 @@
# -jh
import sys, string, regex
import sys, string, regex, getopt, os
# Different parse modes for phase 1
MODE_REGULAR = 0
......@@ -270,21 +270,21 @@ comment_stopcodes = [CC_ENDLINE]
# gather all characters together, specified by a list of catcodes
def code2string(cc, codelist):
print 'code2string: codelist = ' + pcl(codelist),
##print 'code2string: codelist = ' + pcl(codelist),
result = ''
for catagory in codelist:
if cc[catagory]:
result = result + cc[catagory]
print 'result = ' + `result`
for category in codelist:
if cc[category]:
result = result + cc[category]
##print 'result = ' + `result`
return result
# automatically generate all characters of catcode other, being the
# complement set in the ASCII range (128 characters)
def make_other_codes(cc):
otherchars = range(128) # could be made 256, no problem
for catagory in all_but_other_codes:
if cc[catagory]:
for c in cc[catagory]:
otherchars = range(256) # could be made 256, no problem
for category in all_but_other_codes:
if cc[category]:
for c in cc[category]:
otherchars[ord(c)] = None
result = ''
for i in otherchars:
......@@ -294,12 +294,12 @@ def make_other_codes(cc):
# catcode dump (which characters have which catcodes).
def dump_cc(name, cc):
print '\t' + name
print '=' * (8+len(name))
##print '\t' + name
##print '=' * (8+len(name))
if len(cc) != 16:
raise TypeError, 'cc not good cat class'
for i in range(16):
print pc(i) + '\t' + `cc[i]`
## for i in range(16):
## print pc(i) + '\t' + `cc[i]`
# In the beginning,....
......@@ -707,7 +707,7 @@ def handlecs(buf, where, curpmode, lvl, result, end):
if x2 == end:
raise error, 'premature end of command.' + lle(lvl, buf, where)
delimchar = buf[x2]
print 'VERB: delimchar ' + `delimchar`
##print 'VERB: delimchar ' + `delimchar`
pos = regex.compile(un_re(delimchar)).search(buf, x2 + 1)
if pos < 0:
raise error, 'end of \'verb\' argument (' + \
......@@ -877,7 +877,7 @@ for_texi = ('emph', 'var', 'strong', 'code', 'kbd', 'key', 'dfn', 'samp', \
# try to remove macros and return flat text
def flattext(buf, pp):
pp = crcopy(pp)
print '---> FLATTEXT ' + `pp`
##print '---> FLATTEXT ' + `pp`
wobj = Wobj().init()
i, length = 0, len(pp)
......@@ -942,7 +942,7 @@ def flattext(buf, pp):
pass
dumpit(buf, wobj.write, pp)
print 'FLATTEXT: RETURNING ' + `wobj.data`
##print 'FLATTEXT: RETURNING ' + `wobj.data`
return wobj.data
# try to generate node names (a bit shorter than the chapter title)
......@@ -950,7 +950,7 @@ def flattext(buf, pp):
def invent_node_names(text):
words = string.split(text)
print 'WORDS ' + `words`
##print 'WORDS ' + `words`
if len(words) == 2 \
and string.lower(words[0]) == 'built-in' \
......@@ -1268,7 +1268,7 @@ def changeit(buf, pp):
elif ch.chtype == chunk_type(IF):
# \if...
flag, negate, data = ch.data
print 'IF: flag, negate = ' + `flag, negate`
##print 'IF: flag, negate = ' + `flag, negate`
if flag not in flags.keys():
raise error, 'unknown flag ' + `flag`
......@@ -1533,7 +1533,7 @@ def changeit(buf, pp):
('exception', 'object'):
command = 'vindex'
else:
print 'WARNING: can\'t catagorize ' + `idxsi` + ' for \'ttindex\' command'
print 'WARNING: can\'t categorize ' + `idxsi` + ' for \'ttindex\' command'
command = 'cindex'
if not cat_class:
......@@ -1670,7 +1670,7 @@ def changeit(buf, pp):
text = flattext(buf, cp1)
if text[-1] == '.':
text = text[:-1]
print 'FLATTEXT:', `text`
## print 'FLATTEXT:', `text`
if text in hist.nodenames:
print 'WARNING: node name ' + `text` + ' already used'
out.doublenodes.append(text)
......@@ -2058,7 +2058,7 @@ def dumpit(buf, wm, pp):
wm('\n')
elif ch.chtype == chunk_type(COMMENT):
print 'COMMENT: previous chunk =', pp[i-2]
## print 'COMMENT: previous chunk =', pp[i-2]
if pp[i-2].chtype == chunk_type(PLAIN):
print 'PLAINTEXT =', `s(buf, pp[i-2].data)`
if s(buf, ch.data) and \
......@@ -2083,55 +2083,47 @@ def dumpit(buf, wm, pp):
from posix import popen
def main():
buf = open(sys.argv[1], 'r').read()
restargs = sys.argv[2:]
w, pp = parseit(buf)
startchange()
## try:
while 1:
outfile = None
headerfile = 'texipre.dat'
trailerfile = 'texipost.dat'
try:
opts, args = getopt.getopt(sys.argv[1:], 'o:h:t:')
except getopt.error:
args = []
if not args:
print 'usage: partparse [-o outfile] [-h headerfile]',
print '[-t trailerfile] file ...'
sys.exit(2)
for opt, arg in opts:
if opt == '-o': outfile = arg
if opt == '-h': headerfile = arg
if opt == '-t': trailerfile = arg
if not outfile:
root, ext = os.path.splitext(args[0])
outfile = root + '.texi'
if outfile in args:
print 'will not overwrite input file', outfile
sys.exit(2)
outf = open(outfile, 'w')
outf.write(open(headerfile, 'r').read())
for file in args:
if len(args) > 1: print '='*20, file, '='*20
buf = open(file, 'r').read()
w, pp = parseit(buf)
startchange()
changeit(buf, pp)
## pass
break
## finally:
while 1:
outf = open('@out.texi', 'w')
preamble = open('texipre.dat', 'r')
while 1:
l = preamble.readline()
if not l:
preamble.close()
break
outf.write(l)
dumpit(buf, outf.write, pp)
while restargs:
del buf, pp
buf = open(restargs[0], 'r').read()
del restargs[0]
w, pp = parseit(buf)
startchange()
changeit(buf, pp)
dumpit(buf, outf.write, pp)
outf.write(open(trailerfile, 'r').read())
postamble = open('texipost.dat', 'r')
while 1:
l = postamble.readline()
if not l:
postamble.close()
break
outf.write(l)
outf.close()
outf.close()
## pass
break
main()
import os
import sys
import regex
import string
import getopt
def main():
process(sys.stdin, sys.stdout)
dashes = regex.compile('^-+[ \t]*$')
equals = regex.compile('^=+[ \t]*$')
stars = regex.compile('^\*+[ \t]*$')
blank = regex.compile('^[ \t]*$')
indented = regex.compile('^\( *\t\| \)[ \t]*[^ \t]')
def process(fi, fo):
inverbatim = 0
line = '\n'
nextline = fi.readline()
while nextline:
prevline = line
line = nextline
nextline = fi.readline()
fmt = None
if dashes.match(nextline) >= 0:
fmt = '\\subsection{%s}\n'
elif equals.match(nextline) >= 0:
fmt = '\\section{%s}\n'
elif stars.match(nextline) >= 0:
fmt = '\\chapter{%s}\n'
if fmt:
nextline = '\n'
line = fmt % string.strip(line)
elif inverbatim:
if blank.match(line) >= 0 and \
indented.match(nextline) < 0:
inverbatim = 0
fo.write('\\end{verbatim}\n')
else:
if indented.match(line) >= 0 and \
blank.match(prevline) >= 0:
inverbatim = 1
fo.write('\\begin{verbatim}\n')
if inverbatim:
line = string.expandtabs(line, 4)
fo.write(line)
#main()
process(open('ext.tex', 'r'), sys.stdout)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment