Kaydet (Commit) 1a2d894b authored tarafından cvs2svn's avatar cvs2svn

This commit was manufactured by cvs2svn to create branch

'release21-maint'.
üst 6dc482cf
# 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()
"""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()
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
\ No newline at end of file
This diff is collapsed.
/***********************************************************
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
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import macfs
import marshal
import types
from MACFS import kOnSystemDisk
class PrefObject:
def __init__(self, dict = None):
if dict == None:
self._prefsdict = {}
else:
self._prefsdict = dict
def __len__(self):
return len(self._prefsdict)
def __delattr__(self, attr):
if self._prefsdict.has_key(attr):
del self._prefsdict[attr]
else:
raise AttributeError, 'delete non-existing instance attribute'
def __getattr__(self, attr):
if attr == '__members__':
keys = self._prefsdict.keys()
keys.sort()
return keys
try:
return self._prefsdict[attr]
except KeyError:
raise AttributeError, attr
def __setattr__(self, attr, value):
if attr[0] <> '_':
self._prefsdict[attr] = value
else:
self.__dict__[attr] = value
def getprefsdict(self):
return self._prefsdict
class PrefFile(PrefObject):
def __init__(self, path, creator = 'Pyth'):
# Find the preferences folder and our prefs file, create if needed.
self.__path = path
self.__creator = creator
self._prefsdict = {}
try:
prefdict = marshal.load(open(self.__path, 'rb'))
except (IOError, ValueError):
# file not found, or currupt marshal data
pass
else:
for key, value in prefdict.items():
if type(value) == types.DictType:
self._prefsdict[key] = PrefObject(value)
else:
self._prefsdict[key] = value
def save(self):
prefdict = {}
for key, value in self._prefsdict.items():
if type(value) == types.InstanceType:
prefdict[key] = value.getprefsdict()
if not prefdict[key]:
del prefdict[key]
else:
prefdict[key] = value
marshal.dump(prefdict, open(self.__path, 'wb'))
fss = macfs.FSSpec(self.__path)
fss.SetCreatorType(self.__creator, 'pref')
def __getattr__(self, attr):
if attr == '__members__':
keys = self._prefsdict.keys()
keys.sort()
return keys
try:
return self._prefsdict[attr]
except KeyError:
if attr[0] <> '_':
self._prefsdict[attr] = PrefObject()
return self._prefsdict[attr]
else:
raise AttributeError, attr
_prefscache = {}
def GetPrefs(prefname, creator = 'Pyth'):
import macostools, os
if _prefscache.has_key(prefname):
return _prefscache[prefname]
# Find the preferences folder and our prefs file, create if needed.
vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0)
prefsfolder_fss = macfs.FSSpec((vrefnum, dirid, ''))
prefsfolder = prefsfolder_fss.as_pathname()
path = os.path.join(prefsfolder, prefname)
head, tail = os.path.split(path)
# make sure the folder(s) exist
macostools.mkdirs(head)
preffile = PrefFile(path, creator)
_prefscache[prefname] = preffile
return preffile
This diff is collapsed.
This diff is collapsed.
"""Module to analyze Python source code; for syntax coloring tools.
Interface:
tags = fontify(pytext, searchfrom, searchto)
The 'pytext' argument is a string containing Python source code.
The (optional) arguments 'searchfrom' and 'searchto' may contain a slice in pytext.
The returned value is a list of tuples, formatted like this:
[('keyword', 0, 6, None), ('keyword', 11, 17, None), ('comment', 23, 53, None), etc. ]
The tuple contents are always like this:
(tag, startindex, endindex, sublist)
tag is one of 'keyword', 'string', 'comment' or 'identifier'
sublist is not used, hence always None.
"""
# Based on FontText.py by Mitchell S. Chapman,
# which was modified by Zachary Roadhouse,
# then un-Tk'd by Just van Rossum.
# Many thanks for regular expression debugging & authoring are due to:
# Tim (the-incredib-ly y'rs) Peters and Cristian Tismer
# So, who owns the copyright? ;-) How about this:
# Copyright 1996-2001:
# Mitchell S. Chapman,
# Zachary Roadhouse,
# Tim Peters,
# Just van Rossum
__version__ = "0.4"
import string
import re
# First a little helper, since I don't like to repeat things. (Tismer speaking)
import string
def replace(where, what, with):
return string.join(string.split(where, what), with)
# This list of keywords is taken from ref/node13.html of the
# Python 1.3 HTML documentation. ("access" is intentionally omitted.)
keywordsList = [
"assert", "exec",
"del", "from", "lambda", "return",
"and", "elif", "global", "not", "try",
"break", "else", "if", "or", "while",
"class", "except", "import", "pass",
"continue", "finally", "in", "print",
"def", "for", "is", "raise", "yield"]
# Build up a regular expression which will match anything
# interesting, including multi-line triple-quoted strings.
commentPat = r"#[^\n]*"
pat = r"q[^\\q\n]*(\\[\000-\377][^\\q\n]*)*q"
quotePat = replace(pat, "q", "'") + "|" + replace(pat, 'q', '"')
# Way to go, Tim!
pat = r"""
qqq
[^\\q]*
(
( \\[\000-\377]
| q
( \\[\000-\377]
| [^\q]
| q
( \\[\000-\377]
| [^\\q]
)
)
)
[^\\q]*
)*
qqq
"""
pat = string.join(string.split(pat), '') # get rid of whitespace
tripleQuotePat = replace(pat, "q", "'") + "|" + replace(pat, 'q', '"')
# Build up a regular expression which matches all and only
# Python keywords. This will let us skip the uninteresting
# identifier references.
# nonKeyPat identifies characters which may legally precede
# a keyword pattern.
nonKeyPat = r"(^|[^a-zA-Z0-9_.\"'])"
keyPat = nonKeyPat + "(" + "|".join(keywordsList) + ")" + nonKeyPat
matchPat = commentPat + "|" + keyPat + "|" + tripleQuotePat + "|" + quotePat
matchRE = re.compile(matchPat)
idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*" # Ident w. leading whitespace.
idRE = re.compile(idKeyPat)
def fontify(pytext, searchfrom = 0, searchto = None):
if searchto is None:
searchto = len(pytext)
# Cache a few attributes for quicker reference.
search = matchRE.search
idSearch = idRE.search
tags = []
tags_append = tags.append
commentTag = 'comment'
stringTag = 'string'
keywordTag = 'keyword'
identifierTag = 'identifier'
start = 0
end = searchfrom
while 1:
m = search(pytext, end)
if m is None:
break # EXIT LOOP
start = m.start()
if start >= searchto:
break # EXIT LOOP
match = m.group(0)
end = start + len(match)
c = match[0]
if c not in "#'\"":
# Must have matched a keyword.
if start <> searchfrom:
# there's still a redundant char before and after it, strip!
match = match[1:-1]
start = start + 1
else:
# this is the first keyword in the text.
# Only a space at the end.
match = match[:-1]
end = end - 1
tags_append((keywordTag, start, end, None))
# If this was a defining keyword, look ahead to the
# following identifier.
if match in ["def", "class"]:
m = idSearch(pytext, end)
if m is not None:
start = m.start()
if start == end:
match = m.group(0)
end = start + len(match)
tags_append((identifierTag, start, end, None))
elif c == "#":
tags_append((commentTag, start, end, None))
else:
tags_append((stringTag, start, end, None))
return tags
def test(path):
f = open(path)
text = f.read()
f.close()
tags = fontify(text)
for tag, start, end, sublist in tags:
print tag, `text[start:end]`
This diff is collapsed.
This diff is collapsed.
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