[Python-checkins] r87583 - in python/branches/py3k: Demo/README Demo/classes Demo/curses Demo/distutils/test2to3 Demo/embed Demo/newmetaclasses Demo/scripts Demo/sockets Demo/tix Demo/tkinter Tools/demo Tools/demo/Eiffel.py Tools/demo/Vec.py Tools/demo/beer.py Tools/demo/hanoi.py Tools/demo/life.py Tools/demo/markov.py Tools/demo/mcast.py Tools/demo/queens.py Tools/demo/rpython.py Tools/demo/rpythond.py Tools/demo/sortvisu.py Tools/demo/ss1.py Tools/test2to3

georg.brandl python-checkins at python.org
Thu Dec 30 22:33:07 CET 2010


Author: georg.brandl
Date: Thu Dec 30 22:33:07 2010
New Revision: 87583

Log:
More cleanup: Move some demos into a dedicated Tools/demo dir, move 2to3 demo to Tools, and remove all the other Demo content.

Added:
   python/branches/py3k/Tools/demo/
   python/branches/py3k/Tools/demo/Eiffel.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/newmetaclasses/Eiffel.py
   python/branches/py3k/Tools/demo/Vec.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/classes/Vec.py
   python/branches/py3k/Tools/demo/beer.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/scripts/beer.py
   python/branches/py3k/Tools/demo/hanoi.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/tkinter/guido/hanoi.py
   python/branches/py3k/Tools/demo/life.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/curses/life.py
   python/branches/py3k/Tools/demo/markov.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/scripts/markov.py
   python/branches/py3k/Tools/demo/mcast.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/sockets/mcast.py
   python/branches/py3k/Tools/demo/queens.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/scripts/queens.py
   python/branches/py3k/Tools/demo/rpython.py
      - copied, changed from r87579, /python/branches/py3k/Demo/sockets/rpython.py
   python/branches/py3k/Tools/demo/rpythond.py
      - copied, changed from r87579, /python/branches/py3k/Demo/sockets/rpythond.py
   python/branches/py3k/Tools/demo/sortvisu.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/tkinter/guido/sortvisu.py
   python/branches/py3k/Tools/demo/ss1.py
      - copied unchanged from r87579, /python/branches/py3k/Demo/tkinter/guido/ss1.py
   python/branches/py3k/Tools/test2to3/
      - copied from r87579, /python/branches/py3k/Demo/distutils/test2to3/
Removed:
   python/branches/py3k/Demo/README
   python/branches/py3k/Demo/classes/
   python/branches/py3k/Demo/curses/
   python/branches/py3k/Demo/distutils/test2to3/
   python/branches/py3k/Demo/embed/
   python/branches/py3k/Demo/newmetaclasses/
   python/branches/py3k/Demo/scripts/
   python/branches/py3k/Demo/sockets/
   python/branches/py3k/Demo/tix/
   python/branches/py3k/Demo/tkinter/

