summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-06-08 15:35:45 (GMT)
committerThomas Wouters <thomas@python.org>2006-06-08 15:35:45 (GMT)
commit73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6 (patch)
tree206b2ca44cf23af41ac27cb7b3744f2e60a3341d /Demo
parent1ba5b3b425e970ec3e4a19165475aa68fa5ac893 (diff)
downloadcpython-73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6.zip
cpython-73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6.tar.gz
cpython-73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6.tar.bz2
Merge the rest of the trunk.
Merged revisions 46490-46494,46496,46498,46500,46506,46521,46538,46558,46563-46567,46570-46571,46583,46593,46595-46598,46604,46606,46609-46753 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r46610 | martin.v.loewis | 2006-06-03 09:42:26 +0200 (Sat, 03 Jun 2006) | 2 lines Updated version (win32-icons2.zip) from #1490384. ........ r46612 | andrew.kuchling | 2006-06-03 20:09:41 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1472084] Fix description of do_tag ........ r46614 | andrew.kuchling | 2006-06-03 20:33:35 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1475554] Strengthen text to say 'must' instead of 'should' ........ r46616 | andrew.kuchling | 2006-06-03 20:41:28 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1441864] Clarify description of 'data' argument ........ r46617 | andrew.kuchling | 2006-06-03 20:43:24 +0200 (Sat, 03 Jun 2006) | 1 line Minor rewording ........ r46619 | andrew.kuchling | 2006-06-03 21:02:35 +0200 (Sat, 03 Jun 2006) | 9 lines [Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler. Fix by renaming the variable. In a different module, Neal fixed it by renaming _self to self. There's already a variable named 'self' here, so I used selfptr. (I'm committing this on a Mac without Tk, but it's a simple search-and-replace. <crosses fingers>, so I'll watch the buildbots and see what happens.) ........ r46621 | fredrik.lundh | 2006-06-03 23:56:05 +0200 (Sat, 03 Jun 2006) | 5 lines "_self" is a said to be a reserved word in Watcom C 10.6. I'm not sure that's really standard compliant behaviour, but I guess we have to fix that anyway... ........ r46622 | andrew.kuchling | 2006-06-04 00:44:42 +0200 (Sun, 04 Jun 2006) | 1 line Update readme ........ r46623 | andrew.kuchling | 2006-06-04 00:59:23 +0200 (Sun, 04 Jun 2006) | 1 line Drop 0 parameter ........ r46624 | andrew.kuchling | 2006-06-04 00:59:59 +0200 (Sun, 04 Jun 2006) | 1 line Some code tidying; use curses.wrapper ........ r46625 | andrew.kuchling | 2006-06-04 01:02:15 +0200 (Sun, 04 Jun 2006) | 1 line Use True; value returned from main is unused ........ r46626 | andrew.kuchling | 2006-06-04 01:07:21 +0200 (Sun, 04 Jun 2006) | 1 line Use true division, and the True value ........ r46627 | andrew.kuchling | 2006-06-04 01:09:58 +0200 (Sun, 04 Jun 2006) | 1 line Docstring fix; use True ........ r46628 | andrew.kuchling | 2006-06-04 01:15:56 +0200 (Sun, 04 Jun 2006) | 1 line Put code in a main() function; loosen up the spacing to match current code style ........ r46629 | andrew.kuchling | 2006-06-04 01:39:07 +0200 (Sun, 04 Jun 2006) | 1 line Use functions; modernize code ........ r46630 | andrew.kuchling | 2006-06-04 01:43:22 +0200 (Sun, 04 Jun 2006) | 1 line This demo requires Medusa (not just asyncore); remove it ........ r46631 | andrew.kuchling | 2006-06-04 01:46:36 +0200 (Sun, 04 Jun 2006) | 2 lines Remove xmlrpc demo -- it duplicates the SimpleXMLRPCServer module. ........ r46632 | andrew.kuchling | 2006-06-04 01:47:22 +0200 (Sun, 04 Jun 2006) | 1 line Remove xmlrpc/ directory ........ r46633 | andrew.kuchling | 2006-06-04 01:51:21 +0200 (Sun, 04 Jun 2006) | 1 line Remove dangling reference ........ r46634 | andrew.kuchling | 2006-06-04 01:59:36 +0200 (Sun, 04 Jun 2006) | 1 line Add more whitespace; use a better socket name ........ r46635 | tim.peters | 2006-06-04 03:22:53 +0200 (Sun, 04 Jun 2006) | 2 lines Whitespace normalization. ........ r46637 | tim.peters | 2006-06-04 05:26:02 +0200 (Sun, 04 Jun 2006) | 16 lines In a PYMALLOC_DEBUG build obmalloc adds extra debugging info to each allocated block. This was using 4 bytes for each such piece of info regardless of platform. This didn't really matter before (proof: no bug reports, and the debug-build obmalloc would have assert-failed if it was ever asked for a chunk of memory >= 2**32 bytes), since container indices were plain ints. But after the Py_ssize_t changes, it's at least theoretically possible to allocate a list or string whose guts exceed 2**32 bytes, and the PYMALLOC_DEBUG routines would fail then (having only 4 bytes to record the originally requested size). Now we use sizeof(size_t) bytes for each of a PYMALLOC_DEBUG build's extra debugging fields. This won't make any difference on 32-bit boxes, but will add 16 bytes to each allocation in a debug build on a 64-bit box. ........ r46638 | tim.peters | 2006-06-04 05:38:04 +0200 (Sun, 04 Jun 2006) | 4 lines _PyObject_DebugMalloc(): The return value should add 2*sizeof(size_t) now, not 8. This probably accounts for current disasters on the 64-bit buildbot slaves. ........ r46639 | neal.norwitz | 2006-06-04 08:19:31 +0200 (Sun, 04 Jun 2006) | 1 line SF #1499797, Fix for memory leak in WindowsError_str ........ r46640 | andrew.macintyre | 2006-06-04 14:31:09 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1454481: Make thread stack size runtime tunable. ........ r46641 | andrew.macintyre | 2006-06-04 14:59:59 +0200 (Sun, 04 Jun 2006) | 2 lines clean up function declarations to conform to PEP-7 style. ........ r46642 | martin.blais | 2006-06-04 15:49:49 +0200 (Sun, 04 Jun 2006) | 15 lines Fixes in struct and socket from merge reviews. - Following Guido's comments, renamed * pack_to -> pack_into * recv_buf -> recv_into * recvfrom_buf -> recvfrom_into - Made fixes to _struct.c according to Neal Norwitz comments on the checkins list. - Converted some ints into the appropriate -- I hope -- ssize_t and size_t. ........ r46643 | ronald.oussoren | 2006-06-04 16:05:28 +0200 (Sun, 04 Jun 2006) | 3 lines "Import" LDFLAGS in Mac/OSX/Makefile.in to ensure pythonw gets build with the right compiler flags. ........ r46644 | ronald.oussoren | 2006-06-04 16:24:59 +0200 (Sun, 04 Jun 2006) | 2 lines Drop Mac wrappers for the WASTE library. ........ r46645 | tim.peters | 2006-06-04 17:49:07 +0200 (Sun, 04 Jun 2006) | 3 lines s_methods[]: Stop compiler warnings by casting s_unpack_from to PyCFunction. ........ r46646 | george.yoshida | 2006-06-04 19:04:12 +0200 (Sun, 04 Jun 2006) | 2 lines Remove a redundant word ........ r46647 | george.yoshida | 2006-06-04 19:17:25 +0200 (Sun, 04 Jun 2006) | 2 lines Markup fix ........ r46648 | martin.v.loewis | 2006-06-04 21:36:28 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1359618: Speed-up charmap encoder. ........ r46649 | georg.brandl | 2006-06-04 23:46:16 +0200 (Sun, 04 Jun 2006) | 3 lines Repair refleaks in unicodeobject. ........ r46650 | georg.brandl | 2006-06-04 23:56:52 +0200 (Sun, 04 Jun 2006) | 4 lines Patch #1346214: correctly optimize away "if 0"-style stmts (thanks to Neal for review) ........ r46651 | georg.brandl | 2006-06-05 00:15:37 +0200 (Mon, 05 Jun 2006) | 2 lines Bug #1500293: fix memory leaks in _subprocess module. ........ r46654 | tim.peters | 2006-06-05 01:43:53 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46655 | tim.peters | 2006-06-05 01:52:47 +0200 (Mon, 05 Jun 2006) | 16 lines Revert revisions: 46640 Patch #1454481: Make thread stack size runtime tunable. 46647 Markup fix The first is causing many buildbots to fail test runs, and there are multiple causes with seemingly no immediate prospects for repairing them. See python-dev discussion. Note that a branch can (and should) be created for resolving these problems, like svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH followed by merging rev 46647 to the new branch. ........ r46656 | andrew.kuchling | 2006-06-05 02:08:09 +0200 (Mon, 05 Jun 2006) | 1 line Mention second encoding speedup ........ r46657 | gregory.p.smith | 2006-06-05 02:31:01 +0200 (Mon, 05 Jun 2006) | 7 lines bugfix: when log_archive was called with the DB_ARCH_REMOVE flag present in BerkeleyDB >= 4.2 it tried to construct a list out of an uninitialized char **log_list. feature: export the DB_ARCH_REMOVE flag by name in the module on BerkeleyDB >= 4.2. ........ r46658 | gregory.p.smith | 2006-06-05 02:33:35 +0200 (Mon, 05 Jun 2006) | 5 lines fix a bug in the previous commit. don't leak empty list on error return and fix the additional rare (out of memory only) bug that it was supposed to fix of not freeing log_list when the python allocator failed. ........ r46660 | tim.peters | 2006-06-05 02:55:26 +0200 (Mon, 05 Jun 2006) | 9 lines "Flat is better than nested." Move the long-winded, multiply-nested -R support out of runtest() and into some module-level helper functions. This makes runtest() and the -R code easier to follow. That in turn allowed seeing some opportunities for code simplification, and made it obvious that reglog.txt never got closed. ........ r46661 | hyeshik.chang | 2006-06-05 02:59:54 +0200 (Mon, 05 Jun 2006) | 3 lines Fix a potentially invalid memory access of CJKCodecs' shift-jis decoder. (found by Neal Norwitz) ........ r46663 | gregory.p.smith | 2006-06-05 03:39:52 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.log_stat() method on BerkeleyDB >= 4.0 [patch #1494885] ........ r46664 | tim.peters | 2006-06-05 03:43:03 +0200 (Mon, 05 Jun 2006) | 3 lines Remove doctest.testmod's deprecated (in 2.4) `isprivate` argument. A lot of hair went into supporting that! ........ r46665 | tim.peters | 2006-06-05 03:47:24 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46666 | tim.peters | 2006-06-05 03:48:21 +0200 (Mon, 05 Jun 2006) | 2 lines Make doctest news more accurate. ........ r46667 | gregory.p.smith | 2006-06-05 03:56:15 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.lsn_reset() method on BerkeleyDB >= 4.4 [patch #1494902] ........ r46668 | gregory.p.smith | 2006-06-05 04:02:25 +0200 (Mon, 05 Jun 2006) | 3 lines mention the just committed bsddb changes ........ r46671 | gregory.p.smith | 2006-06-05 19:38:04 +0200 (Mon, 05 Jun 2006) | 3 lines * add support for DBSequence objects [patch #1466734] ........ r46672 | gregory.p.smith | 2006-06-05 20:20:07 +0200 (Mon, 05 Jun 2006) | 3 lines forgot to add this file in previous commit ........ r46673 | tim.peters | 2006-06-05 20:36:12 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46674 | tim.peters | 2006-06-05 20:36:54 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46675 | gregory.p.smith | 2006-06-05 20:48:21 +0200 (Mon, 05 Jun 2006) | 4 lines * fix DBCursor.pget() bug with keyword argument names when no data= is supplied [SF pybsddb bug #1477863] ........ r46676 | andrew.kuchling | 2006-06-05 21:05:32 +0200 (Mon, 05 Jun 2006) | 1 line Remove use of Trove name, which isn't very helpful to users ........ r46677 | andrew.kuchling | 2006-06-05 21:08:25 +0200 (Mon, 05 Jun 2006) | 1 line [Bug #1470026] Include link to list of classifiers ........ r46679 | tim.peters | 2006-06-05 22:48:49 +0200 (Mon, 05 Jun 2006) | 10 lines Access _struct attributes directly instead of mucking with getattr. string_reverse(): Simplify. assertRaises(): Raise TestFailed on failure. test_unpack_from(), test_pack_into(), test_pack_into_fn(): never use `assert` to test for an expected result (it doesn't test anything when Python is run with -O). ........ r46680 | tim.peters | 2006-06-05 22:49:27 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46681 | gregory.p.smith | 2006-06-06 01:38:06 +0200 (Tue, 06 Jun 2006) | 3 lines add depends = ['md5.h'] to the _md5 module extension for correctness sake. ........ r46682 | brett.cannon | 2006-06-06 01:51:55 +0200 (Tue, 06 Jun 2006) | 4 lines Add 3 more bytes to a buffer to cover constants in string and null byte on top of 10 possible digits for an int. Closes bug #1501223. ........ r46684 | gregory.p.smith | 2006-06-06 01:59:37 +0200 (Tue, 06 Jun 2006) | 5 lines - bsddb: the __len__ method of a DB object has been fixed to return correct results. It could previously incorrectly return 0 in some cases. Fixes SF bug 1493322 (pybsddb bug 1184012). ........ r46686 | tim.peters | 2006-06-06 02:25:07 +0200 (Tue, 06 Jun 2006) | 7 lines _PySys_Init(): It's rarely a good idea to size a buffer to the exact maximum size someone guesses is needed. In this case, if we're really worried about extreme integers, then "cp%d" can actually need 14 bytes (2 for "cp" + 1 for \0 at the end + 11 for -(2**31-1)). So reserve 128 bytes instead -- nothing is actually saved by making a stack-local buffer tiny. ........ r46687 | neal.norwitz | 2006-06-06 09:22:08 +0200 (Tue, 06 Jun 2006) | 1 line Remove unused variable (and stop compiler warning) ........ r46688 | neal.norwitz | 2006-06-06 09:23:01 +0200 (Tue, 06 Jun 2006) | 1 line Fix a bunch of parameter strings ........ r46689 | thomas.heller | 2006-06-06 13:34:33 +0200 (Tue, 06 Jun 2006) | 6 lines Convert CFieldObject tp_members to tp_getset, since there is no structmember typecode for Py_ssize_t fields. This should fix some of the errors on the PPC64 debian machine (64-bit, big endian). Assigning to readonly fields now raises AttributeError instead of TypeError, so the testcase has to be changed as well. ........ r46690 | thomas.heller | 2006-06-06 13:54:32 +0200 (Tue, 06 Jun 2006) | 1 line Damn - the sentinel was missing. And fix another silly mistake. ........ r46691 | martin.blais | 2006-06-06 14:46:55 +0200 (Tue, 06 Jun 2006) | 13 lines Normalized a few cases of whitespace in function declarations. Found them using:: find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done (I was doing this all over my own code anyway, because I'd been using spaces in all defs, so I thought I'd make a run on the Python code as well. If you need to do such fixes in your own code, you can use xx-rename or parenregu.el within emacs.) ........ r46693 | thomas.heller | 2006-06-06 17:34:18 +0200 (Tue, 06 Jun 2006) | 1 line Specify argtypes for all test functions. Maybe that helps on strange ;-) architectures ........ r46694 | tim.peters | 2006-06-06 17:50:17 +0200 (Tue, 06 Jun 2006) | 5 lines BSequence_set_range(): Rev 46688 ("Fix a bunch of parameter strings") changed this function's signature seemingly by mistake, which is causing buildbots to fail test_bsddb3. Restored the pre-46688 signature. ........ r46695 | tim.peters | 2006-06-06 17:52:35 +0200 (Tue, 06 Jun 2006) | 4 lines On python-dev Thomas Heller said these were committed by mistake in rev 46693, so reverting this part of rev 46693. ........ r46696 | andrew.kuchling | 2006-06-06 19:10:41 +0200 (Tue, 06 Jun 2006) | 1 line Fix comment typo ........ r46697 | brett.cannon | 2006-06-06 20:08:16 +0200 (Tue, 06 Jun 2006) | 2 lines Fix coding style guide bug. ........ r46698 | thomas.heller | 2006-06-06 20:50:46 +0200 (Tue, 06 Jun 2006) | 2 lines Add a hack so that foreign functions returning float now do work on 64-bit big endian platforms. ........ r46699 | thomas.heller | 2006-06-06 21:25:13 +0200 (Tue, 06 Jun 2006) | 3 lines Use the same big-endian hack as in _ctypes/callproc.c for callback functions. This fixes the callback function tests that return float. ........ r46700 | ronald.oussoren | 2006-06-06 21:50:24 +0200 (Tue, 06 Jun 2006) | 5 lines * Ensure that "make altinstall" works when the tree was configured with --enable-framework * Also for --enable-framework: allow users to use --prefix to specify the location of the compatibility symlinks (such as /usr/local/bin/python) ........ r46701 | ronald.oussoren | 2006-06-06 21:56:00 +0200 (Tue, 06 Jun 2006) | 3 lines A quick hack to ensure the right key-bindings for IDLE on osx: install patched configuration files during a framework install. ........ r46702 | tim.peters | 2006-06-07 03:04:59 +0200 (Wed, 07 Jun 2006) | 4 lines dash_R_cleanup(): Clear filecmp._cache. This accounts for different results across -R runs (at least on Windows) of test_filecmp. ........ r46705 | tim.peters | 2006-06-07 08:57:51 +0200 (Wed, 07 Jun 2006) | 17 lines SF patch 1501987: Remove randomness from test_exceptions, from ?iga Seilnacht (sorry about the name, but Firefox on my box can't display the first character of the name -- the SF "Unix name" is zseil). This appears to cure the oddball intermittent leaks across runs when running test_exceptions under -R. I'm not sure why, but I'm too sleepy to care ;-) The thrust of the SF patch was to remove randomness in the pickle protocol used. I changed the patch to use range(pickle.HIGHEST_PROTOCOL + 1), to try both pickle and cPickle, and randomly mucked with other test lines to put statements on their own lines. Not a bugfix candidate (this is fiddling new-in-2.5 code). ........ r46706 | andrew.kuchling | 2006-06-07 15:55:33 +0200 (Wed, 07 Jun 2006) | 1 line Add an SQLite introduction, taken from the 'What's New' text ........ r46708 | andrew.kuchling | 2006-06-07 19:02:52 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46709 | andrew.kuchling | 2006-06-07 19:03:46 +0200 (Wed, 07 Jun 2006) | 1 line Add an item; also, escape % ........ r46710 | andrew.kuchling | 2006-06-07 19:04:01 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46716 | ronald.oussoren | 2006-06-07 20:57:44 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/Tools one level up ........ r46717 | ronald.oussoren | 2006-06-07 20:58:01 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/PythonLauncher one level up ........ r46718 | ronald.oussoren | 2006-06-07 20:58:42 +0200 (Wed, 07 Jun 2006) | 2 lines mv Mac/OSX/BuildScript one level up ........ r46719 | ronald.oussoren | 2006-06-07 21:02:03 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/* one level up ........ r46720 | ronald.oussoren | 2006-06-07 21:06:01 +0200 (Wed, 07 Jun 2006) | 2 lines And the last bit: move IDLE one level up and adjust makefiles ........ r46723 | ronald.oussoren | 2006-06-07 21:38:53 +0200 (Wed, 07 Jun 2006) | 4 lines - Patch the correct version of python in the Info.plists at build time, instead of relying on a maintainer to update them before releases. - Remove the now empty Mac/OSX directory ........ r46727 | ronald.oussoren | 2006-06-07 22:18:44 +0200 (Wed, 07 Jun 2006) | 7 lines * If BuildApplet.py is used as an applet it starts with a version of sys.exutable that isn't usuable on an #!-line. That results in generated applets that don't actually work. Work around this problem by resetting sys.executable. * argvemulator.py didn't work on intel macs. This patch fixes this (bug #1491468) ........ r46728 | tim.peters | 2006-06-07 22:40:06 +0200 (Wed, 07 Jun 2006) | 2 lines Whitespace normalization. ........ r46729 | tim.peters | 2006-06-07 22:40:54 +0200 (Wed, 07 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46730 | thomas.heller | 2006-06-07 22:43:06 +0200 (Wed, 07 Jun 2006) | 7 lines Fix for foreign functions returning small structures on 64-bit big endian machines. Should fix the remaininf failure in the PPC64 Debian buildbot. Thanks to Matthias Klose for providing access to a machine to debug and test this. ........ r46731 | brett.cannon | 2006-06-07 23:48:17 +0200 (Wed, 07 Jun 2006) | 2 lines Clarify documentation for bf_getcharbuffer. ........ r46735 | neal.norwitz | 2006-06-08 07:12:45 +0200 (Thu, 08 Jun 2006) | 1 line Fix a refleak in recvfrom_into ........ r46736 | gregory.p.smith | 2006-06-08 07:17:08 +0200 (Thu, 08 Jun 2006) | 9 lines - bsddb: the bsddb.dbtables Modify method now raises the proper error and aborts the db transaction safely when a modifier callback fails. Fixes SF python patch/bug #1408584. Also cleans up the bsddb.dbtables docstrings since thats the only documentation that exists for that unadvertised module. (people really should really just use sqlite3) ........ r46737 | gregory.p.smith | 2006-06-08 07:38:11 +0200 (Thu, 08 Jun 2006) | 4 lines * Turn the deadlock situation described in SF bug #775414 into a DBDeadLockError exception. * add the test case for my previous dbtables commit. ........ r46738 | gregory.p.smith | 2006-06-08 07:39:54 +0200 (Thu, 08 Jun 2006) | 2 lines pasted set_lk_detect line in wrong spot in previous commit. fixed. passes tests this time. ........ r46739 | armin.rigo | 2006-06-08 12:56:24 +0200 (Thu, 08 Jun 2006) | 6 lines (arre, arigo) SF bug #1350060 Give a consistent behavior for comparison and hashing of method objects (both user- and built-in methods). Now compares the 'self' recursively. The hash was already asking for the hash of 'self'. ........ r46740 | andrew.kuchling | 2006-06-08 13:56:44 +0200 (Thu, 08 Jun 2006) | 1 line Typo fix ........ r46741 | georg.brandl | 2006-06-08 14:45:01 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502750: Fix getargs "i" format to use LONG_MIN and LONG_MAX for bounds checking. ........ r46743 | georg.brandl | 2006-06-08 14:54:13 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502728: Correctly link against librt library on HP-UX. ........ r46745 | georg.brandl | 2006-06-08 14:55:47 +0200 (Thu, 08 Jun 2006) | 3 lines Add news for recent bugfix. ........ r46746 | georg.brandl | 2006-06-08 15:31:07 +0200 (Thu, 08 Jun 2006) | 4 lines Argh. "integer" is a very confusing word ;) Actually, checking for INT_MAX and INT_MIN is correct since the format code explicitly handles a C "int". ........ r46748 | nick.coghlan | 2006-06-08 15:54:49 +0200 (Thu, 08 Jun 2006) | 1 line Add functools.update_wrapper() and functools.wraps() as described in PEP 356 ........ r46751 | georg.brandl | 2006-06-08 16:50:21 +0200 (Thu, 08 Jun 2006) | 4 lines Bug #1502805: don't alias file.__exit__ to file.close since the latter can return something that's true. ........ r46752 | georg.brandl | 2006-06-08 16:50:53 +0200 (Thu, 08 Jun 2006) | 3 lines Convert test_file to unittest. ........
Diffstat (limited to 'Demo')
-rw-r--r--Demo/README3
-rwxr-xr-xDemo/classes/Dates.py70
-rw-r--r--Demo/curses/README5
-rwxr-xr-xDemo/curses/life.py128
-rw-r--r--Demo/curses/rain.py4
-rwxr-xr-xDemo/curses/repeat.py4
-rw-r--r--Demo/curses/tclock.py25
-rw-r--r--Demo/curses/xmas.py6
-rw-r--r--Demo/sockets/README1
-rw-r--r--Demo/sockets/unixclient.py4
-rw-r--r--Demo/sockets/unixserver.py15
-rw-r--r--Demo/threads/fcmp.py6
-rw-r--r--Demo/xmlrpc/xmlrpc_handler.py104
-rw-r--r--Demo/xmlrpc/xmlrpcserver.py75
-rwxr-xr-xDemo/zlib/minigzip.py147
-rwxr-xr-xDemo/zlib/zlibdemo.py77
16 files changed, 266 insertions, 408 deletions
diff --git a/Demo/README b/Demo/README
index 5e3d9e2..9d150d6 100644
--- a/Demo/README
+++ b/Demo/README
@@ -57,8 +57,5 @@ tkinter Demos using the Tk interface (including Matt Conway's
xml Some XML demos.
-xmlrpc XML-RPC server framework (but see the standard library
- module SimpleXMLRPCServer.py for a replacement).
-
zlib Some demos for the zlib module (see also the standard
library module gzip.py).
diff --git a/Demo/classes/Dates.py b/Demo/classes/Dates.py
index f8f0634..6494b6a 100755
--- a/Demo/classes/Dates.py
+++ b/Demo/classes/Dates.py
@@ -59,32 +59,32 @@ del dbm, dim
_INT_TYPES = type(1), type(1L)
-def _is_leap( year ): # 1 if leap year, else 0
+def _is_leap(year): # 1 if leap year, else 0
if year % 4 != 0: return 0
if year % 400 == 0: return 1
return year % 100 != 0
-def _days_in_year( year ): # number of days in year
+def _days_in_year(year): # number of days in year
return 365 + _is_leap(year)
-def _days_before_year( year ): # number of days before year
+def _days_before_year(year): # number of days before year
return year*365L + (year+3)/4 - (year+99)/100 + (year+399)/400
-def _days_in_month( month, year ): # number of days in month of year
+def _days_in_month(month, year): # number of days in month of year
if month == 2 and _is_leap(year): return 29
return _DAYS_IN_MONTH[month-1]
-def _days_before_month( month, year ): # number of days in year before month
+def _days_before_month(month, year): # number of days in year before month
return _DAYS_BEFORE_MONTH[month-1] + (month > 2 and _is_leap(year))
-def _date2num( date ): # compute ordinal of date.month,day,year
- return _days_before_year( date.year ) + \
- _days_before_month( date.month, date.year ) + \
+def _date2num(date): # compute ordinal of date.month,day,year
+ return _days_before_year(date.year) + \
+ _days_before_month(date.month, date.year) + \
date.day
-_DI400Y = _days_before_year( 400 ) # number of days in 400 years
+_DI400Y = _days_before_year(400) # number of days in 400 years
-def _num2date( n ): # return date with ordinal n
+def _num2date(n): # return date with ordinal n
if type(n) not in _INT_TYPES:
raise TypeError, 'argument must be integer: %r' % type(n)
@@ -95,53 +95,53 @@ def _num2date( n ): # return date with ordinal n
n400 = (n-1)/_DI400Y # # of 400-year blocks preceding
year, n = 400 * n400, n - _DI400Y * n400
more = n / 365
- dby = _days_before_year( more )
+ dby = _days_before_year(more)
if dby >= n:
more = more - 1
- dby = dby - _days_in_year( more )
+ dby = dby - _days_in_year(more)
year, n = year + more, int(n - dby)
try: year = int(year) # chop to int, if it fits
except (ValueError, OverflowError): pass
- month = min( n/29 + 1, 12 )
- dbm = _days_before_month( month, year )
+ month = min(n/29 + 1, 12)
+ dbm = _days_before_month(month, year)
if dbm >= n:
month = month - 1
- dbm = dbm - _days_in_month( month, year )
+ dbm = dbm - _days_in_month(month, year)
ans.month, ans.day, ans.year = month, n-dbm, year
return ans
-def _num2day( n ): # return weekday name of day with ordinal n
+def _num2day(n): # return weekday name of day with ordinal n
return _DAY_NAMES[ int(n % 7) ]
class Date:
- def __init__( self, month, day, year ):
+ def __init__(self, month, day, year):
if not 1 <= month <= 12:
raise ValueError, 'month must be in 1..12: %r' % (month,)
- dim = _days_in_month( month, year )
+ dim = _days_in_month(month, year)
if not 1 <= day <= dim:
raise ValueError, 'day must be in 1..%r: %r' % (dim, day)
self.month, self.day, self.year = month, day, year
- self.ord = _date2num( self )
+ self.ord = _date2num(self)
# don't allow setting existing attributes
- def __setattr__( self, name, value ):
+ def __setattr__(self, name, value):
if self.__dict__.has_key(name):
raise AttributeError, 'read-only attribute ' + name
self.__dict__[name] = value
- def __cmp__( self, other ):
- return cmp( self.ord, other.ord )
+ def __cmp__(self, other):
+ return cmp(self.ord, other.ord)
# define a hash function so dates can be used as dictionary keys
- def __hash__( self ):
- return hash( self.ord )
+ def __hash__(self):
+ return hash(self.ord)
# print as, e.g., Mon 16 Aug 1993
- def __repr__( self ):
+ def __repr__(self):
return '%.3s %2d %.3s %r' % (
self.weekday(),
self.day,
@@ -149,33 +149,33 @@ class Date:
self.year)
# Python 1.1 coerces neither int+date nor date+int
- def __add__( self, n ):
+ def __add__(self, n):
if type(n) not in _INT_TYPES:
raise TypeError, 'can\'t add %r to date' % type(n)
- return _num2date( self.ord + n )
+ return _num2date(self.ord + n)
__radd__ = __add__ # handle int+date
# Python 1.1 coerces neither date-int nor date-date
- def __sub__( self, other ):
+ def __sub__(self, other):
if type(other) in _INT_TYPES: # date-int
- return _num2date( self.ord - other )
+ return _num2date(self.ord - other)
else:
return self.ord - other.ord # date-date
# complain about int-date
- def __rsub__( self, other ):
+ def __rsub__(self, other):
raise TypeError, 'Can\'t subtract date from integer'
- def weekday( self ):
- return _num2day( self.ord )
+ def weekday(self):
+ return _num2day(self.ord)
def today():
import time
local = time.localtime(time.time())
- return Date( local[1], local[2], local[0] )
+ return Date(local[1], local[2], local[0])
DateTestError = 'DateTestError'
-def test( firstyear, lastyear ):
+def test(firstyear, lastyear):
a = Date(9,30,1913)
b = Date(9,30,1914)
if repr(a) != 'Tue 30 Sep 1913':
@@ -207,7 +207,7 @@ def test( firstyear, lastyear ):
# verify date<->number conversions for first and last days for
# all years in firstyear .. lastyear
- lord = _days_before_year( firstyear )
+ lord = _days_before_year(firstyear)
y = firstyear
while y <= lastyear:
ford = lord + 1
diff --git a/Demo/curses/README b/Demo/curses/README
index f2a3b74..2d1c4b1 100644
--- a/Demo/curses/README
+++ b/Demo/curses/README
@@ -11,14 +11,11 @@ I wouldn't mind someone else making an effort in that direction, of
course.
ncurses.py -- currently only a panels demo
- XXX this won't work until panel support is checked in
rain.py -- raindrops keep falling on my desktop
tclock.py -- ASCII clock, by Howard Jones
xmas.py -- I'm dreaming of an ASCII christmas
-Please send bugfixes and new contributions to me or, even better,
-submit them to the Python Bug Tracker on SourceForge
-(<URL:http://sourceforge.net/bugs/?group_id=5470>).
+Please submit bugfixes and new contributions to the Python bug tracker.
Other demos
diff --git a/Demo/curses/life.py b/Demo/curses/life.py
index a787e26..a5bbed2 100755
--- a/Demo/curses/life.py
+++ b/Demo/curses/life.py
@@ -44,14 +44,15 @@ class LifeBoard:
scr -- curses screen object to use for display
char -- character used to render live cells (default: '*')
"""
- self.state={} ; self.scr=scr
+ self.state = {}
+ self.scr = scr
Y, X = self.scr.getmaxyx()
self.X, self.Y = X-2, Y-2-1
self.char = char
self.scr.clear()
# Draw a border around the board
- border_line='+'+(self.X*'-')+'+'
+ border_line = '+'+(self.X*'-')+'+'
self.scr.addstr(0, 0, border_line)
self.scr.addstr(self.Y+1,0, border_line)
for y in range(0, self.Y):
@@ -73,16 +74,16 @@ class LifeBoard:
del self.state[x,y]
self.scr.addch(y+1, x+1, ' ')
else:
- self.state[x,y]=1
+ self.state[x,y] = 1
self.scr.addch(y+1, x+1, self.char)
self.scr.refresh()
def erase(self):
"""Clear the entire board and update the board display"""
- self.state={}
- self.display(update_board=0)
+ self.state = {}
+ self.display(update_board=False)
- def display(self, update_board=1):
+ def display(self, update_board=True):
"""Display the whole board, optionally computing one generation"""
M,N = self.X, self.Y
if not update_board:
@@ -95,42 +96,46 @@ class LifeBoard:
self.scr.refresh()
return
- d={} ; self.boring=1
+ d = {}
+ self.boring = 1
for i in range(0, M):
- L=range( max(0, i-1), min(M, i+2) )
+ L = range( max(0, i-1), min(M, i+2) )
for j in range(0, N):
- s=0
- live=self.state.has_key( (i,j) )
+ s = 0
+ live = self.state.has_key( (i,j) )
for k in range( max(0, j-1), min(N, j+2) ):
for l in L:
if self.state.has_key( (l,k) ):
- s=s+1
- s=s-live
- if s==3:
+ s += 1
+ s -= live
+ if s == 3:
# Birth
- d[i,j]=1
+ d[i,j] = 1
self.scr.addch(j+1, i+1, self.char)
- if not live: self.boring=0
- elif s==2 and live: d[i,j]=1 # Survival
+ if not live: self.boring = 0
+ elif s == 2 and live: d[i,j] = 1 # Survival
elif live:
# Death
self.scr.addch(j+1, i+1, ' ')
- self.boring=0
- self.state=d
+ self.boring = 0
+ self.state = d
self.scr.refresh()
def makeRandom(self):
"Fill the board with a random pattern"
- self.state={}
+ self.state = {}
for i in range(0, self.X):
for j in range(0, self.Y):
- if random.random() > 0.5: self.set(j,i)
+ if random.random() > 0.5:
+ self.set(j,i)
def erase_menu(stdscr, menu_y):
"Clear the space where the menu resides"
- stdscr.move(menu_y, 0) ; stdscr.clrtoeol()
- stdscr.move(menu_y+1, 0) ; stdscr.clrtoeol()
+ stdscr.move(menu_y, 0)
+ stdscr.clrtoeol()
+ stdscr.move(menu_y+1, 0)
+ stdscr.clrtoeol()
def display_menu(stdscr, menu_y):
"Display the menu of possible keystroke commands"
@@ -140,18 +145,17 @@ def display_menu(stdscr, menu_y):
stdscr.addstr(menu_y+1, 4,
'E)rase the board, R)andom fill, S)tep once or C)ontinuously, Q)uit')
-def main(stdscr):
-
+def keyloop(stdscr):
# Clear the screen and display the menu of keys
stdscr.clear()
stdscr_y, stdscr_x = stdscr.getmaxyx()
- menu_y=(stdscr_y-3)-1
+ menu_y = (stdscr_y-3)-1
display_menu(stdscr, menu_y)
# Allocate a subwindow for the Life board and create the board object
- subwin=stdscr.subwin(stdscr_y-3, stdscr_x, 0, 0)
- board=LifeBoard(subwin, char=ord('*'))
- board.display(update_board=0)
+ subwin = stdscr.subwin(stdscr_y-3, stdscr_x, 0, 0)
+ board = LifeBoard(subwin, char=ord('*'))
+ board.display(update_board=False)
# xpos, ypos are the cursor's position
xpos, ypos = board.X/2, board.Y/2
@@ -159,9 +163,9 @@ def main(stdscr):
# Main loop:
while (1):
stdscr.move(1+ypos, 1+xpos) # Move the cursor
- c=stdscr.getch() # Get a keystroke
+ c = stdscr.getch() # Get a keystroke
if 0<c<256:
- c=chr(c)
+ c = chr(c)
if c in ' \n':
board.toggle(ypos, xpos)
elif c in 'Cc':
@@ -173,50 +177,40 @@ def main(stdscr):
# if no keystroke is available, instead of waiting.
stdscr.nodelay(1)
while (1):
- c=stdscr.getch()
- if c!=-1: break
- stdscr.addstr(0,0, '/'); stdscr.refresh()
+ c = stdscr.getch()
+ if c != -1:
+ break
+ stdscr.addstr(0,0, '/')
+ stdscr.refresh()
board.display()
- stdscr.addstr(0,0, '+'); stdscr.refresh()
+ stdscr.addstr(0,0, '+')
+ stdscr.refresh()
stdscr.nodelay(0) # Disable nodelay mode
display_menu(stdscr, menu_y)
- elif c in 'Ee': board.erase()
- elif c in 'Qq': break
+ elif c in 'Ee':
+ board.erase()
+ elif c in 'Qq':
+ break
elif c in 'Rr':
board.makeRandom()
- board.display(update_board=0)
+ board.display(update_board=False)
elif c in 'Ss':
board.display()
else: pass # Ignore incorrect keys
- elif c==curses.KEY_UP and ypos>0: ypos=ypos-1
- elif c==curses.KEY_DOWN and ypos<board.Y-1: ypos=ypos+1
- elif c==curses.KEY_LEFT and xpos>0: xpos=xpos-1
- elif c==curses.KEY_RIGHT and xpos<board.X-1: xpos=xpos+1
- else: pass # Ignore incorrect keys
-
-if __name__=='__main__':
- try:
- # Initialize curses
- stdscr=curses.initscr()
- # Turn off echoing of keys, and enter cbreak mode,
- # where no buffering is performed on keyboard input
- curses.noecho() ; curses.cbreak()
-
- # In keypad mode, escape sequences for special keys
- # (like the cursor keys) will be interpreted and
- # a special value like curses.KEY_LEFT will be returned
- stdscr.keypad(1)
- main(stdscr) # Enter the main loop
- # Set everything back to normal
- stdscr.keypad(0)
- curses.echo() ; curses.nocbreak()
- curses.endwin() # Terminate curses
- except:
- # In the event of an error, restore the terminal
- # to a sane state.
- stdscr.keypad(0)
- curses.echo() ; curses.nocbreak()
- curses.endwin()
- traceback.print_exc() # Print the exception
+ elif c == curses.KEY_UP and ypos>0: ypos -= 1
+ elif c == curses.KEY_DOWN and ypos<board.Y-1: ypos += 1
+ elif c == curses.KEY_LEFT and xpos>0: xpos -= 1
+ elif c == curses.KEY_RIGHT and xpos<board.X-1: xpos += 1
+ else:
+ # Ignore incorrect keys
+ pass
+
+
+def main(stdscr):
+ keyloop(stdscr) # Enter the main loop
+
+
+if __name__ == '__main__':
+ curses.wrapper(main)
diff --git a/Demo/curses/rain.py b/Demo/curses/rain.py
index 69794b3..9d46e6e 100644
--- a/Demo/curses/rain.py
+++ b/Demo/curses/rain.py
@@ -48,7 +48,7 @@ def main(win):
ypos[j] = randrange(0, r) + 2
j = 0
- while 1:
+ while True:
x = randrange(0, c) + 2
y = randrange(0, r) + 2
@@ -83,7 +83,7 @@ def main(win):
ch = stdscr.getch()
if ch == ord('q') or ch == ord('Q'):
- return 0
+ return
elif ch == ord('s'):
stdscr.nodelay(0)
elif ch == ord(' '):
diff --git a/Demo/curses/repeat.py b/Demo/curses/repeat.py
index 158264c..fa7daac 100755
--- a/Demo/curses/repeat.py
+++ b/Demo/curses/repeat.py
@@ -2,7 +2,7 @@
"""repeat <shell-command>
-This simple program repeatedly (with 1-second intervals) executes the
+This simple program repeatedly (at 1-second intervals) executes the
shell command given on the command line and displays the output (or as
much of it as fits on the screen). It uses curses to paint each new
output on top of the old output, so that if nothing changes, the
@@ -38,7 +38,7 @@ def main():
sys.exit(sts)
w = curses.initscr()
try:
- while 1:
+ while True:
w.erase()
try:
w.addstr(text)
diff --git a/Demo/curses/tclock.py b/Demo/curses/tclock.py
index 1950043..8058d9a 100644
--- a/Demo/curses/tclock.py
+++ b/Demo/curses/tclock.py
@@ -14,7 +14,8 @@ def sign(_x):
return 1
def A2XY(angle, radius):
- return int(round(ASPECT * radius * sin(angle))), int(round(radius * cos(angle)))
+ return (int(round(ASPECT * radius * sin(angle))),
+ int(round(radius * cos(angle))))
def plot(x, y, col):
stdscr.addch(y, x, col)
@@ -37,9 +38,9 @@ def dline(pair, from_x, from_y, x2, y2, ch):
y = from_y
if ax > ay:
- d = ay - ax / 2
+ d = ay - ax // 2
- while 1:
+ while True:
plot(x, y, ch)
if x == x2:
return
@@ -50,9 +51,9 @@ def dline(pair, from_x, from_y, x2, y2, ch):
x += sx
d += ay
else:
- d = ax - ay / 2
+ d = ax - ay // 2
- while 1:
+ while True:
plot(x, y, ch)
if y == y2:
return
@@ -78,12 +79,12 @@ def main(win):
curses.init_pair(2, curses.COLOR_MAGENTA, my_bg)
curses.init_pair(3, curses.COLOR_GREEN, my_bg)
- cx = (curses.COLS - 1) / 2
- cy = curses.LINES / 2
- ch = min( cy-1, int(cx / ASPECT) - 1)
- mradius = (3 * ch) / 4
- hradius = ch / 2
- sradius = 5 * ch / 6
+ cx = (curses.COLS - 1) // 2
+ cy = curses.LINES // 2
+ ch = min( cy-1, int(cx // ASPECT) - 1)
+ mradius = (3 * ch) // 4
+ hradius = ch // 2
+ sradius = 5 * ch // 6
for i in range(0, 12):
sangle = (i + 1) * 2.0 * pi / 12.0
@@ -96,7 +97,7 @@ def main(win):
sradius = max(sradius-4, 8)
- while 1:
+ while True:
curses.napms(1000)
tim = time.time()
diff --git a/Demo/curses/xmas.py b/Demo/curses/xmas.py
index e51bc5f..349b3a8 100644
--- a/Demo/curses/xmas.py
+++ b/Demo/curses/xmas.py
@@ -4,7 +4,7 @@
# $Id$
#
# I'm dreaming of an ascii character-based monochrome Christmas,
-# Just like the one's I used to know!
+# Just like the ones I used to know!
# Via a full duplex communications channel,
# At 9600 bits per second,
# Even though it's kinda slow.
@@ -272,7 +272,7 @@ def strng5():
def blinkit():
treescrn8.touchwin()
- for cycle in range(0, 5):
+ for cycle in range(5):
if cycle == 0:
treescrn3.overlay(treescrn8)
treescrn8.refresh()
@@ -380,7 +380,7 @@ def reindeer():
middeer0.refresh()
w_del_msg.refresh()
- for looper in range(0, 2):
+ for looper in range(2):
deer_step(middeer3, y_pos, x_pos)
deer_step(middeer2, y_pos, x_pos)
deer_step(middeer1, y_pos, x_pos)
diff --git a/Demo/sockets/README b/Demo/sockets/README
index 21ed808..f5405ab 100644
--- a/Demo/sockets/README
+++ b/Demo/sockets/README
@@ -19,4 +19,3 @@ mcast.py A Python translation of
/usr/people/4Dgifts/examples/network/mcast.c
(Note that IN.py is in ../../lib/sgi.)
-See also ../../lib/nntp.py for another example of socket code.
diff --git a/Demo/sockets/unixclient.py b/Demo/sockets/unixclient.py
index cccd617..fdbcc7a 100644
--- a/Demo/sockets/unixclient.py
+++ b/Demo/sockets/unixclient.py
@@ -1,7 +1,9 @@
# Echo client demo using Unix sockets
# Piet van Oostrum
+
from socket import *
-FILE = 'blabla'
+
+FILE = 'unix-socket'
s = socket(AF_UNIX, SOCK_STREAM)
s.connect(FILE)
s.send('Hello, world')
diff --git a/Demo/sockets/unixserver.py b/Demo/sockets/unixserver.py
index 5eccabb..b73f857 100644
--- a/Demo/sockets/unixserver.py
+++ b/Demo/sockets/unixserver.py
@@ -1,17 +1,24 @@
# Echo server demo using Unix sockets (handles one connection only)
# Piet van Oostrum
+
import os
from socket import *
-FILE = 'blabla'
+
+FILE = 'unix-socket'
s = socket(AF_UNIX, SOCK_STREAM)
s.bind(FILE)
+
print 'Sock name is: ['+s.getsockname()+']'
+
+# Wait for a connection
s.listen(1)
conn, addr = s.accept()
-print 'Connected by', addr
-while 1:
+
+while True:
data = conn.recv(1024)
- if not data: break
+ if not data:
+ break
conn.send(data)
+
conn.close()
os.unlink(FILE)
diff --git a/Demo/threads/fcmp.py b/Demo/threads/fcmp.py
index 83ebe01..27af76d 100644
--- a/Demo/threads/fcmp.py
+++ b/Demo/threads/fcmp.py
@@ -4,14 +4,14 @@ from Coroutine import *
# fringe visits a nested list in inorder, and detaches for each non-list
# element; raises EarlyExit after the list is exhausted
-def fringe( co, list ):
+def fringe(co, list):
for x in list:
if type(x) is type([]):
fringe(co, x)
else:
co.back(x)
-def printinorder( list ):
+def printinorder(list):
co = Coroutine()
f = co.create(fringe, co, list)
try:
@@ -27,7 +27,7 @@ x = [0, 1, [2, [3]], [4,5], [[[6]]] ]
printinorder(x) # 0 1 2 3 4 5 6
# fcmp lexicographically compares the fringes of two nested lists
-def fcmp( l1, l2 ):
+def fcmp(l1, l2):
co1 = Coroutine(); f1 = co1.create(fringe, co1, l1)
co2 = Coroutine(); f2 = co2.create(fringe, co2, l2)
while 1:
diff --git a/Demo/xmlrpc/xmlrpc_handler.py b/Demo/xmlrpc/xmlrpc_handler.py
deleted file mode 100644
index 359d6f1..0000000
--- a/Demo/xmlrpc/xmlrpc_handler.py
+++ /dev/null
@@ -1,104 +0,0 @@
-#
-# XML-RPC SERVER
-# $Id$
-#
-# an asynchronous XML-RPC server for Medusa
-#
-# written by Sam Rushing
-#
-# Based on "xmlrpcserver.py" by Fredrik Lundh (fredrik@pythonware.com)
-#
-
-import http_server
-import xmlrpclib
-
-import sys
-
-class xmlrpc_handler:
-
- def match (self, request):
- # Note: /RPC2 is not required by the spec, so you may override this method.
- if request.uri[:5] == '/RPC2':
- return 1
- else:
- return 0
-
- def handle_request (self, request):
- [path, params, query, fragment] = request.split_uri()
-
- if request.command.lower() in ('post', 'put'):
- request.collector = collector (self, request)
- else:
- request.error (400)
-
- def continue_request (self, data, request):
- params, method = xmlrpclib.loads (data)
- try:
- # generate response
- try:
- response = self.call (method, params)
- response = (response,)
- except:
- # report exception back to server
- response = xmlrpclib.dumps (
- xmlrpclib.Fault (1, "%s:%s" % sys.exc_info()[:2])
- )
- else:
- response = xmlrpclib.dumps (response, methodresponse=1)
- except:
- # internal error, report as HTTP server error
- request.error (500)
- else:
- # got a valid XML RPC response
- request['Content-Type'] = 'text/xml'
- request.push (response)
- request.done()
-
- def call (self, method, params):
- # override this method to implement RPC methods
- raise "NotYetImplemented"
-
-class collector:
-
- "gathers input for POST and PUT requests"
-
- def __init__ (self, handler, request):
-
- self.handler = handler
- self.request = request
- self.data = ''
-
- # make sure there's a content-length header
- cl = request.get_header ('content-length')
-
- if not cl:
- request.error (411)
- else:
- cl = int (cl)
- # using a 'numeric' terminator
- self.request.channel.set_terminator (cl)
-
- def collect_incoming_data (self, data):
- self.data = self.data + data
-
- def found_terminator (self):
- # set the terminator back to the default
- self.request.channel.set_terminator ('\r\n\r\n')
- self.handler.continue_request (self.data, self.request)
-
-if __name__ == '__main__':
-
- class rpc_demo (xmlrpc_handler):
-
- def call (self, method, params):
- print 'method="%s" params=%s' % (method, params)
- return "Sure, that works"
-
- import asyncore
- import http_server
-
- hs = http_server.http_server ('', 8000)
- rpc = rpc_demo()
- hs.install_handler (rpc)
-
- asyncore.loop()
diff --git a/Demo/xmlrpc/xmlrpcserver.py b/Demo/xmlrpc/xmlrpcserver.py
deleted file mode 100644
index 7af73be..0000000
--- a/Demo/xmlrpc/xmlrpcserver.py
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# XML-RPC SERVER
-# $Id$
-#
-# a simple XML-RPC server for Python
-#
-# History:
-# 1999-02-01 fl added to xmlrpclib distribution
-#
-# written by Fredrik Lundh, January 1999.
-#
-# Copyright (c) 1999 by Secret Labs AB.
-# Copyright (c) 1999 by Fredrik Lundh.
-#
-# fredrik@pythonware.com
-# http://www.pythonware.com
-#
-# --------------------------------------------------------------------
-# Permission to use, copy, modify, and distribute this software and
-# its associated documentation for any purpose and without fee is
-# hereby granted. This software is provided as is.
-# --------------------------------------------------------------------
-#
-
-import SocketServer, BaseHTTPServer
-import xmlrpclib
-import sys
-
-class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
-
- def do_POST(self):
- try:
- # get arguments
- data = self.rfile.read(int(self.headers["content-length"]))
- params, method = xmlrpclib.loads(data)
-
- # generate response
- try:
- response = self.call(method, params)
- # wrap response in a singleton tuple
- response = (response,)
- except:
- # report exception back to server
- response = xmlrpclib.dumps(
- xmlrpclib.Fault(1, "%s:%s" % sys.exc_info()[:2])
- )
- else:
- response = xmlrpclib.dumps(
- response,
- methodresponse=1
- )
- except:
- # internal error, report as HTTP server error
- self.send_response(500)
- self.end_headers()
- else:
- # got a valid XML RPC response
- self.send_response(200)
- self.send_header("Content-type", "text/xml")
- self.send_header("Content-length", str(len(response)))
- self.end_headers()
- self.wfile.write(response)
-
- # shut down the connection (from Skip Montanaro)
- self.wfile.flush()
- self.connection.shutdown(1)
-
- def call(self, method, params):
- # override this method to implement RPC methods
- print "CALL", method, params
- return params
-
-if __name__ == '__main__':
- server = SocketServer.TCPServer(('', 8000), RequestHandler)
- server.serve_forever()
diff --git a/Demo/zlib/minigzip.py b/Demo/zlib/minigzip.py
index e2801de..87fed4a 100755
--- a/Demo/zlib/minigzip.py
+++ b/Demo/zlib/minigzip.py
@@ -1,106 +1,133 @@
#!/usr/bin/env python
# Demo program for zlib; it compresses or decompresses files, but *doesn't*
# delete the original. This doesn't support all of gzip's options.
+#
+# The 'gzip' module in the standard library provides a more complete
+# implementation of gzip-format files.
+
+import zlib, sys, os
FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16
def write32(output, value):
- output.write(chr(value & 255)) ; value=value / 256
- output.write(chr(value & 255)) ; value=value / 256
- output.write(chr(value & 255)) ; value=value / 256
+ output.write(chr(value & 255)) ; value=value // 256
+ output.write(chr(value & 255)) ; value=value // 256
+ output.write(chr(value & 255)) ; value=value // 256
output.write(chr(value & 255))
def read32(input):
- v=ord(input.read(1))
- v=v+ (ord(input.read(1))<<8 )
- v=v+ (ord(input.read(1))<<16)
- v=v+ (ord(input.read(1))<<24)
+ v = ord(input.read(1))
+ v += (ord(input.read(1)) << 8 )
+ v += (ord(input.read(1)) << 16)
+ v += (ord(input.read(1)) << 24)
return v
-import zlib, sys
-if len(sys.argv)!=2:
- print 'Usage: minigzip.py <filename>'
- print ' The file will be compressed or decompressed.'
- sys.exit(0)
-
-filename=sys.argv[1]
-compressing=1 ; outputname=filename+'.gz'
-if filename[-3:]=='.gz':
- compressing=0 ; outputname=filename[:-3]
-input=open(filename) ; output=open(outputname, 'w')
-
-if compressing:
+def compress (filename, input, output):
output.write('\037\213\010') # Write the header, ...
output.write(chr(FNAME)) # ... flag byte ...
- import os # ... modification time ...
- statval=os.stat(filename)
- mtime=statval[8]
+ statval = os.stat(filename) # ... modification time ...
+ mtime = statval[8]
write32(output, mtime)
output.write('\002') # ... slowest compression alg. ...
output.write('\377') # ... OS (=unknown) ...
output.write(filename+'\000') # ... original filename ...
- crcval=zlib.crc32("")
- compobj=zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS,
+ crcval = zlib.crc32("")
+ compobj = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS,
zlib.DEF_MEM_LEVEL, 0)
- while (1):
- data=input.read(1024)
- if data=="": break
- crcval=zlib.crc32(data, crcval)
+ while True:
+ data = input.read(1024)
+ if data == "":
+ break
+ crcval = zlib.crc32(data, crcval)
output.write(compobj.compress(data))
output.write(compobj.flush())
write32(output, crcval) # ... the CRC ...
write32(output, statval[6]) # and the file size.
-else:
- magic=input.read(2)
- if magic!='\037\213':
- print 'Not a gzipped file' ; sys.exit(0)
- if ord(input.read(1))!=8:
- print 'Unknown compression method' ; sys.exit(0)
- flag=ord(input.read(1))
+def decompress (input, output):
+ magic = input.read(2)
+ if magic != '\037\213':
+ print 'Not a gzipped file'
+ sys.exit(0)
+ if ord(input.read(1)) != 8:
+ print 'Unknown compression method'
+ sys.exit(0)
+ flag = ord(input.read(1))
input.read(4+1+1) # Discard modification time,
# extra flags, and OS byte.
if flag & FEXTRA:
# Read & discard the extra field, if present
- xlen=ord(input.read(1))
- xlen=xlen+256*ord(input.read(1))
+ xlen = ord(input.read(1))
+ xlen += 256*ord(input.read(1))
input.read(xlen)
if flag & FNAME:
# Read and discard a null-terminated string containing the filename
- while (1):
- s=input.read(1)
- if s=='\000': break
+ while True:
+ s = input.read(1)
+ if s == '\0': break
if flag & FCOMMENT:
# Read and discard a null-terminated string containing a comment
- while (1):
+ while True:
s=input.read(1)
- if s=='\000': break
+ if s=='\0': break
if flag & FHCRC:
input.read(2) # Read & discard the 16-bit header CRC
- decompobj=zlib.decompressobj(-zlib.MAX_WBITS)
- crcval=zlib.crc32("")
- length=0
- while (1):
+
+ decompobj = zlib.decompressobj(-zlib.MAX_WBITS)
+ crcval = zlib.crc32("")
+ length = 0
+ while True:
data=input.read(1024)
- if data=="": break
- decompdata=decompobj.decompress(data)
- print len(decompdata)
- output.write(decompdata) ; length=length+len(decompdata)
- crcval=zlib.crc32(decompdata, crcval)
- decompdata=decompobj.flush()
- output.write(decompdata) ; length=length+len(decompdata)
- crcval=zlib.crc32(decompdata, crcval)
+ if data == "":
+ break
+ decompdata = decompobj.decompress(data)
+ output.write(decompdata)
+ length += len(decompdata)
+ crcval = zlib.crc32(decompdata, crcval)
+
+ decompdata = decompobj.flush()
+ output.write(decompdata)
+ length += len(decompdata)
+ crcval = zlib.crc32(decompdata, crcval)
# We've read to the end of the file, so we have to rewind in order
# to reread the 8 bytes containing the CRC and the file size. The
# decompressor is smart and knows when to stop, so feeding it
# extra data is harmless.
input.seek(-8, 2)
- crc32=read32(input)
- isize=read32(input)
- if crc32!=crcval: print 'CRC check failed.'
- if isize!=length: print 'Incorrect length of data produced'
+ crc32 = read32(input)
+ isize = read32(input)
+ if crc32 != crcval:
+ print 'CRC check failed.'
+ if isize != length:
+ print 'Incorrect length of data produced'
+
+def main():
+ if len(sys.argv)!=2:
+ print 'Usage: minigzip.py <filename>'
+ print ' The file will be compressed or decompressed.'
+ sys.exit(0)
+
+ filename = sys.argv[1]
+ if filename.endswith('.gz'):
+ compressing = False
+ outputname = filename[:-3]
+ else:
+ compressing = True
+ outputname = filename + '.gz'
+
+ input = open(filename, 'rb')
+ output = open(outputname, 'wb')
+
+ if compressing:
+ compress(filename, input, output)
+ else:
+ decompress(input, output)
+
+ input.close()
+ output.close()
-input.close() ; output.close()
+if __name__ == '__main__':
+ main()
diff --git a/Demo/zlib/zlibdemo.py b/Demo/zlib/zlibdemo.py
index 5a0ab63..b449c19 100755
--- a/Demo/zlib/zlibdemo.py
+++ b/Demo/zlib/zlibdemo.py
@@ -1,35 +1,48 @@
#!/usr/bin/env python
+# Takes an optional filename, defaulting to this file itself.
+# Reads the file and compresses the content using level 1 and level 9
+# compression, printing a summary of the results.
+
import zlib, sys
-if len(sys.argv)>1: filename=sys.argv[1]
-else: filename='zlibdemo.py'
-print 'Reading', filename
-f=open(filename, 'r') # Get the data to compress
-s=f.read()
-f.close()
-
-# First, we'll compress the string in one step
-comptext=zlib.compress(s, 1)
-decomp=zlib.decompress(comptext)
-
-print '1-step compression: (level 1)'
-print ' Original:', len(s), 'Compressed:', len(comptext),
-print 'Uncompressed:', len(decomp)
-
-# Now, let's compress the string in stages; set chunk to work in smaller steps
-
-chunk=256
-compressor=zlib.compressobj(9)
-decompressor=zlib.decompressobj()
-comptext=decomp=''
-for i in range(0, len(s), chunk):
- comptext=comptext+compressor.compress(s[i:i+chunk])
-comptext=comptext+compressor.flush() # Don't forget to call flush()!!
-
-for i in range(0, len(comptext), chunk):
- decomp=decomp+decompressor.decompress(comptext[i:i+chunk])
-decomp=decomp+decompressor.flush()
-
-print 'Progressive compression (level 9):'
-print ' Original:', len(s), 'Compressed:', len(comptext),
-print 'Uncompressed:', len(decomp)
+
+def main():
+ if len(sys.argv) > 1:
+ filename = sys.argv[1]
+ else:
+ filename = sys.argv[0]
+ print 'Reading', filename
+
+ f = open(filename, 'rb') # Get the data to compress
+ s = f.read()
+ f.close()
+
+ # First, we'll compress the string in one step
+ comptext = zlib.compress(s, 1)
+ decomp = zlib.decompress(comptext)
+
+ print '1-step compression: (level 1)'
+ print ' Original:', len(s), 'Compressed:', len(comptext),
+ print 'Uncompressed:', len(decomp)
+
+ # Now, let's compress the string in stages; set chunk to work in smaller steps
+
+ chunk = 256
+ compressor = zlib.compressobj(9)
+ decompressor = zlib.decompressobj()
+ comptext = decomp = ''
+ for i in range(0, len(s), chunk):
+ comptext = comptext+compressor.compress(s[i:i+chunk])
+ # Don't forget to call flush()!!
+ comptext = comptext + compressor.flush()
+
+ for i in range(0, len(comptext), chunk):
+ decomp = decomp + decompressor.decompress(comptext[i:i+chunk])
+ decomp=decomp+decompressor.flush()
+
+ print 'Progressive compression (level 9):'
+ print ' Original:', len(s), 'Compressed:', len(comptext),
+ print 'Uncompressed:', len(decomp)
+
+if __name__ == '__main__':
+ main()