Commits

Anonymous committed b1a1de1

This commit was manufactured by cvs2svn to create branch
'release21-maint'.

Comments (0)

Files changed (16)

Lib/test/test_socketserver.py

+# Test suite for SocketServer.py
+
+# XXX This must be run manually -- somehow the I/O redirection of the
+# regression test breaks the test.
+
+from test_support import verbose, verify, TESTFN
+if not verbose:
+    raise ImportError, "test_socketserver can only be run manually"
+
+from SocketServer import *
+import socket
+import select
+import time
+import threading
+import os
+
+NREQ = 3
+DELAY = 0.5
+
+class MyMixinHandler:
+    def handle(self):
+        time.sleep(DELAY)
+        line = self.rfile.readline()
+        time.sleep(DELAY)
+        self.wfile.write(line)
+
+class MyStreamHandler(MyMixinHandler, StreamRequestHandler):
+    pass
+
+class MyDatagramHandler(MyMixinHandler, DatagramRequestHandler):
+    pass
+
+class MyMixinServer:
+    def serve_a_few(self):
+        for i in range(NREQ):
+            self.handle_request()
+    def handle_error(self, request, client_address):
+        self.close_request(request)
+        self.server_close()
+        raise
+
+teststring = "hello world\n"
+
+def receive(sock, n, timeout=20):
+    r, w, x = select.select([sock], [], [], timeout)
+    if sock in r:
+        return sock.recv(n)
+    else:
+        raise RuntimeError, "timed out on %s" % `sock`
+
+def testdgram(proto, addr):
+    s = socket.socket(proto, socket.SOCK_DGRAM)
+    s.sendto(teststring, addr)
+    buf = data = receive(s, 100)
+    while data and '\n' not in buf:
+        data = receive(s, 100)
+        buf += data
+    verify(buf == teststring)
+    s.close()
+
+def teststream(proto, addr):
+    s = socket.socket(proto, socket.SOCK_STREAM)
+    s.connect(addr)
+    s.send(teststring)
+    buf = data = receive(s, 100)
+    while data and '\n' not in buf:
+        data = receive(s, 100)
+        buf += data
+    verify(buf == teststring)
+    s.close()
+
+class ServerThread(threading.Thread):
+    def __init__(self, addr, svrcls, hdlrcls):
+        threading.Thread.__init__(self)
+        self.__addr = addr
+        self.__svrcls = svrcls
+        self.__hdlrcls = hdlrcls
+    def run(self):
+        class svrcls(MyMixinServer, self.__svrcls):
+            pass
+        if verbose: print "thread: creating server"
+        svr = svrcls(self.__addr, self.__hdlrcls)
+        if verbose: print "thread: serving three times"
+        svr.serve_a_few()
+        if verbose: print "thread: done"
+
+seed = 0
+def pickport():
+    global seed
+    seed += 1
+    return 10000 + (os.getpid() % 1000)*10 + seed
+
+host = "localhost"
+testfiles = []
+def pickaddr(proto):
+    if proto == socket.AF_INET:
+        return (host, pickport())
+    else:
+        fn = TESTFN + str(pickport())
+        testfiles.append(fn)
+        return fn
+
+def cleanup():
+    for fn in testfiles:
+        try:
+            os.remove(fn)
+        except os.error:
+            pass
+    testfiles[:] = []
+
+def testloop(proto, servers, hdlrcls, testfunc):
+    for svrcls in servers:
+        addr = pickaddr(proto)
+        if verbose:
+            print "ADDR =", addr
+            print "CLASS =", svrcls
+        t = ServerThread(addr, svrcls, hdlrcls)
+        if verbose: print "server created"
+        t.start()
+        if verbose: print "server running"
+        for i in range(NREQ):
+            time.sleep(DELAY)
+            if verbose: print "test client", i
+            testfunc(proto, addr)
+        if verbose: print "waiting for server"
+        t.join()
+        if verbose: print "done"
+
+tcpservers = [TCPServer, ThreadingTCPServer]
+if hasattr(os, 'fork'):
+    tcpservers.append(ForkingTCPServer)
+udpservers = [UDPServer, ThreadingUDPServer]
+if hasattr(os, 'fork'):
+    udpservers.append(ForkingUDPServer)
+
+if not hasattr(socket, 'AF_UNIX'):
+    streamservers = []
+    dgramservers = []
+else:
+    class ForkingUnixStreamServer(ForkingMixIn, UnixStreamServer): pass
+    streamservers = [UnixStreamServer, ThreadingUnixStreamServer,
+                     ForkingUnixStreamServer]
+    class ForkingUnixDatagramServer(ForkingMixIn, UnixDatagramServer): pass
+    dgramservers = [UnixDatagramServer, ThreadingUnixDatagramServer,
+                    ForkingUnixDatagramServer]
+
+def testall():
+    testloop(socket.AF_INET, tcpservers, MyStreamHandler, teststream)
+    testloop(socket.AF_INET, udpservers, MyDatagramHandler, testdgram)
+    if hasattr(socket, 'AF_UNIX'):
+        testloop(socket.AF_UNIX, streamservers, MyStreamHandler, teststream)
+        # Alas, on Linux (at least) recvfrom() doesn't return a meaningful
+        # client address so this cannot work:
+        ##testloop(socket.AF_UNIX, dgramservers, MyDatagramHandler, testdgram)
+
+def main():
+    try:
+        testall()
+    finally:
+        cleanup()
+
+main()

Mac/Demo/quicktime/VerySimplePlayer.py

+"""VerySimplePlayer converted to python
+
+Jack Jansen, CWI, December 1995
+"""
+
+import Qt
+import QuickTime
+import Qd
+import QuickDraw
+import Evt
+import Events
+import Win
+import Windows
+import macfs
+import sys
+
+# XXXX maxbounds = (40, 40, 1000, 1000)
+
+def main():
+	print 'hello world' # XXXX
+	# skip the toolbox initializations, already done
+	# XXXX Should use gestalt here to check for quicktime version
+	Qt.EnterMovies()
+	
+	# Get the movie file
+	fss, ok = macfs.StandardGetFile(QuickTime.MovieFileType)
+	if not ok:
+		sys.exit(0)
+		
+	# Open the window
+	bounds = (175, 75, 175+160, 75+120)
+	theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0)
+	# XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
+	Qd.SetPort(theWindow)
+	
+	# Get the movie
+	theMovie = loadMovie(fss)
+	
+	# Relocate to (0, 0)
+	bounds = theMovie.GetMovieBox()
+	bounds = 0, 0, bounds[2]-bounds[0], bounds[3]-bounds[1]
+	theMovie.SetMovieBox(bounds)
+	
+	# Create a controller
+	theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie)
+	
+	# Get movie size and update window parameters
+	rv, bounds = theController.MCGetControllerBoundsRect()
+	theWindow.SizeWindow(bounds[2], bounds[3], 0)   # XXXX or [3] [2]?
+	Qt.AlignWindow(theWindow, 0)
+	theWindow.ShowWindow()
+	
+	# XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds)
+	theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1')
+	
+	# XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow)
+	
+	done = 0
+	while not done:
+		gotone, evt = Evt.WaitNextEvent(0xffff, 0)
+		(what, message, when, where, modifiers) = evt
+##		print what, message, when, where, modifiers # XXXX
+		
+		if theController.MCIsPlayerEvent(evt):
+			continue
+			
+		if what == Events.mouseDown:
+			part, whichWindow = Win.FindWindow(where)
+			if part == Windows.inGoAway:
+				done = whichWindow.TrackGoAway(where)
+			elif part == Windows.inDrag:
+				Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000))
+		elif what == Events.updateEvt:
+			whichWindow = Win.WhichWindow(message)
+			if not whichWindow:
+				# Probably the console window. Print something, hope it helps.
+				print 'update'
+			else:
+				Qd.SetPort(whichWindow)
+				whichWindow.BeginUpdate()
+				Qd.EraseRect(whichWindow.GetWindowPort().portRect)
+				whichWindow.EndUpdate()
+			
+def loadMovie(theFile):
+	"""Load a movie given an fsspec. Return the movie object"""
+	movieResRef = Qt.OpenMovieFile(theFile, 1)
+	movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
+	return movie
+	
+if __name__ == '__main__':
+	main()
+	

Mac/Distributions/readme.txt