Deleted: python/branches/py3k/Demo/README
==============================================================================
--- python/branches/py3k/Demo/README	Thu Dec 30 22:33:07 2010
+++ (empty file)
@@ -1,62 +0,0 @@
-This directory contains various demonstrations of what you can do with
-Python.  They were all written by me except where explicitly stated
-otherwise -- in general, demos contributed by others ends up in the
-../Contrib directory, unless I think they're of utmost general
-importance (like Matt Conway's Tk demos).
-
-A fair number of utilities that are useful when while developing
-Python code can be found in the ../Tools directory -- some of these
-can also be considered good examples of how to write Python code.
-
-Finally, in order to save disk space and net bandwidth, not all
-subdirectories listed here are distributed.  They are listed just
-in case I change my mind about them.
-
-
-cgi             CGI examples.
-
-classes         Some examples of how to use classes.
-
-comparisons     A set of responses to a really old language-comparison
-                challenge.
-
-curses          A set of curses demos.
-
-distutils       Test for using transparent 2to3 conversion in distutils.
-
-embed           An example of embedding Python in another application
-                (see also pysvr).
-
-imputil         Demonstration subclasses of imputil.Importer.
-
-md5test         Test program for the optional md5 module.
-
-newmetaclasses  Demonstration of metaclasses.
-
-parser          Example using the parser module.
-
-pysvr           An example of embedding Python in a threaded
-                application.
-
-rpc             A set of classes for building clients and servers for
-                Sun RPC.
-
-scripts         Some useful Python scripts that I put in my bin
-                directory.  No optional built-in modules needed.
-
-sockets         Examples for the new built-in module 'socket'.
-
-threads         Demos that use the 'thread' module.  (Currently these
-                only run on SGIs, but this may change in the future.)
-
-tix             Demos using the Tix widget set addition to Tkinter.
-
-tkinter         Demos using the Tk interface (including Matt Conway's
-                excellent set of demos).
-
-turtle          Demos for the "turtle" module.
-
-xml             Some XML demos.
-
-zlib            Some demos for the zlib module (see also the standard
-                library module gzip.py).

Copied: python/branches/py3k/Tools/demo/rpython.py (from r87579, /python/branches/py3k/Demo/sockets/rpython.py)
==============================================================================
--- /python/branches/py3k/Demo/sockets/rpython.py	(original)
+++ python/branches/py3k/Tools/demo/rpython.py	Thu Dec 30 22:33:07 2010
@@ -4,8 +4,7 @@
 # Execute Python commands remotely and send output back.
 
 import sys
-import string
-from socket import *
+from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR
 
 PORT = 4127
 BUFSIZE = 1024
@@ -16,20 +15,22 @@
         sys.exit(2)
     host = sys.argv[1]
     port = PORT
-    i = string.find(host, ':')
+    i = host.find(':')
     if i >= 0:
-        port = string.atoi(port[i+1:])
+        port = int(port[i+1:])
         host = host[:i]
-    command = string.join(sys.argv[2:])
+    command = ' '.join(sys.argv[2:])
     s = socket(AF_INET, SOCK_STREAM)
     s.connect((host, port))
-    s.send(command)
-    s.shutdown(1)
-    reply = ''
-    while 1:
+    s.send(command.encode())
+    s.shutdown(SHUT_WR)
+    reply = b''
+    while True:
         data = s.recv(BUFSIZE)
-        if not data: break
-        reply = reply + data
-    print(reply, end=' ')
+        if not data:
+            break
+        reply += data
+    print(reply.decode(), end=' ')
+    s.close()
 
 main()

Copied: python/branches/py3k/Tools/demo/rpythond.py (from r87579, /python/branches/py3k/Demo/sockets/rpythond.py)
==============================================================================
--- /python/branches/py3k/Demo/sockets/rpythond.py	(original)
+++ python/branches/py3k/Tools/demo/rpythond.py	Thu Dec 30 22:33:07 2010
@@ -6,7 +6,7 @@
 # from any host on the Internet!
 
 import sys
-from socket import *
+from socket import socket, AF_INET, SOCK_STREAM
 import io
 import traceback
 
@@ -15,23 +15,23 @@
 
 def main():
     if len(sys.argv) > 1:
-        port = int(eval(sys.argv[1]))
+        port = int(sys.argv[1])
     else:
         port = PORT
     s = socket(AF_INET, SOCK_STREAM)
     s.bind(('', port))
     s.listen(1)
-    while 1:
+    while True:
         conn, (remotehost, remoteport) = s.accept()
-        print('connected by', remotehost, remoteport)
-        request = ''
+        print('connection from', remotehost, remoteport)
+        request = b''
         while 1:
             data = conn.recv(BUFSIZE)
             if not data:
                 break
-            request = request + data
-        reply = execute(request)
-        conn.send(reply)
+            request += data
+        reply = execute(request.decode())
+        conn.send(reply.encode())
         conn.close()
 
 def execute(request):
@@ -49,4 +49,7 @@
         sys.stdout = stdout
     return fakefile.getvalue()
 
-main()
+try:
+    main()
+except KeyboardInterrupt:
+    pass


More information about the Python-checkins mailing list