Commit d2449399 authored by jack's avatar jack

Putting pyexpat under cvs

parent 8c08723f
# Universal Makefile to build Python extensions.
#
# Instructions:
#
# 0) Build and install the basic Python 1.4 distribution. You must
# also install the headers ("make inclinstall") and the binary library
# files ("make libainstall").
#
# 1) Edit Makefile.pre.in (not any other file!!!) to change the
# definition of installdir (and possibly exec_installdir). These
# should match the prefix and exec_prefix used when installing Python.
# Alternatively, you can specify a value for installdir on the
# "make -f Makefile.pre.in Makefile" command line (see below). This
# is probably easier since it avoids editing Makefile.pre.in at all...
#
# 2) Copy Setup.in to Setup and edit Setup to change the selection of
# modules you want to use. Read the comments in the core Python's
# Modules/Setup.in for more detailed instructions.
#
# 3) Run "make Makefile -f Makefile.pre.in". This creates Makefile
# (producing Makefile.pre and sedscript as intermediate files) and
# config.c. Values for installdir, srcdir, VPATH, LINKPATH, OPT,
# BASELIB and BASESETUP on the make command line will be incorporated
# in the final Makefile.
#
# 4) Run "make". This creates a Python executable. The set of
# built-in modules and features is a superset of that of the basic
# Python -- additions are taken from ./Setup.
#
# If you don't actually want to install the Python headers and
# binary library files, you can edit the "Fixed definitions" section
# below to point directly into the source and/or build tree.
#
# Note: Each time you edit Makefile.pre.in or Setup, you must run
# "make Makefile" before running "make".
#
# Hint: if you want to use VPATH, you can start in an empty
# subdirectory and say (e.g.):
# make -f ../Makefile.pre.in VERSION=1.4 srcdir=.. VPATH=.. Makefile
# === Variables that you just *have* to customize manually ===
# (You can also specify their values on the command line for
# "make -f Makefile.pre.in VERSION=1.4 Makefile".)
# The prefix used by "make inclinstall libainstall" of core python
installdir= /ufs/jack/src/python/build.irix6/tmp
# The exec_prefix used by the same
exec_installdir=$(installdir)
# Source directory and VPATH in case you want to use VPATH.
# (You will have to edit these two lines yourself -- there is no
# automatic support as the Makefile is not generated by
# config.status.)
srcdir= .
VPATH= .
# === Variables that you may want to customize ===
# Add possible -L options here
LINKPATH=
# You may want to change this to -O
OPT= -g
# Add more -I and -D options here
CFLAGS= $(OPT) -I$(INCLUDEPY) -I$(LIBPL) $(DEFS)
# These two variables can be set in Setup to merge extensions.
# See example[23].
BASELIB=
BASESETUP=
# === Variables set by makesetup ===
MODOBJS= _MODOBJS_
MODLIBS= _MODLIBS_
# === Definitions added by makesetup ===
# === Variables from configure (through sedscript) ===
VERSION= @VERSION@
CC= @CC@
DEFS= @DEFS@
LIBS= @LIBS@
LIBM= @LIBM@
LIBC= @LIBC@
RANLIB= @RANLIB@
MACHDEP= @MACHDEP@
SO= @SO@
LDSHARED= @LDSHARED@
CCSHARED= @CCSHARED@
LINKFORSHARED= @LINKFORSHARED@
# Install prefix for architecture-independent files
prefix= /usr/local
# Install prefix for architecture-dependent files
exec_prefix= $(prefix)
# === Fixed definitions ===
# Expanded directories
BINDIR= $(exec_installdir)/bin
LIBDIR= $(exec_prefix)/lib
MANDIR= $(installdir)/man
INCLUDEDIR= $(installdir)/include
SCRIPTDIR= $(prefix)/lib
# Detailed destination directories
BINLIBDEST= $(LIBDIR)/python$(VERSION)
LIBDEST= $(SCRIPTDIR)/python$(VERSION)
INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)
LIBP= $(exec_installdir)/lib/python$(VERSION)
LIBPL= $(LIBP)/config
PYTHONLIBS= $(LIBPL)/libModules.a \
$(LIBPL)/libPython.a \
$(LIBPL)/libObjects.a \
$(LIBPL)/libParser.a
MAKESETUP= $(LIBPL)/makesetup
MAKEFILE= $(LIBPL)/Makefile
CONFIGC= $(LIBPL)/config.c
CONFIGCIN= $(LIBPL)/config.c.in
SETUP= $(LIBPL)/Setup
SYSLIBS= $(LIBM) $(LIBC)
ADDOBJS= $(LIBPL)/main.o getpath.o config.o
# === Fixed rules ===
all: python
sharedmods: $(SHAREDMODS)
python: $(ADDOBJS) lib.a $(PYTHONLIBS) Makefile $(BASELIB)
$(CC) $(ADDOBJS) lib.a $(PYTHONLIBS) \
$(LINKPATH) $(BASELIB) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python
lib.a: $(MODOBJS)
-rm -f lib.a
ar cr lib.a $(MODOBJS)
-$(RANLIB) lib.a || \
echo "don't worry if ranlib fails -- probably SYSV or equiv"
# This runs makesetup *twice* to use the BASESETUP definition from Setup
config.c Makefile: Makefile.pre Setup $(BASESETUP) $(MAKESETUP)
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
$(MAKE) -f Makefile do-it-again
do-it-again:
$(MAKESETUP) \
-m Makefile.pre -c $(CONFIGCIN) Setup -n $(BASESETUP) $(SETUP)
config.o: config.c
$(CC) $(CFLAGS) -c config.c
getpath.o: $(LIBPL)/getpath.c Makefile
$(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c $(LIBPL)/getpath.c
# Setup is copied from Setup.in *only* if it doesn't yet exist
Setup:
cp $(srcdir)/Setup.in Setup
Makefile.pre: Makefile.pre.in sedscript
sed -f sedscript $(srcdir)/Makefile.pre.in >Makefile.pre
# Shortcuts to make the sed arguments on one line
P=prefix
E=exec_prefix
H=Generated automatically from Makefile.pre.in by sedscript.
sedscript: $(MAKEFILE)
sed -n \
-e '1s/.*/1i\\/p' \
-e '2s%.*%# $H%p' \
-e '/^VERSION=/s/^VERSION=[ ]*\(.*\)/s%@VERSION[@]%\1%/p' \
-e '/^CC=/s/^CC=[ ]*\(.*\)/s%@CC[@]%\1%/p' \
-e '/^DEFS=/s/^DEFS=[ ]*\(.*\)/s%@DEFS[@]%\1%/p' \
-e '/^LIBS=/s/^LIBS=[ ]*\(.*\)/s%@LIBS[@]%\1%/p' \
-e '/^LIBM=/s/^LIBM=[ ]*\(.*\)/s%@LIBM[@]%\1%/p' \
-e '/^LIBC=/s/^LIBC=[ ]*\(.*\)/s%@LIBC[@]%\1%/p' \
-e '/^RANLIB=/s/^RANLIB=[ ]*\(.*\)/s%@RANLIB[@]%\1%/p' \
-e '/^MACHDEP=/s/^MACHDEP=[ ]*\(.*\)/s%@MACHDEP[@]%\1%/p' \
-e '/^SO=/s/^SO=[ ]*\(.*\)/s%@SO[@]%\1%/p' \
-e '/^LDSHARED=/s/^LDSHARED=[ ]*\(.*\)/s%@LDSHARED[@]%\1%/p' \
-e '/^CCSHARED=/s/^CCSHARED=[ ]*\(.*\)/s%@CCSHARED[@]%\1%/p' \
-e '/^LINKFORSHARED=/s/^LINKFORSHARED=[ ]*\(.*\)/s%@LINKFORSHARED[@]%\1%/p' \
-e '/^$P=/s/^$P=\(.*\)/s%^$P=.*%$P=\1%/p' \
-e '/^$E=/s/^$E=\(.*\)/s%^$E=.*%$E=\1%/p' \
$(MAKEFILE) >sedscript
( \
echo "/^installdir=/s%=.*%= $(installdir)%"; \
echo "/^exec_installdir=/s%=.*%=$(exec_installdir)%"; \
echo "/^srcdir=/s%=.*%= $(srcdir)%"; \
echo "/^VPATH=/s%=.*%= $(VPATH)%"; \
echo "/^LINKPATH=/s%=.*%= $(LINKPATH)%"; \
echo "/^OPT=/s%=.*%= $(OPT)%"; \
echo "/^BASELIB=/s%=.*%= $(BASELIB)%"; \
echo "/^BASESETUP=/s%=.*%= $(BASESETUP)%"; \
) >>sedscript
clean:
-rm -f *.o *~
clobber: clean
-rm -f python lib.a sedscript config.c Makefile.pre
distclean: clobber
-rm -f Makefile Setup
Python Expat wrapper module, version of 19-May-98
=================================================
If you have downloaded the binary distribution for the macintosh you
can skip the "building" sections and go straight to the "using"
bit. If you are using a macintosh and do want to build from source you
should get the pyexpat.tgz distribution (Stuffit Expander with
Expander Enhancer will know how to unpack a gzipped tar file).
Building the pyexpat module under unix
--------------------------------------
- Build libexpat.a in expat. This version is very slightly different
from the original by James Clark (the libexpat.a target was added,
and a few C++ comments were replaced by C comments).
- Edit Makefile.pre.in and set your installdir
- make -f Makefile.pre.in VERSION=1.5.1 Makefile
- make sharedmods
- put the shared module somewhere in your sys.path
(if you want a static Python edit Setup.in, and replace the last line
with "make").
Building the pyexpat module on the macintosh
--------------------------------------------
- Unpack the various .hqx project files.
- All the projects are linked, so building pyexpat.prj should build
everything. If this doesn't work you will find the library
subprojects to build in the expat folder.
- Use EditPythonPrefs to add the current folder to sys.path.
Using the pyexpat module
-----------------------
The pyexpat module exports two functions:
ParserCreate(encoding) Creates a new parser object. The optional
encoding arg (a string) specifies the encoding.
ErrorString(number) Return a string corresponding to the given error
number.
Parser objects have one method:
Parse(data, isfinal) Parse some data. If the optional isfinal arg is 1
this is the last bit of data. Returns true if parsing
succeeded (so far), otherwise the error attributes have
information on the error.
Parser objects have the following attributes:
StartElementHandler, EndElementHandler, CharacterDataHandler,
ProcessingInstructionHandler - The Python handlers called for various
events. See below for the signatures.
ErrorCode, ErrorLineNumber, ErrorColumnNumber, ErrorByteIndex -
Readonly integers giving information on the current parse
error.
Testing it
----------
There's a very minimal test script in expattest.py. It should be easy
to adapt it to generate ESIS (but I'm not familiar enough with ESIS to
do it). This module parsed Hamlet in 2 seconds on an 180 Mhz R5000 SGI
O2.
Feedback
--------
This module currently lives at
ftp://ftp.cwi.nl/pub/jack/python/pyexpatsrc.tgz (source) and
ftp://ftp.cwi.nl/pub/jack/python/pyexpat.hqx (macintosh binary-only).
The author is Jack Jansen, jack@cwi.nl. The expat proper was written
by James Clark and can be found at http://www.jclark.com/xml/ .
Jack Jansen, CWI, Amsterdam
jack@cwi.nl
\ No newline at end of file
*shared*
pyexpat pyexpat.o expat/libexpat.a -Iexpat/xmlparse
"""This file (which is sourced, not imported) checks the version of the
"versioncheck" package. It is also an example of how to format your own
_checkversion.py file"""
import pyversioncheck
_PACKAGE="pyexpat"
_VERSION="1.1"
_URL="http://www.cwi.nl/~jack/pyexpatversion.txt"
try:
_myverbose=VERBOSE
except NameError:
_myverbose=1
pyversioncheck.versioncheck(_PACKAGE, _URL, _VERSION, verbose=_myverbose)
This diff is collapsed.
This diff is collapsed.
# Very simple test - Parse a file and print what happens
import sys
import pyexpat
import sys
import os
class Outputter:
def __init__(self, verbose=0):
self.startcount = 0
self.endcount = 0
self.cdatacount = 0
self.instcount = 0
self.verbose = verbose
def startelt(self, name, attrs):
self.startcount = self.startcount + 1
if self.verbose:
print 'start', name
for i in range(0, len(attrs), 2):
print 'attr', attrs[i], attrs[i+1]
def endelt(self, name):
self.endcount = self.endcount + 1
if self.verbose:
print 'end', name
def cdata(self, data):
self.cdatacount = self.cdatacount + 1
if self.verbose:
print 'cdata', data
def inst(self, target, data):
self.instcount = self.instcount + 1
if self.verbose:
print 'inst', target, data
if len(sys.argv) > 1 and sys.argv[1] == '-v':
out = Outputter(verbose=1)
del sys.argv[1]
else:
out = Outputter()
if len(sys.argv) != 2:
if os.name == 'mac':
import macfs
fss, ok = macfs.StandardGetFile()
if not ok: sys.exit(0)
sys.argv.append(fss.as_pathname())
else:
print 'Usage: pyexpattest [-v] inputfile'
sys.exit(1)
parser = pyexpat.ParserCreate()
parser.StartElementHandler = out.startelt
parser.EndElementHandler = out.endelt
parser.CharacterDataHandler = out.cdata
parser.ProcessingInstructionHandler = out.inst
data = open(sys.argv[1]).read()
rv = parser.Parse(data, 1)
print 'Parser returned', rv
if rv == 0:
print '** Error', parser.ErrorCode
print '** Line', parser.ErrorLineNumber
print '** Column', parser.ErrorColumnNumber
print '** Byte', parser.ErrorByteIndex
print 'Summary of XML parser upcalls:'
print 'start elements:', out.startcount
print 'end elements:', out.endcount
print 'character data:', out.cdatacount
print 'processing instructions:', out.instcount
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