+How to make a Python-distribution.
+----------------------------------
+
+These notes are mainly for myself, or for whoever tries to make a MacPython
+distribution when I'm fed up with it. They were last updated for 2.1b2.
+
+- Increase fragment version number in PythonCore and PythonCoreCarbon.
+  the fragment number is Python's sys.hexversion, it should be set in the
+  "PEF" preferences.
+- Increase version number in _versioncheck.py
+- Build PythonStandSmall, run once in root folder
+- Update Relnotes, readme's, Demo:build.html
+- Make sure tkresources.rsrc is up-to-date
+- fullbuild everything with increase-buildno
+- Update Numeric and build/install it both with Classic and with Carbon python
+- Run configurepython
+- Recompile OSAm and possibly other Contrib stuff
+- mkdistr binary.include
+- mkdistr dev.include
+- make distribution archive with Installer Vise
+  Things to make sure of:
+  - Finder icon positions
+  - Version numbers in "Packages..." window
+  - Version number in "Installer Settings" -> "Easy Install Text"
+  - Version number in "Project" -> Attributes
+  - Version number in "Project" -> PostProcess
+  - Version number in "Internet" -> "Download Sites"
+  - Version number in "Internet" -> "File Groups".
+- test on virgin systems (OSX, OS9, OS8 without Carbon). Make sure to test
+  tkinter too.
+- Upload
+- Update README file in ftp directory
+- Change version number in public_html/macpythonversion.txt .
+- Update macpython.html
+- Send an announcement to:
+   pythonmac-sig@python.org
+   python-dev@python.org
+   python-announce@python.org
+   archivist@info-mac.org
+   adcnews@apple.com
+   http://www.macupdate.com
+   http://guide.apple.com/usindex.html
+   http://www.versiontracker.com/ Jack.Jansen@oratrix.com

Mac/Include/config.h

