[Python-checkins] r54966 - in sandbox/trunk: 2to3/fixes/fix_intern.py 2to3/fixes/fix_numliterals.py Doc/2.5-pr.txt Doc/func-example.py decimal-c/README.txt decimal-c/_decimal.c decimal-c/decimal.h decimal-c/decimal.py decimal-c/setup.py decimal-c/test_decimal.py hotbuffer/Modules/_hotbuf.c import_in_py/importbench.py mailbox/mailbox-msg-lockfix.py pdb/Doc/tools/buildindex.py pdb/Doc/tools/indfix.py pdb/Doc/tools/patchlevel.h pdb/Doc/tools/toc2bkm.py pdb/README.txt pdb/mconnection.py pdb/mpdb.py pdb/mproc.py pdb/mqueue.py pdb/mremote.py pdb/mthread.py pdb/patches/11-08-06-sigtestexample.py pdb/patches/27-07-06-sighandler.py pdb/patches/30-05-06-pdb.py pdb/patches/31-07-06-sighandler.py pdb/patches/31-07-06-test.py pdb/pdbserver.py pdb/test/files/proc.py pdb/test/files/thread_script.py pdb/test/support.py pdb/test/test_mconnection.py pdb/test/test_mpdb.py pdb/test/test_mthread.py pdb/test/test_process.py pep3101/README.txt pep3101/StringFormat.py pep3101/doctests/README.txt pep3101/doctests/basic_errors.txt pep3101/doctests/basic_examples.txt pep3101/doctests/basic_torture.txt pep3101/doctests/test.py pep3101/loadpep.py pep3101/pep3101.c pep3101/pep3101.h pep3101/pep_differences.txt pep3101/setup.py pep3101/stringformat.c pep3101/test_simpleformat.py pep3101/unicodeformat.c refactor/concrete.py refactor/example.py refactor/has_key.py rjsh-pybench/Empty.py rjsh-pybench/NewInstances.py seealso/convert-python-faqs.py seealso/make-seealso.py seealso/parse-seealso.py setuptools/setuptools/tests/win_script_wrapper.txt stringbench/stringbench.py tests/test_sax.py tests/test_saxgen.py trackers/trackers.txt welease/README.txt welease/welease.py
guido.van.rossum
python-checkins at python.org
Wed Apr 25 21:51:57 CEST 2007
Author: guido.van.rossum
Date: Wed Apr 25 21:51:51 2007
New Revision: 54966
Modified:
sandbox/trunk/2to3/fixes/fix_intern.py (props changed)
sandbox/trunk/2to3/fixes/fix_numliterals.py (props changed)
sandbox/trunk/Doc/2.5-pr.txt (props changed)
sandbox/trunk/Doc/func-example.py (props changed)
sandbox/trunk/decimal-c/README.txt (props changed)
sandbox/trunk/decimal-c/_decimal.c (props changed)
sandbox/trunk/decimal-c/decimal.h (props changed)
sandbox/trunk/decimal-c/decimal.py (props changed)
sandbox/trunk/decimal-c/setup.py (props changed)
sandbox/trunk/decimal-c/test_decimal.py (props changed)
sandbox/trunk/hotbuffer/Modules/_hotbuf.c (props changed)
sandbox/trunk/import_in_py/importbench.py (props changed)
sandbox/trunk/mailbox/mailbox-msg-lockfix.py (props changed)
sandbox/trunk/pdb/Doc/tools/buildindex.py (props changed)
sandbox/trunk/pdb/Doc/tools/indfix.py (props changed)
sandbox/trunk/pdb/Doc/tools/patchlevel.h (props changed)
sandbox/trunk/pdb/Doc/tools/toc2bkm.py (props changed)
sandbox/trunk/pdb/README.txt (contents, props changed)
sandbox/trunk/pdb/mconnection.py (contents, props changed)
sandbox/trunk/pdb/mpdb.py (props changed)
sandbox/trunk/pdb/mproc.py (props changed)
sandbox/trunk/pdb/mqueue.py (props changed)
sandbox/trunk/pdb/mremote.py (props changed)
sandbox/trunk/pdb/mthread.py (props changed)
sandbox/trunk/pdb/patches/11-08-06-sigtestexample.py (props changed)
sandbox/trunk/pdb/patches/27-07-06-sighandler.py (props changed)
sandbox/trunk/pdb/patches/30-05-06-pdb.py (props changed)
sandbox/trunk/pdb/patches/31-07-06-sighandler.py (props changed)
sandbox/trunk/pdb/patches/31-07-06-test.py (props changed)
sandbox/trunk/pdb/pdbserver.py (props changed)
sandbox/trunk/pdb/test/files/proc.py (props changed)
sandbox/trunk/pdb/test/files/thread_script.py (props changed)
sandbox/trunk/pdb/test/support.py (props changed)
sandbox/trunk/pdb/test/test_mconnection.py (props changed)
sandbox/trunk/pdb/test/test_mpdb.py (props changed)
sandbox/trunk/pdb/test/test_mthread.py (props changed)
sandbox/trunk/pdb/test/test_process.py (props changed)
sandbox/trunk/pep3101/README.txt (props changed)
sandbox/trunk/pep3101/StringFormat.py (props changed)
sandbox/trunk/pep3101/doctests/README.txt (props changed)
sandbox/trunk/pep3101/doctests/basic_errors.txt (props changed)
sandbox/trunk/pep3101/doctests/basic_examples.txt (props changed)
sandbox/trunk/pep3101/doctests/basic_torture.txt (props changed)
sandbox/trunk/pep3101/doctests/test.py (props changed)
sandbox/trunk/pep3101/loadpep.py (props changed)
sandbox/trunk/pep3101/pep3101.c (props changed)
sandbox/trunk/pep3101/pep3101.h (props changed)
sandbox/trunk/pep3101/pep_differences.txt (props changed)
sandbox/trunk/pep3101/setup.py (props changed)
sandbox/trunk/pep3101/stringformat.c (props changed)
sandbox/trunk/pep3101/test_simpleformat.py (props changed)
sandbox/trunk/pep3101/unicodeformat.c (props changed)
sandbox/trunk/refactor/concrete.py (props changed)
sandbox/trunk/refactor/example.py (props changed)
sandbox/trunk/refactor/has_key.py (props changed)
sandbox/trunk/rjsh-pybench/Empty.py (contents, props changed)
sandbox/trunk/rjsh-pybench/NewInstances.py (props changed)
sandbox/trunk/seealso/convert-python-faqs.py (props changed)
sandbox/trunk/seealso/make-seealso.py (props changed)
sandbox/trunk/seealso/parse-seealso.py (props changed)
sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt (contents, props changed)
sandbox/trunk/stringbench/stringbench.py (props changed)
sandbox/trunk/tests/test_sax.py (props changed)
sandbox/trunk/tests/test_saxgen.py (props changed)
sandbox/trunk/trackers/trackers.txt (props changed)
sandbox/trunk/welease/README.txt (props changed)
sandbox/trunk/welease/welease.py (props changed)
Log:
Setting svn:eol properties everywhere where they weren't set yet.
Modified: sandbox/trunk/pdb/README.txt
==============================================================================
--- sandbox/trunk/pdb/README.txt (original)
+++ sandbox/trunk/pdb/README.txt Wed Apr 25 21:51:51 2007
@@ -1,65 +1,65 @@
--=[Pdb Improvements]=-
-
--=[Author: Matt Fleming <mattjfleming at googlemail.com>]=-
--=[Mentor: Robert L. Bernstein]=-
-
--=[Abstract]=-
-This project is part of a Google Summer of Code 2006 project. Many people
-have stated that they would like to see improvements in pdb. This projects
-aims to fulfill this wish.
-
--=[TODO]=-
-* Write more unit tests
-* Write a signal handler that scripts can import from mpdb that, when
- the signal is received, start remote debugging.
-* info [target/threads]
- set debug threads [on|off]
- show debug threads, command needs to be written.
-* Implement thread debugging, commands to switch between threads.
- - Because the 'main' thread may exit unexpectedly we need to keep
- any other threads that we're debugging alive. This may mean that
- we have to write some code when the main debugger exits to check
- for any threads being debugged and not exit until all threads have
- finished (or at least ask if they're sure they wanna leave).
-* Lightweight and heavyweight mechanism for setting up threads
- - The reason we want a lightweight mechanism is so that we can
- place mpdb.set_trace() inside a script so that we can debug
- the script. It has to be lighweight because the programmer
- might not want all the features of an MPdb instance, if for example
- they only care about debugging this one thread instance.
- - We need a heavyweight mechanism to allow a programmer to inspect
- and control all threads.
-* Provide a proper top-level methods including, set_trace(), post_mortem(),
- run(), remote_sighandler() (for allowing a signal to start
- remote debugging)
-* Clean up FIFO output (too many newlines)
-* mconnection should use the exceptions that have been introduced and mpdb
- should check for these exceptions being raised.
-* Write documentation
- - Debugger commands
- - Debugger model/architecture:
- - Debugging outside a process
- - Debugging remotely
- - Debugging threads
-* We can switch between threads (like in gdb) with 'thread <thread id>', but
- this currently has _no_ effect. We should at some point be able to switch
- threads and from them on not have to use the 'thread apply <tid> <cmd>'
- syntax, but just '<cmd>' which would be applied to the current thread.
-* Allow reading commands from .mpdbrc file
-* Changed the name of the default history file from ~/.pydbhist to ~/.mpdbhist
-* do_return inherited from pydb.gdb.Gdb doesn't use self.stdin for reading
- input from the user and doesn't work remotely.
-* pdbserver using a TCP connection uses setsockopt() REUSEADDR by default.
- Need some way to make this configurable. `set reuseaddr' ?
-* The style in which mpdb.py is written is too 'amorphous'. Need to at least
- separate process, thread and communication code out.
-
--=[FIXED]=-
-* Can restart program remotely with new arguments.
-* Allow thread debugging to be turned on with a command line switch.
-* Decide on a way to execute commands for a specific thread. ('thread' command)
-* Provide a command to distinguish between 'server' and 'client', because
- at the moment 'info target' only tells the user whether they are local
- or remote, and not whether they are the local/remote server or
- local/remote client - target attr is either 'remote-client' or
- 'remote-pdbserver'.
+-=[Pdb Improvements]=-
+
+-=[Author: Matt Fleming <mattjfleming at googlemail.com>]=-
+-=[Mentor: Robert L. Bernstein]=-
+
+-=[Abstract]=-
+This project is part of a Google Summer of Code 2006 project. Many people
+have stated that they would like to see improvements in pdb. This projects
+aims to fulfill this wish.
+
+-=[TODO]=-
+* Write more unit tests
+* Write a signal handler that scripts can import from mpdb that, when
+ the signal is received, start remote debugging.
+* info [target/threads]
+ set debug threads [on|off]
+ show debug threads, command needs to be written.
+* Implement thread debugging, commands to switch between threads.
+ - Because the 'main' thread may exit unexpectedly we need to keep
+ any other threads that we're debugging alive. This may mean that
+ we have to write some code when the main debugger exits to check
+ for any threads being debugged and not exit until all threads have
+ finished (or at least ask if they're sure they wanna leave).
+* Lightweight and heavyweight mechanism for setting up threads
+ - The reason we want a lightweight mechanism is so that we can
+ place mpdb.set_trace() inside a script so that we can debug
+ the script. It has to be lighweight because the programmer
+ might not want all the features of an MPdb instance, if for example
+ they only care about debugging this one thread instance.
+ - We need a heavyweight mechanism to allow a programmer to inspect
+ and control all threads.
+* Provide a proper top-level methods including, set_trace(), post_mortem(),
+ run(), remote_sighandler() (for allowing a signal to start
+ remote debugging)
+* Clean up FIFO output (too many newlines)
+* mconnection should use the exceptions that have been introduced and mpdb
+ should check for these exceptions being raised.
+* Write documentation
+ - Debugger commands
+ - Debugger model/architecture:
+ - Debugging outside a process
+ - Debugging remotely
+ - Debugging threads
+* We can switch between threads (like in gdb) with 'thread <thread id>', but
+ this currently has _no_ effect. We should at some point be able to switch
+ threads and from them on not have to use the 'thread apply <tid> <cmd>'
+ syntax, but just '<cmd>' which would be applied to the current thread.
+* Allow reading commands from .mpdbrc file
+* Changed the name of the default history file from ~/.pydbhist to ~/.mpdbhist
+* do_return inherited from pydb.gdb.Gdb doesn't use self.stdin for reading
+ input from the user and doesn't work remotely.
+* pdbserver using a TCP connection uses setsockopt() REUSEADDR by default.
+ Need some way to make this configurable. `set reuseaddr' ?
+* The style in which mpdb.py is written is too 'amorphous'. Need to at least
+ separate process, thread and communication code out.
+
+-=[FIXED]=-
+* Can restart program remotely with new arguments.
+* Allow thread debugging to be turned on with a command line switch.
+* Decide on a way to execute commands for a specific thread. ('thread' command)
+* Provide a command to distinguish between 'server' and 'client', because
+ at the moment 'info target' only tells the user whether they are local
+ or remote, and not whether they are the local/remote server or
+ local/remote client - target attr is either 'remote-client' or
+ 'remote-pdbserver'.
Modified: sandbox/trunk/pdb/mconnection.py
==============================================================================
--- sandbox/trunk/pdb/mconnection.py (original)
+++ sandbox/trunk/pdb/mconnection.py Wed Apr 25 21:51:51 2007
@@ -1,342 +1,342 @@
-""" This file contains all connections that a debugger can
-create.
-"""
-
-NotImplementedMessage = "This method must be overriden in a subclass"
-
-### Exceptions
-class ConnectionFailed(Exception): pass
-class DroppedConnection(Exception): pass
-class ReadError(Exception): pass
-class WriteError(Exception): pass
-
-class MConnectionInterface(object):
- """ This is an abstract class that specifies the interface a server
- connection class must implement. If a target is given, we'll
- set up a connection on that target
- """
- def connect(self, target):
- """Use this to set the target. It can also be specified
- on the initialization."""
- raise NotImplementedError, NotImplementedMessage
-
- def disconnect(self):
- """ This method is called to disconnect connections."""
- raise NotImplementedError, NotImplementedMessage
-
- def readline(self):
- """ This method reads a line of data of maximum length 'bufsize'
- from the connected debugger.
- """
- raise NotImplementedError, NotImplementedMessage
-
- def write(self, msg):
- """ This method is used to write to a debugger that is
- connected to this server.
- """
- raise NotImplementedError, NotImplementedMessage
-
-def import_hook(target):
- cls = target[target.rfind('.')+1:]
- target = target[:target.rfind('.')]
- try:
- pkg = __import__(target, globals(), locals(), [])
- except ImportError:
- return None
- return getattr(pkg, cls)
-
-class MConnectionClientFactory:
-
- """A factory class that provides a connection for use with a client
- for example, with a target function.
- """
- @staticmethod
- def create(target):
- if 'tcp' in target:
- return MConnectionClientTCP()
- elif 'serial' in target:
- return MConnectionSerial()
- elif 'fifo' in target:
- return MConnectionClientFIFO()
- else:
- return import_hook(target)
-
-
-class MConnectionServerFactory:
-
- """A factory class that provides a connection to be used with
- a pdbserver.
- """
- @staticmethod
- def create(target):
- if 'tcp' in target:
- return MConnectionServerTCP()
- elif 'serial' in target:
- return MConnectionSerial()
- elif 'fifo' in target:
- return MConnectionServerFIFO()
- else:
- return import_hook(target)
-
-### This might go in a different file
-# Not, serial protocol does not require the distinction between server and
-# client.
-class MConnectionSerial(MConnectionInterface):
-
- """ This connection class that allows a connection to a
- target via a serial line.
- """
-
- def __init__(self):
- MConnectionInterface.__init__(self)
- self.input = None
- self.output = None
-
- def connect(self, device):
- """ Create our fileobject by opening the serial device for
- this connection. A serial device must be specified,
- (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).
- """
- self._dev = device
- try:
- self.input = open(self._dev, 'r')
- self.output = open(self._dev, 'w')
- except IOError,e:
- # Use e[1] for more detail about why the connection failed
- raise ConnectionFailed, e[1]
-
- def disconnect(self):
- """ Close the serial device. """
- if self.output is None and self.input is None:
- return
- self.output.close()
- self.input.close()
-
- def readline(self, bufsize=2048):
- try:
- line = self.input.readline(bufsize)
- except IOError, e:
- raise ReadError, e[1]
- return line
-
- def write(self, msg):
- if msg[-1] is not '\n':
- msg += '\n'
- try:
- self.output.write(msg)
- self.output.flush()
- except IOError, e:
- raise WriteError, e[1]
-
-
-### This might go in a different file
-import socket
-
-class MConnectionServerTCP(MConnectionInterface):
- """This is an implementation of a server class that uses the TCP
- protocol as its means of communication.
- """
- def __init__(self):
- self.listening = False
- self._sock = self.output = self.input = None
- MConnectionInterface.__init__(self)
-
- def connect(self, addr, reuseaddr=True):
- """Set to allow a connection from a client. 'addr' specifies
- the hostname and port combination of the server.
- """
- try:
- h,p = addr.split(':')
- except ValueError:
- raise ConnectionFailed, 'Invalid address'
- self.host = h
- self.port = int(p)
- if not self.listening:
- self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- if reuseaddr:
- self._sock.setsockopt(socket.SOL_SOCKET,
- socket.SO_REUSEADDR, 1)
- try:
- self._sock.bind((self.host, self.port))
- except socket.error, e:
- # Use e[1] as a more detailed error message
- raise ConnectionFailed, e[1]
- self._sock.listen(1)
- self.listening = True
- self.output, addr = self._sock.accept()
- self.input = self.output
-
- def disconnect(self):
- if self.output is None or self._sock is None:
- return
- self.output.close()
- self._sock.close()
- self._sock = None
- self.listening = False
-
- def readline(self, bufsize=2048):
- try:
- line = self.input.recv(bufsize)
- except socket.error, e:
- raise ReadError, e[1]
- if not line:
- raise ReadError, 'Connection closed'
- if line[-1] != '\n': line += '\n'
- return line
-
- def write(self, msg):
- try:
- self.output.sendall(msg)
- except socket.error, e:
- raise WriteError, e[1]
-
-class MConnectionClientTCP(MConnectionInterface):
- """ A class that allows a connection to be made from a debugger
- to a server via TCP.
- """
- def __init__(self):
- """ Specify the address to connection to. """
- MConnectionInterface.__init__(self)
- self._sock = self.output = self.input = None
- self.connected = True
-
- def connect(self, addr):
- """Connect to the server. 'input' reads data from the
- server. 'output' writes data to the server. Specify the
- address of the server (e.g. host:2020). """
- try:
- h, p = addr.split(':')
- except ValueError:
- raise ConnectionFailed, 'Invalid address'
- self.host = h
- self.port = int(p)
- self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- self._sock.connect((self.host, self.port))
- except socket.error, e:
- raise ConnectionFailed, e[1]
- self.connected = True
-
- def write(self, msg):
- try:
- self._sock.sendall(msg)
- except socket.error, e:
- raise WriteError, e[1]
-
- def readline(self, bufsize=2048):
- try:
- line = self._sock.recv(bufsize)
- except socket.error, e:
- raise ReadError, e[1]
- if not line:
- raise ReadError, 'Connection closed'
- return line
-
- def disconnect(self):
- """ Close the socket to the server. """
- # We shouldn't bail if we haven't been connected yet
- if self._sock is None:
- return
- else:
- self._sock.close()
- self._sock = None
- self.connected = False
-
-import os
-class MConnectionServerFIFO(MConnectionInterface):
- """ This class implements a named pipe for communication between
- a pdbserver and client.
- """
- def __init__(self):
- MConnectionInterface.__init__(self)
- self.input = self.output = self._filename = self._mode = None
-
- def connect(self, name, mode=0644):
- self._filename = name
- self._file_in = self._filename+'0'
- self._file_out = self._filename+'1'
- self._mode = mode
- try:
- os.mkfifo(self._file_in, self._mode)
- os.mkfifo(self._file_out, self._mode)
- except OSError, e:
- raise ConnectionFailed, e[1]
- self.input = open(self._file_in, 'r')
- self.output = open(self._file_out, 'w')
-
- def disconnect(self):
- """ Disconnect from the named pipe. """
- if not self.input or not self.output:
- return
- self.output.close()
- self.input.close()
- self.input = self.output = None
- os.unlink(self._file_in)
- os.unlink(self._file_out)
-
-
- def readline(self):
- """ Read a line from the named pipe. """
- try:
- # Using readline allows the data to be read quicker, don't
- # know why.
- line = self.input.readline()
- except IOError, e:
- raise ReadError, e[1]
- if not line:
- raise ReadError, 'Connection closed'
- return line
-
- def write(self, msg):
- if msg[-1] != '\n': msg += '\n'
- try:
- self.output.write(msg)
- self.output.flush()
- except IOError, e:
- raise WriteError, e[1]
-
-class MConnectionClientFIFO(MConnectionInterface):
- """ This class is the client class for accessing a named pipe
- used for communication between client and pdbserver.
- """
- def __init__(self):
- MConnectionInterface.__init__(self)
- self.input = self.output = self._filename = self._mode = None
-
- def connect(self, name, mode=0644):
- self._filename = name
- self._file_in = self._filename+'1'
- self._file_out = self._filename+'0'
- self._mode = mode
- try:
- self.output = open(self._file_out, 'w')
- self.input = open(self._file_in, 'r')
- except IOError, e:
- raise ConnectionFailed, e[1]
-
- def disconnect(self):
- if not self.input or not self.output:
- return
- self.output.close()
- self.input.close()
- self.input = self.output = None
-
- def readline(self):
- try:
- line = self.input.readline()
- except IOError, e:
- raise ReadError, e[1]
- if not line:
- raise ReadError, 'Connection closed'
- return line
-
- def write(self, msg):
- if msg[-1] != '\n': msg += '\n'
- try:
- self.output.write(msg)
- self.output.flush()
- except IOError, e:
- raise WriteError, e[1]
-
-
-
+""" This file contains all connections that a debugger can
+create.
+"""
+
+NotImplementedMessage = "This method must be overriden in a subclass"
+
+### Exceptions
+class ConnectionFailed(Exception): pass
+class DroppedConnection(Exception): pass
+class ReadError(Exception): pass
+class WriteError(Exception): pass
+
+class MConnectionInterface(object):
+ """ This is an abstract class that specifies the interface a server
+ connection class must implement. If a target is given, we'll
+ set up a connection on that target
+ """
+ def connect(self, target):
+ """Use this to set the target. It can also be specified
+ on the initialization."""
+ raise NotImplementedError, NotImplementedMessage
+
+ def disconnect(self):
+ """ This method is called to disconnect connections."""
+ raise NotImplementedError, NotImplementedMessage
+
+ def readline(self):
+ """ This method reads a line of data of maximum length 'bufsize'
+ from the connected debugger.
+ """
+ raise NotImplementedError, NotImplementedMessage
+
+ def write(self, msg):
+ """ This method is used to write to a debugger that is
+ connected to this server.
+ """
+ raise NotImplementedError, NotImplementedMessage
+
+def import_hook(target):
+ cls = target[target.rfind('.')+1:]
+ target = target[:target.rfind('.')]
+ try:
+ pkg = __import__(target, globals(), locals(), [])
+ except ImportError:
+ return None
+ return getattr(pkg, cls)
+
+class MConnectionClientFactory:
+
+ """A factory class that provides a connection for use with a client
+ for example, with a target function.
+ """
+ @staticmethod
+ def create(target):
+ if 'tcp' in target:
+ return MConnectionClientTCP()
+ elif 'serial' in target:
+ return MConnectionSerial()
+ elif 'fifo' in target:
+ return MConnectionClientFIFO()
+ else:
+ return import_hook(target)
+
+
+class MConnectionServerFactory:
+
+ """A factory class that provides a connection to be used with
+ a pdbserver.
+ """
+ @staticmethod
+ def create(target):
+ if 'tcp' in target:
+ return MConnectionServerTCP()
+ elif 'serial' in target:
+ return MConnectionSerial()
+ elif 'fifo' in target:
+ return MConnectionServerFIFO()
+ else:
+ return import_hook(target)
+
+### This might go in a different file
+# Not, serial protocol does not require the distinction between server and
+# client.
+class MConnectionSerial(MConnectionInterface):
+
+ """ This connection class that allows a connection to a
+ target via a serial line.
+ """
+
+ def __init__(self):
+ MConnectionInterface.__init__(self)
+ self.input = None
+ self.output = None
+
+ def connect(self, device):
+ """ Create our fileobject by opening the serial device for
+ this connection. A serial device must be specified,
+ (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).
+ """
+ self._dev = device
+ try:
+ self.input = open(self._dev, 'r')
+ self.output = open(self._dev, 'w')
+ except IOError,e:
+ # Use e[1] for more detail about why the connection failed
+ raise ConnectionFailed, e[1]
+
+ def disconnect(self):
+ """ Close the serial device. """
+ if self.output is None and self.input is None:
+ return
+ self.output.close()
+ self.input.close()
+
+ def readline(self, bufsize=2048):
+ try:
+ line = self.input.readline(bufsize)
+ except IOError, e:
+ raise ReadError, e[1]
+ return line
+
+ def write(self, msg):
+ if msg[-1] is not '\n':
+ msg += '\n'
+ try:
+ self.output.write(msg)
+ self.output.flush()
+ except IOError, e:
+ raise WriteError, e[1]
+
+
+### This might go in a different file
+import socket
+
+class MConnectionServerTCP(MConnectionInterface):
+ """This is an implementation of a server class that uses the TCP
+ protocol as its means of communication.
+ """
+ def __init__(self):
+ self.listening = False
+ self._sock = self.output = self.input = None
+ MConnectionInterface.__init__(self)
+
+ def connect(self, addr, reuseaddr=True):
+ """Set to allow a connection from a client. 'addr' specifies
+ the hostname and port combination of the server.
+ """
+ try:
+ h,p = addr.split(':')
+ except ValueError:
+ raise ConnectionFailed, 'Invalid address'
+ self.host = h
+ self.port = int(p)
+ if not self.listening:
+ self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ if reuseaddr:
+ self._sock.setsockopt(socket.SOL_SOCKET,
+ socket.SO_REUSEADDR, 1)
+ try:
+ self._sock.bind((self.host, self.port))
+ except socket.error, e:
+ # Use e[1] as a more detailed error message
+ raise ConnectionFailed, e[1]
+ self._sock.listen(1)
+ self.listening = True
+ self.output, addr = self._sock.accept()
+ self.input = self.output
+
+ def disconnect(self):
+ if self.output is None or self._sock is None:
+ return
+ self.output.close()
+ self._sock.close()
+ self._sock = None
+ self.listening = False
+
+ def readline(self, bufsize=2048):
+ try:
+ line = self.input.recv(bufsize)
+ except socket.error, e:
+ raise ReadError, e[1]
+ if not line:
+ raise ReadError, 'Connection closed'
+ if line[-1] != '\n': line += '\n'
+ return line
+
+ def write(self, msg):
+ try:
+ self.output.sendall(msg)
+ except socket.error, e:
+ raise WriteError, e[1]
+
+class MConnectionClientTCP(MConnectionInterface):
+ """ A class that allows a connection to be made from a debugger
+ to a server via TCP.
+ """
+ def __init__(self):
+ """ Specify the address to connection to. """
+ MConnectionInterface.__init__(self)
+ self._sock = self.output = self.input = None
+ self.connected = True
+
+ def connect(self, addr):
+ """Connect to the server. 'input' reads data from the
+ server. 'output' writes data to the server. Specify the
+ address of the server (e.g. host:2020). """
+ try:
+ h, p = addr.split(':')
+ except ValueError:
+ raise ConnectionFailed, 'Invalid address'
+ self.host = h
+ self.port = int(p)
+ self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ try:
+ self._sock.connect((self.host, self.port))
+ except socket.error, e:
+ raise ConnectionFailed, e[1]
+ self.connected = True
+
+ def write(self, msg):
+ try:
+ self._sock.sendall(msg)
+ except socket.error, e:
+ raise WriteError, e[1]
+
+ def readline(self, bufsize=2048):
+ try:
+ line = self._sock.recv(bufsize)
+ except socket.error, e:
+ raise ReadError, e[1]
+ if not line:
+ raise ReadError, 'Connection closed'
+ return line
+
+ def disconnect(self):
+ """ Close the socket to the server. """
+ # We shouldn't bail if we haven't been connected yet
+ if self._sock is None:
+ return
+ else:
+ self._sock.close()
+ self._sock = None
+ self.connected = False
+
+import os
+class MConnectionServerFIFO(MConnectionInterface):
+ """ This class implements a named pipe for communication between
+ a pdbserver and client.
+ """
+ def __init__(self):
+ MConnectionInterface.__init__(self)
+ self.input = self.output = self._filename = self._mode = None
+
+ def connect(self, name, mode=0644):
+ self._filename = name
+ self._file_in = self._filename+'0'
+ self._file_out = self._filename+'1'
+ self._mode = mode
+ try:
+ os.mkfifo(self._file_in, self._mode)
+ os.mkfifo(self._file_out, self._mode)
+ except OSError, e:
+ raise ConnectionFailed, e[1]
+ self.input = open(self._file_in, 'r')
+ self.output = open(self._file_out, 'w')
+
+ def disconnect(self):
+ """ Disconnect from the named pipe. """
+ if not self.input or not self.output:
+ return
+ self.output.close()
+ self.input.close()
+ self.input = self.output = None
+ os.unlink(self._file_in)
+ os.unlink(self._file_out)
+
+
+ def readline(self):
+ """ Read a line from the named pipe. """
+ try:
+ # Using readline allows the data to be read quicker, don't
+ # know why.
+ line = self.input.readline()
+ except IOError, e:
+ raise ReadError, e[1]
+ if not line:
+ raise ReadError, 'Connection closed'
+ return line
+
+ def write(self, msg):
+ if msg[-1] != '\n': msg += '\n'
+ try:
+ self.output.write(msg)
+ self.output.flush()
+ except IOError, e:
+ raise WriteError, e[1]
+
+class MConnectionClientFIFO(MConnectionInterface):
+ """ This class is the client class for accessing a named pipe
+ used for communication between client and pdbserver.
+ """
+ def __init__(self):
+ MConnectionInterface.__init__(self)
+ self.input = self.output = self._filename = self._mode = None
+
+ def connect(self, name, mode=0644):
+ self._filename = name
+ self._file_in = self._filename+'1'
+ self._file_out = self._filename+'0'
+ self._mode = mode
+ try:
+ self.output = open(self._file_out, 'w')
+ self.input = open(self._file_in, 'r')
+ except IOError, e:
+ raise ConnectionFailed, e[1]
+
+ def disconnect(self):
+ if not self.input or not self.output:
+ return
+ self.output.close()
+ self.input.close()
+ self.input = self.output = None
+
+ def readline(self):
+ try:
+ line = self.input.readline()
+ except IOError, e:
+ raise ReadError, e[1]
+ if not line:
+ raise ReadError, 'Connection closed'
+ return line
+
+ def write(self, msg):
+ if msg[-1] != '\n': msg += '\n'
+ try:
+ self.output.write(msg)
+ self.output.flush()
+ except IOError, e:
+ raise WriteError, e[1]
+
+
+
Modified: sandbox/trunk/rjsh-pybench/Empty.py
==============================================================================
--- sandbox/trunk/rjsh-pybench/Empty.py (original)
+++ sandbox/trunk/rjsh-pybench/Empty.py Wed Apr 25 21:51:51 2007
@@ -1,23 +1,23 @@
-from pybench import Test
-
-class EmptyTest(Test):
- """This is just here as a potential measure of repeatability."""
-
- version = 0.3
- operations = 1
- rounds = 60000
-
- def test(self):
-
- l = []
- for i in xrange(self.rounds):
- pass
-
-
- def calibrate(self):
-
- l = []
-
- for i in xrange(self.rounds):
- pass
-
+from pybench import Test
+
+class EmptyTest(Test):
+ """This is just here as a potential measure of repeatability."""
+
+ version = 0.3
+ operations = 1
+ rounds = 60000
+
+ def test(self):
+
+ l = []
+ for i in xrange(self.rounds):
+ pass
+
+
+ def calibrate(self):
+
+ l = []
+
+ for i in xrange(self.rounds):
+ pass
+
Modified: sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt
==============================================================================
--- sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt (original)
+++ sandbox/trunk/setuptools/setuptools/tests/win_script_wrapper.txt Wed Apr 25 21:51:51 2007
@@ -1,104 +1,104 @@
-Python Script Wrapper for Windows
-=================================
-
-setuptools includes wrappers for Python scripts that allows them to be
-executed like regular windows programs. There are 2 wrappers, once
-for command-line programs, cli.exe, and one for graphica programs,
-gui.exe. These programs are almost identical, function pretty much
-the same way, and are generated from the same source file. In this
-document, we'll demonstrate use of the command-line program only. The
-wrapper programs are used by copying them to the directory containing
-the script they are to wrap and with the same name as the script they
-are to wrap. In the rest of this document, we'll give an example that
-will illustrate this.
-
-Let's create a simple script, foo-script.py:
-
- >>> import os, sys, tempfile
- >>> from setuptools.command.easy_install import nt_quote_arg
- >>> sample_directory = tempfile.mkdtemp()
- >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
- ... """#!%(python_exe)s
- ... import sys
- ... input = repr(sys.stdin.read())
- ... print sys.argv[0][-14:]
- ... print sys.argv[1:]
- ... print input
- ... if __debug__:
- ... print 'non-optimized'
- ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
-
-Note that the script starts with a Unix-style '#!' line saying which
-Python executable to run. The wrapper will use this to find the
-correct Python executable.
-
-We'll also copy cli.exe to the sample-directory with the name foo.exe:
-
- >>> import pkg_resources
- >>> open(os.path.join(sample_directory, 'foo.exe'), 'wb').write(
- ... pkg_resources.resource_string('setuptools', 'cli.exe')
- ... )
-
-When the copy of cli.exe, foo.exe in this example, runs, it examines
-the path name it was run with and computes a Python script path name
-by removing the '.exe' suffic and adding the '-script.py' suffix. (For
-GUI programs, the suffix '-script-pyw' is added.) This is why we
-named out script the way we did. Now we can run out script by running
-the wrapper:
-
- >>> import os
- >>> input, output = os.popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))
- ... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"')
- >>> input.write('hello\nworld\n')
- >>> input.close()
- >>> print output.read(),
- \foo-script.py
- ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
- 'hello\nworld\n'
- non-optimized
-
-This example was a little pathological in that it exercised windows
-(MS C runtime) quoting rules:
-
-- Strings containing spaces are surrounded by double quotes.
-
-- Double quotes in strings need to be escaped by preceding them with
- back slashes.
-
-- One or more backslashes preceding double quotes quotes need to be
- escaped by preceding each of them them with back slashes.
-
-Specifying Python Command-line Options
---------------------------------------
-
-You can specify a single argument on the '#!' line. This can be used
-to specify Python options like -O, to run in optimized mode or -i
-to start the interactive interpreter. You can combine multiple
-options as usual. For example, to run in optimized mode and
-enter the interpreter after running the script, you could use -Oi:
-
- >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
- ... """#!%(python_exe)s -Oi
- ... import sys
- ... input = repr(sys.stdin.read())
- ... print sys.argv[0][-14:]
- ... print sys.argv[1:]
- ... print input
- ... if __debug__:
- ... print 'non-optimized'
- ... sys.ps1 = '---'
- ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
-
- >>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
- >>> input.close()
- >>> print output.read(),
- \foo-script.py
- []
- ''
- ---
-
-
-We're done with the sample_directory:
-
- >>> import shutil
- >>> shutil.rmtree(sample_directory)
+Python Script Wrapper for Windows
+=================================
+
+setuptools includes wrappers for Python scripts that allows them to be
+executed like regular windows programs. There are 2 wrappers, once
+for command-line programs, cli.exe, and one for graphica programs,
+gui.exe. These programs are almost identical, function pretty much
+the same way, and are generated from the same source file. In this
+document, we'll demonstrate use of the command-line program only. The
+wrapper programs are used by copying them to the directory containing
+the script they are to wrap and with the same name as the script they
+are to wrap. In the rest of this document, we'll give an example that
+will illustrate this.
+
+Let's create a simple script, foo-script.py:
+
+ >>> import os, sys, tempfile
+ >>> from setuptools.command.easy_install import nt_quote_arg
+ >>> sample_directory = tempfile.mkdtemp()
+ >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
+ ... """#!%(python_exe)s
+ ... import sys
+ ... input = repr(sys.stdin.read())
+ ... print sys.argv[0][-14:]
+ ... print sys.argv[1:]
+ ... print input
+ ... if __debug__:
+ ... print 'non-optimized'
+ ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+
+Note that the script starts with a Unix-style '#!' line saying which
+Python executable to run. The wrapper will use this to find the
+correct Python executable.
+
+We'll also copy cli.exe to the sample-directory with the name foo.exe:
+
+ >>> import pkg_resources
+ >>> open(os.path.join(sample_directory, 'foo.exe'), 'wb').write(
+ ... pkg_resources.resource_string('setuptools', 'cli.exe')
+ ... )
+
+When the copy of cli.exe, foo.exe in this example, runs, it examines
+the path name it was run with and computes a Python script path name
+by removing the '.exe' suffic and adding the '-script.py' suffix. (For
+GUI programs, the suffix '-script-pyw' is added.) This is why we
+named out script the way we did. Now we can run out script by running
+the wrapper:
+
+ >>> import os
+ >>> input, output = os.popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'foo.exe'))
+ ... + r' arg1 "arg 2" "arg \"2\\\"" "arg 4\\" "arg5 a\\b"')
+ >>> input.write('hello\nworld\n')
+ >>> input.close()
+ >>> print output.read(),
+ \foo-script.py
+ ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
+ 'hello\nworld\n'
+ non-optimized
+
+This example was a little pathological in that it exercised windows
+(MS C runtime) quoting rules:
+
+- Strings containing spaces are surrounded by double quotes.
+
+- Double quotes in strings need to be escaped by preceding them with
+ back slashes.
+
+- One or more backslashes preceding double quotes quotes need to be
+ escaped by preceding each of them them with back slashes.
+
+Specifying Python Command-line Options
+--------------------------------------
+
+You can specify a single argument on the '#!' line. This can be used
+to specify Python options like -O, to run in optimized mode or -i
+to start the interactive interpreter. You can combine multiple
+options as usual. For example, to run in optimized mode and
+enter the interpreter after running the script, you could use -Oi:
+
+ >>> open(os.path.join(sample_directory, 'foo-script.py'), 'w').write(
+ ... """#!%(python_exe)s -Oi
+ ... import sys
+ ... input = repr(sys.stdin.read())
+ ... print sys.argv[0][-14:]
+ ... print sys.argv[1:]
+ ... print input
+ ... if __debug__:
+ ... print 'non-optimized'
+ ... sys.ps1 = '---'
+ ... """ % dict(python_exe=nt_quote_arg(sys.executable)))
+
+ >>> input, output = os.popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
+ >>> input.close()
+ >>> print output.read(),
+ \foo-script.py
+ []
+ ''
+ ---
+
+
+We're done with the sample_directory:
+
+ >>> import shutil
+ >>> shutil.rmtree(sample_directory)
More information about the Python-checkins
mailing list