+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+/* config.h for Macintosh.
+   Valid only for CodeWarrior.
+   There's no point in giving exact version numbers of the compilers
+   since we don't update this file as each compiler comes out;
+   with CodeWarrior, we generally use the most recent version.
+*/
+
+#define USE_STACKCHECK
+
+/* Define if on Macintosh (MPW or __MWERKS__ should also be defined) */
+#ifndef macintosh
+#define macintosh
+#endif
+
+#if defined(USE_GUSI1) || defined(USE_GUSI2)
+#define USE_GUSI
+#endif
+
+#ifndef USE_GUSI
+#define DONT_HAVE_SYS_TYPES_H
+#define DONT_HAVE_SYS_STAT_H
+#define HAVE_STAT_H
+#endif
+
+/* Define if on AIX 3.
+   System headers sometimes define this.
+   We just want to avoid a redefinition error message.  */
+#ifndef _ALL_SOURCE
+#undef _ALL_SOURCE
+#endif
+
+/* Define if type char is unsigned and you are not using gcc.  */
+#ifndef __CHAR_UNSIGNED__
+#undef __CHAR_UNSIGNED__
+#endif
+
+/* Define to empty if the keyword does not work.  */
+#undef const
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+#undef gid_t
+
+/* Define if your struct tm has tm_zone.  */
+#undef HAVE_TM_ZONE
+
+/* Define if you don't have tm_zone but do have the external array
+   tzname.  */
+#undef HAVE_TZNAME
+
+/* Define if on MINIX.  */
+#undef _MINIX
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+#undef mode_t
+
+/* Define to `long' if <sys/types.h> doesn't define.  */
+#undef off_t
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+#undef pid_t
+
+/* Define if the system does not provide POSIX.1 features except
+   with this defined.  */
+#undef _POSIX_1_SOURCE
+
+/* Define if you need to in order for stat and other things to work.  */
+#undef _POSIX_SOURCE
+
+/* Define as the return type of signal handlers (int or void).  */
+#define RETSIGTYPE void
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+#undef size_t
+
+/* Define if you have the ANSI C header files.  */
+#define STDC_HEADERS 1
+
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+#undef TIME_WITH_SYS_TIME
+
+/* Define if your <sys/time.h> declares struct tm.  */
+#undef TM_IN_SYS_TIME
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+#undef uid_t
+
+/* Define if your processor stores words with the most significant
+   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
+#define WORDS_BIGENDIAN 1
+
+/* Define for AIX if your compiler is a genuine IBM xlC/xlC_r
+   and you want support for AIX C++ shared extension modules. */
+#undef AIX_GENUINE_CPLUSPLUS
+
+/* Define if your <unistd.h> contains bad prototypes for exec*()
+   (as it does on SGI IRIX 4.x) */
+#undef BAD_EXEC_PROTOTYPES
+
+/* Define if your compiler botches static forward declarations */
+#define BAD_STATIC_FORWARD
+
+/* Define this if you have BeOS threads */
+#undef BEOS_THREADS
+
+/* Define if you have the Mach cthreads package */
+#undef C_THREADS
+
+/* Defined when case of imported modules are checked against case of file. */
+#define CHECK_IMPORT_CASE
+
+/* Define to `long' if <time.h> doesn't define.  */
+#undef clock_t
+
+/* Defined on Solaris to see additional function prototypes. */
+#undef __EXTENSIONS__
+
+/* Define if getpgrp() must be called as getpgrp(0). */
+#undef GETPGRP_HAVE_ARG
+
+/* Define if gettimeofday() does not have second (timezone) argument
+   This is the case on Motorola V4 (R40V4.2) */
+#undef GETTIMEOFDAY_NO_TZ
+
+/* Define this if your time.h defines altzone */
+#undef HAVE_ALTZONE
+
+/* Defined when any dynamic module loading is enabled */
+/* #undef HAVE_DYNAMIC_LOADING */
+
+/* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */
+#undef HAVE_GETC_UNLOCKED
+
+/* Define this if you have some version of gethostbyname_r() */
+#undef HAVE_GETHOSTBYNAME_R
+
+/* Define this if you have the 3-arg version of gethostbyname_r() */
+#undef HAVE_GETHOSTBYNAME_R_3_ARG
+
+/* Define this if you have the 5-arg version of gethostbyname_r() */
+#undef HAVE_GETHOSTBYNAME_R_5_ARG
+
+/* Define this if you have the 6-arg version of gethostbyname_r() */
+#undef HAVE_GETHOSTBYNAME_R_6_ARG
+
+/* Defined to enable large file support when an off_t is bigger than a long
+   and long long is available and at least as big as an off_t. You may need
+   to add some flags for configuration and compilation to enable this mode.
+   E.g, for Solaris 2.7:
+   CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" OPT="-O2 $CFLAGS" \
+ configure
+*/
+#undef HAVE_LARGEFILE_SUPPORT
+
+/* Define this if you have the type long long */
+#undef HAVE_LONG_LONG
+
+/* Define if your compiler supports function prototypes */
+#define HAVE_PROTOTYPES 1
+
+/* Define if you have GNU PTH threads */
+#undef HAVE_PTH
+
+/* Define if your compiler supports variable length function prototypes
+   (e.g. void fprintf(FILE *, char *, ...);) *and* <stdarg.h> */
+#define HAVE_STDARG_PROTOTYPES
+
+/* Define this if you have the type uintptr_t */
+#undef HAVE_UINTPTR_T
+
+/* Define if you have a useable wchar_t type defined in wchar.h; useable
+   means wchar_t must be 16-bit unsigned type. (see
+   Include/unicodeobject.h). */
+#define HAVE_USABLE_WCHAR_T 1
+
+/* Define if the compiler provides a wchar.h header file. */
+#define HAVE_WCHAR_H 1
+
+/* Define if you want to have a Unicode type. */
+#define Py_USING_UNICODE 1
+
+/* Define as the integral type used for Unicode representation. */
+#define PY_UNICODE_TYPE wchar_t
+
+/* Define as the size of the unicode type. */
+#define Py_UNICODE_SIZE 2
+
+/* Define if malloc(0) returns a NULL pointer */
+#ifdef USE_MSL_MALLOC
+#define MALLOC_ZERO_RETURNS_NULL
+#else
+#undef MALLOC_ZERO_RETURNS_NULL
+#endif
+
+/* Define if you have POSIX threads */
+#ifdef USE_GUSI2
+#define _POSIX_THREADS
+#endif
+
+/* Define if you want to build an interpreter with many run-time checks  */
+#undef Py_DEBUG
+
+/* Define to force use of thread-safe errno, h_errno, and other functions */
+#undef _REENTRANT
+
+/* Define if setpgrp() must be called as setpgrp(0, 0). */
+#undef SETPGRP_HAVE_ARG
+
+/* Define to empty if the keyword does not work.  */
+#undef signed
+
+/* Define if i>>j for signed int i does not extend the sign bit
+   when i < 0
+*/
+#define SIGNED_RIGHT_SHIFT_ZERO_FILLS
+
+/* The number of bytes in an off_t. */
+#define SIZEOF_OFF_T 4
+
+/* The number of bytes in a time_t. */
+#define SIZEOF_TIME_T 4
+
+/* The number of bytes in a pthread_t. */
+#ifdef USE_GUSI2
+#define SIZEOF_PTHREAD_T 4
+#endif
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+#undef socklen_t
+
+/* Define if  you can safely include both <sys/select.h> and <sys/time.h>
+   (which you can't on SCO ODT 3.0). */
+#undef SYS_SELECT_WITH_SYS_TIME
+
+/* Define if a va_list is an array of some kind */
+#undef VA_LIST_IS_ARRAY
+
+/* Define to empty if the keyword does not work.  */
+#undef volatile
+
+/* Define if you want SIGFPE handled (see Include/pyfpe.h). */
+#undef WANT_SIGFPE_HANDLER
+
+/* Define if you want wctype.h functions to be used instead of the
+   one supplied by Python itself. (see Include/unicodectype.h). */
+#undef WANT_WCTYPE_FUNCTIONS
+
+/* Define if you want to compile in cycle garbage collection */
+#undef WITH_CYCLE_GC
+
+/* Define if you want to emulate SGI (IRIX 4) dynamic linking.
+   This is rumoured to work on VAX (Ultrix), Sun3 (SunOS 3.4),
+   Sequent Symmetry (Dynix), and Atari ST.
+   This requires the "dl-dld" library,
+   ftp://ftp.cwi.nl/pub/dynload/dl-dld-1.1.tar.Z,
+   as well as the "GNU dld" library,
+   ftp://ftp.cwi.nl/pub/dynload/dld-3.2.3.tar.Z.
+   Don't bother on SunOS 4 or 5, they already have dynamic linking using
+   shared libraries */ 
+#undef WITH_DL_DLD
+
+/* Define if you want to use the new-style (Openstep, Rhapsody, MacOS)
+   dynamic linker (dyld) instead of the old-style (NextStep) dynamic
+   linker (rld). Dyld is necessary to support frameworks. */
+#undef WITH_DYLD
+
+/* Define if you want to compile in Python-specific mallocs */
+#undef WITH_PYMALLOC
+
+/* Define if you want to produce an OpenStep/Rhapsody framework
+   (shared library plus accessory files). */
+#undef WITH_NEXT_FRAMEWORK
+
+/* Define if you want to use SGI (IRIX 4) dynamic linking.
+   This requires the "dl" library by Jack Jansen,
+   ftp://ftp.cwi.nl/pub/dynload/dl-1.6.tar.Z.
+   Don't bother on IRIX 5, it already has dynamic linking using SunOS
+   style shared libraries */ 
+#undef WITH_SGI_DL
+
+/* Define if you want to compile in rudimentary thread support */
+/* #undef WITH_THREAD */
+
+/* The number of bytes in a char.  */
+#define SIZEOF_CHAR 1
+
+/* The number of bytes in a double.  */
+#define SIZEOF_DOUBLE 8
+
+/* The number of bytes in a float.  */
+#define SIZEOF_FLOAT 4
+
+/* The number of bytes in a fpos_t.  */
+#define SIZEOF_FPOS_T 4
+
+/* The number of bytes in a int.  */
+#define SIZEOF_INT 4
+
+/* The number of bytes in a long.  */
+#define SIZEOF_LONG 4
+
+/* The number of bytes in a long long.  */
+#undef SIZEOF_LONG_LONG
+
+/* The number of bytes in a short.  */
+#define SIZEOF_SHORT 2
+
+/* The number of bytes in a uintptr_t.  */
+#define SIZEOF_UINTPTR_T 4
+
+/* The number of bytes in a void *.  */
+#define SIZEOF_VOID_P 4
+
+/* Define if you have the _getpty function.  */
+#undef HAVE__GETPTY
+
+/* Define if you have the alarm function.  */
+#undef HAVE_ALARM
+
+/* Define if you have the chown function.  */
+#undef HAVE_CHOWN
+
+/* Define if you have clock.  */
+#define HAVE_CLOCK
+
+/* Define if you have the confstr function.  */
+#undef HAVE_CONFSTR
+
+/* Define if you have the ctermid function.  */
+#undef HAVE_CTERMID
+
+/* Define if you have the ctermid_r function.  */
+#undef HAVE_CTERMID_R
+
+/* Define if you have the dlopen function.  */
+#undef HAVE_DLOPEN
+
+/* Define if you have the dup2 function.  */
+#undef HAVE_DUP2
+
+/* Define if you have the execv function.  */
+#undef HAVE_EXECV
+
+/* Define if you have the fdatasync function.  */
+#undef HAVE_FDATASYNC
+
+/* Define if you have the flock function.  */
+#undef HAVE_FLOCK
+
+/* Define if you have the fork function.  */
+#undef HAVE_FORK
+
+/* Define if you have the forkpty function.  */
+#undef HAVE_FORKPTY
+
+/* Define if you have the fpathconf function.  */
+#undef HAVE_FPATHCONF
+
+/* Define if you have the fseek64 function.  */
+#undef HAVE_FSEEK64
+
+/* Define if you have the fseeko function.  */
+#undef HAVE_FSEEKO
+
+/* Define if you have the fstatvfs function.  */
+#undef HAVE_FSTATVFS
+
+/* Define if you have the fsync function.  */
+#define HAVE_FSYNC
+
+/* Define if you have the ftell64 function.  */
+#undef HAVE_FTELL64
+
+/* Define if you have the ftello function.  */
+#undef HAVE_FTELLO
+
+/* Define if you have the ftime function.  */
+#undef HAVE_FTIME
+
+/* Define if you have the ftruncate function.  */
+#ifdef USE_GUSI
+#define HAVE_FTRUNCATE
+#endif
+
+/* Define if you have the getcwd function.  */
+#define HAVE_GETCWD
+
+/* Define if you have the getgroups function.  */
+#undef HAVE_GETGROUPS
+
+/* Define if you have the gethostbyname function.  */
+#ifdef USE_GUSI
+#define HAVE_GETHOSTBYNAME 1
+#endif
+
+/* Define if you have the getlogin function.  */
+#undef HAVE_GETLOGIN
+
+/* Define if you have the getpeername function.  */
+#ifdef USE_GUSI
+#define HAVE_GETPEERNAME
+#endif
+
+/* Define if you have the getpgrp function.  */
+#undef HAVE_GETPGRP
+
+/* Define if you have the getpid function.  */
+#undef HAVE_GETPID
+
+/* Define if you have the getpwent function.  */
+#undef HAVE_GETPWENT
+
+/* Define if you have the gettimeofday function.  */
+#ifdef USE_GUSI
+#define HAVE_GETTIMEOFDAY
+#endif
+
+/* Define if you have the getwd function.  */
+#undef HAVE_GETWD
+
+/* Define if you have the hypot function.  */
+#ifndef __MC68K__
+/* 68K hypot definition (and implementation) are unuseable
+** because they use 10-byte floats.
+*/
+#define HAVE_HYPOT
+#endif
+
+/* Define if you have the kill function.  */
+#undef HAVE_KILL
+
+/* Define if you have the link function.  */
+#undef HAVE_LINK
+
+/* Define if you have the lstat function.  */
+#undef HAVE_LSTAT
+
+/* Define if you have the memmove function.  */
+#define HAVE_MEMMOVE
+
+/* Define if you have the mkfifo function.  */
+#undef HAVE_MKFIFO
+
+/* Define if you have the mktime function.  */
+#define HAVE_MKTIME
+
+/* Define if you have the mremap function.  */
+#undef HAVE_MREMAP
+
+/* Define if you have the nice function.  */
+#undef HAVE_NICE
+
+/* Define if you have the openpty function.  */
+#undef HAVE_OPENPTY
+
+/* Define if you have the pathconf function.  */
+#undef HAVE_PATHCONF
+
+/* Define if you have the pause function.  */
+#undef HAVE_PAUSE
+
+/* Define if you have the plock function.  */
+#undef HAVE_PLOCK
+
+/* Define if you have the poll function.  */
+#undef HAVE_POLL
+
+/* Define if you have the pthread_init function.  */
+#undef HAVE_PTHREAD_INIT
+
+/* Define if you have the putenv function.  */
+#undef HAVE_PUTENV
+
+/* Define if you have the readlink function.  */
+#undef HAVE_READLINK
+
+/* Define if you have the select function.  */
+#ifdef USE_GUSI
+#define HAVE_SELECT
+#endif
+
+/* Define if you have the setegid function.  */
+#undef HAVE_SETEGID
+
+/* Define if you have the seteuid function.  */
+#undef HAVE_SETEUID
+
+/* Define if you have the setgid function.  */
+#undef HAVE_SETGID
+
+/* Define if you have the setlocale function.  */
+#undef HAVE_SETLOCALE
+
+/* Define if you have the setpgid function.  */
+#undef HAVE_SETPGID
+
+/* Define if you have the setpgrp function.  */
+#undef HAVE_SETPGRP
+
+/* Define if you have the setregid function.  */
+#undef HAVE_SETREGID
+
+/* Define if you have the setreuid function.  */
+#undef HAVE_SETREUID
+
+/* Define if you have the setsid function.  */
+#undef HAVE_SETSID
+
+/* Define if you have the setuid function.  */
+#undef HAVE_SETUID
+
+/* Define if you have the setvbuf function.  */
+#define HAVE_SETVBUF
+
+/* Define if you have the sigaction function.  */
+#undef HAVE_SIGACTION
+
+/* Define if you have the siginterrupt function.  */
+#undef HAVE_SIGINTERRUPT
+
+/* Define if you have the sigrelse function.  */
+#undef HAVE_SIGRELSE
+
+/* Define if you have the statvfs function.  */
+#undef HAVE_STATVFS
+
+/* Define if you have the strdup function.  */
+#undef HAVE_STRDUP
+
+/* Define if you have the strerror function.  */
+#define HAVE_STRERROR
+
+/* Define if you have the strftime function.  */
+#define HAVE_STRFTIME
+
+/* Define if you have the strptime function.  */
+#undef HAVE_STRPTIME
+
+/* Define if you have the symlink function.  */
+#undef HAVE_SYMLINK
+
+/* Define if you have the sysconf function.  */
+#undef HAVE_SYSCONF
+
+/* Define if you have the tcgetpgrp function.  */
+#undef HAVE_TCGETPGRP
+
+/* Define if you have the tcsetpgrp function.  */
+#undef HAVE_TCSETPGRP
+
+/* Define if you have the tempnam function.  */
+#undef HAVE_TEMPNAM
+
+/* Define if you have the timegm function.  */
+#undef HAVE_TIMEGM
+
+/* Define if you have the times function.  */
+#undef HAVE_TIMES
+
+/* Define if you have the tmpfile function.  */
+#define HAVE_TMPFILE
+
+/* Define if you have the tmpnam function.  */
+#define HAVE_TMPNAM
+
+/* Define if you have the tmpnam_r function.  */
+#undef HAVE_TMPNAM_R
+
+/* Define if you have the truncate function.  */
+#define HAVE_TRUNCATE
+
+/* Define if you have the uname function.  */
+#undef HAVE_UNAME
+
+/* Define if you have the waitpid function.  */
+#undef HAVE_WAITPID
+
+/* Define if you have the <db.h> header file.  */
+#undef HAVE_DB_H
+
+/* Define if you have the <db1/ndbm.h> header file.  */
+#undef HAVE_DB1_NDBM_H
+
+/* Define if you have the <db_185.h> header file.  */
+#undef HAVE_DB_185_H
+
+/* Define if you have the <dirent.h> header file.  */
+#ifdef USE_GUSI
+#define HAVE_DIRENT_H
+#endif
+
+/* Define if you have the <dlfcn.h> header file.  */
+#undef HAVE_DLFCN_H
+
+/* Define if you have the <fcntl.h> header file.  */
+#define HAVE_FCNTL_H
+
+/* Define if you have the <gdbm/ndbm.h> header file.  */
+#undef HAVE_GDBM_NDBM_H
+
+/* Define if you have the <libutil.h> header file.  */
+#undef HAVE_LIBUTIL_H
+
+/* Define if you have the <limits.h> header file.  */
+#define HAVE_LIMITS_H
+
+/* Define if you have the <locale.h> header file.  */
+#define HAVE_LOCALE_H
+
+/* Define if you have the <ncurses.h> header file.  */
+#undef HAVE_NCURSES_H
+
+/* Define if you have the <ndbm.h> header file.  */
+#undef HAVE_NDBM_H
+
+/* Define if you have the <ndir.h> header file.  */
+#undef HAVE_NDIR_H
+
+/* Define if you have the <poll.h> header file.  */
+#undef HAVE_POLL_H
+
+/* Define if you have the <pthread.h> header file.  */
+#ifdef USE_GUSI2
+#define HAVE_PTHREAD_H
+#endif
+
+/* Define if you have the <pty.h> header file.  */
+#undef HAVE_PTY_H
+
+/* Define if you have the <signal.h> header file.  */
+#define HAVE_SIGNAL_H
+
+/* Define if you have the <stdarg.h> header file.  */
+#define HAVE_STDARG_H
+
+/* Define if you have the <stddef.h> header file.  */
+#define HAVE_STDDEF_H
+
+/* Define if you have the <stdlib.h> header file.  */
+#define HAVE_STDLIB_H
+
+/* Define if you have the <sys/audioio.h> header file.  */
+#undef HAVE_SYS_AUDIOIO_H
+
+/* Define if you have the <sys/dir.h> header file.  */
+#undef HAVE_SYS_DIR_H
+
+/* Define if you have the <sys/file.h> header file.  */
+#undef HAVE_SYS_FILE_H
+
+/* Define if you have the <sys/lock.h> header file.  */
+#undef HAVE_SYS_LOCK_H
+
+/* Define if you have the <sys/modem.h> header file.  */
+#undef HAVE_SYS_MODEM_H
+
+/* Define if you have the <sys/ndir.h> header file.  */
+#undef HAVE_SYS_NDIR_H
+
+/* Define if you have the <sys/param.h> header file.  */
+#undef HAVE_SYS_PARAM_H
+
+/* Define if you have the <sys/select.h> header file.  */
+#undef HAVE_SYS_SELECT_H
+
+/* Define if you have the <sys/socket.h> header file.  */
+#ifdef USE_GUSI
+#define HAVE_SYS_SOCKET_H
+#endif
+
+/* Define if you have the <sys/time.h> header file.  */
+#ifdef USE_GUSI
+#define HAVE_SYS_TIME_H
+#endif
+
+/* Define if you have the <sys/times.h> header file.  */
+#undef HAVE_SYS_TIMES_H
+
+/* Define if you have the <sys/un.h> header file.  */
+#undef HAVE_SYS_UN_H
+
+/* Define if you have the <sys/utsname.h> header file.  */
+#undef HAVE_SYS_UTSNAME_H
+
+/* Define if you have the <sys/wait.h> header file.  */
+#undef HAVE_SYS_WAIT_H
+
+/* Define if you have the <termios.h> header file.  */
+#undef HAVE_TERMIOS_H
+
+/* Define if you have the <thread.h> header file.  */
+#undef HAVE_THREAD_H
+
+/* Define if you have the <unistd.h> header file.  */
+#define HAVE_UNISTD_H
+
+/* Define if you have the <utime.h> header file.  */
+#define HAVE_UTIME_H
+
+/* Define if you have the dl library (-ldl).  */
+#undef HAVE_LIBDL
+
+/* Define if you have the dld library (-ldld).  */
+#undef HAVE_LIBDLD
+
+/* Define if you have the ieee library (-lieee).  */
+#undef HAVE_LIBIEEE
+
+#ifdef __CYGWIN__
+#ifdef USE_DL_IMPORT
+#define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
+#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
+#else
+#define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
+#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
+#endif
+#endif

Mac/Include/macglue.h

+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Types.h>
+#include <Files.h>
+#include <Events.h>
+#include <StandardFile.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#ifdef __cplusplus
+	extern "C" {
+#endif
+
+/* Scheduler parameters */
+typedef struct {
+	int		check_interrupt;	/* if true check for command-dot */
+	int		process_events;		/* if nonzero enable evt processing, this mask */
+	int		besocial;		/* Be social, give up CPU now and again */
+	double		check_interval;		/* how often to check */
+	double		bg_yield;		/* yield at most so long when in background */
+} PyMacSchedParams;
+
+char *PyMac_getscript(void);	/* Get the default encoding for our 8bit character set */
+#ifdef USE_GUSI1
+void PyMac_FixGUSIcd(void);		/* Workaround for GUSI chdir() call */
+extern void PyMac_SetGUSISpin(void);		/* Install our private GUSI spin routine */
+#endif
+
+char *PyMac_StrError(int);			/* strerror with mac errors */
+PyObject *PyErr_Mac(PyObject *, int);		/* Exception with a mac error */
+PyObject *PyMac_Error(OSErr);			/* Uses PyMac_GetOSErrException */
+unsigned char *Pstring(char *str);		/* Convert c-string to pascal-string in static buffer */
+
+#ifdef USE_GUSI
+extern int PyMac_ConsoleIsDead;			/* True when exiting */
+extern void PyMac_StopGUSISpin(void);		/* Stop eventprocessing during exit() */
+#endif
+
+extern short PyMac_AppRefNum;			/* RefNum of application rsrcfork (from macmain.c) */
+extern FSSpec PyMac_ApplicationFSSpec;		/* Application location (from macargv.c) */
+extern char PyMac_ApplicationPath[];		/* Application location (from macargv.c) */
+extern OSErr PyMac_init_application_location(void);	/* Init the above */
+extern OSErr PyMac_GetFullPath(FSSpec *, char *); /* convert fsspec->path (macargv.c) */
+extern int PyMac_GetArgv(char ***, int);	/* Get argc, argv (from macargv.c) */
+extern int PyMac_AppearanceCompliant;	/* True if in appearance support mode */
+
+extern PyObject *PyMac_OSErrException;		/* Exception for OSErr */
+PyObject *PyMac_GetOSErrException(void);	/* Initialize & return it */
+
+#if !TARGET_API_MAC_OSX
+void PyMac_GetSchedParams(PyMacSchedParams *);	/* Get schedulers params */
+void PyMac_SetSchedParams(PyMacSchedParams *);	/* Set schedulers params */
+int PyMac_DoYield(int, int);	/* Yield cpu. First arg is maxtime, second ok to call python */
+#endif
+int PyMac_HandleEvent(EventRecord *);	/* Handle one event, possibly in Python */
+void PyMac_HandleEventIntern(EventRecord *); /* Handle one event internal only */
+int PyMac_SetEventHandler(PyObject *);	/* set python-coded event handler */
+
+#if !TARGET_API_MAC_OSX
+void PyMac_InitMenuBar(void);			/* Setup menu bar as we want it */
+void PyMac_RestoreMenuBar(void);		/* Restore menu bar for ease of exiting */
+void PyMac_RaiseConsoleWindow();		/* Bring console window to front, if it exists */
+#endif
+int PyMac_FindResourceModule(PyStringObject *, char *, char *); /* Test for 'PYC ' resource in a file */
+PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */
+int PyMac_FindCodeResourceModule(PyStringObject *, char *, char *); /* Test for 'PYD ' resource in a file */
+PyObject * PyMac_LoadCodeResourceModule(char *, char *); /* Load 'PYD ' resource from file */
+struct filedescr *PyMac_FindModuleExtension(char *, size_t *, char *); /* Look for module in single folder */
+
+#if TARGET_API_MAC_OS8
+int PyMac_GetDirectory(FSSpec *dirfss, char *prompt);		/* Ask user for a directory */
+void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList, 
+	StandardFileReply *reply, char *prompt);	/* Ask user for file, with prompt */
+#endif /* TARGET_API_MAC_OS8 */
+
+int PyMac_GetOSType(PyObject *, OSType *);	/* argument parser for OSType */
+PyObject *PyMac_BuildOSType(OSType);		/* Convert OSType to PyObject */
+
+PyObject *PyMac_BuildNumVersion(NumVersion);	/* Convert NumVersion to PyObject */
+
+int PyMac_GetStr255(PyObject *, Str255);	/* argument parser for Str255 */
+PyObject *PyMac_BuildStr255(Str255);		/* Convert Str255 to PyObject */
+PyObject *PyMac_BuildOptStr255(Str255);		/* Convert Str255 to PyObject, NULL to None */
+
+int PyMac_GetRect(PyObject *, Rect *);		/* argument parser for Rect */
+PyObject *PyMac_BuildRect(Rect *);		/* Convert Rect to PyObject */
+
+int PyMac_GetPoint(PyObject *, Point *);	/* argument parser for Point */
+PyObject *PyMac_BuildPoint(Point);		/* Convert Point to PyObject */
+
+int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for EventRecord */
+PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to PyObject */
+
+int PyMac_GetFixed(PyObject *, Fixed *);	/* argument parser for Fixed */
+PyObject *PyMac_BuildFixed(Fixed);			/* Convert Fixed to PyObject */
+int PyMac_Getwide(PyObject *, wide *);	/* argument parser for wide */
+PyObject *PyMac_Buildwide(wide *);			/* Convert wide to PyObject */
+void PyMac_InitApplet(void);			/* Initialize and run an Applet */
+void PyMac_Initialize(void);			/* Initialize function for embedding Python */
+
+#ifdef USE_GUSI2
+short PyMac_OpenPrefFile(void);			/* From macgetpath.c, open and return preference file */
+#endif
+
+/* from macfsmodule.c: */
+int PyMac_GetFSSpec(PyObject *, FSSpec *);	/* argument parser for FSSpec */
+PyObject *PyMac_BuildFSSpec(FSSpec *);		/* Convert FSSpec to PyObject */
+
+int PyMac_GetFSRef(PyObject *, FSRef *);	/* argument parser for FSRef */
+PyObject *PyMac_BuildFSRef(FSRef *);		/* Convert FSRef to PyObject */
+
+
+/* From macfiletype.c: */
+
+long PyMac_getfiletype(char *);			/* Get file type */
+int PyMac_setfiletype(char *, long, long);		/* Set file creator and type */
+
+/* from macmain.c: */
+void PyMac_Exit(int);
+void PyMac_InitApplication(void);
+void PyMac_OutputSeen(void);
+void PyMac_OutputNotSeen(void);
+int PyMac_GetDelayConsoleFlag(void);
+#ifdef USE_MAC_APPLET_SUPPORT
+void PyMac_InitApplet(void);
+#endif
+
+/* from macgetargv: */
+OSErr PyMac_init_process_location(void);
+#ifndef HAVE_STRDUP
+char *	strdup(const char *str);
+#endif
+
+#ifdef __cplusplus
+	}
+#endif

Mac/Lib/EasyDialogs.py

+"""Easy to use dialogs.
+
+Message(msg) -- display a message and an OK button.
+AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
+AskPassword(prompt, default) -- like AskString(), but shows text as bullets.
+AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
+bar = Progress(label, maxvalue) -- Display a progress bar
+bar.set(value) -- Set value
+bar.inc( *amount ) -- increment value by amount (default=1)
+bar.label( *newlabel ) -- get or set text label. 
+
+More documentation in each function.
+This module uses DLOG resources 260 and on.
+Based upon STDWIN dialogs with the same names and functions.
+"""
+
+from Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
+import Qd
+import QuickDraw
+import Dialogs
+import Windows
+import Dlg,Win,Evt,Events # sdm7g
+import Ctl
+import Controls
+import Menu
+import MacOS
+import string
+from ControlAccessor import *	# Also import Controls constants
+import macfs
+
+def cr2lf(text):
+	if '\r' in text:
+		text = string.join(string.split(text, '\r'), '\n')
+	return text
+
+def lf2cr(text):
+	if '\n' in text:
+		text = string.join(string.split(text, '\n'), '\r')
+	if len(text) > 253:
+		text = text[:253] + '\311'
+	return text
+
+def Message(msg, id=260, ok=None):
+	"""Display a MESSAGE string.
+	
+	Return when the user clicks the OK button or presses Return.
+	
+	The MESSAGE string can be at most 255 characters long.
+	"""
+	
+	d = GetNewDialog(id, -1)
+	if not d:
+		print "Can't get DLOG resource with id =", id
+		return
+	h = d.GetDialogItemAsControl(2)
+	SetDialogItemText(h, lf2cr(msg))
+	if ok != None:
+		h = d.GetDialogItemAsControl(1)
+		h.SetControlTitle(ok)
+	d.SetDialogDefaultItem(1)
+	d.AutoSizeDialog()
+	d.GetDialogWindow().ShowWindow()
+	while 1:
+		n = ModalDialog(None)
+		if n == 1:
+			return
+
+
+def AskString(prompt, default = "", id=261, ok=None, cancel=None):
+	"""Display a PROMPT string and a text entry field with a DEFAULT string.
+	
+	Return the contents of the text entry field when the user clicks the
+	OK button or presses Return.
+	Return None when the user clicks the Cancel button.
+	
+	If omitted, DEFAULT is empty.
+	
+	The PROMPT and DEFAULT strings, as well as the return value,
+	can be at most 255 characters long.
+	"""
+	
+	d = GetNewDialog(id, -1)
+	if not d:
+		print "Can't get DLOG resource with id =", id
+		return
+	h = d.GetDialogItemAsControl(3)
+	SetDialogItemText(h, lf2cr(prompt))
+	h = d.GetDialogItemAsControl(4)
+	SetDialogItemText(h, lf2cr(default))
+	d.SelectDialogItemText(4, 0, 999)
+#	d.SetDialogItem(4, 0, 255)
+	if ok != None:
+		h = d.GetDialogItemAsControl(1)
+		h.SetControlTitle(ok)
+	if cancel != None:
+		h = d.GetDialogItemAsControl(2)
+		h.SetControlTitle(cancel)
+	d.SetDialogDefaultItem(1)
+	d.SetDialogCancelItem(2)
+	d.AutoSizeDialog()
+	d.GetDialogWindow().ShowWindow()
+	while 1:
+		n = ModalDialog(None)
+		if n == 1:
+			h = d.GetDialogItemAsControl(4)
+			return cr2lf(GetDialogItemText(h))
+		if n == 2: return None
+
+def AskPassword(prompt,	 default='', id=264, ok=None, cancel=None):	
+	"""Display a PROMPT string and a text entry field with a DEFAULT string.
+	The string is displayed as bullets only.
+	
+	Return the contents of the text entry field when the user clicks the
+	OK button or presses Return.
+	Return None when the user clicks the Cancel button.
+	
+	If omitted, DEFAULT is empty.
+	
+	The PROMPT and DEFAULT strings, as well as the return value,
+	can be at most 255 characters long.
+	"""
+	d = GetNewDialog(id, -1)
+	if not d:
+		print "Can't get DLOG resource with id =", id
+		return
+	h = d.GetDialogItemAsControl(3)
+	SetDialogItemText(h, lf2cr(prompt))	
+	pwd = d.GetDialogItemAsControl(4)
+	bullets = '\245'*len(default)
+##	SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets)
+	SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag, default)
+	d.SelectDialogItemText(4, 0, 999)
+	Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart)
+	if ok != None:
+		h = d.GetDialogItemAsControl(1)
+		h.SetControlTitle(ok)
+	if cancel != None:
+		h = d.GetDialogItemAsControl(2)
+		h.SetControlTitle(cancel)
+	d.SetDialogDefaultItem(Dialogs.ok)
+	d.SetDialogCancelItem(Dialogs.cancel)
+	d.AutoSizeDialog()
+	d.GetDialogWindow().ShowWindow()
+	while 1:
+		n = ModalDialog(None)
+		if n == 1:
+			h = d.GetDialogItemAsControl(4)
+			return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag))
+		if n == 2: return None
+
+def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
+	"""Display a QUESTION string which can be answered with Yes or No.
+	
+	Return 1 when the user clicks the Yes button.
+	Return 0 when the user clicks the No button.
+	Return -1 when the user clicks the Cancel button.
+	
+	When the user presses Return, the DEFAULT value is returned.
+	If omitted, this is 0 (No).
+	
+	The QUESTION string can be at most 255 characters.
+	"""
+	
+	d = GetNewDialog(id, -1)
+	if not d:
+		print "Can't get DLOG resource with id =", id
+		return
+	# Button assignments:
+	# 1 = default (invisible)
+	# 2 = Yes
+	# 3 = No
+	# 4 = Cancel
+	# The question string is item 5
+	h = d.GetDialogItemAsControl(5)
+	SetDialogItemText(h, lf2cr(question))
+	if yes != None:
+		if yes == '':
+			d.HideDialogItem(2)
+		else:
+			h = d.GetDialogItemAsControl(2)
+			h.SetControlTitle(yes)
+	if no != None:
+		if no == '':
+			d.HideDialogItem(3)
+		else:
+			h = d.GetDialogItemAsControl(3)
+			h.SetControlTitle(no)
+	if cancel != None:
+		if cancel == '':
+			d.HideDialogItem(4)
+		else:
+			h = d.GetDialogItemAsControl(4)
+			h.SetControlTitle(cancel)
+	d.SetDialogCancelItem(4)
+	if default == 1:
+		d.SetDialogDefaultItem(2)
+	elif default == 0:
+		d.SetDialogDefaultItem(3)
+	elif default == -1:
+		d.SetDialogDefaultItem(4)
+	d.AutoSizeDialog()
+	d.GetDialogWindow().ShowWindow()
+	while 1:
+		n = ModalDialog(None)
+		if n == 1: return default
+		if n == 2: return 1
+		if n == 3: return 0
+		if n == 4: return -1
+
+
+		
+
+screenbounds = Qd.qd.screenBits.bounds
+screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
+	screenbounds[2]-4, screenbounds[3]-4
+
+				
+class ProgressBar:
+	def __init__(self, title="Working...", maxval=100, label="", id=263):
+		self.w = None
+		self.d = None
+		self.maxval = maxval
+		self.curval = -1
+		self.d = GetNewDialog(id, -1)
+		self.w = self.d.GetDialogWindow()
+		self.label(label)
+		self._update(0)
+		self.d.AutoSizeDialog()
+		self.title(title)
+		self.w.ShowWindow()
+		self.d.DrawDialog()
+
+	def __del__( self ):
+		if self.w:
+			self.w.BringToFront()
+			self.w.HideWindow()
+		del self.w
+		del self.d
+		
+	def title(self, newstr=""):
+		"""title(text) - Set title of progress window"""
+		self.w.BringToFront()
+		self.w.SetWTitle(newstr)
+		
+	def label( self, *newstr ):
+		"""label(text) - Set text in progress box"""
+		self.w.BringToFront()
+		if newstr:
+			self._label = lf2cr(newstr[0])
+		text_h = self.d.GetDialogItemAsControl(2)
+		SetDialogItemText(text_h, self._label)		
+				
+	def _update(self, value):
+		maxval = self.maxval
+		if maxval == 0:
+			# XXXX Quick fix. Should probably display an unknown duration
+			value = 0
+			maxval = 1
+		if maxval > 32767:
+			value = int(value/(maxval/32767.0))
+			maxval = 32767
+		progbar = self.d.GetDialogItemAsControl(3)
+		progbar.SetControlMaximum(maxval)
+		progbar.SetControlValue(value)	
+		# Test for cancel button
+		
+		ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1  )
+		if ready : 
+			what,msg,when,where,mod = ev
+			part = Win.FindWindow(where)[0]
+			if Dlg.IsDialogEvent(ev):
+				ds = Dlg.DialogSelect(ev)
+				if ds[0] and ds[1] == self.d and ds[-1] == 1:
+					self.w.HideWindow()
+					self.w = None
+					self.d = None
+					raise KeyboardInterrupt, ev
+			else:
+				if part == 4:	# inDrag 
+					self.d.DragWindow(where, screenbounds)
+				else:
+					MacOS.HandleEvent(ev) 
+			
+			
+	def set(self, value, max=None):
+		"""set(value) - Set progress bar position"""
+		if max != None:
+			self.maxval = max
+		if value < 0: value = 0
+		if value > self.maxval: value = self.maxval
+		self.curval = value
+		self._update(value)
+
+	def inc(self, n=1):
+		"""inc(amt) - Increment progress bar position"""
+		self.set(self.curval + n)
+
+ARGV_ID=265
+ARGV_ITEM_OK=1
+ARGV_ITEM_CANCEL=2
+ARGV_OPTION_GROUP=3
+ARGV_OPTION_EXPLAIN=4
+ARGV_OPTION_VALUE=5
+ARGV_OPTION_ADD=6
+ARGV_COMMAND_GROUP=7
+ARGV_COMMAND_EXPLAIN=8
+ARGV_COMMAND_ADD=9
+ARGV_ADD_OLDFILE=10
+ARGV_ADD_NEWFILE=11
+ARGV_ADD_FOLDER=12
+ARGV_CMDLINE_GROUP=13
+ARGV_CMDLINE_DATA=14
+
+##def _myModalDialog(d):
+##	while 1:
+##		ready, ev = Evt.WaitNextEvent(0xffff, -1)
+##		print 'DBG: WNE', ready, ev
+##		if ready : 
+##			what,msg,when,where,mod = ev
+##			part, window = Win.FindWindow(where)
+##			if Dlg.IsDialogEvent(ev):
+##				didit, dlgdone, itemdone = Dlg.DialogSelect(ev)
+##				print 'DBG: DialogSelect', didit, dlgdone, itemdone, d
+##				if didit and dlgdone == d:
+##					return itemdone
+##			elif window == d.GetDialogWindow():
+##				d.GetDialogWindow().SelectWindow()
+##				if part == 4:	# inDrag 
+##						d.DragWindow(where, screenbounds)
+##				else:
+##					MacOS.HandleEvent(ev) 
+##			else:
+##				MacOS.HandleEvent(ev) 
+##
+def _setmenu(control, items):
+		mhandle = control.GetControlData_Handle(Controls.kControlMenuPart,
+				Controls.kControlPopupButtonMenuHandleTag)
+		menu = Menu.as_Menu(mhandle)
+		for item in items:
+			if type(item) == type(()):
+				label = item[0]
+			else:
+				label = item
+			if label[-1] == '=' or label[-1] == ':':
+				label = label[:-1]
+			menu.AppendMenu(label)
+##		mhandle, mid = menu.getpopupinfo()
+##		control.SetControlData_Handle(Controls.kControlMenuPart,
+##				Controls.kControlPopupButtonMenuHandleTag, mhandle)
+		control.SetControlMinimum(1)
+		control.SetControlMaximum(len(items)+1)
+		
+def _selectoption(d, optionlist, idx):
+	if idx < 0 or idx >= len(optionlist):
+		MacOS.SysBeep()
+		return
+	option = optionlist[idx]
+	if type(option) == type(()) and \
+			len(option) > 1:
+		help = option[-1]
+	else:
+		help = ''
+	h = d.GetDialogItemAsControl(ARGV_OPTION_EXPLAIN)
+	Dlg.SetDialogItemText(h, help)
+	hasvalue = 0
+	if type(option) == type(()):
+		label = option[0]
+	else:
+		label = option
+	if label[-1] == '=' or label[-1] == ':':
+		hasvalue = 1
+	h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
+	Dlg.SetDialogItemText(h, '')
+	if hasvalue:
+		d.ShowDialogItem(ARGV_OPTION_VALUE)
+		d.SelectDialogItemText(ARGV_OPTION_VALUE, 0, 0)
+	else:
+		d.HideDialogItem(ARGV_OPTION_VALUE)
+
+
+def GetArgv(optionlist=None, commandlist=None, addoldfile=1, addnewfile=1, addfolder=1, id=ARGV_ID):
+	d = GetNewDialog(id, -1)
+	if not d:
+		print "Can't get DLOG resource with id =", id
+		return
+#	h = d.GetDialogItemAsControl(3)
+#	SetDialogItemText(h, lf2cr(prompt))
+#	h = d.GetDialogItemAsControl(4)
+#	SetDialogItemText(h, lf2cr(default))
+#	d.SelectDialogItemText(4, 0, 999)
+#	d.SetDialogItem(4, 0, 255)
+	if optionlist:
+		_setmenu(d.GetDialogItemAsControl(ARGV_OPTION_GROUP), optionlist)
+		_selectoption(d, optionlist, 0)
+	else:
+		d.GetDialogItemAsControl(ARGV_OPTION_GROUP).DeactivateControl()
+	if commandlist:
+		_setmenu(d.GetDialogItemAsControl(ARGV_COMMAND_GROUP), commandlist)
+		if type(commandlist[0]) == type(()) and len(commandlist[0]) > 1:
+			help = commandlist[0][-1]
+			h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
+			Dlg.SetDialogItemText(h, help)
+	else:
+		d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).DeactivateControl()
+	if not addoldfile:
+		d.GetDialogItemAsControl(ARGV_ADD_OLDFILE).DeactivateControl()
+	if not addnewfile:
+		d.GetDialogItemAsControl(ARGV_ADD_NEWFILE).DeactivateControl()
+	if not addfolder:
+		d.GetDialogItemAsControl(ARGV_ADD_FOLDER).DeactivateControl()
+	d.SetDialogDefaultItem(ARGV_ITEM_OK)
+	d.SetDialogCancelItem(ARGV_ITEM_CANCEL)
+	d.GetDialogWindow().ShowWindow()
+	d.DrawDialog()
+	appsw = MacOS.SchedParams(1, 0)
+	try:
+		while 1:
+			stringstoadd = []
+			n = ModalDialog(None)
+			if n == ARGV_ITEM_OK:
+				break
+			elif n == ARGV_ITEM_CANCEL:
+				raise SystemExit
+			elif n == ARGV_OPTION_GROUP:
+				idx = d.GetDialogItemAsControl(ARGV_OPTION_GROUP).GetControlValue()-1
+				_selectoption(d, optionlist, idx)
+			elif n == ARGV_OPTION_VALUE:
+				pass
+			elif n == ARGV_OPTION_ADD:
+				idx = d.GetDialogItemAsControl(ARGV_OPTION_GROUP).GetControlValue()-1
+				if 0 <= idx < len(optionlist):
+					option = optionlist[idx]
+					if type(option) == type(()):
+						option = option[0]
+					if option[-1] == '=' or option[-1] == ':':
+						option = option[:-1]
+						h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE)
+						value = Dlg.GetDialogItemText(h)
+					else:
+						value = ''
+					if len(option) == 1:
+						stringtoadd = '-' + option
+					else:
+						stringtoadd = '--' + option
+					stringstoadd = [stringtoadd]
+					if value:
+						stringstoadd.append(value)
+				else:
+					MacOS.SysBeep()
+			elif n == ARGV_COMMAND_GROUP:
+				idx = d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).GetControlValue()-1
+				if 0 <= idx < len(commandlist) and type(commandlist[idx]) == type(()) and \
+						len(commandlist[idx]) > 1:
+					help = commandlist[idx][-1]
+					h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN)
+					Dlg.SetDialogItemText(h, help)
+			elif n == ARGV_COMMAND_ADD:
+				idx = d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).GetControlValue()-1
+				if 0 <= idx < len(commandlist):
+					command = commandlist[idx]
+					if type(command) == type(()):
+						command = command[0]
+					stringstoadd = [command]
+				else:
+					MacOS.SysBeep()
+			elif n == ARGV_ADD_OLDFILE:
+				fss, ok = macfs.StandardGetFile()
+				if ok:
+					stringstoadd = [fss.as_pathname()]
+			elif n == ARGV_ADD_NEWFILE:
+				fss, ok = macfs.StandardPutFile('')
+				if ok:
+					stringstoadd = [fss.as_pathname()]
+			elif n == ARGV_ADD_FOLDER:
+				fss, ok = macfs.GetDirectory()
+				if ok:
+					stringstoadd = [fss.as_pathname()]
+			elif n == ARGV_CMDLINE_DATA:
+				pass # Nothing to do
+			else:
+				raise RuntimeError, "Unknown dialog item %d"%n
+			
+			for stringtoadd in stringstoadd:
+				if '"' in stringtoadd or "'" in stringtoadd or " " in stringtoadd:
+					stringtoadd = `stringtoadd`
+				h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
+				oldstr = GetDialogItemText(h)
+				if oldstr and oldstr[-1] != ' ':
+					oldstr = oldstr + ' '
+				oldstr = oldstr + stringtoadd
+				if oldstr[-1] != ' ':
+					oldstr = oldstr + ' '
+				SetDialogItemText(h, oldstr)
+				d.SelectDialogItemText(ARGV_CMDLINE_DATA, 0x7fff, 0x7fff)
+		h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA)
+		oldstr = GetDialogItemText(h)
+		tmplist = string.split(oldstr)
+		newlist = []
+		while tmplist:
+			item = tmplist[0]
+			del tmplist[0]
+			if item[0] == '"':
+				while item[-1] != '"':
+					if not tmplist:
+						raise RuntimeError, "Unterminated quoted argument"
+					item = item + ' ' + tmplist[0]
+					del tmplist[0]
+				item = item[1:-1]
+			if item[0] == "'":
+				while item[-1] != "'":
+					if not tmplist:
+						raise RuntimeError, "Unterminated quoted argument"
+					item = item + ' ' + tmplist[0]
+					del tmplist[0]
+				item = item[1:-1]
+			newlist.append(item)
+		return newlist
+	finally:
+		apply(MacOS.SchedParams, appsw)
+		del d
+	
+def test():
+	import time, sys
+
+	Message("Testing EasyDialogs.")
+	optionlist = (('v', 'Verbose'), ('verbose', 'Verbose as long option'), 
+				('flags=', 'Valued option'), ('f:', 'Short valued option'))
+	commandlist = (('start', 'Start something'), ('stop', 'Stop something'))
+	argv = GetArgv(optionlist=optionlist, commandlist=commandlist, addoldfile=0)
+	for i in range(len(argv)):
+		print 'arg[%d] = %s'%(i, `argv[i]`)
+	print 'Type return to continue - ',
+	sys.stdin.readline()
+	ok = AskYesNoCancel("Do you want to proceed?")
+	ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No")
+	if ok > 0:
+		s = AskString("Enter your first name", "Joe")
+		s2 = AskPassword("Okay %s, tell us your nickname"%s, s, cancel="None")
+		if not s2:
+			Message("%s has no secret nickname"%s)
+		else:
+			Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
+	text = ( "Working Hard...", "Hardly Working..." , 
+			"So far, so good!", "Keep on truckin'" )
+	bar = ProgressBar("Progress, progress...", 100)
+	try:
+		appsw = MacOS.SchedParams(1, 0)
+		for i in range(100):
+			bar.set(i)
+			time.sleep(0.1)
+			if i % 10 == 0:
+				bar.label(text[(i/10) % 4])
+		bar.label("Done.")
+		time.sleep(0.3) 	# give'em a chance to see the done.
+	finally:
+		del bar
+		apply(MacOS.SchedParams, appsw)
+
+if __name__ == '__main__':
+	try:
+		test()
+	except KeyboardInterrupt:
+		Message("Operation Canceled.")
+

Mac/Modules/macfsmodule.c

+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+#include "Python.h"
+#include "macglue.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <Memory.h>
+#include <Files.h>
+#include <Folders.h>
+#include <StandardFile.h>
+#include <Aliases.h>
+#include <LowMem.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#include "getapplbycreator.h"
+
+
+static PyObject *ErrorObject;
+
+/* ----------------------------------------------------- */
+/* Declarations for objects of type Alias */
+
+typedef struct {
+	PyObject_HEAD
+	AliasHandle alias;
+} mfsaobject;
+
+staticforward PyTypeObject Mfsatype;
+
+#define is_mfsaobject(v)		((v)->ob_type == &Mfsatype)
+
+/* ---------------------------------------------------------------- */
+/* Declarations for objects of type FSSpec */
+
+typedef struct {
+	PyObject_HEAD
+	FSSpec fsspec;
+} mfssobject;
+
+staticforward PyTypeObject Mfsstype;
+
+#define is_mfssobject(v)		((v)->ob_type == &Mfsstype)
+
+/* ---------------------------------------------------------------- */
+/* Declarations for objects of type FSRef */
+
+typedef struct {
+	PyObject_HEAD
+	FSRef fsref;
+} mfsrobject;
+
+staticforward PyTypeObject Mfsrtype;
+
+#define is_mfsrobject(v)		((v)->ob_type == &Mfsrtype)
+
+
+/* ---------------------------------------------------------------- */
+/* Declarations for objects of type FInfo */
+
+typedef struct {
+	PyObject_HEAD
+	FInfo finfo;
+} mfsiobject;
+
+staticforward PyTypeObject Mfsitype;
+
+#define is_mfsiobject(v)		((v)->ob_type == &Mfsitype)
+
+
+staticforward mfssobject *newmfssobject(FSSpec *fss); /* Forward */
+staticforward mfsrobject *newmfsrobject(FSRef *fsr); /* Forward */
+
+/* ---------------------------------------------------------------- */
+
+static PyObject *
+mfsa_Resolve(self, args)
+	mfsaobject *self;
+	PyObject *args;
+{
+	FSSpec from, *fromp, result;
+	Boolean changed;
+	OSErr err;
+	
+	from.name[0] = 0;
+	if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
+		return NULL;
+	if (from.name[0] )
+		fromp = &from;
+	else
+		fromp = NULL;
+	err = ResolveAlias(fromp, self->alias, &result, &changed);
+	if ( err && err != fnfErr ) {
+		PyErr_Mac(ErrorObject, err);
+		return NULL;
+	}
+	return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
+}
+
+static PyObject *
+mfsa_GetInfo(self, args)
+	mfsaobject *self;
+	PyObject *args;
+{
+	Str63 value;
+	int i;
+	OSErr err;
+	
+	if (!PyArg_ParseTuple(args, "i", &i))
+		return NULL;
+	err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
+	if ( err ) {
+		PyErr_Mac(ErrorObject, err);
+		return 0;
+	}
+	return PyString_FromStringAndSize((char *)&value[1], value[0]);
+}
+
+static PyObject *
+mfsa_Update(self, args)
+	mfsaobject *self;
+	PyObject *args;
+{
+	FSSpec target, fromfile, *fromfilep;
+	OSErr err;
+	Boolean changed;
+	
+	fromfile.name[0] = 0;
+	if (!PyArg_ParseTuple(args, "O&|O&",  PyMac_GetFSSpec, &target,
+					 PyMac_GetFSSpec, &fromfile))
+		return NULL;
+	if ( fromfile.name[0] )
+		fromfilep = &fromfile;
+	else
+		fromfilep = NULL;
+	err = UpdateAlias(fromfilep, &target, self->alias, &changed);
+	if ( err ) {
+		PyErr_Mac(ErrorObject, err);
+		return 0;
+	}
+	return Py_BuildValue("i", (int)changed);
+}
+
+static struct PyMethodDef mfsa_methods[] = {
+	{"Resolve",	(PyCFunction)mfsa_Resolve,	1},
+	{"GetInfo",	(PyCFunction)mfsa_GetInfo,	1},
+	{"Update",	(PyCFunction)mfsa_Update,	1},
+ 
+	{NULL,		NULL}		/* sentinel */
+};
+
+/* ---------- */
+
+static PyObject *
+mfsa_getattr(self, name)
+	mfsaobject *self;
+	char *name;
+{
+	if ( strcmp(name, "data") == 0 ) {
+		int size;
+		PyObject *rv;
+		
+		size = GetHandleSize((Handle)self->alias);
+		HLock((Handle)self->alias);
+		rv = PyString_FromStringAndSize(*(Handle)self->alias, size);
+		HUnlock((Handle)self->alias);
+		return rv;
+	}
+	return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
+}
+
+static mfsaobject *
+newmfsaobject(AliasHandle alias)
+{
+	mfsaobject *self;
+
+	self = PyObject_NEW(mfsaobject, &Mfsatype);
+	if (self == NULL)
+		return NULL;
+	self->alias = alias;
+	return self;
+}
+
+
+static void
+mfsa_dealloc(self)
+	mfsaobject *self;
+{
+#if 0
+	if ( self->alias ) {
+		should we do something here?
+	}
+#endif
+		
+	PyMem_DEL(self);
+}
+
+statichere PyTypeObject Mfsatype = {
+	PyObject_HEAD_INIT(&PyType_Type)
+	0,				/*ob_size*/
+	"Alias",			/*tp_name*/
+	sizeof(mfsaobject),		/*tp_basicsize*/
+	0,				/*tp_itemsize*/
+	/* methods */
+	(destructor)mfsa_dealloc,	/*tp_dealloc*/
+	(printfunc)0,			/*tp_print*/
+	(getattrfunc)mfsa_getattr,	/*tp_getattr*/
+	(setattrfunc)0,			/*tp_setattr*/
+	(cmpfunc)0,			/*tp_compare*/
+	(reprfunc)0,			/*tp_repr*/
+	0,				/*tp_as_number*/
+	0,				/*tp_as_sequence*/
+	0,				/*tp_as_mapping*/
+	(hashfunc)0,			/*tp_hash*/
+};
+
+/* End of code for Alias objects */
+/* -------------------------------------------------------- */
+
+/* ---------------------------------------------------------------- */
+
+static struct PyMethodDef mfsi_methods[] = {
+	
+	{NULL,		NULL}		/* sentinel */
+};
+
+/* ---------- */
+
+static mfsiobject *
+newmfsiobject()
+{
+	mfsiobject *self;
+	
+	self = PyObject_NEW(mfsiobject, &Mfsitype);
+	if (self == NULL)
+		return NULL;
+	memset((char *)&self->finfo, '\0', sizeof(self->finfo));
+	return self;
+}
+
+static void
+mfsi_dealloc(self)
+	mfsiobject *self;
+{
+	PyMem_DEL(self);
+}
+
+static PyObject *
+mfsi_getattr(self, name)
+	mfsiobject *self;
+	char *name;
+{
+	if ( strcmp(name, "Type") == 0 )
+		return PyMac_BuildOSType(self->finfo.fdType);
+	else if ( strcmp(name, "Creator") == 0 )
+		return PyMac_BuildOSType(self->finfo.fdCreator);
+	else if ( strcmp(name, "Flags") == 0 )
+		return Py_BuildValue("i", (int)self->finfo.fdFlags);
+	else if ( strcmp(name, "Location") == 0 )
+		return PyMac_BuildPoint(self->finfo.fdLocation);
+	else if ( strcmp(name, "Fldr") == 0 )
+		return Py_BuildValue("i", (int)self->finfo.fdFldr);
+	else
+		return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
+}
+
+
+static int
+mfsi_setattr(self, name, v)
+	mfsiobject *self;
+	char *name;
+	PyObject *v;
+{
+	int rv;
+	int i;
+	
+	if ( v == NULL ) {
+		PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
+		return -1;
+	}
+	if ( strcmp(name, "Type") == 0 )
+		rv = PyMac_GetOSType(v, &self->finfo.fdType);
+	else if ( strcmp(name, "Creator") == 0 )
+		rv = PyMac_GetOSType(v, &self->finfo.fdCreator);
+	else if ( strcmp(name, "Flags") == 0 ) {
+		rv = PyArg_Parse(v, "i", &i);
+		self->finfo.fdFlags = (short)i;
+	} else if ( strcmp(name, "Location") == 0 )
+		rv = PyMac_GetPoint(v, &self->finfo.fdLocation);
+	else if ( strcmp(name, "Fldr") == 0 ) {
+		rv = PyArg_Parse(v, "i", &i);
+		self->finfo.fdFldr = (short)i;
+	} else {
+		PyErr_SetString(PyExc_AttributeError, "No such attribute");
+		return -1;
+	}
+	if (rv)
+		return 0;
+	return -1;
+}
+
+
+static PyTypeObject Mfsitype = {
+	PyObject_HEAD_INIT(&PyType_Type)
+	0,				/*ob_size*/
+	"FInfo",			/*tp_name*/
+	sizeof(mfsiobject),		/*tp_basicsize*/
+	0,				/*tp_itemsize*/
+	/* methods */
+	(destructor)mfsi_dealloc,	/*tp_dealloc*/
+	(printfunc)0,		/*tp_print*/
+	(getattrfunc)mfsi_getattr,	/*tp_getattr*/
+	(setattrfunc)mfsi_setattr,	/*tp_setattr*/
+	(cmpfunc)0,		/*tp_compare*/
+	(reprfunc)0,		/*tp_repr*/
+	0,			/*tp_as_number*/
+	0,		/*tp_as_sequence*/
+	0,		/*tp_as_mapping*/
+	(hashfunc)0,		/*tp_hash*/
+};
+
+/* End of code for FInfo object objects */
+/* -------------------------------------------------------- */
+
+
+/*
+** Helper routines for the FSRef and FSSpec creators in macglue.c
+** They return an FSSpec/FSRef if the Python object encapsulating
+** either is passed. They return a boolean success indicator.
+** Note that they do not set an exception on failure, they're only
+** helper routines.
+*/
+static int
+_mfs_GetFSSpecFromFSSpec(PyObject *self, FSSpec *fssp)
+{
+	if ( is_mfssobject(self) ) {
+		*fssp = ((mfssobject *)self)->fsspec;
+		return 1;
+	}
+	return 0;
+}
+
+/* Return an FSSpec if this is an FSref */
+static int