From 73e5a5b65d66f4fba9c4f626bcd6400f4a7215e6 Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Thu, 8 Jun 2006 15:35:45 +0000 Subject: 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. , 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. ........ --- Demo/README | 3 - Demo/classes/Dates.py | 70 +- Demo/curses/README | 5 +- Demo/curses/life.py | 128 +- Demo/curses/rain.py | 4 +- Demo/curses/repeat.py | 4 +- Demo/curses/tclock.py | 25 +- Demo/curses/xmas.py | 6 +- Demo/sockets/README | 1 - Demo/sockets/unixclient.py | 4 +- Demo/sockets/unixserver.py | 15 +- Demo/threads/fcmp.py | 6 +- Demo/xmlrpc/xmlrpc_handler.py | 104 - Demo/xmlrpc/xmlrpcserver.py | 75 - Demo/zlib/minigzip.py | 147 +- Demo/zlib/zlibdemo.py | 77 +- Doc/api/newtypes.tex | 16 +- Doc/dist/dist.tex | 4 +- Doc/lib/libdoctest.tex | 15 +- Doc/lib/libfunctools.tex | 46 + Doc/lib/libsgmllib.tex | 5 +- Doc/lib/libsocket.tex | 4 +- Doc/lib/libsqlite3.tex | 101 +- Doc/lib/liburllib2.tex | 12 +- Doc/mac/undoc.tex | 11 - Doc/whatsnew/whatsnew25.tex | 22 +- Include/symtable.h | 2 + Include/unicodeobject.h | 5 + Lib/bsddb/__init__.py | 1 + Lib/bsddb/dbobj.py | 44 + Lib/bsddb/dbtables.py | 43 +- Lib/bsddb/test/test_all.py | 14 +- Lib/bsddb/test/test_basics.py | 10 + Lib/bsddb/test/test_cursor_pget_bug.py | 65 + Lib/bsddb/test/test_dbtables.py | 10 + Lib/bsddb/test/test_sequence.py | 112 + Lib/ctypes/test/test_cfuncs.py | 8 + Lib/ctypes/test/test_pointers.py | 2 +- Lib/ctypes/test/test_structures.py | 8 +- Lib/doctest.py | 85 +- Lib/encodings/cp037.py | 266 +- Lib/encodings/cp1006.py | 265 +- Lib/encodings/cp1026.py | 266 +- Lib/encodings/cp1140.py | 266 +- Lib/encodings/cp1250.py | 261 +- Lib/encodings/cp1251.py | 265 +- Lib/encodings/cp1252.py | 261 +- Lib/encodings/cp1253.py | 249 +- Lib/encodings/cp1254.py | 259 +- Lib/encodings/cp1255.py | 243 +- Lib/encodings/cp1256.py | 266 +- Lib/encodings/cp1257.py | 254 +- Lib/encodings/cp1258.py | 257 +- Lib/encodings/cp424.py | 228 +- Lib/encodings/cp500.py | 266 +- Lib/encodings/cp856.py | 225 +- Lib/encodings/cp874.py | 235 +- Lib/encodings/cp875.py | 260 +- Lib/encodings/iso8859_1.py | 266 +- Lib/encodings/iso8859_10.py | 266 +- Lib/encodings/iso8859_11.py | 258 +- Lib/encodings/iso8859_13.py | 266 +- Lib/encodings/iso8859_14.py | 266 +- Lib/encodings/iso8859_15.py | 266 +- Lib/encodings/iso8859_16.py | 266 +- Lib/encodings/iso8859_2.py | 266 +- Lib/encodings/iso8859_3.py | 259 +- Lib/encodings/iso8859_4.py | 266 +- Lib/encodings/iso8859_5.py | 266 +- Lib/encodings/iso8859_6.py | 221 +- Lib/encodings/iso8859_7.py | 263 +- Lib/encodings/iso8859_8.py | 230 +- Lib/encodings/iso8859_9.py | 266 +- Lib/encodings/koi8_r.py | 266 +- Lib/encodings/koi8_u.py | 266 +- Lib/encodings/mac_centeuro.py | 266 +- Lib/encodings/mac_croatian.py | 266 +- Lib/encodings/mac_cyrillic.py | 266 +- Lib/encodings/mac_farsi.py | 266 +- Lib/encodings/mac_greek.py | 266 +- Lib/encodings/mac_iceland.py | 266 +- Lib/encodings/mac_roman.py | 266 +- Lib/encodings/mac_romanian.py | 266 +- Lib/encodings/mac_turkish.py | 266 +- Lib/encodings/tis_620.py | 257 +- Lib/functools.py | 61 +- Lib/lib-tk/Tix.py | 4 +- Lib/markupbase.py | 2 +- Lib/plat-mac/Carbon/WASTEconst.py | 207 -- Lib/plat-mac/EasyDialogs.py | 4 +- Lib/plat-mac/WASTEconst.py | 207 -- Lib/plat-mac/argvemulator.py | 90 +- Lib/smtplib.py | 2 +- Lib/socket.py | 6 +- Lib/struct.py | 4 +- Lib/subprocess.py | 10 +- Lib/test/regrtest.py | 133 +- Lib/test/test_bsddb3.py | 2 + Lib/test/test_builtin.py | 2 +- Lib/test/test_class.py | 34 + Lib/test/test_descr.py | 15 +- Lib/test/test_doctest.py | 57 +- Lib/test/test_exceptions.py | 49 +- Lib/test/test_file.py | 655 +++-- Lib/test/test_functools.py | 109 + Lib/test/test_generators.py | 6 +- Lib/test/test_socket.py | 12 +- Lib/test/test_struct.py | 67 +- Lib/test/test_tempfile.py | 2 +- Mac/BuildScript/README.txt | 35 + Mac/BuildScript/build-installer.py | 1028 ++++++++ Mac/BuildScript/ncurses-5.5.patch | 36 + Mac/BuildScript/resources/ReadMe.txt | 31 + Mac/BuildScript/resources/Welcome.rtf | 15 + Mac/BuildScript/resources/background.jpg | Bin 0 -> 45421 bytes Mac/BuildScript/scripts/postflight.documentation | 12 + Mac/BuildScript/scripts/postflight.framework | 33 + Mac/BuildScript/scripts/postflight.patch-profile | 71 + Mac/Demo/index.html | 4 - Mac/Demo/textedit.html | 3 +- Mac/Demo/waste.html | 72 - Mac/Demo/waste/htmled.py | 830 ------- Mac/Demo/waste/swed.py | 634 ----- Mac/Demo/waste/wed.py | 426 ---- Mac/Extras.ReadMe.txt | 5 + Mac/Extras.install.py | 54 + Mac/IDLE/Info.plist.in | 55 + Mac/IDLE/Makefile.in | 59 + Mac/IDLE/config-extensions.def | 88 + Mac/IDLE/config-main.def | 79 + Mac/IDLE/idlemain.py | 27 + Mac/Icons/Disk Image.icns | Bin 0 -> 50703 bytes Mac/Icons/IDLE.icns | Bin 0 -> 53456 bytes Mac/Icons/Python Folder.icns | Bin 0 -> 133608 bytes Mac/Icons/PythonCompiled.icns | Bin 0 -> 60777 bytes Mac/Icons/PythonLauncher.icns | Bin 0 -> 42658 bytes Mac/Icons/PythonSource.icns | Bin 0 -> 54522 bytes Mac/Icons/ReadMe.txt | 3 + Mac/Makefile.in | 251 ++ Mac/Modules/waste/wastemodule.c | 2596 -------------------- Mac/Modules/waste/wastescan.py | 152 -- Mac/Modules/waste/wastesupport.py | 444 ---- Mac/OSX/BuildScript/README.txt | 35 - Mac/OSX/BuildScript/build-installer.py | 1014 -------- Mac/OSX/BuildScript/ncurses-5.5.patch | 36 - Mac/OSX/BuildScript/resources/ReadMe.txt | 31 - Mac/OSX/BuildScript/resources/Welcome.rtf | 15 - Mac/OSX/BuildScript/resources/background.jpg | Bin 45421 -> 0 bytes .../BuildScript/scripts/postflight.documentation | 12 - Mac/OSX/BuildScript/scripts/postflight.framework | 33 - .../BuildScript/scripts/postflight.patch-profile | 71 - .../HelpIndexingTool/Help_Indexing_Tool_Suite.py | 110 - .../HelpIndexingTool/Miscellaneous_Standards.py | 49 - Mac/OSX/Doc/HelpIndexingTool/Required_Suite.py | 32 - Mac/OSX/Doc/HelpIndexingTool/Standard_Suite.py | 343 --- Mac/OSX/Doc/HelpIndexingTool/__init__.py | 78 - Mac/OSX/Doc/HelpIndexingTool/odds_and_ends.py | 49 - Mac/OSX/Doc/README | 35 - Mac/OSX/Doc/setup.py | 214 -- Mac/OSX/Extras.ReadMe.txt | 5 - Mac/OSX/Extras.install.py | 54 - Mac/OSX/IDLE/Info.plist | 55 - Mac/OSX/IDLE/Makefile.in | 52 - Mac/OSX/IDLE/idlemain.py | 27 - Mac/OSX/Icons/Disk Image.icns | Bin 50703 -> 0 bytes Mac/OSX/Icons/IDLE.icns | Bin 53456 -> 0 bytes Mac/OSX/Icons/Python Folder.icns | Bin 133608 -> 0 bytes Mac/OSX/Icons/PythonCompiled.icns | Bin 60777 -> 0 bytes Mac/OSX/Icons/PythonLauncher.icns | Bin 42658 -> 0 bytes Mac/OSX/Icons/PythonSource.icns | Bin 54522 -> 0 bytes Mac/OSX/Icons/ReadMe.txt | 3 - Mac/OSX/Makefile.in | 241 -- Mac/OSX/PythonLauncher/English.lproj/Credits.rtf | 30 - .../English.lproj/MainMenu.nib/classes.nib | 12 - .../English.lproj/MainMenu.nib/info.nib | 21 - .../English.lproj/MainMenu.nib/objects.nib | Bin 5016 -> 0 bytes .../English.lproj/MyDocument.nib/classes.nib | 26 - .../English.lproj/MyDocument.nib/info.nib | 16 - .../English.lproj/MyDocument.nib/objects.nib | Bin 4845 -> 0 bytes .../English.lproj/PreferenceWindow.nib/classes.nib | 26 - .../English.lproj/PreferenceWindow.nib/info.nib | 16 - .../English.lproj/PreferenceWindow.nib/objects.nib | Bin 5882 -> 0 bytes Mac/OSX/PythonLauncher/FileSettings.h | 64 - Mac/OSX/PythonLauncher/FileSettings.m | 298 --- Mac/OSX/PythonLauncher/Info.plist | 65 - Mac/OSX/PythonLauncher/Makefile.in | 78 - Mac/OSX/PythonLauncher/MyAppDelegate.h | 15 - Mac/OSX/PythonLauncher/MyAppDelegate.m | 96 - Mac/OSX/PythonLauncher/MyDocument.h | 41 - Mac/OSX/PythonLauncher/MyDocument.m | 175 -- .../PreferenceWindow.nib/classes.nib | 26 - .../PythonLauncher/PreferenceWindow.nib/info.nib | 16 - .../PreferenceWindow.nib/objects.nib | Bin 5882 -> 0 bytes .../PythonLauncher/PreferencesWindowController.h | 38 - .../PythonLauncher/PreferencesWindowController.m | 121 - Mac/OSX/PythonLauncher/doscript.h | 12 - Mac/OSX/PythonLauncher/doscript.m | 118 - Mac/OSX/PythonLauncher/factorySettings.plist | 87 - Mac/OSX/PythonLauncher/main.m | 17 - Mac/OSX/README | 167 -- Mac/OSX/Tools/pythonw.c | 17 - Mac/OSX/fixapplepython23.py | 118 - Mac/OSXResources/app/Info.plist | 60 - Mac/OSXResources/app/PkgInfo | 1 - .../English.lproj/Documentation/PackageManager.gif | Bin 6087 -> 0 bytes .../English.lproj/Documentation/community.html | 69 - .../English.lproj/Documentation/doc/index.html | 21 - .../English.lproj/Documentation/finder.html | 36 - .../Resources/English.lproj/Documentation/gui.html | 54 - .../English.lproj/Documentation/ide/IDE.gif | Bin 10249 -> 0 bytes .../Documentation/ide/entering_in_new_window.gif | Bin 15578 -> 0 bytes .../Documentation/ide/hello_world.gif | Bin 15681 -> 0 bytes .../English.lproj/Documentation/ide/index.html | 222 -- .../Documentation/ide/loading_ide.gif | Bin 50595 -> 0 bytes .../Documentation/ide/making_new_window.gif | Bin 25978 -> 0 bytes .../Documentation/ide/new_ide_window.gif | Bin 20606 -> 0 bytes .../Documentation/ide/new_window_made.gif | Bin 21808 -> 0 bytes .../Documentation/ide/output_window.gif | Bin 37660 -> 0 bytes .../Documentation/ide/saving_edited_file.gif | Bin 26559 -> 0 bytes .../Documentation/ide/simple_commands.gif | Bin 14134 -> 0 bytes .../Documentation/ide/syntax_error.gif | Bin 12850 -> 0 bytes .../English.lproj/Documentation/index.html | 51 - .../English.lproj/Documentation/intro.html | 76 - .../English.lproj/Documentation/packman.html | 64 - .../English.lproj/Documentation/python.gif | Bin 6389 -> 0 bytes .../English.lproj/Documentation/pythonsmall.gif | Bin 138 -> 0 bytes .../English.lproj/Documentation/scripting.html | 53 - .../English.lproj/Documentation/shell.html | 52 - .../app/Resources/English.lproj/InfoPlist.strings | Bin 656 -> 0 bytes Mac/OSXResources/app/Resources/PythonApplet.icns | Bin 63136 -> 0 bytes .../app/Resources/PythonInterpreter.icns | Bin 42658 -> 0 bytes .../framework/English.lproj/InfoPlist.strings | Bin 358 -> 0 bytes Mac/OSXResources/framework/Info.plist | 26 - Mac/OSXResources/framework/version.plist | 18 - Mac/OSXResources/iconsrc/IDE.psd | Bin 83876 -> 0 bytes Mac/OSXResources/iconsrc/PackageManager.psd | Bin 71056 -> 0 bytes Mac/OSXResources/iconsrc/PythonApplet.psd | Bin 41543 -> 0 bytes Mac/OSXResources/iconsrc/PythonCompiled.psd | Bin 76118 -> 0 bytes Mac/OSXResources/iconsrc/PythonIcon.psd | Bin 67236 -> 0 bytes Mac/OSXResources/iconsrc/PythonSource.psd | Bin 62075 -> 0 bytes Mac/OSXResources/iconsrc/PythonWSource.psd | Bin 64185 -> 0 bytes Mac/PythonLauncher/English.lproj/Credits.rtf | 30 + .../English.lproj/MainMenu.nib/classes.nib | 12 + .../English.lproj/MainMenu.nib/info.nib | 21 + .../English.lproj/MainMenu.nib/objects.nib | Bin 0 -> 5016 bytes .../English.lproj/MyDocument.nib/classes.nib | 26 + .../English.lproj/MyDocument.nib/info.nib | 16 + .../English.lproj/MyDocument.nib/objects.nib | Bin 0 -> 4845 bytes .../English.lproj/PreferenceWindow.nib/classes.nib | 26 + .../English.lproj/PreferenceWindow.nib/info.nib | 16 + .../English.lproj/PreferenceWindow.nib/objects.nib | Bin 0 -> 5882 bytes Mac/PythonLauncher/FileSettings.h | 64 + Mac/PythonLauncher/FileSettings.m | 298 +++ Mac/PythonLauncher/Info.plist.in | 65 + Mac/PythonLauncher/Makefile.in | 81 + Mac/PythonLauncher/MyAppDelegate.h | 15 + Mac/PythonLauncher/MyAppDelegate.m | 96 + Mac/PythonLauncher/MyDocument.h | 41 + Mac/PythonLauncher/MyDocument.m | 175 ++ Mac/PythonLauncher/PreferencesWindowController.h | 38 + Mac/PythonLauncher/PreferencesWindowController.m | 121 + Mac/PythonLauncher/doscript.h | 12 + Mac/PythonLauncher/doscript.m | 118 + Mac/PythonLauncher/factorySettings.plist | 87 + Mac/PythonLauncher/main.m | 17 + Mac/README | 167 ++ Mac/Resources/app/Info.plist | 60 + Mac/Resources/app/PkgInfo | 1 + .../English.lproj/Documentation/PackageManager.gif | Bin 0 -> 6087 bytes .../English.lproj/Documentation/community.html | 69 + .../English.lproj/Documentation/doc/index.html | 21 + .../English.lproj/Documentation/finder.html | 36 + .../Resources/English.lproj/Documentation/gui.html | 54 + .../English.lproj/Documentation/ide/IDE.gif | Bin 0 -> 10249 bytes .../Documentation/ide/entering_in_new_window.gif | Bin 0 -> 15578 bytes .../Documentation/ide/hello_world.gif | Bin 0 -> 15681 bytes .../English.lproj/Documentation/ide/index.html | 222 ++ .../Documentation/ide/loading_ide.gif | Bin 0 -> 50595 bytes .../Documentation/ide/making_new_window.gif | Bin 0 -> 25978 bytes .../Documentation/ide/new_ide_window.gif | Bin 0 -> 20606 bytes .../Documentation/ide/new_window_made.gif | Bin 0 -> 21808 bytes .../Documentation/ide/output_window.gif | Bin 0 -> 37660 bytes .../Documentation/ide/saving_edited_file.gif | Bin 0 -> 26559 bytes .../Documentation/ide/simple_commands.gif | Bin 0 -> 14134 bytes .../Documentation/ide/syntax_error.gif | Bin 0 -> 12850 bytes .../English.lproj/Documentation/index.html | 51 + .../English.lproj/Documentation/intro.html | 76 + .../English.lproj/Documentation/packman.html | 64 + .../English.lproj/Documentation/python.gif | Bin 0 -> 6389 bytes .../English.lproj/Documentation/pythonsmall.gif | Bin 0 -> 138 bytes .../English.lproj/Documentation/scripting.html | 53 + .../English.lproj/Documentation/shell.html | 52 + .../app/Resources/English.lproj/InfoPlist.strings | Bin 0 -> 656 bytes Mac/Resources/app/Resources/PythonApplet.icns | Bin 0 -> 63136 bytes Mac/Resources/app/Resources/PythonInterpreter.icns | Bin 0 -> 42658 bytes .../framework/English.lproj/InfoPlist.strings | Bin 0 -> 358 bytes Mac/Resources/framework/Info.plist | 26 + Mac/Resources/framework/version.plist | 18 + Mac/Resources/iconsrc/IDE.psd | Bin 0 -> 83876 bytes Mac/Resources/iconsrc/PackageManager.psd | Bin 0 -> 71056 bytes Mac/Resources/iconsrc/PythonApplet.psd | Bin 0 -> 41543 bytes Mac/Resources/iconsrc/PythonCompiled.psd | Bin 0 -> 76118 bytes Mac/Resources/iconsrc/PythonIcon.psd | Bin 0 -> 67236 bytes Mac/Resources/iconsrc/PythonSource.psd | Bin 0 -> 62075 bytes Mac/Resources/iconsrc/PythonWSource.psd | Bin 0 -> 64185 bytes .../HelpIndexingTool/Help_Indexing_Tool_Suite.py | 110 + .../HelpIndexingTool/Miscellaneous_Standards.py | 49 + Mac/Tools/Doc/HelpIndexingTool/Required_Suite.py | 32 + Mac/Tools/Doc/HelpIndexingTool/Standard_Suite.py | 343 +++ Mac/Tools/Doc/HelpIndexingTool/__init__.py | 78 + Mac/Tools/Doc/HelpIndexingTool/odds_and_ends.py | 49 + Mac/Tools/Doc/README | 35 + Mac/Tools/Doc/setup.py | 214 ++ Mac/Tools/fixapplepython23.py | 119 + Mac/Tools/pythonw.c | 17 + Mac/scripts/BuildApplet.py | 12 + Makefile.pre.in | 26 +- Misc/SpecialBuilds.txt | 32 +- Modules/_bsddb.c | 594 ++++- Modules/_codecsmodule.c | 10 + Modules/_ctypes/callbacks.c | 43 +- Modules/_ctypes/callproc.c | 9 +- Modules/_ctypes/cfield.c | 37 +- Modules/_elementtree.c | 4 +- Modules/_struct.c | 29 +- Modules/_tkinter.c | 30 +- Modules/cjkcodecs/_codecs_jp.c | 3 +- Modules/socketmodule.c | 74 +- Objects/abstract.c | 3 +- Objects/classobject.c | 17 +- Objects/descrobject.c | 26 +- Objects/exceptions.c | 1 - Objects/fileobject.c | 19 +- Objects/obmalloc.c | 242 +- Objects/unicodeobject.c | 337 ++- PC/_subprocess.c | 13 +- PC/py.ico | Bin 23558 -> 19790 bytes PC/pyc.ico | Bin 23558 -> 19790 bytes PC/pycon.ico | Bin 23558 -> 19790 bytes Parser/node.c | 2 +- Python/compile.c | 43 +- Python/symtable.c | 21 +- Python/sysmodule.c | 2 +- Python/thread.c | 3 +- Python/thread_nt.h | 60 +- Python/thread_os2.h | 3 +- Tools/unicode/Makefile | 2 +- Tools/unicode/gencodec.py | 51 +- Tools/webchecker/webchecker.py | 4 +- configure | 52 +- configure.in | 30 +- setup.py | 27 +- 352 files changed, 8346 insertions(+), 23787 deletions(-) delete mode 100644 Demo/xmlrpc/xmlrpc_handler.py delete mode 100644 Demo/xmlrpc/xmlrpcserver.py create mode 100644 Lib/bsddb/test/test_cursor_pget_bug.py create mode 100644 Lib/bsddb/test/test_sequence.py delete mode 100644 Lib/plat-mac/Carbon/WASTEconst.py delete mode 100644 Lib/plat-mac/WASTEconst.py create mode 100644 Mac/BuildScript/README.txt create mode 100755 Mac/BuildScript/build-installer.py create mode 100644 Mac/BuildScript/ncurses-5.5.patch create mode 100644 Mac/BuildScript/resources/ReadMe.txt create mode 100644 Mac/BuildScript/resources/Welcome.rtf create mode 100644 Mac/BuildScript/resources/background.jpg create mode 100755 Mac/BuildScript/scripts/postflight.documentation create mode 100755 Mac/BuildScript/scripts/postflight.framework create mode 100755 Mac/BuildScript/scripts/postflight.patch-profile delete mode 100644 Mac/Demo/waste.html delete mode 100644 Mac/Demo/waste/htmled.py delete mode 100644 Mac/Demo/waste/swed.py delete mode 100644 Mac/Demo/waste/wed.py create mode 100644 Mac/Extras.ReadMe.txt create mode 100644 Mac/Extras.install.py create mode 100644 Mac/IDLE/Info.plist.in create mode 100644 Mac/IDLE/Makefile.in create mode 100644 Mac/IDLE/config-extensions.def create mode 100644 Mac/IDLE/config-main.def create mode 100644 Mac/IDLE/idlemain.py create mode 100644 Mac/Icons/Disk Image.icns create mode 100644 Mac/Icons/IDLE.icns create mode 100644 Mac/Icons/Python Folder.icns create mode 100644 Mac/Icons/PythonCompiled.icns create mode 100644 Mac/Icons/PythonLauncher.icns create mode 100644 Mac/Icons/PythonSource.icns create mode 100644 Mac/Icons/ReadMe.txt create mode 100644 Mac/Makefile.in delete mode 100644 Mac/Modules/waste/wastemodule.c delete mode 100644 Mac/Modules/waste/wastescan.py delete mode 100644 Mac/Modules/waste/wastesupport.py delete mode 100644 Mac/OSX/BuildScript/README.txt delete mode 100755 Mac/OSX/BuildScript/build-installer.py delete mode 100644 Mac/OSX/BuildScript/ncurses-5.5.patch delete mode 100644 Mac/OSX/BuildScript/resources/ReadMe.txt delete mode 100644 Mac/OSX/BuildScript/resources/Welcome.rtf delete mode 100644 Mac/OSX/BuildScript/resources/background.jpg delete mode 100755 Mac/OSX/BuildScript/scripts/postflight.documentation delete mode 100755 Mac/OSX/BuildScript/scripts/postflight.framework delete mode 100755 Mac/OSX/BuildScript/scripts/postflight.patch-profile delete mode 100644 Mac/OSX/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py delete mode 100644 Mac/OSX/Doc/HelpIndexingTool/Miscellaneous_Standards.py delete mode 100644 Mac/OSX/Doc/HelpIndexingTool/Required_Suite.py delete mode 100644 Mac/OSX/Doc/HelpIndexingTool/Standard_Suite.py delete mode 100644 Mac/OSX/Doc/HelpIndexingTool/__init__.py delete mode 100644 Mac/OSX/Doc/HelpIndexingTool/odds_and_ends.py delete mode 100644 Mac/OSX/Doc/README delete mode 100644 Mac/OSX/Doc/setup.py delete mode 100644 Mac/OSX/Extras.ReadMe.txt delete mode 100644 Mac/OSX/Extras.install.py delete mode 100644 Mac/OSX/IDLE/Info.plist delete mode 100644 Mac/OSX/IDLE/Makefile.in delete mode 100644 Mac/OSX/IDLE/idlemain.py delete mode 100644 Mac/OSX/Icons/Disk Image.icns delete mode 100644 Mac/OSX/Icons/IDLE.icns delete mode 100644 Mac/OSX/Icons/Python Folder.icns delete mode 100644 Mac/OSX/Icons/PythonCompiled.icns delete mode 100644 Mac/OSX/Icons/PythonLauncher.icns delete mode 100644 Mac/OSX/Icons/PythonSource.icns delete mode 100644 Mac/OSX/Icons/ReadMe.txt delete mode 100644 Mac/OSX/Makefile.in delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/Credits.rtf delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/classes.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/info.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/objects.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib delete mode 100644 Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib delete mode 100755 Mac/OSX/PythonLauncher/FileSettings.h delete mode 100755 Mac/OSX/PythonLauncher/FileSettings.m delete mode 100644 Mac/OSX/PythonLauncher/Info.plist delete mode 100644 Mac/OSX/PythonLauncher/Makefile.in delete mode 100644 Mac/OSX/PythonLauncher/MyAppDelegate.h delete mode 100644 Mac/OSX/PythonLauncher/MyAppDelegate.m delete mode 100755 Mac/OSX/PythonLauncher/MyDocument.h delete mode 100755 Mac/OSX/PythonLauncher/MyDocument.m delete mode 100644 Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib delete mode 100644 Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib delete mode 100644 Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib delete mode 100644 Mac/OSX/PythonLauncher/PreferencesWindowController.h delete mode 100644 Mac/OSX/PythonLauncher/PreferencesWindowController.m delete mode 100644 Mac/OSX/PythonLauncher/doscript.h delete mode 100644 Mac/OSX/PythonLauncher/doscript.m delete mode 100644 Mac/OSX/PythonLauncher/factorySettings.plist delete mode 100755 Mac/OSX/PythonLauncher/main.m delete mode 100644 Mac/OSX/README delete mode 100644 Mac/OSX/Tools/pythonw.c delete mode 100644 Mac/OSX/fixapplepython23.py delete mode 100644 Mac/OSXResources/app/Info.plist delete mode 100644 Mac/OSXResources/app/PkgInfo delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/PackageManager.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/community.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/doc/index.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/finder.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/gui.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/IDE.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/hello_world.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/index.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/output_window.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/index.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/intro.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/packman.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/python.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/pythonsmall.gif delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/scripting.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/Documentation/shell.html delete mode 100644 Mac/OSXResources/app/Resources/English.lproj/InfoPlist.strings delete mode 100644 Mac/OSXResources/app/Resources/PythonApplet.icns delete mode 100644 Mac/OSXResources/app/Resources/PythonInterpreter.icns delete mode 100644 Mac/OSXResources/framework/English.lproj/InfoPlist.strings delete mode 100644 Mac/OSXResources/framework/Info.plist delete mode 100644 Mac/OSXResources/framework/version.plist delete mode 100644 Mac/OSXResources/iconsrc/IDE.psd delete mode 100644 Mac/OSXResources/iconsrc/PackageManager.psd delete mode 100644 Mac/OSXResources/iconsrc/PythonApplet.psd delete mode 100755 Mac/OSXResources/iconsrc/PythonCompiled.psd delete mode 100755 Mac/OSXResources/iconsrc/PythonIcon.psd delete mode 100755 Mac/OSXResources/iconsrc/PythonSource.psd delete mode 100644 Mac/OSXResources/iconsrc/PythonWSource.psd create mode 100644 Mac/PythonLauncher/English.lproj/Credits.rtf create mode 100644 Mac/PythonLauncher/English.lproj/MainMenu.nib/classes.nib create mode 100644 Mac/PythonLauncher/English.lproj/MainMenu.nib/info.nib create mode 100644 Mac/PythonLauncher/English.lproj/MainMenu.nib/objects.nib create mode 100644 Mac/PythonLauncher/English.lproj/MyDocument.nib/classes.nib create mode 100644 Mac/PythonLauncher/English.lproj/MyDocument.nib/info.nib create mode 100644 Mac/PythonLauncher/English.lproj/MyDocument.nib/objects.nib create mode 100644 Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib create mode 100644 Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib create mode 100644 Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib create mode 100755 Mac/PythonLauncher/FileSettings.h create mode 100755 Mac/PythonLauncher/FileSettings.m create mode 100644 Mac/PythonLauncher/Info.plist.in create mode 100644 Mac/PythonLauncher/Makefile.in create mode 100644 Mac/PythonLauncher/MyAppDelegate.h create mode 100644 Mac/PythonLauncher/MyAppDelegate.m create mode 100755 Mac/PythonLauncher/MyDocument.h create mode 100755 Mac/PythonLauncher/MyDocument.m create mode 100644 Mac/PythonLauncher/PreferencesWindowController.h create mode 100644 Mac/PythonLauncher/PreferencesWindowController.m create mode 100644 Mac/PythonLauncher/doscript.h create mode 100644 Mac/PythonLauncher/doscript.m create mode 100644 Mac/PythonLauncher/factorySettings.plist create mode 100755 Mac/PythonLauncher/main.m create mode 100644 Mac/README create mode 100644 Mac/Resources/app/Info.plist create mode 100644 Mac/Resources/app/PkgInfo create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/PackageManager.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/community.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/doc/index.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/finder.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/gui.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/IDE.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/hello_world.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/index.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/output_window.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/index.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/intro.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/packman.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/python.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/pythonsmall.gif create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/scripting.html create mode 100644 Mac/Resources/app/Resources/English.lproj/Documentation/shell.html create mode 100644 Mac/Resources/app/Resources/English.lproj/InfoPlist.strings create mode 100644 Mac/Resources/app/Resources/PythonApplet.icns create mode 100644 Mac/Resources/app/Resources/PythonInterpreter.icns create mode 100644 Mac/Resources/framework/English.lproj/InfoPlist.strings create mode 100644 Mac/Resources/framework/Info.plist create mode 100644 Mac/Resources/framework/version.plist create mode 100644 Mac/Resources/iconsrc/IDE.psd create mode 100644 Mac/Resources/iconsrc/PackageManager.psd create mode 100644 Mac/Resources/iconsrc/PythonApplet.psd create mode 100755 Mac/Resources/iconsrc/PythonCompiled.psd create mode 100755 Mac/Resources/iconsrc/PythonIcon.psd create mode 100755 Mac/Resources/iconsrc/PythonSource.psd create mode 100644 Mac/Resources/iconsrc/PythonWSource.psd create mode 100644 Mac/Tools/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py create mode 100644 Mac/Tools/Doc/HelpIndexingTool/Miscellaneous_Standards.py create mode 100644 Mac/Tools/Doc/HelpIndexingTool/Required_Suite.py create mode 100644 Mac/Tools/Doc/HelpIndexingTool/Standard_Suite.py create mode 100644 Mac/Tools/Doc/HelpIndexingTool/__init__.py create mode 100644 Mac/Tools/Doc/HelpIndexingTool/odds_and_ends.py create mode 100644 Mac/Tools/Doc/README create mode 100644 Mac/Tools/Doc/setup.py create mode 100644 Mac/Tools/fixapplepython23.py create mode 100644 Mac/Tools/pythonw.c 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 -(). +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 00: ypos=ypos-1 - elif c==curses.KEY_DOWN and ypos0: xpos=xpos-1 - elif c==curses.KEY_RIGHT and xpos0: ypos -= 1 + elif c == curses.KEY_DOWN and ypos0: xpos -= 1 + elif c == curses.KEY_RIGHT and xpos -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 ' - 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 ' + 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() diff --git a/Doc/api/newtypes.tex b/Doc/api/newtypes.tex index 28f77f7..04f6795 100644 --- a/Doc/api/newtypes.tex +++ b/Doc/api/newtypes.tex @@ -1549,7 +1549,9 @@ to be able to test for its presence before using it.} Before using this slot, the caller should test whether it is present by using the \cfunction{PyType_HasFeature()}\ttindex{PyType_HasFeature()} - function. If present, it may be \NULL, indicating that the object's + function. If the flag is present, \member{bf_getcharbuffer} may be + \NULL, + indicating that the object's contents cannot be used as \emph{8-bit characters}. The slot function may also raise an error if the object's contents cannot be interpreted as 8-bit characters. For example, if the @@ -1574,12 +1576,13 @@ to be able to test for its presence before using it.} \begin{ctypedesc}[getreadbufferproc]{Py_ssize_t (*readbufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr)} - Return a pointer to a readable segment of the buffer. This function + Return a pointer to a readable segment of the buffer in + \code{*\var{ptrptr}}. This function is allowed to raise an exception, in which case it must return - \code{-1}. The \var{segment} which is passed must be zero or + \code{-1}. The \var{segment} which is specified must be zero or positive, and strictly less than the number of segments returned by the \member{bf_getsegcount} slot function. On success, it returns - the length of the buffer memory, and sets \code{*\var{ptrptr}} to a + the length of the segment, and sets \code{*\var{ptrptr}} to a pointer to that memory. \end{ctypedesc} @@ -1608,8 +1611,9 @@ to be able to test for its presence before using it.} \begin{ctypedesc}[getcharbufferproc]{Py_ssize_t (*charbufferproc) (PyObject *self, Py_ssize_t segment, const char **ptrptr)} - Return the size of the memory buffer in \var{ptrptr} for segment - \var{segment}. \code{*\var{ptrptr}} is set to the memory buffer. + Return the size of the segment \var{segment} that \var{ptrptr} + is set to. \code{*\var{ptrptr}} is set to the memory buffer. + Returns \code{-1} on error. \end{ctypedesc} diff --git a/Doc/dist/dist.tex b/Doc/dist/dist.tex index 9970ec2..e95c0d3 100644 --- a/Doc/dist/dist.tex +++ b/Doc/dist/dist.tex @@ -849,7 +849,7 @@ version. This information includes: {long string}{} \lineiv{download_url}{location where the package may be downloaded} {URL}{(4)} - \lineiv{classifiers}{a list of Trove classifiers} + \lineiv{classifiers}{a list of classifiers} {list of strings}{(4)} \end{tableiv} @@ -2251,7 +2251,7 @@ are laid out in the following table. \lineiii{scripts}{A list of standalone script files to be built and installed}{a list of strings} \lineiii{ext_modules}{A list of Python extensions to be built}{A list of instances of \class{distutils.core.Extension}} -\lineiii{classifiers}{A list of Trove categories for the package}{XXX link to better definition} +\lineiii{classifiers}{A list of categories for the package}{The list of available categorizations is at \url{http://cheeseshop.python.org/pypi?:action=list_classifiers}.} \lineiii{distclass}{the \class{Distribution} class to use}{A subclass of \class{distutils.core.Distribution}} % What on earth is the use case for script_name? \lineiii{script_name}{The name of the setup.py script - defaults to \code{sys.argv[0]}}{a string} diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index f9a97fa..957ecf4 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -952,7 +952,7 @@ sections \ref{doctest-simple-testmod} and \begin{funcdesc}{testmod}{\optional{m}\optional{, name}\optional{, globs}\optional{, verbose}\optional{, - isprivate}\optional{, report}\optional{, + report}\optional{, optionflags}\optional{, extraglobs}\optional{, raise_on_error}\optional{, exclude_empty}} @@ -990,19 +990,14 @@ sections \ref{doctest-simple-testmod} and for function \function{testfile()} above, except that \var{globs} defaults to \code{\var{m}.__dict__}. - Optional argument \var{isprivate} specifies a function used to - determine whether a name is private. The default function treats - all names as public. \var{isprivate} can be set to - \code{doctest.is_private} to skip over names that are - private according to Python's underscore naming convention. - \deprecated{2.4}{\var{isprivate} was a stupid idea -- don't use it. - If you need to skip tests based on name, filter the list returned by - \code{DocTestFinder.find()} instead.} - \versionchanged[The parameter \var{optionflags} was added]{2.3} \versionchanged[The parameters \var{extraglobs}, \var{raise_on_error} and \var{exclude_empty} were added]{2.4} + + \versionchanged[The optional argument \var{isprivate}, deprecated + in 2.4, was removed]{2.5} + \end{funcdesc} There's also a function to run the doctests associated with a single object. diff --git a/Doc/lib/libfunctools.tex b/Doc/lib/libfunctools.tex index a25a23a..33a6f52 100644 --- a/Doc/lib/libfunctools.tex +++ b/Doc/lib/libfunctools.tex @@ -5,6 +5,7 @@ \moduleauthor{Peter Harris}{scav@blueyonder.co.uk} \moduleauthor{Raymond Hettinger}{python@rcn.com} +\moduleauthor{Nick Coghlan}{ncoghlan@gmail.com} \sectionauthor{Peter Harris}{scav@blueyonder.co.uk} \modulesynopsis{Higher-order functions and operations on callable objects.} @@ -50,6 +51,51 @@ two: \end{verbatim} \end{funcdesc} +\begin{funcdesc}{update_wrapper} +{wrapper, wrapped\optional{, assigned}\optional{, updated}} +Update a wrapper function to look like the wrapped function. The optional +arguments are tuples to specify which attributes of the original +function are assigned directly to the matching attributes on the wrapper +function and which attributes of the wrapper function are updated with +the corresponding attributes from the original function. The default +values for these arguments are the module level constants +\var{WRAPPER_ASSIGNMENTS} (which assigns to the wrapper function's name, +module and documentation string) and \var{WRAPPER_UPDATES} (which +updates the wrapper function's instance dictionary). + +The main intended use for this function is in decorator functions +which wrap the decorated function and return the wrapper. If the +wrapper function is not updated, the metadata of the returned function +will reflect the wrapper definition rather than the original function +definition, which is typically less than helpful. +\end{funcdesc} + +\begin{funcdesc}{wraps} +{wrapped\optional{, assigned}\optional{, updated}} +This is a convenience function for invoking +\code{partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)} +as a function decorator when defining a wrapper function. For example: + \begin{verbatim} + >>> def my_decorator(f): + ... @wraps(f) + ... def wrapper(*args, **kwds): + ... print 'Calling decorated function' + ... return f(*args, **kwds) + ... return wrapper + ... + >>> @my_decorator + ... def example(): + ... print 'Called example function' + ... + >>> example() + Calling decorated function + Called example function + >>> example.__name__ + 'example' + \end{verbatim} +Without the use of this decorator factory, the name of the example +function would have been \code{'wrapper'}. +\end{funcdesc} \subsection{\class{partial} Objects \label{partial-objects}} diff --git a/Doc/lib/libsgmllib.tex b/Doc/lib/libsgmllib.tex index 1578313..3ec1018 100644 --- a/Doc/lib/libsgmllib.tex +++ b/Doc/lib/libsgmllib.tex @@ -218,8 +218,9 @@ preference over \method{do_\var{tag}()}. The \end{methoddescni} \begin{methoddescni}{do_\var{tag}}{attributes} -This method is called to process an opening tag \var{tag} that does -not come with a matching closing tag. The \var{attributes} argument +This method is called to process an opening tag \var{tag} +for which no \method{start_\var{tag}} method is defined. +The \var{attributes} argument has the same meaning as described for \method{handle_starttag()} above. \end{methoddescni} diff --git a/Doc/lib/libsocket.tex b/Doc/lib/libsocket.tex index c7b656d..8066528 100644 --- a/Doc/lib/libsocket.tex +++ b/Doc/lib/libsocket.tex @@ -548,7 +548,7 @@ are described in \ref{bltin-file-objects}, ``File Objects.'') The file object references a \cfunction{dup()}ped version of the socket file descriptor, so the file object and socket object may be closed or garbage-collected independently. -The socket should be in blocking mode. +The socket must be in blocking mode. \index{I/O control!buffering}The optional \var{mode} and \var{bufsize} arguments are interpreted the same way as by the built-in \function{file()} function; see ``Built-in Functions'' @@ -647,7 +647,7 @@ Timeout mode internally sets the socket in non-blocking mode. The blocking and timeout modes are shared between file descriptors and socket objects that refer to the same network endpoint. A consequence of this is that file objects returned by the \method{makefile()} -method should only be used when the socket is in blocking mode; in +method must only be used when the socket is in blocking mode; in timeout or non-blocking mode file operations that cannot be completed immediately will fail. diff --git a/Doc/lib/libsqlite3.tex b/Doc/lib/libsqlite3.tex index 8c80eb6..db15c00 100644 --- a/Doc/lib/libsqlite3.tex +++ b/Doc/lib/libsqlite3.tex @@ -6,6 +6,105 @@ \sectionauthor{Gerhard Häring}{gh@ghaering.de} \versionadded{2.5} +SQLite is a C library that provides a SQL-language database that +stores data in disk files without requiring a separate server process. +pysqlite was written by Gerhard H\"aring and provides a SQL interface +compliant with the DB-API 2.0 specification described by +\pep{249}. This means that it should be possible to write the first +version of your applications using SQLite for data storage. If +switching to a larger database such as PostgreSQL or Oracle is +later necessary, the switch should be relatively easy. + +To use the module, you must first create a \class{Connection} object +that represents the database. Here the data will be stored in the +\file{/tmp/example} file: + +\begin{verbatim} +conn = sqlite3.connect('/tmp/example') +\end{verbatim} + +You can also supply the special name \samp{:memory:} to create +a database in RAM. + +Once you have a \class{Connection}, you can create a \class{Cursor} +object and call its \method{execute()} method to perform SQL commands: + +\begin{verbatim} +c = conn.cursor() + +# Create table +c.execute('''create table stocks +(date timestamp, trans varchar, symbol varchar, + qty decimal, price decimal)''') + +# Insert a row of data +c.execute("""insert into stocks + values ('2006-01-05','BUY','RHAT',100,35.14)""") +\end{verbatim} + +Usually your SQL operations will need to use values from Python +variables. You shouldn't assemble your query using Python's string +operations because doing so is insecure; it makes your program +vulnerable to an SQL injection attack. + +Instead, use the DB-API's parameter substitution. Put \samp{?} as a +placeholder wherever you want to use a value, and then provide a tuple +of values as the second argument to the cursor's \method{execute()} +method. (Other database modules may use a different placeholder, +such as \samp{\%s} or \samp{:1}.) For example: + +\begin{verbatim} +# Never do this -- insecure! +symbol = 'IBM' +c.execute("... where symbol = '%s'" % symbol) + +# Do this instead +t = (symbol,) +c.execute('select * from stocks where symbol=?', t) + +# Larger example +for t in (('2006-03-28', 'BUY', 'IBM', 1000, 45.00), + ('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00), + ('2006-04-06', 'SELL', 'IBM', 500, 53.00), + ): + c.execute('insert into stocks values (?,?,?,?,?)', t) +\end{verbatim} + +To retrieve data after executing a SELECT statement, you can either +treat the cursor as an iterator, call the cursor's \method{fetchone()} +method to retrieve a single matching row, +or call \method{fetchall()} to get a list of the matching rows. + +This example uses the iterator form: + +\begin{verbatim} +>>> c = conn.cursor() +>>> c.execute('select * from stocks order by price') +>>> for row in c: +... print row +... +(u'2006-01-05', u'BUY', u'RHAT', 100, 35.140000000000001) +(u'2006-03-28', u'BUY', u'IBM', 1000, 45.0) +(u'2006-04-06', u'SELL', u'IBM', 500, 53.0) +(u'2006-04-05', u'BUY', u'MSOFT', 1000, 72.0) +>>> +\end{verbatim} + +\begin{seealso} + +\seeurl{http://www.pysqlite.org} +{The pysqlite web page.} + +\seeurl{http://www.sqlite.org} +{The SQLite web page; the documentation describes the syntax and the +available data types for the supported SQL dialect.} + +\seepep{249}{Database API Specification 2.0}{PEP written by +Marc-Andr\'e Lemburg.} + +\end{seealso} + + \subsection{Module functions and constants\label{sqlite3-Module-Contents}} \begin{datadesc}{PARSE_DECLTYPES} @@ -467,7 +566,7 @@ connections. If you want \strong{autocommit mode}, then set \member{isolation_level} to None. -Otherwise leave it at it's default, which will result in a plain "BEGIN" +Otherwise leave it at its default, which will result in a plain "BEGIN" statement, or set it to one of SQLite's supported isolation levels: DEFERRED, IMMEDIATE or EXCLUSIVE. diff --git a/Doc/lib/liburllib2.tex b/Doc/lib/liburllib2.tex index f77ed25..f4351c3 100644 --- a/Doc/lib/liburllib2.tex +++ b/Doc/lib/liburllib2.tex @@ -18,11 +18,13 @@ The \module{urllib2} module defines the following functions: Open the URL \var{url}, which can be either a string or a \class{Request} object. -\var{data} should be a string, which specifies additional data to -send to the server. In HTTP requests, which are the only ones that -support \var{data}, it should be a buffer in the format of -\mimetype{application/x-www-form-urlencoded}, for example one returned -from \function{urllib.urlencode()}. +\var{data} may be a string specifying additional data to send to the +server. Currently HTTP requests are the only ones that use \var{data}; +the HTTP request will be a POST instead of a GET when the \var{data} +parameter is provided. \var{data} should be a buffer in the standard +\mimetype{application/x-www-form-urlencoded} format. The +\function{urllib.urlencode()} function takes a mapping or sequence of +2-tuples and returns a string in this format. This function returns a file-like object with two additional methods: diff --git a/Doc/mac/undoc.tex b/Doc/mac/undoc.tex index 63a4dbd..72abadf 100644 --- a/Doc/mac/undoc.tex +++ b/Doc/mac/undoc.tex @@ -95,14 +95,3 @@ audio tracks. The \module{W} widgets are used extensively in the \program{IDE}. -\section{\module{waste} --- non-Apple \program{TextEdit} replacement} -\declaremodule{standard}{waste} - \platform{Mac} -\modulesynopsis{Interface to the ``WorldScript-Aware Styled Text Engine.''} - -\begin{seealso} - \seetitle[http://www.merzwaren.com/waste/]{About WASTE}{Information - about the WASTE widget and library, including - documentation and downloads.} -\end{seealso} - diff --git a/Doc/whatsnew/whatsnew25.tex b/Doc/whatsnew/whatsnew25.tex index 5bee789..4015d98 100644 --- a/Doc/whatsnew/whatsnew25.tex +++ b/Doc/whatsnew/whatsnew25.tex @@ -1166,12 +1166,13 @@ In 2.5 the internal data structure has been customized for implementing sets, and as a result sets will use a third less memory and are somewhat faster. (Implemented by Raymond Hettinger.) -\item The speed of some Unicode operations, such as -finding substrings, string splitting, and character map decoding, has -been improved. (Substring search and splitting improvements were +\item The speed of some Unicode operations, such as finding +substrings, string splitting, and character map encoding and decoding, +has been improved. (Substring search and splitting improvements were added by Fredrik Lundh and Andrew Dalke at the NeedForSpeed -sprint. Character map decoding was improved by Walter D\"orwald.) -% Patch 1313939 +sprint. Character maps were improved by Walter D\"orwald and +Martin von~L\"owis.) +% Patch 1313939, 1359618 \item The \function{long(\var{str}, \var{base})} function is now faster on long digit strings because fewer intermediate results are @@ -1185,6 +1186,11 @@ strings into an internal representation and caches this representation, yielding a 20\% speedup. (Contributed by Bob Ippolito at the NeedForSpeed sprint.) +\item The \module{re} module got a 1 or 2\% speedup by switching to +Python's allocator functions instead of the system's +\cfunction{malloc()} and \cfunction{free()}. +(Contributed by Jack Diederich at the NeedForSpeed sprint.) + \item The code generator's peephole optimizer now performs simple constant folding in expressions. If you write something like \code{a = 2+3}, the code generator will do the arithmetic and produce @@ -1358,7 +1364,6 @@ to specify which generation to collect. now support a \code{key} keyword parameter similar to the one provided by the \function{min()}/\function{max()} functions and the \method{sort()} methods. For example: -Example: \begin{verbatim} >>> import heapq @@ -1923,10 +1928,11 @@ variables. You shouldn't assemble your query using Python's string operations because doing so is insecure; it makes your program vulnerable to an SQL injection attack. -Instead, use SQLite's parameter substitution. Put \samp{?} as a +Instead, use the DB-API's parameter substitution. Put \samp{?} as a placeholder wherever you want to use a value, and then provide a tuple of values as the second argument to the cursor's \method{execute()} -method. For example: +method. (Other database modules may use a different placeholder, +such as \samp{\%s} or \samp{:1}.) For example: \begin{verbatim} # Never do this -- insecure! diff --git a/Include/symtable.h b/Include/symtable.h index 222831a..1e5996d 100644 --- a/Include/symtable.h +++ b/Include/symtable.h @@ -39,6 +39,8 @@ typedef struct _symtable_entry { unsigned ste_generator : 1; /* true if namespace is a generator */ unsigned ste_varargs : 1; /* true if block has varargs */ unsigned ste_varkeywords : 1; /* true if block has varkeywords */ + unsigned ste_returns_value : 1; /* true if namespace uses return with + an argument */ int ste_lineno; /* first line of block */ int ste_opt_lineno; /* lineno of last exec or import * */ int ste_tmpname; /* counter for listcomp temp vars */ diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 8c39cfe..3177051 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -650,6 +650,11 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString( const char *errors /* error handling */ ); +PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap( + PyObject* string /* 256 character map */ + ); + + /* --- UTF-7 Codecs ------------------------------------------------------- */ PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7( diff --git a/Lib/bsddb/__init__.py b/Lib/bsddb/__init__.py index c004c08..90ed362 100644 --- a/Lib/bsddb/__init__.py +++ b/Lib/bsddb/__init__.py @@ -343,6 +343,7 @@ def _openDBEnv(cachesize): e.set_cachesize(0, cachesize) else: raise error, "cachesize must be >= 20480" + e.set_lk_detect(db.DB_LOCK_DEFAULT) e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL) return e diff --git a/Lib/bsddb/dbobj.py b/Lib/bsddb/dbobj.py index 4a75dd2..961b9e9 100644 --- a/Lib/bsddb/dbobj.py +++ b/Lib/bsddb/dbobj.py @@ -91,9 +91,14 @@ class DBEnv: return self._cobj.lock_stat(*args, **kwargs) def log_archive(self, *args, **kwargs): return self._cobj.log_archive(*args, **kwargs) + def set_get_returns_none(self, *args, **kwargs): return self._cobj.set_get_returns_none(*args, **kwargs) + if db.version() >= (4,0): + def log_stat(self, *args, **kwargs): + return apply(self._cobj.log_stat, args, kwargs) + if db.version() >= (4,1): def dbremove(self, *args, **kwargs): return self._cobj.dbremove(*args, **kwargs) @@ -102,6 +107,10 @@ class DBEnv: def set_encrypt(self, *args, **kwargs): return self._cobj.set_encrypt(*args, **kwargs) + if db.version() >= (4,4): + def lsn_reset(self, *args, **kwargs): + return apply(self._cobj.lsn_reset, args, kwargs) + class DB(DictMixin): def __init__(self, dbenv, *args, **kwargs): @@ -208,3 +217,38 @@ class DB(DictMixin): if db.version() >= (4,1): def set_encrypt(self, *args, **kwargs): return self._cobj.set_encrypt(*args, **kwargs) + + +class DBSequence: + def __init__(self, *args, **kwargs): + self._cobj = apply(db.DBSequence, args, kwargs) + + def close(self, *args, **kwargs): + return apply(self._cobj.close, args, kwargs) + def get(self, *args, **kwargs): + return apply(self._cobj.get, args, kwargs) + def get_dbp(self, *args, **kwargs): + return apply(self._cobj.get_dbp, args, kwargs) + def get_key(self, *args, **kwargs): + return apply(self._cobj.get_key, args, kwargs) + def init_value(self, *args, **kwargs): + return apply(self._cobj.init_value, args, kwargs) + def open(self, *args, **kwargs): + return apply(self._cobj.open, args, kwargs) + def remove(self, *args, **kwargs): + return apply(self._cobj.remove, args, kwargs) + def stat(self, *args, **kwargs): + return apply(self._cobj.stat, args, kwargs) + def set_cachesize(self, *args, **kwargs): + return apply(self._cobj.set_cachesize, args, kwargs) + def set_flags(self, *args, **kwargs): + return apply(self._cobj.set_flags, args, kwargs) + def set_range(self, *args, **kwargs): + return apply(self._cobj.set_range, args, kwargs) + def get_cachesize(self, *args, **kwargs): + return apply(self._cobj.get_cachesize, args, kwargs) + def get_flags(self, *args, **kwargs): + return apply(self._cobj.get_flags, args, kwargs) + def get_range(self, *args, **kwargs): + return apply(self._cobj.get_range, args, kwargs) +>>>>>>> .merge-right.r46752 diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py index fd33b6e..369db43 100644 --- a/Lib/bsddb/dbtables.py +++ b/Lib/bsddb/dbtables.py @@ -131,7 +131,8 @@ def contains_metastrings(s) : class bsdTableDB : def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600, recover=0, dbflags=0): - """bsdTableDB.open(filename, dbhome, create=0, truncate=0, mode=0600) + """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600) + Open database name in the dbhome BerkeleyDB directory. Use keyword arguments when calling this constructor. """ @@ -218,7 +219,8 @@ class bsdTableDB : def CreateTable(self, table, columns): - """CreateTable(table, columns) - Create a new table in the database + """CreateTable(table, columns) - Create a new table in the database. + raises TableDBError if it already exists or for other DB errors. """ assert isinstance(columns, ListType) @@ -286,7 +288,8 @@ class bsdTableDB : def CreateOrExtendTable(self, table, columns): """CreateOrExtendTable(table, columns) - - Create a new table in the database. + Create a new table in the database. + If a table of this name already exists, extend it to have any additional columns present in the given list as well as all of its current columns. @@ -411,14 +414,15 @@ class bsdTableDB : def Modify(self, table, conditions={}, mappings={}): - """Modify(table, conditions) - Modify in rows matching 'conditions' - using mapping functions in 'mappings' - * conditions is a dictionary keyed on column names - containing condition functions expecting the data string as an - argument and returning a boolean. - * mappings is a dictionary keyed on column names containint condition - functions expecting the data string as an argument and returning the - new string for that column. + """Modify(table, conditions={}, mappings={}) - Modify items in rows matching 'conditions' using mapping functions in 'mappings' + + * table - the table name + * conditions - a dictionary keyed on column names containing + a condition callable expecting the data string as an + argument and returning a boolean. + * mappings - a dictionary keyed on column names containing a + condition callable expecting the data string as an argument and + returning the new string for that column. """ try: matching_rowids = self.__Select(table, [], conditions) @@ -450,7 +454,8 @@ class bsdTableDB : txn.commit() txn = None - except DBError, dberror: + # catch all exceptions here since we call unknown callables + except: if txn: txn.abort() raise @@ -461,9 +466,10 @@ class bsdTableDB : def Delete(self, table, conditions={}): """Delete(table, conditions) - Delete items matching the given conditions from the table. - * conditions is a dictionary keyed on column names - containing condition functions expecting the data string as an - argument and returning a boolean. + + * conditions - a dictionary keyed on column names containing + condition functions expecting the data string as an + argument and returning a boolean. """ try: matching_rowids = self.__Select(table, [], conditions) @@ -499,11 +505,12 @@ class bsdTableDB : def Select(self, table, columns, conditions={}): - """Select(table, conditions) - retrieve specific row data + """Select(table, columns, conditions) - retrieve specific row data Returns a list of row column->value mapping dictionaries. - * columns is a list of which column data to return. If + + * columns - a list of which column data to return. If columns is None, all columns will be returned. - * conditions is a dictionary keyed on column names + * conditions - a dictionary keyed on column names containing callable conditions expecting the data string as an argument and returning a boolean. """ diff --git a/Lib/bsddb/test/test_all.py b/Lib/bsddb/test/test_all.py index abfaf47..ad8b1e9 100644 --- a/Lib/bsddb/test/test_all.py +++ b/Lib/bsddb/test/test_all.py @@ -4,6 +4,12 @@ import sys import os import unittest +try: + # For Pythons w/distutils pybsddb + from bsddb3 import db +except ImportError: + # For Python 2.3 + from bsddb import db verbose = 0 if 'verbose' in sys.argv: @@ -16,12 +22,6 @@ if 'silent' in sys.argv: # take care of old flag, just in case def print_versions(): - try: - # For Pythons w/distutils pybsddb - from bsddb3 import db - except ImportError: - # For Python 2.3 - from bsddb import db print print '-=' * 38 print db.DB_VERSION_STRING @@ -69,6 +69,8 @@ def suite(): 'test_queue', 'test_recno', 'test_thread', + 'test_sequence', + 'test_cursor_pget_bug', ] alltests = unittest.TestSuite() diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py index 7e8f835..bec5da3 100644 --- a/Lib/bsddb/test/test_basics.py +++ b/Lib/bsddb/test/test_basics.py @@ -659,12 +659,22 @@ class BasicTransactionTestCase(BasicTestCase): except db.DBIncompleteError: pass + if db.version() >= (4,0): + statDict = self.env.log_stat(0); + assert statDict.has_key('magic') + assert statDict.has_key('version') + assert statDict.has_key('cur_file') + assert statDict.has_key('region_nowait') + # must have at least one log file present: logs = self.env.log_archive(db.DB_ARCH_ABS | db.DB_ARCH_LOG) assert logs != None for log in logs: if verbose: print 'log file: ' + log + if db.version >= (4,2): + logs = self.env.log_archive(db.DB_ARCH_REMOVE) + assert not logs self.txn = self.env.txn_begin() diff --git a/Lib/bsddb/test/test_cursor_pget_bug.py b/Lib/bsddb/test/test_cursor_pget_bug.py new file mode 100644 index 0000000..de47e6d --- /dev/null +++ b/Lib/bsddb/test/test_cursor_pget_bug.py @@ -0,0 +1,65 @@ +import unittest +import sys, os, glob + +try: + # For Pythons w/distutils pybsddb + from bsddb3 import db +except ImportError: + # For Python 2.3 + from bsddb import db + + +#---------------------------------------------------------------------- + +class pget_bugTestCase(unittest.TestCase): + """Verify that cursor.pget works properly""" + db_name = 'test-cursor_pget.db' + + def setUp(self): + self.homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home') + try: + os.mkdir(self.homeDir) + except os.error: + pass + self.env = db.DBEnv() + self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL) + self.primary_db = db.DB(self.env) + self.primary_db.open(self.db_name, 'primary', db.DB_BTREE, db.DB_CREATE) + self.secondary_db = db.DB(self.env) + self.secondary_db.set_flags(db.DB_DUP) + self.secondary_db.open(self.db_name, 'secondary', db.DB_BTREE, db.DB_CREATE) + self.primary_db.associate(self.secondary_db, lambda key, data: data) + self.primary_db.put('salad', 'eggs') + self.primary_db.put('spam', 'ham') + self.primary_db.put('omelet', 'eggs') + + + def tearDown(self): + self.secondary_db.close() + self.primary_db.close() + self.env.close() + del self.secondary_db + del self.primary_db + del self.env + for file in glob.glob(os.path.join(self.homeDir, '*')): + os.remove(file) + os.removedirs(self.homeDir) + + def test_pget(self): + cursor = self.secondary_db.cursor() + + self.assertEquals(('eggs', 'salad', 'eggs'), cursor.pget(key='eggs', flags=db.DB_SET)) + self.assertEquals(('eggs', 'omelet', 'eggs'), cursor.pget(db.DB_NEXT_DUP)) + self.assertEquals(None, cursor.pget(db.DB_NEXT_DUP)) + + self.assertEquals(('ham', 'spam', 'ham'), cursor.pget('ham', 'spam', flags=db.DB_SET)) + self.assertEquals(None, cursor.pget(db.DB_NEXT_DUP)) + + cursor.close() + + +def test_suite(): + return unittest.makeSuite(pget_bugTestCase) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py index 1128a5a..26e3d36 100644 --- a/Lib/bsddb/test/test_dbtables.py +++ b/Lib/bsddb/test/test_dbtables.py @@ -339,6 +339,16 @@ class TableDBTestCase(unittest.TestCase): conditions={'Name': dbtables.LikeCond('%')}, mappings={'Access': increment_access}) + try: + self.tdb.Modify(tabname, + conditions={'Name': dbtables.LikeCond('%')}, + mappings={'Access': 'What is your quest?'}) + except TypeError: + # success, the string value in mappings isn't callable + pass + else: + raise RuntimeError, "why was TypeError not raised for bad callable?" + # Delete key in select conditions values = self.tdb.Select( tabname, None, diff --git a/Lib/bsddb/test/test_sequence.py b/Lib/bsddb/test/test_sequence.py new file mode 100644 index 0000000..979f858 --- /dev/null +++ b/Lib/bsddb/test/test_sequence.py @@ -0,0 +1,112 @@ +import unittest +import os +import sys +import tempfile +import glob + +try: + # For Pythons w/distutils pybsddb + from bsddb3 import db +except ImportError: + from bsddb import db + +from test_all import verbose + + +class DBSequenceTest(unittest.TestCase): + def setUp(self): + self.int_32_max = 0x100000000 + self.homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home') + try: + os.mkdir(self.homeDir) + except os.error: + pass + tempfile.tempdir = self.homeDir + self.filename = os.path.split(tempfile.mktemp())[1] + tempfile.tempdir = None + + self.dbenv = db.DBEnv() + self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 0666) + self.d = db.DB(self.dbenv) + self.d.open(self.filename, db.DB_BTREE, db.DB_CREATE, 0666) + + def tearDown(self): + if hasattr(self, 'seq'): + self.seq.close() + del self.seq + if hasattr(self, 'd'): + self.d.close() + del self.d + if hasattr(self, 'dbenv'): + self.dbenv.close() + del self.dbenv + + files = glob.glob(os.path.join(self.homeDir, '*')) + for file in files: + os.remove(file) + + def test_get(self): + self.seq = db.DBSequence(self.d, flags=0) + start_value = 10 * self.int_32_max + self.assertEqual(0xA00000000, start_value) + self.assertEquals(None, self.seq.init_value(start_value)) + self.assertEquals(None, self.seq.open(key='id', txn=None, flags=db.DB_CREATE)) + self.assertEquals(start_value, self.seq.get(5)) + self.assertEquals(start_value + 5, self.seq.get()) + + def test_remove(self): + self.seq = db.DBSequence(self.d, flags=0) + self.assertEquals(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) + self.assertEquals(None, self.seq.remove(txn=None, flags=0)) + del self.seq + + def test_get_key(self): + self.seq = db.DBSequence(self.d, flags=0) + key = 'foo' + self.assertEquals(None, self.seq.open(key=key, txn=None, flags=db.DB_CREATE)) + self.assertEquals(key, self.seq.get_key()) + + def test_get_dbp(self): + self.seq = db.DBSequence(self.d, flags=0) + self.assertEquals(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) + self.assertEquals(self.d, self.seq.get_dbp()) + + def test_cachesize(self): + self.seq = db.DBSequence(self.d, flags=0) + cashe_size = 10 + self.assertEquals(None, self.seq.set_cachesize(cashe_size)) + self.assertEquals(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) + self.assertEquals(cashe_size, self.seq.get_cachesize()) + + def test_flags(self): + self.seq = db.DBSequence(self.d, flags=0) + flag = db.DB_SEQ_WRAP; + self.assertEquals(None, self.seq.set_flags(flag)) + self.assertEquals(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) + self.assertEquals(flag, self.seq.get_flags() & flag) + + def test_range(self): + self.seq = db.DBSequence(self.d, flags=0) + seq_range = (10 * self.int_32_max, 11 * self.int_32_max - 1) + self.assertEquals(None, self.seq.set_range(seq_range)) + self.seq.init_value(seq_range[0]) + self.assertEquals(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) + self.assertEquals(seq_range, self.seq.get_range()) + + def test_stat(self): + self.seq = db.DBSequence(self.d, flags=0) + self.assertEquals(None, self.seq.open(key='foo', txn=None, flags=db.DB_CREATE)) + stat = self.seq.stat() + for param in ('nowait', 'min', 'max', 'value', 'current', + 'flags', 'cache_size', 'last_value', 'wait'): + self.assertTrue(param in stat, "parameter %s isn't in stat info" % param) + +def test_suite(): + suite = unittest.TestSuite() + if db.version() >= (4,3): + suite.addTest(unittest.makeSuite(DBSequenceTest)) + return suite + + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') diff --git a/Lib/ctypes/test/test_cfuncs.py b/Lib/ctypes/test/test_cfuncs.py index 9d8db1f..fa858a6 100644 --- a/Lib/ctypes/test/test_cfuncs.py +++ b/Lib/ctypes/test/test_cfuncs.py @@ -40,41 +40,49 @@ class CFunctions(unittest.TestCase): def test_short(self): self._dll.tf_h.restype = c_short + self._dll.tf_h.argtypes = (c_short,) self.failUnlessEqual(self._dll.tf_h(-32766), -10922) self.failUnlessEqual(self.S(), -32766) def test_short_plus(self): self._dll.tf_bh.restype = c_short + self._dll.tf_bh.argtypes = (c_byte, c_short) self.failUnlessEqual(self._dll.tf_bh(0, -32766), -10922) self.failUnlessEqual(self.S(), -32766) def test_ushort(self): self._dll.tf_H.restype = c_ushort + self._dll.tf_H.argtypes = (c_ushort,) self.failUnlessEqual(self._dll.tf_H(65535), 21845) self.failUnlessEqual(self.U(), 65535) def test_ushort_plus(self): self._dll.tf_bH.restype = c_ushort + self._dll.tf_bH.argtypes = (c_byte, c_ushort) self.failUnlessEqual(self._dll.tf_bH(0, 65535), 21845) self.failUnlessEqual(self.U(), 65535) def test_int(self): self._dll.tf_i.restype = c_int + self._dll.tf_i.argtypes = (c_int,) self.failUnlessEqual(self._dll.tf_i(-2147483646), -715827882) self.failUnlessEqual(self.S(), -2147483646) def test_int_plus(self): self._dll.tf_bi.restype = c_int + self._dll.tf_bi.argtypes = (c_byte, c_int) self.failUnlessEqual(self._dll.tf_bi(0, -2147483646), -715827882) self.failUnlessEqual(self.S(), -2147483646) def test_uint(self): self._dll.tf_I.restype = c_uint + self._dll.tf_I.argtypes = (c_uint,) self.failUnlessEqual(self._dll.tf_I(4294967295), 1431655765) self.failUnlessEqual(self.U(), 4294967295) def test_uint_plus(self): self._dll.tf_bI.restype = c_uint + self._dll.tf_bI.argtypes = (c_byte, c_uint) self.failUnlessEqual(self._dll.tf_bI(0, 4294967295), 1431655765) self.failUnlessEqual(self.U(), 4294967295) diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py index 600bb75..a7a2802 100644 --- a/Lib/ctypes/test/test_pointers.py +++ b/Lib/ctypes/test/test_pointers.py @@ -133,7 +133,7 @@ class PointersTestCase(unittest.TestCase): self.failUnlessEqual(p[0], 42) self.failUnlessEqual(p.contents.value, 42) - def test_charpp( self ): + def test_charpp(self): """Test that a character pointer-to-pointer is correctly passed""" dll = CDLL(_ctypes_test.__file__) func = dll._testfunc_c_p_p diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py index 5340f79..49f064b 100644 --- a/Lib/ctypes/test/test_structures.py +++ b/Lib/ctypes/test/test_structures.py @@ -138,8 +138,8 @@ class StructureTestCase(unittest.TestCase): self.failUnlessEqual(X.y.size, sizeof(c_char)) # readonly - self.assertRaises(TypeError, setattr, X.x, "offset", 92) - self.assertRaises(TypeError, setattr, X.x, "size", 92) + self.assertRaises(AttributeError, setattr, X.x, "offset", 92) + self.assertRaises(AttributeError, setattr, X.x, "size", 92) class X(Union): _fields_ = [("x", c_int), @@ -152,8 +152,8 @@ class StructureTestCase(unittest.TestCase): self.failUnlessEqual(X.y.size, sizeof(c_char)) # readonly - self.assertRaises(TypeError, setattr, X.x, "offset", 92) - self.assertRaises(TypeError, setattr, X.x, "size", 92) + self.assertRaises(AttributeError, setattr, X.x, "offset", 92) + self.assertRaises(AttributeError, setattr, X.x, "size", 92) # XXX Should we check nested data types also? # offset is always relative to the class... diff --git a/Lib/doctest.py b/Lib/doctest.py index d549163..47b3aae 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -63,7 +63,6 @@ __all__ = [ 'REPORT_ONLY_FIRST_FAILURE', 'REPORTING_FLAGS', # 1. Utility Functions - 'is_private', # 2. Example & DocTest 'Example', 'DocTest', @@ -101,11 +100,6 @@ import unittest, difflib, pdb, tempfile import warnings from StringIO import StringIO -# Don't whine about the deprecated is_private function in this -# module's tests. -warnings.filterwarnings("ignore", "is_private", DeprecationWarning, - __name__, 0) - # There are 4 basic classes: # - Example: a pair, plus an intra-docstring line number. # - DocTest: a collection of examples, parsed from a docstring, plus @@ -178,35 +172,6 @@ ELLIPSIS_MARKER = '...' ## 1. Utility Functions ###################################################################### -def is_private(prefix, base): - """prefix, base -> true iff name prefix + "." + base is "private". - - Prefix may be an empty string, and base does not contain a period. - Prefix is ignored (although functions you write conforming to this - protocol may make use of it). - Return true iff base begins with an (at least one) underscore, but - does not both begin and end with (at least) two underscores. - - >>> is_private("a.b", "my_func") - False - >>> is_private("____", "_my_func") - True - >>> is_private("someclass", "__init__") - False - >>> is_private("sometypo", "__init_") - True - >>> is_private("x.y.z", "_") - True - >>> is_private("_x.y.z", "__") - False - >>> is_private("", "") # senseless but consistent - False - """ - warnings.warn("is_private is deprecated; it wasn't useful; " - "examine DocTestFinder.find() lists instead", - DeprecationWarning, stacklevel=2) - return base[:1] == "_" and not base[:2] == "__" == base[-2:] - def _extract_future_flags(globs): """ Return the compiler-flags associated with the future features that @@ -759,7 +724,7 @@ class DocTestFinder: """ def __init__(self, verbose=False, parser=DocTestParser(), - recurse=True, _namefilter=None, exclude_empty=True): + recurse=True, exclude_empty=True): """ Create a new doctest finder. @@ -779,12 +744,8 @@ class DocTestFinder: self._verbose = verbose self._recurse = recurse self._exclude_empty = exclude_empty - # _namefilter is undocumented, and exists only for temporary backward- - # compatibility support of testmod's deprecated isprivate mess. - self._namefilter = _namefilter - def find(self, obj, name=None, module=None, globs=None, - extraglobs=None): + def find(self, obj, name=None, module=None, globs=None, extraglobs=None): """ Return a list of the DocTests that are defined by the given object's docstring, or by any of its contained objects' @@ -862,13 +823,6 @@ class DocTestFinder: self._find(tests, obj, name, module, source_lines, globs, {}) return tests - def _filter(self, obj, prefix, base): - """ - Return true if the given object should not be examined. - """ - return (self._namefilter is not None and - self._namefilter(prefix, base)) - def _from_module(self, module, object): """ Return true if the given object is defined in the given @@ -910,9 +864,6 @@ class DocTestFinder: # Look for tests in a module's contained objects. if inspect.ismodule(obj) and self._recurse: for valname, val in obj.__dict__.items(): - # Check if this contained object should be ignored. - if self._filter(val, name, valname): - continue valname = '%s.%s' % (name, valname) # Recurse to functions & classes. if ((inspect.isfunction(val) or inspect.isclass(val)) and @@ -941,9 +892,6 @@ class DocTestFinder: # Look for tests in a class's contained objects. if inspect.isclass(obj) and self._recurse: for valname, val in obj.__dict__.items(): - # Check if this contained object should be ignored. - if self._filter(val, name, valname): - continue # Special handling for staticmethod/classmethod. if isinstance(val, staticmethod): val = getattr(obj, valname) @@ -1751,17 +1699,16 @@ class DebugRunner(DocTestRunner): # class, updated by testmod. master = None -def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None, +def testmod(m=None, name=None, globs=None, verbose=None, report=True, optionflags=0, extraglobs=None, raise_on_error=False, exclude_empty=False): - """m=None, name=None, globs=None, verbose=None, isprivate=None, - report=True, optionflags=0, extraglobs=None, raise_on_error=False, + """m=None, name=None, globs=None, verbose=None, report=True, + optionflags=0, extraglobs=None, raise_on_error=False, exclude_empty=False Test examples in docstrings in functions and classes reachable from module m (or the current module if m is not supplied), starting - with m.__doc__. Unless isprivate is specified, private names - are not skipped. + with m.__doc__. Also test examples reachable from dict m.__test__ if it exists and is not None. m.__test__ maps names to functions, classes and strings; @@ -1810,13 +1757,6 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None, first unexpected exception or failure. This allows failures to be post-mortem debugged. - Deprecated in Python 2.4: - Optional keyword arg "isprivate" specifies a function used to - determine whether a name is private. The default function is - treat all functions as public. Optionally, "isprivate" can be - set to doctest.is_private to skip over functions marked as private - using the underscore naming convention; see its docs for details. - Advanced tomfoolery: testmod runs methods of a local instance of class doctest.Tester, then merges the results into (or creates) global Tester instance doctest.master. Methods of doctest.master @@ -1827,11 +1767,6 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None, """ global master - if isprivate is not None: - warnings.warn("the isprivate argument is deprecated; " - "examine DocTestFinder.find() lists instead", - DeprecationWarning) - # If no module was given, then use __main__. if m is None: # DWA - m will still be None if this wasn't invoked from the command @@ -1848,7 +1783,7 @@ def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None, name = m.__name__ # Find, parse, and run all tests in the given module. - finder = DocTestFinder(_namefilter=isprivate, exclude_empty=exclude_empty) + finder = DocTestFinder(exclude_empty=exclude_empty) if raise_on_error: runner = DebugRunner(verbose=verbose, optionflags=optionflags) @@ -2021,8 +1956,7 @@ def run_docstring_examples(f, globs, verbose=False, name="NoName", # actually used in any way. class Tester: - def __init__(self, mod=None, globs=None, verbose=None, - isprivate=None, optionflags=0): + def __init__(self, mod=None, globs=None, verbose=None, optionflags=0): warnings.warn("class Tester is deprecated; " "use class doctest.DocTestRunner instead", @@ -2037,9 +1971,8 @@ class Tester: self.globs = globs self.verbose = verbose - self.isprivate = isprivate self.optionflags = optionflags - self.testfinder = DocTestFinder(_namefilter=isprivate) + self.testfinder = DocTestFinder() self.testrunner = DocTestRunner(verbose=verbose, optionflags=optionflags) diff --git a/Lib/encodings/cp037.py b/Lib/encodings/cp037.py index 7e589a9..c802b89 100644 --- a/Lib/encodings/cp037.py +++ b/Lib/encodings/cp037.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\x9f' # 0xFF -> CONTROL ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x37, # END OF TRANSMISSION - 0x0005: 0x2D, # ENQUIRY - 0x0006: 0x2E, # ACKNOWLEDGE - 0x0007: 0x2F, # BELL - 0x0008: 0x16, # BACKSPACE - 0x0009: 0x05, # HORIZONTAL TABULATION - 0x000A: 0x25, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x3C, # DEVICE CONTROL FOUR - 0x0015: 0x3D, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x32, # SYNCHRONOUS IDLE - 0x0017: 0x26, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x3F, # SUBSTITUTE - 0x001B: 0x27, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x40, # SPACE - 0x0021: 0x5A, # EXCLAMATION MARK - 0x0022: 0x7F, # QUOTATION MARK - 0x0023: 0x7B, # NUMBER SIGN - 0x0024: 0x5B, # DOLLAR SIGN - 0x0025: 0x6C, # PERCENT SIGN - 0x0026: 0x50, # AMPERSAND - 0x0027: 0x7D, # APOSTROPHE - 0x0028: 0x4D, # LEFT PARENTHESIS - 0x0029: 0x5D, # RIGHT PARENTHESIS - 0x002A: 0x5C, # ASTERISK - 0x002B: 0x4E, # PLUS SIGN - 0x002C: 0x6B, # COMMA - 0x002D: 0x60, # HYPHEN-MINUS - 0x002E: 0x4B, # FULL STOP - 0x002F: 0x61, # SOLIDUS - 0x0030: 0xF0, # DIGIT ZERO - 0x0031: 0xF1, # DIGIT ONE - 0x0032: 0xF2, # DIGIT TWO - 0x0033: 0xF3, # DIGIT THREE - 0x0034: 0xF4, # DIGIT FOUR - 0x0035: 0xF5, # DIGIT FIVE - 0x0036: 0xF6, # DIGIT SIX - 0x0037: 0xF7, # DIGIT SEVEN - 0x0038: 0xF8, # DIGIT EIGHT - 0x0039: 0xF9, # DIGIT NINE - 0x003A: 0x7A, # COLON - 0x003B: 0x5E, # SEMICOLON - 0x003C: 0x4C, # LESS-THAN SIGN - 0x003D: 0x7E, # EQUALS SIGN - 0x003E: 0x6E, # GREATER-THAN SIGN - 0x003F: 0x6F, # QUESTION MARK - 0x0040: 0x7C, # COMMERCIAL AT - 0x0041: 0xC1, # LATIN CAPITAL LETTER A - 0x0042: 0xC2, # LATIN CAPITAL LETTER B - 0x0043: 0xC3, # LATIN CAPITAL LETTER C - 0x0044: 0xC4, # LATIN CAPITAL LETTER D - 0x0045: 0xC5, # LATIN CAPITAL LETTER E - 0x0046: 0xC6, # LATIN CAPITAL LETTER F - 0x0047: 0xC7, # LATIN CAPITAL LETTER G - 0x0048: 0xC8, # LATIN CAPITAL LETTER H - 0x0049: 0xC9, # LATIN CAPITAL LETTER I - 0x004A: 0xD1, # LATIN CAPITAL LETTER J - 0x004B: 0xD2, # LATIN CAPITAL LETTER K - 0x004C: 0xD3, # LATIN CAPITAL LETTER L - 0x004D: 0xD4, # LATIN CAPITAL LETTER M - 0x004E: 0xD5, # LATIN CAPITAL LETTER N - 0x004F: 0xD6, # LATIN CAPITAL LETTER O - 0x0050: 0xD7, # LATIN CAPITAL LETTER P - 0x0051: 0xD8, # LATIN CAPITAL LETTER Q - 0x0052: 0xD9, # LATIN CAPITAL LETTER R - 0x0053: 0xE2, # LATIN CAPITAL LETTER S - 0x0054: 0xE3, # LATIN CAPITAL LETTER T - 0x0055: 0xE4, # LATIN CAPITAL LETTER U - 0x0056: 0xE5, # LATIN CAPITAL LETTER V - 0x0057: 0xE6, # LATIN CAPITAL LETTER W - 0x0058: 0xE7, # LATIN CAPITAL LETTER X - 0x0059: 0xE8, # LATIN CAPITAL LETTER Y - 0x005A: 0xE9, # LATIN CAPITAL LETTER Z - 0x005B: 0xBA, # LEFT SQUARE BRACKET - 0x005C: 0xE0, # REVERSE SOLIDUS - 0x005D: 0xBB, # RIGHT SQUARE BRACKET - 0x005E: 0xB0, # CIRCUMFLEX ACCENT - 0x005F: 0x6D, # LOW LINE - 0x0060: 0x79, # GRAVE ACCENT - 0x0061: 0x81, # LATIN SMALL LETTER A - 0x0062: 0x82, # LATIN SMALL LETTER B - 0x0063: 0x83, # LATIN SMALL LETTER C - 0x0064: 0x84, # LATIN SMALL LETTER D - 0x0065: 0x85, # LATIN SMALL LETTER E - 0x0066: 0x86, # LATIN SMALL LETTER F - 0x0067: 0x87, # LATIN SMALL LETTER G - 0x0068: 0x88, # LATIN SMALL LETTER H - 0x0069: 0x89, # LATIN SMALL LETTER I - 0x006A: 0x91, # LATIN SMALL LETTER J - 0x006B: 0x92, # LATIN SMALL LETTER K - 0x006C: 0x93, # LATIN SMALL LETTER L - 0x006D: 0x94, # LATIN SMALL LETTER M - 0x006E: 0x95, # LATIN SMALL LETTER N - 0x006F: 0x96, # LATIN SMALL LETTER O - 0x0070: 0x97, # LATIN SMALL LETTER P - 0x0071: 0x98, # LATIN SMALL LETTER Q - 0x0072: 0x99, # LATIN SMALL LETTER R - 0x0073: 0xA2, # LATIN SMALL LETTER S - 0x0074: 0xA3, # LATIN SMALL LETTER T - 0x0075: 0xA4, # LATIN SMALL LETTER U - 0x0076: 0xA5, # LATIN SMALL LETTER V - 0x0077: 0xA6, # LATIN SMALL LETTER W - 0x0078: 0xA7, # LATIN SMALL LETTER X - 0x0079: 0xA8, # LATIN SMALL LETTER Y - 0x007A: 0xA9, # LATIN SMALL LETTER Z - 0x007B: 0xC0, # LEFT CURLY BRACKET - 0x007C: 0x4F, # VERTICAL LINE - 0x007D: 0xD0, # RIGHT CURLY BRACKET - 0x007E: 0xA1, # TILDE - 0x007F: 0x07, # DELETE - 0x0080: 0x20, # CONTROL - 0x0081: 0x21, # CONTROL - 0x0082: 0x22, # CONTROL - 0x0083: 0x23, # CONTROL - 0x0084: 0x24, # CONTROL - 0x0085: 0x15, # CONTROL - 0x0086: 0x06, # CONTROL - 0x0087: 0x17, # CONTROL - 0x0088: 0x28, # CONTROL - 0x0089: 0x29, # CONTROL - 0x008A: 0x2A, # CONTROL - 0x008B: 0x2B, # CONTROL - 0x008C: 0x2C, # CONTROL - 0x008D: 0x09, # CONTROL - 0x008E: 0x0A, # CONTROL - 0x008F: 0x1B, # CONTROL - 0x0090: 0x30, # CONTROL - 0x0091: 0x31, # CONTROL - 0x0092: 0x1A, # CONTROL - 0x0093: 0x33, # CONTROL - 0x0094: 0x34, # CONTROL - 0x0095: 0x35, # CONTROL - 0x0096: 0x36, # CONTROL - 0x0097: 0x08, # CONTROL - 0x0098: 0x38, # CONTROL - 0x0099: 0x39, # CONTROL - 0x009A: 0x3A, # CONTROL - 0x009B: 0x3B, # CONTROL - 0x009C: 0x04, # CONTROL - 0x009D: 0x14, # CONTROL - 0x009E: 0x3E, # CONTROL - 0x009F: 0xFF, # CONTROL - 0x00A0: 0x41, # NO-BREAK SPACE - 0x00A1: 0xAA, # INVERTED EXCLAMATION MARK - 0x00A2: 0x4A, # CENT SIGN - 0x00A3: 0xB1, # POUND SIGN - 0x00A4: 0x9F, # CURRENCY SIGN - 0x00A5: 0xB2, # YEN SIGN - 0x00A6: 0x6A, # BROKEN BAR - 0x00A7: 0xB5, # SECTION SIGN - 0x00A8: 0xBD, # DIAERESIS - 0x00A9: 0xB4, # COPYRIGHT SIGN - 0x00AA: 0x9A, # FEMININE ORDINAL INDICATOR - 0x00AB: 0x8A, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0x5F, # NOT SIGN - 0x00AD: 0xCA, # SOFT HYPHEN - 0x00AE: 0xAF, # REGISTERED SIGN - 0x00AF: 0xBC, # MACRON - 0x00B0: 0x90, # DEGREE SIGN - 0x00B1: 0x8F, # PLUS-MINUS SIGN - 0x00B2: 0xEA, # SUPERSCRIPT TWO - 0x00B3: 0xFA, # SUPERSCRIPT THREE - 0x00B4: 0xBE, # ACUTE ACCENT - 0x00B5: 0xA0, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB3, # MIDDLE DOT - 0x00B8: 0x9D, # CEDILLA - 0x00B9: 0xDA, # SUPERSCRIPT ONE - 0x00BA: 0x9B, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0x8B, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xB7, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xB8, # VULGAR FRACTION ONE HALF - 0x00BE: 0xB9, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xAB, # INVERTED QUESTION MARK - 0x00C0: 0x64, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0x65, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0x62, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0x66, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x63, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x67, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0x9E, # LATIN CAPITAL LIGATURE AE - 0x00C7: 0x68, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0x74, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x71, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0x72, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0x73, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0x78, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0x75, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0x76, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0x77, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xAC, # LATIN CAPITAL LETTER ETH (ICELANDIC) - 0x00D1: 0x69, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xED, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEB, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xEF, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xEC, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xBF, # MULTIPLICATION SIGN - 0x00D8: 0x80, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xFD, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xFE, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xFB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xFC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xAD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xAE, # LATIN CAPITAL LETTER THORN (ICELANDIC) - 0x00DF: 0x59, # LATIN SMALL LETTER SHARP S (GERMAN) - 0x00E0: 0x44, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x45, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x42, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x46, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x43, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x47, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0x9C, # LATIN SMALL LIGATURE AE - 0x00E7: 0x48, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x54, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x51, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x52, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x53, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x58, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x55, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x56, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x57, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0x8C, # LATIN SMALL LETTER ETH (ICELANDIC) - 0x00F1: 0x49, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xCD, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xCE, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xCB, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xCF, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xCC, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xE1, # DIVISION SIGN - 0x00F8: 0x70, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xDD, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xDE, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xDB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xDC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0x8D, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0x8E, # LATIN SMALL LETTER THORN (ICELANDIC) - 0x00FF: 0xDF, # LATIN SMALL LETTER Y WITH DIAERESIS -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1006.py b/Lib/encodings/cp1006.py index 7829969..e21e804 100644 --- a/Lib/encodings/cp1006.py +++ b/Lib/encodings/cp1006.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,262 +303,5 @@ decoding_table = ( u'\ufe7d' # 0xFF -> ARABIC SHADDA MEDIAL FORM ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00AD: 0xAD, # SOFT HYPHEN - 0x060C: 0xAB, # ARABIC COMMA - 0x061B: 0xAC, # ARABIC SEMICOLON - 0x061F: 0xAE, # ARABIC QUESTION MARK - 0x06F0: 0xA1, # EXTENDED ARABIC-INDIC DIGIT ZERO - 0x06F1: 0xA2, # EXTENDED ARABIC-INDIC DIGIT ONE - 0x06F2: 0xA3, # EXTENDED ARABIC-INDIC DIGIT TWO - 0x06F3: 0xA4, # EXTENDED ARABIC-INDIC DIGIT THREE - 0x06F4: 0xA5, # EXTENDED ARABIC-INDIC DIGIT FOUR - 0x06F5: 0xA6, # EXTENDED ARABIC-INDIC DIGIT FIVE - 0x06F6: 0xA7, # EXTENDED ARABIC-INDIC DIGIT SIX - 0x06F7: 0xA8, # EXTENDED ARABIC-INDIC DIGIT SEVEN - 0x06F8: 0xA9, # EXTENDED ARABIC-INDIC DIGIT EIGHT - 0x06F9: 0xAA, # EXTENDED ARABIC-INDIC DIGIT NINE - 0xFB56: 0xB5, # ARABIC LETTER PEH ISOLATED FORM - 0xFB58: 0xB6, # ARABIC LETTER PEH INITIAL FORM - 0xFB66: 0xBA, # ARABIC LETTER TTEH ISOLATED FORM - 0xFB68: 0xBB, # ARABIC LETTER TTEH INITIAL FORM - 0xFB7A: 0xC0, # ARABIC LETTER TCHEH ISOLATED FORM - 0xFB7C: 0xC1, # ARABIC LETTER TCHEH INITIAL FORM - 0xFB84: 0xC7, # ARABIC LETTER DAHAL ISOLATED FORMN - 0xFB8A: 0xCC, # ARABIC LETTER JEH ISOLATED FORM - 0xFB8C: 0xCA, # ARABIC LETTER RREH ISOLATED FORM - 0xFB92: 0xE5, # ARABIC LETTER GAF ISOLATED FORM - 0xFB94: 0xE6, # ARABIC LETTER GAF INITIAL FORM - 0xFB9E: 0xEC, # ARABIC LETTER NOON GHUNNA ISOLATED FORM - 0xFBA6: 0xF1, # ARABIC LETTER HEH GOAL ISOLATED FORM - 0xFBA8: 0xF2, # ARABIC LETTER HEH GOAL INITIAL FORM - 0xFBA9: 0xF3, # ARABIC LETTER HEH GOAL MEDIAL FORM - 0xFBAA: 0xF4, # ARABIC LETTER HEH DOACHASHMEE ISOLATED FORM - 0xFBAE: 0xFD, # ARABIC LETTER YEH BARREE ISOLATED FORM - 0xFBB0: 0xFC, # ARABIC LETTER YEH BARREE WITH HAMZA ABOVE ISOLATED FORM - 0xFE7C: 0xFE, # ARABIC SHADDA ISOLATED FORM - 0xFE7D: 0xFF, # ARABIC SHADDA MEDIAL FORM - 0xFE80: 0xF5, # ARABIC LETTER HAMZA ISOLATED FORM - 0xFE81: 0xAF, # ARABIC LETTER ALEF WITH MADDA ABOVE ISOLATED FORM - 0xFE85: 0xEF, # ARABIC LETTER WAW WITH HAMZA ABOVE ISOLATED FORM - 0xFE89: 0xF6, # ARABIC LETTER YEH WITH HAMZA ABOVE ISOLATED FORM - 0xFE8A: 0xF7, # ARABIC LETTER YEH WITH HAMZA ABOVE FINAL FORM - 0xFE8B: 0xF8, # ARABIC LETTER YEH WITH HAMZA ABOVE INITIAL FORM - 0xFE8D: 0xB0, # ARABIC LETTER ALEF ISOLATED FORM - 0xFE8E: None, # ARABIC LETTER ALEF FINAL FORM - 0xFE8F: 0xB3, # ARABIC LETTER BEH ISOLATED FORM - 0xFE91: 0xB4, # ARABIC LETTER BEH INITIAL FORM - 0xFE93: 0xB7, # ARABIC LETTER TEH MARBUTA ISOLATED FORM - 0xFE95: 0xB8, # ARABIC LETTER TEH ISOLATED FORM - 0xFE97: 0xB9, # ARABIC LETTER TEH INITIAL FORM - 0xFE99: 0xBC, # ARABIC LETTER THEH ISOLATED FORM - 0xFE9B: 0xBD, # ARABIC LETTER THEH INITIAL FORM - 0xFE9D: 0xBE, # ARABIC LETTER JEEM ISOLATED FORM - 0xFE9F: 0xBF, # ARABIC LETTER JEEM INITIAL FORM - 0xFEA1: 0xC2, # ARABIC LETTER HAH ISOLATED FORM - 0xFEA3: 0xC3, # ARABIC LETTER HAH INITIAL FORM - 0xFEA5: 0xC4, # ARABIC LETTER KHAH ISOLATED FORM - 0xFEA7: 0xC5, # ARABIC LETTER KHAH INITIAL FORM - 0xFEA9: 0xC6, # ARABIC LETTER DAL ISOLATED FORM - 0xFEAB: 0xC8, # ARABIC LETTER THAL ISOLATED FORM - 0xFEAD: 0xC9, # ARABIC LETTER REH ISOLATED FORM - 0xFEAF: 0xCB, # ARABIC LETTER ZAIN ISOLATED FORM - 0xFEB1: 0xCD, # ARABIC LETTER SEEN ISOLATED FORM - 0xFEB3: 0xCE, # ARABIC LETTER SEEN INITIAL FORM - 0xFEB5: 0xCF, # ARABIC LETTER SHEEN ISOLATED FORM - 0xFEB7: 0xD0, # ARABIC LETTER SHEEN INITIAL FORM - 0xFEB9: 0xD1, # ARABIC LETTER SAD ISOLATED FORM - 0xFEBB: 0xD2, # ARABIC LETTER SAD INITIAL FORM - 0xFEBD: 0xD3, # ARABIC LETTER DAD ISOLATED FORM - 0xFEBF: 0xD4, # ARABIC LETTER DAD INITIAL FORM - 0xFEC1: 0xD5, # ARABIC LETTER TAH ISOLATED FORM - 0xFEC5: 0xD6, # ARABIC LETTER ZAH ISOLATED FORM - 0xFEC9: 0xD7, # ARABIC LETTER AIN ISOLATED FORM - 0xFECA: 0xD8, # ARABIC LETTER AIN FINAL FORM - 0xFECB: 0xD9, # ARABIC LETTER AIN INITIAL FORM - 0xFECC: 0xDA, # ARABIC LETTER AIN MEDIAL FORM - 0xFECD: 0xDB, # ARABIC LETTER GHAIN ISOLATED FORM - 0xFECE: 0xDC, # ARABIC LETTER GHAIN FINAL FORM - 0xFECF: 0xDD, # ARABIC LETTER GHAIN INITIAL FORM - 0xFED0: 0xDE, # ARABIC LETTER GHAIN MEDIAL FORM - 0xFED1: 0xDF, # ARABIC LETTER FEH ISOLATED FORM - 0xFED3: 0xE0, # ARABIC LETTER FEH INITIAL FORM - 0xFED5: 0xE1, # ARABIC LETTER QAF ISOLATED FORM - 0xFED7: 0xE2, # ARABIC LETTER QAF INITIAL FORM - 0xFED9: 0xE3, # ARABIC LETTER KAF ISOLATED FORM - 0xFEDB: 0xE4, # ARABIC LETTER KAF INITIAL FORM - 0xFEDD: 0xE7, # ARABIC LETTER LAM ISOLATED FORM - 0xFEDF: 0xE8, # ARABIC LETTER LAM INITIAL FORM - 0xFEE0: 0xE9, # ARABIC LETTER LAM MEDIAL FORM - 0xFEE1: 0xEA, # ARABIC LETTER MEEM ISOLATED FORM - 0xFEE3: 0xEB, # ARABIC LETTER MEEM INITIAL FORM - 0xFEE5: 0xED, # ARABIC LETTER NOON ISOLATED FORM - 0xFEE7: 0xEE, # ARABIC LETTER NOON INITIAL FORM - 0xFEED: 0xF0, # ARABIC LETTER WAW ISOLATED FORM - 0xFEF1: 0xF9, # ARABIC LETTER YEH ISOLATED FORM - 0xFEF2: 0xFA, # ARABIC LETTER YEH FINAL FORM - 0xFEF3: 0xFB, # ARABIC LETTER YEH INITIAL FORM -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1026.py b/Lib/encodings/cp1026.py index 01c8804..45bbe62 100644 --- a/Lib/encodings/cp1026.py +++ b/Lib/encodings/cp1026.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\x9f' # 0xFF -> CONTROL ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x37, # END OF TRANSMISSION - 0x0005: 0x2D, # ENQUIRY - 0x0006: 0x2E, # ACKNOWLEDGE - 0x0007: 0x2F, # BELL - 0x0008: 0x16, # BACKSPACE - 0x0009: 0x05, # HORIZONTAL TABULATION - 0x000A: 0x25, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x3C, # DEVICE CONTROL FOUR - 0x0015: 0x3D, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x32, # SYNCHRONOUS IDLE - 0x0017: 0x26, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x3F, # SUBSTITUTE - 0x001B: 0x27, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x40, # SPACE - 0x0021: 0x4F, # EXCLAMATION MARK - 0x0022: 0xFC, # QUOTATION MARK - 0x0023: 0xEC, # NUMBER SIGN - 0x0024: 0xAD, # DOLLAR SIGN - 0x0025: 0x6C, # PERCENT SIGN - 0x0026: 0x50, # AMPERSAND - 0x0027: 0x7D, # APOSTROPHE - 0x0028: 0x4D, # LEFT PARENTHESIS - 0x0029: 0x5D, # RIGHT PARENTHESIS - 0x002A: 0x5C, # ASTERISK - 0x002B: 0x4E, # PLUS SIGN - 0x002C: 0x6B, # COMMA - 0x002D: 0x60, # HYPHEN-MINUS - 0x002E: 0x4B, # FULL STOP - 0x002F: 0x61, # SOLIDUS - 0x0030: 0xF0, # DIGIT ZERO - 0x0031: 0xF1, # DIGIT ONE - 0x0032: 0xF2, # DIGIT TWO - 0x0033: 0xF3, # DIGIT THREE - 0x0034: 0xF4, # DIGIT FOUR - 0x0035: 0xF5, # DIGIT FIVE - 0x0036: 0xF6, # DIGIT SIX - 0x0037: 0xF7, # DIGIT SEVEN - 0x0038: 0xF8, # DIGIT EIGHT - 0x0039: 0xF9, # DIGIT NINE - 0x003A: 0x7A, # COLON - 0x003B: 0x5E, # SEMICOLON - 0x003C: 0x4C, # LESS-THAN SIGN - 0x003D: 0x7E, # EQUALS SIGN - 0x003E: 0x6E, # GREATER-THAN SIGN - 0x003F: 0x6F, # QUESTION MARK - 0x0040: 0xAE, # COMMERCIAL AT - 0x0041: 0xC1, # LATIN CAPITAL LETTER A - 0x0042: 0xC2, # LATIN CAPITAL LETTER B - 0x0043: 0xC3, # LATIN CAPITAL LETTER C - 0x0044: 0xC4, # LATIN CAPITAL LETTER D - 0x0045: 0xC5, # LATIN CAPITAL LETTER E - 0x0046: 0xC6, # LATIN CAPITAL LETTER F - 0x0047: 0xC7, # LATIN CAPITAL LETTER G - 0x0048: 0xC8, # LATIN CAPITAL LETTER H - 0x0049: 0xC9, # LATIN CAPITAL LETTER I - 0x004A: 0xD1, # LATIN CAPITAL LETTER J - 0x004B: 0xD2, # LATIN CAPITAL LETTER K - 0x004C: 0xD3, # LATIN CAPITAL LETTER L - 0x004D: 0xD4, # LATIN CAPITAL LETTER M - 0x004E: 0xD5, # LATIN CAPITAL LETTER N - 0x004F: 0xD6, # LATIN CAPITAL LETTER O - 0x0050: 0xD7, # LATIN CAPITAL LETTER P - 0x0051: 0xD8, # LATIN CAPITAL LETTER Q - 0x0052: 0xD9, # LATIN CAPITAL LETTER R - 0x0053: 0xE2, # LATIN CAPITAL LETTER S - 0x0054: 0xE3, # LATIN CAPITAL LETTER T - 0x0055: 0xE4, # LATIN CAPITAL LETTER U - 0x0056: 0xE5, # LATIN CAPITAL LETTER V - 0x0057: 0xE6, # LATIN CAPITAL LETTER W - 0x0058: 0xE7, # LATIN CAPITAL LETTER X - 0x0059: 0xE8, # LATIN CAPITAL LETTER Y - 0x005A: 0xE9, # LATIN CAPITAL LETTER Z - 0x005B: 0x68, # LEFT SQUARE BRACKET - 0x005C: 0xDC, # REVERSE SOLIDUS - 0x005D: 0xAC, # RIGHT SQUARE BRACKET - 0x005E: 0x5F, # CIRCUMFLEX ACCENT - 0x005F: 0x6D, # LOW LINE - 0x0060: 0x8D, # GRAVE ACCENT - 0x0061: 0x81, # LATIN SMALL LETTER A - 0x0062: 0x82, # LATIN SMALL LETTER B - 0x0063: 0x83, # LATIN SMALL LETTER C - 0x0064: 0x84, # LATIN SMALL LETTER D - 0x0065: 0x85, # LATIN SMALL LETTER E - 0x0066: 0x86, # LATIN SMALL LETTER F - 0x0067: 0x87, # LATIN SMALL LETTER G - 0x0068: 0x88, # LATIN SMALL LETTER H - 0x0069: 0x89, # LATIN SMALL LETTER I - 0x006A: 0x91, # LATIN SMALL LETTER J - 0x006B: 0x92, # LATIN SMALL LETTER K - 0x006C: 0x93, # LATIN SMALL LETTER L - 0x006D: 0x94, # LATIN SMALL LETTER M - 0x006E: 0x95, # LATIN SMALL LETTER N - 0x006F: 0x96, # LATIN SMALL LETTER O - 0x0070: 0x97, # LATIN SMALL LETTER P - 0x0071: 0x98, # LATIN SMALL LETTER Q - 0x0072: 0x99, # LATIN SMALL LETTER R - 0x0073: 0xA2, # LATIN SMALL LETTER S - 0x0074: 0xA3, # LATIN SMALL LETTER T - 0x0075: 0xA4, # LATIN SMALL LETTER U - 0x0076: 0xA5, # LATIN SMALL LETTER V - 0x0077: 0xA6, # LATIN SMALL LETTER W - 0x0078: 0xA7, # LATIN SMALL LETTER X - 0x0079: 0xA8, # LATIN SMALL LETTER Y - 0x007A: 0xA9, # LATIN SMALL LETTER Z - 0x007B: 0x48, # LEFT CURLY BRACKET - 0x007C: 0xBB, # VERTICAL LINE - 0x007D: 0x8C, # RIGHT CURLY BRACKET - 0x007E: 0xCC, # TILDE - 0x007F: 0x07, # DELETE - 0x0080: 0x20, # CONTROL - 0x0081: 0x21, # CONTROL - 0x0082: 0x22, # CONTROL - 0x0083: 0x23, # CONTROL - 0x0084: 0x24, # CONTROL - 0x0085: 0x15, # CONTROL - 0x0086: 0x06, # CONTROL - 0x0087: 0x17, # CONTROL - 0x0088: 0x28, # CONTROL - 0x0089: 0x29, # CONTROL - 0x008A: 0x2A, # CONTROL - 0x008B: 0x2B, # CONTROL - 0x008C: 0x2C, # CONTROL - 0x008D: 0x09, # CONTROL - 0x008E: 0x0A, # CONTROL - 0x008F: 0x1B, # CONTROL - 0x0090: 0x30, # CONTROL - 0x0091: 0x31, # CONTROL - 0x0092: 0x1A, # CONTROL - 0x0093: 0x33, # CONTROL - 0x0094: 0x34, # CONTROL - 0x0095: 0x35, # CONTROL - 0x0096: 0x36, # CONTROL - 0x0097: 0x08, # CONTROL - 0x0098: 0x38, # CONTROL - 0x0099: 0x39, # CONTROL - 0x009A: 0x3A, # CONTROL - 0x009B: 0x3B, # CONTROL - 0x009C: 0x04, # CONTROL - 0x009D: 0x14, # CONTROL - 0x009E: 0x3E, # CONTROL - 0x009F: 0xFF, # CONTROL - 0x00A0: 0x41, # NO-BREAK SPACE - 0x00A1: 0xAA, # INVERTED EXCLAMATION MARK - 0x00A2: 0xB0, # CENT SIGN - 0x00A3: 0xB1, # POUND SIGN - 0x00A4: 0x9F, # CURRENCY SIGN - 0x00A5: 0xB2, # YEN SIGN - 0x00A6: 0x8E, # BROKEN BAR - 0x00A7: 0xB5, # SECTION SIGN - 0x00A8: 0xBD, # DIAERESIS - 0x00A9: 0xB4, # COPYRIGHT SIGN - 0x00AA: 0x9A, # FEMININE ORDINAL INDICATOR - 0x00AB: 0x8A, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xBA, # NOT SIGN - 0x00AD: 0xCA, # SOFT HYPHEN - 0x00AE: 0xAF, # REGISTERED SIGN - 0x00AF: 0xBC, # MACRON - 0x00B0: 0x90, # DEGREE SIGN - 0x00B1: 0x8F, # PLUS-MINUS SIGN - 0x00B2: 0xEA, # SUPERSCRIPT TWO - 0x00B3: 0xFA, # SUPERSCRIPT THREE - 0x00B4: 0xBE, # ACUTE ACCENT - 0x00B5: 0xA0, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB3, # MIDDLE DOT - 0x00B8: 0x9D, # CEDILLA - 0x00B9: 0xDA, # SUPERSCRIPT ONE - 0x00BA: 0x9B, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0x8B, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xB7, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xB8, # VULGAR FRACTION ONE HALF - 0x00BE: 0xB9, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xAB, # INVERTED QUESTION MARK - 0x00C0: 0x64, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0x65, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0x62, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0x66, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x63, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x67, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0x9E, # LATIN CAPITAL LIGATURE AE - 0x00C7: 0x4A, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0x74, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x71, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0x72, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0x73, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0x78, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0x75, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0x76, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0x77, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0x69, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xED, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEB, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xEF, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x7B, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xBF, # MULTIPLICATION SIGN - 0x00D8: 0x80, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xFD, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xFE, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xFB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0x7F, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0x59, # LATIN SMALL LETTER SHARP S (GERMAN) - 0x00E0: 0x44, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x45, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x42, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x46, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x43, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x47, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0x9C, # LATIN SMALL LIGATURE AE - 0x00E7: 0xC0, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x54, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x51, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x52, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x53, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x58, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x55, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x56, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x57, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0x49, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xCD, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xCE, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xCB, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xCF, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xA1, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xE1, # DIVISION SIGN - 0x00F8: 0x70, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xDD, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xDE, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xDB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xE0, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xDF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x011E: 0x5A, # LATIN CAPITAL LETTER G WITH BREVE - 0x011F: 0xD0, # LATIN SMALL LETTER G WITH BREVE - 0x0130: 0x5B, # LATIN CAPITAL LETTER I WITH DOT ABOVE - 0x0131: 0x79, # LATIN SMALL LETTER DOTLESS I - 0x015E: 0x7C, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0x6A, # LATIN SMALL LETTER S WITH CEDILLA -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1140.py b/Lib/encodings/cp1140.py index ac8d41b..7e507fd 100644 --- a/Lib/encodings/cp1140.py +++ b/Lib/encodings/cp1140.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\x9f' # 0xFF -> CONTROL ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x37, # END OF TRANSMISSION - 0x0005: 0x2D, # ENQUIRY - 0x0006: 0x2E, # ACKNOWLEDGE - 0x0007: 0x2F, # BELL - 0x0008: 0x16, # BACKSPACE - 0x0009: 0x05, # HORIZONTAL TABULATION - 0x000A: 0x25, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x3C, # DEVICE CONTROL FOUR - 0x0015: 0x3D, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x32, # SYNCHRONOUS IDLE - 0x0017: 0x26, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x3F, # SUBSTITUTE - 0x001B: 0x27, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x40, # SPACE - 0x0021: 0x5A, # EXCLAMATION MARK - 0x0022: 0x7F, # QUOTATION MARK - 0x0023: 0x7B, # NUMBER SIGN - 0x0024: 0x5B, # DOLLAR SIGN - 0x0025: 0x6C, # PERCENT SIGN - 0x0026: 0x50, # AMPERSAND - 0x0027: 0x7D, # APOSTROPHE - 0x0028: 0x4D, # LEFT PARENTHESIS - 0x0029: 0x5D, # RIGHT PARENTHESIS - 0x002A: 0x5C, # ASTERISK - 0x002B: 0x4E, # PLUS SIGN - 0x002C: 0x6B, # COMMA - 0x002D: 0x60, # HYPHEN-MINUS - 0x002E: 0x4B, # FULL STOP - 0x002F: 0x61, # SOLIDUS - 0x0030: 0xF0, # DIGIT ZERO - 0x0031: 0xF1, # DIGIT ONE - 0x0032: 0xF2, # DIGIT TWO - 0x0033: 0xF3, # DIGIT THREE - 0x0034: 0xF4, # DIGIT FOUR - 0x0035: 0xF5, # DIGIT FIVE - 0x0036: 0xF6, # DIGIT SIX - 0x0037: 0xF7, # DIGIT SEVEN - 0x0038: 0xF8, # DIGIT EIGHT - 0x0039: 0xF9, # DIGIT NINE - 0x003A: 0x7A, # COLON - 0x003B: 0x5E, # SEMICOLON - 0x003C: 0x4C, # LESS-THAN SIGN - 0x003D: 0x7E, # EQUALS SIGN - 0x003E: 0x6E, # GREATER-THAN SIGN - 0x003F: 0x6F, # QUESTION MARK - 0x0040: 0x7C, # COMMERCIAL AT - 0x0041: 0xC1, # LATIN CAPITAL LETTER A - 0x0042: 0xC2, # LATIN CAPITAL LETTER B - 0x0043: 0xC3, # LATIN CAPITAL LETTER C - 0x0044: 0xC4, # LATIN CAPITAL LETTER D - 0x0045: 0xC5, # LATIN CAPITAL LETTER E - 0x0046: 0xC6, # LATIN CAPITAL LETTER F - 0x0047: 0xC7, # LATIN CAPITAL LETTER G - 0x0048: 0xC8, # LATIN CAPITAL LETTER H - 0x0049: 0xC9, # LATIN CAPITAL LETTER I - 0x004A: 0xD1, # LATIN CAPITAL LETTER J - 0x004B: 0xD2, # LATIN CAPITAL LETTER K - 0x004C: 0xD3, # LATIN CAPITAL LETTER L - 0x004D: 0xD4, # LATIN CAPITAL LETTER M - 0x004E: 0xD5, # LATIN CAPITAL LETTER N - 0x004F: 0xD6, # LATIN CAPITAL LETTER O - 0x0050: 0xD7, # LATIN CAPITAL LETTER P - 0x0051: 0xD8, # LATIN CAPITAL LETTER Q - 0x0052: 0xD9, # LATIN CAPITAL LETTER R - 0x0053: 0xE2, # LATIN CAPITAL LETTER S - 0x0054: 0xE3, # LATIN CAPITAL LETTER T - 0x0055: 0xE4, # LATIN CAPITAL LETTER U - 0x0056: 0xE5, # LATIN CAPITAL LETTER V - 0x0057: 0xE6, # LATIN CAPITAL LETTER W - 0x0058: 0xE7, # LATIN CAPITAL LETTER X - 0x0059: 0xE8, # LATIN CAPITAL LETTER Y - 0x005A: 0xE9, # LATIN CAPITAL LETTER Z - 0x005B: 0xBA, # LEFT SQUARE BRACKET - 0x005C: 0xE0, # REVERSE SOLIDUS - 0x005D: 0xBB, # RIGHT SQUARE BRACKET - 0x005E: 0xB0, # CIRCUMFLEX ACCENT - 0x005F: 0x6D, # LOW LINE - 0x0060: 0x79, # GRAVE ACCENT - 0x0061: 0x81, # LATIN SMALL LETTER A - 0x0062: 0x82, # LATIN SMALL LETTER B - 0x0063: 0x83, # LATIN SMALL LETTER C - 0x0064: 0x84, # LATIN SMALL LETTER D - 0x0065: 0x85, # LATIN SMALL LETTER E - 0x0066: 0x86, # LATIN SMALL LETTER F - 0x0067: 0x87, # LATIN SMALL LETTER G - 0x0068: 0x88, # LATIN SMALL LETTER H - 0x0069: 0x89, # LATIN SMALL LETTER I - 0x006A: 0x91, # LATIN SMALL LETTER J - 0x006B: 0x92, # LATIN SMALL LETTER K - 0x006C: 0x93, # LATIN SMALL LETTER L - 0x006D: 0x94, # LATIN SMALL LETTER M - 0x006E: 0x95, # LATIN SMALL LETTER N - 0x006F: 0x96, # LATIN SMALL LETTER O - 0x0070: 0x97, # LATIN SMALL LETTER P - 0x0071: 0x98, # LATIN SMALL LETTER Q - 0x0072: 0x99, # LATIN SMALL LETTER R - 0x0073: 0xA2, # LATIN SMALL LETTER S - 0x0074: 0xA3, # LATIN SMALL LETTER T - 0x0075: 0xA4, # LATIN SMALL LETTER U - 0x0076: 0xA5, # LATIN SMALL LETTER V - 0x0077: 0xA6, # LATIN SMALL LETTER W - 0x0078: 0xA7, # LATIN SMALL LETTER X - 0x0079: 0xA8, # LATIN SMALL LETTER Y - 0x007A: 0xA9, # LATIN SMALL LETTER Z - 0x007B: 0xC0, # LEFT CURLY BRACKET - 0x007C: 0x4F, # VERTICAL LINE - 0x007D: 0xD0, # RIGHT CURLY BRACKET - 0x007E: 0xA1, # TILDE - 0x007F: 0x07, # DELETE - 0x0080: 0x20, # CONTROL - 0x0081: 0x21, # CONTROL - 0x0082: 0x22, # CONTROL - 0x0083: 0x23, # CONTROL - 0x0084: 0x24, # CONTROL - 0x0085: 0x15, # CONTROL - 0x0086: 0x06, # CONTROL - 0x0087: 0x17, # CONTROL - 0x0088: 0x28, # CONTROL - 0x0089: 0x29, # CONTROL - 0x008A: 0x2A, # CONTROL - 0x008B: 0x2B, # CONTROL - 0x008C: 0x2C, # CONTROL - 0x008D: 0x09, # CONTROL - 0x008E: 0x0A, # CONTROL - 0x008F: 0x1B, # CONTROL - 0x0090: 0x30, # CONTROL - 0x0091: 0x31, # CONTROL - 0x0092: 0x1A, # CONTROL - 0x0093: 0x33, # CONTROL - 0x0094: 0x34, # CONTROL - 0x0095: 0x35, # CONTROL - 0x0096: 0x36, # CONTROL - 0x0097: 0x08, # CONTROL - 0x0098: 0x38, # CONTROL - 0x0099: 0x39, # CONTROL - 0x009A: 0x3A, # CONTROL - 0x009B: 0x3B, # CONTROL - 0x009C: 0x04, # CONTROL - 0x009D: 0x14, # CONTROL - 0x009E: 0x3E, # CONTROL - 0x009F: 0xFF, # CONTROL - 0x00A0: 0x41, # NO-BREAK SPACE - 0x00A1: 0xAA, # INVERTED EXCLAMATION MARK - 0x00A2: 0x4A, # CENT SIGN - 0x00A3: 0xB1, # POUND SIGN - 0x00A5: 0xB2, # YEN SIGN - 0x00A6: 0x6A, # BROKEN BAR - 0x00A7: 0xB5, # SECTION SIGN - 0x00A8: 0xBD, # DIAERESIS - 0x00A9: 0xB4, # COPYRIGHT SIGN - 0x00AA: 0x9A, # FEMININE ORDINAL INDICATOR - 0x00AB: 0x8A, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0x5F, # NOT SIGN - 0x00AD: 0xCA, # SOFT HYPHEN - 0x00AE: 0xAF, # REGISTERED SIGN - 0x00AF: 0xBC, # MACRON - 0x00B0: 0x90, # DEGREE SIGN - 0x00B1: 0x8F, # PLUS-MINUS SIGN - 0x00B2: 0xEA, # SUPERSCRIPT TWO - 0x00B3: 0xFA, # SUPERSCRIPT THREE - 0x00B4: 0xBE, # ACUTE ACCENT - 0x00B5: 0xA0, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB3, # MIDDLE DOT - 0x00B8: 0x9D, # CEDILLA - 0x00B9: 0xDA, # SUPERSCRIPT ONE - 0x00BA: 0x9B, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0x8B, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xB7, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xB8, # VULGAR FRACTION ONE HALF - 0x00BE: 0xB9, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xAB, # INVERTED QUESTION MARK - 0x00C0: 0x64, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0x65, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0x62, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0x66, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x63, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x67, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0x9E, # LATIN CAPITAL LIGATURE AE - 0x00C7: 0x68, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0x74, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x71, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0x72, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0x73, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0x78, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0x75, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0x76, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0x77, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xAC, # LATIN CAPITAL LETTER ETH (ICELANDIC) - 0x00D1: 0x69, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xED, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEB, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xEF, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xEC, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xBF, # MULTIPLICATION SIGN - 0x00D8: 0x80, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xFD, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xFE, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xFB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xFC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xAD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xAE, # LATIN CAPITAL LETTER THORN (ICELANDIC) - 0x00DF: 0x59, # LATIN SMALL LETTER SHARP S (GERMAN) - 0x00E0: 0x44, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x45, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x42, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x46, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x43, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x47, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0x9C, # LATIN SMALL LIGATURE AE - 0x00E7: 0x48, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x54, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x51, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x52, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x53, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x58, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x55, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x56, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x57, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0x8C, # LATIN SMALL LETTER ETH (ICELANDIC) - 0x00F1: 0x49, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xCD, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xCE, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xCB, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xCF, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xCC, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xE1, # DIVISION SIGN - 0x00F8: 0x70, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xDD, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xDE, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xDB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xDC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0x8D, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0x8E, # LATIN SMALL LETTER THORN (ICELANDIC) - 0x00FF: 0xDF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x20AC: 0x9F, # EURO SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1250.py b/Lib/encodings/cp1250.py index 6e6f57c..d620b89 100644 --- a/Lib/encodings/cp1250.py +++ b/Lib/encodings/cp1250.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,258 +303,5 @@ decoding_table = ( u'\u02d9' # 0xFF -> DOT ABOVE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x0102: 0xC3, # LATIN CAPITAL LETTER A WITH BREVE - 0x0103: 0xE3, # LATIN SMALL LETTER A WITH BREVE - 0x0104: 0xA5, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xB9, # LATIN SMALL LETTER A WITH OGONEK - 0x0106: 0xC6, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0xE6, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x010E: 0xCF, # LATIN CAPITAL LETTER D WITH CARON - 0x010F: 0xEF, # LATIN SMALL LETTER D WITH CARON - 0x0110: 0xD0, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xF0, # LATIN SMALL LETTER D WITH STROKE - 0x0118: 0xCA, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xEA, # LATIN SMALL LETTER E WITH OGONEK - 0x011A: 0xCC, # LATIN CAPITAL LETTER E WITH CARON - 0x011B: 0xEC, # LATIN SMALL LETTER E WITH CARON - 0x0139: 0xC5, # LATIN CAPITAL LETTER L WITH ACUTE - 0x013A: 0xE5, # LATIN SMALL LETTER L WITH ACUTE - 0x013D: 0xBC, # LATIN CAPITAL LETTER L WITH CARON - 0x013E: 0xBE, # LATIN SMALL LETTER L WITH CARON - 0x0141: 0xA3, # LATIN CAPITAL LETTER L WITH STROKE - 0x0142: 0xB3, # LATIN SMALL LETTER L WITH STROKE - 0x0143: 0xD1, # LATIN CAPITAL LETTER N WITH ACUTE - 0x0144: 0xF1, # LATIN SMALL LETTER N WITH ACUTE - 0x0147: 0xD2, # LATIN CAPITAL LETTER N WITH CARON - 0x0148: 0xF2, # LATIN SMALL LETTER N WITH CARON - 0x0150: 0xD5, # LATIN CAPITAL LETTER O WITH DOUBLE ACUTE - 0x0151: 0xF5, # LATIN SMALL LETTER O WITH DOUBLE ACUTE - 0x0154: 0xC0, # LATIN CAPITAL LETTER R WITH ACUTE - 0x0155: 0xE0, # LATIN SMALL LETTER R WITH ACUTE - 0x0158: 0xD8, # LATIN CAPITAL LETTER R WITH CARON - 0x0159: 0xF8, # LATIN SMALL LETTER R WITH CARON - 0x015A: 0x8C, # LATIN CAPITAL LETTER S WITH ACUTE - 0x015B: 0x9C, # LATIN SMALL LETTER S WITH ACUTE - 0x015E: 0xAA, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0xBA, # LATIN SMALL LETTER S WITH CEDILLA - 0x0160: 0x8A, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0x9A, # LATIN SMALL LETTER S WITH CARON - 0x0162: 0xDE, # LATIN CAPITAL LETTER T WITH CEDILLA - 0x0163: 0xFE, # LATIN SMALL LETTER T WITH CEDILLA - 0x0164: 0x8D, # LATIN CAPITAL LETTER T WITH CARON - 0x0165: 0x9D, # LATIN SMALL LETTER T WITH CARON - 0x016E: 0xD9, # LATIN CAPITAL LETTER U WITH RING ABOVE - 0x016F: 0xF9, # LATIN SMALL LETTER U WITH RING ABOVE - 0x0170: 0xDB, # LATIN CAPITAL LETTER U WITH DOUBLE ACUTE - 0x0171: 0xFB, # LATIN SMALL LETTER U WITH DOUBLE ACUTE - 0x0179: 0x8F, # LATIN CAPITAL LETTER Z WITH ACUTE - 0x017A: 0x9F, # LATIN SMALL LETTER Z WITH ACUTE - 0x017B: 0xAF, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xBF, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x017D: 0x8E, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0x9E, # LATIN SMALL LETTER Z WITH CARON - 0x02C7: 0xA1, # CARON - 0x02D8: 0xA2, # BREVE - 0x02D9: 0xFF, # DOT ABOVE - 0x02DB: 0xB2, # OGONEK - 0x02DD: 0xBD, # DOUBLE ACUTE ACCENT - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1251.py b/Lib/encodings/cp1251.py index ed835fe..216771f 100644 --- a/Lib/encodings/cp1251.py +++ b/Lib/encodings/cp1251.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,262 +303,5 @@ decoding_table = ( u'\u044f' # 0xFF -> CYRILLIC SMALL LETTER YA ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x0401: 0xA8, # CYRILLIC CAPITAL LETTER IO - 0x0402: 0x80, # CYRILLIC CAPITAL LETTER DJE - 0x0403: 0x81, # CYRILLIC CAPITAL LETTER GJE - 0x0404: 0xAA, # CYRILLIC CAPITAL LETTER UKRAINIAN IE - 0x0405: 0xBD, # CYRILLIC CAPITAL LETTER DZE - 0x0406: 0xB2, # CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0407: 0xAF, # CYRILLIC CAPITAL LETTER YI - 0x0408: 0xA3, # CYRILLIC CAPITAL LETTER JE - 0x0409: 0x8A, # CYRILLIC CAPITAL LETTER LJE - 0x040A: 0x8C, # CYRILLIC CAPITAL LETTER NJE - 0x040B: 0x8E, # CYRILLIC CAPITAL LETTER TSHE - 0x040C: 0x8D, # CYRILLIC CAPITAL LETTER KJE - 0x040E: 0xA1, # CYRILLIC CAPITAL LETTER SHORT U - 0x040F: 0x8F, # CYRILLIC CAPITAL LETTER DZHE - 0x0410: 0xC0, # CYRILLIC CAPITAL LETTER A - 0x0411: 0xC1, # CYRILLIC CAPITAL LETTER BE - 0x0412: 0xC2, # CYRILLIC CAPITAL LETTER VE - 0x0413: 0xC3, # CYRILLIC CAPITAL LETTER GHE - 0x0414: 0xC4, # CYRILLIC CAPITAL LETTER DE - 0x0415: 0xC5, # CYRILLIC CAPITAL LETTER IE - 0x0416: 0xC6, # CYRILLIC CAPITAL LETTER ZHE - 0x0417: 0xC7, # CYRILLIC CAPITAL LETTER ZE - 0x0418: 0xC8, # CYRILLIC CAPITAL LETTER I - 0x0419: 0xC9, # CYRILLIC CAPITAL LETTER SHORT I - 0x041A: 0xCA, # CYRILLIC CAPITAL LETTER KA - 0x041B: 0xCB, # CYRILLIC CAPITAL LETTER EL - 0x041C: 0xCC, # CYRILLIC CAPITAL LETTER EM - 0x041D: 0xCD, # CYRILLIC CAPITAL LETTER EN - 0x041E: 0xCE, # CYRILLIC CAPITAL LETTER O - 0x041F: 0xCF, # CYRILLIC CAPITAL LETTER PE - 0x0420: 0xD0, # CYRILLIC CAPITAL LETTER ER - 0x0421: 0xD1, # CYRILLIC CAPITAL LETTER ES - 0x0422: 0xD2, # CYRILLIC CAPITAL LETTER TE - 0x0423: 0xD3, # CYRILLIC CAPITAL LETTER U - 0x0424: 0xD4, # CYRILLIC CAPITAL LETTER EF - 0x0425: 0xD5, # CYRILLIC CAPITAL LETTER HA - 0x0426: 0xD6, # CYRILLIC CAPITAL LETTER TSE - 0x0427: 0xD7, # CYRILLIC CAPITAL LETTER CHE - 0x0428: 0xD8, # CYRILLIC CAPITAL LETTER SHA - 0x0429: 0xD9, # CYRILLIC CAPITAL LETTER SHCHA - 0x042A: 0xDA, # CYRILLIC CAPITAL LETTER HARD SIGN - 0x042B: 0xDB, # CYRILLIC CAPITAL LETTER YERU - 0x042C: 0xDC, # CYRILLIC CAPITAL LETTER SOFT SIGN - 0x042D: 0xDD, # CYRILLIC CAPITAL LETTER E - 0x042E: 0xDE, # CYRILLIC CAPITAL LETTER YU - 0x042F: 0xDF, # CYRILLIC CAPITAL LETTER YA - 0x0430: 0xE0, # CYRILLIC SMALL LETTER A - 0x0431: 0xE1, # CYRILLIC SMALL LETTER BE - 0x0432: 0xE2, # CYRILLIC SMALL LETTER VE - 0x0433: 0xE3, # CYRILLIC SMALL LETTER GHE - 0x0434: 0xE4, # CYRILLIC SMALL LETTER DE - 0x0435: 0xE5, # CYRILLIC SMALL LETTER IE - 0x0436: 0xE6, # CYRILLIC SMALL LETTER ZHE - 0x0437: 0xE7, # CYRILLIC SMALL LETTER ZE - 0x0438: 0xE8, # CYRILLIC SMALL LETTER I - 0x0439: 0xE9, # CYRILLIC SMALL LETTER SHORT I - 0x043A: 0xEA, # CYRILLIC SMALL LETTER KA - 0x043B: 0xEB, # CYRILLIC SMALL LETTER EL - 0x043C: 0xEC, # CYRILLIC SMALL LETTER EM - 0x043D: 0xED, # CYRILLIC SMALL LETTER EN - 0x043E: 0xEE, # CYRILLIC SMALL LETTER O - 0x043F: 0xEF, # CYRILLIC SMALL LETTER PE - 0x0440: 0xF0, # CYRILLIC SMALL LETTER ER - 0x0441: 0xF1, # CYRILLIC SMALL LETTER ES - 0x0442: 0xF2, # CYRILLIC SMALL LETTER TE - 0x0443: 0xF3, # CYRILLIC SMALL LETTER U - 0x0444: 0xF4, # CYRILLIC SMALL LETTER EF - 0x0445: 0xF5, # CYRILLIC SMALL LETTER HA - 0x0446: 0xF6, # CYRILLIC SMALL LETTER TSE - 0x0447: 0xF7, # CYRILLIC SMALL LETTER CHE - 0x0448: 0xF8, # CYRILLIC SMALL LETTER SHA - 0x0449: 0xF9, # CYRILLIC SMALL LETTER SHCHA - 0x044A: 0xFA, # CYRILLIC SMALL LETTER HARD SIGN - 0x044B: 0xFB, # CYRILLIC SMALL LETTER YERU - 0x044C: 0xFC, # CYRILLIC SMALL LETTER SOFT SIGN - 0x044D: 0xFD, # CYRILLIC SMALL LETTER E - 0x044E: 0xFE, # CYRILLIC SMALL LETTER YU - 0x044F: 0xFF, # CYRILLIC SMALL LETTER YA - 0x0451: 0xB8, # CYRILLIC SMALL LETTER IO - 0x0452: 0x90, # CYRILLIC SMALL LETTER DJE - 0x0453: 0x83, # CYRILLIC SMALL LETTER GJE - 0x0454: 0xBA, # CYRILLIC SMALL LETTER UKRAINIAN IE - 0x0455: 0xBE, # CYRILLIC SMALL LETTER DZE - 0x0456: 0xB3, # CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0457: 0xBF, # CYRILLIC SMALL LETTER YI - 0x0458: 0xBC, # CYRILLIC SMALL LETTER JE - 0x0459: 0x9A, # CYRILLIC SMALL LETTER LJE - 0x045A: 0x9C, # CYRILLIC SMALL LETTER NJE - 0x045B: 0x9E, # CYRILLIC SMALL LETTER TSHE - 0x045C: 0x9D, # CYRILLIC SMALL LETTER KJE - 0x045E: 0xA2, # CYRILLIC SMALL LETTER SHORT U - 0x045F: 0x9F, # CYRILLIC SMALL LETTER DZHE - 0x0490: 0xA5, # CYRILLIC CAPITAL LETTER GHE WITH UPTURN - 0x0491: 0xB4, # CYRILLIC SMALL LETTER GHE WITH UPTURN - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x88, # EURO SIGN - 0x2116: 0xB9, # NUMERO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1252.py b/Lib/encodings/cp1252.py index e5b6905..e60a328 100644 --- a/Lib/encodings/cp1252.py +++ b/Lib/encodings/cp1252.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,258 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xAA, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BA: 0xBA, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xD0, # LATIN CAPITAL LETTER ETH - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xDE, # LATIN CAPITAL LETTER THORN - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0xF0, # LATIN SMALL LETTER ETH - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0xFE, # LATIN SMALL LETTER THORN - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0152: 0x8C, # LATIN CAPITAL LIGATURE OE - 0x0153: 0x9C, # LATIN SMALL LIGATURE OE - 0x0160: 0x8A, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0x9A, # LATIN SMALL LETTER S WITH CARON - 0x0178: 0x9F, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x017D: 0x8E, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0x9E, # LATIN SMALL LETTER Z WITH CARON - 0x0192: 0x83, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0x88, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02DC: 0x98, # SMALL TILDE - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1253.py b/Lib/encodings/cp1253.py index 3ce70b25..49f6ccc 100644 --- a/Lib/encodings/cp1253.py +++ b/Lib/encodings/cp1253.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,246 +303,5 @@ decoding_table = ( u'\ufffe' # 0xFF -> UNDEFINED ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x0192: 0x83, # LATIN SMALL LETTER F WITH HOOK - 0x0384: 0xB4, # GREEK TONOS - 0x0385: 0xA1, # GREEK DIALYTIKA TONOS - 0x0386: 0xA2, # GREEK CAPITAL LETTER ALPHA WITH TONOS - 0x0388: 0xB8, # GREEK CAPITAL LETTER EPSILON WITH TONOS - 0x0389: 0xB9, # GREEK CAPITAL LETTER ETA WITH TONOS - 0x038A: 0xBA, # GREEK CAPITAL LETTER IOTA WITH TONOS - 0x038C: 0xBC, # GREEK CAPITAL LETTER OMICRON WITH TONOS - 0x038E: 0xBE, # GREEK CAPITAL LETTER UPSILON WITH TONOS - 0x038F: 0xBF, # GREEK CAPITAL LETTER OMEGA WITH TONOS - 0x0390: 0xC0, # GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS - 0x0391: 0xC1, # GREEK CAPITAL LETTER ALPHA - 0x0392: 0xC2, # GREEK CAPITAL LETTER BETA - 0x0393: 0xC3, # GREEK CAPITAL LETTER GAMMA - 0x0394: 0xC4, # GREEK CAPITAL LETTER DELTA - 0x0395: 0xC5, # GREEK CAPITAL LETTER EPSILON - 0x0396: 0xC6, # GREEK CAPITAL LETTER ZETA - 0x0397: 0xC7, # GREEK CAPITAL LETTER ETA - 0x0398: 0xC8, # GREEK CAPITAL LETTER THETA - 0x0399: 0xC9, # GREEK CAPITAL LETTER IOTA - 0x039A: 0xCA, # GREEK CAPITAL LETTER KAPPA - 0x039B: 0xCB, # GREEK CAPITAL LETTER LAMDA - 0x039C: 0xCC, # GREEK CAPITAL LETTER MU - 0x039D: 0xCD, # GREEK CAPITAL LETTER NU - 0x039E: 0xCE, # GREEK CAPITAL LETTER XI - 0x039F: 0xCF, # GREEK CAPITAL LETTER OMICRON - 0x03A0: 0xD0, # GREEK CAPITAL LETTER PI - 0x03A1: 0xD1, # GREEK CAPITAL LETTER RHO - 0x03A3: 0xD3, # GREEK CAPITAL LETTER SIGMA - 0x03A4: 0xD4, # GREEK CAPITAL LETTER TAU - 0x03A5: 0xD5, # GREEK CAPITAL LETTER UPSILON - 0x03A6: 0xD6, # GREEK CAPITAL LETTER PHI - 0x03A7: 0xD7, # GREEK CAPITAL LETTER CHI - 0x03A8: 0xD8, # GREEK CAPITAL LETTER PSI - 0x03A9: 0xD9, # GREEK CAPITAL LETTER OMEGA - 0x03AA: 0xDA, # GREEK CAPITAL LETTER IOTA WITH DIALYTIKA - 0x03AB: 0xDB, # GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA - 0x03AC: 0xDC, # GREEK SMALL LETTER ALPHA WITH TONOS - 0x03AD: 0xDD, # GREEK SMALL LETTER EPSILON WITH TONOS - 0x03AE: 0xDE, # GREEK SMALL LETTER ETA WITH TONOS - 0x03AF: 0xDF, # GREEK SMALL LETTER IOTA WITH TONOS - 0x03B0: 0xE0, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS - 0x03B1: 0xE1, # GREEK SMALL LETTER ALPHA - 0x03B2: 0xE2, # GREEK SMALL LETTER BETA - 0x03B3: 0xE3, # GREEK SMALL LETTER GAMMA - 0x03B4: 0xE4, # GREEK SMALL LETTER DELTA - 0x03B5: 0xE5, # GREEK SMALL LETTER EPSILON - 0x03B6: 0xE6, # GREEK SMALL LETTER ZETA - 0x03B7: 0xE7, # GREEK SMALL LETTER ETA - 0x03B8: 0xE8, # GREEK SMALL LETTER THETA - 0x03B9: 0xE9, # GREEK SMALL LETTER IOTA - 0x03BA: 0xEA, # GREEK SMALL LETTER KAPPA - 0x03BB: 0xEB, # GREEK SMALL LETTER LAMDA - 0x03BC: 0xEC, # GREEK SMALL LETTER MU - 0x03BD: 0xED, # GREEK SMALL LETTER NU - 0x03BE: 0xEE, # GREEK SMALL LETTER XI - 0x03BF: 0xEF, # GREEK SMALL LETTER OMICRON - 0x03C0: 0xF0, # GREEK SMALL LETTER PI - 0x03C1: 0xF1, # GREEK SMALL LETTER RHO - 0x03C2: 0xF2, # GREEK SMALL LETTER FINAL SIGMA - 0x03C3: 0xF3, # GREEK SMALL LETTER SIGMA - 0x03C4: 0xF4, # GREEK SMALL LETTER TAU - 0x03C5: 0xF5, # GREEK SMALL LETTER UPSILON - 0x03C6: 0xF6, # GREEK SMALL LETTER PHI - 0x03C7: 0xF7, # GREEK SMALL LETTER CHI - 0x03C8: 0xF8, # GREEK SMALL LETTER PSI - 0x03C9: 0xF9, # GREEK SMALL LETTER OMEGA - 0x03CA: 0xFA, # GREEK SMALL LETTER IOTA WITH DIALYTIKA - 0x03CB: 0xFB, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA - 0x03CC: 0xFC, # GREEK SMALL LETTER OMICRON WITH TONOS - 0x03CD: 0xFD, # GREEK SMALL LETTER UPSILON WITH TONOS - 0x03CE: 0xFE, # GREEK SMALL LETTER OMEGA WITH TONOS - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2015: 0xAF, # HORIZONTAL BAR - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1254.py b/Lib/encodings/cp1254.py index 31cd48c..65530ab 100644 --- a/Lib/encodings/cp1254.py +++ b/Lib/encodings/cp1254.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,256 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xAA, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BA: 0xBA, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x011E: 0xD0, # LATIN CAPITAL LETTER G WITH BREVE - 0x011F: 0xF0, # LATIN SMALL LETTER G WITH BREVE - 0x0130: 0xDD, # LATIN CAPITAL LETTER I WITH DOT ABOVE - 0x0131: 0xFD, # LATIN SMALL LETTER DOTLESS I - 0x0152: 0x8C, # LATIN CAPITAL LIGATURE OE - 0x0153: 0x9C, # LATIN SMALL LIGATURE OE - 0x015E: 0xDE, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0xFE, # LATIN SMALL LETTER S WITH CEDILLA - 0x0160: 0x8A, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0x9A, # LATIN SMALL LETTER S WITH CARON - 0x0178: 0x9F, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0192: 0x83, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0x88, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02DC: 0x98, # SMALL TILDE - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1255.py b/Lib/encodings/cp1255.py index 47c43ce..fd1456fa 100644 --- a/Lib/encodings/cp1255.py +++ b/Lib/encodings/cp1255.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,240 +303,5 @@ decoding_table = ( u'\ufffe' # 0xFF -> UNDEFINED ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00D7: 0xAA, # MULTIPLICATION SIGN - 0x00F7: 0xBA, # DIVISION SIGN - 0x0192: 0x83, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0x88, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02DC: 0x98, # SMALL TILDE - 0x05B0: 0xC0, # HEBREW POINT SHEVA - 0x05B1: 0xC1, # HEBREW POINT HATAF SEGOL - 0x05B2: 0xC2, # HEBREW POINT HATAF PATAH - 0x05B3: 0xC3, # HEBREW POINT HATAF QAMATS - 0x05B4: 0xC4, # HEBREW POINT HIRIQ - 0x05B5: 0xC5, # HEBREW POINT TSERE - 0x05B6: 0xC6, # HEBREW POINT SEGOL - 0x05B7: 0xC7, # HEBREW POINT PATAH - 0x05B8: 0xC8, # HEBREW POINT QAMATS - 0x05B9: 0xC9, # HEBREW POINT HOLAM - 0x05BB: 0xCB, # HEBREW POINT QUBUTS - 0x05BC: 0xCC, # HEBREW POINT DAGESH OR MAPIQ - 0x05BD: 0xCD, # HEBREW POINT METEG - 0x05BE: 0xCE, # HEBREW PUNCTUATION MAQAF - 0x05BF: 0xCF, # HEBREW POINT RAFE - 0x05C0: 0xD0, # HEBREW PUNCTUATION PASEQ - 0x05C1: 0xD1, # HEBREW POINT SHIN DOT - 0x05C2: 0xD2, # HEBREW POINT SIN DOT - 0x05C3: 0xD3, # HEBREW PUNCTUATION SOF PASUQ - 0x05D0: 0xE0, # HEBREW LETTER ALEF - 0x05D1: 0xE1, # HEBREW LETTER BET - 0x05D2: 0xE2, # HEBREW LETTER GIMEL - 0x05D3: 0xE3, # HEBREW LETTER DALET - 0x05D4: 0xE4, # HEBREW LETTER HE - 0x05D5: 0xE5, # HEBREW LETTER VAV - 0x05D6: 0xE6, # HEBREW LETTER ZAYIN - 0x05D7: 0xE7, # HEBREW LETTER HET - 0x05D8: 0xE8, # HEBREW LETTER TET - 0x05D9: 0xE9, # HEBREW LETTER YOD - 0x05DA: 0xEA, # HEBREW LETTER FINAL KAF - 0x05DB: 0xEB, # HEBREW LETTER KAF - 0x05DC: 0xEC, # HEBREW LETTER LAMED - 0x05DD: 0xED, # HEBREW LETTER FINAL MEM - 0x05DE: 0xEE, # HEBREW LETTER MEM - 0x05DF: 0xEF, # HEBREW LETTER FINAL NUN - 0x05E0: 0xF0, # HEBREW LETTER NUN - 0x05E1: 0xF1, # HEBREW LETTER SAMEKH - 0x05E2: 0xF2, # HEBREW LETTER AYIN - 0x05E3: 0xF3, # HEBREW LETTER FINAL PE - 0x05E4: 0xF4, # HEBREW LETTER PE - 0x05E5: 0xF5, # HEBREW LETTER FINAL TSADI - 0x05E6: 0xF6, # HEBREW LETTER TSADI - 0x05E7: 0xF7, # HEBREW LETTER QOF - 0x05E8: 0xF8, # HEBREW LETTER RESH - 0x05E9: 0xF9, # HEBREW LETTER SHIN - 0x05EA: 0xFA, # HEBREW LETTER TAV - 0x05F0: 0xD4, # HEBREW LIGATURE YIDDISH DOUBLE VAV - 0x05F1: 0xD5, # HEBREW LIGATURE YIDDISH VAV YOD - 0x05F2: 0xD6, # HEBREW LIGATURE YIDDISH DOUBLE YOD - 0x05F3: 0xD7, # HEBREW PUNCTUATION GERESH - 0x05F4: 0xD8, # HEBREW PUNCTUATION GERSHAYIM - 0x200E: 0xFD, # LEFT-TO-RIGHT MARK - 0x200F: 0xFE, # RIGHT-TO-LEFT MARK - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AA: 0xA4, # NEW SHEQEL SIGN - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1256.py b/Lib/encodings/cp1256.py index e90393b..302b5fa 100644 --- a/Lib/encodings/cp1256.py +++ b/Lib/encodings/cp1256.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u06d2' # 0xFF -> ARABIC LETTER YEH BARREE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0152: 0x8C, # LATIN CAPITAL LIGATURE OE - 0x0153: 0x9C, # LATIN SMALL LIGATURE OE - 0x0192: 0x83, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0x88, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x060C: 0xA1, # ARABIC COMMA - 0x061B: 0xBA, # ARABIC SEMICOLON - 0x061F: 0xBF, # ARABIC QUESTION MARK - 0x0621: 0xC1, # ARABIC LETTER HAMZA - 0x0622: 0xC2, # ARABIC LETTER ALEF WITH MADDA ABOVE - 0x0623: 0xC3, # ARABIC LETTER ALEF WITH HAMZA ABOVE - 0x0624: 0xC4, # ARABIC LETTER WAW WITH HAMZA ABOVE - 0x0625: 0xC5, # ARABIC LETTER ALEF WITH HAMZA BELOW - 0x0626: 0xC6, # ARABIC LETTER YEH WITH HAMZA ABOVE - 0x0627: 0xC7, # ARABIC LETTER ALEF - 0x0628: 0xC8, # ARABIC LETTER BEH - 0x0629: 0xC9, # ARABIC LETTER TEH MARBUTA - 0x062A: 0xCA, # ARABIC LETTER TEH - 0x062B: 0xCB, # ARABIC LETTER THEH - 0x062C: 0xCC, # ARABIC LETTER JEEM - 0x062D: 0xCD, # ARABIC LETTER HAH - 0x062E: 0xCE, # ARABIC LETTER KHAH - 0x062F: 0xCF, # ARABIC LETTER DAL - 0x0630: 0xD0, # ARABIC LETTER THAL - 0x0631: 0xD1, # ARABIC LETTER REH - 0x0632: 0xD2, # ARABIC LETTER ZAIN - 0x0633: 0xD3, # ARABIC LETTER SEEN - 0x0634: 0xD4, # ARABIC LETTER SHEEN - 0x0635: 0xD5, # ARABIC LETTER SAD - 0x0636: 0xD6, # ARABIC LETTER DAD - 0x0637: 0xD8, # ARABIC LETTER TAH - 0x0638: 0xD9, # ARABIC LETTER ZAH - 0x0639: 0xDA, # ARABIC LETTER AIN - 0x063A: 0xDB, # ARABIC LETTER GHAIN - 0x0640: 0xDC, # ARABIC TATWEEL - 0x0641: 0xDD, # ARABIC LETTER FEH - 0x0642: 0xDE, # ARABIC LETTER QAF - 0x0643: 0xDF, # ARABIC LETTER KAF - 0x0644: 0xE1, # ARABIC LETTER LAM - 0x0645: 0xE3, # ARABIC LETTER MEEM - 0x0646: 0xE4, # ARABIC LETTER NOON - 0x0647: 0xE5, # ARABIC LETTER HEH - 0x0648: 0xE6, # ARABIC LETTER WAW - 0x0649: 0xEC, # ARABIC LETTER ALEF MAKSURA - 0x064A: 0xED, # ARABIC LETTER YEH - 0x064B: 0xF0, # ARABIC FATHATAN - 0x064C: 0xF1, # ARABIC DAMMATAN - 0x064D: 0xF2, # ARABIC KASRATAN - 0x064E: 0xF3, # ARABIC FATHA - 0x064F: 0xF5, # ARABIC DAMMA - 0x0650: 0xF6, # ARABIC KASRA - 0x0651: 0xF8, # ARABIC SHADDA - 0x0652: 0xFA, # ARABIC SUKUN - 0x0679: 0x8A, # ARABIC LETTER TTEH - 0x067E: 0x81, # ARABIC LETTER PEH - 0x0686: 0x8D, # ARABIC LETTER TCHEH - 0x0688: 0x8F, # ARABIC LETTER DDAL - 0x0691: 0x9A, # ARABIC LETTER RREH - 0x0698: 0x8E, # ARABIC LETTER JEH - 0x06A9: 0x98, # ARABIC LETTER KEHEH - 0x06AF: 0x90, # ARABIC LETTER GAF - 0x06BA: 0x9F, # ARABIC LETTER NOON GHUNNA - 0x06BE: 0xAA, # ARABIC LETTER HEH DOACHASHMEE - 0x06C1: 0xC0, # ARABIC LETTER HEH GOAL - 0x06D2: 0xFF, # ARABIC LETTER YEH BARREE - 0x200C: 0x9D, # ZERO WIDTH NON-JOINER - 0x200D: 0x9E, # ZERO WIDTH JOINER - 0x200E: 0xFD, # LEFT-TO-RIGHT MARK - 0x200F: 0xFE, # RIGHT-TO-LEFT MARK - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1257.py b/Lib/encodings/cp1257.py index dcc81c0..53a6b29 100644 --- a/Lib/encodings/cp1257.py +++ b/Lib/encodings/cp1257.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,251 +303,5 @@ decoding_table = ( u'\u02d9' # 0xFF -> DOT ABOVE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0x8D, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0x9D, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0x8F, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xAF, # LATIN CAPITAL LETTER AE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xA8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xBF, # LATIN SMALL LETTER AE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xB8, # LATIN SMALL LETTER O WITH STROKE - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0100: 0xC2, # LATIN CAPITAL LETTER A WITH MACRON - 0x0101: 0xE2, # LATIN SMALL LETTER A WITH MACRON - 0x0104: 0xC0, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xE0, # LATIN SMALL LETTER A WITH OGONEK - 0x0106: 0xC3, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0xE3, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x0112: 0xC7, # LATIN CAPITAL LETTER E WITH MACRON - 0x0113: 0xE7, # LATIN SMALL LETTER E WITH MACRON - 0x0116: 0xCB, # LATIN CAPITAL LETTER E WITH DOT ABOVE - 0x0117: 0xEB, # LATIN SMALL LETTER E WITH DOT ABOVE - 0x0118: 0xC6, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xE6, # LATIN SMALL LETTER E WITH OGONEK - 0x0122: 0xCC, # LATIN CAPITAL LETTER G WITH CEDILLA - 0x0123: 0xEC, # LATIN SMALL LETTER G WITH CEDILLA - 0x012A: 0xCE, # LATIN CAPITAL LETTER I WITH MACRON - 0x012B: 0xEE, # LATIN SMALL LETTER I WITH MACRON - 0x012E: 0xC1, # LATIN CAPITAL LETTER I WITH OGONEK - 0x012F: 0xE1, # LATIN SMALL LETTER I WITH OGONEK - 0x0136: 0xCD, # LATIN CAPITAL LETTER K WITH CEDILLA - 0x0137: 0xED, # LATIN SMALL LETTER K WITH CEDILLA - 0x013B: 0xCF, # LATIN CAPITAL LETTER L WITH CEDILLA - 0x013C: 0xEF, # LATIN SMALL LETTER L WITH CEDILLA - 0x0141: 0xD9, # LATIN CAPITAL LETTER L WITH STROKE - 0x0142: 0xF9, # LATIN SMALL LETTER L WITH STROKE - 0x0143: 0xD1, # LATIN CAPITAL LETTER N WITH ACUTE - 0x0144: 0xF1, # LATIN SMALL LETTER N WITH ACUTE - 0x0145: 0xD2, # LATIN CAPITAL LETTER N WITH CEDILLA - 0x0146: 0xF2, # LATIN SMALL LETTER N WITH CEDILLA - 0x014C: 0xD4, # LATIN CAPITAL LETTER O WITH MACRON - 0x014D: 0xF4, # LATIN SMALL LETTER O WITH MACRON - 0x0156: 0xAA, # LATIN CAPITAL LETTER R WITH CEDILLA - 0x0157: 0xBA, # LATIN SMALL LETTER R WITH CEDILLA - 0x015A: 0xDA, # LATIN CAPITAL LETTER S WITH ACUTE - 0x015B: 0xFA, # LATIN SMALL LETTER S WITH ACUTE - 0x0160: 0xD0, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xF0, # LATIN SMALL LETTER S WITH CARON - 0x016A: 0xDB, # LATIN CAPITAL LETTER U WITH MACRON - 0x016B: 0xFB, # LATIN SMALL LETTER U WITH MACRON - 0x0172: 0xD8, # LATIN CAPITAL LETTER U WITH OGONEK - 0x0173: 0xF8, # LATIN SMALL LETTER U WITH OGONEK - 0x0179: 0xCA, # LATIN CAPITAL LETTER Z WITH ACUTE - 0x017A: 0xEA, # LATIN SMALL LETTER Z WITH ACUTE - 0x017B: 0xDD, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xFD, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x017D: 0xDE, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xFE, # LATIN SMALL LETTER Z WITH CARON - 0x02C7: 0x8E, # CARON - 0x02D9: 0xFF, # DOT ABOVE - 0x02DB: 0x9E, # OGONEK - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp1258.py b/Lib/encodings/cp1258.py index d4d2271..4b25d8e 100644 --- a/Lib/encodings/cp1258.py +++ b/Lib/encodings/cp1258.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,254 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xAA, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BA: 0xBA, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0102: 0xC3, # LATIN CAPITAL LETTER A WITH BREVE - 0x0103: 0xE3, # LATIN SMALL LETTER A WITH BREVE - 0x0110: 0xD0, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xF0, # LATIN SMALL LETTER D WITH STROKE - 0x0152: 0x8C, # LATIN CAPITAL LIGATURE OE - 0x0153: 0x9C, # LATIN SMALL LIGATURE OE - 0x0178: 0x9F, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0192: 0x83, # LATIN SMALL LETTER F WITH HOOK - 0x01A0: 0xD5, # LATIN CAPITAL LETTER O WITH HORN - 0x01A1: 0xF5, # LATIN SMALL LETTER O WITH HORN - 0x01AF: 0xDD, # LATIN CAPITAL LETTER U WITH HORN - 0x01B0: 0xFD, # LATIN SMALL LETTER U WITH HORN - 0x02C6: 0x88, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02DC: 0x98, # SMALL TILDE - 0x0300: 0xCC, # COMBINING GRAVE ACCENT - 0x0301: 0xEC, # COMBINING ACUTE ACCENT - 0x0303: 0xDE, # COMBINING TILDE - 0x0309: 0xD2, # COMBINING HOOK ABOVE - 0x0323: 0xF2, # COMBINING DOT BELOW - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0x82, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0x84, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0x86, # DAGGER - 0x2021: 0x87, # DOUBLE DAGGER - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x2030: 0x89, # PER MILLE SIGN - 0x2039: 0x8B, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0x9B, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x20AB: 0xFE, # DONG SIGN - 0x20AC: 0x80, # EURO SIGN - 0x2122: 0x99, # TRADE MARK SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp424.py b/Lib/encodings/cp424.py index 966aecb..d3ade22 100644 --- a/Lib/encodings/cp424.py +++ b/Lib/encodings/cp424.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,225 +303,5 @@ decoding_table = ( u'\x9f' # 0xFF -> EIGHT ONES ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x37, # END OF TRANSMISSION - 0x0005: 0x2D, # ENQUIRY - 0x0006: 0x2E, # ACKNOWLEDGE - 0x0007: 0x2F, # BELL - 0x0008: 0x16, # BACKSPACE - 0x0009: 0x05, # HORIZONTAL TABULATION - 0x000A: 0x25, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x3C, # DEVICE CONTROL FOUR - 0x0015: 0x3D, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x32, # SYNCHRONOUS IDLE - 0x0017: 0x26, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x3F, # SUBSTITUTE - 0x001B: 0x27, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x40, # SPACE - 0x0021: 0x5A, # EXCLAMATION MARK - 0x0022: 0x7F, # QUOTATION MARK - 0x0023: 0x7B, # NUMBER SIGN - 0x0024: 0x5B, # DOLLAR SIGN - 0x0025: 0x6C, # PERCENT SIGN - 0x0026: 0x50, # AMPERSAND - 0x0027: 0x7D, # APOSTROPHE - 0x0028: 0x4D, # LEFT PARENTHESIS - 0x0029: 0x5D, # RIGHT PARENTHESIS - 0x002A: 0x5C, # ASTERISK - 0x002B: 0x4E, # PLUS SIGN - 0x002C: 0x6B, # COMMA - 0x002D: 0x60, # HYPHEN-MINUS - 0x002E: 0x4B, # FULL STOP - 0x002F: 0x61, # SOLIDUS - 0x0030: 0xF0, # DIGIT ZERO - 0x0031: 0xF1, # DIGIT ONE - 0x0032: 0xF2, # DIGIT TWO - 0x0033: 0xF3, # DIGIT THREE - 0x0034: 0xF4, # DIGIT FOUR - 0x0035: 0xF5, # DIGIT FIVE - 0x0036: 0xF6, # DIGIT SIX - 0x0037: 0xF7, # DIGIT SEVEN - 0x0038: 0xF8, # DIGIT EIGHT - 0x0039: 0xF9, # DIGIT NINE - 0x003A: 0x7A, # COLON - 0x003B: 0x5E, # SEMICOLON - 0x003C: 0x4C, # LESS-THAN SIGN - 0x003D: 0x7E, # EQUALS SIGN - 0x003E: 0x6E, # GREATER-THAN SIGN - 0x003F: 0x6F, # QUESTION MARK - 0x0040: 0x7C, # COMMERCIAL AT - 0x0041: 0xC1, # LATIN CAPITAL LETTER A - 0x0042: 0xC2, # LATIN CAPITAL LETTER B - 0x0043: 0xC3, # LATIN CAPITAL LETTER C - 0x0044: 0xC4, # LATIN CAPITAL LETTER D - 0x0045: 0xC5, # LATIN CAPITAL LETTER E - 0x0046: 0xC6, # LATIN CAPITAL LETTER F - 0x0047: 0xC7, # LATIN CAPITAL LETTER G - 0x0048: 0xC8, # LATIN CAPITAL LETTER H - 0x0049: 0xC9, # LATIN CAPITAL LETTER I - 0x004A: 0xD1, # LATIN CAPITAL LETTER J - 0x004B: 0xD2, # LATIN CAPITAL LETTER K - 0x004C: 0xD3, # LATIN CAPITAL LETTER L - 0x004D: 0xD4, # LATIN CAPITAL LETTER M - 0x004E: 0xD5, # LATIN CAPITAL LETTER N - 0x004F: 0xD6, # LATIN CAPITAL LETTER O - 0x0050: 0xD7, # LATIN CAPITAL LETTER P - 0x0051: 0xD8, # LATIN CAPITAL LETTER Q - 0x0052: 0xD9, # LATIN CAPITAL LETTER R - 0x0053: 0xE2, # LATIN CAPITAL LETTER S - 0x0054: 0xE3, # LATIN CAPITAL LETTER T - 0x0055: 0xE4, # LATIN CAPITAL LETTER U - 0x0056: 0xE5, # LATIN CAPITAL LETTER V - 0x0057: 0xE6, # LATIN CAPITAL LETTER W - 0x0058: 0xE7, # LATIN CAPITAL LETTER X - 0x0059: 0xE8, # LATIN CAPITAL LETTER Y - 0x005A: 0xE9, # LATIN CAPITAL LETTER Z - 0x005B: 0xBA, # LEFT SQUARE BRACKET - 0x005C: 0xE0, # REVERSE SOLIDUS - 0x005D: 0xBB, # RIGHT SQUARE BRACKET - 0x005E: 0xB0, # CIRCUMFLEX ACCENT - 0x005F: 0x6D, # LOW LINE - 0x0060: 0x79, # GRAVE ACCENT - 0x0061: 0x81, # LATIN SMALL LETTER A - 0x0062: 0x82, # LATIN SMALL LETTER B - 0x0063: 0x83, # LATIN SMALL LETTER C - 0x0064: 0x84, # LATIN SMALL LETTER D - 0x0065: 0x85, # LATIN SMALL LETTER E - 0x0066: 0x86, # LATIN SMALL LETTER F - 0x0067: 0x87, # LATIN SMALL LETTER G - 0x0068: 0x88, # LATIN SMALL LETTER H - 0x0069: 0x89, # LATIN SMALL LETTER I - 0x006A: 0x91, # LATIN SMALL LETTER J - 0x006B: 0x92, # LATIN SMALL LETTER K - 0x006C: 0x93, # LATIN SMALL LETTER L - 0x006D: 0x94, # LATIN SMALL LETTER M - 0x006E: 0x95, # LATIN SMALL LETTER N - 0x006F: 0x96, # LATIN SMALL LETTER O - 0x0070: 0x97, # LATIN SMALL LETTER P - 0x0071: 0x98, # LATIN SMALL LETTER Q - 0x0072: 0x99, # LATIN SMALL LETTER R - 0x0073: 0xA2, # LATIN SMALL LETTER S - 0x0074: 0xA3, # LATIN SMALL LETTER T - 0x0075: 0xA4, # LATIN SMALL LETTER U - 0x0076: 0xA5, # LATIN SMALL LETTER V - 0x0077: 0xA6, # LATIN SMALL LETTER W - 0x0078: 0xA7, # LATIN SMALL LETTER X - 0x0079: 0xA8, # LATIN SMALL LETTER Y - 0x007A: 0xA9, # LATIN SMALL LETTER Z - 0x007B: 0xC0, # LEFT CURLY BRACKET - 0x007C: 0x4F, # VERTICAL LINE - 0x007D: 0xD0, # RIGHT CURLY BRACKET - 0x007E: 0xA1, # TILDE - 0x007F: 0x07, # DELETE - 0x0080: 0x20, # DIGIT SELECT - 0x0081: 0x21, # START OF SIGNIFICANCE - 0x0082: 0x22, # FIELD SEPARATOR - 0x0083: 0x23, # WORD UNDERSCORE - 0x0084: 0x24, # BYPASS OR INHIBIT PRESENTATION - 0x0085: 0x15, # NEW LINE - 0x0086: 0x06, # REQUIRED NEW LINE - 0x0087: 0x17, # PROGRAM OPERATOR COMMUNICATION - 0x0088: 0x28, # SET ATTRIBUTE - 0x0089: 0x29, # START FIELD EXTENDED - 0x008A: 0x2A, # SET MODE OR SWITCH - 0x008B: 0x2B, # CONTROL SEQUENCE PREFIX - 0x008C: 0x2C, # MODIFY FIELD ATTRIBUTE - 0x008D: 0x09, # SUPERSCRIPT - 0x008E: 0x0A, # REPEAT - 0x008F: 0x1B, # CUSTOMER USE ONE - 0x0090: 0x30, # - 0x0091: 0x31, # - 0x0092: 0x1A, # UNIT BACK SPACE - 0x0093: 0x33, # INDEX RETURN - 0x0094: 0x34, # PRESENTATION POSITION - 0x0095: 0x35, # TRANSPARENT - 0x0096: 0x36, # NUMERIC BACKSPACE - 0x0097: 0x08, # GRAPHIC ESCAPE - 0x0098: 0x38, # SUBSCRIPT - 0x0099: 0x39, # INDENT TABULATION - 0x009A: 0x3A, # REVERSE FORM FEED - 0x009B: 0x3B, # CUSTOMER USE THREE - 0x009C: 0x04, # SELECT - 0x009D: 0x14, # RESTORE/ENABLE PRESENTATION - 0x009E: 0x3E, # - 0x009F: 0xFF, # EIGHT ONES - 0x00A0: 0x74, # NO-BREAK SPACE - 0x00A2: 0x4A, # CENT SIGN - 0x00A3: 0xB1, # POUND SIGN - 0x00A4: 0x9F, # CURRENCY SIGN - 0x00A5: 0xB2, # YEN SIGN - 0x00A6: 0x6A, # BROKEN BAR - 0x00A7: 0xB5, # SECTION SIGN - 0x00A8: 0xBD, # DIAERESIS - 0x00A9: 0xB4, # COPYRIGHT SIGN - 0x00AB: 0x8A, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0x5F, # NOT SIGN - 0x00AD: 0xCA, # SOFT HYPHEN - 0x00AE: 0xAF, # REGISTERED SIGN - 0x00AF: 0xBC, # MACRON - 0x00B0: 0x90, # DEGREE SIGN - 0x00B1: 0x8F, # PLUS-MINUS SIGN - 0x00B2: 0xEA, # SUPERSCRIPT TWO - 0x00B3: 0xFA, # SUPERSCRIPT THREE - 0x00B4: 0xBE, # ACUTE ACCENT - 0x00B5: 0xA0, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB3, # MIDDLE DOT - 0x00B8: 0x9D, # CEDILLA - 0x00B9: 0xDA, # SUPERSCRIPT ONE - 0x00BB: 0x8B, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xB7, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xB8, # VULGAR FRACTION ONE HALF - 0x00BE: 0xB9, # VULGAR FRACTION THREE QUARTERS - 0x00D7: 0xBF, # MULTIPLICATION SIGN - 0x00F7: 0xE1, # DIVISION SIGN - 0x05D0: 0x41, # HEBREW LETTER ALEF - 0x05D1: 0x42, # HEBREW LETTER BET - 0x05D2: 0x43, # HEBREW LETTER GIMEL - 0x05D3: 0x44, # HEBREW LETTER DALET - 0x05D4: 0x45, # HEBREW LETTER HE - 0x05D5: 0x46, # HEBREW LETTER VAV - 0x05D6: 0x47, # HEBREW LETTER ZAYIN - 0x05D7: 0x48, # HEBREW LETTER HET - 0x05D8: 0x49, # HEBREW LETTER TET - 0x05D9: 0x51, # HEBREW LETTER YOD - 0x05DA: 0x52, # HEBREW LETTER FINAL KAF - 0x05DB: 0x53, # HEBREW LETTER KAF - 0x05DC: 0x54, # HEBREW LETTER LAMED - 0x05DD: 0x55, # HEBREW LETTER FINAL MEM - 0x05DE: 0x56, # HEBREW LETTER MEM - 0x05DF: 0x57, # HEBREW LETTER FINAL NUN - 0x05E0: 0x58, # HEBREW LETTER NUN - 0x05E1: 0x59, # HEBREW LETTER SAMEKH - 0x05E2: 0x62, # HEBREW LETTER AYIN - 0x05E3: 0x63, # HEBREW LETTER FINAL PE - 0x05E4: 0x64, # HEBREW LETTER PE - 0x05E5: 0x65, # HEBREW LETTER FINAL TSADI - 0x05E6: 0x66, # HEBREW LETTER TSADI - 0x05E7: 0x67, # HEBREW LETTER QOF - 0x05E8: 0x68, # HEBREW LETTER RESH - 0x05E9: 0x69, # HEBREW LETTER SHIN - 0x05EA: 0x71, # HEBREW LETTER TAV - 0x2017: 0x78, # DOUBLE LOW LINE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp500.py b/Lib/encodings/cp500.py index 83af090..60766c0 100644 --- a/Lib/encodings/cp500.py +++ b/Lib/encodings/cp500.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\x9f' # 0xFF -> CONTROL ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x37, # END OF TRANSMISSION - 0x0005: 0x2D, # ENQUIRY - 0x0006: 0x2E, # ACKNOWLEDGE - 0x0007: 0x2F, # BELL - 0x0008: 0x16, # BACKSPACE - 0x0009: 0x05, # HORIZONTAL TABULATION - 0x000A: 0x25, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x3C, # DEVICE CONTROL FOUR - 0x0015: 0x3D, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x32, # SYNCHRONOUS IDLE - 0x0017: 0x26, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x3F, # SUBSTITUTE - 0x001B: 0x27, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x40, # SPACE - 0x0021: 0x4F, # EXCLAMATION MARK - 0x0022: 0x7F, # QUOTATION MARK - 0x0023: 0x7B, # NUMBER SIGN - 0x0024: 0x5B, # DOLLAR SIGN - 0x0025: 0x6C, # PERCENT SIGN - 0x0026: 0x50, # AMPERSAND - 0x0027: 0x7D, # APOSTROPHE - 0x0028: 0x4D, # LEFT PARENTHESIS - 0x0029: 0x5D, # RIGHT PARENTHESIS - 0x002A: 0x5C, # ASTERISK - 0x002B: 0x4E, # PLUS SIGN - 0x002C: 0x6B, # COMMA - 0x002D: 0x60, # HYPHEN-MINUS - 0x002E: 0x4B, # FULL STOP - 0x002F: 0x61, # SOLIDUS - 0x0030: 0xF0, # DIGIT ZERO - 0x0031: 0xF1, # DIGIT ONE - 0x0032: 0xF2, # DIGIT TWO - 0x0033: 0xF3, # DIGIT THREE - 0x0034: 0xF4, # DIGIT FOUR - 0x0035: 0xF5, # DIGIT FIVE - 0x0036: 0xF6, # DIGIT SIX - 0x0037: 0xF7, # DIGIT SEVEN - 0x0038: 0xF8, # DIGIT EIGHT - 0x0039: 0xF9, # DIGIT NINE - 0x003A: 0x7A, # COLON - 0x003B: 0x5E, # SEMICOLON - 0x003C: 0x4C, # LESS-THAN SIGN - 0x003D: 0x7E, # EQUALS SIGN - 0x003E: 0x6E, # GREATER-THAN SIGN - 0x003F: 0x6F, # QUESTION MARK - 0x0040: 0x7C, # COMMERCIAL AT - 0x0041: 0xC1, # LATIN CAPITAL LETTER A - 0x0042: 0xC2, # LATIN CAPITAL LETTER B - 0x0043: 0xC3, # LATIN CAPITAL LETTER C - 0x0044: 0xC4, # LATIN CAPITAL LETTER D - 0x0045: 0xC5, # LATIN CAPITAL LETTER E - 0x0046: 0xC6, # LATIN CAPITAL LETTER F - 0x0047: 0xC7, # LATIN CAPITAL LETTER G - 0x0048: 0xC8, # LATIN CAPITAL LETTER H - 0x0049: 0xC9, # LATIN CAPITAL LETTER I - 0x004A: 0xD1, # LATIN CAPITAL LETTER J - 0x004B: 0xD2, # LATIN CAPITAL LETTER K - 0x004C: 0xD3, # LATIN CAPITAL LETTER L - 0x004D: 0xD4, # LATIN CAPITAL LETTER M - 0x004E: 0xD5, # LATIN CAPITAL LETTER N - 0x004F: 0xD6, # LATIN CAPITAL LETTER O - 0x0050: 0xD7, # LATIN CAPITAL LETTER P - 0x0051: 0xD8, # LATIN CAPITAL LETTER Q - 0x0052: 0xD9, # LATIN CAPITAL LETTER R - 0x0053: 0xE2, # LATIN CAPITAL LETTER S - 0x0054: 0xE3, # LATIN CAPITAL LETTER T - 0x0055: 0xE4, # LATIN CAPITAL LETTER U - 0x0056: 0xE5, # LATIN CAPITAL LETTER V - 0x0057: 0xE6, # LATIN CAPITAL LETTER W - 0x0058: 0xE7, # LATIN CAPITAL LETTER X - 0x0059: 0xE8, # LATIN CAPITAL LETTER Y - 0x005A: 0xE9, # LATIN CAPITAL LETTER Z - 0x005B: 0x4A, # LEFT SQUARE BRACKET - 0x005C: 0xE0, # REVERSE SOLIDUS - 0x005D: 0x5A, # RIGHT SQUARE BRACKET - 0x005E: 0x5F, # CIRCUMFLEX ACCENT - 0x005F: 0x6D, # LOW LINE - 0x0060: 0x79, # GRAVE ACCENT - 0x0061: 0x81, # LATIN SMALL LETTER A - 0x0062: 0x82, # LATIN SMALL LETTER B - 0x0063: 0x83, # LATIN SMALL LETTER C - 0x0064: 0x84, # LATIN SMALL LETTER D - 0x0065: 0x85, # LATIN SMALL LETTER E - 0x0066: 0x86, # LATIN SMALL LETTER F - 0x0067: 0x87, # LATIN SMALL LETTER G - 0x0068: 0x88, # LATIN SMALL LETTER H - 0x0069: 0x89, # LATIN SMALL LETTER I - 0x006A: 0x91, # LATIN SMALL LETTER J - 0x006B: 0x92, # LATIN SMALL LETTER K - 0x006C: 0x93, # LATIN SMALL LETTER L - 0x006D: 0x94, # LATIN SMALL LETTER M - 0x006E: 0x95, # LATIN SMALL LETTER N - 0x006F: 0x96, # LATIN SMALL LETTER O - 0x0070: 0x97, # LATIN SMALL LETTER P - 0x0071: 0x98, # LATIN SMALL LETTER Q - 0x0072: 0x99, # LATIN SMALL LETTER R - 0x0073: 0xA2, # LATIN SMALL LETTER S - 0x0074: 0xA3, # LATIN SMALL LETTER T - 0x0075: 0xA4, # LATIN SMALL LETTER U - 0x0076: 0xA5, # LATIN SMALL LETTER V - 0x0077: 0xA6, # LATIN SMALL LETTER W - 0x0078: 0xA7, # LATIN SMALL LETTER X - 0x0079: 0xA8, # LATIN SMALL LETTER Y - 0x007A: 0xA9, # LATIN SMALL LETTER Z - 0x007B: 0xC0, # LEFT CURLY BRACKET - 0x007C: 0xBB, # VERTICAL LINE - 0x007D: 0xD0, # RIGHT CURLY BRACKET - 0x007E: 0xA1, # TILDE - 0x007F: 0x07, # DELETE - 0x0080: 0x20, # CONTROL - 0x0081: 0x21, # CONTROL - 0x0082: 0x22, # CONTROL - 0x0083: 0x23, # CONTROL - 0x0084: 0x24, # CONTROL - 0x0085: 0x15, # CONTROL - 0x0086: 0x06, # CONTROL - 0x0087: 0x17, # CONTROL - 0x0088: 0x28, # CONTROL - 0x0089: 0x29, # CONTROL - 0x008A: 0x2A, # CONTROL - 0x008B: 0x2B, # CONTROL - 0x008C: 0x2C, # CONTROL - 0x008D: 0x09, # CONTROL - 0x008E: 0x0A, # CONTROL - 0x008F: 0x1B, # CONTROL - 0x0090: 0x30, # CONTROL - 0x0091: 0x31, # CONTROL - 0x0092: 0x1A, # CONTROL - 0x0093: 0x33, # CONTROL - 0x0094: 0x34, # CONTROL - 0x0095: 0x35, # CONTROL - 0x0096: 0x36, # CONTROL - 0x0097: 0x08, # CONTROL - 0x0098: 0x38, # CONTROL - 0x0099: 0x39, # CONTROL - 0x009A: 0x3A, # CONTROL - 0x009B: 0x3B, # CONTROL - 0x009C: 0x04, # CONTROL - 0x009D: 0x14, # CONTROL - 0x009E: 0x3E, # CONTROL - 0x009F: 0xFF, # CONTROL - 0x00A0: 0x41, # NO-BREAK SPACE - 0x00A1: 0xAA, # INVERTED EXCLAMATION MARK - 0x00A2: 0xB0, # CENT SIGN - 0x00A3: 0xB1, # POUND SIGN - 0x00A4: 0x9F, # CURRENCY SIGN - 0x00A5: 0xB2, # YEN SIGN - 0x00A6: 0x6A, # BROKEN BAR - 0x00A7: 0xB5, # SECTION SIGN - 0x00A8: 0xBD, # DIAERESIS - 0x00A9: 0xB4, # COPYRIGHT SIGN - 0x00AA: 0x9A, # FEMININE ORDINAL INDICATOR - 0x00AB: 0x8A, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xBA, # NOT SIGN - 0x00AD: 0xCA, # SOFT HYPHEN - 0x00AE: 0xAF, # REGISTERED SIGN - 0x00AF: 0xBC, # MACRON - 0x00B0: 0x90, # DEGREE SIGN - 0x00B1: 0x8F, # PLUS-MINUS SIGN - 0x00B2: 0xEA, # SUPERSCRIPT TWO - 0x00B3: 0xFA, # SUPERSCRIPT THREE - 0x00B4: 0xBE, # ACUTE ACCENT - 0x00B5: 0xA0, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB3, # MIDDLE DOT - 0x00B8: 0x9D, # CEDILLA - 0x00B9: 0xDA, # SUPERSCRIPT ONE - 0x00BA: 0x9B, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0x8B, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xB7, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xB8, # VULGAR FRACTION ONE HALF - 0x00BE: 0xB9, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xAB, # INVERTED QUESTION MARK - 0x00C0: 0x64, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0x65, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0x62, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0x66, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x63, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x67, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0x9E, # LATIN CAPITAL LIGATURE AE - 0x00C7: 0x68, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0x74, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x71, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0x72, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0x73, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0x78, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0x75, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0x76, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0x77, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xAC, # LATIN CAPITAL LETTER ETH (ICELANDIC) - 0x00D1: 0x69, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xED, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEB, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xEF, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xEC, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xBF, # MULTIPLICATION SIGN - 0x00D8: 0x80, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xFD, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xFE, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xFB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xFC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xAD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xAE, # LATIN CAPITAL LETTER THORN (ICELANDIC) - 0x00DF: 0x59, # LATIN SMALL LETTER SHARP S (GERMAN) - 0x00E0: 0x44, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x45, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x42, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x46, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x43, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x47, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0x9C, # LATIN SMALL LIGATURE AE - 0x00E7: 0x48, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x54, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x51, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x52, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x53, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x58, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x55, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x56, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x57, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0x8C, # LATIN SMALL LETTER ETH (ICELANDIC) - 0x00F1: 0x49, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xCD, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xCE, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xCB, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xCF, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xCC, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xE1, # DIVISION SIGN - 0x00F8: 0x70, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xDD, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xDE, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xDB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xDC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0x8D, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0x8E, # LATIN SMALL LETTER THORN (ICELANDIC) - 0x00FF: 0xDF, # LATIN SMALL LETTER Y WITH DIAERESIS -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp856.py b/Lib/encodings/cp856.py index c72fcad..203c2c4 100644 --- a/Lib/encodings/cp856.py +++ b/Lib/encodings/cp856.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,222 +303,5 @@ decoding_table = ( u'\xa0' # 0xFF -> NO-BREAK SPACE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xFF, # NO-BREAK SPACE - 0x00A2: 0xBD, # CENT SIGN - 0x00A3: 0x9C, # POUND SIGN - 0x00A4: 0xCF, # CURRENCY SIGN - 0x00A5: 0xBE, # YEN SIGN - 0x00A6: 0xDD, # BROKEN BAR - 0x00A7: 0xF5, # SECTION SIGN - 0x00A8: 0xF9, # DIAERESIS - 0x00A9: 0xB8, # COPYRIGHT SIGN - 0x00AB: 0xAE, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAA, # NOT SIGN - 0x00AD: 0xF0, # SOFT HYPHEN - 0x00AE: 0xA9, # REGISTERED SIGN - 0x00AF: 0xEE, # MACRON - 0x00B0: 0xF8, # DEGREE SIGN - 0x00B1: 0xF1, # PLUS-MINUS SIGN - 0x00B2: 0xFD, # SUPERSCRIPT TWO - 0x00B3: 0xFC, # SUPERSCRIPT THREE - 0x00B4: 0xEF, # ACUTE ACCENT - 0x00B5: 0xE6, # MICRO SIGN - 0x00B6: 0xF4, # PILCROW SIGN - 0x00B7: 0xFA, # MIDDLE DOT - 0x00B8: 0xF7, # CEDILLA - 0x00B9: 0xFB, # SUPERSCRIPT ONE - 0x00BB: 0xAF, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xAC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xAB, # VULGAR FRACTION ONE HALF - 0x00BE: 0xF3, # VULGAR FRACTION THREE QUARTERS - 0x00D7: 0x9E, # MULTIPLICATION SIGN - 0x00F7: 0xF6, # DIVISION SIGN - 0x05D0: 0x80, # HEBREW LETTER ALEF - 0x05D1: 0x81, # HEBREW LETTER BET - 0x05D2: 0x82, # HEBREW LETTER GIMEL - 0x05D3: 0x83, # HEBREW LETTER DALET - 0x05D4: 0x84, # HEBREW LETTER HE - 0x05D5: 0x85, # HEBREW LETTER VAV - 0x05D6: 0x86, # HEBREW LETTER ZAYIN - 0x05D7: 0x87, # HEBREW LETTER HET - 0x05D8: 0x88, # HEBREW LETTER TET - 0x05D9: 0x89, # HEBREW LETTER YOD - 0x05DA: 0x8A, # HEBREW LETTER FINAL KAF - 0x05DB: 0x8B, # HEBREW LETTER KAF - 0x05DC: 0x8C, # HEBREW LETTER LAMED - 0x05DD: 0x8D, # HEBREW LETTER FINAL MEM - 0x05DE: 0x8E, # HEBREW LETTER MEM - 0x05DF: 0x8F, # HEBREW LETTER FINAL NUN - 0x05E0: 0x90, # HEBREW LETTER NUN - 0x05E1: 0x91, # HEBREW LETTER SAMEKH - 0x05E2: 0x92, # HEBREW LETTER AYIN - 0x05E3: 0x93, # HEBREW LETTER FINAL PE - 0x05E4: 0x94, # HEBREW LETTER PE - 0x05E5: 0x95, # HEBREW LETTER FINAL TSADI - 0x05E6: 0x96, # HEBREW LETTER TSADI - 0x05E7: 0x97, # HEBREW LETTER QOF - 0x05E8: 0x98, # HEBREW LETTER RESH - 0x05E9: 0x99, # HEBREW LETTER SHIN - 0x05EA: 0x9A, # HEBREW LETTER TAV - 0x2017: 0xF2, # DOUBLE LOW LINE - 0x2500: 0xC4, # BOX DRAWINGS LIGHT HORIZONTAL - 0x2502: 0xB3, # BOX DRAWINGS LIGHT VERTICAL - 0x250C: 0xDA, # BOX DRAWINGS LIGHT DOWN AND RIGHT - 0x2510: 0xBF, # BOX DRAWINGS LIGHT DOWN AND LEFT - 0x2514: 0xC0, # BOX DRAWINGS LIGHT UP AND RIGHT - 0x2518: 0xD9, # BOX DRAWINGS LIGHT UP AND LEFT - 0x251C: 0xC3, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT - 0x2524: 0xB4, # BOX DRAWINGS LIGHT VERTICAL AND LEFT - 0x252C: 0xC2, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - 0x2534: 0xC1, # BOX DRAWINGS LIGHT UP AND HORIZONTAL - 0x253C: 0xC5, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - 0x2550: 0xCD, # BOX DRAWINGS DOUBLE HORIZONTAL - 0x2551: 0xBA, # BOX DRAWINGS DOUBLE VERTICAL - 0x2554: 0xC9, # BOX DRAWINGS DOUBLE DOWN AND RIGHT - 0x2557: 0xBB, # BOX DRAWINGS DOUBLE DOWN AND LEFT - 0x255A: 0xC8, # BOX DRAWINGS DOUBLE UP AND RIGHT - 0x255D: 0xBC, # BOX DRAWINGS DOUBLE UP AND LEFT - 0x2560: 0xCC, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT - 0x2563: 0xB9, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT - 0x2566: 0xCB, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL - 0x2569: 0xCA, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL - 0x256C: 0xCE, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL - 0x2580: 0xDF, # UPPER HALF BLOCK - 0x2584: 0xDC, # LOWER HALF BLOCK - 0x2588: 0xDB, # FULL BLOCK - 0x2591: 0xB0, # LIGHT SHADE - 0x2592: 0xB1, # MEDIUM SHADE - 0x2593: 0xB2, # DARK SHADE - 0x25A0: 0xFE, # BLACK SQUARE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp874.py b/Lib/encodings/cp874.py index 591e8aa..6110f46 100644 --- a/Lib/encodings/cp874.py +++ b/Lib/encodings/cp874.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,232 +303,5 @@ decoding_table = ( u'\ufffe' # 0xFF -> UNDEFINED ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x0E01: 0xA1, # THAI CHARACTER KO KAI - 0x0E02: 0xA2, # THAI CHARACTER KHO KHAI - 0x0E03: 0xA3, # THAI CHARACTER KHO KHUAT - 0x0E04: 0xA4, # THAI CHARACTER KHO KHWAI - 0x0E05: 0xA5, # THAI CHARACTER KHO KHON - 0x0E06: 0xA6, # THAI CHARACTER KHO RAKHANG - 0x0E07: 0xA7, # THAI CHARACTER NGO NGU - 0x0E08: 0xA8, # THAI CHARACTER CHO CHAN - 0x0E09: 0xA9, # THAI CHARACTER CHO CHING - 0x0E0A: 0xAA, # THAI CHARACTER CHO CHANG - 0x0E0B: 0xAB, # THAI CHARACTER SO SO - 0x0E0C: 0xAC, # THAI CHARACTER CHO CHOE - 0x0E0D: 0xAD, # THAI CHARACTER YO YING - 0x0E0E: 0xAE, # THAI CHARACTER DO CHADA - 0x0E0F: 0xAF, # THAI CHARACTER TO PATAK - 0x0E10: 0xB0, # THAI CHARACTER THO THAN - 0x0E11: 0xB1, # THAI CHARACTER THO NANGMONTHO - 0x0E12: 0xB2, # THAI CHARACTER THO PHUTHAO - 0x0E13: 0xB3, # THAI CHARACTER NO NEN - 0x0E14: 0xB4, # THAI CHARACTER DO DEK - 0x0E15: 0xB5, # THAI CHARACTER TO TAO - 0x0E16: 0xB6, # THAI CHARACTER THO THUNG - 0x0E17: 0xB7, # THAI CHARACTER THO THAHAN - 0x0E18: 0xB8, # THAI CHARACTER THO THONG - 0x0E19: 0xB9, # THAI CHARACTER NO NU - 0x0E1A: 0xBA, # THAI CHARACTER BO BAIMAI - 0x0E1B: 0xBB, # THAI CHARACTER PO PLA - 0x0E1C: 0xBC, # THAI CHARACTER PHO PHUNG - 0x0E1D: 0xBD, # THAI CHARACTER FO FA - 0x0E1E: 0xBE, # THAI CHARACTER PHO PHAN - 0x0E1F: 0xBF, # THAI CHARACTER FO FAN - 0x0E20: 0xC0, # THAI CHARACTER PHO SAMPHAO - 0x0E21: 0xC1, # THAI CHARACTER MO MA - 0x0E22: 0xC2, # THAI CHARACTER YO YAK - 0x0E23: 0xC3, # THAI CHARACTER RO RUA - 0x0E24: 0xC4, # THAI CHARACTER RU - 0x0E25: 0xC5, # THAI CHARACTER LO LING - 0x0E26: 0xC6, # THAI CHARACTER LU - 0x0E27: 0xC7, # THAI CHARACTER WO WAEN - 0x0E28: 0xC8, # THAI CHARACTER SO SALA - 0x0E29: 0xC9, # THAI CHARACTER SO RUSI - 0x0E2A: 0xCA, # THAI CHARACTER SO SUA - 0x0E2B: 0xCB, # THAI CHARACTER HO HIP - 0x0E2C: 0xCC, # THAI CHARACTER LO CHULA - 0x0E2D: 0xCD, # THAI CHARACTER O ANG - 0x0E2E: 0xCE, # THAI CHARACTER HO NOKHUK - 0x0E2F: 0xCF, # THAI CHARACTER PAIYANNOI - 0x0E30: 0xD0, # THAI CHARACTER SARA A - 0x0E31: 0xD1, # THAI CHARACTER MAI HAN-AKAT - 0x0E32: 0xD2, # THAI CHARACTER SARA AA - 0x0E33: 0xD3, # THAI CHARACTER SARA AM - 0x0E34: 0xD4, # THAI CHARACTER SARA I - 0x0E35: 0xD5, # THAI CHARACTER SARA II - 0x0E36: 0xD6, # THAI CHARACTER SARA UE - 0x0E37: 0xD7, # THAI CHARACTER SARA UEE - 0x0E38: 0xD8, # THAI CHARACTER SARA U - 0x0E39: 0xD9, # THAI CHARACTER SARA UU - 0x0E3A: 0xDA, # THAI CHARACTER PHINTHU - 0x0E3F: 0xDF, # THAI CURRENCY SYMBOL BAHT - 0x0E40: 0xE0, # THAI CHARACTER SARA E - 0x0E41: 0xE1, # THAI CHARACTER SARA AE - 0x0E42: 0xE2, # THAI CHARACTER SARA O - 0x0E43: 0xE3, # THAI CHARACTER SARA AI MAIMUAN - 0x0E44: 0xE4, # THAI CHARACTER SARA AI MAIMALAI - 0x0E45: 0xE5, # THAI CHARACTER LAKKHANGYAO - 0x0E46: 0xE6, # THAI CHARACTER MAIYAMOK - 0x0E47: 0xE7, # THAI CHARACTER MAITAIKHU - 0x0E48: 0xE8, # THAI CHARACTER MAI EK - 0x0E49: 0xE9, # THAI CHARACTER MAI THO - 0x0E4A: 0xEA, # THAI CHARACTER MAI TRI - 0x0E4B: 0xEB, # THAI CHARACTER MAI CHATTAWA - 0x0E4C: 0xEC, # THAI CHARACTER THANTHAKHAT - 0x0E4D: 0xED, # THAI CHARACTER NIKHAHIT - 0x0E4E: 0xEE, # THAI CHARACTER YAMAKKAN - 0x0E4F: 0xEF, # THAI CHARACTER FONGMAN - 0x0E50: 0xF0, # THAI DIGIT ZERO - 0x0E51: 0xF1, # THAI DIGIT ONE - 0x0E52: 0xF2, # THAI DIGIT TWO - 0x0E53: 0xF3, # THAI DIGIT THREE - 0x0E54: 0xF4, # THAI DIGIT FOUR - 0x0E55: 0xF5, # THAI DIGIT FIVE - 0x0E56: 0xF6, # THAI DIGIT SIX - 0x0E57: 0xF7, # THAI DIGIT SEVEN - 0x0E58: 0xF8, # THAI DIGIT EIGHT - 0x0E59: 0xF9, # THAI DIGIT NINE - 0x0E5A: 0xFA, # THAI CHARACTER ANGKHANKHU - 0x0E5B: 0xFB, # THAI CHARACTER KHOMUT - 0x2013: 0x96, # EN DASH - 0x2014: 0x97, # EM DASH - 0x2018: 0x91, # LEFT SINGLE QUOTATION MARK - 0x2019: 0x92, # RIGHT SINGLE QUOTATION MARK - 0x201C: 0x93, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0x94, # RIGHT DOUBLE QUOTATION MARK - 0x2022: 0x95, # BULLET - 0x2026: 0x85, # HORIZONTAL ELLIPSIS - 0x20AC: 0x80, # EURO SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/cp875.py b/Lib/encodings/cp875.py index 879d5a4..72b160b 100644 --- a/Lib/encodings/cp875.py +++ b/Lib/encodings/cp875.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,257 +303,5 @@ decoding_table = ( u'\x9f' # 0xFF -> CONTROL ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x37, # END OF TRANSMISSION - 0x0005: 0x2D, # ENQUIRY - 0x0006: 0x2E, # ACKNOWLEDGE - 0x0007: 0x2F, # BELL - 0x0008: 0x16, # BACKSPACE - 0x0009: 0x05, # HORIZONTAL TABULATION - 0x000A: 0x25, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x3C, # DEVICE CONTROL FOUR - 0x0015: 0x3D, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x32, # SYNCHRONOUS IDLE - 0x0017: 0x26, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: None, # SUBSTITUTE - 0x001B: 0x27, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x40, # SPACE - 0x0021: 0x4F, # EXCLAMATION MARK - 0x0022: 0x7F, # QUOTATION MARK - 0x0023: 0x7B, # NUMBER SIGN - 0x0024: 0x5B, # DOLLAR SIGN - 0x0025: 0x6C, # PERCENT SIGN - 0x0026: 0x50, # AMPERSAND - 0x0027: 0x7D, # APOSTROPHE - 0x0028: 0x4D, # LEFT PARENTHESIS - 0x0029: 0x5D, # RIGHT PARENTHESIS - 0x002A: 0x5C, # ASTERISK - 0x002B: 0x4E, # PLUS SIGN - 0x002C: 0x6B, # COMMA - 0x002D: 0x60, # HYPHEN-MINUS - 0x002E: 0x4B, # FULL STOP - 0x002F: 0x61, # SOLIDUS - 0x0030: 0xF0, # DIGIT ZERO - 0x0031: 0xF1, # DIGIT ONE - 0x0032: 0xF2, # DIGIT TWO - 0x0033: 0xF3, # DIGIT THREE - 0x0034: 0xF4, # DIGIT FOUR - 0x0035: 0xF5, # DIGIT FIVE - 0x0036: 0xF6, # DIGIT SIX - 0x0037: 0xF7, # DIGIT SEVEN - 0x0038: 0xF8, # DIGIT EIGHT - 0x0039: 0xF9, # DIGIT NINE - 0x003A: 0x7A, # COLON - 0x003B: 0x5E, # SEMICOLON - 0x003C: 0x4C, # LESS-THAN SIGN - 0x003D: 0x7E, # EQUALS SIGN - 0x003E: 0x6E, # GREATER-THAN SIGN - 0x003F: 0x6F, # QUESTION MARK - 0x0040: 0x7C, # COMMERCIAL AT - 0x0041: 0xC1, # LATIN CAPITAL LETTER A - 0x0042: 0xC2, # LATIN CAPITAL LETTER B - 0x0043: 0xC3, # LATIN CAPITAL LETTER C - 0x0044: 0xC4, # LATIN CAPITAL LETTER D - 0x0045: 0xC5, # LATIN CAPITAL LETTER E - 0x0046: 0xC6, # LATIN CAPITAL LETTER F - 0x0047: 0xC7, # LATIN CAPITAL LETTER G - 0x0048: 0xC8, # LATIN CAPITAL LETTER H - 0x0049: 0xC9, # LATIN CAPITAL LETTER I - 0x004A: 0xD1, # LATIN CAPITAL LETTER J - 0x004B: 0xD2, # LATIN CAPITAL LETTER K - 0x004C: 0xD3, # LATIN CAPITAL LETTER L - 0x004D: 0xD4, # LATIN CAPITAL LETTER M - 0x004E: 0xD5, # LATIN CAPITAL LETTER N - 0x004F: 0xD6, # LATIN CAPITAL LETTER O - 0x0050: 0xD7, # LATIN CAPITAL LETTER P - 0x0051: 0xD8, # LATIN CAPITAL LETTER Q - 0x0052: 0xD9, # LATIN CAPITAL LETTER R - 0x0053: 0xE2, # LATIN CAPITAL LETTER S - 0x0054: 0xE3, # LATIN CAPITAL LETTER T - 0x0055: 0xE4, # LATIN CAPITAL LETTER U - 0x0056: 0xE5, # LATIN CAPITAL LETTER V - 0x0057: 0xE6, # LATIN CAPITAL LETTER W - 0x0058: 0xE7, # LATIN CAPITAL LETTER X - 0x0059: 0xE8, # LATIN CAPITAL LETTER Y - 0x005A: 0xE9, # LATIN CAPITAL LETTER Z - 0x005B: 0x4A, # LEFT SQUARE BRACKET - 0x005C: 0xE0, # REVERSE SOLIDUS - 0x005D: 0x5A, # RIGHT SQUARE BRACKET - 0x005E: 0x5F, # CIRCUMFLEX ACCENT - 0x005F: 0x6D, # LOW LINE - 0x0060: 0x79, # GRAVE ACCENT - 0x0061: 0x81, # LATIN SMALL LETTER A - 0x0062: 0x82, # LATIN SMALL LETTER B - 0x0063: 0x83, # LATIN SMALL LETTER C - 0x0064: 0x84, # LATIN SMALL LETTER D - 0x0065: 0x85, # LATIN SMALL LETTER E - 0x0066: 0x86, # LATIN SMALL LETTER F - 0x0067: 0x87, # LATIN SMALL LETTER G - 0x0068: 0x88, # LATIN SMALL LETTER H - 0x0069: 0x89, # LATIN SMALL LETTER I - 0x006A: 0x91, # LATIN SMALL LETTER J - 0x006B: 0x92, # LATIN SMALL LETTER K - 0x006C: 0x93, # LATIN SMALL LETTER L - 0x006D: 0x94, # LATIN SMALL LETTER M - 0x006E: 0x95, # LATIN SMALL LETTER N - 0x006F: 0x96, # LATIN SMALL LETTER O - 0x0070: 0x97, # LATIN SMALL LETTER P - 0x0071: 0x98, # LATIN SMALL LETTER Q - 0x0072: 0x99, # LATIN SMALL LETTER R - 0x0073: 0xA2, # LATIN SMALL LETTER S - 0x0074: 0xA3, # LATIN SMALL LETTER T - 0x0075: 0xA4, # LATIN SMALL LETTER U - 0x0076: 0xA5, # LATIN SMALL LETTER V - 0x0077: 0xA6, # LATIN SMALL LETTER W - 0x0078: 0xA7, # LATIN SMALL LETTER X - 0x0079: 0xA8, # LATIN SMALL LETTER Y - 0x007A: 0xA9, # LATIN SMALL LETTER Z - 0x007B: 0xC0, # LEFT CURLY BRACKET - 0x007C: 0x6A, # VERTICAL LINE - 0x007D: 0xD0, # RIGHT CURLY BRACKET - 0x007E: 0xA1, # TILDE - 0x007F: 0x07, # DELETE - 0x0080: 0x20, # CONTROL - 0x0081: 0x21, # CONTROL - 0x0082: 0x22, # CONTROL - 0x0083: 0x23, # CONTROL - 0x0084: 0x24, # CONTROL - 0x0085: 0x15, # CONTROL - 0x0086: 0x06, # CONTROL - 0x0087: 0x17, # CONTROL - 0x0088: 0x28, # CONTROL - 0x0089: 0x29, # CONTROL - 0x008A: 0x2A, # CONTROL - 0x008B: 0x2B, # CONTROL - 0x008C: 0x2C, # CONTROL - 0x008D: 0x09, # CONTROL - 0x008E: 0x0A, # CONTROL - 0x008F: 0x1B, # CONTROL - 0x0090: 0x30, # CONTROL - 0x0091: 0x31, # CONTROL - 0x0092: 0x1A, # CONTROL - 0x0093: 0x33, # CONTROL - 0x0094: 0x34, # CONTROL - 0x0095: 0x35, # CONTROL - 0x0096: 0x36, # CONTROL - 0x0097: 0x08, # CONTROL - 0x0098: 0x38, # CONTROL - 0x0099: 0x39, # CONTROL - 0x009A: 0x3A, # CONTROL - 0x009B: 0x3B, # CONTROL - 0x009C: 0x04, # CONTROL - 0x009D: 0x14, # CONTROL - 0x009E: 0x3E, # CONTROL - 0x009F: 0xFF, # CONTROL - 0x00A0: 0x74, # NO-BREAK SPACE - 0x00A3: 0xB0, # POUND SIGN - 0x00A6: 0xDF, # BROKEN BAR - 0x00A7: 0xEB, # SECTION SIGN - 0x00A8: 0x70, # DIAERESIS - 0x00A9: 0xFB, # COPYRIGHT SIGN - 0x00AB: 0xEE, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xEF, # NOT SIGN - 0x00AD: 0xCA, # SOFT HYPHEN - 0x00B0: 0x90, # DEGREE SIGN - 0x00B1: 0xDA, # PLUS-MINUS SIGN - 0x00B2: 0xEA, # SUPERSCRIPT TWO - 0x00B3: 0xFA, # SUPERSCRIPT THREE - 0x00B4: 0xA0, # ACUTE ACCENT - 0x00BB: 0xFE, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BD: 0xDB, # VULGAR FRACTION ONE HALF - 0x0385: 0x80, # GREEK DIALYTIKA TONOS - 0x0386: 0x71, # GREEK CAPITAL LETTER ALPHA WITH TONOS - 0x0387: 0xDD, # GREEK ANO TELEIA - 0x0388: 0x72, # GREEK CAPITAL LETTER EPSILON WITH TONOS - 0x0389: 0x73, # GREEK CAPITAL LETTER ETA WITH TONOS - 0x038A: 0x75, # GREEK CAPITAL LETTER IOTA WITH TONOS - 0x038C: 0x76, # GREEK CAPITAL LETTER OMICRON WITH TONOS - 0x038E: 0x77, # GREEK CAPITAL LETTER UPSILON WITH TONOS - 0x038F: 0x78, # GREEK CAPITAL LETTER OMEGA WITH TONOS - 0x0390: 0xCC, # GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS - 0x0391: 0x41, # GREEK CAPITAL LETTER ALPHA - 0x0392: 0x42, # GREEK CAPITAL LETTER BETA - 0x0393: 0x43, # GREEK CAPITAL LETTER GAMMA - 0x0394: 0x44, # GREEK CAPITAL LETTER DELTA - 0x0395: 0x45, # GREEK CAPITAL LETTER EPSILON - 0x0396: 0x46, # GREEK CAPITAL LETTER ZETA - 0x0397: 0x47, # GREEK CAPITAL LETTER ETA - 0x0398: 0x48, # GREEK CAPITAL LETTER THETA - 0x0399: 0x49, # GREEK CAPITAL LETTER IOTA - 0x039A: 0x51, # GREEK CAPITAL LETTER KAPPA - 0x039B: 0x52, # GREEK CAPITAL LETTER LAMDA - 0x039C: 0x53, # GREEK CAPITAL LETTER MU - 0x039D: 0x54, # GREEK CAPITAL LETTER NU - 0x039E: 0x55, # GREEK CAPITAL LETTER XI - 0x039F: 0x56, # GREEK CAPITAL LETTER OMICRON - 0x03A0: 0x57, # GREEK CAPITAL LETTER PI - 0x03A1: 0x58, # GREEK CAPITAL LETTER RHO - 0x03A3: 0x59, # GREEK CAPITAL LETTER SIGMA - 0x03A4: 0x62, # GREEK CAPITAL LETTER TAU - 0x03A5: 0x63, # GREEK CAPITAL LETTER UPSILON - 0x03A6: 0x64, # GREEK CAPITAL LETTER PHI - 0x03A7: 0x65, # GREEK CAPITAL LETTER CHI - 0x03A8: 0x66, # GREEK CAPITAL LETTER PSI - 0x03A9: 0x67, # GREEK CAPITAL LETTER OMEGA - 0x03AA: 0x68, # GREEK CAPITAL LETTER IOTA WITH DIALYTIKA - 0x03AB: 0x69, # GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA - 0x03AC: 0xB1, # GREEK SMALL LETTER ALPHA WITH TONOS - 0x03AD: 0xB2, # GREEK SMALL LETTER EPSILON WITH TONOS - 0x03AE: 0xB3, # GREEK SMALL LETTER ETA WITH TONOS - 0x03AF: 0xB5, # GREEK SMALL LETTER IOTA WITH TONOS - 0x03B0: 0xCD, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS - 0x03B1: 0x8A, # GREEK SMALL LETTER ALPHA - 0x03B2: 0x8B, # GREEK SMALL LETTER BETA - 0x03B3: 0x8C, # GREEK SMALL LETTER GAMMA - 0x03B4: 0x8D, # GREEK SMALL LETTER DELTA - 0x03B5: 0x8E, # GREEK SMALL LETTER EPSILON - 0x03B6: 0x8F, # GREEK SMALL LETTER ZETA - 0x03B7: 0x9A, # GREEK SMALL LETTER ETA - 0x03B8: 0x9B, # GREEK SMALL LETTER THETA - 0x03B9: 0x9C, # GREEK SMALL LETTER IOTA - 0x03BA: 0x9D, # GREEK SMALL LETTER KAPPA - 0x03BB: 0x9E, # GREEK SMALL LETTER LAMDA - 0x03BC: 0x9F, # GREEK SMALL LETTER MU - 0x03BD: 0xAA, # GREEK SMALL LETTER NU - 0x03BE: 0xAB, # GREEK SMALL LETTER XI - 0x03BF: 0xAC, # GREEK SMALL LETTER OMICRON - 0x03C0: 0xAD, # GREEK SMALL LETTER PI - 0x03C1: 0xAE, # GREEK SMALL LETTER RHO - 0x03C2: 0xBA, # GREEK SMALL LETTER FINAL SIGMA - 0x03C3: 0xAF, # GREEK SMALL LETTER SIGMA - 0x03C4: 0xBB, # GREEK SMALL LETTER TAU - 0x03C5: 0xBC, # GREEK SMALL LETTER UPSILON - 0x03C6: 0xBD, # GREEK SMALL LETTER PHI - 0x03C7: 0xBE, # GREEK SMALL LETTER CHI - 0x03C8: 0xBF, # GREEK SMALL LETTER PSI - 0x03C9: 0xCB, # GREEK SMALL LETTER OMEGA - 0x03CA: 0xB4, # GREEK SMALL LETTER IOTA WITH DIALYTIKA - 0x03CB: 0xB8, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA - 0x03CC: 0xB6, # GREEK SMALL LETTER OMICRON WITH TONOS - 0x03CD: 0xB7, # GREEK SMALL LETTER UPSILON WITH TONOS - 0x03CE: 0xB9, # GREEK SMALL LETTER OMEGA WITH TONOS - 0x2015: 0xCF, # HORIZONTAL BAR - 0x2018: 0xCE, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xDE, # RIGHT SINGLE QUOTATION MARK -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_1.py b/Lib/encodings/iso8859_1.py index b985585..71bc13f 100644 --- a/Lib/encodings/iso8859_1.py +++ b/Lib/encodings/iso8859_1.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xAA, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BA: 0xBA, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xD0, # LATIN CAPITAL LETTER ETH (Icelandic) - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xDE, # LATIN CAPITAL LETTER THORN (Icelandic) - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S (German) - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0xF0, # LATIN SMALL LETTER ETH (Icelandic) - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0xFE, # LATIN SMALL LETTER THORN (Icelandic) - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_10.py b/Lib/encodings/iso8859_10.py index 8588430..757e5c5 100644 --- a/Lib/encodings/iso8859_10.py +++ b/Lib/encodings/iso8859_10.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u0138' # 0xFF -> LATIN SMALL LETTER KRA ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A7: 0xA7, # SECTION SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xD0, # LATIN CAPITAL LETTER ETH (Icelandic) - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xDE, # LATIN CAPITAL LETTER THORN (Icelandic) - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S (German) - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0xF0, # LATIN SMALL LETTER ETH (Icelandic) - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0xFE, # LATIN SMALL LETTER THORN (Icelandic) - 0x0100: 0xC0, # LATIN CAPITAL LETTER A WITH MACRON - 0x0101: 0xE0, # LATIN SMALL LETTER A WITH MACRON - 0x0104: 0xA1, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xB1, # LATIN SMALL LETTER A WITH OGONEK - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x0110: 0xA9, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xB9, # LATIN SMALL LETTER D WITH STROKE - 0x0112: 0xA2, # LATIN CAPITAL LETTER E WITH MACRON - 0x0113: 0xB2, # LATIN SMALL LETTER E WITH MACRON - 0x0116: 0xCC, # LATIN CAPITAL LETTER E WITH DOT ABOVE - 0x0117: 0xEC, # LATIN SMALL LETTER E WITH DOT ABOVE - 0x0118: 0xCA, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xEA, # LATIN SMALL LETTER E WITH OGONEK - 0x0122: 0xA3, # LATIN CAPITAL LETTER G WITH CEDILLA - 0x0123: 0xB3, # LATIN SMALL LETTER G WITH CEDILLA - 0x0128: 0xA5, # LATIN CAPITAL LETTER I WITH TILDE - 0x0129: 0xB5, # LATIN SMALL LETTER I WITH TILDE - 0x012A: 0xA4, # LATIN CAPITAL LETTER I WITH MACRON - 0x012B: 0xB4, # LATIN SMALL LETTER I WITH MACRON - 0x012E: 0xC7, # LATIN CAPITAL LETTER I WITH OGONEK - 0x012F: 0xE7, # LATIN SMALL LETTER I WITH OGONEK - 0x0136: 0xA6, # LATIN CAPITAL LETTER K WITH CEDILLA - 0x0137: 0xB6, # LATIN SMALL LETTER K WITH CEDILLA - 0x0138: 0xFF, # LATIN SMALL LETTER KRA - 0x013B: 0xA8, # LATIN CAPITAL LETTER L WITH CEDILLA - 0x013C: 0xB8, # LATIN SMALL LETTER L WITH CEDILLA - 0x0145: 0xD1, # LATIN CAPITAL LETTER N WITH CEDILLA - 0x0146: 0xF1, # LATIN SMALL LETTER N WITH CEDILLA - 0x014A: 0xAF, # LATIN CAPITAL LETTER ENG - 0x014B: 0xBF, # LATIN SMALL LETTER ENG - 0x014C: 0xD2, # LATIN CAPITAL LETTER O WITH MACRON - 0x014D: 0xF2, # LATIN SMALL LETTER O WITH MACRON - 0x0160: 0xAA, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xBA, # LATIN SMALL LETTER S WITH CARON - 0x0166: 0xAB, # LATIN CAPITAL LETTER T WITH STROKE - 0x0167: 0xBB, # LATIN SMALL LETTER T WITH STROKE - 0x0168: 0xD7, # LATIN CAPITAL LETTER U WITH TILDE - 0x0169: 0xF7, # LATIN SMALL LETTER U WITH TILDE - 0x016A: 0xAE, # LATIN CAPITAL LETTER U WITH MACRON - 0x016B: 0xBE, # LATIN SMALL LETTER U WITH MACRON - 0x0172: 0xD9, # LATIN CAPITAL LETTER U WITH OGONEK - 0x0173: 0xF9, # LATIN SMALL LETTER U WITH OGONEK - 0x017D: 0xAC, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xBC, # LATIN SMALL LETTER Z WITH CARON - 0x2015: 0xBD, # HORIZONTAL BAR -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_11.py b/Lib/encodings/iso8859_11.py index fffe692..27ece8d 100644 --- a/Lib/encodings/iso8859_11.py +++ b/Lib/encodings/iso8859_11.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,255 +303,5 @@ decoding_table = ( u'\ufffe' ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x0E01: 0xA1, # THAI CHARACTER KO KAI - 0x0E02: 0xA2, # THAI CHARACTER KHO KHAI - 0x0E03: 0xA3, # THAI CHARACTER KHO KHUAT - 0x0E04: 0xA4, # THAI CHARACTER KHO KHWAI - 0x0E05: 0xA5, # THAI CHARACTER KHO KHON - 0x0E06: 0xA6, # THAI CHARACTER KHO RAKHANG - 0x0E07: 0xA7, # THAI CHARACTER NGO NGU - 0x0E08: 0xA8, # THAI CHARACTER CHO CHAN - 0x0E09: 0xA9, # THAI CHARACTER CHO CHING - 0x0E0A: 0xAA, # THAI CHARACTER CHO CHANG - 0x0E0B: 0xAB, # THAI CHARACTER SO SO - 0x0E0C: 0xAC, # THAI CHARACTER CHO CHOE - 0x0E0D: 0xAD, # THAI CHARACTER YO YING - 0x0E0E: 0xAE, # THAI CHARACTER DO CHADA - 0x0E0F: 0xAF, # THAI CHARACTER TO PATAK - 0x0E10: 0xB0, # THAI CHARACTER THO THAN - 0x0E11: 0xB1, # THAI CHARACTER THO NANGMONTHO - 0x0E12: 0xB2, # THAI CHARACTER THO PHUTHAO - 0x0E13: 0xB3, # THAI CHARACTER NO NEN - 0x0E14: 0xB4, # THAI CHARACTER DO DEK - 0x0E15: 0xB5, # THAI CHARACTER TO TAO - 0x0E16: 0xB6, # THAI CHARACTER THO THUNG - 0x0E17: 0xB7, # THAI CHARACTER THO THAHAN - 0x0E18: 0xB8, # THAI CHARACTER THO THONG - 0x0E19: 0xB9, # THAI CHARACTER NO NU - 0x0E1A: 0xBA, # THAI CHARACTER BO BAIMAI - 0x0E1B: 0xBB, # THAI CHARACTER PO PLA - 0x0E1C: 0xBC, # THAI CHARACTER PHO PHUNG - 0x0E1D: 0xBD, # THAI CHARACTER FO FA - 0x0E1E: 0xBE, # THAI CHARACTER PHO PHAN - 0x0E1F: 0xBF, # THAI CHARACTER FO FAN - 0x0E20: 0xC0, # THAI CHARACTER PHO SAMPHAO - 0x0E21: 0xC1, # THAI CHARACTER MO MA - 0x0E22: 0xC2, # THAI CHARACTER YO YAK - 0x0E23: 0xC3, # THAI CHARACTER RO RUA - 0x0E24: 0xC4, # THAI CHARACTER RU - 0x0E25: 0xC5, # THAI CHARACTER LO LING - 0x0E26: 0xC6, # THAI CHARACTER LU - 0x0E27: 0xC7, # THAI CHARACTER WO WAEN - 0x0E28: 0xC8, # THAI CHARACTER SO SALA - 0x0E29: 0xC9, # THAI CHARACTER SO RUSI - 0x0E2A: 0xCA, # THAI CHARACTER SO SUA - 0x0E2B: 0xCB, # THAI CHARACTER HO HIP - 0x0E2C: 0xCC, # THAI CHARACTER LO CHULA - 0x0E2D: 0xCD, # THAI CHARACTER O ANG - 0x0E2E: 0xCE, # THAI CHARACTER HO NOKHUK - 0x0E2F: 0xCF, # THAI CHARACTER PAIYANNOI - 0x0E30: 0xD0, # THAI CHARACTER SARA A - 0x0E31: 0xD1, # THAI CHARACTER MAI HAN-AKAT - 0x0E32: 0xD2, # THAI CHARACTER SARA AA - 0x0E33: 0xD3, # THAI CHARACTER SARA AM - 0x0E34: 0xD4, # THAI CHARACTER SARA I - 0x0E35: 0xD5, # THAI CHARACTER SARA II - 0x0E36: 0xD6, # THAI CHARACTER SARA UE - 0x0E37: 0xD7, # THAI CHARACTER SARA UEE - 0x0E38: 0xD8, # THAI CHARACTER SARA U - 0x0E39: 0xD9, # THAI CHARACTER SARA UU - 0x0E3A: 0xDA, # THAI CHARACTER PHINTHU - 0x0E3F: 0xDF, # THAI CURRENCY SYMBOL BAHT - 0x0E40: 0xE0, # THAI CHARACTER SARA E - 0x0E41: 0xE1, # THAI CHARACTER SARA AE - 0x0E42: 0xE2, # THAI CHARACTER SARA O - 0x0E43: 0xE3, # THAI CHARACTER SARA AI MAIMUAN - 0x0E44: 0xE4, # THAI CHARACTER SARA AI MAIMALAI - 0x0E45: 0xE5, # THAI CHARACTER LAKKHANGYAO - 0x0E46: 0xE6, # THAI CHARACTER MAIYAMOK - 0x0E47: 0xE7, # THAI CHARACTER MAITAIKHU - 0x0E48: 0xE8, # THAI CHARACTER MAI EK - 0x0E49: 0xE9, # THAI CHARACTER MAI THO - 0x0E4A: 0xEA, # THAI CHARACTER MAI TRI - 0x0E4B: 0xEB, # THAI CHARACTER MAI CHATTAWA - 0x0E4C: 0xEC, # THAI CHARACTER THANTHAKHAT - 0x0E4D: 0xED, # THAI CHARACTER NIKHAHIT - 0x0E4E: 0xEE, # THAI CHARACTER YAMAKKAN - 0x0E4F: 0xEF, # THAI CHARACTER FONGMAN - 0x0E50: 0xF0, # THAI DIGIT ZERO - 0x0E51: 0xF1, # THAI DIGIT ONE - 0x0E52: 0xF2, # THAI DIGIT TWO - 0x0E53: 0xF3, # THAI DIGIT THREE - 0x0E54: 0xF4, # THAI DIGIT FOUR - 0x0E55: 0xF5, # THAI DIGIT FIVE - 0x0E56: 0xF6, # THAI DIGIT SIX - 0x0E57: 0xF7, # THAI DIGIT SEVEN - 0x0E58: 0xF8, # THAI DIGIT EIGHT - 0x0E59: 0xF9, # THAI DIGIT NINE - 0x0E5A: 0xFA, # THAI CHARACTER ANGKHANKHU - 0x0E5B: 0xFB, # THAI CHARACTER KHOMUT -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_13.py b/Lib/encodings/iso8859_13.py index a890580..71adb5c 100644 --- a/Lib/encodings/iso8859_13.py +++ b/Lib/encodings/iso8859_13.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u2019' # 0xFF -> RIGHT SINGLE QUOTATION MARK ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xAF, # LATIN CAPITAL LETTER AE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xA8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S (German) - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xBF, # LATIN SMALL LETTER AE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xB8, # LATIN SMALL LETTER O WITH STROKE - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0100: 0xC2, # LATIN CAPITAL LETTER A WITH MACRON - 0x0101: 0xE2, # LATIN SMALL LETTER A WITH MACRON - 0x0104: 0xC0, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xE0, # LATIN SMALL LETTER A WITH OGONEK - 0x0106: 0xC3, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0xE3, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x0112: 0xC7, # LATIN CAPITAL LETTER E WITH MACRON - 0x0113: 0xE7, # LATIN SMALL LETTER E WITH MACRON - 0x0116: 0xCB, # LATIN CAPITAL LETTER E WITH DOT ABOVE - 0x0117: 0xEB, # LATIN SMALL LETTER E WITH DOT ABOVE - 0x0118: 0xC6, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xE6, # LATIN SMALL LETTER E WITH OGONEK - 0x0122: 0xCC, # LATIN CAPITAL LETTER G WITH CEDILLA - 0x0123: 0xEC, # LATIN SMALL LETTER G WITH CEDILLA - 0x012A: 0xCE, # LATIN CAPITAL LETTER I WITH MACRON - 0x012B: 0xEE, # LATIN SMALL LETTER I WITH MACRON - 0x012E: 0xC1, # LATIN CAPITAL LETTER I WITH OGONEK - 0x012F: 0xE1, # LATIN SMALL LETTER I WITH OGONEK - 0x0136: 0xCD, # LATIN CAPITAL LETTER K WITH CEDILLA - 0x0137: 0xED, # LATIN SMALL LETTER K WITH CEDILLA - 0x013B: 0xCF, # LATIN CAPITAL LETTER L WITH CEDILLA - 0x013C: 0xEF, # LATIN SMALL LETTER L WITH CEDILLA - 0x0141: 0xD9, # LATIN CAPITAL LETTER L WITH STROKE - 0x0142: 0xF9, # LATIN SMALL LETTER L WITH STROKE - 0x0143: 0xD1, # LATIN CAPITAL LETTER N WITH ACUTE - 0x0144: 0xF1, # LATIN SMALL LETTER N WITH ACUTE - 0x0145: 0xD2, # LATIN CAPITAL LETTER N WITH CEDILLA - 0x0146: 0xF2, # LATIN SMALL LETTER N WITH CEDILLA - 0x014C: 0xD4, # LATIN CAPITAL LETTER O WITH MACRON - 0x014D: 0xF4, # LATIN SMALL LETTER O WITH MACRON - 0x0156: 0xAA, # LATIN CAPITAL LETTER R WITH CEDILLA - 0x0157: 0xBA, # LATIN SMALL LETTER R WITH CEDILLA - 0x015A: 0xDA, # LATIN CAPITAL LETTER S WITH ACUTE - 0x015B: 0xFA, # LATIN SMALL LETTER S WITH ACUTE - 0x0160: 0xD0, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xF0, # LATIN SMALL LETTER S WITH CARON - 0x016A: 0xDB, # LATIN CAPITAL LETTER U WITH MACRON - 0x016B: 0xFB, # LATIN SMALL LETTER U WITH MACRON - 0x0172: 0xD8, # LATIN CAPITAL LETTER U WITH OGONEK - 0x0173: 0xF8, # LATIN SMALL LETTER U WITH OGONEK - 0x0179: 0xCA, # LATIN CAPITAL LETTER Z WITH ACUTE - 0x017A: 0xEA, # LATIN SMALL LETTER Z WITH ACUTE - 0x017B: 0xDD, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xFD, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x017D: 0xDE, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xFE, # LATIN SMALL LETTER Z WITH CARON - 0x2019: 0xFF, # RIGHT SINGLE QUOTATION MARK - 0x201C: 0xB4, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xA1, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xA5, # DOUBLE LOW-9 QUOTATION MARK -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_14.py b/Lib/encodings/iso8859_14.py index afa458c..56843d5 100644 --- a/Lib/encodings/iso8859_14.py +++ b/Lib/encodings/iso8859_14.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A3: 0xA3, # POUND SIGN - 0x00A7: 0xA7, # SECTION SIGN - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x010A: 0xA4, # LATIN CAPITAL LETTER C WITH DOT ABOVE - 0x010B: 0xA5, # LATIN SMALL LETTER C WITH DOT ABOVE - 0x0120: 0xB2, # LATIN CAPITAL LETTER G WITH DOT ABOVE - 0x0121: 0xB3, # LATIN SMALL LETTER G WITH DOT ABOVE - 0x0174: 0xD0, # LATIN CAPITAL LETTER W WITH CIRCUMFLEX - 0x0175: 0xF0, # LATIN SMALL LETTER W WITH CIRCUMFLEX - 0x0176: 0xDE, # LATIN CAPITAL LETTER Y WITH CIRCUMFLEX - 0x0177: 0xFE, # LATIN SMALL LETTER Y WITH CIRCUMFLEX - 0x0178: 0xAF, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x1E02: 0xA1, # LATIN CAPITAL LETTER B WITH DOT ABOVE - 0x1E03: 0xA2, # LATIN SMALL LETTER B WITH DOT ABOVE - 0x1E0A: 0xA6, # LATIN CAPITAL LETTER D WITH DOT ABOVE - 0x1E0B: 0xAB, # LATIN SMALL LETTER D WITH DOT ABOVE - 0x1E1E: 0xB0, # LATIN CAPITAL LETTER F WITH DOT ABOVE - 0x1E1F: 0xB1, # LATIN SMALL LETTER F WITH DOT ABOVE - 0x1E40: 0xB4, # LATIN CAPITAL LETTER M WITH DOT ABOVE - 0x1E41: 0xB5, # LATIN SMALL LETTER M WITH DOT ABOVE - 0x1E56: 0xB7, # LATIN CAPITAL LETTER P WITH DOT ABOVE - 0x1E57: 0xB9, # LATIN SMALL LETTER P WITH DOT ABOVE - 0x1E60: 0xBB, # LATIN CAPITAL LETTER S WITH DOT ABOVE - 0x1E61: 0xBF, # LATIN SMALL LETTER S WITH DOT ABOVE - 0x1E6A: 0xD7, # LATIN CAPITAL LETTER T WITH DOT ABOVE - 0x1E6B: 0xF7, # LATIN SMALL LETTER T WITH DOT ABOVE - 0x1E80: 0xA8, # LATIN CAPITAL LETTER W WITH GRAVE - 0x1E81: 0xB8, # LATIN SMALL LETTER W WITH GRAVE - 0x1E82: 0xAA, # LATIN CAPITAL LETTER W WITH ACUTE - 0x1E83: 0xBA, # LATIN SMALL LETTER W WITH ACUTE - 0x1E84: 0xBD, # LATIN CAPITAL LETTER W WITH DIAERESIS - 0x1E85: 0xBE, # LATIN SMALL LETTER W WITH DIAERESIS - 0x1EF2: 0xAC, # LATIN CAPITAL LETTER Y WITH GRAVE - 0x1EF3: 0xBC, # LATIN SMALL LETTER Y WITH GRAVE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_15.py b/Lib/encodings/iso8859_15.py index 4a8334e..13b140c 100644 --- a/Lib/encodings/iso8859_15.py +++ b/Lib/encodings/iso8859_15.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A7: 0xA7, # SECTION SIGN - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xAA, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BA: 0xBA, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xD0, # LATIN CAPITAL LETTER ETH - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xDE, # LATIN CAPITAL LETTER THORN - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0xF0, # LATIN SMALL LETTER ETH - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0xFE, # LATIN SMALL LETTER THORN - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0152: 0xBC, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xBD, # LATIN SMALL LIGATURE OE - 0x0160: 0xA6, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xA8, # LATIN SMALL LETTER S WITH CARON - 0x0178: 0xBE, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x017D: 0xB4, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xB8, # LATIN SMALL LETTER Z WITH CARON - 0x20AC: 0xA4, # EURO SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_16.py b/Lib/encodings/iso8859_16.py index aeebfb6..00b9ac8 100644 --- a/Lib/encodings/iso8859_16.py +++ b/Lib/encodings/iso8859_16.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A7: 0xA7, # SECTION SIGN - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0102: 0xC3, # LATIN CAPITAL LETTER A WITH BREVE - 0x0103: 0xE3, # LATIN SMALL LETTER A WITH BREVE - 0x0104: 0xA1, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xA2, # LATIN SMALL LETTER A WITH OGONEK - 0x0106: 0xC5, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0xE5, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0xB2, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xB9, # LATIN SMALL LETTER C WITH CARON - 0x0110: 0xD0, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xF0, # LATIN SMALL LETTER D WITH STROKE - 0x0118: 0xDD, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xFD, # LATIN SMALL LETTER E WITH OGONEK - 0x0141: 0xA3, # LATIN CAPITAL LETTER L WITH STROKE - 0x0142: 0xB3, # LATIN SMALL LETTER L WITH STROKE - 0x0143: 0xD1, # LATIN CAPITAL LETTER N WITH ACUTE - 0x0144: 0xF1, # LATIN SMALL LETTER N WITH ACUTE - 0x0150: 0xD5, # LATIN CAPITAL LETTER O WITH DOUBLE ACUTE - 0x0151: 0xF5, # LATIN SMALL LETTER O WITH DOUBLE ACUTE - 0x0152: 0xBC, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xBD, # LATIN SMALL LIGATURE OE - 0x015A: 0xD7, # LATIN CAPITAL LETTER S WITH ACUTE - 0x015B: 0xF7, # LATIN SMALL LETTER S WITH ACUTE - 0x0160: 0xA6, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xA8, # LATIN SMALL LETTER S WITH CARON - 0x0170: 0xD8, # LATIN CAPITAL LETTER U WITH DOUBLE ACUTE - 0x0171: 0xF8, # LATIN SMALL LETTER U WITH DOUBLE ACUTE - 0x0178: 0xBE, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0179: 0xAC, # LATIN CAPITAL LETTER Z WITH ACUTE - 0x017A: 0xAE, # LATIN SMALL LETTER Z WITH ACUTE - 0x017B: 0xAF, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xBF, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x017D: 0xB4, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xB8, # LATIN SMALL LETTER Z WITH CARON - 0x0218: 0xAA, # LATIN CAPITAL LETTER S WITH COMMA BELOW - 0x0219: 0xBA, # LATIN SMALL LETTER S WITH COMMA BELOW - 0x021A: 0xDE, # LATIN CAPITAL LETTER T WITH COMMA BELOW - 0x021B: 0xFE, # LATIN SMALL LETTER T WITH COMMA BELOW - 0x201D: 0xB5, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xA5, # DOUBLE LOW-9 QUOTATION MARK - 0x20AC: 0xA4, # EURO SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_2.py b/Lib/encodings/iso8859_2.py index 845f322..38e91d8 100644 --- a/Lib/encodings/iso8859_2.py +++ b/Lib/encodings/iso8859_2.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02d9' # 0xFF -> DOT ABOVE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B8: 0xB8, # CEDILLA - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xDD, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xFD, # LATIN SMALL LETTER Y WITH ACUTE - 0x0102: 0xC3, # LATIN CAPITAL LETTER A WITH BREVE - 0x0103: 0xE3, # LATIN SMALL LETTER A WITH BREVE - 0x0104: 0xA1, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xB1, # LATIN SMALL LETTER A WITH OGONEK - 0x0106: 0xC6, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0xE6, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x010E: 0xCF, # LATIN CAPITAL LETTER D WITH CARON - 0x010F: 0xEF, # LATIN SMALL LETTER D WITH CARON - 0x0110: 0xD0, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xF0, # LATIN SMALL LETTER D WITH STROKE - 0x0118: 0xCA, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xEA, # LATIN SMALL LETTER E WITH OGONEK - 0x011A: 0xCC, # LATIN CAPITAL LETTER E WITH CARON - 0x011B: 0xEC, # LATIN SMALL LETTER E WITH CARON - 0x0139: 0xC5, # LATIN CAPITAL LETTER L WITH ACUTE - 0x013A: 0xE5, # LATIN SMALL LETTER L WITH ACUTE - 0x013D: 0xA5, # LATIN CAPITAL LETTER L WITH CARON - 0x013E: 0xB5, # LATIN SMALL LETTER L WITH CARON - 0x0141: 0xA3, # LATIN CAPITAL LETTER L WITH STROKE - 0x0142: 0xB3, # LATIN SMALL LETTER L WITH STROKE - 0x0143: 0xD1, # LATIN CAPITAL LETTER N WITH ACUTE - 0x0144: 0xF1, # LATIN SMALL LETTER N WITH ACUTE - 0x0147: 0xD2, # LATIN CAPITAL LETTER N WITH CARON - 0x0148: 0xF2, # LATIN SMALL LETTER N WITH CARON - 0x0150: 0xD5, # LATIN CAPITAL LETTER O WITH DOUBLE ACUTE - 0x0151: 0xF5, # LATIN SMALL LETTER O WITH DOUBLE ACUTE - 0x0154: 0xC0, # LATIN CAPITAL LETTER R WITH ACUTE - 0x0155: 0xE0, # LATIN SMALL LETTER R WITH ACUTE - 0x0158: 0xD8, # LATIN CAPITAL LETTER R WITH CARON - 0x0159: 0xF8, # LATIN SMALL LETTER R WITH CARON - 0x015A: 0xA6, # LATIN CAPITAL LETTER S WITH ACUTE - 0x015B: 0xB6, # LATIN SMALL LETTER S WITH ACUTE - 0x015E: 0xAA, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0xBA, # LATIN SMALL LETTER S WITH CEDILLA - 0x0160: 0xA9, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xB9, # LATIN SMALL LETTER S WITH CARON - 0x0162: 0xDE, # LATIN CAPITAL LETTER T WITH CEDILLA - 0x0163: 0xFE, # LATIN SMALL LETTER T WITH CEDILLA - 0x0164: 0xAB, # LATIN CAPITAL LETTER T WITH CARON - 0x0165: 0xBB, # LATIN SMALL LETTER T WITH CARON - 0x016E: 0xD9, # LATIN CAPITAL LETTER U WITH RING ABOVE - 0x016F: 0xF9, # LATIN SMALL LETTER U WITH RING ABOVE - 0x0170: 0xDB, # LATIN CAPITAL LETTER U WITH DOUBLE ACUTE - 0x0171: 0xFB, # LATIN SMALL LETTER U WITH DOUBLE ACUTE - 0x0179: 0xAC, # LATIN CAPITAL LETTER Z WITH ACUTE - 0x017A: 0xBC, # LATIN SMALL LETTER Z WITH ACUTE - 0x017B: 0xAF, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xBF, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x017D: 0xAE, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xBE, # LATIN SMALL LETTER Z WITH CARON - 0x02C7: 0xB7, # CARON - 0x02D8: 0xA2, # BREVE - 0x02D9: 0xFF, # DOT ABOVE - 0x02DB: 0xB2, # OGONEK - 0x02DD: 0xBD, # DOUBLE ACUTE ACCENT -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_3.py b/Lib/encodings/iso8859_3.py index fbc8775..23daafd 100644 --- a/Lib/encodings/iso8859_3.py +++ b/Lib/encodings/iso8859_3.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,256 +303,5 @@ decoding_table = ( u'\u02d9' # 0xFF -> DOT ABOVE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0108: 0xC6, # LATIN CAPITAL LETTER C WITH CIRCUMFLEX - 0x0109: 0xE6, # LATIN SMALL LETTER C WITH CIRCUMFLEX - 0x010A: 0xC5, # LATIN CAPITAL LETTER C WITH DOT ABOVE - 0x010B: 0xE5, # LATIN SMALL LETTER C WITH DOT ABOVE - 0x011C: 0xD8, # LATIN CAPITAL LETTER G WITH CIRCUMFLEX - 0x011D: 0xF8, # LATIN SMALL LETTER G WITH CIRCUMFLEX - 0x011E: 0xAB, # LATIN CAPITAL LETTER G WITH BREVE - 0x011F: 0xBB, # LATIN SMALL LETTER G WITH BREVE - 0x0120: 0xD5, # LATIN CAPITAL LETTER G WITH DOT ABOVE - 0x0121: 0xF5, # LATIN SMALL LETTER G WITH DOT ABOVE - 0x0124: 0xA6, # LATIN CAPITAL LETTER H WITH CIRCUMFLEX - 0x0125: 0xB6, # LATIN SMALL LETTER H WITH CIRCUMFLEX - 0x0126: 0xA1, # LATIN CAPITAL LETTER H WITH STROKE - 0x0127: 0xB1, # LATIN SMALL LETTER H WITH STROKE - 0x0130: 0xA9, # LATIN CAPITAL LETTER I WITH DOT ABOVE - 0x0131: 0xB9, # LATIN SMALL LETTER DOTLESS I - 0x0134: 0xAC, # LATIN CAPITAL LETTER J WITH CIRCUMFLEX - 0x0135: 0xBC, # LATIN SMALL LETTER J WITH CIRCUMFLEX - 0x015C: 0xDE, # LATIN CAPITAL LETTER S WITH CIRCUMFLEX - 0x015D: 0xFE, # LATIN SMALL LETTER S WITH CIRCUMFLEX - 0x015E: 0xAA, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0xBA, # LATIN SMALL LETTER S WITH CEDILLA - 0x016C: 0xDD, # LATIN CAPITAL LETTER U WITH BREVE - 0x016D: 0xFD, # LATIN SMALL LETTER U WITH BREVE - 0x017B: 0xAF, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xBF, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x02D8: 0xA2, # BREVE - 0x02D9: 0xFF, # DOT ABOVE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_4.py b/Lib/encodings/iso8859_4.py index e705954..c8e03b5 100644 --- a/Lib/encodings/iso8859_4.py +++ b/Lib/encodings/iso8859_4.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02d9' # 0xFF -> DOT ABOVE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B8: 0xB8, # CEDILLA - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0100: 0xC0, # LATIN CAPITAL LETTER A WITH MACRON - 0x0101: 0xE0, # LATIN SMALL LETTER A WITH MACRON - 0x0104: 0xA1, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0xB1, # LATIN SMALL LETTER A WITH OGONEK - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x0110: 0xD0, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xF0, # LATIN SMALL LETTER D WITH STROKE - 0x0112: 0xAA, # LATIN CAPITAL LETTER E WITH MACRON - 0x0113: 0xBA, # LATIN SMALL LETTER E WITH MACRON - 0x0116: 0xCC, # LATIN CAPITAL LETTER E WITH DOT ABOVE - 0x0117: 0xEC, # LATIN SMALL LETTER E WITH DOT ABOVE - 0x0118: 0xCA, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xEA, # LATIN SMALL LETTER E WITH OGONEK - 0x0122: 0xAB, # LATIN CAPITAL LETTER G WITH CEDILLA - 0x0123: 0xBB, # LATIN SMALL LETTER G WITH CEDILLA - 0x0128: 0xA5, # LATIN CAPITAL LETTER I WITH TILDE - 0x0129: 0xB5, # LATIN SMALL LETTER I WITH TILDE - 0x012A: 0xCF, # LATIN CAPITAL LETTER I WITH MACRON - 0x012B: 0xEF, # LATIN SMALL LETTER I WITH MACRON - 0x012E: 0xC7, # LATIN CAPITAL LETTER I WITH OGONEK - 0x012F: 0xE7, # LATIN SMALL LETTER I WITH OGONEK - 0x0136: 0xD3, # LATIN CAPITAL LETTER K WITH CEDILLA - 0x0137: 0xF3, # LATIN SMALL LETTER K WITH CEDILLA - 0x0138: 0xA2, # LATIN SMALL LETTER KRA - 0x013B: 0xA6, # LATIN CAPITAL LETTER L WITH CEDILLA - 0x013C: 0xB6, # LATIN SMALL LETTER L WITH CEDILLA - 0x0145: 0xD1, # LATIN CAPITAL LETTER N WITH CEDILLA - 0x0146: 0xF1, # LATIN SMALL LETTER N WITH CEDILLA - 0x014A: 0xBD, # LATIN CAPITAL LETTER ENG - 0x014B: 0xBF, # LATIN SMALL LETTER ENG - 0x014C: 0xD2, # LATIN CAPITAL LETTER O WITH MACRON - 0x014D: 0xF2, # LATIN SMALL LETTER O WITH MACRON - 0x0156: 0xA3, # LATIN CAPITAL LETTER R WITH CEDILLA - 0x0157: 0xB3, # LATIN SMALL LETTER R WITH CEDILLA - 0x0160: 0xA9, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xB9, # LATIN SMALL LETTER S WITH CARON - 0x0166: 0xAC, # LATIN CAPITAL LETTER T WITH STROKE - 0x0167: 0xBC, # LATIN SMALL LETTER T WITH STROKE - 0x0168: 0xDD, # LATIN CAPITAL LETTER U WITH TILDE - 0x0169: 0xFD, # LATIN SMALL LETTER U WITH TILDE - 0x016A: 0xDE, # LATIN CAPITAL LETTER U WITH MACRON - 0x016B: 0xFE, # LATIN SMALL LETTER U WITH MACRON - 0x0172: 0xD9, # LATIN CAPITAL LETTER U WITH OGONEK - 0x0173: 0xF9, # LATIN SMALL LETTER U WITH OGONEK - 0x017D: 0xAE, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xBE, # LATIN SMALL LETTER Z WITH CARON - 0x02C7: 0xB7, # CARON - 0x02D9: 0xFF, # DOT ABOVE - 0x02DB: 0xB2, # OGONEK -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_5.py b/Lib/encodings/iso8859_5.py index 93a4e90..c01cd1c 100644 --- a/Lib/encodings/iso8859_5.py +++ b/Lib/encodings/iso8859_5.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u045f' # 0xFF -> CYRILLIC SMALL LETTER DZHE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A7: 0xFD, # SECTION SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x0401: 0xA1, # CYRILLIC CAPITAL LETTER IO - 0x0402: 0xA2, # CYRILLIC CAPITAL LETTER DJE - 0x0403: 0xA3, # CYRILLIC CAPITAL LETTER GJE - 0x0404: 0xA4, # CYRILLIC CAPITAL LETTER UKRAINIAN IE - 0x0405: 0xA5, # CYRILLIC CAPITAL LETTER DZE - 0x0406: 0xA6, # CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0407: 0xA7, # CYRILLIC CAPITAL LETTER YI - 0x0408: 0xA8, # CYRILLIC CAPITAL LETTER JE - 0x0409: 0xA9, # CYRILLIC CAPITAL LETTER LJE - 0x040A: 0xAA, # CYRILLIC CAPITAL LETTER NJE - 0x040B: 0xAB, # CYRILLIC CAPITAL LETTER TSHE - 0x040C: 0xAC, # CYRILLIC CAPITAL LETTER KJE - 0x040E: 0xAE, # CYRILLIC CAPITAL LETTER SHORT U - 0x040F: 0xAF, # CYRILLIC CAPITAL LETTER DZHE - 0x0410: 0xB0, # CYRILLIC CAPITAL LETTER A - 0x0411: 0xB1, # CYRILLIC CAPITAL LETTER BE - 0x0412: 0xB2, # CYRILLIC CAPITAL LETTER VE - 0x0413: 0xB3, # CYRILLIC CAPITAL LETTER GHE - 0x0414: 0xB4, # CYRILLIC CAPITAL LETTER DE - 0x0415: 0xB5, # CYRILLIC CAPITAL LETTER IE - 0x0416: 0xB6, # CYRILLIC CAPITAL LETTER ZHE - 0x0417: 0xB7, # CYRILLIC CAPITAL LETTER ZE - 0x0418: 0xB8, # CYRILLIC CAPITAL LETTER I - 0x0419: 0xB9, # CYRILLIC CAPITAL LETTER SHORT I - 0x041A: 0xBA, # CYRILLIC CAPITAL LETTER KA - 0x041B: 0xBB, # CYRILLIC CAPITAL LETTER EL - 0x041C: 0xBC, # CYRILLIC CAPITAL LETTER EM - 0x041D: 0xBD, # CYRILLIC CAPITAL LETTER EN - 0x041E: 0xBE, # CYRILLIC CAPITAL LETTER O - 0x041F: 0xBF, # CYRILLIC CAPITAL LETTER PE - 0x0420: 0xC0, # CYRILLIC CAPITAL LETTER ER - 0x0421: 0xC1, # CYRILLIC CAPITAL LETTER ES - 0x0422: 0xC2, # CYRILLIC CAPITAL LETTER TE - 0x0423: 0xC3, # CYRILLIC CAPITAL LETTER U - 0x0424: 0xC4, # CYRILLIC CAPITAL LETTER EF - 0x0425: 0xC5, # CYRILLIC CAPITAL LETTER HA - 0x0426: 0xC6, # CYRILLIC CAPITAL LETTER TSE - 0x0427: 0xC7, # CYRILLIC CAPITAL LETTER CHE - 0x0428: 0xC8, # CYRILLIC CAPITAL LETTER SHA - 0x0429: 0xC9, # CYRILLIC CAPITAL LETTER SHCHA - 0x042A: 0xCA, # CYRILLIC CAPITAL LETTER HARD SIGN - 0x042B: 0xCB, # CYRILLIC CAPITAL LETTER YERU - 0x042C: 0xCC, # CYRILLIC CAPITAL LETTER SOFT SIGN - 0x042D: 0xCD, # CYRILLIC CAPITAL LETTER E - 0x042E: 0xCE, # CYRILLIC CAPITAL LETTER YU - 0x042F: 0xCF, # CYRILLIC CAPITAL LETTER YA - 0x0430: 0xD0, # CYRILLIC SMALL LETTER A - 0x0431: 0xD1, # CYRILLIC SMALL LETTER BE - 0x0432: 0xD2, # CYRILLIC SMALL LETTER VE - 0x0433: 0xD3, # CYRILLIC SMALL LETTER GHE - 0x0434: 0xD4, # CYRILLIC SMALL LETTER DE - 0x0435: 0xD5, # CYRILLIC SMALL LETTER IE - 0x0436: 0xD6, # CYRILLIC SMALL LETTER ZHE - 0x0437: 0xD7, # CYRILLIC SMALL LETTER ZE - 0x0438: 0xD8, # CYRILLIC SMALL LETTER I - 0x0439: 0xD9, # CYRILLIC SMALL LETTER SHORT I - 0x043A: 0xDA, # CYRILLIC SMALL LETTER KA - 0x043B: 0xDB, # CYRILLIC SMALL LETTER EL - 0x043C: 0xDC, # CYRILLIC SMALL LETTER EM - 0x043D: 0xDD, # CYRILLIC SMALL LETTER EN - 0x043E: 0xDE, # CYRILLIC SMALL LETTER O - 0x043F: 0xDF, # CYRILLIC SMALL LETTER PE - 0x0440: 0xE0, # CYRILLIC SMALL LETTER ER - 0x0441: 0xE1, # CYRILLIC SMALL LETTER ES - 0x0442: 0xE2, # CYRILLIC SMALL LETTER TE - 0x0443: 0xE3, # CYRILLIC SMALL LETTER U - 0x0444: 0xE4, # CYRILLIC SMALL LETTER EF - 0x0445: 0xE5, # CYRILLIC SMALL LETTER HA - 0x0446: 0xE6, # CYRILLIC SMALL LETTER TSE - 0x0447: 0xE7, # CYRILLIC SMALL LETTER CHE - 0x0448: 0xE8, # CYRILLIC SMALL LETTER SHA - 0x0449: 0xE9, # CYRILLIC SMALL LETTER SHCHA - 0x044A: 0xEA, # CYRILLIC SMALL LETTER HARD SIGN - 0x044B: 0xEB, # CYRILLIC SMALL LETTER YERU - 0x044C: 0xEC, # CYRILLIC SMALL LETTER SOFT SIGN - 0x044D: 0xED, # CYRILLIC SMALL LETTER E - 0x044E: 0xEE, # CYRILLIC SMALL LETTER YU - 0x044F: 0xEF, # CYRILLIC SMALL LETTER YA - 0x0451: 0xF1, # CYRILLIC SMALL LETTER IO - 0x0452: 0xF2, # CYRILLIC SMALL LETTER DJE - 0x0453: 0xF3, # CYRILLIC SMALL LETTER GJE - 0x0454: 0xF4, # CYRILLIC SMALL LETTER UKRAINIAN IE - 0x0455: 0xF5, # CYRILLIC SMALL LETTER DZE - 0x0456: 0xF6, # CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0457: 0xF7, # CYRILLIC SMALL LETTER YI - 0x0458: 0xF8, # CYRILLIC SMALL LETTER JE - 0x0459: 0xF9, # CYRILLIC SMALL LETTER LJE - 0x045A: 0xFA, # CYRILLIC SMALL LETTER NJE - 0x045B: 0xFB, # CYRILLIC SMALL LETTER TSHE - 0x045C: 0xFC, # CYRILLIC SMALL LETTER KJE - 0x045E: 0xFE, # CYRILLIC SMALL LETTER SHORT U - 0x045F: 0xFF, # CYRILLIC SMALL LETTER DZHE - 0x2116: 0xF0, # NUMERO SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_6.py b/Lib/encodings/iso8859_6.py index f911cc4..16c34a3 100644 --- a/Lib/encodings/iso8859_6.py +++ b/Lib/encodings/iso8859_6.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,218 +303,5 @@ decoding_table = ( u'\ufffe' ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x060C: 0xAC, # ARABIC COMMA - 0x061B: 0xBB, # ARABIC SEMICOLON - 0x061F: 0xBF, # ARABIC QUESTION MARK - 0x0621: 0xC1, # ARABIC LETTER HAMZA - 0x0622: 0xC2, # ARABIC LETTER ALEF WITH MADDA ABOVE - 0x0623: 0xC3, # ARABIC LETTER ALEF WITH HAMZA ABOVE - 0x0624: 0xC4, # ARABIC LETTER WAW WITH HAMZA ABOVE - 0x0625: 0xC5, # ARABIC LETTER ALEF WITH HAMZA BELOW - 0x0626: 0xC6, # ARABIC LETTER YEH WITH HAMZA ABOVE - 0x0627: 0xC7, # ARABIC LETTER ALEF - 0x0628: 0xC8, # ARABIC LETTER BEH - 0x0629: 0xC9, # ARABIC LETTER TEH MARBUTA - 0x062A: 0xCA, # ARABIC LETTER TEH - 0x062B: 0xCB, # ARABIC LETTER THEH - 0x062C: 0xCC, # ARABIC LETTER JEEM - 0x062D: 0xCD, # ARABIC LETTER HAH - 0x062E: 0xCE, # ARABIC LETTER KHAH - 0x062F: 0xCF, # ARABIC LETTER DAL - 0x0630: 0xD0, # ARABIC LETTER THAL - 0x0631: 0xD1, # ARABIC LETTER REH - 0x0632: 0xD2, # ARABIC LETTER ZAIN - 0x0633: 0xD3, # ARABIC LETTER SEEN - 0x0634: 0xD4, # ARABIC LETTER SHEEN - 0x0635: 0xD5, # ARABIC LETTER SAD - 0x0636: 0xD6, # ARABIC LETTER DAD - 0x0637: 0xD7, # ARABIC LETTER TAH - 0x0638: 0xD8, # ARABIC LETTER ZAH - 0x0639: 0xD9, # ARABIC LETTER AIN - 0x063A: 0xDA, # ARABIC LETTER GHAIN - 0x0640: 0xE0, # ARABIC TATWEEL - 0x0641: 0xE1, # ARABIC LETTER FEH - 0x0642: 0xE2, # ARABIC LETTER QAF - 0x0643: 0xE3, # ARABIC LETTER KAF - 0x0644: 0xE4, # ARABIC LETTER LAM - 0x0645: 0xE5, # ARABIC LETTER MEEM - 0x0646: 0xE6, # ARABIC LETTER NOON - 0x0647: 0xE7, # ARABIC LETTER HEH - 0x0648: 0xE8, # ARABIC LETTER WAW - 0x0649: 0xE9, # ARABIC LETTER ALEF MAKSURA - 0x064A: 0xEA, # ARABIC LETTER YEH - 0x064B: 0xEB, # ARABIC FATHATAN - 0x064C: 0xEC, # ARABIC DAMMATAN - 0x064D: 0xED, # ARABIC KASRATAN - 0x064E: 0xEE, # ARABIC FATHA - 0x064F: 0xEF, # ARABIC DAMMA - 0x0650: 0xF0, # ARABIC KASRA - 0x0651: 0xF1, # ARABIC SHADDA - 0x0652: 0xF2, # ARABIC SUKUN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_7.py b/Lib/encodings/iso8859_7.py index 4cce6e2..a560023 100644 --- a/Lib/encodings/iso8859_7.py +++ b/Lib/encodings/iso8859_7.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,260 +303,5 @@ decoding_table = ( u'\ufffe' ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A3: 0xA3, # POUND SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B7: 0xB7, # MIDDLE DOT - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x037A: 0xAA, # GREEK YPOGEGRAMMENI - 0x0384: 0xB4, # GREEK TONOS - 0x0385: 0xB5, # GREEK DIALYTIKA TONOS - 0x0386: 0xB6, # GREEK CAPITAL LETTER ALPHA WITH TONOS - 0x0388: 0xB8, # GREEK CAPITAL LETTER EPSILON WITH TONOS - 0x0389: 0xB9, # GREEK CAPITAL LETTER ETA WITH TONOS - 0x038A: 0xBA, # GREEK CAPITAL LETTER IOTA WITH TONOS - 0x038C: 0xBC, # GREEK CAPITAL LETTER OMICRON WITH TONOS - 0x038E: 0xBE, # GREEK CAPITAL LETTER UPSILON WITH TONOS - 0x038F: 0xBF, # GREEK CAPITAL LETTER OMEGA WITH TONOS - 0x0390: 0xC0, # GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS - 0x0391: 0xC1, # GREEK CAPITAL LETTER ALPHA - 0x0392: 0xC2, # GREEK CAPITAL LETTER BETA - 0x0393: 0xC3, # GREEK CAPITAL LETTER GAMMA - 0x0394: 0xC4, # GREEK CAPITAL LETTER DELTA - 0x0395: 0xC5, # GREEK CAPITAL LETTER EPSILON - 0x0396: 0xC6, # GREEK CAPITAL LETTER ZETA - 0x0397: 0xC7, # GREEK CAPITAL LETTER ETA - 0x0398: 0xC8, # GREEK CAPITAL LETTER THETA - 0x0399: 0xC9, # GREEK CAPITAL LETTER IOTA - 0x039A: 0xCA, # GREEK CAPITAL LETTER KAPPA - 0x039B: 0xCB, # GREEK CAPITAL LETTER LAMDA - 0x039C: 0xCC, # GREEK CAPITAL LETTER MU - 0x039D: 0xCD, # GREEK CAPITAL LETTER NU - 0x039E: 0xCE, # GREEK CAPITAL LETTER XI - 0x039F: 0xCF, # GREEK CAPITAL LETTER OMICRON - 0x03A0: 0xD0, # GREEK CAPITAL LETTER PI - 0x03A1: 0xD1, # GREEK CAPITAL LETTER RHO - 0x03A3: 0xD3, # GREEK CAPITAL LETTER SIGMA - 0x03A4: 0xD4, # GREEK CAPITAL LETTER TAU - 0x03A5: 0xD5, # GREEK CAPITAL LETTER UPSILON - 0x03A6: 0xD6, # GREEK CAPITAL LETTER PHI - 0x03A7: 0xD7, # GREEK CAPITAL LETTER CHI - 0x03A8: 0xD8, # GREEK CAPITAL LETTER PSI - 0x03A9: 0xD9, # GREEK CAPITAL LETTER OMEGA - 0x03AA: 0xDA, # GREEK CAPITAL LETTER IOTA WITH DIALYTIKA - 0x03AB: 0xDB, # GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA - 0x03AC: 0xDC, # GREEK SMALL LETTER ALPHA WITH TONOS - 0x03AD: 0xDD, # GREEK SMALL LETTER EPSILON WITH TONOS - 0x03AE: 0xDE, # GREEK SMALL LETTER ETA WITH TONOS - 0x03AF: 0xDF, # GREEK SMALL LETTER IOTA WITH TONOS - 0x03B0: 0xE0, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS - 0x03B1: 0xE1, # GREEK SMALL LETTER ALPHA - 0x03B2: 0xE2, # GREEK SMALL LETTER BETA - 0x03B3: 0xE3, # GREEK SMALL LETTER GAMMA - 0x03B4: 0xE4, # GREEK SMALL LETTER DELTA - 0x03B5: 0xE5, # GREEK SMALL LETTER EPSILON - 0x03B6: 0xE6, # GREEK SMALL LETTER ZETA - 0x03B7: 0xE7, # GREEK SMALL LETTER ETA - 0x03B8: 0xE8, # GREEK SMALL LETTER THETA - 0x03B9: 0xE9, # GREEK SMALL LETTER IOTA - 0x03BA: 0xEA, # GREEK SMALL LETTER KAPPA - 0x03BB: 0xEB, # GREEK SMALL LETTER LAMDA - 0x03BC: 0xEC, # GREEK SMALL LETTER MU - 0x03BD: 0xED, # GREEK SMALL LETTER NU - 0x03BE: 0xEE, # GREEK SMALL LETTER XI - 0x03BF: 0xEF, # GREEK SMALL LETTER OMICRON - 0x03C0: 0xF0, # GREEK SMALL LETTER PI - 0x03C1: 0xF1, # GREEK SMALL LETTER RHO - 0x03C2: 0xF2, # GREEK SMALL LETTER FINAL SIGMA - 0x03C3: 0xF3, # GREEK SMALL LETTER SIGMA - 0x03C4: 0xF4, # GREEK SMALL LETTER TAU - 0x03C5: 0xF5, # GREEK SMALL LETTER UPSILON - 0x03C6: 0xF6, # GREEK SMALL LETTER PHI - 0x03C7: 0xF7, # GREEK SMALL LETTER CHI - 0x03C8: 0xF8, # GREEK SMALL LETTER PSI - 0x03C9: 0xF9, # GREEK SMALL LETTER OMEGA - 0x03CA: 0xFA, # GREEK SMALL LETTER IOTA WITH DIALYTIKA - 0x03CB: 0xFB, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA - 0x03CC: 0xFC, # GREEK SMALL LETTER OMICRON WITH TONOS - 0x03CD: 0xFD, # GREEK SMALL LETTER UPSILON WITH TONOS - 0x03CE: 0xFE, # GREEK SMALL LETTER OMEGA WITH TONOS - 0x2015: 0xAF, # HORIZONTAL BAR - 0x2018: 0xA1, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xA2, # RIGHT SINGLE QUOTATION MARK - 0x20AC: 0xA4, # EURO SIGN - 0x20AF: 0xA5, # DRACHMA SIGN -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_8.py b/Lib/encodings/iso8859_8.py index 8c29a87..43cf213 100644 --- a/Lib/encodings/iso8859_8.py +++ b/Lib/encodings/iso8859_8.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,227 +303,5 @@ decoding_table = ( u'\ufffe' ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00D7: 0xAA, # MULTIPLICATION SIGN - 0x00F7: 0xBA, # DIVISION SIGN - 0x05D0: 0xE0, # HEBREW LETTER ALEF - 0x05D1: 0xE1, # HEBREW LETTER BET - 0x05D2: 0xE2, # HEBREW LETTER GIMEL - 0x05D3: 0xE3, # HEBREW LETTER DALET - 0x05D4: 0xE4, # HEBREW LETTER HE - 0x05D5: 0xE5, # HEBREW LETTER VAV - 0x05D6: 0xE6, # HEBREW LETTER ZAYIN - 0x05D7: 0xE7, # HEBREW LETTER HET - 0x05D8: 0xE8, # HEBREW LETTER TET - 0x05D9: 0xE9, # HEBREW LETTER YOD - 0x05DA: 0xEA, # HEBREW LETTER FINAL KAF - 0x05DB: 0xEB, # HEBREW LETTER KAF - 0x05DC: 0xEC, # HEBREW LETTER LAMED - 0x05DD: 0xED, # HEBREW LETTER FINAL MEM - 0x05DE: 0xEE, # HEBREW LETTER MEM - 0x05DF: 0xEF, # HEBREW LETTER FINAL NUN - 0x05E0: 0xF0, # HEBREW LETTER NUN - 0x05E1: 0xF1, # HEBREW LETTER SAMEKH - 0x05E2: 0xF2, # HEBREW LETTER AYIN - 0x05E3: 0xF3, # HEBREW LETTER FINAL PE - 0x05E4: 0xF4, # HEBREW LETTER PE - 0x05E5: 0xF5, # HEBREW LETTER FINAL TSADI - 0x05E6: 0xF6, # HEBREW LETTER TSADI - 0x05E7: 0xF7, # HEBREW LETTER QOF - 0x05E8: 0xF8, # HEBREW LETTER RESH - 0x05E9: 0xF9, # HEBREW LETTER SHIN - 0x05EA: 0xFA, # HEBREW LETTER TAV - 0x200E: 0xFD, # LEFT-TO-RIGHT MARK - 0x200F: 0xFE, # RIGHT-TO-LEFT MARK - 0x2017: 0xDF, # DOUBLE LOW LINE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/iso8859_9.py b/Lib/encodings/iso8859_9.py index 9648e9f..b802938 100644 --- a/Lib/encodings/iso8859_9.py +++ b/Lib/encodings/iso8859_9.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\xff' # 0xFF -> LATIN SMALL LETTER Y WITH DIAERESIS ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x00A0: 0xA0, # NO-BREAK SPACE - 0x00A1: 0xA1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A4: 0xA4, # CURRENCY SIGN - 0x00A5: 0xA5, # YEN SIGN - 0x00A6: 0xA6, # BROKEN BAR - 0x00A7: 0xA7, # SECTION SIGN - 0x00A8: 0xA8, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xAA, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xAB, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xAC, # NOT SIGN - 0x00AD: 0xAD, # SOFT HYPHEN - 0x00AE: 0xAE, # REGISTERED SIGN - 0x00AF: 0xAF, # MACRON - 0x00B0: 0xB0, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0xB2, # SUPERSCRIPT TWO - 0x00B3: 0xB3, # SUPERSCRIPT THREE - 0x00B4: 0xB4, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xB6, # PILCROW SIGN - 0x00B7: 0xB7, # MIDDLE DOT - 0x00B8: 0xB8, # CEDILLA - 0x00B9: 0xB9, # SUPERSCRIPT ONE - 0x00BA: 0xBA, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xBB, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BC: 0xBC, # VULGAR FRACTION ONE QUARTER - 0x00BD: 0xBD, # VULGAR FRACTION ONE HALF - 0x00BE: 0xBE, # VULGAR FRACTION THREE QUARTERS - 0x00BF: 0xBF, # INVERTED QUESTION MARK - 0x00C0: 0xC0, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xC1, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xC2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xC3, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0xC4, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0xC5, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xC6, # LATIN CAPITAL LETTER AE - 0x00C7: 0xC7, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xC8, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0xC9, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xCA, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xCB, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xCC, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xCD, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xCE, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xCF, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0xD1, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xD2, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xD3, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xD4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xD5, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0xD6, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D7: 0xD7, # MULTIPLICATION SIGN - 0x00D8: 0xD8, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xD9, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xDA, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xDB, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0xDC, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xDF, # LATIN SMALL LETTER SHARP S - 0x00E0: 0xE0, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0xE1, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0xE2, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0xE3, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0xE4, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0xE5, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xE6, # LATIN SMALL LETTER AE - 0x00E7: 0xE7, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0xE8, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0xE9, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0xEA, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0xEB, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0xEC, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0xED, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0xEE, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0xEF, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0xF1, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0xF2, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0xF3, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0xF4, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0xF5, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0xF6, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xF7, # DIVISION SIGN - 0x00F8: 0xF8, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0xF9, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0xFA, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0xFB, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0xFC, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xFF, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x011E: 0xD0, # LATIN CAPITAL LETTER G WITH BREVE - 0x011F: 0xF0, # LATIN SMALL LETTER G WITH BREVE - 0x0130: 0xDD, # LATIN CAPITAL LETTER I WITH DOT ABOVE - 0x0131: 0xFD, # LATIN SMALL LETTER DOTLESS I - 0x015E: 0xDE, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0xFE, # LATIN SMALL LETTER S WITH CEDILLA -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/koi8_r.py b/Lib/encodings/koi8_r.py index 3efeb56..f9eb82c 100644 --- a/Lib/encodings/koi8_r.py +++ b/Lib/encodings/koi8_r.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u042a' # 0xFF -> CYRILLIC CAPITAL LETTER HARD SIGN ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0x9A, # NO-BREAK SPACE - 0x00A9: 0xBF, # COPYRIGHT SIGN - 0x00B0: 0x9C, # DEGREE SIGN - 0x00B2: 0x9D, # SUPERSCRIPT TWO - 0x00B7: 0x9E, # MIDDLE DOT - 0x00F7: 0x9F, # DIVISION SIGN - 0x0401: 0xB3, # CYRILLIC CAPITAL LETTER IO - 0x0410: 0xE1, # CYRILLIC CAPITAL LETTER A - 0x0411: 0xE2, # CYRILLIC CAPITAL LETTER BE - 0x0412: 0xF7, # CYRILLIC CAPITAL LETTER VE - 0x0413: 0xE7, # CYRILLIC CAPITAL LETTER GHE - 0x0414: 0xE4, # CYRILLIC CAPITAL LETTER DE - 0x0415: 0xE5, # CYRILLIC CAPITAL LETTER IE - 0x0416: 0xF6, # CYRILLIC CAPITAL LETTER ZHE - 0x0417: 0xFA, # CYRILLIC CAPITAL LETTER ZE - 0x0418: 0xE9, # CYRILLIC CAPITAL LETTER I - 0x0419: 0xEA, # CYRILLIC CAPITAL LETTER SHORT I - 0x041A: 0xEB, # CYRILLIC CAPITAL LETTER KA - 0x041B: 0xEC, # CYRILLIC CAPITAL LETTER EL - 0x041C: 0xED, # CYRILLIC CAPITAL LETTER EM - 0x041D: 0xEE, # CYRILLIC CAPITAL LETTER EN - 0x041E: 0xEF, # CYRILLIC CAPITAL LETTER O - 0x041F: 0xF0, # CYRILLIC CAPITAL LETTER PE - 0x0420: 0xF2, # CYRILLIC CAPITAL LETTER ER - 0x0421: 0xF3, # CYRILLIC CAPITAL LETTER ES - 0x0422: 0xF4, # CYRILLIC CAPITAL LETTER TE - 0x0423: 0xF5, # CYRILLIC CAPITAL LETTER U - 0x0424: 0xE6, # CYRILLIC CAPITAL LETTER EF - 0x0425: 0xE8, # CYRILLIC CAPITAL LETTER HA - 0x0426: 0xE3, # CYRILLIC CAPITAL LETTER TSE - 0x0427: 0xFE, # CYRILLIC CAPITAL LETTER CHE - 0x0428: 0xFB, # CYRILLIC CAPITAL LETTER SHA - 0x0429: 0xFD, # CYRILLIC CAPITAL LETTER SHCHA - 0x042A: 0xFF, # CYRILLIC CAPITAL LETTER HARD SIGN - 0x042B: 0xF9, # CYRILLIC CAPITAL LETTER YERU - 0x042C: 0xF8, # CYRILLIC CAPITAL LETTER SOFT SIGN - 0x042D: 0xFC, # CYRILLIC CAPITAL LETTER E - 0x042E: 0xE0, # CYRILLIC CAPITAL LETTER YU - 0x042F: 0xF1, # CYRILLIC CAPITAL LETTER YA - 0x0430: 0xC1, # CYRILLIC SMALL LETTER A - 0x0431: 0xC2, # CYRILLIC SMALL LETTER BE - 0x0432: 0xD7, # CYRILLIC SMALL LETTER VE - 0x0433: 0xC7, # CYRILLIC SMALL LETTER GHE - 0x0434: 0xC4, # CYRILLIC SMALL LETTER DE - 0x0435: 0xC5, # CYRILLIC SMALL LETTER IE - 0x0436: 0xD6, # CYRILLIC SMALL LETTER ZHE - 0x0437: 0xDA, # CYRILLIC SMALL LETTER ZE - 0x0438: 0xC9, # CYRILLIC SMALL LETTER I - 0x0439: 0xCA, # CYRILLIC SMALL LETTER SHORT I - 0x043A: 0xCB, # CYRILLIC SMALL LETTER KA - 0x043B: 0xCC, # CYRILLIC SMALL LETTER EL - 0x043C: 0xCD, # CYRILLIC SMALL LETTER EM - 0x043D: 0xCE, # CYRILLIC SMALL LETTER EN - 0x043E: 0xCF, # CYRILLIC SMALL LETTER O - 0x043F: 0xD0, # CYRILLIC SMALL LETTER PE - 0x0440: 0xD2, # CYRILLIC SMALL LETTER ER - 0x0441: 0xD3, # CYRILLIC SMALL LETTER ES - 0x0442: 0xD4, # CYRILLIC SMALL LETTER TE - 0x0443: 0xD5, # CYRILLIC SMALL LETTER U - 0x0444: 0xC6, # CYRILLIC SMALL LETTER EF - 0x0445: 0xC8, # CYRILLIC SMALL LETTER HA - 0x0446: 0xC3, # CYRILLIC SMALL LETTER TSE - 0x0447: 0xDE, # CYRILLIC SMALL LETTER CHE - 0x0448: 0xDB, # CYRILLIC SMALL LETTER SHA - 0x0449: 0xDD, # CYRILLIC SMALL LETTER SHCHA - 0x044A: 0xDF, # CYRILLIC SMALL LETTER HARD SIGN - 0x044B: 0xD9, # CYRILLIC SMALL LETTER YERU - 0x044C: 0xD8, # CYRILLIC SMALL LETTER SOFT SIGN - 0x044D: 0xDC, # CYRILLIC SMALL LETTER E - 0x044E: 0xC0, # CYRILLIC SMALL LETTER YU - 0x044F: 0xD1, # CYRILLIC SMALL LETTER YA - 0x0451: 0xA3, # CYRILLIC SMALL LETTER IO - 0x2219: 0x95, # BULLET OPERATOR - 0x221A: 0x96, # SQUARE ROOT - 0x2248: 0x97, # ALMOST EQUAL TO - 0x2264: 0x98, # LESS-THAN OR EQUAL TO - 0x2265: 0x99, # GREATER-THAN OR EQUAL TO - 0x2320: 0x93, # TOP HALF INTEGRAL - 0x2321: 0x9B, # BOTTOM HALF INTEGRAL - 0x2500: 0x80, # BOX DRAWINGS LIGHT HORIZONTAL - 0x2502: 0x81, # BOX DRAWINGS LIGHT VERTICAL - 0x250C: 0x82, # BOX DRAWINGS LIGHT DOWN AND RIGHT - 0x2510: 0x83, # BOX DRAWINGS LIGHT DOWN AND LEFT - 0x2514: 0x84, # BOX DRAWINGS LIGHT UP AND RIGHT - 0x2518: 0x85, # BOX DRAWINGS LIGHT UP AND LEFT - 0x251C: 0x86, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT - 0x2524: 0x87, # BOX DRAWINGS LIGHT VERTICAL AND LEFT - 0x252C: 0x88, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - 0x2534: 0x89, # BOX DRAWINGS LIGHT UP AND HORIZONTAL - 0x253C: 0x8A, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - 0x2550: 0xA0, # BOX DRAWINGS DOUBLE HORIZONTAL - 0x2551: 0xA1, # BOX DRAWINGS DOUBLE VERTICAL - 0x2552: 0xA2, # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE - 0x2553: 0xA4, # BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE - 0x2554: 0xA5, # BOX DRAWINGS DOUBLE DOWN AND RIGHT - 0x2555: 0xA6, # BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE - 0x2556: 0xA7, # BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE - 0x2557: 0xA8, # BOX DRAWINGS DOUBLE DOWN AND LEFT - 0x2558: 0xA9, # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE - 0x2559: 0xAA, # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE - 0x255A: 0xAB, # BOX DRAWINGS DOUBLE UP AND RIGHT - 0x255B: 0xAC, # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE - 0x255C: 0xAD, # BOX DRAWINGS UP DOUBLE AND LEFT SINGLE - 0x255D: 0xAE, # BOX DRAWINGS DOUBLE UP AND LEFT - 0x255E: 0xAF, # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE - 0x255F: 0xB0, # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE - 0x2560: 0xB1, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT - 0x2561: 0xB2, # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE - 0x2562: 0xB4, # BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE - 0x2563: 0xB5, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT - 0x2564: 0xB6, # BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE - 0x2565: 0xB7, # BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE - 0x2566: 0xB8, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL - 0x2567: 0xB9, # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE - 0x2568: 0xBA, # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE - 0x2569: 0xBB, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL - 0x256A: 0xBC, # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE - 0x256B: 0xBD, # BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE - 0x256C: 0xBE, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL - 0x2580: 0x8B, # UPPER HALF BLOCK - 0x2584: 0x8C, # LOWER HALF BLOCK - 0x2588: 0x8D, # FULL BLOCK - 0x258C: 0x8E, # LEFT HALF BLOCK - 0x2590: 0x8F, # RIGHT HALF BLOCK - 0x2591: 0x90, # LIGHT SHADE - 0x2592: 0x91, # MEDIUM SHADE - 0x2593: 0x92, # DARK SHADE - 0x25A0: 0x94, # BLACK SQUARE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/koi8_u.py b/Lib/encodings/koi8_u.py index 5f46db1..a9317b1 100644 --- a/Lib/encodings/koi8_u.py +++ b/Lib/encodings/koi8_u.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u042a' # 0xFF -> CYRILLIC CAPITAL LETTER HARD SIGN ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x00A0: 0x9A, # NO-BREAK SPACE - 0x00A9: 0xBF, # COPYRIGHT SIGN - 0x00B0: 0x9C, # DEGREE SIGN - 0x00B2: 0x9D, # SUPERSCRIPT TWO - 0x00B7: 0x9E, # MIDDLE DOT - 0x00F7: 0x9F, # DIVISION SIGN - 0x0401: 0xB3, # CYRILLIC CAPITAL LETTER IO - 0x0404: 0xB4, # CYRILLIC CAPITAL LETTER UKRAINIAN IE - 0x0406: 0xB6, # CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0407: 0xB7, # CYRILLIC CAPITAL LETTER YI (UKRAINIAN) - 0x0410: 0xE1, # CYRILLIC CAPITAL LETTER A - 0x0411: 0xE2, # CYRILLIC CAPITAL LETTER BE - 0x0412: 0xF7, # CYRILLIC CAPITAL LETTER VE - 0x0413: 0xE7, # CYRILLIC CAPITAL LETTER GHE - 0x0414: 0xE4, # CYRILLIC CAPITAL LETTER DE - 0x0415: 0xE5, # CYRILLIC CAPITAL LETTER IE - 0x0416: 0xF6, # CYRILLIC CAPITAL LETTER ZHE - 0x0417: 0xFA, # CYRILLIC CAPITAL LETTER ZE - 0x0418: 0xE9, # CYRILLIC CAPITAL LETTER I - 0x0419: 0xEA, # CYRILLIC CAPITAL LETTER SHORT I - 0x041A: 0xEB, # CYRILLIC CAPITAL LETTER KA - 0x041B: 0xEC, # CYRILLIC CAPITAL LETTER EL - 0x041C: 0xED, # CYRILLIC CAPITAL LETTER EM - 0x041D: 0xEE, # CYRILLIC CAPITAL LETTER EN - 0x041E: 0xEF, # CYRILLIC CAPITAL LETTER O - 0x041F: 0xF0, # CYRILLIC CAPITAL LETTER PE - 0x0420: 0xF2, # CYRILLIC CAPITAL LETTER ER - 0x0421: 0xF3, # CYRILLIC CAPITAL LETTER ES - 0x0422: 0xF4, # CYRILLIC CAPITAL LETTER TE - 0x0423: 0xF5, # CYRILLIC CAPITAL LETTER U - 0x0424: 0xE6, # CYRILLIC CAPITAL LETTER EF - 0x0425: 0xE8, # CYRILLIC CAPITAL LETTER HA - 0x0426: 0xE3, # CYRILLIC CAPITAL LETTER TSE - 0x0427: 0xFE, # CYRILLIC CAPITAL LETTER CHE - 0x0428: 0xFB, # CYRILLIC CAPITAL LETTER SHA - 0x0429: 0xFD, # CYRILLIC CAPITAL LETTER SHCHA - 0x042A: 0xFF, # CYRILLIC CAPITAL LETTER HARD SIGN - 0x042B: 0xF9, # CYRILLIC CAPITAL LETTER YERU - 0x042C: 0xF8, # CYRILLIC CAPITAL LETTER SOFT SIGN - 0x042D: 0xFC, # CYRILLIC CAPITAL LETTER E - 0x042E: 0xE0, # CYRILLIC CAPITAL LETTER YU - 0x042F: 0xF1, # CYRILLIC CAPITAL LETTER YA - 0x0430: 0xC1, # CYRILLIC SMALL LETTER A - 0x0431: 0xC2, # CYRILLIC SMALL LETTER BE - 0x0432: 0xD7, # CYRILLIC SMALL LETTER VE - 0x0433: 0xC7, # CYRILLIC SMALL LETTER GHE - 0x0434: 0xC4, # CYRILLIC SMALL LETTER DE - 0x0435: 0xC5, # CYRILLIC SMALL LETTER IE - 0x0436: 0xD6, # CYRILLIC SMALL LETTER ZHE - 0x0437: 0xDA, # CYRILLIC SMALL LETTER ZE - 0x0438: 0xC9, # CYRILLIC SMALL LETTER I - 0x0439: 0xCA, # CYRILLIC SMALL LETTER SHORT I - 0x043A: 0xCB, # CYRILLIC SMALL LETTER KA - 0x043B: 0xCC, # CYRILLIC SMALL LETTER EL - 0x043C: 0xCD, # CYRILLIC SMALL LETTER EM - 0x043D: 0xCE, # CYRILLIC SMALL LETTER EN - 0x043E: 0xCF, # CYRILLIC SMALL LETTER O - 0x043F: 0xD0, # CYRILLIC SMALL LETTER PE - 0x0440: 0xD2, # CYRILLIC SMALL LETTER ER - 0x0441: 0xD3, # CYRILLIC SMALL LETTER ES - 0x0442: 0xD4, # CYRILLIC SMALL LETTER TE - 0x0443: 0xD5, # CYRILLIC SMALL LETTER U - 0x0444: 0xC6, # CYRILLIC SMALL LETTER EF - 0x0445: 0xC8, # CYRILLIC SMALL LETTER HA - 0x0446: 0xC3, # CYRILLIC SMALL LETTER TSE - 0x0447: 0xDE, # CYRILLIC SMALL LETTER CHE - 0x0448: 0xDB, # CYRILLIC SMALL LETTER SHA - 0x0449: 0xDD, # CYRILLIC SMALL LETTER SHCHA - 0x044A: 0xDF, # CYRILLIC SMALL LETTER HARD SIGN - 0x044B: 0xD9, # CYRILLIC SMALL LETTER YERU - 0x044C: 0xD8, # CYRILLIC SMALL LETTER SOFT SIGN - 0x044D: 0xDC, # CYRILLIC SMALL LETTER E - 0x044E: 0xC0, # CYRILLIC SMALL LETTER YU - 0x044F: 0xD1, # CYRILLIC SMALL LETTER YA - 0x0451: 0xA3, # CYRILLIC SMALL LETTER IO - 0x0454: 0xA4, # CYRILLIC SMALL LETTER UKRAINIAN IE - 0x0456: 0xA6, # CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0457: 0xA7, # CYRILLIC SMALL LETTER YI (UKRAINIAN) - 0x0490: 0xBD, # CYRILLIC CAPITAL LETTER UKRAINIAN GHE WITH UPTURN - 0x0491: 0xAD, # CYRILLIC SMALL LETTER UKRAINIAN GHE WITH UPTURN - 0x2219: 0x95, # BULLET OPERATOR - 0x221A: 0x96, # SQUARE ROOT - 0x2248: 0x97, # ALMOST EQUAL TO - 0x2264: 0x98, # LESS-THAN OR EQUAL TO - 0x2265: 0x99, # GREATER-THAN OR EQUAL TO - 0x2320: 0x93, # TOP HALF INTEGRAL - 0x2321: 0x9B, # BOTTOM HALF INTEGRAL - 0x2500: 0x80, # BOX DRAWINGS LIGHT HORIZONTAL - 0x2502: 0x81, # BOX DRAWINGS LIGHT VERTICAL - 0x250C: 0x82, # BOX DRAWINGS LIGHT DOWN AND RIGHT - 0x2510: 0x83, # BOX DRAWINGS LIGHT DOWN AND LEFT - 0x2514: 0x84, # BOX DRAWINGS LIGHT UP AND RIGHT - 0x2518: 0x85, # BOX DRAWINGS LIGHT UP AND LEFT - 0x251C: 0x86, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT - 0x2524: 0x87, # BOX DRAWINGS LIGHT VERTICAL AND LEFT - 0x252C: 0x88, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL - 0x2534: 0x89, # BOX DRAWINGS LIGHT UP AND HORIZONTAL - 0x253C: 0x8A, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL - 0x2550: 0xA0, # BOX DRAWINGS DOUBLE HORIZONTAL - 0x2551: 0xA1, # BOX DRAWINGS DOUBLE VERTICAL - 0x2552: 0xA2, # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE - 0x2554: 0xA5, # BOX DRAWINGS DOUBLE DOWN AND RIGHT - 0x2557: 0xA8, # BOX DRAWINGS DOUBLE DOWN AND LEFT - 0x2558: 0xA9, # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE - 0x2559: 0xAA, # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE - 0x255A: 0xAB, # BOX DRAWINGS DOUBLE UP AND RIGHT - 0x255B: 0xAC, # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE - 0x255D: 0xAE, # BOX DRAWINGS DOUBLE UP AND LEFT - 0x255E: 0xAF, # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE - 0x255F: 0xB0, # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE - 0x2560: 0xB1, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT - 0x2561: 0xB2, # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE - 0x2563: 0xB5, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT - 0x2566: 0xB8, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL - 0x2567: 0xB9, # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE - 0x2568: 0xBA, # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE - 0x2569: 0xBB, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL - 0x256A: 0xBC, # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE - 0x256C: 0xBE, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL - 0x2580: 0x8B, # UPPER HALF BLOCK - 0x2584: 0x8C, # LOWER HALF BLOCK - 0x2588: 0x8D, # FULL BLOCK - 0x258C: 0x8E, # LEFT HALF BLOCK - 0x2590: 0x8F, # RIGHT HALF BLOCK - 0x2591: 0x90, # LIGHT SHADE - 0x2592: 0x91, # MEDIUM SHADE - 0x2593: 0x92, # DARK SHADE - 0x25A0: 0x94, # BLACK SQUARE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_centeuro.py b/Lib/encodings/mac_centeuro.py index 54a1510..483c821 100644 --- a/Lib/encodings/mac_centeuro.py +++ b/Lib/encodings/mac_centeuro.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02c7' # 0xFF -> CARON ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A3: 0xA3, # POUND SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A8: 0xAC, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00C1: 0xE7, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CD: 0xEA, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEF, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xCD, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00DA: 0xF2, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xF8, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0x9B, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xF9, # LATIN SMALL LETTER Y WITH ACUTE - 0x0100: 0x81, # LATIN CAPITAL LETTER A WITH MACRON - 0x0101: 0x82, # LATIN SMALL LETTER A WITH MACRON - 0x0104: 0x84, # LATIN CAPITAL LETTER A WITH OGONEK - 0x0105: 0x88, # LATIN SMALL LETTER A WITH OGONEK - 0x0106: 0x8C, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0x8D, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0x89, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0x8B, # LATIN SMALL LETTER C WITH CARON - 0x010E: 0x91, # LATIN CAPITAL LETTER D WITH CARON - 0x010F: 0x93, # LATIN SMALL LETTER D WITH CARON - 0x0112: 0x94, # LATIN CAPITAL LETTER E WITH MACRON - 0x0113: 0x95, # LATIN SMALL LETTER E WITH MACRON - 0x0116: 0x96, # LATIN CAPITAL LETTER E WITH DOT ABOVE - 0x0117: 0x98, # LATIN SMALL LETTER E WITH DOT ABOVE - 0x0118: 0xA2, # LATIN CAPITAL LETTER E WITH OGONEK - 0x0119: 0xAB, # LATIN SMALL LETTER E WITH OGONEK - 0x011A: 0x9D, # LATIN CAPITAL LETTER E WITH CARON - 0x011B: 0x9E, # LATIN SMALL LETTER E WITH CARON - 0x0122: 0xFE, # LATIN CAPITAL LETTER G WITH CEDILLA - 0x0123: 0xAE, # LATIN SMALL LETTER G WITH CEDILLA - 0x012A: 0xB1, # LATIN CAPITAL LETTER I WITH MACRON - 0x012B: 0xB4, # LATIN SMALL LETTER I WITH MACRON - 0x012E: 0xAF, # LATIN CAPITAL LETTER I WITH OGONEK - 0x012F: 0xB0, # LATIN SMALL LETTER I WITH OGONEK - 0x0136: 0xB5, # LATIN CAPITAL LETTER K WITH CEDILLA - 0x0137: 0xFA, # LATIN SMALL LETTER K WITH CEDILLA - 0x0139: 0xBD, # LATIN CAPITAL LETTER L WITH ACUTE - 0x013A: 0xBE, # LATIN SMALL LETTER L WITH ACUTE - 0x013B: 0xB9, # LATIN CAPITAL LETTER L WITH CEDILLA - 0x013C: 0xBA, # LATIN SMALL LETTER L WITH CEDILLA - 0x013D: 0xBB, # LATIN CAPITAL LETTER L WITH CARON - 0x013E: 0xBC, # LATIN SMALL LETTER L WITH CARON - 0x0141: 0xFC, # LATIN CAPITAL LETTER L WITH STROKE - 0x0142: 0xB8, # LATIN SMALL LETTER L WITH STROKE - 0x0143: 0xC1, # LATIN CAPITAL LETTER N WITH ACUTE - 0x0144: 0xC4, # LATIN SMALL LETTER N WITH ACUTE - 0x0145: 0xBF, # LATIN CAPITAL LETTER N WITH CEDILLA - 0x0146: 0xC0, # LATIN SMALL LETTER N WITH CEDILLA - 0x0147: 0xC5, # LATIN CAPITAL LETTER N WITH CARON - 0x0148: 0xCB, # LATIN SMALL LETTER N WITH CARON - 0x014C: 0xCF, # LATIN CAPITAL LETTER O WITH MACRON - 0x014D: 0xD8, # LATIN SMALL LETTER O WITH MACRON - 0x0150: 0xCC, # LATIN CAPITAL LETTER O WITH DOUBLE ACUTE - 0x0151: 0xCE, # LATIN SMALL LETTER O WITH DOUBLE ACUTE - 0x0154: 0xD9, # LATIN CAPITAL LETTER R WITH ACUTE - 0x0155: 0xDA, # LATIN SMALL LETTER R WITH ACUTE - 0x0156: 0xDF, # LATIN CAPITAL LETTER R WITH CEDILLA - 0x0157: 0xE0, # LATIN SMALL LETTER R WITH CEDILLA - 0x0158: 0xDB, # LATIN CAPITAL LETTER R WITH CARON - 0x0159: 0xDE, # LATIN SMALL LETTER R WITH CARON - 0x015A: 0xE5, # LATIN CAPITAL LETTER S WITH ACUTE - 0x015B: 0xE6, # LATIN SMALL LETTER S WITH ACUTE - 0x0160: 0xE1, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xE4, # LATIN SMALL LETTER S WITH CARON - 0x0164: 0xE8, # LATIN CAPITAL LETTER T WITH CARON - 0x0165: 0xE9, # LATIN SMALL LETTER T WITH CARON - 0x016A: 0xED, # LATIN CAPITAL LETTER U WITH MACRON - 0x016B: 0xF0, # LATIN SMALL LETTER U WITH MACRON - 0x016E: 0xF1, # LATIN CAPITAL LETTER U WITH RING ABOVE - 0x016F: 0xF3, # LATIN SMALL LETTER U WITH RING ABOVE - 0x0170: 0xF4, # LATIN CAPITAL LETTER U WITH DOUBLE ACUTE - 0x0171: 0xF5, # LATIN SMALL LETTER U WITH DOUBLE ACUTE - 0x0172: 0xF6, # LATIN CAPITAL LETTER U WITH OGONEK - 0x0173: 0xF7, # LATIN SMALL LETTER U WITH OGONEK - 0x0179: 0x8F, # LATIN CAPITAL LETTER Z WITH ACUTE - 0x017A: 0x90, # LATIN SMALL LETTER Z WITH ACUTE - 0x017B: 0xFB, # LATIN CAPITAL LETTER Z WITH DOT ABOVE - 0x017C: 0xFD, # LATIN SMALL LETTER Z WITH DOT ABOVE - 0x017D: 0xEB, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xEC, # LATIN SMALL LETTER Z WITH CARON - 0x02C7: 0xFF, # CARON - 0x2013: 0xD0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0xE2, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xE3, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2039: 0xDC, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0xDD, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2202: 0xB6, # PARTIAL DIFFERENTIAL - 0x2206: 0xC6, # INCREMENT - 0x2211: 0xB7, # N-ARY SUMMATION - 0x221A: 0xC3, # SQUARE ROOT - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO - 0x25CA: 0xD7, # LOZENGE -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_croatian.py b/Lib/encodings/mac_croatian.py index 9e93cdd..f57f7b4 100644 --- a/Lib/encodings/mac_croatian.py +++ b/Lib/encodings/mac_croatian.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02c7' # 0xFF -> CARON ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A1: 0xC1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A8: 0xAC, # DIAERESIS - 0x00A9: 0xD9, # COPYRIGHT SIGN - 0x00AA: 0xBB, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00AF: 0xF8, # MACRON - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B4: 0xAB, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00B7: 0xE1, # MIDDLE DOT - 0x00B8: 0xFC, # CEDILLA - 0x00BA: 0xBC, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xDF, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BF: 0xC0, # INVERTED QUESTION MARK - 0x00C0: 0xCB, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xE7, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xE5, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xCC, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x81, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xDE, # LATIN CAPITAL LETTER AE - 0x00C7: 0x82, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xE9, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xFD, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xFA, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xED, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xEA, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xEB, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xEC, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0x84, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xF1, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEF, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xCD, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D8: 0xAF, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xF4, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xF2, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xF3, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x8B, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x8C, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xFE, # LATIN SMALL LETTER AE - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x93, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0x96, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0x98, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0x9B, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00F8: 0xBF, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0106: 0xC6, # LATIN CAPITAL LETTER C WITH ACUTE - 0x0107: 0xE6, # LATIN SMALL LETTER C WITH ACUTE - 0x010C: 0xC8, # LATIN CAPITAL LETTER C WITH CARON - 0x010D: 0xE8, # LATIN SMALL LETTER C WITH CARON - 0x0110: 0xD0, # LATIN CAPITAL LETTER D WITH STROKE - 0x0111: 0xF0, # LATIN SMALL LETTER D WITH STROKE - 0x0131: 0xF5, # LATIN SMALL LETTER DOTLESS I - 0x0152: 0xCE, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xCF, # LATIN SMALL LIGATURE OE - 0x0160: 0xA9, # LATIN CAPITAL LETTER S WITH CARON - 0x0161: 0xB9, # LATIN SMALL LETTER S WITH CARON - 0x017D: 0xAE, # LATIN CAPITAL LETTER Z WITH CARON - 0x017E: 0xBE, # LATIN SMALL LETTER Z WITH CARON - 0x0192: 0xC4, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0xF6, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02C7: 0xFF, # CARON - 0x02DA: 0xFB, # RING ABOVE - 0x02DC: 0xF7, # SMALL TILDE - 0x03A9: 0xBD, # GREEK CAPITAL LETTER OMEGA - 0x03C0: 0xF9, # GREEK SMALL LETTER PI - 0x2013: 0xE0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0xE2, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xE3, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2030: 0xE4, # PER MILLE SIGN - 0x2039: 0xDC, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0xDD, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x2044: 0xDA, # FRACTION SLASH - 0x20AC: 0xDB, # EURO SIGN - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2202: 0xB6, # PARTIAL DIFFERENTIAL - 0x2206: 0xB4, # INCREMENT - 0x220F: 0xB8, # N-ARY PRODUCT - 0x2211: 0xB7, # N-ARY SUMMATION - 0x221A: 0xC3, # SQUARE ROOT - 0x221E: 0xB0, # INFINITY - 0x222B: 0xBA, # INTEGRAL - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO - 0x25CA: 0xD7, # LOZENGE - 0xF8FF: 0xD8, # Apple logo -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_cyrillic.py b/Lib/encodings/mac_cyrillic.py index 8ffd715..63324a1 100644 --- a/Lib/encodings/mac_cyrillic.py +++ b/Lib/encodings/mac_cyrillic.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u20ac' # 0xFF -> EURO SIGN ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A3: 0xA3, # POUND SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00F7: 0xD6, # DIVISION SIGN - 0x0192: 0xC4, # LATIN SMALL LETTER F WITH HOOK - 0x0401: 0xDD, # CYRILLIC CAPITAL LETTER IO - 0x0402: 0xAB, # CYRILLIC CAPITAL LETTER DJE - 0x0403: 0xAE, # CYRILLIC CAPITAL LETTER GJE - 0x0404: 0xB8, # CYRILLIC CAPITAL LETTER UKRAINIAN IE - 0x0405: 0xC1, # CYRILLIC CAPITAL LETTER DZE - 0x0406: 0xA7, # CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0407: 0xBA, # CYRILLIC CAPITAL LETTER YI - 0x0408: 0xB7, # CYRILLIC CAPITAL LETTER JE - 0x0409: 0xBC, # CYRILLIC CAPITAL LETTER LJE - 0x040A: 0xBE, # CYRILLIC CAPITAL LETTER NJE - 0x040B: 0xCB, # CYRILLIC CAPITAL LETTER TSHE - 0x040C: 0xCD, # CYRILLIC CAPITAL LETTER KJE - 0x040E: 0xD8, # CYRILLIC CAPITAL LETTER SHORT U - 0x040F: 0xDA, # CYRILLIC CAPITAL LETTER DZHE - 0x0410: 0x80, # CYRILLIC CAPITAL LETTER A - 0x0411: 0x81, # CYRILLIC CAPITAL LETTER BE - 0x0412: 0x82, # CYRILLIC CAPITAL LETTER VE - 0x0413: 0x83, # CYRILLIC CAPITAL LETTER GHE - 0x0414: 0x84, # CYRILLIC CAPITAL LETTER DE - 0x0415: 0x85, # CYRILLIC CAPITAL LETTER IE - 0x0416: 0x86, # CYRILLIC CAPITAL LETTER ZHE - 0x0417: 0x87, # CYRILLIC CAPITAL LETTER ZE - 0x0418: 0x88, # CYRILLIC CAPITAL LETTER I - 0x0419: 0x89, # CYRILLIC CAPITAL LETTER SHORT I - 0x041A: 0x8A, # CYRILLIC CAPITAL LETTER KA - 0x041B: 0x8B, # CYRILLIC CAPITAL LETTER EL - 0x041C: 0x8C, # CYRILLIC CAPITAL LETTER EM - 0x041D: 0x8D, # CYRILLIC CAPITAL LETTER EN - 0x041E: 0x8E, # CYRILLIC CAPITAL LETTER O - 0x041F: 0x8F, # CYRILLIC CAPITAL LETTER PE - 0x0420: 0x90, # CYRILLIC CAPITAL LETTER ER - 0x0421: 0x91, # CYRILLIC CAPITAL LETTER ES - 0x0422: 0x92, # CYRILLIC CAPITAL LETTER TE - 0x0423: 0x93, # CYRILLIC CAPITAL LETTER U - 0x0424: 0x94, # CYRILLIC CAPITAL LETTER EF - 0x0425: 0x95, # CYRILLIC CAPITAL LETTER HA - 0x0426: 0x96, # CYRILLIC CAPITAL LETTER TSE - 0x0427: 0x97, # CYRILLIC CAPITAL LETTER CHE - 0x0428: 0x98, # CYRILLIC CAPITAL LETTER SHA - 0x0429: 0x99, # CYRILLIC CAPITAL LETTER SHCHA - 0x042A: 0x9A, # CYRILLIC CAPITAL LETTER HARD SIGN - 0x042B: 0x9B, # CYRILLIC CAPITAL LETTER YERU - 0x042C: 0x9C, # CYRILLIC CAPITAL LETTER SOFT SIGN - 0x042D: 0x9D, # CYRILLIC CAPITAL LETTER E - 0x042E: 0x9E, # CYRILLIC CAPITAL LETTER YU - 0x042F: 0x9F, # CYRILLIC CAPITAL LETTER YA - 0x0430: 0xE0, # CYRILLIC SMALL LETTER A - 0x0431: 0xE1, # CYRILLIC SMALL LETTER BE - 0x0432: 0xE2, # CYRILLIC SMALL LETTER VE - 0x0433: 0xE3, # CYRILLIC SMALL LETTER GHE - 0x0434: 0xE4, # CYRILLIC SMALL LETTER DE - 0x0435: 0xE5, # CYRILLIC SMALL LETTER IE - 0x0436: 0xE6, # CYRILLIC SMALL LETTER ZHE - 0x0437: 0xE7, # CYRILLIC SMALL LETTER ZE - 0x0438: 0xE8, # CYRILLIC SMALL LETTER I - 0x0439: 0xE9, # CYRILLIC SMALL LETTER SHORT I - 0x043A: 0xEA, # CYRILLIC SMALL LETTER KA - 0x043B: 0xEB, # CYRILLIC SMALL LETTER EL - 0x043C: 0xEC, # CYRILLIC SMALL LETTER EM - 0x043D: 0xED, # CYRILLIC SMALL LETTER EN - 0x043E: 0xEE, # CYRILLIC SMALL LETTER O - 0x043F: 0xEF, # CYRILLIC SMALL LETTER PE - 0x0440: 0xF0, # CYRILLIC SMALL LETTER ER - 0x0441: 0xF1, # CYRILLIC SMALL LETTER ES - 0x0442: 0xF2, # CYRILLIC SMALL LETTER TE - 0x0443: 0xF3, # CYRILLIC SMALL LETTER U - 0x0444: 0xF4, # CYRILLIC SMALL LETTER EF - 0x0445: 0xF5, # CYRILLIC SMALL LETTER HA - 0x0446: 0xF6, # CYRILLIC SMALL LETTER TSE - 0x0447: 0xF7, # CYRILLIC SMALL LETTER CHE - 0x0448: 0xF8, # CYRILLIC SMALL LETTER SHA - 0x0449: 0xF9, # CYRILLIC SMALL LETTER SHCHA - 0x044A: 0xFA, # CYRILLIC SMALL LETTER HARD SIGN - 0x044B: 0xFB, # CYRILLIC SMALL LETTER YERU - 0x044C: 0xFC, # CYRILLIC SMALL LETTER SOFT SIGN - 0x044D: 0xFD, # CYRILLIC SMALL LETTER E - 0x044E: 0xFE, # CYRILLIC SMALL LETTER YU - 0x044F: 0xDF, # CYRILLIC SMALL LETTER YA - 0x0451: 0xDE, # CYRILLIC SMALL LETTER IO - 0x0452: 0xAC, # CYRILLIC SMALL LETTER DJE - 0x0453: 0xAF, # CYRILLIC SMALL LETTER GJE - 0x0454: 0xB9, # CYRILLIC SMALL LETTER UKRAINIAN IE - 0x0455: 0xCF, # CYRILLIC SMALL LETTER DZE - 0x0456: 0xB4, # CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I - 0x0457: 0xBB, # CYRILLIC SMALL LETTER YI - 0x0458: 0xC0, # CYRILLIC SMALL LETTER JE - 0x0459: 0xBD, # CYRILLIC SMALL LETTER LJE - 0x045A: 0xBF, # CYRILLIC SMALL LETTER NJE - 0x045B: 0xCC, # CYRILLIC SMALL LETTER TSHE - 0x045C: 0xCE, # CYRILLIC SMALL LETTER KJE - 0x045E: 0xD9, # CYRILLIC SMALL LETTER SHORT U - 0x045F: 0xDB, # CYRILLIC SMALL LETTER DZHE - 0x0490: 0xA2, # CYRILLIC CAPITAL LETTER GHE WITH UPTURN - 0x0491: 0xB6, # CYRILLIC SMALL LETTER GHE WITH UPTURN - 0x2013: 0xD0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xD7, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x20AC: 0xFF, # EURO SIGN - 0x2116: 0xDC, # NUMERO SIGN - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2206: 0xC6, # INCREMENT - 0x221A: 0xC3, # SQUARE ROOT - 0x221E: 0xB0, # INFINITY - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_farsi.py b/Lib/encodings/mac_farsi.py index 6d26a42..9dbd76a 100644 --- a/Lib/encodings/mac_farsi.py +++ b/Lib/encodings/mac_farsi.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u06d2' # 0xFF -> ARABIC LETTER YEH BARREE ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE, left-right - 0x0020: 0xA0, # SPACE, right-left - 0x0021: 0x21, # EXCLAMATION MARK, left-right - 0x0021: 0xA1, # EXCLAMATION MARK, right-left - 0x0022: 0x22, # QUOTATION MARK, left-right - 0x0022: 0xA2, # QUOTATION MARK, right-left - 0x0023: 0x23, # NUMBER SIGN, left-right - 0x0023: 0xA3, # NUMBER SIGN, right-left - 0x0024: 0x24, # DOLLAR SIGN, left-right - 0x0024: 0xA4, # DOLLAR SIGN, right-left - 0x0025: 0x25, # PERCENT SIGN, left-right - 0x0026: 0x26, # AMPERSAND, left-right - 0x0026: 0xA6, # AMPERSAND, right-left - 0x0027: 0x27, # APOSTROPHE, left-right - 0x0027: 0xA7, # APOSTROPHE, right-left - 0x0028: 0x28, # LEFT PARENTHESIS, left-right - 0x0028: 0xA8, # LEFT PARENTHESIS, right-left - 0x0029: 0x29, # RIGHT PARENTHESIS, left-right - 0x0029: 0xA9, # RIGHT PARENTHESIS, right-left - 0x002A: 0x2A, # ASTERISK, left-right - 0x002A: 0xAA, # ASTERISK, right-left - 0x002B: 0x2B, # PLUS SIGN, left-right - 0x002B: 0xAB, # PLUS SIGN, right-left - 0x002C: 0x2C, # COMMA, left-right; in Arabic-script context, displayed as 0x066C ARABIC THOUSANDS SEPARATOR - 0x002D: 0x2D, # HYPHEN-MINUS, left-right - 0x002D: 0xAD, # HYPHEN-MINUS, right-left - 0x002E: 0x2E, # FULL STOP, left-right; in Arabic-script context, displayed as 0x066B ARABIC DECIMAL SEPARATOR - 0x002E: 0xAE, # FULL STOP, right-left - 0x002F: 0x2F, # SOLIDUS, left-right - 0x002F: 0xAF, # SOLIDUS, right-left - 0x0030: 0x30, # DIGIT ZERO; in Arabic-script context, displayed as 0x06F0 EXTENDED ARABIC-INDIC DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE; in Arabic-script context, displayed as 0x06F1 EXTENDED ARABIC-INDIC DIGIT ONE - 0x0032: 0x32, # DIGIT TWO; in Arabic-script context, displayed as 0x06F2 EXTENDED ARABIC-INDIC DIGIT TWO - 0x0033: 0x33, # DIGIT THREE; in Arabic-script context, displayed as 0x06F3 EXTENDED ARABIC-INDIC DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR; in Arabic-script context, displayed as 0x06F4 EXTENDED ARABIC-INDIC DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE; in Arabic-script context, displayed as 0x06F5 EXTENDED ARABIC-INDIC DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX; in Arabic-script context, displayed as 0x06F6 EXTENDED ARABIC-INDIC DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN; in Arabic-script context, displayed as 0x06F7 EXTENDED ARABIC-INDIC DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT; in Arabic-script context, displayed as 0x06F8 EXTENDED ARABIC-INDIC DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE; in Arabic-script context, displayed as 0x06F9 EXTENDED ARABIC-INDIC DIGIT NINE - 0x003A: 0x3A, # COLON, left-right - 0x003A: 0xBA, # COLON, right-left - 0x003B: 0x3B, # SEMICOLON, left-right - 0x003C: 0x3C, # LESS-THAN SIGN, left-right - 0x003C: 0xBC, # LESS-THAN SIGN, right-left - 0x003D: 0x3D, # EQUALS SIGN, left-right - 0x003D: 0xBD, # EQUALS SIGN, right-left - 0x003E: 0x3E, # GREATER-THAN SIGN, left-right - 0x003E: 0xBE, # GREATER-THAN SIGN, right-left - 0x003F: 0x3F, # QUESTION MARK, left-right - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET, left-right - 0x005B: 0xDB, # LEFT SQUARE BRACKET, right-left - 0x005C: 0x5C, # REVERSE SOLIDUS, left-right - 0x005C: 0xDC, # REVERSE SOLIDUS, right-left - 0x005D: 0x5D, # RIGHT SQUARE BRACKET, left-right - 0x005D: 0xDD, # RIGHT SQUARE BRACKET, right-left - 0x005E: 0x5E, # CIRCUMFLEX ACCENT, left-right - 0x005E: 0xDE, # CIRCUMFLEX ACCENT, right-left - 0x005F: 0x5F, # LOW LINE, left-right - 0x005F: 0xDF, # LOW LINE, right-left - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET, left-right - 0x007B: 0xFB, # LEFT CURLY BRACKET, right-left - 0x007C: 0x7C, # VERTICAL LINE, left-right - 0x007C: 0xFC, # VERTICAL LINE, right-left - 0x007D: 0x7D, # RIGHT CURLY BRACKET, left-right - 0x007D: 0xFD, # RIGHT CURLY BRACKET, right-left - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0x81, # NO-BREAK SPACE, right-left - 0x00AB: 0x8C, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK, right-left - 0x00BB: 0x98, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK, right-left - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C7: 0x82, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00D1: 0x84, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0x96, # LATIN SMALL LETTER N WITH TILDE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0x9B, # DIVISION SIGN, right-left - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x060C: 0xAC, # ARABIC COMMA - 0x061B: 0xBB, # ARABIC SEMICOLON - 0x061F: 0xBF, # ARABIC QUESTION MARK - 0x0621: 0xC1, # ARABIC LETTER HAMZA - 0x0622: 0xC2, # ARABIC LETTER ALEF WITH MADDA ABOVE - 0x0623: 0xC3, # ARABIC LETTER ALEF WITH HAMZA ABOVE - 0x0624: 0xC4, # ARABIC LETTER WAW WITH HAMZA ABOVE - 0x0625: 0xC5, # ARABIC LETTER ALEF WITH HAMZA BELOW - 0x0626: 0xC6, # ARABIC LETTER YEH WITH HAMZA ABOVE - 0x0627: 0xC7, # ARABIC LETTER ALEF - 0x0628: 0xC8, # ARABIC LETTER BEH - 0x0629: 0xC9, # ARABIC LETTER TEH MARBUTA - 0x062A: 0xCA, # ARABIC LETTER TEH - 0x062B: 0xCB, # ARABIC LETTER THEH - 0x062C: 0xCC, # ARABIC LETTER JEEM - 0x062D: 0xCD, # ARABIC LETTER HAH - 0x062E: 0xCE, # ARABIC LETTER KHAH - 0x062F: 0xCF, # ARABIC LETTER DAL - 0x0630: 0xD0, # ARABIC LETTER THAL - 0x0631: 0xD1, # ARABIC LETTER REH - 0x0632: 0xD2, # ARABIC LETTER ZAIN - 0x0633: 0xD3, # ARABIC LETTER SEEN - 0x0634: 0xD4, # ARABIC LETTER SHEEN - 0x0635: 0xD5, # ARABIC LETTER SAD - 0x0636: 0xD6, # ARABIC LETTER DAD - 0x0637: 0xD7, # ARABIC LETTER TAH - 0x0638: 0xD8, # ARABIC LETTER ZAH - 0x0639: 0xD9, # ARABIC LETTER AIN - 0x063A: 0xDA, # ARABIC LETTER GHAIN - 0x0640: 0xE0, # ARABIC TATWEEL - 0x0641: 0xE1, # ARABIC LETTER FEH - 0x0642: 0xE2, # ARABIC LETTER QAF - 0x0643: 0xE3, # ARABIC LETTER KAF - 0x0644: 0xE4, # ARABIC LETTER LAM - 0x0645: 0xE5, # ARABIC LETTER MEEM - 0x0646: 0xE6, # ARABIC LETTER NOON - 0x0647: 0xE7, # ARABIC LETTER HEH - 0x0648: 0xE8, # ARABIC LETTER WAW - 0x0649: 0xE9, # ARABIC LETTER ALEF MAKSURA - 0x064A: 0xEA, # ARABIC LETTER YEH - 0x064B: 0xEB, # ARABIC FATHATAN - 0x064C: 0xEC, # ARABIC DAMMATAN - 0x064D: 0xED, # ARABIC KASRATAN - 0x064E: 0xEE, # ARABIC FATHA - 0x064F: 0xEF, # ARABIC DAMMA - 0x0650: 0xF0, # ARABIC KASRA - 0x0651: 0xF1, # ARABIC SHADDA - 0x0652: 0xF2, # ARABIC SUKUN - 0x066A: 0xA5, # ARABIC PERCENT SIGN - 0x0679: 0xF4, # ARABIC LETTER TTEH - 0x067E: 0xF3, # ARABIC LETTER PEH - 0x0686: 0xF5, # ARABIC LETTER TCHEH - 0x0688: 0xF9, # ARABIC LETTER DDAL - 0x0691: 0xFA, # ARABIC LETTER RREH - 0x0698: 0xFE, # ARABIC LETTER JEH - 0x06A4: 0xF7, # ARABIC LETTER VEH - 0x06AF: 0xF8, # ARABIC LETTER GAF - 0x06BA: 0x8B, # ARABIC LETTER NOON GHUNNA - 0x06D2: 0xFF, # ARABIC LETTER YEH BARREE - 0x06D5: 0xF6, # ARABIC LETTER AE - 0x06F0: 0xB0, # EXTENDED ARABIC-INDIC DIGIT ZERO, right-left (need override) - 0x06F1: 0xB1, # EXTENDED ARABIC-INDIC DIGIT ONE, right-left (need override) - 0x06F2: 0xB2, # EXTENDED ARABIC-INDIC DIGIT TWO, right-left (need override) - 0x06F3: 0xB3, # EXTENDED ARABIC-INDIC DIGIT THREE, right-left (need override) - 0x06F4: 0xB4, # EXTENDED ARABIC-INDIC DIGIT FOUR, right-left (need override) - 0x06F5: 0xB5, # EXTENDED ARABIC-INDIC DIGIT FIVE, right-left (need override) - 0x06F6: 0xB6, # EXTENDED ARABIC-INDIC DIGIT SIX, right-left (need override) - 0x06F7: 0xB7, # EXTENDED ARABIC-INDIC DIGIT SEVEN, right-left (need override) - 0x06F8: 0xB8, # EXTENDED ARABIC-INDIC DIGIT EIGHT, right-left (need override) - 0x06F9: 0xB9, # EXTENDED ARABIC-INDIC DIGIT NINE, right-left (need override) - 0x2026: 0x93, # HORIZONTAL ELLIPSIS, right-left - 0x274A: 0xC0, # EIGHT TEARDROP-SPOKED PROPELLER ASTERISK, right-left -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_greek.py b/Lib/encodings/mac_greek.py index 7264f9a..68f4fff 100644 --- a/Lib/encodings/mac_greek.py +++ b/Lib/encodings/mac_greek.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\xad' # 0xFF -> SOFT HYPHEN # before Mac OS 9.2.2, was undefined ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A3: 0x92, # POUND SIGN - 0x00A5: 0xB4, # YEN SIGN - 0x00A6: 0x9B, # BROKEN BAR - 0x00A7: 0xAC, # SECTION SIGN - 0x00A8: 0x8C, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AD: 0xFF, # SOFT HYPHEN # before Mac OS 9.2.2, was undefined - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00B0: 0xAE, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B2: 0x82, # SUPERSCRIPT TWO - 0x00B3: 0x84, # SUPERSCRIPT THREE - 0x00B7: 0xAF, # MIDDLE DOT - 0x00B9: 0x81, # SUPERSCRIPT ONE - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BD: 0x97, # VULGAR FRACTION ONE HALF - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x0153: 0xCF, # LATIN SMALL LIGATURE OE - 0x0384: 0x8B, # GREEK TONOS - 0x0385: 0x87, # GREEK DIALYTIKA TONOS - 0x0386: 0xCD, # GREEK CAPITAL LETTER ALPHA WITH TONOS - 0x0388: 0xCE, # GREEK CAPITAL LETTER EPSILON WITH TONOS - 0x0389: 0xD7, # GREEK CAPITAL LETTER ETA WITH TONOS - 0x038A: 0xD8, # GREEK CAPITAL LETTER IOTA WITH TONOS - 0x038C: 0xD9, # GREEK CAPITAL LETTER OMICRON WITH TONOS - 0x038E: 0xDA, # GREEK CAPITAL LETTER UPSILON WITH TONOS - 0x038F: 0xDF, # GREEK CAPITAL LETTER OMEGA WITH TONOS - 0x0390: 0xFD, # GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS - 0x0391: 0xB0, # GREEK CAPITAL LETTER ALPHA - 0x0392: 0xB5, # GREEK CAPITAL LETTER BETA - 0x0393: 0xA1, # GREEK CAPITAL LETTER GAMMA - 0x0394: 0xA2, # GREEK CAPITAL LETTER DELTA - 0x0395: 0xB6, # GREEK CAPITAL LETTER EPSILON - 0x0396: 0xB7, # GREEK CAPITAL LETTER ZETA - 0x0397: 0xB8, # GREEK CAPITAL LETTER ETA - 0x0398: 0xA3, # GREEK CAPITAL LETTER THETA - 0x0399: 0xB9, # GREEK CAPITAL LETTER IOTA - 0x039A: 0xBA, # GREEK CAPITAL LETTER KAPPA - 0x039B: 0xA4, # GREEK CAPITAL LETTER LAMDA - 0x039C: 0xBB, # GREEK CAPITAL LETTER MU - 0x039D: 0xC1, # GREEK CAPITAL LETTER NU - 0x039E: 0xA5, # GREEK CAPITAL LETTER XI - 0x039F: 0xC3, # GREEK CAPITAL LETTER OMICRON - 0x03A0: 0xA6, # GREEK CAPITAL LETTER PI - 0x03A1: 0xC4, # GREEK CAPITAL LETTER RHO - 0x03A3: 0xAA, # GREEK CAPITAL LETTER SIGMA - 0x03A4: 0xC6, # GREEK CAPITAL LETTER TAU - 0x03A5: 0xCB, # GREEK CAPITAL LETTER UPSILON - 0x03A6: 0xBC, # GREEK CAPITAL LETTER PHI - 0x03A7: 0xCC, # GREEK CAPITAL LETTER CHI - 0x03A8: 0xBE, # GREEK CAPITAL LETTER PSI - 0x03A9: 0xBF, # GREEK CAPITAL LETTER OMEGA - 0x03AA: 0xAB, # GREEK CAPITAL LETTER IOTA WITH DIALYTIKA - 0x03AB: 0xBD, # GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA - 0x03AC: 0xC0, # GREEK SMALL LETTER ALPHA WITH TONOS - 0x03AD: 0xDB, # GREEK SMALL LETTER EPSILON WITH TONOS - 0x03AE: 0xDC, # GREEK SMALL LETTER ETA WITH TONOS - 0x03AF: 0xDD, # GREEK SMALL LETTER IOTA WITH TONOS - 0x03B0: 0xFE, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS - 0x03B1: 0xE1, # GREEK SMALL LETTER ALPHA - 0x03B2: 0xE2, # GREEK SMALL LETTER BETA - 0x03B3: 0xE7, # GREEK SMALL LETTER GAMMA - 0x03B4: 0xE4, # GREEK SMALL LETTER DELTA - 0x03B5: 0xE5, # GREEK SMALL LETTER EPSILON - 0x03B6: 0xFA, # GREEK SMALL LETTER ZETA - 0x03B7: 0xE8, # GREEK SMALL LETTER ETA - 0x03B8: 0xF5, # GREEK SMALL LETTER THETA - 0x03B9: 0xE9, # GREEK SMALL LETTER IOTA - 0x03BA: 0xEB, # GREEK SMALL LETTER KAPPA - 0x03BB: 0xEC, # GREEK SMALL LETTER LAMDA - 0x03BC: 0xED, # GREEK SMALL LETTER MU - 0x03BD: 0xEE, # GREEK SMALL LETTER NU - 0x03BE: 0xEA, # GREEK SMALL LETTER XI - 0x03BF: 0xEF, # GREEK SMALL LETTER OMICRON - 0x03C0: 0xF0, # GREEK SMALL LETTER PI - 0x03C1: 0xF2, # GREEK SMALL LETTER RHO - 0x03C2: 0xF7, # GREEK SMALL LETTER FINAL SIGMA - 0x03C3: 0xF3, # GREEK SMALL LETTER SIGMA - 0x03C4: 0xF4, # GREEK SMALL LETTER TAU - 0x03C5: 0xF9, # GREEK SMALL LETTER UPSILON - 0x03C6: 0xE6, # GREEK SMALL LETTER PHI - 0x03C7: 0xF8, # GREEK SMALL LETTER CHI - 0x03C8: 0xE3, # GREEK SMALL LETTER PSI - 0x03C9: 0xF6, # GREEK SMALL LETTER OMEGA - 0x03CA: 0xFB, # GREEK SMALL LETTER IOTA WITH DIALYTIKA - 0x03CB: 0xFC, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA - 0x03CC: 0xDE, # GREEK SMALL LETTER OMICRON WITH TONOS - 0x03CD: 0xE0, # GREEK SMALL LETTER UPSILON WITH TONOS - 0x03CE: 0xF1, # GREEK SMALL LETTER OMEGA WITH TONOS - 0x2013: 0xD0, # EN DASH - 0x2015: 0xD1, # HORIZONTAL BAR - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2022: 0x96, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2030: 0x98, # PER MILLE SIGN - 0x20AC: 0x9C, # EURO SIGN # before Mac OS 9.2.2, was SOFT HYPHEN - 0x2122: 0x93, # TRADE MARK SIGN - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_iceland.py b/Lib/encodings/mac_iceland.py index 5d8d9ad..c24add2 100644 --- a/Lib/encodings/mac_iceland.py +++ b/Lib/encodings/mac_iceland.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02c7' # 0xFF -> CARON ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A1: 0xC1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A5: 0xB4, # YEN SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A8: 0xAC, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xBB, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00AF: 0xF8, # MACRON - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B4: 0xAB, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00B7: 0xE1, # MIDDLE DOT - 0x00B8: 0xFC, # CEDILLA - 0x00BA: 0xBC, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BF: 0xC0, # INVERTED QUESTION MARK - 0x00C0: 0xCB, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xE7, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xE5, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xCC, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x81, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xAE, # LATIN CAPITAL LETTER AE - 0x00C7: 0x82, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xE9, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xE6, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xE8, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xED, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xEA, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xEB, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xEC, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D0: 0xDC, # LATIN CAPITAL LETTER ETH - 0x00D1: 0x84, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xF1, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEF, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xCD, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D8: 0xAF, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xF4, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xF2, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xF3, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DD: 0xA0, # LATIN CAPITAL LETTER Y WITH ACUTE - 0x00DE: 0xDE, # LATIN CAPITAL LETTER THORN - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x8B, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x8C, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xBE, # LATIN SMALL LETTER AE - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x93, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F0: 0xDD, # LATIN SMALL LETTER ETH - 0x00F1: 0x96, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0x98, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0x9B, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00F8: 0xBF, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FD: 0xE0, # LATIN SMALL LETTER Y WITH ACUTE - 0x00FE: 0xDF, # LATIN SMALL LETTER THORN - 0x00FF: 0xD8, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0131: 0xF5, # LATIN SMALL LETTER DOTLESS I - 0x0152: 0xCE, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xCF, # LATIN SMALL LIGATURE OE - 0x0178: 0xD9, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0192: 0xC4, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0xF6, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02C7: 0xFF, # CARON - 0x02D8: 0xF9, # BREVE - 0x02D9: 0xFA, # DOT ABOVE - 0x02DA: 0xFB, # RING ABOVE - 0x02DB: 0xFE, # OGONEK - 0x02DC: 0xF7, # SMALL TILDE - 0x02DD: 0xFD, # DOUBLE ACUTE ACCENT - 0x03A9: 0xBD, # GREEK CAPITAL LETTER OMEGA - 0x03C0: 0xB9, # GREEK SMALL LETTER PI - 0x2013: 0xD0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0xE2, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xE3, # DOUBLE LOW-9 QUOTATION MARK - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2030: 0xE4, # PER MILLE SIGN - 0x2044: 0xDA, # FRACTION SLASH - 0x20AC: 0xDB, # EURO SIGN - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2202: 0xB6, # PARTIAL DIFFERENTIAL - 0x2206: 0xC6, # INCREMENT - 0x220F: 0xB8, # N-ARY PRODUCT - 0x2211: 0xB7, # N-ARY SUMMATION - 0x221A: 0xC3, # SQUARE ROOT - 0x221E: 0xB0, # INFINITY - 0x222B: 0xBA, # INTEGRAL - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO - 0x25CA: 0xD7, # LOZENGE - 0xF8FF: 0xF0, # Apple logo -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_roman.py b/Lib/encodings/mac_roman.py index 9552e53..62605ec 100644 --- a/Lib/encodings/mac_roman.py +++ b/Lib/encodings/mac_roman.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02c7' # 0xFF -> CARON ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A1: 0xC1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A5: 0xB4, # YEN SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A8: 0xAC, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xBB, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00AF: 0xF8, # MACRON - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B4: 0xAB, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00B7: 0xE1, # MIDDLE DOT - 0x00B8: 0xFC, # CEDILLA - 0x00BA: 0xBC, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BF: 0xC0, # INVERTED QUESTION MARK - 0x00C0: 0xCB, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xE7, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xE5, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xCC, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x81, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xAE, # LATIN CAPITAL LETTER AE - 0x00C7: 0x82, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xE9, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xE6, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xE8, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xED, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xEA, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xEB, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xEC, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0x84, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xF1, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEF, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xCD, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D8: 0xAF, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xF4, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xF2, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xF3, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x8B, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x8C, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xBE, # LATIN SMALL LETTER AE - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x93, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0x96, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0x98, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0x9B, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00F8: 0xBF, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xD8, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0131: 0xF5, # LATIN SMALL LETTER DOTLESS I - 0x0152: 0xCE, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xCF, # LATIN SMALL LIGATURE OE - 0x0178: 0xD9, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0192: 0xC4, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0xF6, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02C7: 0xFF, # CARON - 0x02D8: 0xF9, # BREVE - 0x02D9: 0xFA, # DOT ABOVE - 0x02DA: 0xFB, # RING ABOVE - 0x02DB: 0xFE, # OGONEK - 0x02DC: 0xF7, # SMALL TILDE - 0x02DD: 0xFD, # DOUBLE ACUTE ACCENT - 0x03A9: 0xBD, # GREEK CAPITAL LETTER OMEGA - 0x03C0: 0xB9, # GREEK SMALL LETTER PI - 0x2013: 0xD0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0xE2, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xE3, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2021: 0xE0, # DOUBLE DAGGER - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2030: 0xE4, # PER MILLE SIGN - 0x2039: 0xDC, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0xDD, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x2044: 0xDA, # FRACTION SLASH - 0x20AC: 0xDB, # EURO SIGN - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2202: 0xB6, # PARTIAL DIFFERENTIAL - 0x2206: 0xC6, # INCREMENT - 0x220F: 0xB8, # N-ARY PRODUCT - 0x2211: 0xB7, # N-ARY SUMMATION - 0x221A: 0xC3, # SQUARE ROOT - 0x221E: 0xB0, # INFINITY - 0x222B: 0xBA, # INTEGRAL - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO - 0x25CA: 0xD7, # LOZENGE - 0xF8FF: 0xF0, # Apple logo - 0xFB01: 0xDE, # LATIN SMALL LIGATURE FI - 0xFB02: 0xDF, # LATIN SMALL LIGATURE FL -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_romanian.py b/Lib/encodings/mac_romanian.py index 51282c3..5bd5ae8 100644 --- a/Lib/encodings/mac_romanian.py +++ b/Lib/encodings/mac_romanian.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02c7' # 0xFF -> CARON ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A1: 0xC1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A5: 0xB4, # YEN SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A8: 0xAC, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xBB, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00AF: 0xF8, # MACRON - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B4: 0xAB, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00B7: 0xE1, # MIDDLE DOT - 0x00B8: 0xFC, # CEDILLA - 0x00BA: 0xBC, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BF: 0xC0, # INVERTED QUESTION MARK - 0x00C0: 0xCB, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xE7, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xE5, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xCC, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x81, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C7: 0x82, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xE9, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xE6, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xE8, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xED, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xEA, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xEB, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xEC, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0x84, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xF1, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEF, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xCD, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D9: 0xF4, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xF2, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xF3, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x8B, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x8C, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x93, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0x96, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0x98, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0x9B, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xD8, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x0102: 0xAE, # LATIN CAPITAL LETTER A WITH BREVE - 0x0103: 0xBE, # LATIN SMALL LETTER A WITH BREVE - 0x0131: 0xF5, # LATIN SMALL LETTER DOTLESS I - 0x0152: 0xCE, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xCF, # LATIN SMALL LIGATURE OE - 0x0178: 0xD9, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0192: 0xC4, # LATIN SMALL LETTER F WITH HOOK - 0x0218: 0xAF, # LATIN CAPITAL LETTER S WITH COMMA BELOW # for Unicode 3.0 and later - 0x0219: 0xBF, # LATIN SMALL LETTER S WITH COMMA BELOW # for Unicode 3.0 and later - 0x021A: 0xDE, # LATIN CAPITAL LETTER T WITH COMMA BELOW # for Unicode 3.0 and later - 0x021B: 0xDF, # LATIN SMALL LETTER T WITH COMMA BELOW # for Unicode 3.0 and later - 0x02C6: 0xF6, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02C7: 0xFF, # CARON - 0x02D8: 0xF9, # BREVE - 0x02D9: 0xFA, # DOT ABOVE - 0x02DA: 0xFB, # RING ABOVE - 0x02DB: 0xFE, # OGONEK - 0x02DC: 0xF7, # SMALL TILDE - 0x02DD: 0xFD, # DOUBLE ACUTE ACCENT - 0x03A9: 0xBD, # GREEK CAPITAL LETTER OMEGA - 0x03C0: 0xB9, # GREEK SMALL LETTER PI - 0x2013: 0xD0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0xE2, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xE3, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2021: 0xE0, # DOUBLE DAGGER - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2030: 0xE4, # PER MILLE SIGN - 0x2039: 0xDC, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK - 0x203A: 0xDD, # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK - 0x2044: 0xDA, # FRACTION SLASH - 0x20AC: 0xDB, # EURO SIGN - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2202: 0xB6, # PARTIAL DIFFERENTIAL - 0x2206: 0xC6, # INCREMENT - 0x220F: 0xB8, # N-ARY PRODUCT - 0x2211: 0xB7, # N-ARY SUMMATION - 0x221A: 0xC3, # SQUARE ROOT - 0x221E: 0xB0, # INFINITY - 0x222B: 0xBA, # INTEGRAL - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO - 0x25CA: 0xD7, # LOZENGE - 0xF8FF: 0xF0, # Apple logo -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/mac_turkish.py b/Lib/encodings/mac_turkish.py index 4e5641f..0787f49 100644 --- a/Lib/encodings/mac_turkish.py +++ b/Lib/encodings/mac_turkish.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,263 +303,5 @@ decoding_table = ( u'\u02c7' # 0xFF -> CARON ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # CONTROL CHARACTER - 0x0001: 0x01, # CONTROL CHARACTER - 0x0002: 0x02, # CONTROL CHARACTER - 0x0003: 0x03, # CONTROL CHARACTER - 0x0004: 0x04, # CONTROL CHARACTER - 0x0005: 0x05, # CONTROL CHARACTER - 0x0006: 0x06, # CONTROL CHARACTER - 0x0007: 0x07, # CONTROL CHARACTER - 0x0008: 0x08, # CONTROL CHARACTER - 0x0009: 0x09, # CONTROL CHARACTER - 0x000A: 0x0A, # CONTROL CHARACTER - 0x000B: 0x0B, # CONTROL CHARACTER - 0x000C: 0x0C, # CONTROL CHARACTER - 0x000D: 0x0D, # CONTROL CHARACTER - 0x000E: 0x0E, # CONTROL CHARACTER - 0x000F: 0x0F, # CONTROL CHARACTER - 0x0010: 0x10, # CONTROL CHARACTER - 0x0011: 0x11, # CONTROL CHARACTER - 0x0012: 0x12, # CONTROL CHARACTER - 0x0013: 0x13, # CONTROL CHARACTER - 0x0014: 0x14, # CONTROL CHARACTER - 0x0015: 0x15, # CONTROL CHARACTER - 0x0016: 0x16, # CONTROL CHARACTER - 0x0017: 0x17, # CONTROL CHARACTER - 0x0018: 0x18, # CONTROL CHARACTER - 0x0019: 0x19, # CONTROL CHARACTER - 0x001A: 0x1A, # CONTROL CHARACTER - 0x001B: 0x1B, # CONTROL CHARACTER - 0x001C: 0x1C, # CONTROL CHARACTER - 0x001D: 0x1D, # CONTROL CHARACTER - 0x001E: 0x1E, # CONTROL CHARACTER - 0x001F: 0x1F, # CONTROL CHARACTER - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # CONTROL CHARACTER - 0x00A0: 0xCA, # NO-BREAK SPACE - 0x00A1: 0xC1, # INVERTED EXCLAMATION MARK - 0x00A2: 0xA2, # CENT SIGN - 0x00A3: 0xA3, # POUND SIGN - 0x00A5: 0xB4, # YEN SIGN - 0x00A7: 0xA4, # SECTION SIGN - 0x00A8: 0xAC, # DIAERESIS - 0x00A9: 0xA9, # COPYRIGHT SIGN - 0x00AA: 0xBB, # FEMININE ORDINAL INDICATOR - 0x00AB: 0xC7, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00AC: 0xC2, # NOT SIGN - 0x00AE: 0xA8, # REGISTERED SIGN - 0x00AF: 0xF8, # MACRON - 0x00B0: 0xA1, # DEGREE SIGN - 0x00B1: 0xB1, # PLUS-MINUS SIGN - 0x00B4: 0xAB, # ACUTE ACCENT - 0x00B5: 0xB5, # MICRO SIGN - 0x00B6: 0xA6, # PILCROW SIGN - 0x00B7: 0xE1, # MIDDLE DOT - 0x00B8: 0xFC, # CEDILLA - 0x00BA: 0xBC, # MASCULINE ORDINAL INDICATOR - 0x00BB: 0xC8, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK - 0x00BF: 0xC0, # INVERTED QUESTION MARK - 0x00C0: 0xCB, # LATIN CAPITAL LETTER A WITH GRAVE - 0x00C1: 0xE7, # LATIN CAPITAL LETTER A WITH ACUTE - 0x00C2: 0xE5, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX - 0x00C3: 0xCC, # LATIN CAPITAL LETTER A WITH TILDE - 0x00C4: 0x80, # LATIN CAPITAL LETTER A WITH DIAERESIS - 0x00C5: 0x81, # LATIN CAPITAL LETTER A WITH RING ABOVE - 0x00C6: 0xAE, # LATIN CAPITAL LETTER AE - 0x00C7: 0x82, # LATIN CAPITAL LETTER C WITH CEDILLA - 0x00C8: 0xE9, # LATIN CAPITAL LETTER E WITH GRAVE - 0x00C9: 0x83, # LATIN CAPITAL LETTER E WITH ACUTE - 0x00CA: 0xE6, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX - 0x00CB: 0xE8, # LATIN CAPITAL LETTER E WITH DIAERESIS - 0x00CC: 0xED, # LATIN CAPITAL LETTER I WITH GRAVE - 0x00CD: 0xEA, # LATIN CAPITAL LETTER I WITH ACUTE - 0x00CE: 0xEB, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX - 0x00CF: 0xEC, # LATIN CAPITAL LETTER I WITH DIAERESIS - 0x00D1: 0x84, # LATIN CAPITAL LETTER N WITH TILDE - 0x00D2: 0xF1, # LATIN CAPITAL LETTER O WITH GRAVE - 0x00D3: 0xEE, # LATIN CAPITAL LETTER O WITH ACUTE - 0x00D4: 0xEF, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX - 0x00D5: 0xCD, # LATIN CAPITAL LETTER O WITH TILDE - 0x00D6: 0x85, # LATIN CAPITAL LETTER O WITH DIAERESIS - 0x00D8: 0xAF, # LATIN CAPITAL LETTER O WITH STROKE - 0x00D9: 0xF4, # LATIN CAPITAL LETTER U WITH GRAVE - 0x00DA: 0xF2, # LATIN CAPITAL LETTER U WITH ACUTE - 0x00DB: 0xF3, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX - 0x00DC: 0x86, # LATIN CAPITAL LETTER U WITH DIAERESIS - 0x00DF: 0xA7, # LATIN SMALL LETTER SHARP S - 0x00E0: 0x88, # LATIN SMALL LETTER A WITH GRAVE - 0x00E1: 0x87, # LATIN SMALL LETTER A WITH ACUTE - 0x00E2: 0x89, # LATIN SMALL LETTER A WITH CIRCUMFLEX - 0x00E3: 0x8B, # LATIN SMALL LETTER A WITH TILDE - 0x00E4: 0x8A, # LATIN SMALL LETTER A WITH DIAERESIS - 0x00E5: 0x8C, # LATIN SMALL LETTER A WITH RING ABOVE - 0x00E6: 0xBE, # LATIN SMALL LETTER AE - 0x00E7: 0x8D, # LATIN SMALL LETTER C WITH CEDILLA - 0x00E8: 0x8F, # LATIN SMALL LETTER E WITH GRAVE - 0x00E9: 0x8E, # LATIN SMALL LETTER E WITH ACUTE - 0x00EA: 0x90, # LATIN SMALL LETTER E WITH CIRCUMFLEX - 0x00EB: 0x91, # LATIN SMALL LETTER E WITH DIAERESIS - 0x00EC: 0x93, # LATIN SMALL LETTER I WITH GRAVE - 0x00ED: 0x92, # LATIN SMALL LETTER I WITH ACUTE - 0x00EE: 0x94, # LATIN SMALL LETTER I WITH CIRCUMFLEX - 0x00EF: 0x95, # LATIN SMALL LETTER I WITH DIAERESIS - 0x00F1: 0x96, # LATIN SMALL LETTER N WITH TILDE - 0x00F2: 0x98, # LATIN SMALL LETTER O WITH GRAVE - 0x00F3: 0x97, # LATIN SMALL LETTER O WITH ACUTE - 0x00F4: 0x99, # LATIN SMALL LETTER O WITH CIRCUMFLEX - 0x00F5: 0x9B, # LATIN SMALL LETTER O WITH TILDE - 0x00F6: 0x9A, # LATIN SMALL LETTER O WITH DIAERESIS - 0x00F7: 0xD6, # DIVISION SIGN - 0x00F8: 0xBF, # LATIN SMALL LETTER O WITH STROKE - 0x00F9: 0x9D, # LATIN SMALL LETTER U WITH GRAVE - 0x00FA: 0x9C, # LATIN SMALL LETTER U WITH ACUTE - 0x00FB: 0x9E, # LATIN SMALL LETTER U WITH CIRCUMFLEX - 0x00FC: 0x9F, # LATIN SMALL LETTER U WITH DIAERESIS - 0x00FF: 0xD8, # LATIN SMALL LETTER Y WITH DIAERESIS - 0x011E: 0xDA, # LATIN CAPITAL LETTER G WITH BREVE - 0x011F: 0xDB, # LATIN SMALL LETTER G WITH BREVE - 0x0130: 0xDC, # LATIN CAPITAL LETTER I WITH DOT ABOVE - 0x0131: 0xDD, # LATIN SMALL LETTER DOTLESS I - 0x0152: 0xCE, # LATIN CAPITAL LIGATURE OE - 0x0153: 0xCF, # LATIN SMALL LIGATURE OE - 0x015E: 0xDE, # LATIN CAPITAL LETTER S WITH CEDILLA - 0x015F: 0xDF, # LATIN SMALL LETTER S WITH CEDILLA - 0x0178: 0xD9, # LATIN CAPITAL LETTER Y WITH DIAERESIS - 0x0192: 0xC4, # LATIN SMALL LETTER F WITH HOOK - 0x02C6: 0xF6, # MODIFIER LETTER CIRCUMFLEX ACCENT - 0x02C7: 0xFF, # CARON - 0x02D8: 0xF9, # BREVE - 0x02D9: 0xFA, # DOT ABOVE - 0x02DA: 0xFB, # RING ABOVE - 0x02DB: 0xFE, # OGONEK - 0x02DC: 0xF7, # SMALL TILDE - 0x02DD: 0xFD, # DOUBLE ACUTE ACCENT - 0x03A9: 0xBD, # GREEK CAPITAL LETTER OMEGA - 0x03C0: 0xB9, # GREEK SMALL LETTER PI - 0x2013: 0xD0, # EN DASH - 0x2014: 0xD1, # EM DASH - 0x2018: 0xD4, # LEFT SINGLE QUOTATION MARK - 0x2019: 0xD5, # RIGHT SINGLE QUOTATION MARK - 0x201A: 0xE2, # SINGLE LOW-9 QUOTATION MARK - 0x201C: 0xD2, # LEFT DOUBLE QUOTATION MARK - 0x201D: 0xD3, # RIGHT DOUBLE QUOTATION MARK - 0x201E: 0xE3, # DOUBLE LOW-9 QUOTATION MARK - 0x2020: 0xA0, # DAGGER - 0x2021: 0xE0, # DOUBLE DAGGER - 0x2022: 0xA5, # BULLET - 0x2026: 0xC9, # HORIZONTAL ELLIPSIS - 0x2030: 0xE4, # PER MILLE SIGN - 0x2122: 0xAA, # TRADE MARK SIGN - 0x2202: 0xB6, # PARTIAL DIFFERENTIAL - 0x2206: 0xC6, # INCREMENT - 0x220F: 0xB8, # N-ARY PRODUCT - 0x2211: 0xB7, # N-ARY SUMMATION - 0x221A: 0xC3, # SQUARE ROOT - 0x221E: 0xB0, # INFINITY - 0x222B: 0xBA, # INTEGRAL - 0x2248: 0xC5, # ALMOST EQUAL TO - 0x2260: 0xAD, # NOT EQUAL TO - 0x2264: 0xB2, # LESS-THAN OR EQUAL TO - 0x2265: 0xB3, # GREATER-THAN OR EQUAL TO - 0x25CA: 0xD7, # LOZENGE - 0xF8A0: 0xF5, # undefined1 - 0xF8FF: 0xF0, # Apple logo -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/encodings/tis_620.py b/Lib/encodings/tis_620.py index 166d932..b2cd22b 100644 --- a/Lib/encodings/tis_620.py +++ b/Lib/encodings/tis_620.py @@ -9,14 +9,14 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) + return codecs.charmap_encode(input,errors,encoding_table) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_table) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_table)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): @@ -303,254 +303,5 @@ decoding_table = ( u'\ufffe' ) -### Encoding Map - -encoding_map = { - 0x0000: 0x00, # NULL - 0x0001: 0x01, # START OF HEADING - 0x0002: 0x02, # START OF TEXT - 0x0003: 0x03, # END OF TEXT - 0x0004: 0x04, # END OF TRANSMISSION - 0x0005: 0x05, # ENQUIRY - 0x0006: 0x06, # ACKNOWLEDGE - 0x0007: 0x07, # BELL - 0x0008: 0x08, # BACKSPACE - 0x0009: 0x09, # HORIZONTAL TABULATION - 0x000A: 0x0A, # LINE FEED - 0x000B: 0x0B, # VERTICAL TABULATION - 0x000C: 0x0C, # FORM FEED - 0x000D: 0x0D, # CARRIAGE RETURN - 0x000E: 0x0E, # SHIFT OUT - 0x000F: 0x0F, # SHIFT IN - 0x0010: 0x10, # DATA LINK ESCAPE - 0x0011: 0x11, # DEVICE CONTROL ONE - 0x0012: 0x12, # DEVICE CONTROL TWO - 0x0013: 0x13, # DEVICE CONTROL THREE - 0x0014: 0x14, # DEVICE CONTROL FOUR - 0x0015: 0x15, # NEGATIVE ACKNOWLEDGE - 0x0016: 0x16, # SYNCHRONOUS IDLE - 0x0017: 0x17, # END OF TRANSMISSION BLOCK - 0x0018: 0x18, # CANCEL - 0x0019: 0x19, # END OF MEDIUM - 0x001A: 0x1A, # SUBSTITUTE - 0x001B: 0x1B, # ESCAPE - 0x001C: 0x1C, # FILE SEPARATOR - 0x001D: 0x1D, # GROUP SEPARATOR - 0x001E: 0x1E, # RECORD SEPARATOR - 0x001F: 0x1F, # UNIT SEPARATOR - 0x0020: 0x20, # SPACE - 0x0021: 0x21, # EXCLAMATION MARK - 0x0022: 0x22, # QUOTATION MARK - 0x0023: 0x23, # NUMBER SIGN - 0x0024: 0x24, # DOLLAR SIGN - 0x0025: 0x25, # PERCENT SIGN - 0x0026: 0x26, # AMPERSAND - 0x0027: 0x27, # APOSTROPHE - 0x0028: 0x28, # LEFT PARENTHESIS - 0x0029: 0x29, # RIGHT PARENTHESIS - 0x002A: 0x2A, # ASTERISK - 0x002B: 0x2B, # PLUS SIGN - 0x002C: 0x2C, # COMMA - 0x002D: 0x2D, # HYPHEN-MINUS - 0x002E: 0x2E, # FULL STOP - 0x002F: 0x2F, # SOLIDUS - 0x0030: 0x30, # DIGIT ZERO - 0x0031: 0x31, # DIGIT ONE - 0x0032: 0x32, # DIGIT TWO - 0x0033: 0x33, # DIGIT THREE - 0x0034: 0x34, # DIGIT FOUR - 0x0035: 0x35, # DIGIT FIVE - 0x0036: 0x36, # DIGIT SIX - 0x0037: 0x37, # DIGIT SEVEN - 0x0038: 0x38, # DIGIT EIGHT - 0x0039: 0x39, # DIGIT NINE - 0x003A: 0x3A, # COLON - 0x003B: 0x3B, # SEMICOLON - 0x003C: 0x3C, # LESS-THAN SIGN - 0x003D: 0x3D, # EQUALS SIGN - 0x003E: 0x3E, # GREATER-THAN SIGN - 0x003F: 0x3F, # QUESTION MARK - 0x0040: 0x40, # COMMERCIAL AT - 0x0041: 0x41, # LATIN CAPITAL LETTER A - 0x0042: 0x42, # LATIN CAPITAL LETTER B - 0x0043: 0x43, # LATIN CAPITAL LETTER C - 0x0044: 0x44, # LATIN CAPITAL LETTER D - 0x0045: 0x45, # LATIN CAPITAL LETTER E - 0x0046: 0x46, # LATIN CAPITAL LETTER F - 0x0047: 0x47, # LATIN CAPITAL LETTER G - 0x0048: 0x48, # LATIN CAPITAL LETTER H - 0x0049: 0x49, # LATIN CAPITAL LETTER I - 0x004A: 0x4A, # LATIN CAPITAL LETTER J - 0x004B: 0x4B, # LATIN CAPITAL LETTER K - 0x004C: 0x4C, # LATIN CAPITAL LETTER L - 0x004D: 0x4D, # LATIN CAPITAL LETTER M - 0x004E: 0x4E, # LATIN CAPITAL LETTER N - 0x004F: 0x4F, # LATIN CAPITAL LETTER O - 0x0050: 0x50, # LATIN CAPITAL LETTER P - 0x0051: 0x51, # LATIN CAPITAL LETTER Q - 0x0052: 0x52, # LATIN CAPITAL LETTER R - 0x0053: 0x53, # LATIN CAPITAL LETTER S - 0x0054: 0x54, # LATIN CAPITAL LETTER T - 0x0055: 0x55, # LATIN CAPITAL LETTER U - 0x0056: 0x56, # LATIN CAPITAL LETTER V - 0x0057: 0x57, # LATIN CAPITAL LETTER W - 0x0058: 0x58, # LATIN CAPITAL LETTER X - 0x0059: 0x59, # LATIN CAPITAL LETTER Y - 0x005A: 0x5A, # LATIN CAPITAL LETTER Z - 0x005B: 0x5B, # LEFT SQUARE BRACKET - 0x005C: 0x5C, # REVERSE SOLIDUS - 0x005D: 0x5D, # RIGHT SQUARE BRACKET - 0x005E: 0x5E, # CIRCUMFLEX ACCENT - 0x005F: 0x5F, # LOW LINE - 0x0060: 0x60, # GRAVE ACCENT - 0x0061: 0x61, # LATIN SMALL LETTER A - 0x0062: 0x62, # LATIN SMALL LETTER B - 0x0063: 0x63, # LATIN SMALL LETTER C - 0x0064: 0x64, # LATIN SMALL LETTER D - 0x0065: 0x65, # LATIN SMALL LETTER E - 0x0066: 0x66, # LATIN SMALL LETTER F - 0x0067: 0x67, # LATIN SMALL LETTER G - 0x0068: 0x68, # LATIN SMALL LETTER H - 0x0069: 0x69, # LATIN SMALL LETTER I - 0x006A: 0x6A, # LATIN SMALL LETTER J - 0x006B: 0x6B, # LATIN SMALL LETTER K - 0x006C: 0x6C, # LATIN SMALL LETTER L - 0x006D: 0x6D, # LATIN SMALL LETTER M - 0x006E: 0x6E, # LATIN SMALL LETTER N - 0x006F: 0x6F, # LATIN SMALL LETTER O - 0x0070: 0x70, # LATIN SMALL LETTER P - 0x0071: 0x71, # LATIN SMALL LETTER Q - 0x0072: 0x72, # LATIN SMALL LETTER R - 0x0073: 0x73, # LATIN SMALL LETTER S - 0x0074: 0x74, # LATIN SMALL LETTER T - 0x0075: 0x75, # LATIN SMALL LETTER U - 0x0076: 0x76, # LATIN SMALL LETTER V - 0x0077: 0x77, # LATIN SMALL LETTER W - 0x0078: 0x78, # LATIN SMALL LETTER X - 0x0079: 0x79, # LATIN SMALL LETTER Y - 0x007A: 0x7A, # LATIN SMALL LETTER Z - 0x007B: 0x7B, # LEFT CURLY BRACKET - 0x007C: 0x7C, # VERTICAL LINE - 0x007D: 0x7D, # RIGHT CURLY BRACKET - 0x007E: 0x7E, # TILDE - 0x007F: 0x7F, # DELETE - 0x0080: 0x80, # - 0x0081: 0x81, # - 0x0082: 0x82, # - 0x0083: 0x83, # - 0x0084: 0x84, # - 0x0085: 0x85, # - 0x0086: 0x86, # - 0x0087: 0x87, # - 0x0088: 0x88, # - 0x0089: 0x89, # - 0x008A: 0x8A, # - 0x008B: 0x8B, # - 0x008C: 0x8C, # - 0x008D: 0x8D, # - 0x008E: 0x8E, # - 0x008F: 0x8F, # - 0x0090: 0x90, # - 0x0091: 0x91, # - 0x0092: 0x92, # - 0x0093: 0x93, # - 0x0094: 0x94, # - 0x0095: 0x95, # - 0x0096: 0x96, # - 0x0097: 0x97, # - 0x0098: 0x98, # - 0x0099: 0x99, # - 0x009A: 0x9A, # - 0x009B: 0x9B, # - 0x009C: 0x9C, # - 0x009D: 0x9D, # - 0x009E: 0x9E, # - 0x009F: 0x9F, # - 0x0E01: 0xA1, # THAI CHARACTER KO KAI - 0x0E02: 0xA2, # THAI CHARACTER KHO KHAI - 0x0E03: 0xA3, # THAI CHARACTER KHO KHUAT - 0x0E04: 0xA4, # THAI CHARACTER KHO KHWAI - 0x0E05: 0xA5, # THAI CHARACTER KHO KHON - 0x0E06: 0xA6, # THAI CHARACTER KHO RAKHANG - 0x0E07: 0xA7, # THAI CHARACTER NGO NGU - 0x0E08: 0xA8, # THAI CHARACTER CHO CHAN - 0x0E09: 0xA9, # THAI CHARACTER CHO CHING - 0x0E0A: 0xAA, # THAI CHARACTER CHO CHANG - 0x0E0B: 0xAB, # THAI CHARACTER SO SO - 0x0E0C: 0xAC, # THAI CHARACTER CHO CHOE - 0x0E0D: 0xAD, # THAI CHARACTER YO YING - 0x0E0E: 0xAE, # THAI CHARACTER DO CHADA - 0x0E0F: 0xAF, # THAI CHARACTER TO PATAK - 0x0E10: 0xB0, # THAI CHARACTER THO THAN - 0x0E11: 0xB1, # THAI CHARACTER THO NANGMONTHO - 0x0E12: 0xB2, # THAI CHARACTER THO PHUTHAO - 0x0E13: 0xB3, # THAI CHARACTER NO NEN - 0x0E14: 0xB4, # THAI CHARACTER DO DEK - 0x0E15: 0xB5, # THAI CHARACTER TO TAO - 0x0E16: 0xB6, # THAI CHARACTER THO THUNG - 0x0E17: 0xB7, # THAI CHARACTER THO THAHAN - 0x0E18: 0xB8, # THAI CHARACTER THO THONG - 0x0E19: 0xB9, # THAI CHARACTER NO NU - 0x0E1A: 0xBA, # THAI CHARACTER BO BAIMAI - 0x0E1B: 0xBB, # THAI CHARACTER PO PLA - 0x0E1C: 0xBC, # THAI CHARACTER PHO PHUNG - 0x0E1D: 0xBD, # THAI CHARACTER FO FA - 0x0E1E: 0xBE, # THAI CHARACTER PHO PHAN - 0x0E1F: 0xBF, # THAI CHARACTER FO FAN - 0x0E20: 0xC0, # THAI CHARACTER PHO SAMPHAO - 0x0E21: 0xC1, # THAI CHARACTER MO MA - 0x0E22: 0xC2, # THAI CHARACTER YO YAK - 0x0E23: 0xC3, # THAI CHARACTER RO RUA - 0x0E24: 0xC4, # THAI CHARACTER RU - 0x0E25: 0xC5, # THAI CHARACTER LO LING - 0x0E26: 0xC6, # THAI CHARACTER LU - 0x0E27: 0xC7, # THAI CHARACTER WO WAEN - 0x0E28: 0xC8, # THAI CHARACTER SO SALA - 0x0E29: 0xC9, # THAI CHARACTER SO RUSI - 0x0E2A: 0xCA, # THAI CHARACTER SO SUA - 0x0E2B: 0xCB, # THAI CHARACTER HO HIP - 0x0E2C: 0xCC, # THAI CHARACTER LO CHULA - 0x0E2D: 0xCD, # THAI CHARACTER O ANG - 0x0E2E: 0xCE, # THAI CHARACTER HO NOKHUK - 0x0E2F: 0xCF, # THAI CHARACTER PAIYANNOI - 0x0E30: 0xD0, # THAI CHARACTER SARA A - 0x0E31: 0xD1, # THAI CHARACTER MAI HAN-AKAT - 0x0E32: 0xD2, # THAI CHARACTER SARA AA - 0x0E33: 0xD3, # THAI CHARACTER SARA AM - 0x0E34: 0xD4, # THAI CHARACTER SARA I - 0x0E35: 0xD5, # THAI CHARACTER SARA II - 0x0E36: 0xD6, # THAI CHARACTER SARA UE - 0x0E37: 0xD7, # THAI CHARACTER SARA UEE - 0x0E38: 0xD8, # THAI CHARACTER SARA U - 0x0E39: 0xD9, # THAI CHARACTER SARA UU - 0x0E3A: 0xDA, # THAI CHARACTER PHINTHU - 0x0E3F: 0xDF, # THAI CURRENCY SYMBOL BAHT - 0x0E40: 0xE0, # THAI CHARACTER SARA E - 0x0E41: 0xE1, # THAI CHARACTER SARA AE - 0x0E42: 0xE2, # THAI CHARACTER SARA O - 0x0E43: 0xE3, # THAI CHARACTER SARA AI MAIMUAN - 0x0E44: 0xE4, # THAI CHARACTER SARA AI MAIMALAI - 0x0E45: 0xE5, # THAI CHARACTER LAKKHANGYAO - 0x0E46: 0xE6, # THAI CHARACTER MAIYAMOK - 0x0E47: 0xE7, # THAI CHARACTER MAITAIKHU - 0x0E48: 0xE8, # THAI CHARACTER MAI EK - 0x0E49: 0xE9, # THAI CHARACTER MAI THO - 0x0E4A: 0xEA, # THAI CHARACTER MAI TRI - 0x0E4B: 0xEB, # THAI CHARACTER MAI CHATTAWA - 0x0E4C: 0xEC, # THAI CHARACTER THANTHAKHAT - 0x0E4D: 0xED, # THAI CHARACTER NIKHAHIT - 0x0E4E: 0xEE, # THAI CHARACTER YAMAKKAN - 0x0E4F: 0xEF, # THAI CHARACTER FONGMAN - 0x0E50: 0xF0, # THAI DIGIT ZERO - 0x0E51: 0xF1, # THAI DIGIT ONE - 0x0E52: 0xF2, # THAI DIGIT TWO - 0x0E53: 0xF3, # THAI DIGIT THREE - 0x0E54: 0xF4, # THAI DIGIT FOUR - 0x0E55: 0xF5, # THAI DIGIT FIVE - 0x0E56: 0xF6, # THAI DIGIT SIX - 0x0E57: 0xF7, # THAI DIGIT SEVEN - 0x0E58: 0xF8, # THAI DIGIT EIGHT - 0x0E59: 0xF9, # THAI DIGIT NINE - 0x0E5A: 0xFA, # THAI CHARACTER ANGKHANKHU - 0x0E5B: 0xFB, # THAI CHARACTER KHOMUT -} +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) diff --git a/Lib/functools.py b/Lib/functools.py index 4935c9f..8783f08 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -1,26 +1,51 @@ -"""functools.py - Tools for working with functions +"""functools.py - Tools for working with functions and callable objects """ # Python module wrapper for _functools C module # to allow utilities written in Python to be added # to the functools module. # Written by Nick Coghlan -# Copyright (c) 2006 Python Software Foundation. +# Copyright (C) 2006 Python Software Foundation. +# See C source code for _functools credits/copyright from _functools import partial -__all__ = [ - "partial", -] -# Still to come here (need to write tests and docs): -# update_wrapper - utility function to transfer basic function -# metadata to wrapper functions -# WRAPPER_ASSIGNMENTS & WRAPPER_UPDATES - defaults args to above -# (update_wrapper has been approved by BDFL) -# wraps - decorator factory equivalent to: -# def wraps(f): -# return partial(update_wrapper, wrapped=f) -# -# The wraps function makes it easy to avoid the bug that afflicts the -# decorator example in the python-dev email proposing the -# update_wrapper function: -# http://mail.python.org/pipermail/python-dev/2006-May/064775.html +# update_wrapper() and wraps() are tools to help write +# wrapper functions that can handle naive introspection + +WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__') +WRAPPER_UPDATES = ('__dict__',) +def update_wrapper(wrapper, + wrapped, + assigned = WRAPPER_ASSIGNMENTS, + updated = WRAPPER_UPDATES): + """Update a wrapper function to look like the wrapped function + + wrapper is the function to be updated + wrapped is the original function + assigned is a tuple naming the attributes assigned directly + from the wrapped function to the wrapper function (defaults to + functools.WRAPPER_ASSIGNMENTS) + updated is a tuple naming the attributes off the wrapper that + are updated with the corresponding attribute from the wrapped + function (defaults to functools.WRAPPER_UPDATES) + """ + for attr in assigned: + setattr(wrapper, attr, getattr(wrapped, attr)) + for attr in updated: + getattr(wrapper, attr).update(getattr(wrapped, attr)) + # Return the wrapper so this can be used as a decorator via partial() + return wrapper + +def wraps(wrapped, + assigned = WRAPPER_ASSIGNMENTS, + updated = WRAPPER_UPDATES): + """Decorator factory to apply update_wrapper() to a wrapper function + + Returns a decorator that invokes update_wrapper() with the decorated + function as the wrapper argument and the arguments to wraps() as the + remaining arguments. Default arguments are as for update_wrapper(). + This is a convenience function to simplify applying partial() to + update_wrapper(). + """ + return partial(update_wrapper, wrapped=wrapped, + assigned=assigned, updated=updated) diff --git a/Lib/lib-tk/Tix.py b/Lib/lib-tk/Tix.py index 14c3c24..33ac519 100755 --- a/Lib/lib-tk/Tix.py +++ b/Lib/lib-tk/Tix.py @@ -468,7 +468,7 @@ class DisplayStyle: """DisplayStyle - handle configuration options shared by (multiple) Display Items""" - def __init__(self, itemtype, cnf={}, **kw ): + def __init__(self, itemtype, cnf={}, **kw): master = _default_root # global from Tkinter if not master and cnf.has_key('refwindow'): master=cnf['refwindow'] elif not master and kw.has_key('refwindow'): master= kw['refwindow'] @@ -480,7 +480,7 @@ class DisplayStyle: def __str__(self): return self.stylename - def _options(self, cnf, kw ): + def _options(self, cnf, kw): if kw and cnf: cnf = _cnfmerge((cnf, kw)) elif kw: diff --git a/Lib/markupbase.py b/Lib/markupbase.py index 85b07a2..24808d1 100644 --- a/Lib/markupbase.py +++ b/Lib/markupbase.py @@ -140,7 +140,7 @@ class ParserBase: # Internal -- parse a marked section # Override this to handle MS-word extension syntax content - def parse_marked_section( self, i, report=1 ): + def parse_marked_section(self, i, report=1): rawdata= self.rawdata assert rawdata[i:i+3] == 'R') -weTagDirectionRightToLeft = FOUR_CHAR_CODE('R->L') -weTagBorderStyleNone = FOUR_CHAR_CODE('NONE') -weTagBorderStyleThin = FOUR_CHAR_CODE('SLDL') -weTagBorderStyleDotted = FOUR_CHAR_CODE('DTDL') -weTagBorderStyleThick = FOUR_CHAR_CODE('THKL') -weLineSpacingSingle = 0x00000000 -weLineSpacingOneAndHalf = 0x00008000 -weLineSpacingDouble = 0x00010000 -weCharByteHook = FOUR_CHAR_CODE('cbyt') -weCharToPixelHook = FOUR_CHAR_CODE('c2p ') -weCharTypeHook = FOUR_CHAR_CODE('ctyp') -weClickLoop = FOUR_CHAR_CODE('clik') -weCurrentDrag = FOUR_CHAR_CODE('drag') -weDrawTextHook = FOUR_CHAR_CODE('draw') -weDrawTSMHiliteHook = FOUR_CHAR_CODE('dtsm') -weEraseHook = FOUR_CHAR_CODE('eras') -weFontFamilyToNameHook = FOUR_CHAR_CODE('ff2n') -weFontNameToFamilyHook = FOUR_CHAR_CODE('fn2f') -weFluxProc = FOUR_CHAR_CODE('flux') -weHiliteDropAreaHook = FOUR_CHAR_CODE('hidr') -weLineBreakHook = FOUR_CHAR_CODE('lbrk') -wePixelToCharHook = FOUR_CHAR_CODE('p2c ') -wePort = FOUR_CHAR_CODE('port') -wePreTrackDragHook = FOUR_CHAR_CODE('ptrk') -weRefCon = FOUR_CHAR_CODE('refc') -weScrollProc = FOUR_CHAR_CODE('scrl') -weText = FOUR_CHAR_CODE('text') -weTranslateDragHook = FOUR_CHAR_CODE('xdrg') -weTranslucencyThreshold = FOUR_CHAR_CODE('tluc') -weTSMDocumentID = FOUR_CHAR_CODE('tsmd') -weTSMPreUpdate = FOUR_CHAR_CODE('pre ') -weTSMPostUpdate = FOUR_CHAR_CODE('post') -weURLHint = FOUR_CHAR_CODE('urlh') -weWordBreakHook = FOUR_CHAR_CODE('wbrk') -weNewHandler = FOUR_CHAR_CODE('new ') -weDisposeHandler = FOUR_CHAR_CODE('free') -weDrawHandler = FOUR_CHAR_CODE('draw') -weClickHandler = FOUR_CHAR_CODE('clik') -weStreamHandler = FOUR_CHAR_CODE('strm') -weHoverHandler = FOUR_CHAR_CODE('hovr') -kTypeText = FOUR_CHAR_CODE('TEXT') -kTypeStyles = FOUR_CHAR_CODE('styl') -kTypeSoup = FOUR_CHAR_CODE('SOUP') -kTypeFontTable = FOUR_CHAR_CODE('FISH') -kTypeParaFormat = FOUR_CHAR_CODE('WEpf') -kTypeRulerScrap = FOUR_CHAR_CODE('WEru') -kTypeCharFormat = FOUR_CHAR_CODE('WEcf') -kTypeStyleScrap = FOUR_CHAR_CODE('WEst') -kTypeUnicodeText = FOUR_CHAR_CODE('utxt') -kTypeUTF8Text = FOUR_CHAR_CODE('UTF8') -kTypeStyledText = FOUR_CHAR_CODE('STXT') -weAKNone = 0 -weAKUnspecified = 1 -weAKTyping = 2 -weAKCut = 3 -weAKPaste = 4 -weAKClear = 5 -weAKDrag = 6 -weAKSetStyle = 7 -weAKSetRuler = 8 -weAKBackspace = 9 -weAKFwdDelete = 10 -weAKCaseChange = 11 -weAKObjectChange = 12 -weToScrap = 0 -weToDrag = 1 -weToSoup = 2 -weMouseEnter = 0 -weMouseWithin = 1 -weMouseLeave = 2 -kCurrentSelection = -1 -kNullStyle = -2 diff --git a/Lib/plat-mac/EasyDialogs.py b/Lib/plat-mac/EasyDialogs.py index c622d30..b33d1be 100644 --- a/Lib/plat-mac/EasyDialogs.py +++ b/Lib/plat-mac/EasyDialogs.py @@ -262,7 +262,7 @@ class ProgressBar: self.w.ShowWindow() self.d.DrawDialog() - def __del__( self ): + def __del__(self): if self.w: self.w.BringToFront() self.w.HideWindow() @@ -274,7 +274,7 @@ class ProgressBar: self.w.BringToFront() self.w.SetWTitle(newstr) - def label( self, *newstr ): + def label(self, *newstr): """label(text) - Set text in progress box""" self.w.BringToFront() if newstr: diff --git a/Lib/plat-mac/WASTEconst.py b/Lib/plat-mac/WASTEconst.py deleted file mode 100644 index f453338..0000000 --- a/Lib/plat-mac/WASTEconst.py +++ /dev/null @@ -1,207 +0,0 @@ -# Generated from 'WASTE.h' - -kPascalStackBased = None # workaround for header parsing -def FOUR_CHAR_CODE(x): return x -weCantUndoErr = -10015 -weEmptySelectionErr = -10013 -weUnknownObjectTypeErr = -9478 -weObjectNotFoundErr = -9477 -weReadOnlyErr = -9476 -weTextNotFoundErr = -9474 -weInvalidTextEncodingErr = -9473 -weDuplicateAttributeErr = -9472 -weInvalidAttributeSizeErr = -9471 -weReadOnlyAttributeErr = -9470 -weOddByteCountErr = -9469 -weHandlerNotFoundErr = -1717 -weNotHandledErr = -1708 -weNewerVersionErr = -1706 -weCorruptDataErr = -1702 -weProtocolErr = -603 -weUndefinedSelectorErr = -50 -weFlushLeft = -2 -weFlushRight = -1 -weFlushDefault = 0 -weCenter = 1 -weJustify = 2 -weDirDefault = 1 -weDirRightToLeft = -1 -weDirLeftToRight = 0 -weDoFont = 0x0001 -weDoFace = 0x0002 -weDoSize = 0x0004 -weDoColor = 0x0008 -weDoAll = weDoFont | weDoFace | weDoSize | weDoColor -weDoAddSize = 0x0010 -weDoToggleFace = 0x0020 -weDoReplaceFace = 0x0040 -weDoPreserveScript = 0x0080 -weDoExtractSubscript = 0x0100 -weDoFaceMask = 0x0200 -weDoDirection = 0x00000001 -weDoAlignment = 0x00000002 -weDoLeftIndent = 0x00000004 -weDoRightIndent = 0x00000008 -weDoFirstLineIndent = 0x00000010 -weDoLineSpacing = 0x00000020 -weDoSpaceBefore = 0x00000040 -weDoSpaceAfter = 0x00000080 -weDoBottomBorderStyle = 0x00000400 -kLeadingEdge = -1 -kTrailingEdge = 0 -kObjectEdge = 2 -weFAutoScroll = 0 -weFOutlineHilite = 2 -weFReadOnly = 5 -weFUndo = 6 -weFIntCutAndPaste = 7 -weFDragAndDrop = 8 -weFInhibitRecal = 9 -weFUseTempMem = 10 -weFDrawOffscreen = 11 -weFInhibitRedraw = 12 -weFMonoStyled = 13 -weFMultipleUndo = 14 -weFNoKeyboardSync = 29 -weFInhibitICSupport = 30 -weFInhibitColor = 31 -weDoAutoScroll = 1 << weFAutoScroll -weDoOutlineHilite = 1 << weFOutlineHilite -weDoReadOnly = 1 << weFReadOnly -weDoUndo = 1 << weFUndo -weDoIntCutAndPaste = 1 << weFIntCutAndPaste -weDoDragAndDrop = 1 << weFDragAndDrop -weDoInhibitRecal = 1 << weFInhibitRecal -weDoUseTempMem = 1 << weFUseTempMem -weDoDrawOffscreen = 1 << weFDrawOffscreen -weDoInhibitRedraw = 1 << weFInhibitRedraw -weDoMonoStyled = 1 << weFMonoStyled -weDoMultipleUndo = 1 << weFMultipleUndo -weDoNoKeyboardSync = 1 << weFNoKeyboardSync -weDoInhibitICSupport = 1 << weFInhibitICSupport -# weDoInhibitColor = 1 << weFInhibitColor -weBitToggle = -2 -weBitTest = -1 -weBitClear = 0 -weBitSet = 1 -weLowerCase = 0 -weUpperCase = 1 -weFindWholeWords = 0x00000001 -weFindCaseInsensitive = 0x00000002 -weFindDiacriticalInsensitive = 0x00000004 -wePutIntCutAndPaste = 0x00000001 -wePutAddToTypingSequence = 0x00000002 -wePutDetectUnicodeBOM = 0x00000200 -weStreamDestinationKindMask = 0x000000FF -weStreamIncludeObjects = 0x00000100 -weGetAddUnicodeBOM = 0x00000200 -weGetLittleEndian = 0x00000400 -weTagFontFamily = FOUR_CHAR_CODE('font') -weTagFontSize = FOUR_CHAR_CODE('ptsz') -weTagPlain = FOUR_CHAR_CODE('plan') -weTagBold = FOUR_CHAR_CODE('bold') -weTagItalic = FOUR_CHAR_CODE('ital') -weTagUnderline = FOUR_CHAR_CODE('undl') -weTagOutline = FOUR_CHAR_CODE('outl') -weTagShadow = FOUR_CHAR_CODE('shad') -weTagCondensed = FOUR_CHAR_CODE('cond') -weTagExtended = FOUR_CHAR_CODE('pexp') -weTagStrikethrough = FOUR_CHAR_CODE('strk') -weTagTextColor = FOUR_CHAR_CODE('colr') -weTagBackgroundColor = FOUR_CHAR_CODE('pbcl') -weTagTransferMode = FOUR_CHAR_CODE('pptm') -weTagVerticalShift = FOUR_CHAR_CODE('xshf') -weTagAlignment = FOUR_CHAR_CODE('pjst') -weTagDirection = FOUR_CHAR_CODE('LDIR') -weTagLineSpacing = FOUR_CHAR_CODE('ledg') -weTagLeftIndent = FOUR_CHAR_CODE('lein') -weTagRightIndent = FOUR_CHAR_CODE('riin') -weTagFirstLineIndent = FOUR_CHAR_CODE('fidt') -weTagSpaceBefore = FOUR_CHAR_CODE('spbe') -weTagSpaceAfter = FOUR_CHAR_CODE('spaf') -weTagBottomBorderStyle = FOUR_CHAR_CODE('BBRD') -weTagForceFontFamily = FOUR_CHAR_CODE('ffnt') -weTagAddFontSize = FOUR_CHAR_CODE('+siz') -weTagAddVerticalShift = FOUR_CHAR_CODE('+shf') -weTagTextEncoding = FOUR_CHAR_CODE('ptxe') -weTagQDStyles = FOUR_CHAR_CODE('qdst') -weTagTETextStyle = FOUR_CHAR_CODE('tets') -weTagAlignmentDefault = FOUR_CHAR_CODE('deft') -weTagAlignmentLeft = FOUR_CHAR_CODE('left') -weTagAlignmentCenter = FOUR_CHAR_CODE('cent') -weTagAlignmentRight = FOUR_CHAR_CODE('rght') -weTagAlignmentFull = FOUR_CHAR_CODE('full') -weTagDirectionDefault = FOUR_CHAR_CODE('deft') -weTagDirectionLeftToRight = FOUR_CHAR_CODE('L->R') -weTagDirectionRightToLeft = FOUR_CHAR_CODE('R->L') -weTagBorderStyleNone = FOUR_CHAR_CODE('NONE') -weTagBorderStyleThin = FOUR_CHAR_CODE('SLDL') -weTagBorderStyleDotted = FOUR_CHAR_CODE('DTDL') -weTagBorderStyleThick = FOUR_CHAR_CODE('THKL') -weLineSpacingSingle = 0x00000000 -weLineSpacingOneAndHalf = 0x00008000 -weLineSpacingDouble = 0x00010000 -weCharByteHook = FOUR_CHAR_CODE('cbyt') -weCharToPixelHook = FOUR_CHAR_CODE('c2p ') -weCharTypeHook = FOUR_CHAR_CODE('ctyp') -weClickLoop = FOUR_CHAR_CODE('clik') -weCurrentDrag = FOUR_CHAR_CODE('drag') -weDrawTextHook = FOUR_CHAR_CODE('draw') -weDrawTSMHiliteHook = FOUR_CHAR_CODE('dtsm') -weEraseHook = FOUR_CHAR_CODE('eras') -weFontFamilyToNameHook = FOUR_CHAR_CODE('ff2n') -weFontNameToFamilyHook = FOUR_CHAR_CODE('fn2f') -weFluxProc = FOUR_CHAR_CODE('flux') -weHiliteDropAreaHook = FOUR_CHAR_CODE('hidr') -weLineBreakHook = FOUR_CHAR_CODE('lbrk') -wePixelToCharHook = FOUR_CHAR_CODE('p2c ') -wePort = FOUR_CHAR_CODE('port') -wePreTrackDragHook = FOUR_CHAR_CODE('ptrk') -weRefCon = FOUR_CHAR_CODE('refc') -weScrollProc = FOUR_CHAR_CODE('scrl') -weText = FOUR_CHAR_CODE('text') -weTranslateDragHook = FOUR_CHAR_CODE('xdrg') -weTranslucencyThreshold = FOUR_CHAR_CODE('tluc') -weTSMDocumentID = FOUR_CHAR_CODE('tsmd') -weTSMPreUpdate = FOUR_CHAR_CODE('pre ') -weTSMPostUpdate = FOUR_CHAR_CODE('post') -weURLHint = FOUR_CHAR_CODE('urlh') -weWordBreakHook = FOUR_CHAR_CODE('wbrk') -weNewHandler = FOUR_CHAR_CODE('new ') -weDisposeHandler = FOUR_CHAR_CODE('free') -weDrawHandler = FOUR_CHAR_CODE('draw') -weClickHandler = FOUR_CHAR_CODE('clik') -weStreamHandler = FOUR_CHAR_CODE('strm') -weHoverHandler = FOUR_CHAR_CODE('hovr') -kTypeText = FOUR_CHAR_CODE('TEXT') -kTypeStyles = FOUR_CHAR_CODE('styl') -kTypeSoup = FOUR_CHAR_CODE('SOUP') -kTypeFontTable = FOUR_CHAR_CODE('FISH') -kTypeParaFormat = FOUR_CHAR_CODE('WEpf') -kTypeRulerScrap = FOUR_CHAR_CODE('WEru') -kTypeCharFormat = FOUR_CHAR_CODE('WEcf') -kTypeStyleScrap = FOUR_CHAR_CODE('WEst') -kTypeUnicodeText = FOUR_CHAR_CODE('utxt') -kTypeUTF8Text = FOUR_CHAR_CODE('UTF8') -kTypeStyledText = FOUR_CHAR_CODE('STXT') -weAKNone = 0 -weAKUnspecified = 1 -weAKTyping = 2 -weAKCut = 3 -weAKPaste = 4 -weAKClear = 5 -weAKDrag = 6 -weAKSetStyle = 7 -weAKSetRuler = 8 -weAKBackspace = 9 -weAKFwdDelete = 10 -weAKCaseChange = 11 -weAKObjectChange = 12 -weToScrap = 0 -weToDrag = 1 -weToSoup = 2 -weMouseEnter = 0 -weMouseWithin = 1 -weMouseLeave = 2 -kCurrentSelection = -1 -kNullStyle = -2 diff --git a/Lib/plat-mac/argvemulator.py b/Lib/plat-mac/argvemulator.py index 6103a8a..2d66f1c 100644 --- a/Lib/plat-mac/argvemulator.py +++ b/Lib/plat-mac/argvemulator.py @@ -7,6 +7,7 @@ import traceback from Carbon import AE from Carbon.AppleEvents import * from Carbon import Evt +from Carbon import File from Carbon.Events import * import aetools @@ -16,36 +17,36 @@ class ArgvCollector: def __init__(self): self.quitting = 0 - self.ae_handlers = {} # Remove the funny -psn_xxx_xxx argument if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn': del sys.argv[1] - self.installaehandler('aevt', 'oapp', self.open_app) - self.installaehandler('aevt', 'odoc', self.open_file) - def installaehandler(self, classe, type, callback): - AE.AEInstallEventHandler(classe, type, self.callback_wrapper) - self.ae_handlers[(classe, type)] = callback + AE.AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, self.__runapp) + AE.AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, self.__openfiles) def close(self): - for classe, type in self.ae_handlers.keys(): - AE.AERemoveEventHandler(classe, type) + AE.AERemoveEventHandler(kCoreEventClass, kAEOpenApplication) + AE.AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments) def mainloop(self, mask = highLevelEventMask, timeout = 1*60): + # Note: this is not the right way to run an event loop in OSX or even + # "recent" versions of MacOS9. This is however code that has proven + # itself. stoptime = Evt.TickCount() + timeout while not self.quitting and Evt.TickCount() < stoptime: - self.dooneevent(mask, timeout) - self.close() + self._dooneevent(mask, timeout) - def _quit(self): - self.quitting = 1 + if not self.quitting: + print "argvemulator: timeout waiting for arguments" - def dooneevent(self, mask = highLevelEventMask, timeout = 1*60): + self.close() + + def _dooneevent(self, mask = highLevelEventMask, timeout = 1*60): got, event = Evt.WaitNextEvent(mask, timeout) if got: - self.lowlevelhandler(event) + self._lowlevelhandler(event) - def lowlevelhandler(self, event): + def _lowlevelhandler(self, event): what, message, when, where, modifiers = event h, v = where if what == kHighLevelEvent: @@ -60,53 +61,28 @@ class ArgvCollector: else: print "Unhandled event:", event - def callback_wrapper(self, _request, _reply): - _parameters, _attributes = aetools.unpackevent(_request) - _class = _attributes['evcl'].type - _type = _attributes['evid'].type - - if self.ae_handlers.has_key((_class, _type)): - _function = self.ae_handlers[(_class, _type)] - elif self.ae_handlers.has_key((_class, '****')): - _function = self.ae_handlers[(_class, '****')] - elif self.ae_handlers.has_key(('****', '****')): - _function = self.ae_handlers[('****', '****')] - else: - raise 'Cannot happen: AE callback without handler', (_class, _type) - - # XXXX Do key-to-name mapping here - - _parameters['_attributes'] = _attributes - _parameters['_class'] = _class - _parameters['_type'] = _type - if _parameters.has_key('----'): - _object = _parameters['----'] - del _parameters['----'] - # The try/except that used to be here can mask programmer errors. - # Let the program crash, the programmer can always add a **args - # to the formal parameter list. - rv = _function(_object, **_parameters) - else: - #Same try/except comment as above - rv = _function(**_parameters) - if rv == None: - aetools.packevent(_reply, {}) - else: - aetools.packevent(_reply, {'----':rv}) + def _quit(self): + self.quitting = 1 - def open_app(self, **args): + def __runapp(self, requestevent, replyevent): self._quit() - def open_file(self, _object=None, **args): - for alias in _object: - fsr = alias.FSResolveAlias(None)[0] - pathname = fsr.as_pathname() - sys.argv.append(pathname) - self._quit() + def __openfiles(self, requestevent, replyevent): + try: + listdesc = requestevent.AEGetParamDesc(keyDirectObject, typeAEList) + for i in range(listdesc.AECountItems()): + aliasdesc = listdesc.AEGetNthDesc(i+1, typeAlias)[1] + alias = File.Alias(rawdata=aliasdesc.data) + fsref = alias.FSResolveAlias(None)[0] + pathname = fsref.as_pathname() + sys.argv.append(pathname) + except Exception, e: + print "argvemulator.py warning: can't unpack an open document event" + import traceback + traceback.print_exc() - def other(self, _object=None, _class=None, _type=None, **args): - print 'Ignore AppleEvent', (_class, _type), 'for', _object, 'Other args:', args + self._quit() if __name__ == '__main__': ArgvCollector().mainloop() diff --git a/Lib/smtplib.py b/Lib/smtplib.py index 07916cc..9c8c4fa 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -150,7 +150,7 @@ class SSLFakeFile: It only supports what is needed in smtplib. """ - def __init__( self, sslobj): + def __init__(self, sslobj): self.sslobj = sslobj def readline(self): diff --git a/Lib/socket.py b/Lib/socket.py index cc5e65e..fa0e663 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -141,7 +141,7 @@ class _socketobject(object): __doc__ = _realsocket.__doc__ __slots__ = ["_sock", - "recv", "recv_buf", "recvfrom_buf", + "recv", "recv_into", "recvfrom_into", "send", "sendto", "recvfrom", "__weakref__"] @@ -151,10 +151,10 @@ class _socketobject(object): self._sock = _sock self.send = self._sock.send self.recv = self._sock.recv - self.recv_buf = self._sock.recv_buf + self.recv_into = self._sock.recv_into self.sendto = self._sock.sendto self.recvfrom = self._sock.recvfrom - self.recvfrom_buf = self._sock.recvfrom_buf + self.recvfrom_into = self._sock.recvfrom_into def close(self): self._sock = _closedsocket() diff --git a/Lib/struct.py b/Lib/struct.py index 51ee29a..9113e71 100644 --- a/Lib/struct.py +++ b/Lib/struct.py @@ -62,7 +62,7 @@ def pack(fmt, *args): o = _compile(fmt) return o.pack(*args) -def pack_to(fmt, buf, offset, *args): +def pack_into(fmt, buf, offset, *args): """ Pack the values v2, v2, ... according to fmt, write the packed bytes into the writable buffer buf starting at offset. @@ -72,7 +72,7 @@ def pack_to(fmt, buf, offset, *args): o = _cache[fmt] except KeyError: o = _compile(fmt) - return o.pack_to(buf, offset, *args) + return o.pack_into(buf, offset, *args) def unpack(fmt, s): """ diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 19fe847..a6af7e7 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -388,6 +388,7 @@ if mswindows: hStdInput = None hStdOutput = None hStdError = None + wShowWindow = 0 class pywintypes: error = IOError else: @@ -744,18 +745,17 @@ class Popen(object): args = list2cmdline(args) # Process startup details - default_startupinfo = STARTUPINFO() if startupinfo is None: - startupinfo = default_startupinfo - if not None in (p2cread, c2pwrite, errwrite): + startupinfo = STARTUPINFO() + if None not in (p2cread, c2pwrite, errwrite): startupinfo.dwFlags |= STARTF_USESTDHANDLES startupinfo.hStdInput = p2cread startupinfo.hStdOutput = c2pwrite startupinfo.hStdError = errwrite if shell: - default_startupinfo.dwFlags |= STARTF_USESHOWWINDOW - default_startupinfo.wShowWindow = SW_HIDE + startupinfo.dwFlags |= STARTF_USESHOWWINDOW + startupinfo.wShowWindow = SW_HIDE comspec = os.environ.get("COMSPEC", "cmd.exe") args = comspec + " /c " + args if (GetVersion() >= 0x80000000L or diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 314e7e1..ca4a3b5 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -503,6 +503,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): quiet -- if true, don't print 'skipped' messages (probably redundant) testdir -- test directory """ + test_support.unload(test) if not testdir: testdir = findtestdir() @@ -512,11 +513,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): cfp = None else: cfp = cStringIO.StringIO() - if huntrleaks: - if not hasattr(sys, 'gettotalrefcount'): - raise Exception("Tracking reference leaks requires a debug build " - "of Python") - refrep = open(huntrleaks[2], "a") + try: save_stdout = sys.stdout try: @@ -538,60 +535,7 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): if indirect_test is not None: indirect_test() if huntrleaks: - # This code *is* hackish and inelegant, yes. - # But it seems to do the job. - import copy_reg - fs = warnings.filters[:] - ps = copy_reg.dispatch_table.copy() - pic = sys.path_importer_cache.copy() - import gc - def cleanup(): - import _strptime, linecache, warnings, dircache - import urlparse, urllib, urllib2, mimetypes, doctest - import struct - from distutils.dir_util import _path_created - _path_created.clear() - warnings.filters[:] = fs - gc.collect() - re.purge() - _strptime._regex_cache.clear() - urlparse.clear_cache() - urllib.urlcleanup() - urllib2.install_opener(None) - copy_reg.dispatch_table.clear() - copy_reg.dispatch_table.update(ps) - sys.path_importer_cache.clear() - sys.path_importer_cache.update(pic) - dircache.reset() - linecache.clearcache() - mimetypes._default_mime_types() - struct._cache.clear() - doctest.master = None - if indirect_test: - def run_the_test(): - indirect_test() - else: - def run_the_test(): - reload(the_module) - deltas = [] - repcount = huntrleaks[0] + huntrleaks[1] - print >> sys.stderr, "beginning", repcount, "repetitions" - print >> sys.stderr, \ - ("1234567890"*(repcount//10 + 1))[:repcount] - cleanup() - for i in range(repcount): - rc = sys.gettotalrefcount() - run_the_test() - sys.stderr.write('.') - cleanup() - deltas.append(sys.gettotalrefcount() - rc - 2) - print >>sys.stderr - if max(map(abs, deltas[-huntrleaks[1]:])) > 0: - print >>sys.stderr, test, 'leaked', \ - deltas[-huntrleaks[1]:], 'references' - print >>refrep, test, 'leaked', \ - deltas[-huntrleaks[1]:], 'references' - # The end of the huntrleaks hackishness. + dash_R(the_module, test, indirect_test, huntrleaks) finally: sys.stdout = save_stdout except test_support.ResourceDenied, msg: @@ -651,6 +595,77 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): sys.stdout.flush() return 0 +def dash_R(the_module, test, indirect_test, huntrleaks): + # This code is hackish and inelegant, but it seems to do the job. + import copy_reg + + if not hasattr(sys, 'gettotalrefcount'): + raise Exception("Tracking reference leaks requires a debug build " + "of Python") + + # Save current values for dash_R_cleanup() to restore. + fs = warnings.filters[:] + ps = copy_reg.dispatch_table.copy() + pic = sys.path_importer_cache.copy() + + if indirect_test: + def run_the_test(): + indirect_test() + else: + def run_the_test(): + reload(the_module) + + deltas = [] + nwarmup, ntracked, fname = huntrleaks + repcount = nwarmup + ntracked + print >> sys.stderr, "beginning", repcount, "repetitions" + print >> sys.stderr, ("1234567890"*(repcount//10 + 1))[:repcount] + dash_R_cleanup(fs, ps, pic) + for i in range(repcount): + rc = sys.gettotalrefcount() + run_the_test() + sys.stderr.write('.') + dash_R_cleanup(fs, ps, pic) + if i >= nwarmup: + deltas.append(sys.gettotalrefcount() - rc - 2) + print >> sys.stderr + if any(deltas): + print >> sys.stderr, test, 'leaked', deltas, 'references' + refrep = open(fname, "a") + print >> refrep, test, 'leaked', deltas, 'references' + refrep.close() + +def dash_R_cleanup(fs, ps, pic): + import gc, copy_reg + import _strptime, linecache, warnings, dircache + import urlparse, urllib, urllib2, mimetypes, doctest + import struct, filecmp + from distutils.dir_util import _path_created + + # Restore some original values. + warnings.filters[:] = fs + copy_reg.dispatch_table.clear() + copy_reg.dispatch_table.update(ps) + sys.path_importer_cache.clear() + sys.path_importer_cache.update(pic) + + # Clear assorted module caches. + _path_created.clear() + re.purge() + _strptime._regex_cache.clear() + urlparse.clear_cache() + urllib.urlcleanup() + urllib2.install_opener(None) + dircache.reset() + linecache.clearcache() + mimetypes._default_mime_types() + struct._cache.clear() + filecmp._cache.clear() + doctest.master = None + + # Collect cyclic trash. + gc.collect() + def reportdiff(expected, output): import difflib print "*" * 70 diff --git a/Lib/test/test_bsddb3.py b/Lib/test/test_bsddb3.py index 2d1bff7..8b0c50c 100644 --- a/Lib/test/test_bsddb3.py +++ b/Lib/test/test_bsddb3.py @@ -44,6 +44,8 @@ def suite(): 'test_queue', 'test_recno', 'test_thread', + 'test_sequence', + 'test_cursor_pget_bug', ] alltests = unittest.TestSuite() diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 71e2b0a..e6e4440 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -336,7 +336,7 @@ class BuiltinTest(unittest.TestCase): _cells = {} def __setitem__(self, key, formula): self._cells[key] = formula - def __getitem__(self, key ): + def __getitem__(self, key): return eval(self._cells[key], globals(), self) ss = SpreadSheet() diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 601b8b4..d872357 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -363,3 +363,37 @@ except AttributeError, x: pass else: print "attribute error for I.__init__ got masked" + + +# Test comparison and hash of methods +class A: + def __init__(self, x): + self.x = x + def f(self): + pass + def g(self): + pass + def __eq__(self, other): + return self.x == other.x + def __hash__(self): + return self.x +class B(A): + pass + +a1 = A(1) +a2 = A(2) +assert a1.f == a1.f +assert a1.f != a2.f +assert a1.f != a1.g +assert a1.f == A(1).f +assert hash(a1.f) == hash(a1.f) +assert hash(a1.f) == hash(A(1).f) + +assert A.f != a1.f +assert A.f != A.g +assert B.f == A.f +assert hash(B.f) == hash(A.f) + +# the following triggers a SystemError in 2.4 +a = A(hash(A.f.im_func)^(-1)) +hash(a.f) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 89cebb0..8ee431b 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -3866,11 +3866,24 @@ def methodwrapper(): l = [] vereq(l.__add__, l.__add__) - verify(l.__add__ != [].__add__) + vereq(l.__add__, [].__add__) + verify(l.__add__ != [5].__add__) + verify(l.__add__ != l.__mul__) verify(l.__add__.__name__ == '__add__') verify(l.__add__.__self__ is l) verify(l.__add__.__objclass__ is list) vereq(l.__add__.__doc__, list.__add__.__doc__) + try: + hash(l.__add__) + except TypeError: + pass + else: + raise TestFailed("no TypeError from hash([].__add__)") + + t = () + t += (7,) + vereq(t.__add__, (7,).__add__) + vereq(hash(t.__add__), hash((7,).__add__)) def notimplemented(): # all binary methods should be able to return a NotImplemented diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py index 92d2d74..01f7acd 100644 --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -512,15 +512,11 @@ will only be generated for it once: >>> tests[1].name.split('.')[-1] in ['f', 'g'] True -Filter Functions -~~~~~~~~~~~~~~~~ -A filter function can be used to restrict which objects get examined, -but this is temporary, undocumented internal support for testmod's -deprecated isprivate gimmick. - - >>> def namefilter(prefix, base): - ... return base.startswith('a_') - >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass) +Empty Tests +~~~~~~~~~~~ +By default, an object with no doctests doesn't create any tests: + + >>> tests = doctest.DocTestFinder().find(SampleClass) >>> tests.sort() >>> for t in tests: ... print '%2s %s' % (len(t.examples), t.name) @@ -528,6 +524,9 @@ deprecated isprivate gimmick. 3 SampleClass.NestedClass 1 SampleClass.NestedClass.__init__ 1 SampleClass.__init__ + 2 SampleClass.a_classmethod + 1 SampleClass.a_property + 1 SampleClass.a_staticmethod 1 SampleClass.double 1 SampleClass.get @@ -536,8 +535,7 @@ tells it to include (empty) tests for objects with no doctests. This feature is really to support backward compatibility in what doctest.master.summarize() displays. - >>> tests = doctest.DocTestFinder(_namefilter=namefilter, - ... exclude_empty=False).find(SampleClass) + >>> tests = doctest.DocTestFinder(exclude_empty=False).find(SampleClass) >>> tests.sort() >>> for t in tests: ... print '%2s %s' % (len(t.examples), t.name) @@ -547,35 +545,12 @@ displays. 0 SampleClass.NestedClass.get 0 SampleClass.NestedClass.square 1 SampleClass.__init__ - 1 SampleClass.double - 1 SampleClass.get - -If a given object is filtered out, then none of the objects that it -contains will be added either: - - >>> def namefilter(prefix, base): - ... return base == 'NestedClass' - >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass) - >>> tests.sort() - >>> for t in tests: - ... print '%2s %s' % (len(t.examples), t.name) - 3 SampleClass - 1 SampleClass.__init__ 2 SampleClass.a_classmethod 1 SampleClass.a_property 1 SampleClass.a_staticmethod 1 SampleClass.double 1 SampleClass.get -The filter function apply to contained objects, and *not* to the -object explicitly passed to DocTestFinder: - - >>> def namefilter(prefix, base): - ... return base == 'SampleClass' - >>> tests = doctest.DocTestFinder(_namefilter=namefilter).find(SampleClass) - >>> len(tests) - 9 - Turning off Recursion ~~~~~~~~~~~~~~~~~~~~~ DocTestFinder can be told not to look for tests in contained objects @@ -1913,20 +1888,6 @@ def test_DocTestSuite(): modified the test globals, which are a copy of the sample_doctest module dictionary. The test globals are automatically cleared for us after a test. - - Finally, you can provide an alternate test finder. Here we'll - use a custom test_finder to to run just the test named bar. - However, the test in the module docstring, and the two tests - in the module __test__ dict, aren't filtered, so we actually - run three tests besides bar's. The filtering mechanisms are - poorly conceived, and will go away someday. - - >>> finder = doctest.DocTestFinder( - ... _namefilter=lambda prefix, base: base!='bar') - >>> suite = doctest.DocTestSuite('test.sample_doctest', - ... test_finder=finder) - >>> suite.run(unittest.TestResult()) - """ def test_DocFileSuite(): diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index ebab913..ebe60c1 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1,9 +1,12 @@ # Python test set -- part 5, built-in exceptions -from test.test_support import TESTFN, unlink, run_unittest -import warnings -import sys, traceback, os +import os +import sys import unittest +import warnings +import pickle, cPickle + +from test.test_support import TESTFN, unlink, run_unittest # XXX This is not really enough, each *operation* should be tested! @@ -191,11 +194,15 @@ class ExceptionTests(unittest.TestCase): def testAttributes(self): # test that exception attributes are happy - try: str(u'Hello \u00E1') - except Exception, e: sampleUnicodeEncodeError = e + try: + str(u'Hello \u00E1') + except Exception, e: + sampleUnicodeEncodeError = e - try: unicode('\xff') - except Exception, e: sampleUnicodeDecodeError = e + try: + unicode('\xff') + except Exception, e: + sampleUnicodeDecodeError = e exceptionList = [ (BaseException, (), {'message' : '', 'args' : ()}), @@ -260,19 +267,20 @@ class ExceptionTests(unittest.TestCase): 'strerror' : 'strErrorStr', 'winerror' : 1, 'errno' : 22, 'filename' : 'filenameStr'}) ) - except NameError: pass - - import pickle, random + except NameError: + pass for args in exceptionList: expected = args[-1] try: exc = args[0] - if len(args) == 2: raise exc - else: raise exc(*args[1]) + if len(args) == 2: + raise exc + else: + raise exc(*args[1]) except BaseException, e: if (e is not exc and # needed for sampleUnicode errors - type(e) is not exc): + type(e) is not exc): raise # Verify no ref leaks in Exc_str() s = str(e) @@ -283,12 +291,15 @@ class ExceptionTests(unittest.TestCase): (repr(e), checkArgName)) # test for pickling support - new = pickle.loads(pickle.dumps(e, random.randint(0, 2))) - for checkArgName in expected: - self.assertEquals(repr(getattr(e, checkArgName)), - repr(expected[checkArgName]), - 'pickled exception "%s", attribute "%s' % - (repr(e), checkArgName)) + for p in pickle, cPickle: + for protocol in range(p.HIGHEST_PROTOCOL + 1): + new = p.loads(p.dumps(e, protocol)) + for checkArgName in expected: + got = repr(getattr(new, checkArgName)) + want = repr(expected[checkArgName]) + self.assertEquals(got, want, + 'pickled "%r", attribute "%s' % + (e, checkArgName)) def testKeywordArgs(self): # test that builtin exception don't take keyword args, diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index ca1c6ba..dcfa265 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -1,356 +1,325 @@ import sys import os +import unittest from array import array from weakref import proxy -from test.test_support import verify, TESTFN, TestFailed, findfile +from test.test_support import TESTFN, findfile, run_unittest from UserList import UserList -# verify weak references -f = file(TESTFN, 'w') -p = proxy(f) -p.write('teststring') -verify(f.tell(), p.tell()) -f.close() -f = None -try: - p.tell() -except ReferenceError: - pass -else: - raise TestFailed('file proxy still exists when the file is gone') - -# verify expected attributes exist -f = file(TESTFN, 'w') -softspace = f.softspace -f.name # merely shouldn't blow up -f.mode # ditto -f.closed # ditto - -# verify softspace is writable -f.softspace = softspace # merely shouldn't blow up - -# verify the others aren't -for attr in 'name', 'mode', 'closed': - try: - setattr(f, attr, 'oops') - except (AttributeError, TypeError): - pass - else: - raise TestFailed('expected exception setting file attr %r' % attr) -f.close() - -# check invalid mode strings -for mode in ("", "aU", "wU+"): - try: - f = file(TESTFN, mode) - except ValueError: - pass - else: - f.close() - raise TestFailed('%r is an invalid file mode' % mode) - -# verify writelines with instance sequence -l = UserList(['1', '2']) -f = open(TESTFN, 'wb') -f.writelines(l) -f.close() -f = open(TESTFN, 'rb') -buf = f.read() -f.close() -verify(buf == '12') - -# verify readinto -a = array('c', 'x'*10) -f = open(TESTFN, 'rb') -n = f.readinto(a) -f.close() -verify(buf == a.tostring()[:n]) - -# verify readinto refuses text files -a = array('c', 'x'*10) -f = open(TESTFN, 'r') -try: - f.readinto(a) - raise TestFailed("readinto shouldn't work in text mode") -except TypeError: - pass -finally: - f.close() - -# verify writelines with integers -f = open(TESTFN, 'wb') -try: - f.writelines([1, 2, 3]) -except TypeError: - pass -else: - print "writelines accepted sequence of integers" -f.close() - -# verify writelines with integers in UserList -f = open(TESTFN, 'wb') -l = UserList([1,2,3]) -try: - f.writelines(l) -except TypeError: - pass -else: - print "writelines accepted sequence of integers" -f.close() - -# verify writelines with non-string object -class NonString: pass - -f = open(TESTFN, 'wb') -try: - f.writelines([NonString(), NonString()]) -except TypeError: - pass -else: - print "writelines accepted sequence of non-string objects" -f.close() - -# This causes the interpreter to exit on OSF1 v5.1. -if sys.platform != 'osf1V5': - try: - sys.stdin.seek(-1) - except IOError: - pass - else: - print "should not be able to seek on sys.stdin" -else: - print >>sys.__stdout__, ( - ' Skipping sys.stdin.seek(-1), it may crash the interpreter.' - ' Test manually.') - -try: - sys.stdin.truncate() -except IOError: - pass -else: - print "should not be able to truncate on sys.stdin" - -# verify repr works -f = open(TESTFN) -if not repr(f).startswith(" - # "file.truncate fault on windows" - f = file(TESTFN, 'wb') - f.write('12345678901') # 11 bytes - f.close() - - f = file(TESTFN,'rb+') - data = f.read(5) - if data != '12345': - raise TestFailed("Read on file opened for update failed %r" % data) - if f.tell() != 5: - raise TestFailed("File pos after read wrong %d" % f.tell()) - - f.truncate() - if f.tell() != 5: - raise TestFailed("File pos after ftruncate wrong %d" % f.tell()) - - f.close() - size = os.path.getsize(TESTFN) - if size != 5: - raise TestFailed("File size after ftruncate wrong %d" % size) - -try: - bug801631() -finally: - os.unlink(TESTFN) - -# Test the complex interaction when mixing file-iteration and the various -# read* methods. Ostensibly, the mixture could just be tested to work -# when it should work according to the Python language, instead of fail -# when it should fail according to the current CPython implementation. -# People don't always program Python the way they should, though, and the -# implemenation might change in subtle ways, so we explicitly test for -# errors, too; the test will just have to be updated when the -# implementation changes. -dataoffset = 16384 -filler = "ham\n" -assert not dataoffset % len(filler), \ - "dataoffset must be multiple of len(filler)" -nchunks = dataoffset // len(filler) -testlines = [ - "spam, spam and eggs\n", - "eggs, spam, ham and spam\n", - "saussages, spam, spam and eggs\n", - "spam, ham, spam and eggs\n", - "spam, spam, spam, spam, spam, ham, spam\n", - "wonderful spaaaaaam.\n" -] -methods = [("readline", ()), ("read", ()), ("readlines", ()), - ("readinto", (array("c", " "*100),))] - -try: - # Prepare the testfile - bag = open(TESTFN, "wb") - bag.write(filler * nchunks) - bag.writelines(testlines) - bag.close() - # Test for appropriate errors mixing read* and iteration - for methodname, args in methods: - f = open(TESTFN, 'rb') - if f.next() != filler: - raise TestFailed, "Broken testfile" - meth = getattr(f, methodname) +class AutoFileTests(unittest.TestCase): + # file tests for which a test file is automatically set up + + def setUp(self): + self.f = file(TESTFN, 'wb') + + def tearDown(self): try: - meth(*args) - except ValueError: + if self.f: + self.f.close() + except IOError: pass + + def testWeakRefs(self): + # verify weak references + p = proxy(self.f) + p.write('teststring') + self.assertEquals(self.f.tell(), p.tell()) + self.f.close() + self.f = None + self.assertRaises(ReferenceError, getattr, p, 'tell') + + def testAttributes(self): + # verify expected attributes exist + f = self.f + softspace = f.softspace + f.name # merely shouldn't blow up + f.mode # ditto + f.closed # ditto + + # verify softspace is writable + f.softspace = softspace # merely shouldn't blow up + + # verify the others aren't + for attr in 'name', 'mode', 'closed': + self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops') + + def testReadinto(self): + # verify readinto + self.f.write('12') + self.f.close() + a = array('c', 'x'*10) + self.f = open(TESTFN, 'rb') + n = self.f.readinto(a) + self.assertEquals('12', a.tostring()[:n]) + + def testReadinto_text(self): + # verify readinto refuses text files + a = array('c', 'x'*10) + self.f.close() + self.f = open(TESTFN, 'r') + self.assertRaises(TypeError, self.f.readinto, a) + + def testWritelinesUserList(self): + # verify writelines with instance sequence + l = UserList(['1', '2']) + self.f.writelines(l) + self.f.close() + self.f = open(TESTFN, 'rb') + buf = self.f.read() + self.assertEquals(buf, '12') + + def testWritelinesIntegers(self): + # verify writelines with integers + self.assertRaises(TypeError, self.f.writelines, [1, 2, 3]) + + def testWritelinesIntegersUserList(self): + # verify writelines with integers in UserList + l = UserList([1,2,3]) + self.assertRaises(TypeError, self.f.writelines, l) + + def testWritelinesNonString(self): + # verify writelines with non-string object + class NonString: pass + + self.assertRaises(TypeError, self.f.writelines, [NonString(), NonString()]) + + def testRepr(self): + # verify repr works + self.assert_(repr(self.f).startswith(">sys.__stdout__, ( + ' Skipping sys.stdin.seek(-1), it may crash the interpreter.' + ' Test manually.') + self.assertRaises(IOError, sys.stdin.truncate) + + def testUnicodeOpen(self): + # verify repr works for unicode too + f = open(unicode(TESTFN), "w") + self.assert_(repr(f).startswith(" + # "file.truncate fault on windows" + f = file(TESTFN, 'wb') + f.write('12345678901') # 11 bytes + f.close() + + f = file(TESTFN,'rb+') + data = f.read(5) + if data != '12345': + self.fail("Read on file opened for update failed %r" % data) + if f.tell() != 5: + self.fail("File pos after read wrong %d" % f.tell()) + + f.truncate() + if f.tell() != 5: + self.fail("File pos after ftruncate wrong %d" % f.tell()) + + f.close() + size = os.path.getsize(TESTFN) + if size != 5: + self.fail("File size after ftruncate wrong %d" % size) + + try: + bug801631() + finally: + os.unlink(TESTFN) + + def testIteration(self): + # Test the complex interaction when mixing file-iteration and the various + # read* methods. Ostensibly, the mixture could just be tested to work + # when it should work according to the Python language, instead of fail + # when it should fail according to the current CPython implementation. + # People don't always program Python the way they should, though, and the + # implemenation might change in subtle ways, so we explicitly test for + # errors, too; the test will just have to be updated when the + # implementation changes. + dataoffset = 16384 + filler = "ham\n" + assert not dataoffset % len(filler), \ + "dataoffset must be multiple of len(filler)" + nchunks = dataoffset // len(filler) + testlines = [ + "spam, spam and eggs\n", + "eggs, spam, ham and spam\n", + "saussages, spam, spam and eggs\n", + "spam, ham, spam and eggs\n", + "spam, spam, spam, spam, spam, ham, spam\n", + "wonderful spaaaaaam.\n" + ] + methods = [("readline", ()), ("read", ()), ("readlines", ()), + ("readinto", (array("c", " "*100),))] + + try: + # Prepare the testfile + bag = open(TESTFN, "wb") + bag.write(filler * nchunks) + bag.writelines(testlines) + bag.close() + # Test for appropriate errors mixing read* and iteration + for methodname, args in methods: + f = open(TESTFN, 'rb') + if f.next() != filler: + self.fail, "Broken testfile" + meth = getattr(f, methodname) + try: + meth(*args) + except ValueError: + pass + else: + self.fail("%s%r after next() didn't raise ValueError" % + (methodname, args)) + f.close() + + # Test to see if harmless (by accident) mixing of read* and iteration + # still works. This depends on the size of the internal iteration + # buffer (currently 8192,) but we can test it in a flexible manner. + # Each line in the bag o' ham is 4 bytes ("h", "a", "m", "\n"), so + # 4096 lines of that should get us exactly on the buffer boundary for + # any power-of-2 buffersize between 4 and 16384 (inclusive). + f = open(TESTFN, 'rb') + for i in range(nchunks): + f.next() + testline = testlines.pop(0) + try: + line = f.readline() + except ValueError: + self.fail("readline() after next() with supposedly empty " + "iteration-buffer failed anyway") + if line != testline: + self.fail("readline() after next() with empty buffer " + "failed. Got %r, expected %r" % (line, testline)) + testline = testlines.pop(0) + buf = array("c", "\x00" * len(testline)) + try: + f.readinto(buf) + except ValueError: + self.fail("readinto() after next() with supposedly empty " + "iteration-buffer failed anyway") + line = buf.tostring() + if line != testline: + self.fail("readinto() after next() with empty buffer " + "failed. Got %r, expected %r" % (line, testline)) + + testline = testlines.pop(0) + try: + line = f.read(len(testline)) + except ValueError: + self.fail("read() after next() with supposedly empty " + "iteration-buffer failed anyway") + if line != testline: + self.fail("read() after next() with empty buffer " + "failed. Got %r, expected %r" % (line, testline)) + try: + lines = f.readlines() + except ValueError: + self.fail("readlines() after next() with supposedly empty " + "iteration-buffer failed anyway") + if lines != testlines: + self.fail("readlines() after next() with empty buffer " + "failed. Got %r, expected %r" % (line, testline)) + # Reading after iteration hit EOF shouldn't hurt either + f = open(TESTFN, 'rb') + try: + for line in f: + pass + try: + f.readline() + f.readinto(buf) + f.read() + f.readlines() + except ValueError: + self.fail("read* failed after next() consumed file") + finally: + f.close() + finally: + os.unlink(TESTFN) + + +def test_main(): + run_unittest(AutoFileTests, OtherFileTests) + +if __name__ == '__main__': + test_main() diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 609e8f4..8dc185b 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -152,6 +152,113 @@ class TestPythonPartial(TestPartial): thetype = PythonPartial +class TestUpdateWrapper(unittest.TestCase): + + def check_wrapper(self, wrapper, wrapped, + assigned=functools.WRAPPER_ASSIGNMENTS, + updated=functools.WRAPPER_UPDATES): + # Check attributes were assigned + for name in assigned: + self.failUnless(getattr(wrapper, name) is getattr(wrapped, name)) + # Check attributes were updated + for name in updated: + wrapper_attr = getattr(wrapper, name) + wrapped_attr = getattr(wrapped, name) + for key in wrapped_attr: + self.failUnless(wrapped_attr[key] is wrapper_attr[key]) + + def test_default_update(self): + def f(): + """This is a test""" + pass + f.attr = 'This is also a test' + def wrapper(): + pass + functools.update_wrapper(wrapper, f) + self.check_wrapper(wrapper, f) + self.assertEqual(wrapper.__name__, 'f') + self.assertEqual(wrapper.__doc__, 'This is a test') + self.assertEqual(wrapper.attr, 'This is also a test') + + def test_no_update(self): + def f(): + """This is a test""" + pass + f.attr = 'This is also a test' + def wrapper(): + pass + functools.update_wrapper(wrapper, f, (), ()) + self.check_wrapper(wrapper, f, (), ()) + self.assertEqual(wrapper.__name__, 'wrapper') + self.assertEqual(wrapper.__doc__, None) + self.failIf(hasattr(wrapper, 'attr')) + + def test_selective_update(self): + def f(): + pass + f.attr = 'This is a different test' + f.dict_attr = dict(a=1, b=2, c=3) + def wrapper(): + pass + wrapper.dict_attr = {} + assign = ('attr',) + update = ('dict_attr',) + functools.update_wrapper(wrapper, f, assign, update) + self.check_wrapper(wrapper, f, assign, update) + self.assertEqual(wrapper.__name__, 'wrapper') + self.assertEqual(wrapper.__doc__, None) + self.assertEqual(wrapper.attr, 'This is a different test') + self.assertEqual(wrapper.dict_attr, f.dict_attr) + + +class TestWraps(TestUpdateWrapper): + + def test_default_update(self): + def f(): + """This is a test""" + pass + f.attr = 'This is also a test' + @functools.wraps(f) + def wrapper(): + pass + self.check_wrapper(wrapper, f) + self.assertEqual(wrapper.__name__, 'f') + self.assertEqual(wrapper.__doc__, 'This is a test') + self.assertEqual(wrapper.attr, 'This is also a test') + + def test_no_update(self): + def f(): + """This is a test""" + pass + f.attr = 'This is also a test' + @functools.wraps(f, (), ()) + def wrapper(): + pass + self.check_wrapper(wrapper, f, (), ()) + self.assertEqual(wrapper.__name__, 'wrapper') + self.assertEqual(wrapper.__doc__, None) + self.failIf(hasattr(wrapper, 'attr')) + + def test_selective_update(self): + def f(): + pass + f.attr = 'This is a different test' + f.dict_attr = dict(a=1, b=2, c=3) + def add_dict_attr(f): + f.dict_attr = {} + return f + assign = ('attr',) + update = ('dict_attr',) + @functools.wraps(f, assign, update) + @add_dict_attr + def wrapper(): + pass + self.check_wrapper(wrapper, f, assign, update) + self.assertEqual(wrapper.__name__, 'wrapper') + self.assertEqual(wrapper.__doc__, None) + self.assertEqual(wrapper.attr, 'This is a different test') + self.assertEqual(wrapper.dict_attr, f.dict_attr) + def test_main(verbose=None): @@ -160,6 +267,8 @@ def test_main(verbose=None): TestPartial, TestPartialSubclass, TestPythonPartial, + TestUpdateWrapper, + TestWraps ) test_support.run_unittest(*test_classes) diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index a60a768..a184a8b 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -733,7 +733,7 @@ syntax_tests = """ ... yield 1 Traceback (most recent call last): .. -SyntaxError: 'return' with argument inside generator (, line 2) +SyntaxError: 'return' with argument inside generator (, line 3) >>> def f(): ... yield 1 @@ -876,9 +876,9 @@ These are fine: ... if 0: ... return 3 # but *this* sucks (line 8) ... if 0: -... yield 2 # because it's a generator +... yield 2 # because it's a generator (line 10) Traceback (most recent call last): -SyntaxError: 'return' with argument inside generator (, line 8) +SyntaxError: 'return' with argument inside generator (, line 10) This one caused a crash (see SF bug 567538): diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 2246fb6..01b9b5b 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -860,25 +860,25 @@ class BufferIOTest(SocketConnectedTest): def __init__(self, methodName='runTest'): SocketConnectedTest.__init__(self, methodName=methodName) - def testRecvBuf(self): + def testRecvInto(self): buf = array.array('c', ' '*1024) - nbytes = self.cli_conn.recv_buf(buf) + nbytes = self.cli_conn.recv_into(buf) self.assertEqual(nbytes, len(MSG)) msg = buf.tostring()[:len(MSG)] self.assertEqual(msg, MSG) - def _testRecvBuf(self): + def _testRecvInto(self): buf = buffer(MSG) self.serv_conn.send(buf) - def testRecvFromBuf(self): + def testRecvFromInto(self): buf = array.array('c', ' '*1024) - nbytes, addr = self.cli_conn.recvfrom_buf(buf) + nbytes, addr = self.cli_conn.recvfrom_into(buf) self.assertEqual(nbytes, len(MSG)) msg = buf.tostring()[:len(MSG)] self.assertEqual(msg, MSG) - def _testRecvFromBuf(self): + def _testRecvFromInto(self): buf = buffer(MSG) self.serv_conn.send(buf) diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index af835f7..aa458e6 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -1,4 +1,4 @@ -from test.test_support import TestFailed, verbose, verify +from test.test_support import TestFailed, verbose, verify, vereq import test.test_support import struct import array @@ -16,13 +16,11 @@ except ImportError: PY_STRUCT_RANGE_CHECKING = 0 PY_STRUCT_OVERFLOW_MASKING = 1 else: - PY_STRUCT_RANGE_CHECKING = getattr(_struct, '_PY_STRUCT_RANGE_CHECKING', 0) - PY_STRUCT_OVERFLOW_MASKING = getattr(_struct, '_PY_STRUCT_OVERFLOW_MASKING', 0) + PY_STRUCT_RANGE_CHECKING = _struct._PY_STRUCT_RANGE_CHECKING + PY_STRUCT_OVERFLOW_MASKING = _struct._PY_STRUCT_OVERFLOW_MASKING def string_reverse(s): - chars = list(s) - chars.reverse() - return "".join(chars) + return "".join(reversed(s)) def bigendian_to_native(value): if ISBIGENDIAN: @@ -504,7 +502,7 @@ def assertRaises(excClass, callableObj, *args, **kwargs): except excClass: return else: - raise RuntimeError("%s not raised." % excClass) + raise TestFailed("%s not raised." % excClass) def test_unpack_from(): test_string = 'abcd01234' @@ -512,68 +510,67 @@ def test_unpack_from(): s = struct.Struct(fmt) for cls in (str, buffer): data = cls(test_string) - assert s.unpack_from(data) == ('abcd',) - assert s.unpack_from(data, 2) == ('cd01',) - assert s.unpack_from(data, 4) == ('0123',) + vereq(s.unpack_from(data), ('abcd',)) + vereq(s.unpack_from(data, 2), ('cd01',)) + vereq(s.unpack_from(data, 4), ('0123',)) for i in xrange(6): - assert s.unpack_from(data, i) == (data[i:i+4],) + vereq(s.unpack_from(data, i), (data[i:i+4],)) for i in xrange(6, len(test_string) + 1): simple_err(s.unpack_from, data, i) for cls in (str, buffer): data = cls(test_string) - assert struct.unpack_from(fmt, data) == ('abcd',) - assert struct.unpack_from(fmt, data, 2) == ('cd01',) - assert struct.unpack_from(fmt, data, 4) == ('0123',) + vereq(struct.unpack_from(fmt, data), ('abcd',)) + vereq(struct.unpack_from(fmt, data, 2), ('cd01',)) + vereq(struct.unpack_from(fmt, data, 4), ('0123',)) for i in xrange(6): - assert (struct.unpack_from(fmt, data, i) == (data[i:i+4],)) + vereq(struct.unpack_from(fmt, data, i), (data[i:i+4],)) for i in xrange(6, len(test_string) + 1): simple_err(struct.unpack_from, fmt, data, i) -def test_pack_to(): +def test_pack_into(): test_string = 'Reykjavik rocks, eow!' writable_buf = array.array('c', ' '*100) fmt = '21s' s = struct.Struct(fmt) # Test without offset - s.pack_to(writable_buf, 0, test_string) + s.pack_into(writable_buf, 0, test_string) from_buf = writable_buf.tostring()[:len(test_string)] - assert from_buf == test_string + vereq(from_buf, test_string) # Test with offset. - s.pack_to(writable_buf, 10, test_string) + s.pack_into(writable_buf, 10, test_string) from_buf = writable_buf.tostring()[:len(test_string)+10] - assert from_buf == (test_string[:10] + test_string) + vereq(from_buf, test_string[:10] + test_string) # Go beyond boundaries. small_buf = array.array('c', ' '*10) - assertRaises(struct.error, s.pack_to, small_buf, 0, test_string) - assertRaises(struct.error, s.pack_to, small_buf, 2, test_string) + assertRaises(struct.error, s.pack_into, small_buf, 0, test_string) + assertRaises(struct.error, s.pack_into, small_buf, 2, test_string) -def test_pack_to_fn(): +def test_pack_into_fn(): test_string = 'Reykjavik rocks, eow!' writable_buf = array.array('c', ' '*100) fmt = '21s' - pack_to = lambda *args: struct.pack_to(fmt, *args) + pack_into = lambda *args: struct.pack_into(fmt, *args) - # Test without offset - pack_to(writable_buf, 0, test_string) + # Test without offset. + pack_into(writable_buf, 0, test_string) from_buf = writable_buf.tostring()[:len(test_string)] - assert from_buf == test_string + vereq(from_buf, test_string) # Test with offset. - pack_to(writable_buf, 10, test_string) + pack_into(writable_buf, 10, test_string) from_buf = writable_buf.tostring()[:len(test_string)+10] - assert from_buf == (test_string[:10] + test_string) + vereq(from_buf, test_string[:10] + test_string) # Go beyond boundaries. small_buf = array.array('c', ' '*10) - assertRaises(struct.error, pack_to, small_buf, 0, test_string) - assertRaises(struct.error, pack_to, small_buf, 2, test_string) + assertRaises(struct.error, pack_into, small_buf, 0, test_string) + assertRaises(struct.error, pack_into, small_buf, 2, test_string) + - # Test methods to pack and unpack from buffers rather than strings. test_unpack_from() -test_pack_to() -test_pack_to_fn() - +test_pack_into() +test_pack_into_fn() diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index e274c5b..aeaa77e 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -390,7 +390,7 @@ test_classes.append(test_gettempdir) class test_mkstemp(TC): """Test mkstemp().""" - def do_create(self, dir=None, pre="", suf="", ): + def do_create(self, dir=None, pre="", suf=""): if dir is None: dir = tempfile.gettempdir() try: diff --git a/Mac/BuildScript/README.txt b/Mac/BuildScript/README.txt new file mode 100644 index 0000000..c556de83 --- /dev/null +++ b/Mac/BuildScript/README.txt @@ -0,0 +1,35 @@ +Building a MacPython distribution +================================= + +The ``build-install.py`` script creates MacPython distributions, including +sleepycat db4, sqlite3 and readline support. It builds a complete +framework-based Python out-of-tree, installs it in a funny place with +$DESTROOT, massages that installation to remove .pyc files and such, creates +an Installer package from the installation plus other files in ``resources`` +and ``scripts`` and placed that on a ``.dmg`` disk image. + +Here are the steps you ned to follow to build a MacPython installer: + +- Run ``./build-installer.py``. Optionally you can pass a number of arguments + to specify locations of various files. Please see the top of + ``build-installer.py`` for its usage. +- When done the script will tell you where the DMG image is. + +The script needs to be run on Mac OS X 10.4 with Xcode 2.2 or later and +the 10.4u SDK. + +When all is done, announcements can be posted to at least the following +places: +- pythonmac-sig@python.org +- python-dev@python.org +- python-announce@python.org +- archivist@info-mac.org +- adcnews@apple.com +- news@macnn.com +- http://www.macupdate.com +- http://guide.apple.com/usindex.lasso +- http://www.apple.com/downloads/macosx/submit +- http://www.versiontracker.com/ (userid Jack.Jansen@oratrix.com) +- http://www.macshareware.net (userid jackjansen) + +Also, check out Stephan Deibels http://pythonology.org/market contact list diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py new file mode 100755 index 0000000..05afe98 --- /dev/null +++ b/Mac/BuildScript/build-installer.py @@ -0,0 +1,1028 @@ +#!/usr/bin/python2.3 +""" +This script is used to build the "official unofficial" universal build on +Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its +work. + +Please ensure that this script keeps working with Python 2.3, to avoid +bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4) + +Usage: see USAGE variable in the script. +""" +import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd + +INCLUDE_TIMESTAMP=1 +VERBOSE=1 + +from plistlib import Plist + +import MacOS +import Carbon.File +import Carbon.Icn +import Carbon.Res +from Carbon.Files import kCustomIconResource, fsRdWrPerm, kHasCustomIcon +from Carbon.Files import kFSCatInfoFinderInfo + +try: + from plistlib import writePlist +except ImportError: + # We're run using python2.3 + def writePlist(plist, path): + plist.write(path) + +def shellQuote(value): + """ + Return the string value in a form that can savely be inserted into + a shell command. + """ + return "'%s'"%(value.replace("'", "'\"'\"'")) + +def grepValue(fn, variable): + variable = variable + '=' + for ln in open(fn, 'r'): + if ln.startswith(variable): + value = ln[len(variable):].strip() + return value[1:-1] + +def getVersion(): + return grepValue(os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') + +def getFullVersion(): + fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') + for ln in open(fn): + if 'PY_VERSION' in ln: + return ln.split()[-1][1:-1] + + raise RuntimeError, "Cannot find full version??" + +# The directory we'll use to create the build, will be erased and recreated +WORKDIR="/tmp/_py" + +# The directory we'll use to store third-party sources, set this to something +# else if you don't want to re-fetch required libraries every time. +DEPSRC=os.path.join(WORKDIR, 'third-party') +DEPSRC=os.path.expanduser('~/Universal/other-sources') + +# Location of the preferred SDK +SDKPATH="/Developer/SDKs/MacOSX10.4u.sdk" +#SDKPATH="/" + +# Source directory (asume we're in Mac/BuildScript) +SRCDIR=os.path.dirname( + os.path.dirname( + os.path.dirname( + os.path.abspath(__file__ + )))) + +USAGE=textwrap.dedent("""\ + Usage: build_python [options] + + Options: + -? or -h: Show this message + -b DIR + --build-dir=DIR: Create build here (default: %(WORKDIR)r) + --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r) + --sdk-path=DIR: Location of the SDK (default: %(SDKPATH)r) + --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r) +""")% globals() + + +# Instructions for building libraries that are necessary for building a +# batteries included python. +LIBRARY_RECIPES=[ + dict( + # Note that GNU readline is GPL'd software + name="GNU Readline 5.1.4", + url="http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz" , + patchlevel='0', + patches=[ + # The readline maintainers don't do actual micro releases, but + # just ship a set of patches. + 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-001', + 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-002', + 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-003', + 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-004', + ] + ), + + dict( + name="SQLite 3.3.5", + url="http://www.sqlite.org/sqlite-3.3.5.tar.gz", + checksum='93f742986e8bc2dfa34792e16df017a6feccf3a2', + configure_pre=[ + '--enable-threadsafe', + '--enable-tempstore', + '--enable-shared=no', + '--enable-static=yes', + '--disable-tcl', + ] + ), + + dict( + name="NCurses 5.5", + url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz", + configure_pre=[ + "--without-cxx", + "--without-ada", + "--without-progs", + "--without-curses-h", + "--enable-shared", + "--with-shared", + "--datadir=/usr/share", + "--sysconfdir=/etc", + "--sharedstatedir=/usr/com", + "--with-terminfo-dirs=/usr/share/terminfo", + "--with-default-terminfo-dir=/usr/share/terminfo", + "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), + "--enable-termcap", + ], + patches=[ + "ncurses-5.5.patch", + ], + useLDFlags=False, + install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( + shellQuote(os.path.join(WORKDIR, 'libraries')), + shellQuote(os.path.join(WORKDIR, 'libraries')), + getVersion(), + ), + ), + dict( + name="Sleepycat DB 4.4", + url="http://downloads.sleepycat.com/db-4.4.20.tar.gz", + #name="Sleepycat DB 4.3.29", + #url="http://downloads.sleepycat.com/db-4.3.29.tar.gz", + buildDir="build_unix", + configure="../dist/configure", + configure_pre=[ + '--includedir=/usr/local/include/db4', + ] + ), +] + + +# Instructions for building packages inside the .mpkg. +PKG_RECIPES=[ + dict( + name="PythonFramework", + long_name="Python Framework", + source="/Library/Frameworks/Python.framework", + readme="""\ + This package installs Python.framework, that is the python + interpreter and the standard library. This also includes Python + wrappers for lots of Mac OS X API's. + """, + postflight="scripts/postflight.framework", + ), + dict( + name="PythonApplications", + long_name="GUI Applications", + source="/Applications/MacPython %(VER)s", + readme="""\ + This package installs IDLE (an interactive Python IDLE), + Python Launcher and Build Applet (create application bundles + from python scripts). + + It also installs a number of examples and demos. + """, + required=False, + ), + dict( + name="PythonUnixTools", + long_name="UNIX command-line tools", + source="/usr/local/bin", + readme="""\ + This package installs the unix tools in /usr/local/bin for + compatibility with older releases of MacPython. This package + is not necessary to use MacPython. + """, + required=False, + ), + dict( + name="PythonDocumentation", + long_name="Python Documentation", + topdir="/Library/Frameworks/Python.framework/Versions/%(VER)s/Resources/English.lproj/Documentation", + source="/pydocs", + readme="""\ + This package installs the python documentation at a location + that is useable for pydoc and IDLE. If you have installed Xcode + it will also install a link to the documentation in + /Developer/Documentation/Python + """, + postflight="scripts/postflight.documentation", + required=False, + ), + dict( + name="PythonProfileChanges", + long_name="Shell profile updater", + readme="""\ + This packages updates your shell profile to make sure that + the MacPython tools are found by your shell in preference of + the system provided Python tools. + + If you don't install this package you'll have to add + "/Library/Frameworks/Python.framework/Versions/%(VER)s/bin" + to your PATH by hand. + """, + postflight="scripts/postflight.patch-profile", + topdir="/Library/Frameworks/Python.framework", + source="/empty-dir", + required=False, + ), + dict( + name="PythonSystemFixes", + long_name="Fix system Python", + readme="""\ + This package updates the system python installation on + Mac OS X 10.3 to ensure that you can build new python extensions + using that copy of python after installing this version of + python. + """ + postflight="../Tools/fixapplepython23.py", + topdir="/Library/Frameworks/Python.framework", + source="/empty-dir", + required=False, + ) +] + +def fatal(msg): + """ + A fatal error, bail out. + """ + sys.stderr.write('FATAL: ') + sys.stderr.write(msg) + sys.stderr.write('\n') + sys.exit(1) + +def fileContents(fn): + """ + Return the contents of the named file + """ + return open(fn, 'rb').read() + +def runCommand(commandline): + """ + Run a command and raise RuntimeError if it fails. Output is surpressed + unless the command fails. + """ + fd = os.popen(commandline, 'r') + data = fd.read() + xit = fd.close() + if xit != None: + sys.stdout.write(data) + raise RuntimeError, "command failed: %s"%(commandline,) + + if VERBOSE: + sys.stdout.write(data); sys.stdout.flush() + +def captureCommand(commandline): + fd = os.popen(commandline, 'r') + data = fd.read() + xit = fd.close() + if xit != None: + sys.stdout.write(data) + raise RuntimeError, "command failed: %s"%(commandline,) + + return data + +def checkEnvironment(): + """ + Check that we're running on a supported system. + """ + + if platform.system() != 'Darwin': + fatal("This script should be run on a Mac OS X 10.4 system") + + if platform.release() <= '8.': + fatal("This script should be run on a Mac OS X 10.4 system") + + if not os.path.exists(SDKPATH): + fatal("Please install the latest version of Xcode and the %s SDK"%( + os.path.basename(SDKPATH[:-4]))) + + + +def parseOptions(args = None): + """ + Parse arguments and update global settings. + """ + global WORKDIR, DEPSRC, SDKPATH, SRCDIR + + if args is None: + args = sys.argv[1:] + + try: + options, args = getopt.getopt(args, '?hb', + [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=']) + except getopt.error, msg: + print msg + sys.exit(1) + + if args: + print "Additional arguments" + sys.exit(1) + + for k, v in options: + if k in ('-h', '-?'): + print USAGE + sys.exit(0) + + elif k in ('-d', '--build-dir'): + WORKDIR=v + + elif k in ('--third-party',): + DEPSRC=v + + elif k in ('--sdk-path',): + SDKPATH=v + + elif k in ('--src-dir',): + SRCDIR=v + + else: + raise NotImplementedError, k + + SRCDIR=os.path.abspath(SRCDIR) + WORKDIR=os.path.abspath(WORKDIR) + SDKPATH=os.path.abspath(SDKPATH) + DEPSRC=os.path.abspath(DEPSRC) + + print "Settings:" + print " * Source directory:", SRCDIR + print " * Build directory: ", WORKDIR + print " * SDK location: ", SDKPATH + print " * third-party source:", DEPSRC + print "" + + + + +def extractArchive(builddir, archiveName): + """ + Extract a source archive into 'builddir'. Returns the path of the + extracted archive. + + XXX: This function assumes that archives contain a toplevel directory + that is has the same name as the basename of the archive. This is + save enough for anything we use. + """ + curdir = os.getcwd() + try: + os.chdir(builddir) + if archiveName.endswith('.tar.gz'): + retval = os.path.basename(archiveName[:-7]) + if os.path.exists(retval): + shutil.rmtree(retval) + fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') + + elif archiveName.endswith('.tar.bz2'): + retval = os.path.basename(archiveName[:-8]) + if os.path.exists(retval): + shutil.rmtree(retval) + fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') + + elif archiveName.endswith('.tar'): + retval = os.path.basename(archiveName[:-4]) + if os.path.exists(retval): + shutil.rmtree(retval) + fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') + + elif archiveName.endswith('.zip'): + retval = os.path.basename(archiveName[:-4]) + if os.path.exists(retval): + shutil.rmtree(retval) + fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') + + data = fp.read() + xit = fp.close() + if xit is not None: + sys.stdout.write(data) + raise RuntimeError, "Cannot extract %s"%(archiveName,) + + return os.path.join(builddir, retval) + + finally: + os.chdir(curdir) + +KNOWNSIZES = { + "http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz": 7952742, + "http://downloads.sleepycat.com/db-4.4.20.tar.gz": 2030276, +} + +def downloadURL(url, fname): + """ + Download the contents of the url into the file. + """ + try: + size = os.path.getsize(fname) + except OSError: + pass + else: + if KNOWNSIZES.get(url) == size: + print "Using existing file for", url + return + fpIn = urllib2.urlopen(url) + fpOut = open(fname, 'wb') + block = fpIn.read(10240) + try: + while block: + fpOut.write(block) + block = fpIn.read(10240) + fpIn.close() + fpOut.close() + except: + try: + os.unlink(fname) + except: + pass + +def buildRecipe(recipe, basedir, archList): + """ + Build software using a recipe. This function does the + 'configure;make;make install' dance for C software, with a possibility + to customize this process, basically a poor-mans DarwinPorts. + """ + curdir = os.getcwd() + + name = recipe['name'] + url = recipe['url'] + configure = recipe.get('configure', './configure') + install = recipe.get('install', 'make && make install DESTDIR=%s'%( + shellQuote(basedir))) + + archiveName = os.path.split(url)[-1] + sourceArchive = os.path.join(DEPSRC, archiveName) + + if not os.path.exists(DEPSRC): + os.mkdir(DEPSRC) + + + if os.path.exists(sourceArchive): + print "Using local copy of %s"%(name,) + + else: + print "Downloading %s"%(name,) + downloadURL(url, sourceArchive) + print "Archive for %s stored as %s"%(name, sourceArchive) + + print "Extracting archive for %s"%(name,) + buildDir=os.path.join(WORKDIR, '_bld') + if not os.path.exists(buildDir): + os.mkdir(buildDir) + + workDir = extractArchive(buildDir, sourceArchive) + os.chdir(workDir) + if 'buildDir' in recipe: + os.chdir(recipe['buildDir']) + + + for fn in recipe.get('patches', ()): + if fn.startswith('http://'): + # Download the patch before applying it. + path = os.path.join(DEPSRC, os.path.basename(fn)) + downloadURL(fn, path) + fn = path + + fn = os.path.join(curdir, fn) + runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), + shellQuote(fn),)) + + configure_args = [ + "--prefix=/usr/local", + "--enable-static", + "--disable-shared", + #"CPP=gcc -arch %s -E"%(' -arch '.join(archList,),), + ] + + if 'configure_pre' in recipe: + args = list(recipe['configure_pre']) + if '--disable-static' in args: + configure_args.remove('--enable-static') + if '--enable-shared' in args: + configure_args.remove('--disable-shared') + configure_args.extend(args) + + if recipe.get('useLDFlags', 1): + configure_args.extend([ + "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( + ' -arch '.join(archList), + shellQuote(SDKPATH)[1:-1], + shellQuote(basedir)[1:-1],), + "LDFLAGS=-syslibroot,%s -L%s/usr/local/lib -arch %s"%( + shellQuote(SDKPATH)[1:-1], + shellQuote(basedir)[1:-1], + ' -arch '.join(archList)), + ]) + else: + configure_args.extend([ + "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( + ' -arch '.join(archList), + shellQuote(SDKPATH)[1:-1], + shellQuote(basedir)[1:-1],), + ]) + + if 'configure_post' in recipe: + configure_args = configure_args = list(recipe['configure_post']) + + configure_args.insert(0, configure) + configure_args = [ shellQuote(a) for a in configure_args ] + + print "Running configure for %s"%(name,) + runCommand(' '.join(configure_args) + ' 2>&1') + + print "Running install for %s"%(name,) + runCommand('{ ' + install + ' ;} 2>&1') + + print "Done %s"%(name,) + print "" + + os.chdir(curdir) + +def buildLibraries(): + """ + Build our dependencies into $WORKDIR/libraries/usr/local + """ + print "" + print "Building required libraries" + print "" + universal = os.path.join(WORKDIR, 'libraries') + os.mkdir(universal) + os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) + os.makedirs(os.path.join(universal, 'usr', 'local', 'include')) + + for recipe in LIBRARY_RECIPES: + buildRecipe(recipe, universal, ('i386', 'ppc',)) + + + +def buildPythonDocs(): + # This stores the documentation as Resources/English.lproj/Docuentation + # inside the framwork. pydoc and IDLE will pick it up there. + print "Install python documentation" + rootDir = os.path.join(WORKDIR, '_root') + version = getVersion() + docdir = os.path.join(rootDir, 'pydocs') + + name = 'html-%s.tar.bz2'%(getFullVersion(),) + sourceArchive = os.path.join(DEPSRC, name) + if os.path.exists(sourceArchive): + print "Using local copy of %s"%(name,) + + else: + print "Downloading %s"%(name,) + downloadURL('http://www.python.org/ftp/python/doc/%s/%s'%( + getFullVersion(), name), sourceArchive) + print "Archive for %s stored as %s"%(name, sourceArchive) + + extractArchive(os.path.dirname(docdir), sourceArchive) + os.rename( + os.path.join( + os.path.dirname(docdir), 'Python-Docs-%s'%(getFullVersion(),)), + docdir) + + +def buildPython(): + print "Building a universal python" + + buildDir = os.path.join(WORKDIR, '_bld', 'python') + rootDir = os.path.join(WORKDIR, '_root') + + if os.path.exists(buildDir): + shutil.rmtree(buildDir) + if os.path.exists(rootDir): + shutil.rmtree(rootDir) + os.mkdir(buildDir) + os.mkdir(rootDir) + os.mkdir(os.path.join(rootDir, 'empty-dir')) + curdir = os.getcwd() + os.chdir(buildDir) + + # Not sure if this is still needed, the original build script + # claims that parts of the install assume python.exe exists. + os.symlink('python', os.path.join(buildDir, 'python.exe')) + + # Extract the version from the configure file, needed to calculate + # several paths. + version = getVersion() + + print "Running configure..." + runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( + shellQuote(os.path.join(SRCDIR, 'configure')), + shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1], + shellQuote(WORKDIR)[1:-1])) + + print "Running make" + runCommand("make") + + print "Runing make frameworkinstall" + runCommand("make frameworkinstall DESTDIR=%s"%( + shellQuote(rootDir))) + + print "Runing make frameworkinstallextras" + runCommand("make frameworkinstallextras DESTDIR=%s"%( + shellQuote(rootDir))) + + print "Copy required shared libraries" + if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): + runCommand("mv %s/* %s"%( + shellQuote(os.path.join( + WORKDIR, 'libraries', 'Library', 'Frameworks', + 'Python.framework', 'Versions', getVersion(), + 'lib')), + shellQuote(os.path.join(WORKDIR, '_root', 'Library', 'Frameworks', + 'Python.framework', 'Versions', getVersion(), + 'lib')))) + + print "Fix file modes" + frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') + for dirpath, dirnames, filenames in os.walk(frmDir): + for dn in dirnames: + os.chmod(os.path.join(dirpath, dn), 0775) + + for fn in filenames: + if os.path.islink(fn): + continue + + # "chmod g+w $fn" + p = os.path.join(dirpath, fn) + st = os.stat(p) + os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IXGRP) + + # We added some directories to the search path during the configure + # phase. Remove those because those directories won't be there on + # the end-users system. + path =os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework', + 'Versions', version, 'lib', 'python%s'%(version,), + 'config', 'Makefile') + fp = open(path, 'r') + data = fp.read() + fp.close() + + data = data.replace('-L%s/libraries/usr/local/lib'%(WORKDIR,), '') + data = data.replace('-I%s/libraries/usr/local/include'%(WORKDIR,), '') + fp = open(path, 'w') + fp.write(data) + fp.close() + + # Add symlinks in /usr/local/bin, using relative links + usr_local_bin = os.path.join(rootDir, 'usr', 'local', 'bin') + to_framework = os.path.join('..', '..', '..', 'Library', 'Frameworks', + 'Python.framework', 'Versions', version, 'bin') + if os.path.exists(usr_local_bin): + shutil.rmtree(usr_local_bin) + os.makedirs(usr_local_bin) + for fn in os.listdir( + os.path.join(frmDir, 'Versions', version, 'bin')): + os.symlink(os.path.join(to_framework, fn), + os.path.join(usr_local_bin, fn)) + + os.chdir(curdir) + + + +def patchFile(inPath, outPath): + data = fileContents(inPath) + data = data.replace('$FULL_VERSION', getFullVersion()) + data = data.replace('$VERSION', getVersion()) + data = data.replace('$MACOSX_DEPLOYMENT_TARGET', '10.3 or later') + data = data.replace('$ARCHITECTURES', "i386, ppc") + data = data.replace('$INSTALL_SIZE', installSize()) + fp = open(outPath, 'wb') + fp.write(data) + fp.close() + +def patchScript(inPath, outPath): + data = fileContents(inPath) + data = data.replace('@PYVER@', getVersion()) + fp = open(outPath, 'wb') + fp.write(data) + fp.close() + os.chmod(outPath, 0755) + + + +def packageFromRecipe(targetDir, recipe): + curdir = os.getcwd() + try: + pkgname = recipe['name'] + srcdir = recipe.get('source') + pkgroot = recipe.get('topdir', srcdir) + postflight = recipe.get('postflight') + readme = textwrap.dedent(recipe['readme']) + isRequired = recipe.get('required', True) + + print "- building package %s"%(pkgname,) + + # Substitute some variables + textvars = dict( + VER=getVersion(), + FULLVER=getFullVersion(), + ) + readme = readme % textvars + + if pkgroot is not None: + pkgroot = pkgroot % textvars + else: + pkgroot = '/' + + if srcdir is not None: + srcdir = os.path.join(WORKDIR, '_root', srcdir[1:]) + srcdir = srcdir % textvars + + if postflight is not None: + postflight = os.path.abspath(postflight) + + packageContents = os.path.join(targetDir, pkgname + '.pkg', 'Contents') + os.makedirs(packageContents) + + if srcdir is not None: + os.chdir(srcdir) + runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) + runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) + runCommand("mkbom . %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.bom')),)) + + fn = os.path.join(packageContents, 'PkgInfo') + fp = open(fn, 'w') + fp.write('pmkrpkg1') + fp.close() + + rsrcDir = os.path.join(packageContents, "Resources") + os.mkdir(rsrcDir) + fp = open(os.path.join(rsrcDir, 'ReadMe.txt'), 'w') + fp.write(readme) + fp.close() + + if postflight is not None: + patchScript(postflight, os.path.join(rsrcDir, 'postflight')) + + vers = getFullVersion() + major, minor = map(int, getVersion().split('.', 2)) + pl = Plist( + CFBundleGetInfoString="MacPython.%s %s"%(pkgname, vers,), + CFBundleIdentifier='org.python.MacPython.%s'%(pkgname,), + CFBundleName='MacPython.%s'%(pkgname,), + CFBundleShortVersionString=vers, + IFMajorVersion=major, + IFMinorVersion=minor, + IFPkgFormatVersion=0.10000000149011612, + IFPkgFlagAllowBackRev=False, + IFPkgFlagAuthorizationAction="RootAuthorization", + IFPkgFlagDefaultLocation=pkgroot, + IFPkgFlagFollowLinks=True, + IFPkgFlagInstallFat=True, + IFPkgFlagIsRequired=isRequired, + IFPkgFlagOverwritePermissions=False, + IFPkgFlagRelocatable=False, + IFPkgFlagRestartAction="NoRestart", + IFPkgFlagRootVolumeOnly=True, + IFPkgFlagUpdateInstalledLangauges=False, + ) + writePlist(pl, os.path.join(packageContents, 'Info.plist')) + + pl = Plist( + IFPkgDescriptionDescription=readme, + IFPkgDescriptionTitle=recipe.get('long_name', "MacPython.%s"%(pkgname,)), + IFPkgDescriptionVersion=vers, + ) + writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist')) + + finally: + os.chdir(curdir) + + +def makeMpkgPlist(path): + + vers = getFullVersion() + major, minor = map(int, getVersion().split('.', 2)) + + pl = Plist( + CFBundleGetInfoString="MacPython %s"%(vers,), + CFBundleIdentifier='org.python.MacPython', + CFBundleName='MacPython', + CFBundleShortVersionString=vers, + IFMajorVersion=major, + IFMinorVersion=minor, + IFPkgFlagComponentDirectory="Contents/Packages", + IFPkgFlagPackageList=[ + dict( + IFPkgFlagPackageLocation='%s.pkg'%(item['name']), + IFPkgFlagPackageSelection='selected' + ) + for item in PKG_RECIPES + ], + IFPkgFormatVersion=0.10000000149011612, + IFPkgFlagBackgroundScaling="proportional", + IFPkgFlagBackgroundAlignment="left", + ) + + writePlist(pl, path) + + +def buildInstaller(): + + # Zap all compiled files + for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): + for fn in filenames: + if fn.endswith('.pyc') or fn.endswith('.pyo'): + os.unlink(os.path.join(dirpath, fn)) + + outdir = os.path.join(WORKDIR, 'installer') + if os.path.exists(outdir): + shutil.rmtree(outdir) + os.mkdir(outdir) + + pkgroot = os.path.join(outdir, 'MacPython.mpkg', 'Contents') + pkgcontents = os.path.join(pkgroot, 'Packages') + os.makedirs(pkgcontents) + for recipe in PKG_RECIPES: + packageFromRecipe(pkgcontents, recipe) + + rsrcDir = os.path.join(pkgroot, 'Resources') + + fn = os.path.join(pkgroot, 'PkgInfo') + fp = open(fn, 'w') + fp.write('pmkrpkg1') + fp.close() + + os.mkdir(rsrcDir) + + makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) + pl = Plist( + IFPkgDescriptionTitle="Universal MacPython", + IFPkgDescriptionVersion=getVersion(), + ) + + writePlist(pl, os.path.join(pkgroot, 'Resources', 'Description.plist')) + for fn in os.listdir('resources'): + if fn == '.svn': continue + if fn.endswith('.jpg'): + shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) + else: + patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) + + shutil.copy("../../../LICENSE", os.path.join(rsrcDir, 'License.txt')) + + +def installSize(clear=False, _saved=[]): + if clear: + del _saved[:] + if not _saved: + data = captureCommand("du -ks %s"%( + shellQuote(os.path.join(WORKDIR, '_root')))) + _saved.append("%d"%((0.5 + (int(data.split()[0]) / 1024.0)),)) + return _saved[0] + + +def buildDMG(): + """ + Create DMG containing the rootDir + """ + outdir = os.path.join(WORKDIR, 'diskimage') + if os.path.exists(outdir): + shutil.rmtree(outdir) + + imagepath = os.path.join(outdir, + 'python-%s-macosx'%(getFullVersion(),)) + if INCLUDE_TIMESTAMP: + imagepath = imagepath + '%04d-%02d-%02d'%(time.localtime()[:3]) + imagepath = imagepath + '.dmg' + + os.mkdir(outdir) + runCommand("hdiutil create -volname 'Univeral MacPython %s' -srcfolder %s %s"%( + getFullVersion(), + shellQuote(os.path.join(WORKDIR, 'installer')), + shellQuote(imagepath))) + + return imagepath + + +def setIcon(filePath, icnsPath): + """ + Set the custom icon for the specified file or directory. + + For a directory the icon data is written in a file named 'Icon\r' inside + the directory. For both files and directories write the icon as an 'icns' + resource. Furthermore set kHasCustomIcon in the finder flags for filePath. + """ + ref, isDirectory = Carbon.File.FSPathMakeRef(icnsPath) + icon = Carbon.Icn.ReadIconFile(ref) + del ref + + # + # Open the resource fork of the target, to add the icon later on. + # For directories we use the file 'Icon\r' inside the directory. + # + + ref, isDirectory = Carbon.File.FSPathMakeRef(filePath) + + if isDirectory: + tmpPath = os.path.join(filePath, "Icon\r") + if not os.path.exists(tmpPath): + fp = open(tmpPath, 'w') + fp.close() + + tmpRef, _ = Carbon.File.FSPathMakeRef(tmpPath) + spec = Carbon.File.FSSpec(tmpRef) + + else: + spec = Carbon.File.FSSpec(ref) + + try: + Carbon.Res.HCreateResFile(*spec.as_tuple()) + except MacOS.Error: + pass + + # Try to create the resource fork again, this will avoid problems + # when adding an icon to a directory. I have no idea why this helps, + # but without this adding the icon to a directory will fail sometimes. + try: + Carbon.Res.HCreateResFile(*spec.as_tuple()) + except MacOS.Error: + pass + + refNum = Carbon.Res.FSpOpenResFile(spec, fsRdWrPerm) + + Carbon.Res.UseResFile(refNum) + + # Check if there already is an icon, remove it if there is. + try: + h = Carbon.Res.Get1Resource('icns', kCustomIconResource) + except MacOS.Error: + pass + + else: + h.RemoveResource() + del h + + # Add the icon to the resource for of the target + res = Carbon.Res.Resource(icon) + res.AddResource('icns', kCustomIconResource, '') + res.WriteResource() + res.DetachResource() + Carbon.Res.CloseResFile(refNum) + + # And now set the kHasCustomIcon property for the target. Annoyingly, + # python doesn't seem to have bindings for the API that is needed for + # this. Cop out and call SetFile + os.system("/Developer/Tools/SetFile -a C %s"%( + shellQuote(filePath),)) + + if isDirectory: + os.system('/Developer/Tools/SetFile -a V %s'%( + shellQuote(tmpPath), + )) + +def main(): + # First parse options and check if we can perform our work + parseOptions() + checkEnvironment() + + os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' + + if os.path.exists(WORKDIR): + shutil.rmtree(WORKDIR) + os.mkdir(WORKDIR) + + # Then build third-party libraries such as sleepycat DB4. + buildLibraries() + + # Now build python itself + buildPython() + buildPythonDocs() + fn = os.path.join(WORKDIR, "_root", "Applications", + "MacPython %s"%(getVersion(),), "Update Shell Profile.command") + shutil.copy("scripts/postflight.patch-profile", fn) + os.chmod(fn, 0755) + + folder = os.path.join(WORKDIR, "_root", "Applications", "MacPython %s"%( + getVersion(),)) + os.chmod(folder, 0755) + setIcon(folder, "../Icons/Python Folder.icns") + + # Create the installer + buildInstaller() + + # And copy the readme into the directory containing the installer + patchFile('resources/ReadMe.txt', os.path.join(WORKDIR, 'installer', 'ReadMe.txt')) + + # Ditto for the license file. + shutil.copy('../../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) + + fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') + print >> fp, "# BUILD INFO" + print >> fp, "# Date:", time.ctime() + print >> fp, "# By:", pwd.getpwuid(os.getuid()).pw_gecos + fp.close() + + # Custom icon for the DMG, shown when the DMG is mounted. + shutil.copy("../Icons/Disk Image.icns", + os.path.join(WORKDIR, "installer", ".VolumeIcon.icns")) + os.system("/Developer/Tools/SetFile -a C %s"%( + os.path.join(WORKDIR, "installer", ".VolumeIcon.icns"))) + + + # And copy it to a DMG + buildDMG() + + +if __name__ == "__main__": + main() diff --git a/Mac/BuildScript/ncurses-5.5.patch b/Mac/BuildScript/ncurses-5.5.patch new file mode 100644 index 0000000..0eab3d3 --- /dev/null +++ b/Mac/BuildScript/ncurses-5.5.patch @@ -0,0 +1,36 @@ +diff -r -u ncurses-5.5-orig/test/Makefile.in ncurses-5.5/test/Makefile.in +--- ncurses-5.5-orig/test/Makefile.in 2006-03-24 12:47:40.000000000 +0100 ++++ ncurses-5.5/test/Makefile.in 2006-03-24 12:47:50.000000000 +0100 +@@ -75,7 +75,7 @@ + MATH_LIB = @MATH_LIB@ + + LD = @LD@ +-LINK = @LINK_TESTS@ $(LIBTOOL_LINK) $(CC) $(CFLAGS) ++LINK = @LINK_TESTS@ $(LIBTOOL_LINK) $(CC) + + usFLAGS = @LD_MODEL@ @LOCAL_LDFLAGS@ @LDFLAGS@ + +diff -ru ncurses-5.5-orig/ncurses/tinfo/read_entry.c ncurses-5.5/ncurses/tinfo/read_entry.c +--- ncurses-5.5-orig/ncurses/tinfo/read_entry.c 2004-01-11 02:57:05.000000000 +0100 ++++ ncurses-5.5/ncurses/tinfo/read_entry.c 2006-03-25 22:49:39.000000000 +0100 +@@ -474,7 +474,7 @@ + } + + /* truncate the terminal name to prevent buffer overflow */ +- (void) sprintf(ttn, "%c/%.*s", *tn, (int) sizeof(ttn) - 3, tn); ++ (void) sprintf(ttn, "%x/%.*s", *tn, (int) sizeof(ttn) - 3, tn); + + /* This is System V behavior, in conjunction with our requirements for + * writing terminfo entries. +diff -ru ncurses-5.5-orig/configure ncurses-5.5/configure +--- ncurses-5.5-orig/configure 2005-09-24 23:50:50.000000000 +0200 ++++ ncurses-5.5/configure 2006-03-26 22:24:59.000000000 +0200 +@@ -5027,7 +5027,7 @@ + darwin*) + EXTRA_CFLAGS="-no-cpp-precomp" + CC_SHARED_OPTS="-dynamic" +- MK_SHARED_LIB='$(CC) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@' ++ MK_SHARED_LIB='$(CC) $(CFLAGS) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@' + test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=abi + cf_cv_shlib_version_infix=yes + ;; diff --git a/Mac/BuildScript/resources/ReadMe.txt b/Mac/BuildScript/resources/ReadMe.txt new file mode 100644 index 0000000..1a6e637 --- /dev/null +++ b/Mac/BuildScript/resources/ReadMe.txt @@ -0,0 +1,31 @@ +This package will install MacPython $FULL_VERSION for Mac OS X +$MACOSX_DEPLOYMENT_TARGET for the following +architecture(s): $ARCHITECTURES. + +Separate installers are available for older versions +of Mac OS X, see the homepage, below. + +Installation requires approximately $INSTALL_SIZE MB of disk +space, ignore the message that it will take zero bytes. + +You must install onto your current boot disk, even +though the installer does not enforce this, otherwise +things will not work. + +MacPython consists of the Python programming language +interpreter, plus a set of programs to allow easy +access to it for Mac users (an integrated development +environment, an applet builder), plus a set of pre-built +extension modules that open up specific Macintosh technologies +to Python programs (Carbon, AppleScript, Quicktime, more). + +The installer puts the applications in "MacPython $VERSION" +in your Applications folder, command-line tools in +/usr/local/bin and the underlying machinery in +$PYTHONFRAMEWORKINSTALLDIR. + +More information on MacPython can be found at +http://www.cwi.nl/~jack/macpython and +http://pythonmac.org/. More information on +Python in general can be found at +http://www.python.org. diff --git a/Mac/BuildScript/resources/Welcome.rtf b/Mac/BuildScript/resources/Welcome.rtf new file mode 100644 index 0000000..cb65f09 --- /dev/null +++ b/Mac/BuildScript/resources/Welcome.rtf @@ -0,0 +1,15 @@ +{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf330 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} +{\colortbl;\red255\green255\blue255;} +\paperw11900\paperh16840\margl1440\margr1440\vieww9920\viewh10660\viewkind0 +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural + +\f0\fs24 \cf0 This package will install +\f1\b MacPython $FULL_VERSION +\f0\b0 for +\f1\b Mac OS X $MACOSX_DEPLOYMENT_TARGET +\f0\b0 .\ +\ +MacPython consists of the Python programming language interpreter, plus a set of programs to allow easy access to it for Mac users (an integrated development environment, an applet builder), plus a set of pre-built extension modules that open up specific Macintosh technologies to Python programs (Carbon, AppleScript, Quicktime, more).\ +\ +See the ReadMe file for more information.} \ No newline at end of file diff --git a/Mac/BuildScript/resources/background.jpg b/Mac/BuildScript/resources/background.jpg new file mode 100644 index 0000000..b3c7640 Binary files /dev/null and b/Mac/BuildScript/resources/background.jpg differ diff --git a/Mac/BuildScript/scripts/postflight.documentation b/Mac/BuildScript/scripts/postflight.documentation new file mode 100755 index 0000000..85d400f --- /dev/null +++ b/Mac/BuildScript/scripts/postflight.documentation @@ -0,0 +1,12 @@ +#!/bin/sh + +# FIXME +PYVER="@PYVER@" + +if [ -d /Developer/Documentation ]; then + if [ ! -d /Developer/Documentation/Python ]; then + mkdir -p /Developer/Documentation/Python + fi + + ln -fhs /Library/Frameworks/Python.framework/Versions/${PYVER}/Resources/English.lproj/Documentation "/Developer/Documentation/Python/Reference Documentation" +fi diff --git a/Mac/BuildScript/scripts/postflight.framework b/Mac/BuildScript/scripts/postflight.framework new file mode 100755 index 0000000..532e745 --- /dev/null +++ b/Mac/BuildScript/scripts/postflight.framework @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Recompile the .py files. +# + +PYVER="@PYVER@" +FWK="/Library/Frameworks/Python.framework/Versions/@PYVER@/" + +"${FWK}/bin/python" -Wi -tt \ + "${FWK}/lib/python${PYVER}/compileall.py" \ + -x badsyntax -x site-packages \ + "${FWK}/lib/python${PYVER}" + +"${FWK}/bin/python" -Wi -tt -O \ + "${FWK}/lib/python${PYVER}/compileall.py" \ + -x badsyntax -x site-packages \ + "${FWK}/lib/python${PYVER}" + +"${FWK}/bin/python" -Wi -tt \ + "${FWK}/lib/python${PYVER}/compileall.py" \ + -x badsyntax -x site-packages \ + "${FWK}/Mac/Tools" + +"${FWK}/bin/python" -Wi -tt -O \ + "${FWK}/lib/python${PYVER}/compileall.py" \ + -x badsyntax -x site-packages \ + "${FWK}/Mac/Tools" + + +chown -R admin "${FWK}" +chmod -R g+w "${FWK}" + +exit 0 diff --git a/Mac/BuildScript/scripts/postflight.patch-profile b/Mac/BuildScript/scripts/postflight.patch-profile new file mode 100755 index 0000000..48bf701 --- /dev/null +++ b/Mac/BuildScript/scripts/postflight.patch-profile @@ -0,0 +1,71 @@ +#!/bin/sh + +echo "This script will update your shell profile when the 'bin' directory" +echo "of python is not early enough of the PATH of your shell." +echo "These changes will be effective only in shell windows that you open" +echo "after running this script." + +PYVER=@PYVER@ +PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/Current" + +# Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH. +BSH="`basename "${SHELL}"`" +case "${BSH}" in +bash|ksh|sh|*csh) + P="`${SHELL} -c 'echo $PATH'`" + ;; +*) + echo "Sorry, I don't know how to patch $BSH shells" + exit 0 + ;; +esac + +# Now ensure that our bin directory is on $P and before /usr/bin at that +for elem in `echo $P | tr ':' ' '` +do + if [ "${elem}" == "${PYTHON_ROOT}/bin" ]; then + echo "All right, you're a python lover already" + exit 0 + elif [ "${elem}" == "/usr/bin" ]; then + break + fi +done + +echo "${PYTHON_ROOT}/bin is not on your PATH or at least not early enough" +case "${BSH}" in +*csh) + # Create backup copy before patching + if [ -f "${HOME}/.cshrc" ]; then + cp -fp "${HOME}/.cshrc" "${HOME}/.cshrc.pysave" + fi + echo "" >> "${HOME}/.cshrc" + echo "# Setting PATH for MacPython ${PYVER}" >> "${HOME}/.cshrc" + echo "# The orginal version is saved in .cshrc.pysave" >> "${HOME}/.cshrc" + echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${HOME}/.cshrc" + exit 0 + ;; +bash) + if [ -e "${HOME}/.profile" ]; then + PR="${HOME}/.profile" + else + PR="${HOME}/.bash_profile" + fi + ;; +*sh) + PR="${HOME}/.profile" + ;; +esac + +# Create backup copy before patching +if [ -f "${PR}" ]; then + cp -fp "${PR}" "${PR}.pysave" +fi +echo "" >> "${PR}" +echo "# Setting PATH for MacPython ${PYVER}" >> "${PR}" +echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}" +echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}" +echo 'export PATH' >> "${PR}" +if [ `id -ur` = 0 ]; then + chown "${LOGNAME}" "${PR}" +fi +exit 0 diff --git a/Mac/Demo/index.html b/Mac/Demo/index.html index 6b5806b..443cce9 100644 --- a/Mac/Demo/index.html +++ b/Mac/Demo/index.html @@ -74,10 +74,6 @@ how to use FrameWork application framework and the TextEdit toolbox to build a text editor.
  • -Using WASTE expands on this editor by using -WASTE, an extended TextEdit replacement. - -
  • Creating a C extension module on the Macintosh is meant for the hardcore programmer, and shows how to create an extension module in C. It also handles using Modulator to create the diff --git a/Mac/Demo/textedit.html b/Mac/Demo/textedit.html index 606c668..fcd8c97 100644 --- a/Mac/Demo/textedit.html +++ b/Mac/Demo/textedit.html @@ -80,8 +80,7 @@ A modeless dialog window initialized from a DLOG resource. See the Let us have a look at ped.py (in the Demo:textedit folder), the Pathetic EDitor. It has multiple windows, cut/copy/paste and keyboard input, but that is about all. It looks -as if you can resize the window but it does not work. Still, it serves as an example. We will improve -on ped later, in a waste-based example.

    +as if you can resize the window but it does not work. Still, it serves as an example. Ped creates two classes, TEWindow and Ped. Let us start with the latter one, which is a subclass of FrameWork.Application and our main application. The init function diff --git a/Mac/Demo/waste.html b/Mac/Demo/waste.html deleted file mode 100644 index 96b13bf..0000000 --- a/Mac/Demo/waste.html +++ /dev/null @@ -1,72 +0,0 @@ -Using WASTE - -

    Using WASTE

    -
    - -WASTE is an almost-compatible TextEdit replacement which overcomes -some of the limitations of it (like the 32K limit) and provides some extensions -(drag and drop, images, undo support). Moreover, it has a much cleaner interface -and is therefore easier integrated in Python.

    - -WASTE is written by Marco Piovanelli, <piovanel@kagi.com>, -and copyrighted by him. You can always obtain the latest version (for use in C -or Pascal programs) and the documentation from -<http://www.boingo.com/waste/>. - -We explain the useage of waste here by showing how to modify the TextEdit based -ped.py of the -previous example into the waste-based wed.py, -so you should have both sources handy.

    - -Functionally, wed.py provides three new things: resizable windows, a horizontal -scroll bar and undo.

    - -Let us look at the code, first at the application class Wed. The only real change is that -we now handle undo. Aside from enabling it in the creation routine and the addition of -a callback routine there is a bit of new code in updatemenubar: Waste not only handles -the full details of implementing undo, it will also tell us what the next undo operation will undo -(or redo). We use this to our advantage by changing the undo menu label to tell the user.

    - -The WasteWindow has seen a bit more change. Initialization of the waste data structure is -a bit different, in that we can specify some options at creation time. Also, waste has no SetText -method but a UseText which expects a handle as parameter. We have to be very careful -that we keep this handle around, because Python will happily free the handle if we have no more references -to it (and I doubt that Waste would like this:-). A final difference in open -is that we use a large number for the destination rectangle width, because we will use a horizontal scroll -bar.

    - -The idle method is a bit more involved, since we also call WEAdjustCursor to -provide the correct cursor based on mouse-position. Users like this.

    - -Getscrollbarvalues is simpler than its' TextEdit counterpart because Waste correctly -updates the destination rectangle when the document changes. Also note that waste uses accessor functions -to get at internal values, as opposed to direct struct access for TextEdit.

    - -Scrollbar_callback on the other hand is more elaborate (but also provides more functionality). -It also handles horizontal scrolls (scrolling one-tenth and half a screenful with the buttons). This -function is also "multi-font-ready" in that scrolling one line will do the expected thing in case of multiple -fonts. We will implement a multi-font editor later. A minor annoyance of Waste is that is does not provide -a pinned scroll, so at the end of our callback routine we have to check that we have not scrolled past the -beginning or end of the document, and adjust when needed.

    - -do_update is also changed, because Waste is completely region-based (as opposed to rect-based). -Hence, we erase regions here and we can also return immedeately if there is nothing to update.

    - -Do_postresize is new: because Waste uses accessor functions we can now modify the viewRect from -Python, which is impossible in the Python TextEdit interface, and hence we can implement resize. The -do_key and do_contentclick methods have also seen minor changes, because the -corresponding waste routines need a bit more information than their TextEdit counterparts. The Cut/copy/paste -code is simplified, because Waste uses the normal desktop scrap.

    - -Implementing undo is a wonder of simplicity: Waste handles all the details for us. Also, the new -can_paste method (which controls greying out of the paste menu entry) is an improvement -over what ped did: in ped it was possible that paste was enabled but that the data on the -scrap was incompatible with TextEdit. No more such problems here.

    - -That is all for now. There is an undocumented extended version of wed, swed.py, -which supports multiple fonts, sizes and faces, and uses Waste's tab-calculation to do tab characters "right". -There is also an even more elaborate example, htmled.py which extends swed with -the ability to import html files, showing the use of color and how to use embedded object (rulers, in this case). -These two programs have not been documented yet, though, so you will have to look at them without guidance.

    -


    -Back to the index to pick another example. diff --git a/Mac/Demo/waste/htmled.py b/Mac/Demo/waste/htmled.py deleted file mode 100644 index d8cea1b..0000000 --- a/Mac/Demo/waste/htmled.py +++ /dev/null @@ -1,830 +0,0 @@ -# A minimal text editor. -# -# To be done: -# - Functionality: find, etc. - -from Carbon.Menu import DrawMenuBar -from FrameWork import * -from Carbon import Win -from Carbon import Qd -from Carbon import Res -from Carbon import Fm -import waste -import WASTEconst -from Carbon import Scrap -import os -import EasyDialogs -import macfs -import string -import htmllib - -WATCH = Qd.GetCursor(4).data - -LEFTMARGIN=0 - -UNDOLABELS = [ # Indexed by WEGetUndoInfo() value - None, "", "typing", "Cut", "Paste", "Clear", "Drag", "Style"] - -# Style and size menu. Note that style order is important (tied to bit values) -STYLES = [ - ("Bold", "B"), ("Italic", "I"), ("Underline", "U"), ("Outline", "O"), - ("Shadow", ""), ("Condensed", ""), ("Extended", "") - ] -SIZES = [ 9, 10, 12, 14, 18, 24] - -# Sizes for HTML tag types -HTML_SIZE={ - 'h1': 18, - 'h2': 14 -} - -BIGREGION=Qd.NewRgn() -Qd.SetRectRgn(BIGREGION, -16000, -16000, 16000, 16000) - -class WasteWindow(ScrolledWindow): - def open(self, path, name, data): - self.path = path - self.name = name - r = windowbounds(400, 400) - w = Win.NewWindow(r, name, 1, 0, -1, 1, 0) - self.wid = w - vr = LEFTMARGIN, 0, r[2]-r[0]-15, r[3]-r[1]-15 - dr = (0, 0, vr[2], 0) - Qd.SetPort(w) - Qd.TextFont(4) - Qd.TextSize(9) - flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \ - WASTEconst.weDoMonoStyled | WASTEconst.weDoUndo - self.ted = waste.WENew(dr, vr, flags) - self.ted.WEInstallTabHooks() - style, soup = self.getstylesoup(self.path) - self.ted.WEInsert(data, style, soup) - self.ted.WESetSelection(0,0) - self.ted.WECalText() - self.ted.WEResetModCount() - w.DrawGrowIcon() - self.scrollbars() - self.do_postopen() - self.do_activate(1, None) - - def getstylesoup(self, pathname): - if not pathname: - return None, None - oldrf = Res.CurResFile() - try: - rf = Res.FSpOpenResFile(self.path, 1) - except Res.Error: - return None, None - try: - hstyle = Res.Get1Resource('styl', 128) - hstyle.DetachResource() - except Res.Error: - hstyle = None - try: - hsoup = Res.Get1Resource('SOUP', 128) - hsoup.DetachResource() - except Res.Error: - hsoup = None - Res.CloseResFile(rf) - Res.UseResFile(oldrf) - return hstyle, hsoup - - def do_idle(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - self.ted.WEIdle() - if self.ted.WEAdjustCursor(where, BIGREGION): - return - Qd.SetCursor(Qd.GetQDGlobalsArrow()) - - def getscrollbarvalues(self): - dr = self.ted.WEGetDestRect() - vr = self.ted.WEGetViewRect() - vx = self.scalebarvalue(dr[0], dr[2], vr[0], vr[2]) - vy = self.scalebarvalue(dr[1], dr[3], vr[1], vr[3]) - return vx, vy - - def scrollbar_callback(self, which, what, value): - if which == 'y': - # - # "line" size is minimum of top and bottom line size - # - topline_off,dummy = self.ted.WEGetOffset((1,1)) - topline_num = self.ted.WEOffsetToLine(topline_off) - toplineheight = self.ted.WEGetHeight(topline_num, topline_num+1) - - botlinepos = self.ted.WEGetViewRect()[3] - botline_off, dummy = self.ted.WEGetOffset((1, botlinepos-1)) - botline_num = self.ted.WEOffsetToLine(botline_off) - botlineheight = self.ted.WEGetHeight(botline_num, botline_num+1) - - if botlineheight == 0: - botlineheight = self.ted.WEGetHeight(botline_num-1, botline_num) - if botlineheight < toplineheight: - lineheight = botlineheight - else: - lineheight = toplineheight - if lineheight <= 0: - lineheight = 1 - # - # Now do the command. - # - if what == 'set': - height = self.ted.WEGetHeight(0, 0x3fffffff) - cur = self.getscrollbarvalues()[1] - delta = (cur-value)*height/32767 - if what == '-': - delta = lineheight - elif what == '--': - delta = (self.ted.WEGetViewRect()[3]-lineheight) - if delta <= 0: - delta = lineheight - elif what == '+': - delta = -lineheight - elif what == '++': - delta = -(self.ted.WEGetViewRect()[3]-lineheight) - if delta >= 0: - delta = -lineheight - self.ted.WEScroll(0, delta) - else: - if what == 'set': - return # XXXX - vr = self.ted.WEGetViewRect() - winwidth = vr[2]-vr[0] - if what == '-': - delta = winwidth/10 - elif what == '--': - delta = winwidth/2 - elif what == '+': - delta = -winwidth/10 - elif what == '++': - delta = -winwidth/2 - self.ted.WEScroll(delta, 0) - # Pin the scroll - l, t, r, b = self.ted.WEGetDestRect() - vl, vt, vr, vb = self.ted.WEGetViewRect() - if t > 0 or l > 0: - dx = dy = 0 - if t > 0: dy = -t - if l > 0: dx = -l - self.ted.WEScroll(dx, dy) - elif b < vb: - self.ted.WEScroll(0, vb-b) - - - def do_activate(self, onoff, evt): - Qd.SetPort(self.wid) - ScrolledWindow.do_activate(self, onoff, evt) - if onoff: - self.ted.WEActivate() - self.parent.active = self - self.parent.updatemenubar() - else: - self.ted.WEDeactivate() - - def do_update(self, wid, event): - region = wid.GetWindowPort().visRgn - if Qd.EmptyRgn(region): - return - Qd.EraseRgn(region) - self.ted.WEUpdate(region) - self.updatescrollbars() - - def do_postresize(self, width, height, window): - l, t, r, b = self.ted.WEGetViewRect() - vr = (l, t, l+width-15, t+height-15) - self.ted.WESetViewRect(vr) - self.wid.InvalWindowRect(vr) - ScrolledWindow.do_postresize(self, width, height, window) - - def do_contentclick(self, local, modifiers, evt): - (what, message, when, where, modifiers) = evt - self.ted.WEClick(local, modifiers, when) - self.updatescrollbars() - self.parent.updatemenubar() - - def do_char(self, ch, event): - self.ted.WESelView() - (what, message, when, where, modifiers) = event - self.ted.WEKey(ord(ch), modifiers) - self.updatescrollbars() - self.parent.updatemenubar() - - def close(self): - if self.ted.WEGetModCount(): - save = EasyDialogs.AskYesNoCancel('Save window "%s" before closing?'%self.name, 1) - if save > 0: - self.menu_save() - elif save < 0: - return - if self.parent.active == self: - self.parent.active = None - self.parent.updatemenubar() - del self.ted - self.do_postclose() - - def menu_save(self): - if not self.path: - self.menu_save_as() - return # Will call us recursively - # - # First save data - # - dhandle = self.ted.WEGetText() - data = dhandle.data - fp = open(self.path, 'wb') # NOTE: wb, because data has CR for end-of-line - fp.write(data) - if data[-1] <> '\r': fp.write('\r') - fp.close() - # - # Now save style and soup - # - oldresfile = Res.CurResFile() - try: - rf = Res.FSpOpenResFile(self.path, 3) - except Res.Error: - Res.FSpCreateResFile(self.path, '????', 'TEXT', macfs.smAllScripts) - rf = Res.FSpOpenResFile(self.path, 3) - styles = Res.Resource('') - soup = Res.Resource('') - self.ted.WECopyRange(0, 0x3fffffff, None, styles, soup) - styles.AddResource('styl', 128, '') - soup.AddResource('SOUP', 128, '') - Res.CloseResFile(rf) - Res.UseResFile(oldresfile) - - self.ted.WEResetModCount() - - def menu_save_as(self): - path = EasyDialogs.AskFileForSave(message='Save as:') - if not path: return - self.path = path - self.name = os.path.split(self.path)[-1] - self.wid.SetWTitle(self.name) - self.menu_save() - - def menu_insert(self, fp): - self.ted.WESelView() - data = fp.read() - self.ted.WEInsert(data, None, None) - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_insert_html(self, fp): - import htmllib - import formatter - f = formatter.AbstractFormatter(self) - - # Remember where we are, and don't update - Qd.SetCursor(WATCH) - start, dummy = self.ted.WEGetSelection() - self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 1) - - self.html_init() - p = MyHTMLParser(f) - p.feed(fp.read()) - - # Restore updating, recalc, set focus - dummy, end = self.ted.WEGetSelection() - self.ted.WECalText() - self.ted.WESetSelection(start, end) - self.ted.WESelView() - self.ted.WEFeatureFlag(WASTEconst.weFInhibitRecal, 0) - self.wid.InvalWindowRect(self.ted.WEGetViewRect()) - - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_cut(self): - self.ted.WESelView() - if hasattr(Scrap, 'ZeroScrap'): - Scrap.ZeroScrap() - else: - Scrap.ClearCurrentScrap() - self.ted.WECut() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_copy(self): - if hasattr(Scrap, 'ZeroScrap'): - Scrap.ZeroScrap() - else: - Scrap.ClearCurrentScrap() - self.ted.WECopy() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_paste(self): - self.ted.WESelView() - self.ted.WEPaste() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_clear(self): - self.ted.WESelView() - self.ted.WEDelete() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_undo(self): - self.ted.WEUndo() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_setfont(self, font): - font = Fm.GetFNum(font) - self.mysetstyle(WASTEconst.weDoFont, (font, 0, 0, (0,0,0))) - self.parent.updatemenubar() - - def menu_modface(self, face): - self.mysetstyle(WASTEconst.weDoFace|WASTEconst.weDoToggleFace, - (0, face, 0, (0,0,0))) - - def menu_setface(self, face): - self.mysetstyle(WASTEconst.weDoFace|WASTEconst.weDoReplaceFace, - (0, face, 0, (0,0,0))) - - def menu_setsize(self, size): - self.mysetstyle(WASTEconst.weDoSize, (0, 0, size, (0,0,0))) - - def menu_incsize(self, size): - self.mysetstyle(WASTEconst.weDoAddSize, (0, 0, size, (0,0,0))) - - def mysetstyle(self, which, how): - self.ted.WESelView() - self.ted.WESetStyle(which, how) - self.parent.updatemenubar() - - def have_selection(self): - start, stop = self.ted.WEGetSelection() - return start < stop - - def can_paste(self): - return self.ted.WECanPaste() - - def can_undo(self): - which, redo = self.ted.WEGetUndoInfo() - which = UNDOLABELS[which] - if which == None: return None - if redo: - return "Redo "+which - else: - return "Undo "+which - - def getruninfo(self): - all = (WASTEconst.weDoFont | WASTEconst.weDoFace | WASTEconst.weDoSize) - dummy, mode, (font, face, size, color) = self.ted.WEContinuousStyle(all) - if not (mode & WASTEconst.weDoFont): - font = None - else: - font = Fm.GetFontName(font) - if not (mode & WASTEconst.weDoFace): fact = None - if not (mode & WASTEconst.weDoSize): size = None - return font, face, size - - # - # Methods for writer class for html formatter - # - - def html_init(self): - self.html_font = [12, 0, 0, 0] - self.html_style = 0 - self.html_color = (0,0,0) - self.new_font(self.html_font) - - def new_font(self, font): - if font == None: - font = (12, 0, 0, 0) - font = map(lambda x:x, font) - for i in range(len(font)): - if font[i] == None: - font[i] = self.html_font[i] - [size, italic, bold, tt] = font - self.html_font = font[:] - if tt: - font = Fm.GetFNum('Courier') - else: - font = Fm.GetFNum('Times') - if HTML_SIZE.has_key(size): - size = HTML_SIZE[size] - else: - size = 12 - face = 0 - if bold: face = face | 1 - if italic: face = face | 2 - face = face | self.html_style - self.ted.WESetStyle(WASTEconst.weDoFont | WASTEconst.weDoFace | - WASTEconst.weDoSize | WASTEconst.weDoColor, - (font, face, size, self.html_color)) - - def new_margin(self, margin, level): - self.ted.WEInsert('[Margin %s %s]'%(margin, level), None, None) - - def new_spacing(self, spacing): - self.ted.WEInsert('[spacing %s]'%spacing, None, None) - - def new_styles(self, styles): - self.html_style = 0 - self.html_color = (0,0,0) - if 'anchor' in styles: - self.html_style = self.html_style | 4 - self.html_color = (0xffff, 0, 0) - self.new_font(self.html_font) - - def send_paragraph(self, blankline): - self.ted.WEInsert('\r'*(blankline+1), None, None) - - def send_line_break(self): - self.ted.WEInsert('\r', None, None) - - def send_hor_rule(self, *args, **kw): - # Ignore ruler options, for now - dummydata = Res.Resource('') - self.ted.WEInsertObject('rulr', dummydata, (0,0)) - - def send_label_data(self, data): - self.ted.WEInsert(data, None, None) - - def send_flowing_data(self, data): - self.ted.WEInsert(data, None, None) - - def send_literal_data(self, data): - data = string.replace(data, '\n', '\r') - data = string.expandtabs(data) - self.ted.WEInsert(data, None, None) - -class Wed(Application): - def __init__(self): - Application.__init__(self) - self.num = 0 - self.active = None - self.updatemenubar() - waste.STDObjectHandlers() - # Handler for horizontal ruler - waste.WEInstallObjectHandler('rulr', 'new ', self.newRuler) - waste.WEInstallObjectHandler('rulr', 'draw', self.drawRuler) - - def makeusermenus(self): - self.filemenu = m = Menu(self.menubar, "File") - self.newitem = MenuItem(m, "New window", "N", self.open) - self.openitem = MenuItem(m, "Open...", "O", self.openfile) - self.closeitem = MenuItem(m, "Close", "W", self.closewin) - m.addseparator() - self.saveitem = MenuItem(m, "Save", "S", self.save) - self.saveasitem = MenuItem(m, "Save as...", "", self.saveas) - m.addseparator() - self.insertitem = MenuItem(m, "Insert plaintext...", "", self.insertfile) - self.htmlitem = MenuItem(m, "Insert HTML...", "", self.inserthtml) - m.addseparator() - self.quititem = MenuItem(m, "Quit", "Q", self.quit) - - self.editmenu = m = Menu(self.menubar, "Edit") - self.undoitem = MenuItem(m, "Undo", "Z", self.undo) - self.cutitem = MenuItem(m, "Cut", "X", self.cut) - self.copyitem = MenuItem(m, "Copy", "C", self.copy) - self.pasteitem = MenuItem(m, "Paste", "V", self.paste) - self.clearitem = MenuItem(m, "Clear", "", self.clear) - - self.makefontmenu() - - # Groups of items enabled together: - self.windowgroup = [self.closeitem, self.saveitem, self.saveasitem, - self.editmenu, self.fontmenu, self.facemenu, self.sizemenu, - self.insertitem] - self.focusgroup = [self.cutitem, self.copyitem, self.clearitem] - self.windowgroup_on = -1 - self.focusgroup_on = -1 - self.pastegroup_on = -1 - self.undo_label = "never" - self.ffs_values = () - - def makefontmenu(self): - self.fontmenu = Menu(self.menubar, "Font") - self.fontnames = getfontnames() - self.fontitems = [] - for n in self.fontnames: - m = MenuItem(self.fontmenu, n, "", self.selfont) - self.fontitems.append(m) - self.facemenu = Menu(self.menubar, "Style") - self.faceitems = [] - for n, shortcut in STYLES: - m = MenuItem(self.facemenu, n, shortcut, self.selface) - self.faceitems.append(m) - self.facemenu.addseparator() - self.faceitem_normal = MenuItem(self.facemenu, "Normal", "N", - self.selfacenormal) - self.sizemenu = Menu(self.menubar, "Size") - self.sizeitems = [] - for n in SIZES: - m = MenuItem(self.sizemenu, repr(n), "", self.selsize) - self.sizeitems.append(m) - self.sizemenu.addseparator() - self.sizeitem_bigger = MenuItem(self.sizemenu, "Bigger", "+", - self.selsizebigger) - self.sizeitem_smaller = MenuItem(self.sizemenu, "Smaller", "-", - self.selsizesmaller) - - def selfont(self, id, item, *rest): - if self.active: - font = self.fontnames[item-1] - self.active.menu_setfont(font) - else: - EasyDialogs.Message("No active window?") - - def selface(self, id, item, *rest): - if self.active: - face = (1<<(item-1)) - self.active.menu_modface(face) - else: - EasyDialogs.Message("No active window?") - - def selfacenormal(self, *rest): - if self.active: - self.active.menu_setface(0) - else: - EasyDialogs.Message("No active window?") - - def selsize(self, id, item, *rest): - if self.active: - size = SIZES[item-1] - self.active.menu_setsize(size) - else: - EasyDialogs.Message("No active window?") - - def selsizebigger(self, *rest): - if self.active: - self.active.menu_incsize(2) - else: - EasyDialogs.Message("No active window?") - - def selsizesmaller(self, *rest): - if self.active: - self.active.menu_incsize(-2) - else: - EasyDialogs.Message("No active window?") - - def updatemenubar(self): - changed = 0 - on = (self.active <> None) - if on <> self.windowgroup_on: - for m in self.windowgroup: - m.enable(on) - self.windowgroup_on = on - changed = 1 - if on: - # only if we have an edit menu - on = self.active.have_selection() - if on <> self.focusgroup_on: - for m in self.focusgroup: - m.enable(on) - self.focusgroup_on = on - changed = 1 - on = self.active.can_paste() - if on <> self.pastegroup_on: - self.pasteitem.enable(on) - self.pastegroup_on = on - changed = 1 - on = self.active.can_undo() - if on <> self.undo_label: - if on: - self.undoitem.enable(1) - self.undoitem.settext(on) - self.undo_label = on - else: - self.undoitem.settext("Nothing to undo") - self.undoitem.enable(0) - changed = 1 - if self.updatefontmenus(): - changed = 1 - if changed: - DrawMenuBar() - - def updatefontmenus(self): - info = self.active.getruninfo() - if info == self.ffs_values: - return 0 - # Remove old checkmarks - if self.ffs_values == (): - self.ffs_values = (None, None, None) - font, face, size = self.ffs_values - if font <> None: - fnum = self.fontnames.index(font) - self.fontitems[fnum].check(0) - if face <> None: - for i in range(len(self.faceitems)): - if face & (1< None: - for i in range(len(self.sizeitems)): - if SIZES[i] == size: - self.sizeitems[i].check(0) - - self.ffs_values = info - # Set new checkmarks - font, face, size = self.ffs_values - if font <> None: - fnum = self.fontnames.index(font) - self.fontitems[fnum].check(1) - if face <> None: - for i in range(len(self.faceitems)): - if face & (1< None: - for i in range(len(self.sizeitems)): - if SIZES[i] == size: - self.sizeitems[i].check(1) - # Set outline/normal for sizes - if font: - exists = getfontsizes(font, SIZES) - for i in range(len(self.sizeitems)): - if exists[i]: - self.sizeitems[i].setstyle(0) - else: - self.sizeitems[i].setstyle(8) - - # - # Apple menu - # - - def do_about(self, id, item, window, event): - EasyDialogs.Message("A simple single-font text editor based on WASTE") - - # - # File menu - # - - def open(self, *args): - self._open(0) - - def openfile(self, *args): - self._open(1) - - def _open(self, askfile): - if askfile: - path = EasyDialogs.AskFileForOpen(typeList=('TEXT',)) - if not path: - return - name = os.path.split(path)[-1] - try: - fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line - data = fp.read() - fp.close() - except IOError, arg: - EasyDialogs.Message("IOERROR: %r" % (arg,)) - return - else: - path = None - name = "Untitled %d"%self.num - data = '' - w = WasteWindow(self) - w.open(path, name, data) - self.num = self.num + 1 - - def insertfile(self, *args): - if self.active: - path = EasyDialogs.AskFileForOpen(typeList=('TEXT',)) - if not path: - return - try: - fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line - except IOError, arg: - EasyDialogs.Message("IOERROR: %r" % (args,)) - return - self.active.menu_insert(fp) - else: - EasyDialogs.Message("No active window?") - - def inserthtml(self, *args): - if self.active: - path = EasyDialogs.AskFileForOpen(typeList=('TEXT',)) - if not path: - return - try: - fp = open(path, 'r') - except IOError, arg: - EasyDialogs.Message("IOERROR: %r" % (arg,)) - return - self.active.menu_insert_html(fp) - else: - EasyDialogs.Message("No active window?") - - - def closewin(self, *args): - if self.active: - self.active.close() - else: - EasyDialogs.Message("No active window?") - - def save(self, *args): - if self.active: - self.active.menu_save() - else: - EasyDialogs.Message("No active window?") - - def saveas(self, *args): - if self.active: - self.active.menu_save_as() - else: - EasyDialogs.Message("No active window?") - - - def quit(self, *args): - for w in self._windows.values(): - w.close() - if self._windows: - return - self._quit() - - # - # Edit menu - # - - def undo(self, *args): - if self.active: - self.active.menu_undo() - else: - EasyDialogs.Message("No active window?") - - def cut(self, *args): - if self.active: - self.active.menu_cut() - else: - EasyDialogs.Message("No active window?") - - def copy(self, *args): - if self.active: - self.active.menu_copy() - else: - EasyDialogs.Message("No active window?") - - def paste(self, *args): - if self.active: - self.active.menu_paste() - else: - EasyDialogs.Message("No active window?") - - def clear(self, *args): - if self.active: - self.active.menu_clear() - else: - EasyDialogs.Message("No active window?") - - # - # Other stuff - # - - def idle(self, event): - if self.active: - self.active.do_idle(event) - else: - Qd.SetCursor(Qd.GetQDGlobalsArrow()) - - def newRuler(self, obj): - """Insert a new ruler. Make it as wide as the window minus 2 pxls""" - ted = obj.WEGetObjectOwner() - l, t, r, b = ted.WEGetDestRect() - return r-l, 4 - - def drawRuler(self, (l, t, r, b), obj): - y = (t+b)/2 - Qd.MoveTo(l+2, y) - Qd.LineTo(r-2, y) - return 0 - -class MyHTMLParser(htmllib.HTMLParser): - - def anchor_bgn(self, href, name, type): - self.anchor = href - if self.anchor: - self.anchorlist.append(href) - self.formatter.push_style('anchor') - - def anchor_end(self): - if self.anchor: - self.anchor = None - self.formatter.pop_style() - - -def getfontnames(): - names = [] - for i in range(256): - n = Fm.GetFontName(i) - if n: names.append(n) - return names - -def getfontsizes(name, sizes): - exist = [] - num = Fm.GetFNum(name) - for sz in sizes: - if Fm.RealFont(num, sz): - exist.append(1) - else: - exist.append(0) - return exist - -def main(): - App = Wed() - App.mainloop() - -if __name__ == '__main__': - main() diff --git a/Mac/Demo/waste/swed.py b/Mac/Demo/waste/swed.py deleted file mode 100644 index 2078cce..0000000 --- a/Mac/Demo/waste/swed.py +++ /dev/null @@ -1,634 +0,0 @@ -# A minimal text editor. -# -# To be done: -# - Functionality: find, etc. - -from Carbon.Menu import DrawMenuBar -from FrameWork import * -from Carbon import Win -from Carbon import Qd -from Carbon import Res -from Carbon import Fm -import waste -import WASTEconst -from Carbon import Scrap -import os -import macfs - -UNDOLABELS = [ # Indexed by WEGetUndoInfo() value - None, "", "typing", "Cut", "Paste", "Clear", "Drag", "Style"] - -# Style and size menu. Note that style order is important (tied to bit values) -STYLES = [ - ("Bold", "B"), ("Italic", "I"), ("Underline", "U"), ("Outline", "O"), - ("Shadow", ""), ("Condensed", ""), ("Extended", "") - ] -SIZES = [ 9, 10, 12, 14, 18, 24] - -BIGREGION=Qd.NewRgn() -Qd.SetRectRgn(BIGREGION, -16000, -16000, 16000, 16000) - -class WasteWindow(ScrolledWindow): - def open(self, path, name, data): - self.path = path - self.name = name - r = windowbounds(400, 400) - w = Win.NewWindow(r, name, 1, 0, -1, 1, 0) - self.wid = w - vr = 0, 0, r[2]-r[0]-15, r[3]-r[1]-15 - dr = (0, 0, 10240, 0) - Qd.SetPort(w) - Qd.TextFont(4) - Qd.TextSize(9) - flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \ - WASTEconst.weDoUndo - self.ted = waste.WENew(dr, vr, flags) - self.ted.WEInstallTabHooks() - style, soup = self.getstylesoup() - self.ted.WEInsert(data, style, soup) - self.ted.WESetSelection(0,0) - self.ted.WECalText() - self.ted.WEResetModCount() - w.DrawGrowIcon() - self.scrollbars() - self.do_postopen() - self.do_activate(1, None) - - def getstylesoup(self): - if not self.path: - return None, None - oldrf = Res.CurResFile() - try: - rf = Res.FSpOpenResFile(self.path, 1) - except Res.Error: - return None, None - try: - hstyle = Res.Get1Resource('styl', 128) - hstyle.DetachResource() - except Res.Error: - hstyle = None - try: - hsoup = Res.Get1Resource('SOUP', 128) - hsoup.DetachResource() - except Res.Error: - hsoup = None - Res.CloseResFile(rf) - Res.UseResFile(oldrf) - return hstyle, hsoup - - def do_idle(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - self.ted.WEIdle() - if self.ted.WEAdjustCursor(where, BIGREGION): - return - Qd.SetCursor(Qd.GetQDGlobalsArrow()) - - def getscrollbarvalues(self): - dr = self.ted.WEGetDestRect() - vr = self.ted.WEGetViewRect() - vx = self.scalebarvalue(dr[0], dr[2], vr[0], vr[2]) - vy = self.scalebarvalue(dr[1], dr[3], vr[1], vr[3]) - return vx, vy - - def scrollbar_callback(self, which, what, value): - if which == 'y': - if what == 'set': - height = self.ted.WEGetHeight(0, 0x3fffffff) - cur = self.getscrollbarvalues()[1] - delta = (cur-value)*height/32767 - if what == '-': - topline_off,dummy = self.ted.WEGetOffset((1,1)) - topline_num = self.ted.WEOffsetToLine(topline_off) - delta = self.ted.WEGetHeight(topline_num, topline_num+1) - elif what == '--': - delta = (self.ted.WEGetViewRect()[3]-10) - if delta <= 0: - delta = 10 # Random value - elif what == '+': - # XXXX Wrong: should be bottom line size - topline_off,dummy = self.ted.WEGetOffset((1,1)) - topline_num = self.ted.WEOffsetToLine(topline_off) - delta = -self.ted.WEGetHeight(topline_num, topline_num+1) - elif what == '++': - delta = -(self.ted.WEGetViewRect()[3]-10) - if delta >= 0: - delta = -10 - self.ted.WEScroll(0, delta) - else: - if what == 'set': - return # XXXX - vr = self.ted.WEGetViewRect() - winwidth = vr[2]-vr[0] - if what == '-': - delta = winwidth/10 - elif what == '--': - delta = winwidth/2 - elif what == '+': - delta = -winwidth/10 - elif what == '++': - delta = -winwidth/2 - self.ted.WEScroll(delta, 0) - # Pin the scroll - l, t, r, b = self.ted.WEGetDestRect() - vl, vt, vr, vb = self.ted.WEGetViewRect() - if t > 0 or l > 0: - dx = dy = 0 - if t > 0: dy = -t - if l > 0: dx = -l - self.ted.WEScroll(dx, dy) - elif b < vb: - self.ted.WEScroll(0, b-vb) - - - def do_activate(self, onoff, evt): - Qd.SetPort(self.wid) - ScrolledWindow.do_activate(self, onoff, evt) - if onoff: - self.ted.WEActivate() - self.parent.active = self - self.parent.updatemenubar() - else: - self.ted.WEDeactivate() - - def do_update(self, wid, event): - region = wid.GetWindowPort().visRgn - if Qd.EmptyRgn(region): - return - Qd.EraseRgn(region) - self.ted.WEUpdate(region) - self.updatescrollbars() - - def do_postresize(self, width, height, window): - l, t, r, b = self.ted.WEGetViewRect() - vr = (l, t, l+width-15, t+height-15) - self.ted.WESetViewRect(vr) - self.wid.InvalWindowRect(vr) - ScrolledWindow.do_postresize(self, width, height, window) - - def do_contentclick(self, local, modifiers, evt): - (what, message, when, where, modifiers) = evt - self.ted.WEClick(local, modifiers, when) - self.updatescrollbars() - self.parent.updatemenubar() - - def do_char(self, ch, event): - self.ted.WESelView() - (what, message, when, where, modifiers) = event - self.ted.WEKey(ord(ch), modifiers) - self.updatescrollbars() - self.parent.updatemenubar() - - def close(self): - if self.ted.WEGetModCount(): - save = EasyDialogs.AskYesNoCancel('Save window "%s" before closing?'%self.name, 1) - if save > 0: - self.menu_save() - elif save < 0: - return - if self.parent.active == self: - self.parent.active = None - self.parent.updatemenubar() - del self.ted - self.do_postclose() - - def menu_save(self): - if not self.path: - self.menu_save_as() - return # Will call us recursively - # - # First save data - # - dhandle = self.ted.WEGetText() - data = dhandle.data - fp = open(self.path, 'wb') # NOTE: wb, because data has CR for end-of-line - fp.write(data) - if data[-1] <> '\r': fp.write('\r') - fp.close() - # - # Now save style and soup - # - oldresfile = Res.CurResFile() - try: - rf = Res.FSpOpenResFile(self.path, 3) - except Res.Error: - Res.FSpCreateResFile(self.path, '????', 'TEXT', macfs.smAllScripts) - rf = Res.FSpOpenResFile(self.path, 3) - styles = Res.Resource('') - soup = Res.Resource('') - self.ted.WECopyRange(0, 0x3fffffff, None, styles, soup) - styles.AddResource('styl', 128, '') - soup.AddResource('SOUP', 128, '') - Res.CloseResFile(rf) - Res.UseResFile(oldresfile) - - self.ted.WEResetModCount() - - def menu_save_as(self): - path = EasyDialogs.AskFileForSave(message='Save as:') - if not path: return - self.path = path - self.name = os.path.split(self.path)[-1] - self.wid.SetWTitle(self.name) - self.menu_save() - - def menu_cut(self): - self.ted.WESelView() - if hasattr(Scrap, 'ZeroScrap'): - Scrap.ZeroScrap() - else: - Scrap.ClearCurrentScrap() - self.ted.WECut() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_copy(self): - if hasattr(Scrap, 'ZeroScrap'): - Scrap.ZeroScrap() - else: - Scrap.ClearCurrentScrap() - self.ted.WECopy() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_paste(self): - self.ted.WESelView() - self.ted.WEPaste() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_clear(self): - self.ted.WESelView() - self.ted.WEDelete() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_undo(self): - self.ted.WEUndo() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_setfont(self, font): - font = Fm.GetFNum(font) - self.mysetstyle(WASTEconst.weDoFont, (font, 0, 0, (0,0,0))) - self.parent.updatemenubar() - - def menu_modface(self, face): - self.mysetstyle(WASTEconst.weDoFace|WASTEconst.weDoToggleFace, - (0, face, 0, (0,0,0))) - - def menu_setface(self, face): - self.mysetstyle(WASTEconst.weDoFace|WASTEconst.weDoReplaceFace, - (0, face, 0, (0,0,0))) - - def menu_setsize(self, size): - self.mysetstyle(WASTEconst.weDoSize, (0, 0, size, (0,0,0))) - - def menu_incsize(self, size): - self.mysetstyle(WASTEconst.weDoAddSize, (0, 0, size, (0,0,0))) - - def mysetstyle(self, which, how): - self.ted.WESelView() - self.ted.WESetStyle(which, how) - self.parent.updatemenubar() - - def have_selection(self): - start, stop = self.ted.WEGetSelection() - return start < stop - - def can_paste(self): - return self.ted.WECanPaste() - - def can_undo(self): - which, redo = self.ted.WEGetUndoInfo() - which = UNDOLABELS[which] - if which == None: return None - if redo: - return "Redo "+which - else: - return "Undo "+which - - def getruninfo(self): - all = (WASTEconst.weDoFont | WASTEconst.weDoFace | WASTEconst.weDoSize) - dummy, mode, (font, face, size, color) = self.ted.WEContinuousStyle(all) - if not (mode & WASTEconst.weDoFont): - font = None - else: - font = Fm.GetFontName(font) - if not (mode & WASTEconst.weDoFace): fact = None - if not (mode & WASTEconst.weDoSize): size = None - return font, face, size - -class Wed(Application): - def __init__(self): - Application.__init__(self) - self.num = 0 - self.active = None - self.updatemenubar() - waste.STDObjectHandlers() - - def makeusermenus(self): - self.filemenu = m = Menu(self.menubar, "File") - self.newitem = MenuItem(m, "New window", "N", self.open) - self.openitem = MenuItem(m, "Open...", "O", self.openfile) - self.closeitem = MenuItem(m, "Close", "W", self.closewin) - m.addseparator() - self.saveitem = MenuItem(m, "Save", "S", self.save) - self.saveasitem = MenuItem(m, "Save as...", "", self.saveas) - m.addseparator() - self.quititem = MenuItem(m, "Quit", "Q", self.quit) - - self.editmenu = m = Menu(self.menubar, "Edit") - self.undoitem = MenuItem(m, "Undo", "Z", self.undo) - self.cutitem = MenuItem(m, "Cut", "X", self.cut) - self.copyitem = MenuItem(m, "Copy", "C", self.copy) - self.pasteitem = MenuItem(m, "Paste", "V", self.paste) - self.clearitem = MenuItem(m, "Clear", "", self.clear) - - self.makefontmenu() - - # Groups of items enabled together: - self.windowgroup = [self.closeitem, self.saveitem, self.saveasitem, - self.editmenu, self.fontmenu, self.facemenu, self.sizemenu] - self.focusgroup = [self.cutitem, self.copyitem, self.clearitem] - self.windowgroup_on = -1 - self.focusgroup_on = -1 - self.pastegroup_on = -1 - self.undo_label = "never" - self.ffs_values = () - - def makefontmenu(self): - self.fontmenu = Menu(self.menubar, "Font") - self.fontnames = getfontnames() - self.fontitems = [] - for n in self.fontnames: - m = MenuItem(self.fontmenu, n, "", self.selfont) - self.fontitems.append(m) - self.facemenu = Menu(self.menubar, "Style") - self.faceitems = [] - for n, shortcut in STYLES: - m = MenuItem(self.facemenu, n, shortcut, self.selface) - self.faceitems.append(m) - self.facemenu.addseparator() - self.faceitem_normal = MenuItem(self.facemenu, "Normal", "N", - self.selfacenormal) - self.sizemenu = Menu(self.menubar, "Size") - self.sizeitems = [] - for n in SIZES: - m = MenuItem(self.sizemenu, repr(n), "", self.selsize) - self.sizeitems.append(m) - self.sizemenu.addseparator() - self.sizeitem_bigger = MenuItem(self.sizemenu, "Bigger", "+", - self.selsizebigger) - self.sizeitem_smaller = MenuItem(self.sizemenu, "Smaller", "-", - self.selsizesmaller) - - def selfont(self, id, item, *rest): - if self.active: - font = self.fontnames[item-1] - self.active.menu_setfont(font) - else: - EasyDialogs.Message("No active window?") - - def selface(self, id, item, *rest): - if self.active: - face = (1<<(item-1)) - self.active.menu_modface(face) - else: - EasyDialogs.Message("No active window?") - - def selfacenormal(self, *rest): - if self.active: - self.active.menu_setface(0) - else: - EasyDialogs.Message("No active window?") - - def selsize(self, id, item, *rest): - if self.active: - size = SIZES[item-1] - self.active.menu_setsize(size) - else: - EasyDialogs.Message("No active window?") - - def selsizebigger(self, *rest): - if self.active: - self.active.menu_incsize(2) - else: - EasyDialogs.Message("No active window?") - - def selsizesmaller(self, *rest): - if self.active: - self.active.menu_incsize(-2) - else: - EasyDialogs.Message("No active window?") - - def updatemenubar(self): - changed = 0 - on = (self.active <> None) - if on <> self.windowgroup_on: - for m in self.windowgroup: - m.enable(on) - self.windowgroup_on = on - changed = 1 - if on: - # only if we have an edit menu - on = self.active.have_selection() - if on <> self.focusgroup_on: - for m in self.focusgroup: - m.enable(on) - self.focusgroup_on = on - changed = 1 - on = self.active.can_paste() - if on <> self.pastegroup_on: - self.pasteitem.enable(on) - self.pastegroup_on = on - changed = 1 - on = self.active.can_undo() - if on <> self.undo_label: - if on: - self.undoitem.enable(1) - self.undoitem.settext(on) - self.undo_label = on - else: - self.undoitem.settext("Nothing to undo") - self.undoitem.enable(0) - changed = 1 - if self.updatefontmenus(): - changed = 1 - if changed: - DrawMenuBar() - - def updatefontmenus(self): - info = self.active.getruninfo() - if info == self.ffs_values: - return 0 - # Remove old checkmarks - if self.ffs_values == (): - self.ffs_values = (None, None, None) - font, face, size = self.ffs_values - if font <> None: - fnum = self.fontnames.index(font) - self.fontitems[fnum].check(0) - if face <> None: - for i in range(len(self.faceitems)): - if face & (1< None: - for i in range(len(self.sizeitems)): - if SIZES[i] == size: - self.sizeitems[i].check(0) - - self.ffs_values = info - # Set new checkmarks - font, face, size = self.ffs_values - if font <> None: - fnum = self.fontnames.index(font) - self.fontitems[fnum].check(1) - if face <> None: - for i in range(len(self.faceitems)): - if face & (1< None: - for i in range(len(self.sizeitems)): - if SIZES[i] == size: - self.sizeitems[i].check(1) - # Set outline/normal for sizes - if font: - exists = getfontsizes(font, SIZES) - for i in range(len(self.sizeitems)): - if exists[i]: - self.sizeitems[i].setstyle(0) - else: - self.sizeitems[i].setstyle(8) - - # - # Apple menu - # - - def do_about(self, id, item, window, event): - EasyDialogs.Message("A simple single-font text editor based on WASTE") - - # - # File menu - # - - def open(self, *args): - self._open(0) - - def openfile(self, *args): - self._open(1) - - def _open(self, askfile): - if askfile: - path = EasyDialogs.AskFileForOpen(typeList=('TEXT',)) - if not path: - return - name = os.path.split(path)[-1] - try: - fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line - data = fp.read() - fp.close() - except IOError, arg: - EasyDialogs.Message("IOERROR: %r" % (arg,)) - return - else: - path = None - name = "Untitled %d"%self.num - data = '' - w = WasteWindow(self) - w.open(path, name, data) - self.num = self.num + 1 - - def closewin(self, *args): - if self.active: - self.active.close() - else: - EasyDialogs.Message("No active window?") - - def save(self, *args): - if self.active: - self.active.menu_save() - else: - EasyDialogs.Message("No active window?") - - def saveas(self, *args): - if self.active: - self.active.menu_save_as() - else: - EasyDialogs.Message("No active window?") - - - def quit(self, *args): - for w in self._windows.values(): - w.close() - if self._windows: - return - self._quit() - - # - # Edit menu - # - - def undo(self, *args): - if self.active: - self.active.menu_undo() - else: - EasyDialogs.Message("No active window?") - - def cut(self, *args): - if self.active: - self.active.menu_cut() - else: - EasyDialogs.Message("No active window?") - - def copy(self, *args): - if self.active: - self.active.menu_copy() - else: - EasyDialogs.Message("No active window?") - - def paste(self, *args): - if self.active: - self.active.menu_paste() - else: - EasyDialogs.Message("No active window?") - - def clear(self, *args): - if self.active: - self.active.menu_clear() - else: - EasyDialogs.Message("No active window?") - - # - # Other stuff - # - - def idle(self, event): - if self.active: - self.active.do_idle(event) - else: - Qd.SetCursor(Qd.GetQDGlobalsArrow()) - -def getfontnames(): - names = [] - for i in range(256): - n = Fm.GetFontName(i) - if n: names.append(n) - return names - -def getfontsizes(name, sizes): - exist = [] - num = Fm.GetFNum(name) - for sz in sizes: - if Fm.RealFont(num, sz): - exist.append(1) - else: - exist.append(0) - return exist - -def main(): - App = Wed() - App.mainloop() - -if __name__ == '__main__': - main() diff --git a/Mac/Demo/waste/wed.py b/Mac/Demo/waste/wed.py deleted file mode 100644 index 28ee938..0000000 --- a/Mac/Demo/waste/wed.py +++ /dev/null @@ -1,426 +0,0 @@ -# A minimal text editor. -# -# To be done: -# - Functionality: find, etc. - -from Carbon.Menu import DrawMenuBar -from FrameWork import * -from Carbon import Win -from Carbon import Qd -from Carbon import Res -import waste -import WASTEconst -from Carbon import Scrap -import os -import EasyDialogs - -UNDOLABELS = [ # Indexed by WEGetUndoInfo() value - None, "", "typing", "Cut", "Paste", "Clear", "Drag", "Style"] - -BIGREGION=Qd.NewRgn() -Qd.SetRectRgn(BIGREGION, -16000, -16000, 16000, 16000) - -class WasteWindow(ScrolledWindow): - def open(self, path, name, data): - self.path = path - self.name = name - r = windowbounds(400, 400) - w = Win.NewWindow(r, name, 1, 0, -1, 1, 0) - self.wid = w - vr = 0, 0, r[2]-r[0]-15, r[3]-r[1]-15 - dr = (0, 0, 10240, 0) - Qd.SetPort(w) - Qd.TextFont(4) - Qd.TextSize(9) - flags = WASTEconst.weDoAutoScroll | WASTEconst.weDoOutlineHilite | \ - WASTEconst.weDoMonoStyled | WASTEconst.weDoUndo - self.ted = waste.WENew(dr, vr, flags) - self.tedtexthandle = Res.Resource(data) - self.ted.WEUseText(self.tedtexthandle) - self.ted.WECalText() - w.DrawGrowIcon() - self.scrollbars() - self.changed = 0 - self.do_postopen() - self.do_activate(1, None) - - def do_idle(self, event): - (what, message, when, where, modifiers) = event - Qd.SetPort(self.wid) - self.ted.WEIdle() - if self.ted.WEAdjustCursor(where, BIGREGION): - return - Qd.SetCursor(Qd.GetQDGlobalsArrow()) - - def getscrollbarvalues(self): - dr = self.ted.WEGetDestRect() - vr = self.ted.WEGetViewRect() - vx = self.scalebarvalue(dr[0], dr[2], vr[0], vr[2]) - vy = self.scalebarvalue(dr[1], dr[3], vr[1], vr[3]) -## print dr, vr, vx, vy - return vx, vy - - def scrollbar_callback(self, which, what, value): - if which == 'y': - if what == 'set': - height = self.ted.WEGetHeight(0, 0x3fffffff) - cur = self.getscrollbarvalues()[1] - delta = (cur-value)*height/32767 - if what == '-': - topline_off,dummy = self.ted.WEGetOffset((1,1)) - topline_num = self.ted.WEOffsetToLine(topline_off) - delta = self.ted.WEGetHeight(topline_num, topline_num+1) - elif what == '--': - delta = (self.ted.WEGetViewRect()[3]-10) - if delta <= 0: - delta = 10 # Random value - elif what == '+': - # XXXX Wrong: should be bottom line size - topline_off,dummy = self.ted.WEGetOffset((1,1)) - topline_num = self.ted.WEOffsetToLine(topline_off) - delta = -self.ted.WEGetHeight(topline_num, topline_num+1) - elif what == '++': - delta = -(self.ted.WEGetViewRect()[3]-10) - if delta >= 0: - delta = -10 - self.ted.WEScroll(0, delta) -## print 'SCROLL Y', delta - else: - if what == 'set': - return # XXXX - vr = self.ted.WEGetViewRect() - winwidth = vr[2]-vr[0] - if what == '-': - delta = winwidth/10 - elif what == '--': - delta = winwidth/2 - elif what == '+': - delta = -winwidth/10 - elif what == '++': - delta = -winwidth/2 - self.ted.WEScroll(delta, 0) - # Pin the scroll - l, t, r, b = self.ted.WEGetDestRect() - vl, vt, vr, vb = self.ted.WEGetViewRect() - if t > 0 or l > 0: - dx = dy = 0 - if t > 0: dy = -t - if l > 0: dx = -l -## print 'Extra scroll', dx, dy - self.ted.WEScroll(dx, dy) - elif b < vb: -## print 'Extra downscroll', b-vb - self.ted.WEScroll(0, b-vb) - - - def do_activate(self, onoff, evt): -## print "ACTIVATE", onoff - Qd.SetPort(self.wid) - ScrolledWindow.do_activate(self, onoff, evt) - if onoff: - self.ted.WEActivate() - self.parent.active = self - self.parent.updatemenubar() - else: - self.ted.WEDeactivate() - - def do_update(self, wid, event): - region = wid.GetWindowPort().visRgn - if Qd.EmptyRgn(region): - return - Qd.EraseRgn(region) - self.ted.WEUpdate(region) - self.updatescrollbars() - - def do_postresize(self, width, height, window): - l, t, r, b = self.ted.WEGetViewRect() - vr = (l, t, l+width-15, t+height-15) - self.ted.WESetViewRect(vr) - self.wid.InvalWindowRect(vr) - ScrolledWindow.do_postresize(self, width, height, window) - - def do_contentclick(self, local, modifiers, evt): - (what, message, when, where, modifiers) = evt - self.ted.WEClick(local, modifiers, when) - self.updatescrollbars() - self.parent.updatemenubar() - - def do_char(self, ch, event): - self.ted.WESelView() - (what, message, when, where, modifiers) = event - self.ted.WEKey(ord(ch), modifiers) - self.changed = 1 - self.updatescrollbars() - self.parent.updatemenubar() - - def close(self): - if self.changed: - save = EasyDialogs.AskYesNoCancel('Save window "%s" before closing?'%self.name, 1) - if save > 0: - self.menu_save() - elif save < 0: - return - if self.parent.active == self: - self.parent.active = None - self.parent.updatemenubar() - del self.ted - del self.tedtexthandle - self.do_postclose() - - def menu_save(self): - if not self.path: - self.menu_save_as() - return # Will call us recursively -## print 'Saving to ', self.path - dhandle = self.ted.WEGetText() - data = dhandle.data - fp = open(self.path, 'wb') # NOTE: wb, because data has CR for end-of-line - fp.write(data) - if data[-1] <> '\r': fp.write('\r') - fp.close() - self.changed = 0 - - def menu_save_as(self): - path = EasyDialogs.AskFileForSave(message='Save as:') - if not path: return - self.path = path - self.name = os.path.split(self.path)[-1] - self.wid.SetWTitle(self.name) - self.menu_save() - - def menu_cut(self): - self.ted.WESelView() - if hasattr(Scrap, 'ZeroScrap'): - Scrap.ZeroScrap() - else: - Scrap.ClearCurrentScrap() - self.ted.WECut() - self.updatescrollbars() - self.parent.updatemenubar() - self.changed = 1 - - def menu_copy(self): - if hasattr(Scrap, 'ZeroScrap'): - Scrap.ZeroScrap() - else: - Scrap.ClearCurrentScrap() - self.ted.WECopy() - self.updatescrollbars() - self.parent.updatemenubar() - - def menu_paste(self): - self.ted.WESelView() - self.ted.WEPaste() - self.updatescrollbars() - self.parent.updatemenubar() - self.changed = 1 - - def menu_clear(self): - self.ted.WESelView() - self.ted.WEDelete() - self.updatescrollbars() - self.parent.updatemenubar() - self.changed = 1 - - def menu_undo(self): - self.ted.WEUndo() - self.updatescrollbars() - self.parent.updatemenubar() - - def have_selection(self): - start, stop = self.ted.WEGetSelection() - return start < stop - - def can_paste(self): - return self.ted.WECanPaste() - - def can_undo(self): - which, redo = self.ted.WEGetUndoInfo() - which = UNDOLABELS[which] - if which == None: return None - if redo: - return "Redo "+which - else: - return "Undo "+which - -class Wed(Application): - def __init__(self): - Application.__init__(self) - self.num = 0 - self.active = None - self.updatemenubar() - - def makeusermenus(self): - self.filemenu = m = Menu(self.menubar, "File") - self.newitem = MenuItem(m, "New window", "N", self.open) - self.openitem = MenuItem(m, "Open...", "O", self.openfile) - self.closeitem = MenuItem(m, "Close", "W", self.closewin) - m.addseparator() - self.saveitem = MenuItem(m, "Save", "S", self.save) - self.saveasitem = MenuItem(m, "Save as...", "", self.saveas) - m.addseparator() - self.quititem = MenuItem(m, "Quit", "Q", self.quit) - - self.editmenu = m = Menu(self.menubar, "Edit") - self.undoitem = MenuItem(m, "Undo", "Z", self.undo) - self.cutitem = MenuItem(m, "Cut", "X", self.cut) - self.copyitem = MenuItem(m, "Copy", "C", self.copy) - self.pasteitem = MenuItem(m, "Paste", "V", self.paste) - self.clearitem = MenuItem(m, "Clear", "", self.clear) - - # Groups of items enabled together: - self.windowgroup = [self.closeitem, self.saveitem, self.saveasitem, self.editmenu] - self.focusgroup = [self.cutitem, self.copyitem, self.clearitem] - self.windowgroup_on = -1 - self.focusgroup_on = -1 - self.pastegroup_on = -1 - self.undo_label = "never" - - def updatemenubar(self): - changed = 0 - on = (self.active <> None) - if on <> self.windowgroup_on: - for m in self.windowgroup: - m.enable(on) - self.windowgroup_on = on - changed = 1 - if on: - # only if we have an edit menu - on = self.active.have_selection() - if on <> self.focusgroup_on: - for m in self.focusgroup: - m.enable(on) - self.focusgroup_on = on - changed = 1 - on = self.active.can_paste() - if on <> self.pastegroup_on: - self.pasteitem.enable(on) - self.pastegroup_on = on - changed = 1 - on = self.active.can_undo() - if on <> self.undo_label: - if on: - self.undoitem.enable(1) - self.undoitem.settext(on) - self.undo_label = on - else: - self.undoitem.settext("Nothing to undo") - self.undoitem.enable(0) - changed = 1 - if changed: - DrawMenuBar() - - # - # Apple menu - # - - def do_about(self, id, item, window, event): - EasyDialogs.Message("A simple single-font text editor based on WASTE") - - # - # File menu - # - - def open(self, *args): - self._open(0) - - def openfile(self, *args): - self._open(1) - - def _open(self, askfile): - if askfile: - path = EasyDialogs.AskFileForOpen(typeList=('TEXT',)) - if not path: - return - name = os.path.split(path)[-1] - try: - fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line - data = fp.read() - fp.close() - except IOError, arg: - EasyDialogs.Message("IOERROR: %r" % (arg,)) - return - else: - path = None - name = "Untitled %d"%self.num - data = '' - w = WasteWindow(self) - w.open(path, name, data) - self.num = self.num + 1 - - def closewin(self, *args): - if self.active: - self.active.close() - else: - EasyDialogs.Message("No active window?") - - def save(self, *args): - if self.active: - self.active.menu_save() - else: - EasyDialogs.Message("No active window?") - - def saveas(self, *args): - if self.active: - self.active.menu_save_as() - else: - EasyDialogs.Message("No active window?") - - - def quit(self, *args): - for w in self._windows.values(): - w.close() - if self._windows: - return - self._quit() - - # - # Edit menu - # - - def undo(self, *args): - if self.active: - self.active.menu_undo() - else: - EasyDialogs.Message("No active window?") - - def cut(self, *args): - if self.active: - self.active.menu_cut() - else: - EasyDialogs.Message("No active window?") - - def copy(self, *args): - if self.active: - self.active.menu_copy() - else: - EasyDialogs.Message("No active window?") - - def paste(self, *args): - if self.active: - self.active.menu_paste() - else: - EasyDialogs.Message("No active window?") - - def clear(self, *args): - if self.active: - self.active.menu_clear() - else: - EasyDialogs.Message("No active window?") - - # - # Other stuff - # - - def idle(self, event): - if self.active: - self.active.do_idle(event) - else: - Qd.SetCursor(Qd.GetQDGlobalsArrow()) - -def main(): - App = Wed() - App.mainloop() - -if __name__ == '__main__': - main() diff --git a/Mac/Extras.ReadMe.txt b/Mac/Extras.ReadMe.txt new file mode 100644 index 0000000..2d7fd42 --- /dev/null +++ b/Mac/Extras.ReadMe.txt @@ -0,0 +1,5 @@ +This folder contains examples of Python usage and useful scripts and tools. + +You should be aware that these are not Macintosh-specific but are shared +among Python on all platforms, so there are some that only run on Windows +or Unix or another platform, and/or make little sense on a Macintosh. diff --git a/Mac/Extras.install.py b/Mac/Extras.install.py new file mode 100644 index 0000000..ce00af3 --- /dev/null +++ b/Mac/Extras.install.py @@ -0,0 +1,54 @@ +"""Recursively copy a directory but skip undesired files and +directories (CVS, backup files, pyc files, etc)""" + +import sys +import os +import shutil + +verbose = 1 +debug = 0 + +def isclean(name): + if name == 'CVS': return 0 + if name == '.cvsignore': return 0 + if name == '.DS_store': return 0 + if name == '.svn': return 0 + if name.endswith('~'): return 0 + if name.endswith('.BAK'): return 0 + if name.endswith('.pyc'): return 0 + if name.endswith('.pyo'): return 0 + if name.endswith('.orig'): return 0 + return 1 + +def copycleandir(src, dst): + for cursrc, dirs, files in os.walk(src): + assert cursrc.startswith(src) + curdst = dst + cursrc[len(src):] + if verbose: + print "mkdir", curdst + if not debug: + if not os.path.exists(curdst): + os.makedirs(curdst) + for fn in files: + if isclean(fn): + if verbose: + print "copy", os.path.join(cursrc, fn), os.path.join(curdst, fn) + if not debug: + shutil.copy2(os.path.join(cursrc, fn), os.path.join(curdst, fn)) + else: + if verbose: + print "skipfile", os.path.join(cursrc, fn) + for i in range(len(dirs)-1, -1, -1): + if not isclean(dirs[i]): + if verbose: + print "skipdir", os.path.join(cursrc, dirs[i]) + del dirs[i] + +def main(): + if len(sys.argv) != 3: + sys.stderr.write("Usage: %s srcdir dstdir\n" % sys.argv[0]) + sys.exit(1) + copycleandir(sys.argv[1], sys.argv[2]) + +if __name__ == '__main__': + main() diff --git a/Mac/IDLE/Info.plist.in b/Mac/IDLE/Info.plist.in new file mode 100644 index 0000000..58e913c --- /dev/null +++ b/Mac/IDLE/Info.plist.in @@ -0,0 +1,55 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + py + pyw + + CFBundleTypeIconFile + PythonSource.icns + CFBundleTypeName + Python Script + CFBundleTypeRole + Editor + + + CFBundleTypeExtensions + + pyc + pyo + + CFBundleTypeIconFile + PythonCompiled.icns + CFBundleTypeName + Python Bytecode Document + CFBundleTypeRole + Editor + + + CFBundleExecutable + IDLE + CFBundleGetInfoString + %VERSION%, © 001-2006 Python Software Foundation + CFBundleIconFile + IDLE.icns + CFBundleIdentifier + org.python.IDLE + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + IDLE + CFBundlePackageType + APPL + CFBundleShortVersionString + %VERSION% + CFBundleVersion + %VERSION% + + diff --git a/Mac/IDLE/Makefile.in b/Mac/IDLE/Makefile.in new file mode 100644 index 0000000..2f63892 --- /dev/null +++ b/Mac/IDLE/Makefile.in @@ -0,0 +1,59 @@ +prefix=@prefix@ +CC=@CC@ +LD=@CC@ +BASECFLAGS=@BASECFLAGS@ +OPT=@OPT@ +CFLAGS=$(BASECFLAGS) $(OPT) +LDFLAGS=@LDFLAGS@ +srcdir= @srcdir@ +VERSION= @VERSION@ +UNIVERSALSDK=@UNIVERSALSDK@ +builddir= ../.. + +RUNSHARED= @RUNSHARED@ +BUILDEXE= @BUILDEXEEXT@ +BUILDPYTHON= $(builddir)/python$(BUILDEXE) + +# Deployment target selected during configure, to be checked +# by distutils +MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ +@EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET + +BUNDLEBULDER=$(srcdir)/../../Lib/plat-mac/bundlebuilder.py + +PYTHONAPPSDIR=/Applications/MacPython $(VERSION) + +all: IDLE.app + +install: IDLE.app $(srcdir)/config-main.def $(srcdir)/config-extensions.def + test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" + -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" + cp -PR IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" + touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" + cp $(srcdir)/config-main.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-main.def" + cp $(srcdir)/config-extensions.def "$(DESTDIR)$(prefix)/lib/python$(VERSION)/idlelib/config-extensions.def" + +clean: + rm -rf IDLE.app + +IDLE.app: \ + $(srcdir)/../Icons/IDLE.icns $(srcdir)/idlemain.py \ + $(srcdir)/../Icons/PythonSource.icns \ + $(srcdir)/../Icons/PythonCompiled.icns Info.plist + rm -fr IDLE.app + $(RUNSHARED) $(BUILDPYTHON) $(BUNDLEBULDER) \ + --builddir=. \ + --name=IDLE \ + --link-exec \ + --plist=Info.plist \ + --mainprogram=$(srcdir)/idlemain.py \ + --iconfile=$(srcdir)/../Icons/IDLE.icns \ + --resource=$(srcdir)/../Icons/PythonSource.icns \ + --resource=$(srcdir)/../Icons/PythonCompiled.icns \ + --python=$(prefix)/Resources/Python.app/Contents/MacOS/Python \ + build + + +Info.plist: $(srcdir)/Info.plist.in + sed 's/%VERSION%/'"`$(RUNSHARED) $(BUILDPYTHON) -c 'import platform; print platform.python_version()'`"'/g' < $(srcdir)/Info.plist.in > Info.plist + diff --git a/Mac/IDLE/config-extensions.def b/Mac/IDLE/config-extensions.def new file mode 100644 index 0000000..c17f068 --- /dev/null +++ b/Mac/IDLE/config-extensions.def @@ -0,0 +1,88 @@ +# config-extensions.def +# +# IDLE reads several config files to determine user preferences. This +# file is the default configuration file for IDLE extensions settings. +# +# Each extension must have at least one section, named after the extension +# module. This section must contain an 'enable' item (=1 to enable the +# extension, =0 to disable it), it may contain 'enable_editor' or 'enable_shell' +# items, to apply it only to editor/shell windows, and may also contain any +# other general configuration items for the extension. +# +# Each extension must define at least one section named ExtensionName_bindings +# or ExtensionName_cfgBindings. If present, ExtensionName_bindings defines +# virtual event bindings for the extension that are not user re-configurable. +# If present, ExtensionName_cfgBindings defines virtual event bindings for the +# extension that may be sensibly re-configured. +# +# If there are no keybindings for a menus' virtual events, include lines like +# <>= (See [CodeContext], below.) +# +# Currently it is necessary to manually modify this file to change extension +# key bindings and default values. To customize, create +# ~/.idlerc/config-extensions.cfg and append the appropriate customized +# section(s). Those sections will override the defaults in this file. +# +# Note: If a keybinding is already in use when the extension is +# loaded, the extension's virtual event's keybinding will be set to ''. +# +# See config-keys.def for notes on specifying keys and extend.txt for +# information on creating IDLE extensions. + +[FormatParagraph] +enable=1 +[FormatParagraph_cfgBindings] +format-paragraph= + +[AutoExpand] +enable=1 +[AutoExpand_cfgBindings] +expand-word= + +[ZoomHeight] +enable=1 +[ZoomHeight_cfgBindings] +zoom-height= + +[ScriptBinding] +enable=1 +[ScriptBinding_cfgBindings] +run-module= +check-module= + +[CallTips] +enable=1 +[CallTips_cfgBindings] +force-open-calltip= +[CallTips_bindings] +try-open-calltip= +refresh-calltip= + +[ParenMatch] +enable=1 +style= expression +flash-delay= 500 +bell= 1 +[ParenMatch_cfgBindings] +flash-paren= +[ParenMatch_bindings] +paren-closed= + +[AutoComplete] +enable=1 +popupwait=2000 +[AutoComplete_cfgBindings] +force-open-completions= +[AutoComplete_bindings] +autocomplete= +try-open-completions= + +[CodeContext] +enable=1 +enable_shell=0 +numlines=3 +visible=0 +bgcolor=LightGray +fgcolor=Black +[CodeContext_bindings] +toggle-code-context= diff --git a/Mac/IDLE/config-main.def b/Mac/IDLE/config-main.def new file mode 100644 index 0000000..1cdc0c5 --- /dev/null +++ b/Mac/IDLE/config-main.def @@ -0,0 +1,79 @@ +# IDLE reads several config files to determine user preferences. This +# file is the default config file for general idle settings. +# +# When IDLE starts, it will look in +# the following two sets of files, in order: +# +# default configuration +# --------------------- +# config-main.def the default general config file +# config-extensions.def the default extension config file +# config-highlight.def the default highlighting config file +# config-keys.def the default keybinding config file +# +# user configuration +# ------------------- +# ~/.idlerc/config-main.cfg the user general config file +# ~/.idlerc/config-extensions.cfg the user extension config file +# ~/.idlerc/config-highlight.cfg the user highlighting config file +# ~/.idlerc/config-keys.cfg the user keybinding config file +# +# On Windows2000 and Windows XP the .idlerc directory is at +# Documents and Settings\\.idlerc +# +# On Windows98 it is at c:\.idlerc +# +# Any options the user saves through the config dialog will be saved to +# the relevant user config file. Reverting any general setting to the +# default causes that entry to be wiped from the user file and re-read +# from the default file. User highlighting themes or keybinding sets are +# retained unless specifically deleted within the config dialog. Choosing +# one of the default themes or keysets just applies the relevant settings +# from the default file. +# +# Additional help sources are listed in the [HelpFiles] section and must be +# viewable by a web browser (or the Windows Help viewer in the case of .chm +# files). These sources will be listed on the Help menu. The pattern is +# +# You can't use a semi-colon in a menu item or path. The path will be platform +# specific because of path separators, drive specs etc. +# +# It is best to use the Configuration GUI to set up additional help sources! +# Example: +#1 = My Extra Help Source;/usr/share/doc/foo/index.html +#2 = Another Help Source;/path/to/another.pdf + +[General] +editor-on-startup= 0 +autosave= 0 +print-command-posix=lpr %s +print-command-win=start /min notepad /p %s +delete-exitfunc= 1 + +[EditorWindow] +width= 80 +height= 40 +font= courier +font-size= 10 +font-bold= 0 +encoding= none + +[FormatParagraph] +paragraph=70 + +[Indent] +use-spaces= 1 +num-spaces= 4 + +[Theme] +default= 1 +name= IDLE Classic + +[Keys] +default= 1 +name= IDLE Classic Mac + +[History] +cyclic=1 + +[HelpFiles] diff --git a/Mac/IDLE/idlemain.py b/Mac/IDLE/idlemain.py new file mode 100644 index 0000000..aa75d4c --- /dev/null +++ b/Mac/IDLE/idlemain.py @@ -0,0 +1,27 @@ +""" +Bootstrap script for IDLE as an application bundle. +""" +import sys, os + +from idlelib.PyShell import main + +# Change the current directory the user's home directory, that way we'll get +# a more useful default location in the open/save dialogs. +os.chdir(os.path.expanduser('~/Documents')) + + +# Make sure sys.executable points to the python interpreter inside the +# framework, instead of at the helper executable inside the application +# bundle (the latter works, but doesn't allow access to the window server) +sys.executable = os.path.join(sys.prefix, 'bin', 'python') + +# Look for the -psn argument that the launcher adds and remove it, it will +# only confuse the IDLE startup code. +for idx, value in enumerate(sys.argv): + if value.startswith('-psn_'): + del sys.argv[idx] + break + +#argvemulator.ArgvCollector().mainloop() +if __name__ == '__main__': + main() diff --git a/Mac/Icons/Disk Image.icns b/Mac/Icons/Disk Image.icns new file mode 100644 index 0000000..35f16bf Binary files /dev/null and b/Mac/Icons/Disk Image.icns differ diff --git a/Mac/Icons/IDLE.icns b/Mac/Icons/IDLE.icns new file mode 100644 index 0000000..c12c9da Binary files /dev/null and b/Mac/Icons/IDLE.icns differ diff --git a/Mac/Icons/Python Folder.icns b/Mac/Icons/Python Folder.icns new file mode 100644 index 0000000..ae766ee Binary files /dev/null and b/Mac/Icons/Python Folder.icns differ diff --git a/Mac/Icons/PythonCompiled.icns b/Mac/Icons/PythonCompiled.icns new file mode 100644 index 0000000..7d9f320 Binary files /dev/null and b/Mac/Icons/PythonCompiled.icns differ diff --git a/Mac/Icons/PythonLauncher.icns b/Mac/Icons/PythonLauncher.icns new file mode 100644 index 0000000..e09fd38 Binary files /dev/null and b/Mac/Icons/PythonLauncher.icns differ diff --git a/Mac/Icons/PythonSource.icns b/Mac/Icons/PythonSource.icns new file mode 100644 index 0000000..9e35c1e Binary files /dev/null and b/Mac/Icons/PythonSource.icns differ diff --git a/Mac/Icons/ReadMe.txt b/Mac/Icons/ReadMe.txt new file mode 100644 index 0000000..226836a --- /dev/null +++ b/Mac/Icons/ReadMe.txt @@ -0,0 +1,3 @@ +The icons for use on MacOS X were created by Jacob Rus +with some feedback from the folks on pythonmac-sig@python.org. + diff --git a/Mac/Makefile.in b/Mac/Makefile.in new file mode 100644 index 0000000..82514b2 --- /dev/null +++ b/Mac/Makefile.in @@ -0,0 +1,251 @@ +# This file can be invoked from the various frameworkinstall... targets in the +# main Makefile. The next couple of variables are overridden on the +# commandline in that case. + +VERSION=@VERSION@ +builddir = .. +srcdir=@srcdir@ +prefix=/Library/Frameworks/Python.framework/Versions/$(VERSION) +LIBDEST=$(prefix)/lib/python$(VERSION) +RUNSHARED=@RUNSHARED@ +BUILDEXE=@BUILDEXEEXT@ +BUILDPYTHON=$(builddir)/python$(BUILDEXE) +DESTDIR= +LDFLAGS=@LDFLAGS@ +FRAMEWORKUNIXTOOLSPREFIX=@FRAMEWORKUNIXTOOLSPREFIX@ + +# These are normally glimpsed from the previous set +bindir=$(prefix)/bin +PYTHONAPPSDIR=/Applications/MacPython $(VERSION) +APPINSTALLDIR=$(prefix)/Resources/Python.app + +# Variables for installing the "normal" unix binaries +INSTALLED_PYTHONAPP=$(APPINSTALLDIR)/Contents/MacOS/Python + +# Items more-or-less copied from the main Makefile +DIRMODE=755 +FILEMODE=644 +INSTALL=@INSTALL@ +INSTALL_SYMLINK=ln -fsn +INSTALL_PROGRAM=@INSTALL_PROGRAM@ +INSTALL_SCRIPT= @INSTALL_SCRIPT@ +INSTALL_DATA=@INSTALL_DATA@ +LN=@LN@ +STRIPFLAG=-s +CPMAC=/Developer/Tools/CpMac + +APPTEMPLATE=$(srcdir)/Resources/app +APPSUBDIRS=MacOS Resources Resources/English.lproj \ + Resources/English.lproj/Documentation \ + Resources/English.lproj/Documentation/doc \ + Resources/English.lproj/Documentation/ide +DOCDIR=$(srcdir)/Resources/app/Resources/English.lproj/Documentation +DOCINDEX=$(DOCDIR)/"Documentation idx" +CACHERSRC=$(srcdir)/scripts/cachersrc.py +compileall=$(srcdir)/../Lib/compileall.py + +installapps: install_Python install_BuildApplet install_PythonLauncher \ + install_IDLE checkapplepython install_pythonw install_versionedtools + +install_pythonw: pythonw + $(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)" + $(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/python$(VERSION)" + ln -sf python$(VERSION) "$(DESTDIR)$(prefix)/bin/python" + ln -sf pythonw$(VERSION) "$(DESTDIR)$(prefix)/bin/pythonw" + +# +# Install unix tools in /usr/local/bin. These are just aliases for the +# actual installation inside the framework. +# +installunixtools: + if [ ! -d "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ]; then \ + $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ;\ + fi + for fn in python pythonw idle pydoc python-config smtpd.py \ + python$(VERSION) pythonw$(VERSION) idle$(VERSION) \ + pydoc$(VERSION) python-config$(VERSION) smtpd$(VERSION).py ;\ + do \ + ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\ + done + +# +# Like installunixtools, but only install links to the versioned binaries. +# +altinstallunixtools: + if [ ! -d "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ]; then \ + $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ;\ + fi + for fn in python$(VERSION) pythonw$(VERSION) idle$(VERSION) \ + pydoc$(VERSION) python-config$(VERSION) smtpd$(VERSION).py ;\ + do \ + ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\ + done + + +# By default most tools are installed without a version in their basename, to +# make it easier to install (and use) several python versions side-by-side move +# the tools to a version-specific name and add the non-versioned name as an +# alias. +install_versionedtools: + for fn in idle pydoc python-config ;\ + do \ + if [ -h "$(DESTDIR)$(prefix)/bin/$${fn}" ]; then \ + continue ;\ + fi ;\ + mv "$(DESTDIR)$(prefix)/bin/$${fn}" "$(DESTDIR)$(prefix)/bin/$${fn}$(VERSION)" ;\ + ln -sf "$${fn}$(VERSION)" "$(DESTDIR)$(prefix)/bin/$${fn}" ;\ + done + if [ ! -h "$(DESTDIR)$(prefix)/bin/smtpd.py" ]; then \ + mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py" ;\ + ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py" ;\ + fi + + +pythonw: $(srcdir)/Tools/pythonw.c + $(CC) $(LDFLAGS) -o $@ $(srcdir)/Tools/pythonw.c \ + -DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/Python"' + + +install_PythonLauncher: + cd PythonLauncher && make install DESTDIR=$(DESTDIR) + +install_Python: + @if test ! -f $(DOCINDEX); then \ + echo WARNING: you should run Apple Help Indexing Tool on $(DOCDIR); \ + fi + @for i in "$(PYTHONAPPSDIR)" "$(APPINSTALLDIR)" "$(APPINSTALLDIR)/Contents"; do \ + if test ! -d "$(DESTDIR)$$i"; then \ + echo "Creating directory $(DESTDIR)$$i"; \ + $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$$i"; \ + fi;\ + done + @for i in $(APPSUBDIRS); do \ + if test ! -d "$(DESTDIR)$(APPINSTALLDIR)/Contents/$$i"; then \ + echo "Creating directory $(DESTDIR)$(APPINSTALLDIR)/Contents/$$i"; \ + $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(APPINSTALLDIR)/Contents/$$i"; \ + else true; \ + fi; \ + done + @for d in . $(APPSUBDIRS); \ + do \ + a=$(APPTEMPLATE)/$$d; \ + if test ! -d $$a; then continue; else true; fi; \ + b="$(DESTDIR)$(APPINSTALLDIR)/Contents/$$d"; \ + for i in $$a/*; \ + do \ + case $$i in \ + *CVS) ;; \ + *.svn) ;; \ + *.py[co]) ;; \ + *.orig) ;; \ + *~) ;; \ + *idx) \ + echo $(CPMAC) "$$i" $$b; \ + $(CPMAC) "$$i" "$$b"; \ + ;; \ + *) \ + if test -d $$i; then continue; fi; \ + if test -x $$i; then \ + echo $(INSTALL_SCRIPT) "$$i" "$$b"; \ + $(INSTALL_SCRIPT) "$$i" "$$b"; \ + else \ + echo $(INSTALL_DATA) "$$i" "$$b"; \ + $(INSTALL_DATA) "$$i" "$$b"; \ + fi;; \ + esac; \ + done; \ + done + $(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/Python" + +install_IDLE: + cd IDLE && make install + +install_BuildApplet: + $(RUNSHARED) $(BUILDPYTHON) $(srcdir)/scripts/BuildApplet.py \ + --destroot "$(DESTDIR)" \ + --python $(INSTALLED_PYTHONAPP) \ + --output "$(DESTDIR)$(PYTHONAPPSDIR)/Build Applet.app" \ + $(srcdir)/scripts/BuildApplet.py + +MACLIBDEST=$(LIBDEST)/plat-mac +MACTOOLSDEST=$(prefix)/Mac/Tools +MACTOOLSSRC=$(srcdir)/Mac/Tools +MACTOOLSSUBDIRS=IDE + +installmacsubtree: + @for i in $(MACTOOLSDEST); \ + do \ + if test ! -d $(DESTDIR)$$i; then \ + echo "Creating directory $(DESTDIR)$$i"; \ + $(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \ + else true; \ + fi; \ + done + @for d in $(MACTOOLSSUBDIRS); \ + do \ + a=$(MACTOOLSSRC)/$$d; \ + if test ! -d $$a; then continue; else true; fi; \ + b=$(DESTDIR)$(MACTOOLSDEST)/$$d; \ + if test ! -d $$b; then \ + echo "Creating directory $$b"; \ + $(INSTALL) -d -m $(DIRMODE) $$b; \ + else true; \ + fi; \ + done + @for d in $(MACTOOLSSUBDIRS); \ + do \ + a=$(MACTOOLSSRC)/$$d; \ + if test ! -d $$a; then continue; else true; fi; \ + b=$(DESTDIR)$(MACTOOLSDEST)/$$d; \ + for i in $$a/*; \ + do \ + case $$i in \ + *CVS) ;; \ + *.svn) ;; \ + *.py[co]) ;; \ + *.orig) ;; \ + *~) ;; \ + *.rsrc) \ + echo $(CPMAC) $$i $$b ; \ + $(CPMAC) $$i $$b ; \ + ;; \ + *) \ + if test -d $$i; then continue; fi; \ + if test -x $$i; then \ + echo $(INSTALL_SCRIPT) $$i $$b; \ + $(INSTALL_SCRIPT) $$i $$b; \ + else \ + echo $(INSTALL_DATA) $$i $$b; \ + $(INSTALL_DATA) $$i $$b; \ + fi;; \ + esac; \ + done; \ + done + + + $(RUNSHARED) $(BUILDPYTHON) $(CACHERSRC) -v $(DESTDIR)$(MACLIBDEST) $(DESTDIR)$(MACTOOLSDEST) + $(RUNSHARED) $(BUILDPYTHON) -Wi -tt $(compileall) -d $(MACTOOLSDEST) -x badsyntax $(DESTDIR)$(MACTOOLSDEST) + $(RUNSHARED) $(BUILDPYTHON) -O -Wi -tt $(compileall) -d $(MACTOOLSDEST) -x badsyntax $(DESTDIR)$(MACTOOLSDEST) + +$(INSTALLED_PYTHONAPP): install_Python + +installextras: $(srcdir)/Extras.ReadMe.txt $(srcdir)/Extras.install.py + $(INSTALL) -d "$(DESTDIR)$(PYTHONAPPSDIR)/Extras" + $(INSTALL) $(srcdir)/Extras.ReadMe.txt "$(DESTDIR)$(PYTHONAPPSDIR)/Extras/ReadMe.txt" + $(RUNSHARED) $(BUILDPYTHON) $(srcdir)/Extras.install.py $(srcdir)/../Demo \ + "$(DESTDIR)$(PYTHONAPPSDIR)/Extras/Demo" + $(RUNSHARED) $(BUILDPYTHON) $(srcdir)/Extras.install.py $(srcdir)/Demo \ + "$(DESTDIR)$(PYTHONAPPSDIR)/Extras/Demo.Mac" + + +checkapplepython: $(srcdir)/Tools/fixapplepython23.py + @if ! $(RUNSHARED) $(BUILDPYTHON) $(srcdir)/Tools/fixapplepython23.py -n; then \ + echo "* WARNING: Apple-installed Python 2.3 will have trouble building extensions from now on."; \ + echo "* WARNING: Run $(srcdir)/Tools/fixapplepython23.py with \"sudo\" to fix this."; \ + fi + + +clean: + rm pythonw + cd PythonLauncher && make clean + cd IDLE && make clean diff --git a/Mac/Modules/waste/wastemodule.c b/Mac/Modules/waste/wastemodule.c deleted file mode 100644 index b8234f0..0000000 --- a/Mac/Modules/waste/wastemodule.c +++ /dev/null @@ -1,2596 +0,0 @@ - -/* ========================== Module waste ========================== */ - -#include "Python.h" - - - -#include "pymactoolbox.h" - -/* Macro to test whether a weak-loaded CFM function exists */ -#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ - PyErr_SetString(PyExc_NotImplementedError, \ - "Not available in this shared library/OS version"); \ - return NULL; \ - }} while(0) - - -#include -#include -#include - -/* Exported by Qdmodule.c: */ -extern PyObject *QdRGB_New(RGBColor *); -extern int QdRGB_Convert(PyObject *, RGBColor *); - -/* Exported by AEModule.c: */ -extern PyObject *AEDesc_New(AppleEvent *); -extern int AEDesc_Convert(PyObject *, AppleEvent *); - -/* Forward declaration */ -static PyObject *WEOObj_New(WEObjectReference); -static PyObject *ExistingwasteObj_New(WEReference); - -/* -** Parse/generate TextStyle records -*/ -static PyObject * -TextStyle_New(TextStylePtr itself) -{ - - return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New, - &itself->tsColor); -} - -static int -TextStyle_Convert(PyObject *v, TextStylePtr p_itself) -{ - long font, face, size; - - if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) ) - return 0; - p_itself->tsFont = (short)font; - p_itself->tsFace = (Style)face; - p_itself->tsSize = (short)size; - return 1; -} - -/* -** Parse/generate RunInfo records -*/ -static PyObject * -RunInfo_New(WERunInfo *itself) -{ - - return Py_BuildValue("llhhO&O&", itself->runStart, itself->runEnd, itself->runHeight, - itself->runAscent, TextStyle_New, &itself->runStyle, WEOObj_New, itself->runObject); -} - -/* Conversion of long points and rects */ -int -LongRect_Convert(PyObject *v, LongRect *r) -{ - return PyArg_Parse(v, "(llll)", &r->left, &r->top, &r->right, &r->bottom); -} - -PyObject * -LongRect_New(LongRect *r) -{ - return Py_BuildValue("(llll)", r->left, r->top, r->right, r->bottom); -} - -int -LongPt_Convert(PyObject *v, LongPt *p) -{ - return PyArg_Parse(v, "(ll)", &p->h, &p->v); -} - -PyObject * -LongPt_New(LongPt *p) -{ - return Py_BuildValue("(ll)", p->h, p->v); -} - -/* Stuff for the callbacks: */ -static PyObject *callbackdict; -WENewObjectUPP upp_new_handler; -WEDisposeObjectUPP upp_dispose_handler; -WEDrawObjectUPP upp_draw_handler; -WEClickObjectUPP upp_click_handler; - -static OSErr -any_handler(WESelector what, WEObjectReference who, PyObject *args, PyObject **rv) -{ - FlavorType tp; - PyObject *key, *func; - - if ( args == NULL ) return errAECorruptData; - - tp = WEGetObjectType(who); - - if( (key=Py_BuildValue("O&O&", PyMac_BuildOSType, tp, PyMac_BuildOSType, what)) == NULL) - return errAECorruptData; - if( (func = PyDict_GetItem(callbackdict, key)) == NULL ) { - Py_DECREF(key); - return errAEHandlerNotFound; - } - Py_INCREF(func); - *rv = PyEval_CallObject(func, args); - Py_DECREF(func); - Py_DECREF(key); - if ( *rv == NULL ) { - PySys_WriteStderr("--Exception in callback: "); - PyErr_Print(); - return errAEReplyNotArrived; - } - return 0; -} - -static pascal OSErr -my_new_handler(Point *objectSize, WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - OSErr err; - - args=Py_BuildValue("(O&)", WEOObj_New, objref); - err = any_handler(weNewHandler, objref, args, &rv); - if (!err) { - if (!PyMac_GetPoint(rv, objectSize) ) - err = errAECoercionFail; - } - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return err; -} - -static pascal OSErr -my_dispose_handler(WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - OSErr err; - - args=Py_BuildValue("(O&)", WEOObj_New, objref); - err = any_handler(weDisposeHandler, objref, args, &rv); - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return err; -} - -static pascal OSErr -my_draw_handler(const Rect *destRect, WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - OSErr err; - - args=Py_BuildValue("O&O&", PyMac_BuildRect, destRect, WEOObj_New, objref); - err = any_handler(weDrawHandler, objref, args, &rv); - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return err; -} - -static pascal Boolean -my_click_handler(Point hitPt, EventModifiers modifiers, - unsigned long clickTime, WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - int retvalue; - OSErr err; - - args=Py_BuildValue("O&llO&", PyMac_BuildPoint, hitPt, - (long)modifiers, (long)clickTime, WEOObj_New, objref); - err = any_handler(weClickHandler, objref, args, &rv); - if (!err) - retvalue = PyInt_AsLong(rv); - else - retvalue = 0; - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return retvalue; -} - - - -static PyObject *waste_Error; - -/* ------------------------ Object type WEO ------------------------- */ - -PyTypeObject WEO_Type; - -#define WEOObj_Check(x) ((x)->ob_type == &WEO_Type || PyObject_TypeCheck((x), &WEO_Type)) - -typedef struct WEOObject { - PyObject_HEAD - WEObjectReference ob_itself; -} WEOObject; - -PyObject *WEOObj_New(WEObjectReference itself) -{ - WEOObject *it; - if (itself == NULL) { - Py_INCREF(Py_None); - return Py_None; - } - it = PyObject_NEW(WEOObject, &WEO_Type); - if (it == NULL) return NULL; - it->ob_itself = itself; - return (PyObject *)it; -} - -int WEOObj_Convert(PyObject *v, WEObjectReference *p_itself) -{ - if (!WEOObj_Check(v)) - { - PyErr_SetString(PyExc_TypeError, "WEO required"); - return 0; - } - *p_itself = ((WEOObject *)v)->ob_itself; - return 1; -} - -static void WEOObj_dealloc(WEOObject *self) -{ - /* Cleanup of self->ob_itself goes here */ - self->ob_type->tp_free((PyObject *)self); -} - -static PyObject *WEOObj_WEGetObjectType(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - FlavorType _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetObjectType(_self->ob_itself); - _res = Py_BuildValue("O&", - PyMac_BuildOSType, _rv); - return _res; -} - -static PyObject *WEOObj_WEGetObjectDataHandle(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Handle _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetObjectDataHandle(_self->ob_itself); - _res = Py_BuildValue("O&", - ResObj_New, _rv); - return _res; -} - -static PyObject *WEOObj_WEGetObjectOwner(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEReference _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetObjectOwner(_self->ob_itself); - _res = Py_BuildValue("O&", - ExistingwasteObj_New, _rv); - return _res; -} - -static PyObject *WEOObj_WEGetObjectOffset(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetObjectOffset(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *WEOObj_WEGetObjectSize(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Point _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetObjectSize(_self->ob_itself); - _res = Py_BuildValue("O&", - PyMac_BuildPoint, _rv); - return _res; -} - -static PyObject *WEOObj_WESetObjectSize(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - Point inObjectSize; - if (!PyArg_ParseTuple(_args, "O&", - PyMac_GetPoint, &inObjectSize)) - return NULL; - _err = WESetObjectSize(_self->ob_itself, - inObjectSize); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *WEOObj_WEGetObjectFrame(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - LongRect outObjectFrame; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEGetObjectFrame(_self->ob_itself, - &outObjectFrame); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - LongRect_New, &outObjectFrame); - return _res; -} - -static PyObject *WEOObj_WEGetObjectRefCon(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetObjectRefCon(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *WEOObj_WESetObjectRefCon(WEOObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inRefCon; - if (!PyArg_ParseTuple(_args, "l", - &inRefCon)) - return NULL; - WESetObjectRefCon(_self->ob_itself, - inRefCon); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyMethodDef WEOObj_methods[] = { - {"WEGetObjectType", (PyCFunction)WEOObj_WEGetObjectType, 1, - PyDoc_STR("() -> (FlavorType _rv)")}, - {"WEGetObjectDataHandle", (PyCFunction)WEOObj_WEGetObjectDataHandle, 1, - PyDoc_STR("() -> (Handle _rv)")}, - {"WEGetObjectOwner", (PyCFunction)WEOObj_WEGetObjectOwner, 1, - PyDoc_STR("() -> (WEReference _rv)")}, - {"WEGetObjectOffset", (PyCFunction)WEOObj_WEGetObjectOffset, 1, - PyDoc_STR("() -> (SInt32 _rv)")}, - {"WEGetObjectSize", (PyCFunction)WEOObj_WEGetObjectSize, 1, - PyDoc_STR("() -> (Point _rv)")}, - {"WESetObjectSize", (PyCFunction)WEOObj_WESetObjectSize, 1, - PyDoc_STR("(Point inObjectSize) -> None")}, - {"WEGetObjectFrame", (PyCFunction)WEOObj_WEGetObjectFrame, 1, - PyDoc_STR("() -> (LongRect outObjectFrame)")}, - {"WEGetObjectRefCon", (PyCFunction)WEOObj_WEGetObjectRefCon, 1, - PyDoc_STR("() -> (SInt32 _rv)")}, - {"WESetObjectRefCon", (PyCFunction)WEOObj_WESetObjectRefCon, 1, - PyDoc_STR("(SInt32 inRefCon) -> None")}, - {NULL, NULL, 0} -}; - -#define WEOObj_getsetlist NULL - - -#define WEOObj_compare NULL - -#define WEOObj_repr NULL - -#define WEOObj_hash NULL -#define WEOObj_tp_init 0 - -#define WEOObj_tp_alloc PyType_GenericAlloc - -static PyObject *WEOObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) -{ - PyObject *_self; - WEObjectReference itself; - char *kw[] = {"itself", 0}; - - if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, WEOObj_Convert, &itself)) return NULL; - if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; - ((WEOObject *)_self)->ob_itself = itself; - return _self; -} - -#define WEOObj_tp_free PyObject_Del - - -PyTypeObject WEO_Type = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "waste.WEO", /*tp_name*/ - sizeof(WEOObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor) WEOObj_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc) WEOObj_compare, /*tp_compare*/ - (reprfunc) WEOObj_repr, /*tp_repr*/ - (PyNumberMethods *)0, /* tp_as_number */ - (PySequenceMethods *)0, /* tp_as_sequence */ - (PyMappingMethods *)0, /* tp_as_mapping */ - (hashfunc) WEOObj_hash, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ - PyObject_GenericSetAttr, /*tp_setattro */ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - WEOObj_methods, /* tp_methods */ - 0, /*tp_members*/ - WEOObj_getsetlist, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - WEOObj_tp_init, /* tp_init */ - WEOObj_tp_alloc, /* tp_alloc */ - WEOObj_tp_new, /* tp_new */ - WEOObj_tp_free, /* tp_free */ -}; - -/* ---------------------- End object type WEO ----------------------- */ - - -/* ----------------------- Object type waste ------------------------ */ - -PyTypeObject waste_Type; - -#define wasteObj_Check(x) ((x)->ob_type == &waste_Type || PyObject_TypeCheck((x), &waste_Type)) - -typedef struct wasteObject { - PyObject_HEAD - WEReference ob_itself; -} wasteObject; - -PyObject *wasteObj_New(WEReference itself) -{ - wasteObject *it; - if (itself == NULL) { - PyErr_SetString(waste_Error,"Cannot create null WE"); - return NULL; - } - it = PyObject_NEW(wasteObject, &waste_Type); - if (it == NULL) return NULL; - it->ob_itself = itself; - WESetInfo(weRefCon, (void *)&it, itself); - return (PyObject *)it; -} - -int wasteObj_Convert(PyObject *v, WEReference *p_itself) -{ - if (!wasteObj_Check(v)) - { - PyErr_SetString(PyExc_TypeError, "waste required"); - return 0; - } - *p_itself = ((wasteObject *)v)->ob_itself; - return 1; -} - -static void wasteObj_dealloc(wasteObject *self) -{ - WEDispose(self->ob_itself); - self->ob_type->tp_free((PyObject *)self); -} - -static PyObject *wasteObj_WEGetText(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Handle _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetText(_self->ob_itself); - _res = Py_BuildValue("O&", - ResObj_New, _rv); - return _res; -} - -static PyObject *wasteObj_WEGetChar(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt16 _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WEGetChar(inOffset, - _self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetTextLength(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetTextLength(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetSelection(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 outSelStart; - SInt32 outSelEnd; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEGetSelection(&outSelStart, - &outSelEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outSelStart, - outSelEnd); - return _res; -} - -static PyObject *wasteObj_WEGetDestRect(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect outDestRect; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEGetDestRect(&outDestRect, - _self->ob_itself); - _res = Py_BuildValue("O&", - LongRect_New, &outDestRect); - return _res; -} - -static PyObject *wasteObj_WEGetViewRect(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect outViewRect; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEGetViewRect(&outViewRect, - _self->ob_itself); - _res = Py_BuildValue("O&", - LongRect_New, &outViewRect); - return _res; -} - -static PyObject *wasteObj_WEIsActive(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEIsActive(_self->ob_itself); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetClickCount(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - UInt16 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetClickCount(_self->ob_itself); - _res = Py_BuildValue("H", - _rv); - return _res; -} - -static PyObject *wasteObj_WESetSelection(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inSelStart; - SInt32 inSelEnd; - if (!PyArg_ParseTuple(_args, "ll", - &inSelStart, - &inSelEnd)) - return NULL; - WESetSelection(inSelStart, - inSelEnd, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WESetDestRect(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect inDestRect; - if (!PyArg_ParseTuple(_args, "O&", - LongRect_Convert, &inDestRect)) - return NULL; - WESetDestRect(&inDestRect, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WESetViewRect(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect inViewRect; - if (!PyArg_ParseTuple(_args, "O&", - LongRect_Convert, &inViewRect)) - return NULL; - WESetViewRect(&inViewRect, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEContinuousStyle(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - WEStyleMode ioMode; - TextStyle outTextStyle; - if (!PyArg_ParseTuple(_args, "H", - &ioMode)) - return NULL; - _rv = WEContinuousStyle(&ioMode, - &outTextStyle, - _self->ob_itself); - _res = Py_BuildValue("bHO&", - _rv, - ioMode, - TextStyle_New, &outTextStyle); - return _res; -} - -static PyObject *wasteObj_WECountRuns(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WECountRuns(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEOffsetToRun(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WEOffsetToRun(inOffset, - _self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetRunRange(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inStyleRunIndex; - SInt32 outStyleRunStart; - SInt32 outStyleRunEnd; - if (!PyArg_ParseTuple(_args, "l", - &inStyleRunIndex)) - return NULL; - WEGetRunRange(inStyleRunIndex, - &outStyleRunStart, - &outStyleRunEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outStyleRunStart, - outStyleRunEnd); - return _res; -} - -static PyObject *wasteObj_WEGetRunInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inOffset; - WERunInfo outStyleRunInfo; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - WEGetRunInfo(inOffset, - &outStyleRunInfo, - _self->ob_itself); - _res = Py_BuildValue("O&", - RunInfo_New, &outStyleRunInfo); - return _res; -} - -static PyObject *wasteObj_WEGetIndRunInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inStyleRunIndex; - WERunInfo outStyleRunInfo; - if (!PyArg_ParseTuple(_args, "l", - &inStyleRunIndex)) - return NULL; - WEGetIndRunInfo(inStyleRunIndex, - &outStyleRunInfo, - _self->ob_itself); - _res = Py_BuildValue("O&", - RunInfo_New, &outStyleRunInfo); - return _res; -} - -static PyObject *wasteObj_WEGetRunDirection(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WEGetRunDirection(inOffset, - _self->ob_itself); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *wasteObj_WECountParaRuns(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WECountParaRuns(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEOffsetToParaRun(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WEOffsetToParaRun(inOffset, - _self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetParaRunRange(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inParagraphRunIndex; - SInt32 outParagraphRunStart; - SInt32 outParagraphRunEnd; - if (!PyArg_ParseTuple(_args, "l", - &inParagraphRunIndex)) - return NULL; - WEGetParaRunRange(inParagraphRunIndex, - &outParagraphRunStart, - &outParagraphRunEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outParagraphRunStart, - outParagraphRunEnd); - return _res; -} - -static PyObject *wasteObj_WECountLines(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WECountLines(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEOffsetToLine(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WEOffsetToLine(inOffset, - _self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetLineRange(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inLineIndex; - SInt32 outLineStart; - SInt32 outLineEnd; - if (!PyArg_ParseTuple(_args, "l", - &inLineIndex)) - return NULL; - WEGetLineRange(inLineIndex, - &outLineStart, - &outLineEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outLineStart, - outLineEnd); - return _res; -} - -static PyObject *wasteObj_WEGetHeight(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - SInt32 inStartLineIndex; - SInt32 inEndLineIndex; - if (!PyArg_ParseTuple(_args, "ll", - &inStartLineIndex, - &inEndLineIndex)) - return NULL; - _rv = WEGetHeight(inStartLineIndex, - inEndLineIndex, - _self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetOffset(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - LongPt inPoint; - WEEdge outEdge; - if (!PyArg_ParseTuple(_args, "O&", - LongPt_Convert, &inPoint)) - return NULL; - _rv = WEGetOffset(&inPoint, - &outEdge, - _self->ob_itself); - _res = Py_BuildValue("lB", - _rv, - outEdge); - return _res; -} - -static PyObject *wasteObj_WEGetPoint(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inOffset; - SInt16 inDirection; - LongPt outPoint; - SInt16 outLineHeight; - if (!PyArg_ParseTuple(_args, "lh", - &inOffset, - &inDirection)) - return NULL; - WEGetPoint(inOffset, - inDirection, - &outPoint, - &outLineHeight, - _self->ob_itself); - _res = Py_BuildValue("O&h", - LongPt_New, &outPoint, - outLineHeight); - return _res; -} - -static PyObject *wasteObj_WEFindWord(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inOffset; - WEEdge inEdge; - SInt32 outWordStart; - SInt32 outWordEnd; - if (!PyArg_ParseTuple(_args, "lB", - &inOffset, - &inEdge)) - return NULL; - WEFindWord(inOffset, - inEdge, - &outWordStart, - &outWordEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outWordStart, - outWordEnd); - return _res; -} - -static PyObject *wasteObj_WEFindLine(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inOffset; - WEEdge inEdge; - SInt32 outLineStart; - SInt32 outLineEnd; - if (!PyArg_ParseTuple(_args, "lB", - &inOffset, - &inEdge)) - return NULL; - WEFindLine(inOffset, - inEdge, - &outLineStart, - &outLineEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outLineStart, - outLineEnd); - return _res; -} - -static PyObject *wasteObj_WEFindParagraph(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inOffset; - WEEdge inEdge; - SInt32 outParagraphStart; - SInt32 outParagraphEnd; - if (!PyArg_ParseTuple(_args, "lB", - &inOffset, - &inEdge)) - return NULL; - WEFindParagraph(inOffset, - inEdge, - &outParagraphStart, - &outParagraphEnd, - _self->ob_itself); - _res = Py_BuildValue("ll", - outParagraphStart, - outParagraphEnd); - return _res; -} - -static PyObject *wasteObj_WEFind(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - char* inKey; - SInt32 inKeyLength; - TextEncoding inKeyEncoding; - OptionBits inMatchOptions; - SInt32 inRangeStart; - SInt32 inRangeEnd; - SInt32 outMatchStart; - SInt32 outMatchEnd; - if (!PyArg_ParseTuple(_args, "slllll", - &inKey, - &inKeyLength, - &inKeyEncoding, - &inMatchOptions, - &inRangeStart, - &inRangeEnd)) - return NULL; - _err = WEFind(inKey, - inKeyLength, - inKeyEncoding, - inMatchOptions, - inRangeStart, - inRangeEnd, - &outMatchStart, - &outMatchEnd, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("ll", - outMatchStart, - outMatchEnd); - return _res; -} - -static PyObject *wasteObj_WEStreamRange(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt32 inRangeStart; - SInt32 inRangeEnd; - FlavorType inRequestedType; - OptionBits inStreamOptions; - Handle outData; - if (!PyArg_ParseTuple(_args, "llO&lO&", - &inRangeStart, - &inRangeEnd, - PyMac_GetOSType, &inRequestedType, - &inStreamOptions, - ResObj_Convert, &outData)) - return NULL; - _err = WEStreamRange(inRangeStart, - inRangeEnd, - inRequestedType, - inStreamOptions, - outData, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WECopyRange(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt32 inRangeStart; - SInt32 inRangeEnd; - Handle outText; - StScrpHandle outStyles; - WESoupHandle outSoup; - if (!PyArg_ParseTuple(_args, "llO&O&O&", - &inRangeStart, - &inRangeEnd, - OptResObj_Convert, &outText, - OptResObj_Convert, &outStyles, - OptResObj_Convert, &outSoup)) - return NULL; - _err = WECopyRange(inRangeStart, - inRangeEnd, - outText, - outStyles, - outSoup, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEGetTextRangeAsUnicode(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt32 inRangeStart; - SInt32 inRangeEnd; - Handle outUnicodeText; - Handle ioCharFormat; - Handle ioParaFormat; - TextEncodingVariant inUnicodeVariant; - TextEncodingFormat inTransformationFormat; - OptionBits inGetOptions; - if (!PyArg_ParseTuple(_args, "llO&O&O&lll", - &inRangeStart, - &inRangeEnd, - ResObj_Convert, &outUnicodeText, - ResObj_Convert, &ioCharFormat, - ResObj_Convert, &ioParaFormat, - &inUnicodeVariant, - &inTransformationFormat, - &inGetOptions)) - return NULL; - _err = WEGetTextRangeAsUnicode(inRangeStart, - inRangeEnd, - outUnicodeText, - ioCharFormat, - ioParaFormat, - inUnicodeVariant, - inTransformationFormat, - inGetOptions, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEGetAlignment(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEAlignment _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetAlignment(_self->ob_itself); - _res = Py_BuildValue("B", - _rv); - return _res; -} - -static PyObject *wasteObj_WESetAlignment(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEAlignment inAlignment; - if (!PyArg_ParseTuple(_args, "B", - &inAlignment)) - return NULL; - WESetAlignment(inAlignment, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEGetDirection(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEDirection _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetDirection(_self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WESetDirection(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEDirection inDirection; - if (!PyArg_ParseTuple(_args, "h", - &inDirection)) - return NULL; - WESetDirection(inDirection, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WECalText(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WECalText(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEUpdate(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - RgnHandle inUpdateRgn; - if (!PyArg_ParseTuple(_args, "O&", - ResObj_Convert, &inUpdateRgn)) - return NULL; - WEUpdate(inUpdateRgn, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEScroll(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inHorizontalOffset; - SInt32 inVerticalOffset; - if (!PyArg_ParseTuple(_args, "ll", - &inHorizontalOffset, - &inVerticalOffset)) - return NULL; - WEScroll(inHorizontalOffset, - inVerticalOffset, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEPinScroll(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 inHorizontalOffset; - SInt32 inVerticalOffset; - if (!PyArg_ParseTuple(_args, "ll", - &inHorizontalOffset, - &inVerticalOffset)) - return NULL; - WEPinScroll(inHorizontalOffset, - inVerticalOffset, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WESelView(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WESelView(_self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEActivate(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEActivate(_self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEDeactivate(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEDeactivate(_self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEKey(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - CharParameter inKey; - EventModifiers inModifiers; - if (!PyArg_ParseTuple(_args, "hH", - &inKey, - &inModifiers)) - return NULL; - WEKey(inKey, - inModifiers, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEClick(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Point inHitPoint; - EventModifiers inModifiers; - UInt32 inClickTime; - if (!PyArg_ParseTuple(_args, "O&Hl", - PyMac_GetPoint, &inHitPoint, - &inModifiers, - &inClickTime)) - return NULL; - WEClick(inHitPoint, - inModifiers, - inClickTime, - _self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEAdjustCursor(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - Point inMouseLoc; - RgnHandle ioMouseRgn; - if (!PyArg_ParseTuple(_args, "O&O&", - PyMac_GetPoint, &inMouseLoc, - ResObj_Convert, &ioMouseRgn)) - return NULL; - _rv = WEAdjustCursor(inMouseLoc, - ioMouseRgn, - _self->ob_itself); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *wasteObj_WEIdle(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - UInt32 outMaxSleep; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEIdle(&outMaxSleep, - _self->ob_itself); - _res = Py_BuildValue("l", - outMaxSleep); - return _res; -} - -static PyObject *wasteObj_WEInsert(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - char *inTextPtr__in__; - long inTextPtr__len__; - int inTextPtr__in_len__; - StScrpHandle inStyles; - WESoupHandle inSoup; - if (!PyArg_ParseTuple(_args, "s#O&O&", - &inTextPtr__in__, &inTextPtr__in_len__, - OptResObj_Convert, &inStyles, - OptResObj_Convert, &inSoup)) - return NULL; - inTextPtr__len__ = inTextPtr__in_len__; - _err = WEInsert(inTextPtr__in__, inTextPtr__len__, - inStyles, - inSoup, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEInsertFormattedText(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - char *inTextPtr__in__; - long inTextPtr__len__; - int inTextPtr__in_len__; - StScrpHandle inStyles; - WESoupHandle inSoup; - Handle inParaFormat; - Handle inRulerScrap; - if (!PyArg_ParseTuple(_args, "s#O&O&O&O&", - &inTextPtr__in__, &inTextPtr__in_len__, - OptResObj_Convert, &inStyles, - OptResObj_Convert, &inSoup, - ResObj_Convert, &inParaFormat, - ResObj_Convert, &inRulerScrap)) - return NULL; - inTextPtr__len__ = inTextPtr__in_len__; - _err = WEInsertFormattedText(inTextPtr__in__, inTextPtr__len__, - inStyles, - inSoup, - inParaFormat, - inRulerScrap, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEDelete(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEDelete(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEUseText(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - Handle inText; - if (!PyArg_ParseTuple(_args, "O&", - ResObj_Convert, &inText)) - return NULL; - _err = WEUseText(inText, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEChangeCase(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt16 inCase; - if (!PyArg_ParseTuple(_args, "h", - &inCase)) - return NULL; - _err = WEChangeCase(inCase, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WESetOneAttribute(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt32 inRangeStart; - SInt32 inRangeEnd; - WESelector inAttributeSelector; - char *inAttributeValue__in__; - long inAttributeValue__len__; - int inAttributeValue__in_len__; - if (!PyArg_ParseTuple(_args, "llO&s#", - &inRangeStart, - &inRangeEnd, - PyMac_GetOSType, &inAttributeSelector, - &inAttributeValue__in__, &inAttributeValue__in_len__)) - return NULL; - inAttributeValue__len__ = inAttributeValue__in_len__; - _err = WESetOneAttribute(inRangeStart, - inRangeEnd, - inAttributeSelector, - inAttributeValue__in__, inAttributeValue__len__, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WESetStyle(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WEStyleMode inMode; - TextStyle inTextStyle; - if (!PyArg_ParseTuple(_args, "HO&", - &inMode, - TextStyle_Convert, &inTextStyle)) - return NULL; - _err = WESetStyle(inMode, - &inTextStyle, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEUseStyleScrap(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - StScrpHandle inStyles; - if (!PyArg_ParseTuple(_args, "O&", - ResObj_Convert, &inStyles)) - return NULL; - _err = WEUseStyleScrap(inStyles, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEUndo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEUndo(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WERedo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WERedo(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEClearUndo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEClearUndo(_self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEGetUndoInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEActionKind _rv; - Boolean outRedoFlag; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetUndoInfo(&outRedoFlag, - _self->ob_itself); - _res = Py_BuildValue("hb", - _rv, - outRedoFlag); - return _res; -} - -static PyObject *wasteObj_WEGetIndUndoInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - WEActionKind _rv; - SInt32 inUndoLevel; - if (!PyArg_ParseTuple(_args, "l", - &inUndoLevel)) - return NULL; - _rv = WEGetIndUndoInfo(inUndoLevel, - _self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WEIsTyping(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEIsTyping(_self->ob_itself); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *wasteObj_WEBeginAction(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEBeginAction(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEEndAction(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WEActionKind inActionKind; - if (!PyArg_ParseTuple(_args, "h", - &inActionKind)) - return NULL; - _err = WEEndAction(inActionKind, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEGetModCount(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - UInt32 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetModCount(_self->ob_itself); - _res = Py_BuildValue("l", - _rv); - return _res; -} - -static PyObject *wasteObj_WEResetModCount(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEResetModCount(_self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEInsertObject(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - FlavorType inObjectType; - Handle inObjectDataHandle; - Point inObjectSize; - if (!PyArg_ParseTuple(_args, "O&O&O&", - PyMac_GetOSType, &inObjectType, - ResObj_Convert, &inObjectDataHandle, - PyMac_GetPoint, &inObjectSize)) - return NULL; - _err = WEInsertObject(inObjectType, - inObjectDataHandle, - inObjectSize, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEGetSelectedObject(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WEObjectReference outObject; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEGetSelectedObject(&outObject, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - WEOObj_New, outObject); - return _res; -} - -static PyObject *wasteObj_WEGetObjectAtOffset(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt32 inOffset; - WEObjectReference outObject; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _err = WEGetObjectAtOffset(inOffset, - &outObject, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - WEOObj_New, outObject); - return _res; -} - -static PyObject *wasteObj_WEFindNextObject(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt32 _rv; - SInt32 inOffset; - WEObjectReference outObject; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WEFindNextObject(inOffset, - &outObject, - _self->ob_itself); - _res = Py_BuildValue("lO&", - _rv, - WEOObj_New, outObject); - return _res; -} - -static PyObject *wasteObj_WEUseSoup(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WESoupHandle inSoup; - if (!PyArg_ParseTuple(_args, "O&", - ResObj_Convert, &inSoup)) - return NULL; - _err = WEUseSoup(inSoup, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WECut(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WECut(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WECopy(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WECopy(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEPaste(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEPaste(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WECanPaste(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WECanPaste(_self->ob_itself); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetHiliteRgn(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - RgnHandle _rv; - SInt32 inRangeStart; - SInt32 inRangeEnd; - if (!PyArg_ParseTuple(_args, "ll", - &inRangeStart, - &inRangeEnd)) - return NULL; - _rv = WEGetHiliteRgn(inRangeStart, - inRangeEnd, - _self->ob_itself); - _res = Py_BuildValue("O&", - ResObj_New, _rv); - return _res; -} - -static PyObject *wasteObj_WECharByte(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt16 _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WECharByte(inOffset, - _self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WECharType(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt16 _rv; - SInt32 inOffset; - if (!PyArg_ParseTuple(_args, "l", - &inOffset)) - return NULL; - _rv = WECharType(inOffset, - _self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WEStopInlineSession(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - WEStopInlineSession(_self->ob_itself); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEFeatureFlag(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt16 _rv; - SInt16 inFeature; - SInt16 inAction; - if (!PyArg_ParseTuple(_args, "hh", - &inFeature, - &inAction)) - return NULL; - _rv = WEFeatureFlag(inFeature, - inAction, - _self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetUserInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WESelector inUserTag; - SInt32 outUserInfo; - if (!PyArg_ParseTuple(_args, "O&", - PyMac_GetOSType, &inUserTag)) - return NULL; - _err = WEGetUserInfo(inUserTag, - &outUserInfo, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("l", - outUserInfo); - return _res; -} - -static PyObject *wasteObj_WESetUserInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WESelector inUserTag; - SInt32 inUserInfo; - if (!PyArg_ParseTuple(_args, "O&l", - PyMac_GetOSType, &inUserTag, - &inUserInfo)) - return NULL; - _err = WESetUserInfo(inUserTag, - inUserInfo, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WERemoveUserInfo(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - WESelector inUserTag; - if (!PyArg_ParseTuple(_args, "O&", - PyMac_GetOSType, &inUserTag)) - return NULL; - _err = WERemoveUserInfo(inUserTag, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEInstallTabHooks(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEInstallTabHooks(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WERemoveTabHooks(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WERemoveTabHooks(_self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *wasteObj_WEIsTabHooks(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEIsTabHooks(_self->ob_itself); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *wasteObj_WEGetTabSize(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - SInt16 _rv; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _rv = WEGetTabSize(_self->ob_itself); - _res = Py_BuildValue("h", - _rv); - return _res; -} - -static PyObject *wasteObj_WESetTabSize(wasteObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - SInt16 tabWidth; - if (!PyArg_ParseTuple(_args, "h", - &tabWidth)) - return NULL; - _err = WESetTabSize(tabWidth, - _self->ob_itself); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyMethodDef wasteObj_methods[] = { - {"WEGetText", (PyCFunction)wasteObj_WEGetText, 1, - PyDoc_STR("() -> (Handle _rv)")}, - {"WEGetChar", (PyCFunction)wasteObj_WEGetChar, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt16 _rv)")}, - {"WEGetTextLength", (PyCFunction)wasteObj_WEGetTextLength, 1, - PyDoc_STR("() -> (SInt32 _rv)")}, - {"WEGetSelection", (PyCFunction)wasteObj_WEGetSelection, 1, - PyDoc_STR("() -> (SInt32 outSelStart, SInt32 outSelEnd)")}, - {"WEGetDestRect", (PyCFunction)wasteObj_WEGetDestRect, 1, - PyDoc_STR("() -> (LongRect outDestRect)")}, - {"WEGetViewRect", (PyCFunction)wasteObj_WEGetViewRect, 1, - PyDoc_STR("() -> (LongRect outViewRect)")}, - {"WEIsActive", (PyCFunction)wasteObj_WEIsActive, 1, - PyDoc_STR("() -> (Boolean _rv)")}, - {"WEGetClickCount", (PyCFunction)wasteObj_WEGetClickCount, 1, - PyDoc_STR("() -> (UInt16 _rv)")}, - {"WESetSelection", (PyCFunction)wasteObj_WESetSelection, 1, - PyDoc_STR("(SInt32 inSelStart, SInt32 inSelEnd) -> None")}, - {"WESetDestRect", (PyCFunction)wasteObj_WESetDestRect, 1, - PyDoc_STR("(LongRect inDestRect) -> None")}, - {"WESetViewRect", (PyCFunction)wasteObj_WESetViewRect, 1, - PyDoc_STR("(LongRect inViewRect) -> None")}, - {"WEContinuousStyle", (PyCFunction)wasteObj_WEContinuousStyle, 1, - PyDoc_STR("(WEStyleMode ioMode) -> (Boolean _rv, WEStyleMode ioMode, TextStyle outTextStyle)")}, - {"WECountRuns", (PyCFunction)wasteObj_WECountRuns, 1, - PyDoc_STR("() -> (SInt32 _rv)")}, - {"WEOffsetToRun", (PyCFunction)wasteObj_WEOffsetToRun, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt32 _rv)")}, - {"WEGetRunRange", (PyCFunction)wasteObj_WEGetRunRange, 1, - PyDoc_STR("(SInt32 inStyleRunIndex) -> (SInt32 outStyleRunStart, SInt32 outStyleRunEnd)")}, - {"WEGetRunInfo", (PyCFunction)wasteObj_WEGetRunInfo, 1, - PyDoc_STR("(SInt32 inOffset) -> (WERunInfo outStyleRunInfo)")}, - {"WEGetIndRunInfo", (PyCFunction)wasteObj_WEGetIndRunInfo, 1, - PyDoc_STR("(SInt32 inStyleRunIndex) -> (WERunInfo outStyleRunInfo)")}, - {"WEGetRunDirection", (PyCFunction)wasteObj_WEGetRunDirection, 1, - PyDoc_STR("(SInt32 inOffset) -> (Boolean _rv)")}, - {"WECountParaRuns", (PyCFunction)wasteObj_WECountParaRuns, 1, - PyDoc_STR("() -> (SInt32 _rv)")}, - {"WEOffsetToParaRun", (PyCFunction)wasteObj_WEOffsetToParaRun, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt32 _rv)")}, - {"WEGetParaRunRange", (PyCFunction)wasteObj_WEGetParaRunRange, 1, - PyDoc_STR("(SInt32 inParagraphRunIndex) -> (SInt32 outParagraphRunStart, SInt32 outParagraphRunEnd)")}, - {"WECountLines", (PyCFunction)wasteObj_WECountLines, 1, - PyDoc_STR("() -> (SInt32 _rv)")}, - {"WEOffsetToLine", (PyCFunction)wasteObj_WEOffsetToLine, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt32 _rv)")}, - {"WEGetLineRange", (PyCFunction)wasteObj_WEGetLineRange, 1, - PyDoc_STR("(SInt32 inLineIndex) -> (SInt32 outLineStart, SInt32 outLineEnd)")}, - {"WEGetHeight", (PyCFunction)wasteObj_WEGetHeight, 1, - PyDoc_STR("(SInt32 inStartLineIndex, SInt32 inEndLineIndex) -> (SInt32 _rv)")}, - {"WEGetOffset", (PyCFunction)wasteObj_WEGetOffset, 1, - PyDoc_STR("(LongPt inPoint) -> (SInt32 _rv, WEEdge outEdge)")}, - {"WEGetPoint", (PyCFunction)wasteObj_WEGetPoint, 1, - PyDoc_STR("(SInt32 inOffset, SInt16 inDirection) -> (LongPt outPoint, SInt16 outLineHeight)")}, - {"WEFindWord", (PyCFunction)wasteObj_WEFindWord, 1, - PyDoc_STR("(SInt32 inOffset, WEEdge inEdge) -> (SInt32 outWordStart, SInt32 outWordEnd)")}, - {"WEFindLine", (PyCFunction)wasteObj_WEFindLine, 1, - PyDoc_STR("(SInt32 inOffset, WEEdge inEdge) -> (SInt32 outLineStart, SInt32 outLineEnd)")}, - {"WEFindParagraph", (PyCFunction)wasteObj_WEFindParagraph, 1, - PyDoc_STR("(SInt32 inOffset, WEEdge inEdge) -> (SInt32 outParagraphStart, SInt32 outParagraphEnd)")}, - {"WEFind", (PyCFunction)wasteObj_WEFind, 1, - PyDoc_STR("(char* inKey, SInt32 inKeyLength, TextEncoding inKeyEncoding, OptionBits inMatchOptions, SInt32 inRangeStart, SInt32 inRangeEnd) -> (SInt32 outMatchStart, SInt32 outMatchEnd)")}, - {"WEStreamRange", (PyCFunction)wasteObj_WEStreamRange, 1, - PyDoc_STR("(SInt32 inRangeStart, SInt32 inRangeEnd, FlavorType inRequestedType, OptionBits inStreamOptions, Handle outData) -> None")}, - {"WECopyRange", (PyCFunction)wasteObj_WECopyRange, 1, - PyDoc_STR("(SInt32 inRangeStart, SInt32 inRangeEnd, Handle outText, StScrpHandle outStyles, WESoupHandle outSoup) -> None")}, - {"WEGetTextRangeAsUnicode", (PyCFunction)wasteObj_WEGetTextRangeAsUnicode, 1, - PyDoc_STR("(SInt32 inRangeStart, SInt32 inRangeEnd, Handle outUnicodeText, Handle ioCharFormat, Handle ioParaFormat, TextEncodingVariant inUnicodeVariant, TextEncodingFormat inTransformationFormat, OptionBits inGetOptions) -> None")}, - {"WEGetAlignment", (PyCFunction)wasteObj_WEGetAlignment, 1, - PyDoc_STR("() -> (WEAlignment _rv)")}, - {"WESetAlignment", (PyCFunction)wasteObj_WESetAlignment, 1, - PyDoc_STR("(WEAlignment inAlignment) -> None")}, - {"WEGetDirection", (PyCFunction)wasteObj_WEGetDirection, 1, - PyDoc_STR("() -> (WEDirection _rv)")}, - {"WESetDirection", (PyCFunction)wasteObj_WESetDirection, 1, - PyDoc_STR("(WEDirection inDirection) -> None")}, - {"WECalText", (PyCFunction)wasteObj_WECalText, 1, - PyDoc_STR("() -> None")}, - {"WEUpdate", (PyCFunction)wasteObj_WEUpdate, 1, - PyDoc_STR("(RgnHandle inUpdateRgn) -> None")}, - {"WEScroll", (PyCFunction)wasteObj_WEScroll, 1, - PyDoc_STR("(SInt32 inHorizontalOffset, SInt32 inVerticalOffset) -> None")}, - {"WEPinScroll", (PyCFunction)wasteObj_WEPinScroll, 1, - PyDoc_STR("(SInt32 inHorizontalOffset, SInt32 inVerticalOffset) -> None")}, - {"WESelView", (PyCFunction)wasteObj_WESelView, 1, - PyDoc_STR("() -> None")}, - {"WEActivate", (PyCFunction)wasteObj_WEActivate, 1, - PyDoc_STR("() -> None")}, - {"WEDeactivate", (PyCFunction)wasteObj_WEDeactivate, 1, - PyDoc_STR("() -> None")}, - {"WEKey", (PyCFunction)wasteObj_WEKey, 1, - PyDoc_STR("(CharParameter inKey, EventModifiers inModifiers) -> None")}, - {"WEClick", (PyCFunction)wasteObj_WEClick, 1, - PyDoc_STR("(Point inHitPoint, EventModifiers inModifiers, UInt32 inClickTime) -> None")}, - {"WEAdjustCursor", (PyCFunction)wasteObj_WEAdjustCursor, 1, - PyDoc_STR("(Point inMouseLoc, RgnHandle ioMouseRgn) -> (Boolean _rv)")}, - {"WEIdle", (PyCFunction)wasteObj_WEIdle, 1, - PyDoc_STR("() -> (UInt32 outMaxSleep)")}, - {"WEInsert", (PyCFunction)wasteObj_WEInsert, 1, - PyDoc_STR("(Buffer inTextPtr, StScrpHandle inStyles, WESoupHandle inSoup) -> None")}, - {"WEInsertFormattedText", (PyCFunction)wasteObj_WEInsertFormattedText, 1, - PyDoc_STR("(Buffer inTextPtr, StScrpHandle inStyles, WESoupHandle inSoup, Handle inParaFormat, Handle inRulerScrap) -> None")}, - {"WEDelete", (PyCFunction)wasteObj_WEDelete, 1, - PyDoc_STR("() -> None")}, - {"WEUseText", (PyCFunction)wasteObj_WEUseText, 1, - PyDoc_STR("(Handle inText) -> None")}, - {"WEChangeCase", (PyCFunction)wasteObj_WEChangeCase, 1, - PyDoc_STR("(SInt16 inCase) -> None")}, - {"WESetOneAttribute", (PyCFunction)wasteObj_WESetOneAttribute, 1, - PyDoc_STR("(SInt32 inRangeStart, SInt32 inRangeEnd, WESelector inAttributeSelector, Buffer inAttributeValue) -> None")}, - {"WESetStyle", (PyCFunction)wasteObj_WESetStyle, 1, - PyDoc_STR("(WEStyleMode inMode, TextStyle inTextStyle) -> None")}, - {"WEUseStyleScrap", (PyCFunction)wasteObj_WEUseStyleScrap, 1, - PyDoc_STR("(StScrpHandle inStyles) -> None")}, - {"WEUndo", (PyCFunction)wasteObj_WEUndo, 1, - PyDoc_STR("() -> None")}, - {"WERedo", (PyCFunction)wasteObj_WERedo, 1, - PyDoc_STR("() -> None")}, - {"WEClearUndo", (PyCFunction)wasteObj_WEClearUndo, 1, - PyDoc_STR("() -> None")}, - {"WEGetUndoInfo", (PyCFunction)wasteObj_WEGetUndoInfo, 1, - PyDoc_STR("() -> (WEActionKind _rv, Boolean outRedoFlag)")}, - {"WEGetIndUndoInfo", (PyCFunction)wasteObj_WEGetIndUndoInfo, 1, - PyDoc_STR("(SInt32 inUndoLevel) -> (WEActionKind _rv)")}, - {"WEIsTyping", (PyCFunction)wasteObj_WEIsTyping, 1, - PyDoc_STR("() -> (Boolean _rv)")}, - {"WEBeginAction", (PyCFunction)wasteObj_WEBeginAction, 1, - PyDoc_STR("() -> None")}, - {"WEEndAction", (PyCFunction)wasteObj_WEEndAction, 1, - PyDoc_STR("(WEActionKind inActionKind) -> None")}, - {"WEGetModCount", (PyCFunction)wasteObj_WEGetModCount, 1, - PyDoc_STR("() -> (UInt32 _rv)")}, - {"WEResetModCount", (PyCFunction)wasteObj_WEResetModCount, 1, - PyDoc_STR("() -> None")}, - {"WEInsertObject", (PyCFunction)wasteObj_WEInsertObject, 1, - PyDoc_STR("(FlavorType inObjectType, Handle inObjectDataHandle, Point inObjectSize) -> None")}, - {"WEGetSelectedObject", (PyCFunction)wasteObj_WEGetSelectedObject, 1, - PyDoc_STR("() -> (WEObjectReference outObject)")}, - {"WEGetObjectAtOffset", (PyCFunction)wasteObj_WEGetObjectAtOffset, 1, - PyDoc_STR("(SInt32 inOffset) -> (WEObjectReference outObject)")}, - {"WEFindNextObject", (PyCFunction)wasteObj_WEFindNextObject, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt32 _rv, WEObjectReference outObject)")}, - {"WEUseSoup", (PyCFunction)wasteObj_WEUseSoup, 1, - PyDoc_STR("(WESoupHandle inSoup) -> None")}, - {"WECut", (PyCFunction)wasteObj_WECut, 1, - PyDoc_STR("() -> None")}, - {"WECopy", (PyCFunction)wasteObj_WECopy, 1, - PyDoc_STR("() -> None")}, - {"WEPaste", (PyCFunction)wasteObj_WEPaste, 1, - PyDoc_STR("() -> None")}, - {"WECanPaste", (PyCFunction)wasteObj_WECanPaste, 1, - PyDoc_STR("() -> (Boolean _rv)")}, - {"WEGetHiliteRgn", (PyCFunction)wasteObj_WEGetHiliteRgn, 1, - PyDoc_STR("(SInt32 inRangeStart, SInt32 inRangeEnd) -> (RgnHandle _rv)")}, - {"WECharByte", (PyCFunction)wasteObj_WECharByte, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt16 _rv)")}, - {"WECharType", (PyCFunction)wasteObj_WECharType, 1, - PyDoc_STR("(SInt32 inOffset) -> (SInt16 _rv)")}, - {"WEStopInlineSession", (PyCFunction)wasteObj_WEStopInlineSession, 1, - PyDoc_STR("() -> None")}, - {"WEFeatureFlag", (PyCFunction)wasteObj_WEFeatureFlag, 1, - PyDoc_STR("(SInt16 inFeature, SInt16 inAction) -> (SInt16 _rv)")}, - {"WEGetUserInfo", (PyCFunction)wasteObj_WEGetUserInfo, 1, - PyDoc_STR("(WESelector inUserTag) -> (SInt32 outUserInfo)")}, - {"WESetUserInfo", (PyCFunction)wasteObj_WESetUserInfo, 1, - PyDoc_STR("(WESelector inUserTag, SInt32 inUserInfo) -> None")}, - {"WERemoveUserInfo", (PyCFunction)wasteObj_WERemoveUserInfo, 1, - PyDoc_STR("(WESelector inUserTag) -> None")}, - {"WEInstallTabHooks", (PyCFunction)wasteObj_WEInstallTabHooks, 1, - PyDoc_STR("() -> None")}, - {"WERemoveTabHooks", (PyCFunction)wasteObj_WERemoveTabHooks, 1, - PyDoc_STR("() -> None")}, - {"WEIsTabHooks", (PyCFunction)wasteObj_WEIsTabHooks, 1, - PyDoc_STR("() -> (Boolean _rv)")}, - {"WEGetTabSize", (PyCFunction)wasteObj_WEGetTabSize, 1, - PyDoc_STR("() -> (SInt16 _rv)")}, - {"WESetTabSize", (PyCFunction)wasteObj_WESetTabSize, 1, - PyDoc_STR("(SInt16 tabWidth) -> None")}, - {NULL, NULL, 0} -}; - -#define wasteObj_getsetlist NULL - - -#define wasteObj_compare NULL - -#define wasteObj_repr NULL - -#define wasteObj_hash NULL -#define wasteObj_tp_init 0 - -#define wasteObj_tp_alloc PyType_GenericAlloc - -static PyObject *wasteObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) -{ - PyObject *_self; - WEReference itself; - char *kw[] = {"itself", 0}; - - if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, wasteObj_Convert, &itself)) return NULL; - if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; - ((wasteObject *)_self)->ob_itself = itself; - return _self; -} - -#define wasteObj_tp_free PyObject_Del - - -PyTypeObject waste_Type = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ - "waste.waste", /*tp_name*/ - sizeof(wasteObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor) wasteObj_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - (cmpfunc) wasteObj_compare, /*tp_compare*/ - (reprfunc) wasteObj_repr, /*tp_repr*/ - (PyNumberMethods *)0, /* tp_as_number */ - (PySequenceMethods *)0, /* tp_as_sequence */ - (PyMappingMethods *)0, /* tp_as_mapping */ - (hashfunc) wasteObj_hash, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - PyObject_GenericGetAttr, /*tp_getattro*/ - PyObject_GenericSetAttr, /*tp_setattro */ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - wasteObj_methods, /* tp_methods */ - 0, /*tp_members*/ - wasteObj_getsetlist, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - wasteObj_tp_init, /* tp_init */ - wasteObj_tp_alloc, /* tp_alloc */ - wasteObj_tp_new, /* tp_new */ - wasteObj_tp_free, /* tp_free */ -}; - -/* --------------------- End object type waste ---------------------- */ - - -static PyObject *waste_WENew(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - LongRect inDestRect; - LongRect inViewRect; - OptionBits inOptions; - WEReference outWE; - if (!PyArg_ParseTuple(_args, "O&O&l", - LongRect_Convert, &inDestRect, - LongRect_Convert, &inViewRect, - &inOptions)) - return NULL; - _err = WENew(&inDestRect, - &inViewRect, - inOptions, - &outWE); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - wasteObj_New, outWE); - return _res; -} - -static PyObject *waste_WEUpdateStyleScrap(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - StScrpHandle ioStyles; - WEFontTableHandle inFontTable; - if (!PyArg_ParseTuple(_args, "O&O&", - ResObj_Convert, &ioStyles, - ResObj_Convert, &inFontTable)) - return NULL; - _err = WEUpdateStyleScrap(ioStyles, - inFontTable); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *waste_WEInstallTSMHandlers(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WEInstallTSMHandlers(); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *waste_WERemoveTSMHandlers(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - if (!PyArg_ParseTuple(_args, "")) - return NULL; - _err = WERemoveTSMHandlers(); - if (_err != noErr) return PyMac_Error(_err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -} - -static PyObject *waste_WEHandleTSMEvent(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - OSErr _err; - AppleEvent inAppleEvent; - AppleEvent ioReply; - if (!PyArg_ParseTuple(_args, "O&", - AEDesc_Convert, &inAppleEvent)) - return NULL; - _err = WEHandleTSMEvent(&inAppleEvent, - &ioReply); - if (_err != noErr) return PyMac_Error(_err); - _res = Py_BuildValue("O&", - AEDesc_New, &ioReply); - return _res; -} - -static PyObject *waste_WELongPointToPoint(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongPt inLongPoint; - Point outPoint; - if (!PyArg_ParseTuple(_args, "O&", - LongPt_Convert, &inLongPoint)) - return NULL; - WELongPointToPoint(&inLongPoint, - &outPoint); - _res = Py_BuildValue("O&", - PyMac_BuildPoint, outPoint); - return _res; -} - -static PyObject *waste_WEPointToLongPoint(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Point inPoint; - LongPt outLongPoint; - if (!PyArg_ParseTuple(_args, "O&", - PyMac_GetPoint, &inPoint)) - return NULL; - WEPointToLongPoint(inPoint, - &outLongPoint); - _res = Py_BuildValue("O&", - LongPt_New, &outLongPoint); - return _res; -} - -static PyObject *waste_WESetLongRect(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect outLongRect; - SInt32 inLeft; - SInt32 inTop; - SInt32 inRight; - SInt32 inBottom; - if (!PyArg_ParseTuple(_args, "llll", - &inLeft, - &inTop, - &inRight, - &inBottom)) - return NULL; - WESetLongRect(&outLongRect, - inLeft, - inTop, - inRight, - inBottom); - _res = Py_BuildValue("O&", - LongRect_New, &outLongRect); - return _res; -} - -static PyObject *waste_WELongRectToRect(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect inLongRect; - Rect outRect; - if (!PyArg_ParseTuple(_args, "O&", - LongRect_Convert, &inLongRect)) - return NULL; - WELongRectToRect(&inLongRect, - &outRect); - _res = Py_BuildValue("O&", - PyMac_BuildRect, &outRect); - return _res; -} - -static PyObject *waste_WERectToLongRect(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Rect inRect; - LongRect outLongRect; - if (!PyArg_ParseTuple(_args, "O&", - PyMac_GetRect, &inRect)) - return NULL; - WERectToLongRect(&inRect, - &outLongRect); - _res = Py_BuildValue("O&", - LongRect_New, &outLongRect); - return _res; -} - -static PyObject *waste_WEOffsetLongRect(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - LongRect ioLongRect; - SInt32 inHorizontalOffset; - SInt32 inVerticalOffset; - if (!PyArg_ParseTuple(_args, "ll", - &inHorizontalOffset, - &inVerticalOffset)) - return NULL; - WEOffsetLongRect(&ioLongRect, - inHorizontalOffset, - inVerticalOffset); - _res = Py_BuildValue("O&", - LongRect_New, &ioLongRect); - return _res; -} - -static PyObject *waste_WELongPointInLongRect(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - Boolean _rv; - LongPt inLongPoint; - LongRect inLongRect; - if (!PyArg_ParseTuple(_args, "O&O&", - LongPt_Convert, &inLongPoint, - LongRect_Convert, &inLongRect)) - return NULL; - _rv = WELongPointInLongRect(&inLongPoint, - &inLongRect); - _res = Py_BuildValue("b", - _rv); - return _res; -} - -static PyObject *waste_STDObjectHandlers(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - - OSErr err; - // install the sample object handlers for pictures and sounds -#define kTypePicture 'PICT' -#define kTypeSound 'snd ' - - if ( !PyArg_ParseTuple(_args, "") ) return NULL; - - if ((err = WEInstallObjectHandler(kTypePicture, weNewHandler, - (UniversalProcPtr) NewWENewObjectProc(HandleNewPicture), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypePicture, weDisposeHandler, - (UniversalProcPtr) NewWEDisposeObjectProc(HandleDisposePicture), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypePicture, weDrawHandler, - (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawPicture), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypeSound, weNewHandler, - (UniversalProcPtr) NewWENewObjectProc(HandleNewSound), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypeSound, weDrawHandler, - (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawSound), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypeSound, weClickHandler, - (UniversalProcPtr) NewWEClickObjectProc(HandleClickSound), NULL)) != noErr) - goto cleanup; - Py_INCREF(Py_None); - _res = Py_None; - return _res; - - cleanup: - return PyMac_Error(err); - -} - -static PyObject *waste_WEInstallObjectHandler(PyObject *_self, PyObject *_args) -{ - PyObject *_res = NULL; - - OSErr err; - FlavorType objectType; - WESelector selector; - PyObject *py_handler; - UniversalProcPtr handler; - WEReference we = NULL; - PyObject *key; - - - if ( !PyArg_ParseTuple(_args, "O&O&O|O&", - PyMac_GetOSType, &objectType, - PyMac_GetOSType, &selector, - &py_handler, - WEOObj_Convert, &we) ) return NULL; - - if ( selector == weNewHandler ) handler = (UniversalProcPtr)upp_new_handler; - else if ( selector == weDisposeHandler ) handler = (UniversalProcPtr)upp_dispose_handler; - else if ( selector == weDrawHandler ) handler = (UniversalProcPtr)upp_draw_handler; - else if ( selector == weClickHandler ) handler = (UniversalProcPtr)upp_click_handler; - else return PyMac_Error(weUndefinedSelectorErr); - - if ((key = Py_BuildValue("O&O&", - PyMac_BuildOSType, objectType, - PyMac_BuildOSType, selector)) == NULL ) - return NULL; - - PyDict_SetItem(callbackdict, key, py_handler); - - err = WEInstallObjectHandler(objectType, selector, handler, we); - if ( err ) return PyMac_Error(err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; - -} - -static PyMethodDef waste_methods[] = { - {"WENew", (PyCFunction)waste_WENew, 1, - PyDoc_STR("(LongRect inDestRect, LongRect inViewRect, OptionBits inOptions) -> (WEReference outWE)")}, - {"WEUpdateStyleScrap", (PyCFunction)waste_WEUpdateStyleScrap, 1, - PyDoc_STR("(StScrpHandle ioStyles, WEFontTableHandle inFontTable) -> None")}, - {"WEInstallTSMHandlers", (PyCFunction)waste_WEInstallTSMHandlers, 1, - PyDoc_STR("() -> None")}, - {"WERemoveTSMHandlers", (PyCFunction)waste_WERemoveTSMHandlers, 1, - PyDoc_STR("() -> None")}, - {"WEHandleTSMEvent", (PyCFunction)waste_WEHandleTSMEvent, 1, - PyDoc_STR("(AppleEvent inAppleEvent) -> (AppleEvent ioReply)")}, - {"WELongPointToPoint", (PyCFunction)waste_WELongPointToPoint, 1, - PyDoc_STR("(LongPt inLongPoint) -> (Point outPoint)")}, - {"WEPointToLongPoint", (PyCFunction)waste_WEPointToLongPoint, 1, - PyDoc_STR("(Point inPoint) -> (LongPt outLongPoint)")}, - {"WESetLongRect", (PyCFunction)waste_WESetLongRect, 1, - PyDoc_STR("(SInt32 inLeft, SInt32 inTop, SInt32 inRight, SInt32 inBottom) -> (LongRect outLongRect)")}, - {"WELongRectToRect", (PyCFunction)waste_WELongRectToRect, 1, - PyDoc_STR("(LongRect inLongRect) -> (Rect outRect)")}, - {"WERectToLongRect", (PyCFunction)waste_WERectToLongRect, 1, - PyDoc_STR("(Rect inRect) -> (LongRect outLongRect)")}, - {"WEOffsetLongRect", (PyCFunction)waste_WEOffsetLongRect, 1, - PyDoc_STR("(SInt32 inHorizontalOffset, SInt32 inVerticalOffset) -> (LongRect ioLongRect)")}, - {"WELongPointInLongRect", (PyCFunction)waste_WELongPointInLongRect, 1, - PyDoc_STR("(LongPt inLongPoint, LongRect inLongRect) -> (Boolean _rv)")}, - {"STDObjectHandlers", (PyCFunction)waste_STDObjectHandlers, 1, - PyDoc_STR(NULL)}, - {"WEInstallObjectHandler", (PyCFunction)waste_WEInstallObjectHandler, 1, - PyDoc_STR(NULL)}, - {NULL, NULL, 0} -}; - - - -/* Return the object corresponding to the window, or NULL */ - -PyObject * -ExistingwasteObj_New(w) - WEReference w; -{ - PyObject *it = NULL; - - if (w == NULL) - it = NULL; - else - WEGetInfo(weRefCon, (void *)&it, w); - if (it == NULL || ((wasteObject *)it)->ob_itself != w) - it = Py_None; - Py_INCREF(it); - return it; -} - - -void initwaste(void) -{ - PyObject *m; - PyObject *d; - - - - - m = Py_InitModule("waste", waste_methods); - d = PyModule_GetDict(m); - waste_Error = PyMac_GetOSErrException(); - if (waste_Error == NULL || - PyDict_SetItemString(d, "Error", waste_Error) != 0) - return; - WEO_Type.ob_type = &PyType_Type; - if (PyType_Ready(&WEO_Type) < 0) return; - Py_INCREF(&WEO_Type); - PyModule_AddObject(m, "WEO", (PyObject *)&WEO_Type); - /* Backward-compatible name */ - Py_INCREF(&WEO_Type); - PyModule_AddObject(m, "WEOType", (PyObject *)&WEO_Type); - waste_Type.ob_type = &PyType_Type; - if (PyType_Ready(&waste_Type) < 0) return; - Py_INCREF(&waste_Type); - PyModule_AddObject(m, "waste", (PyObject *)&waste_Type); - /* Backward-compatible name */ - Py_INCREF(&waste_Type); - PyModule_AddObject(m, "wasteType", (PyObject *)&waste_Type); - - callbackdict = PyDict_New(); - if (callbackdict == NULL || PyDict_SetItemString(d, "callbacks", callbackdict) != 0) - return; - upp_new_handler = NewWENewObjectProc(my_new_handler); - upp_dispose_handler = NewWEDisposeObjectProc(my_dispose_handler); - upp_draw_handler = NewWEDrawObjectProc(my_draw_handler); - upp_click_handler = NewWEClickObjectProc(my_click_handler); - - -} - -/* ======================== End module waste ======================== */ - diff --git a/Mac/Modules/waste/wastescan.py b/Mac/Modules/waste/wastescan.py deleted file mode 100644 index b5a2b43..0000000 --- a/Mac/Modules/waste/wastescan.py +++ /dev/null @@ -1,152 +0,0 @@ -# Scan an Apple header file, generating a Python file of generator calls. - -import sys -import os -from bgenlocations import TOOLBOXDIR, BGENDIR -sys.path.append(BGENDIR) -from scantools import Scanner - -WASTEDIR='/Users/jack/src/waste/C_C++ Headers/' - -if not os.path.exists(WASTEDIR): - raise 'Error: not found: %s', WASTEDIR - -OBJECT = "TEHandle" -SHORT = "waste" -OBJECT = "WEReference" -OBJECT2 = "WEObjectReference" - -def main(): - input = WASTEDIR + "WASTE.h" - output = SHORT + "gen.py" - defsoutput = os.path.join(os.path.split(TOOLBOXDIR)[0], "WASTEconst.py") - scanner = MyScanner(input, output, defsoutput) - scanner.scan() -## scanner.gentypetest(SHORT+"typetest.py") - scanner.close() - print "=== Testing definitions output code ===" - execfile(defsoutput, {}, {}) - print "=== Done scanning and generating, now importing the generated code... ===" - exec "import " + SHORT + "support" - print "=== Done. It's up to you to compile it now! ===" - -#class MyScanner(Scanner_PreUH3): -class MyScanner(Scanner): - - def destination(self, type, name, arglist): - classname = "Function" - listname = "functions" - if arglist: - t, n, m = arglist[-1] - # This is non-functional today - if t == OBJECT and m == "InMode": - classname = "Method" - listname = "methods" - else: - t, n, m = arglist[0] - if t == OBJECT2 and m == "InMode": - classname = "Method2" - listname = "methods2" - return classname, listname - - def writeinitialdefs(self): - self.defsfile.write("kPascalStackBased = None # workaround for header parsing\n") - self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") - - def makeblacklistnames(self): - return [ - "WEDispose", - "WESetInfo", # Argument type unknown... - "WEGetInfo", - "WEVersion", # Unfortunately... - "WEPut", # XXXX TBD: needs array of flavortypes. - "WEGetOneAttribute", # XXXX TBD: output buffer - # Incompatible constant definitions - "weDoAutoScroll", - "weDoOutlineHilite", - "weDoReadOnly", - "weDoUndo", - "weDoIntCutAndPaste", - "weDoDragAndDrop", - "weDoInhibitRecal", - "weDoUseTempMem", - "weDoDrawOffscreen", - "weDoInhibitRedraw", - "weDoMonoStyled", - "weDoMultipleUndo", - "weDoNoKeyboardSync", - "weDoInhibitICSupport", - "weDoInhibitColor", - ] - - def makeblacklisttypes(self): - return [ - "DragReference", # For now... - "UniversalProcPtr", - "WEFontIDToNameUPP", - "WEFontNameToIDUPP", - "WEClickLoopUPP", - "WEScrollUPP", - "WETSMPreUpdateUPP", - "WETSMPostUpdateUPP", - "WEPreTrackDragUPP", - "WETranslateDragUPP", - "WEHiliteDropAreaUPP", - "WEDrawTextUPP", - "WEDrawTSMHiliteUPP", - "WEPixelToCharUPP", - "WECharToPixelUPP", - "WELineBreakUPP", - "WEWordBreakUPP", - "WECharByteUPP", - "WECharTypeUPP", - "WEEraseUPP", - "WEFluxUPP", - "WENewObjectUPP", - "WEDisposeObjectUPP", - "WEDrawObjectUPP", - "WEClickObjectUPP", - "WEStreamObjectUPP", - "WEHoverObjectUPP", - "WERuler", # XXXX To be done - "WERuler_ptr", # ditto - "WEParaInfo", # XXXX To be done - "WEPrintSession", # XXXX To be done - "WEPrintOptions_ptr", # XXXX To be done - ] - - def makerepairinstructions(self): - return [ - ([("void_ptr", "*", "InMode"), ("SInt32", "*", "InMode")], - [("InBuffer", "*", "*")]), - - # WEContinuousStyle - ([("WEStyleMode", "ioMode", "OutMode"), ("TextStyle", "outTextStyle", "OutMode")], - [("WEStyleMode", "*", "InOutMode"), ("TextStyle", "*", "*")]), - - # WECopyRange - ([('Handle', 'outText', 'InMode'), ('StScrpHandle', 'outStyles', 'InMode'), - ('WESoupHandle', 'outSoup', 'InMode')], - [('OptHandle', '*', '*'), ('OptStScrpHandle', '*', '*'), - ('OptSoupHandle', '*', '*')]), - - # WEInsert - ([('StScrpHandle', 'inStyles', 'InMode'), ('WESoupHandle', 'inSoup', 'InMode')], - [('OptStScrpHandle', '*', '*'), ('OptSoupHandle', '*', '*')]), - - # WEGetObjectOwner - ("WEGetObjectOwner", - [('WEReference', '*', 'ReturnMode')], - [('ExistingWEReference', '*', 'ReturnMode')]), - - # WEFindParagraph - ([("char_ptr", "inKey", "InMode")], - [("stringptr", "*", "*")]), - - # WESetOneAttribute - ([("void_ptr", "*", "InMode"), ("ByteCount", "*", "InMode")], - [("InBuffer", "*", "*")]), - ] - -if __name__ == "__main__": - main() diff --git a/Mac/Modules/waste/wastesupport.py b/Mac/Modules/waste/wastesupport.py deleted file mode 100644 index 13ddc40..0000000 --- a/Mac/Modules/waste/wastesupport.py +++ /dev/null @@ -1,444 +0,0 @@ -# This script generates a Python interface for an Apple Macintosh Manager. -# It uses the "bgen" package to generate C code. -# The function specifications are generated by scanning the mamager's header file, -# using the "scantools" package (customized for this particular manager). - -import string - -# Declarations that change for each manager -MACHEADERFILE = 'WASTE.h' # The Apple header file -MODNAME = 'waste' # The name of the module -OBJECTNAME = 'waste' # The basic name of the objects used here -KIND = 'Ptr' # Usually 'Ptr' or 'Handle' - -# The following is *usually* unchanged but may still require tuning -MODPREFIX = MODNAME # The prefix for module-wide routines -OBJECTTYPE = "WEReference" # The C type used to represent them -OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods -INPUTFILE = 'wastegen.py' # The file generated by the scanner -TYPETESTFILE = 'wastetypetest.py' # Another file generated by the scanner -OUTPUTFILE = "wastemodule.c" # The file generated by this program - -from macsupport import * - -# Create the type objects -WEReference = OpaqueByValueType("WEReference", "wasteObj") -ExistingWEReference = OpaqueByValueType("WEReference", "ExistingwasteObj") -WEObjectReference = OpaqueByValueType("WEObjectReference", "WEOObj") -StScrpHandle = OpaqueByValueType("StScrpHandle", "ResObj") -RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") -EventModifiers = Type("EventModifiers", "H") -FlavorType = OSTypeType("FlavorType") -WESelector = OSTypeType("WESelector") - -OptHandle = OpaqueByValueType("Handle", "OptResObj") -OptSoupHandle = OpaqueByValueType("WESoupHandle", "OptResObj") -OptStScrpHandle = OpaqueByValueType("StScrpHandle", "OptResObj") - -WEStyleMode = Type("WEStyleMode", "H") -WERulerMode = Type("WERulerMode", "l") -WEActionKind = Type("WEActionKind", "h") -WEAlignment = Type("WEAlignment", "B") -WEEdge = Type("WEEdge", "B") -WEDirection = Type("WEDirection", "h") -WESoupHandle = OpaqueByValueType("WESoupHandle", "ResObj") -WEFontTableHandle = OpaqueByValueType("WEFontTableHandle", "ResObj") -WEFontTableHandle -WERunInfo = OpaqueType("WERunInfo", "RunInfo") - -AppleEvent = OpaqueType('AppleEvent', 'AEDesc') -AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc') - -TextStyle = OpaqueType("TextStyle", "TextStyle") -TextStyle_ptr = TextStyle -LongPt = OpaqueType("LongPt", "LongPt") -LongPt_ptr = LongPt -LongRect = OpaqueType("LongRect", "LongRect") -LongRect_ptr = LongRect - -TextEncodingVariant = Type("TextEncodingVariant", "l") -TextEncodingFormat = Type("TextEncodingFormat", "l") - -includestuff = includestuff + """ -#include <%s>""" % MACHEADERFILE + """ -#include -#include - -/* Exported by Qdmodule.c: */ -extern PyObject *QdRGB_New(RGBColor *); -extern int QdRGB_Convert(PyObject *, RGBColor *); - -/* Exported by AEModule.c: */ -extern PyObject *AEDesc_New(AppleEvent *); -extern int AEDesc_Convert(PyObject *, AppleEvent *); - -/* Forward declaration */ -static PyObject *WEOObj_New(WEObjectReference); -static PyObject *ExistingwasteObj_New(WEReference); - -/* -** Parse/generate TextStyle records -*/ -static PyObject * -TextStyle_New(TextStylePtr itself) -{ - - return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New, - &itself->tsColor); -} - -static int -TextStyle_Convert(PyObject *v, TextStylePtr p_itself) -{ - long font, face, size; - - if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) ) - return 0; - p_itself->tsFont = (short)font; - p_itself->tsFace = (Style)face; - p_itself->tsSize = (short)size; - return 1; -} - -/* -** Parse/generate RunInfo records -*/ -static PyObject * -RunInfo_New(WERunInfo *itself) -{ - - return Py_BuildValue("llhhO&O&", itself->runStart, itself->runEnd, itself->runHeight, - itself->runAscent, TextStyle_New, &itself->runStyle, WEOObj_New, itself->runObject); -} - -/* Conversion of long points and rects */ -int -LongRect_Convert(PyObject *v, LongRect *r) -{ - return PyArg_Parse(v, "(llll)", &r->left, &r->top, &r->right, &r->bottom); -} - -PyObject * -LongRect_New(LongRect *r) -{ - return Py_BuildValue("(llll)", r->left, r->top, r->right, r->bottom); -} - -int -LongPt_Convert(PyObject *v, LongPt *p) -{ - return PyArg_Parse(v, "(ll)", &p->h, &p->v); -} - -PyObject * -LongPt_New(LongPt *p) -{ - return Py_BuildValue("(ll)", p->h, p->v); -} - -/* Stuff for the callbacks: */ -static PyObject *callbackdict; -WENewObjectUPP upp_new_handler; -WEDisposeObjectUPP upp_dispose_handler; -WEDrawObjectUPP upp_draw_handler; -WEClickObjectUPP upp_click_handler; - -static OSErr -any_handler(WESelector what, WEObjectReference who, PyObject *args, PyObject **rv) -{ - FlavorType tp; - PyObject *key, *func; - - if ( args == NULL ) return errAECorruptData; - - tp = WEGetObjectType(who); - - if( (key=Py_BuildValue("O&O&", PyMac_BuildOSType, tp, PyMac_BuildOSType, what)) == NULL) - return errAECorruptData; - if( (func = PyDict_GetItem(callbackdict, key)) == NULL ) { - Py_DECREF(key); - return errAEHandlerNotFound; - } - Py_INCREF(func); - *rv = PyEval_CallObject(func, args); - Py_DECREF(func); - Py_DECREF(key); - if ( *rv == NULL ) { - PySys_WriteStderr("--Exception in callback: "); - PyErr_Print(); - return errAEReplyNotArrived; - } - return 0; -} - -static pascal OSErr -my_new_handler(Point *objectSize, WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - OSErr err; - - args=Py_BuildValue("(O&)", WEOObj_New, objref); - err = any_handler(weNewHandler, objref, args, &rv); - if (!err) { - if (!PyMac_GetPoint(rv, objectSize) ) - err = errAECoercionFail; - } - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return err; -} - -static pascal OSErr -my_dispose_handler(WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - OSErr err; - - args=Py_BuildValue("(O&)", WEOObj_New, objref); - err = any_handler(weDisposeHandler, objref, args, &rv); - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return err; -} - -static pascal OSErr -my_draw_handler(const Rect *destRect, WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - OSErr err; - - args=Py_BuildValue("O&O&", PyMac_BuildRect, destRect, WEOObj_New, objref); - err = any_handler(weDrawHandler, objref, args, &rv); - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return err; -} - -static pascal Boolean -my_click_handler(Point hitPt, EventModifiers modifiers, - unsigned long clickTime, WEObjectReference objref) -{ - PyObject *args=NULL, *rv=NULL; - int retvalue; - OSErr err; - - args=Py_BuildValue("O&llO&", PyMac_BuildPoint, hitPt, - (long)modifiers, (long)clickTime, WEOObj_New, objref); - err = any_handler(weClickHandler, objref, args, &rv); - if (!err) - retvalue = PyInt_AsLong(rv); - else - retvalue = 0; - if ( args ) { - Py_DECREF(args); - } - if ( rv ) { - Py_DECREF(rv); - } - return retvalue; -} - - -""" -finalstuff = finalstuff + """ -/* Return the object corresponding to the window, or NULL */ - -PyObject * -ExistingwasteObj_New(w) - WEReference w; -{ - PyObject *it = NULL; - - if (w == NULL) - it = NULL; - else - WEGetInfo(weRefCon, (void *)&it, w); - if (it == NULL || ((wasteObject *)it)->ob_itself != w) - it = Py_None; - Py_INCREF(it); - return it; -} -""" - -class WEMethodGenerator(OSErrMethodGenerator): - """Similar to MethodGenerator, but has self as last argument""" - - def parseArgumentList(self, args): - args, a0 = args[:-1], args[-1] - t0, n0, m0 = a0 - if m0 != InMode: - raise ValueError, "method's 'self' must be 'InMode'" - self.itself = Variable(t0, "_self->ob_itself", SelfMode) - FunctionGenerator.parseArgumentList(self, args) - self.argumentList.append(self.itself) - - - -class WEObjectDefinition(PEP253Mixin, GlobalObjectDefinition): - def outputCheckNewArg(self): - Output("""if (itself == NULL) { - PyErr_SetString(waste_Error,"Cannot create null WE"); - return NULL; - }""") - def outputInitStructMembers(self): - GlobalObjectDefinition.outputInitStructMembers(self) - Output("WESetInfo(weRefCon, (void *)&it, itself);") - def outputFreeIt(self, itselfname): - Output("WEDispose(%s);", itselfname) - -class WEOObjectDefinition(PEP253Mixin, GlobalObjectDefinition): - def outputCheckNewArg(self): - Output("""if (itself == NULL) { - Py_INCREF(Py_None); - return Py_None; - }""") - -variablestuff = """ - callbackdict = PyDict_New(); - if (callbackdict == NULL || PyDict_SetItemString(d, "callbacks", callbackdict) != 0) - return; - upp_new_handler = NewWENewObjectProc(my_new_handler); - upp_dispose_handler = NewWEDisposeObjectProc(my_dispose_handler); - upp_draw_handler = NewWEDrawObjectProc(my_draw_handler); - upp_click_handler = NewWEClickObjectProc(my_click_handler); -""" - - -# From here on it's basically all boiler plate... - -# Test types used for existence -## execfile(TYPETESTFILE) - -# Create the generator groups and link them -module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff) -object = WEObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) -object2 = WEOObjectDefinition("WEO", "WEOObj", "WEObjectReference") -module.addobject(object2) -module.addobject(object) - -# Create the generator classes used to populate the lists -Function = OSErrFunctionGenerator -Method = WEMethodGenerator -Method2 = OSErrMethodGenerator - -# Create and populate the lists -functions = [] -methods = [] -methods2 = [] -execfile(INPUTFILE) - -# A function written by hand: -stdhandlers_body = """ - OSErr err; - // install the sample object handlers for pictures and sounds -#define kTypePicture 'PICT' -#define kTypeSound 'snd ' - - if ( !PyArg_ParseTuple(_args, "") ) return NULL; - - if ((err = WEInstallObjectHandler(kTypePicture, weNewHandler, - (UniversalProcPtr) NewWENewObjectProc(HandleNewPicture), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypePicture, weDisposeHandler, - (UniversalProcPtr) NewWEDisposeObjectProc(HandleDisposePicture), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypePicture, weDrawHandler, - (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawPicture), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypeSound, weNewHandler, - (UniversalProcPtr) NewWENewObjectProc(HandleNewSound), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypeSound, weDrawHandler, - (UniversalProcPtr) NewWEDrawObjectProc(HandleDrawSound), NULL)) != noErr) - goto cleanup; - - if ((err = WEInstallObjectHandler(kTypeSound, weClickHandler, - (UniversalProcPtr) NewWEClickObjectProc(HandleClickSound), NULL)) != noErr) - goto cleanup; - Py_INCREF(Py_None); - _res = Py_None; - return _res; - -cleanup: - return PyMac_Error(err); -""" - -inshandler_body = """ - OSErr err; - FlavorType objectType; - WESelector selector; - PyObject *py_handler; - UniversalProcPtr handler; - WEReference we = NULL; - PyObject *key; - - - if ( !PyArg_ParseTuple(_args, "O&O&O|O&", - PyMac_GetOSType, &objectType, - PyMac_GetOSType, &selector, - &py_handler, - WEOObj_Convert, &we) ) return NULL; - - if ( selector == weNewHandler ) handler = (UniversalProcPtr)upp_new_handler; - else if ( selector == weDisposeHandler ) handler = (UniversalProcPtr)upp_dispose_handler; - else if ( selector == weDrawHandler ) handler = (UniversalProcPtr)upp_draw_handler; - else if ( selector == weClickHandler ) handler = (UniversalProcPtr)upp_click_handler; - else return PyMac_Error(weUndefinedSelectorErr); - - if ((key = Py_BuildValue("O&O&", - PyMac_BuildOSType, objectType, - PyMac_BuildOSType, selector)) == NULL ) - return NULL; - - PyDict_SetItem(callbackdict, key, py_handler); - - err = WEInstallObjectHandler(objectType, selector, handler, we); - if ( err ) return PyMac_Error(err); - Py_INCREF(Py_None); - _res = Py_None; - return _res; -""" - -stdhand = ManualGenerator("STDObjectHandlers", stdhandlers_body) -inshand = ManualGenerator("WEInstallObjectHandler", inshandler_body) - - -# Tab hook handlers. Could be parsed from WETabs.h, but this is just as simple. -f = Method(OSErr, 'WEInstallTabHooks', (WEReference, 'we', InMode)) -methods.append(f) -f = Method(OSErr, 'WERemoveTabHooks', (WEReference, 'we', InMode)) -methods.append(f) -f = Method(Boolean, 'WEIsTabHooks', (WEReference, 'we', InMode)) -methods.append(f) -f = Method(SInt16, 'WEGetTabSize', (WEReference, 'we', InMode)) -methods.append(f) -f = Method(OSErr, 'WESetTabSize', (SInt16, 'tabWidth', InMode), (WEReference, 'we', InMode)) -methods.append(f) - -# add the populated lists to the generator groups -# (in a different wordl the scan program would generate this) -for f in functions: module.add(f) -module.add(stdhand) -module.add(inshand) -for f in methods: object.add(f) -for f in methods2: object2.add(f) - -# generate output (open the output file as late as possible) -SetOutputFileName(OUTPUTFILE) -module.generate() diff --git a/Mac/OSX/BuildScript/README.txt b/Mac/OSX/BuildScript/README.txt deleted file mode 100644 index c556de83..0000000 --- a/Mac/OSX/BuildScript/README.txt +++ /dev/null @@ -1,35 +0,0 @@ -Building a MacPython distribution -================================= - -The ``build-install.py`` script creates MacPython distributions, including -sleepycat db4, sqlite3 and readline support. It builds a complete -framework-based Python out-of-tree, installs it in a funny place with -$DESTROOT, massages that installation to remove .pyc files and such, creates -an Installer package from the installation plus other files in ``resources`` -and ``scripts`` and placed that on a ``.dmg`` disk image. - -Here are the steps you ned to follow to build a MacPython installer: - -- Run ``./build-installer.py``. Optionally you can pass a number of arguments - to specify locations of various files. Please see the top of - ``build-installer.py`` for its usage. -- When done the script will tell you where the DMG image is. - -The script needs to be run on Mac OS X 10.4 with Xcode 2.2 or later and -the 10.4u SDK. - -When all is done, announcements can be posted to at least the following -places: -- pythonmac-sig@python.org -- python-dev@python.org -- python-announce@python.org -- archivist@info-mac.org -- adcnews@apple.com -- news@macnn.com -- http://www.macupdate.com -- http://guide.apple.com/usindex.lasso -- http://www.apple.com/downloads/macosx/submit -- http://www.versiontracker.com/ (userid Jack.Jansen@oratrix.com) -- http://www.macshareware.net (userid jackjansen) - -Also, check out Stephan Deibels http://pythonology.org/market contact list diff --git a/Mac/OSX/BuildScript/build-installer.py b/Mac/OSX/BuildScript/build-installer.py deleted file mode 100755 index b24f5dc..0000000 --- a/Mac/OSX/BuildScript/build-installer.py +++ /dev/null @@ -1,1014 +0,0 @@ -#!/usr/bin/python2.3 -""" -This script is used to build the "official unofficial" universal build on -Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its -work. - -Please ensure that this script keeps working with Python 2.3, to avoid -bootstrap issues (/usr/bin/python is Python 2.3 on OSX 10.4) - -Usage: see USAGE variable in the script. -""" -import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd - -INCLUDE_TIMESTAMP=1 -VERBOSE=1 - -from plistlib import Plist - -import MacOS -import Carbon.File -import Carbon.Icn -import Carbon.Res -from Carbon.Files import kCustomIconResource, fsRdWrPerm, kHasCustomIcon -from Carbon.Files import kFSCatInfoFinderInfo - -try: - from plistlib import writePlist -except ImportError: - # We're run using python2.3 - def writePlist(plist, path): - plist.write(path) - -def shellQuote(value): - """ - Return the string value in a form that can savely be inserted into - a shell command. - """ - return "'%s'"%(value.replace("'", "'\"'\"'")) - -def grepValue(fn, variable): - variable = variable + '=' - for ln in open(fn, 'r'): - if ln.startswith(variable): - value = ln[len(variable):].strip() - return value[1:-1] - -def getVersion(): - return grepValue(os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') - -def getFullVersion(): - fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') - for ln in open(fn): - if 'PY_VERSION' in ln: - return ln.split()[-1][1:-1] - - raise RuntimeError, "Cannot find full version??" - -# The directory we'll use to create the build, will be erased and recreated -WORKDIR="/tmp/_py" - -# The directory we'll use to store third-party sources, set this to something -# else if you don't want to re-fetch required libraries every time. -DEPSRC=os.path.join(WORKDIR, 'third-party') -DEPSRC=os.path.expanduser('~/Universal/other-sources') - -# Location of the preferred SDK -SDKPATH="/Developer/SDKs/MacOSX10.4u.sdk" -#SDKPATH="/" - -# Source directory (asume we're in Mac/OSX/Dist) -SRCDIR=os.path.dirname( - os.path.dirname( - os.path.dirname( - os.path.dirname( - os.path.abspath(__file__ - ))))) - -USAGE=textwrap.dedent("""\ - Usage: build_python [options] - - Options: - -? or -h: Show this message - -b DIR - --build-dir=DIR: Create build here (default: %(WORKDIR)r) - --third-party=DIR: Store third-party sources here (default: %(DEPSRC)r) - --sdk-path=DIR: Location of the SDK (default: %(SDKPATH)r) - --src-dir=DIR: Location of the Python sources (default: %(SRCDIR)r) -""")% globals() - - -# Instructions for building libraries that are necessary for building a -# batteries included python. -LIBRARY_RECIPES=[ - dict( - # Note that GNU readline is GPL'd software - name="GNU Readline 5.1.4", - url="http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz" , - patchlevel='0', - patches=[ - # The readline maintainers don't do actual micro releases, but - # just ship a set of patches. - 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-001', - 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-002', - 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-003', - 'http://ftp.gnu.org/pub/gnu/readline/readline-5.1-patches/readline51-004', - ] - ), - - dict( - name="SQLite 3.3.5", - url="http://www.sqlite.org/sqlite-3.3.5.tar.gz", - checksum='93f742986e8bc2dfa34792e16df017a6feccf3a2', - configure_pre=[ - '--enable-threadsafe', - '--enable-tempstore', - '--enable-shared=no', - '--enable-static=yes', - '--disable-tcl', - ] - ), - - dict( - name="NCurses 5.5", - url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz", - configure_pre=[ - "--without-cxx", - "--without-ada", - "--without-progs", - "--without-curses-h", - "--enable-shared", - "--with-shared", - "--datadir=/usr/share", - "--sysconfdir=/etc", - "--sharedstatedir=/usr/com", - "--with-terminfo-dirs=/usr/share/terminfo", - "--with-default-terminfo-dir=/usr/share/terminfo", - "--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib"%(getVersion(),), - "--enable-termcap", - ], - patches=[ - "ncurses-5.5.patch", - ], - useLDFlags=False, - install='make && make install DESTDIR=%s && cd %s/usr/local/lib && ln -fs ../../../Library/Frameworks/Python.framework/Versions/%s/lib/lib* .'%( - shellQuote(os.path.join(WORKDIR, 'libraries')), - shellQuote(os.path.join(WORKDIR, 'libraries')), - getVersion(), - ), - ), - dict( - name="Sleepycat DB 4.4", - url="http://downloads.sleepycat.com/db-4.4.20.tar.gz", - #name="Sleepycat DB 4.3.29", - #url="http://downloads.sleepycat.com/db-4.3.29.tar.gz", - buildDir="build_unix", - configure="../dist/configure", - configure_pre=[ - '--includedir=/usr/local/include/db4', - ] - ), -] - - -# Instructions for building packages inside the .mpkg. -PKG_RECIPES=[ - dict( - name="PythonFramework", - long_name="Python Framework", - source="/Library/Frameworks/Python.framework", - readme="""\ - This package installs Python.framework, that is the python - interpreter and the standard library. This also includes Python - wrappers for lots of Mac OS X API's. - """, - postflight="scripts/postflight.framework", - ), - dict( - name="PythonApplications", - long_name="GUI Applications", - source="/Applications/MacPython %(VER)s", - readme="""\ - This package installs Python.framework, that is the python - interpreter and the standard library. This also includes Python - wrappers for lots of Mac OS X API's. - """, - required=False, - ), - dict( - name="PythonUnixTools", - long_name="UNIX command-line tools", - source="/usr/local/bin", - readme="""\ - This package installs the unix tools in /usr/local/bin for - compatibility with older releases of MacPython. This package - is not necessary to use MacPython. - """, - required=False, - ), - dict( - name="PythonDocumentation", - long_name="Python Documentation", - topdir="/Library/Frameworks/Python.framework/Versions/%(VER)s/Resources/English.lproj/Documentation", - source="/pydocs", - readme="""\ - This package installs the python documentation at a location - that is useable for pydoc and IDLE. If you have installed Xcode - it will also install a link to the documentation in - /Developer/Documentation/Python - """, - postflight="scripts/postflight.documentation", - required=False, - ), - dict( - name="PythonProfileChanges", - long_name="Shell profile updater", - readme="""\ - This packages updates your shell profile to make sure that - the MacPython tools are found by your shell in preference of - the system provided Python tools. - - If you don't install this package you'll have to add - "/Library/Frameworks/Python.framework/Versions/%(VER)s/bin" - to your PATH by hand. - """, - postflight="scripts/postflight.patch-profile", - topdir="/Library/Frameworks/Python.framework", - source="/empty-dir", - required=False, - ), -] - - -def fatal(msg): - """ - A fatal error, bail out. - """ - sys.stderr.write('FATAL: ') - sys.stderr.write(msg) - sys.stderr.write('\n') - sys.exit(1) - -def fileContents(fn): - """ - Return the contents of the named file - """ - return open(fn, 'rb').read() - -def runCommand(commandline): - """ - Run a command and raise RuntimeError if it fails. Output is surpressed - unless the command fails. - """ - fd = os.popen(commandline, 'r') - data = fd.read() - xit = fd.close() - if xit != None: - sys.stdout.write(data) - raise RuntimeError, "command failed: %s"%(commandline,) - - if VERBOSE: - sys.stdout.write(data); sys.stdout.flush() - -def captureCommand(commandline): - fd = os.popen(commandline, 'r') - data = fd.read() - xit = fd.close() - if xit != None: - sys.stdout.write(data) - raise RuntimeError, "command failed: %s"%(commandline,) - - return data - -def checkEnvironment(): - """ - Check that we're running on a supported system. - """ - - if platform.system() != 'Darwin': - fatal("This script should be run on a Mac OS X 10.4 system") - - if platform.release() <= '8.': - fatal("This script should be run on a Mac OS X 10.4 system") - - if not os.path.exists(SDKPATH): - fatal("Please install the latest version of Xcode and the %s SDK"%( - os.path.basename(SDKPATH[:-4]))) - - - -def parseOptions(args = None): - """ - Parse arguments and update global settings. - """ - global WORKDIR, DEPSRC, SDKPATH, SRCDIR - - if args is None: - args = sys.argv[1:] - - try: - options, args = getopt.getopt(args, '?hb', - [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=']) - except getopt.error, msg: - print msg - sys.exit(1) - - if args: - print "Additional arguments" - sys.exit(1) - - for k, v in options: - if k in ('-h', '-?'): - print USAGE - sys.exit(0) - - elif k in ('-d', '--build-dir'): - WORKDIR=v - - elif k in ('--third-party',): - DEPSRC=v - - elif k in ('--sdk-path',): - SDKPATH=v - - elif k in ('--src-dir',): - SRCDIR=v - - else: - raise NotImplementedError, k - - SRCDIR=os.path.abspath(SRCDIR) - WORKDIR=os.path.abspath(WORKDIR) - SDKPATH=os.path.abspath(SDKPATH) - DEPSRC=os.path.abspath(DEPSRC) - - print "Settings:" - print " * Source directory:", SRCDIR - print " * Build directory: ", WORKDIR - print " * SDK location: ", SDKPATH - print " * third-party source:", DEPSRC - print "" - - - - -def extractArchive(builddir, archiveName): - """ - Extract a source archive into 'builddir'. Returns the path of the - extracted archive. - - XXX: This function assumes that archives contain a toplevel directory - that is has the same name as the basename of the archive. This is - save enough for anything we use. - """ - curdir = os.getcwd() - try: - os.chdir(builddir) - if archiveName.endswith('.tar.gz'): - retval = os.path.basename(archiveName[:-7]) - if os.path.exists(retval): - shutil.rmtree(retval) - fp = os.popen("tar zxf %s 2>&1"%(shellQuote(archiveName),), 'r') - - elif archiveName.endswith('.tar.bz2'): - retval = os.path.basename(archiveName[:-8]) - if os.path.exists(retval): - shutil.rmtree(retval) - fp = os.popen("tar jxf %s 2>&1"%(shellQuote(archiveName),), 'r') - - elif archiveName.endswith('.tar'): - retval = os.path.basename(archiveName[:-4]) - if os.path.exists(retval): - shutil.rmtree(retval) - fp = os.popen("tar xf %s 2>&1"%(shellQuote(archiveName),), 'r') - - elif archiveName.endswith('.zip'): - retval = os.path.basename(archiveName[:-4]) - if os.path.exists(retval): - shutil.rmtree(retval) - fp = os.popen("unzip %s 2>&1"%(shellQuote(archiveName),), 'r') - - data = fp.read() - xit = fp.close() - if xit is not None: - sys.stdout.write(data) - raise RuntimeError, "Cannot extract %s"%(archiveName,) - - return os.path.join(builddir, retval) - - finally: - os.chdir(curdir) - -KNOWNSIZES = { - "http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz": 7952742, - "http://downloads.sleepycat.com/db-4.4.20.tar.gz": 2030276, -} - -def downloadURL(url, fname): - """ - Download the contents of the url into the file. - """ - try: - size = os.path.getsize(fname) - except OSError: - pass - else: - if KNOWNSIZES.get(url) == size: - print "Using existing file for", url - return - fpIn = urllib2.urlopen(url) - fpOut = open(fname, 'wb') - block = fpIn.read(10240) - try: - while block: - fpOut.write(block) - block = fpIn.read(10240) - fpIn.close() - fpOut.close() - except: - try: - os.unlink(fname) - except: - pass - -def buildRecipe(recipe, basedir, archList): - """ - Build software using a recipe. This function does the - 'configure;make;make install' dance for C software, with a possibility - to customize this process, basically a poor-mans DarwinPorts. - """ - curdir = os.getcwd() - - name = recipe['name'] - url = recipe['url'] - configure = recipe.get('configure', './configure') - install = recipe.get('install', 'make && make install DESTDIR=%s'%( - shellQuote(basedir))) - - archiveName = os.path.split(url)[-1] - sourceArchive = os.path.join(DEPSRC, archiveName) - - if not os.path.exists(DEPSRC): - os.mkdir(DEPSRC) - - - if os.path.exists(sourceArchive): - print "Using local copy of %s"%(name,) - - else: - print "Downloading %s"%(name,) - downloadURL(url, sourceArchive) - print "Archive for %s stored as %s"%(name, sourceArchive) - - print "Extracting archive for %s"%(name,) - buildDir=os.path.join(WORKDIR, '_bld') - if not os.path.exists(buildDir): - os.mkdir(buildDir) - - workDir = extractArchive(buildDir, sourceArchive) - os.chdir(workDir) - if 'buildDir' in recipe: - os.chdir(recipe['buildDir']) - - - for fn in recipe.get('patches', ()): - if fn.startswith('http://'): - # Download the patch before applying it. - path = os.path.join(DEPSRC, os.path.basename(fn)) - downloadURL(fn, path) - fn = path - - fn = os.path.join(curdir, fn) - runCommand('patch -p%s < %s'%(recipe.get('patchlevel', 1), - shellQuote(fn),)) - - configure_args = [ - "--prefix=/usr/local", - "--enable-static", - "--disable-shared", - #"CPP=gcc -arch %s -E"%(' -arch '.join(archList,),), - ] - - if 'configure_pre' in recipe: - args = list(recipe['configure_pre']) - if '--disable-static' in args: - configure_args.remove('--enable-static') - if '--enable-shared' in args: - configure_args.remove('--disable-shared') - configure_args.extend(args) - - if recipe.get('useLDFlags', 1): - configure_args.extend([ - "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( - ' -arch '.join(archList), - shellQuote(SDKPATH)[1:-1], - shellQuote(basedir)[1:-1],), - "LDFLAGS=-syslibroot,%s -L%s/usr/local/lib -arch %s"%( - shellQuote(SDKPATH)[1:-1], - shellQuote(basedir)[1:-1], - ' -arch '.join(archList)), - ]) - else: - configure_args.extend([ - "CFLAGS=-arch %s -isysroot %s -I%s/usr/local/include"%( - ' -arch '.join(archList), - shellQuote(SDKPATH)[1:-1], - shellQuote(basedir)[1:-1],), - ]) - - if 'configure_post' in recipe: - configure_args = configure_args = list(recipe['configure_post']) - - configure_args.insert(0, configure) - configure_args = [ shellQuote(a) for a in configure_args ] - - print "Running configure for %s"%(name,) - runCommand(' '.join(configure_args) + ' 2>&1') - - print "Running install for %s"%(name,) - runCommand('{ ' + install + ' ;} 2>&1') - - print "Done %s"%(name,) - print "" - - os.chdir(curdir) - -def buildLibraries(): - """ - Build our dependencies into $WORKDIR/libraries/usr/local - """ - print "" - print "Building required libraries" - print "" - universal = os.path.join(WORKDIR, 'libraries') - os.mkdir(universal) - os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) - os.makedirs(os.path.join(universal, 'usr', 'local', 'include')) - - for recipe in LIBRARY_RECIPES: - buildRecipe(recipe, universal, ('i386', 'ppc',)) - - - -def buildPythonDocs(): - # This stores the documentation as Resources/English.lproj/Docuentation - # inside the framwork. pydoc and IDLE will pick it up there. - print "Install python documentation" - rootDir = os.path.join(WORKDIR, '_root') - version = getVersion() - docdir = os.path.join(rootDir, 'pydocs') - - name = 'html-%s.tar.bz2'%(getFullVersion(),) - sourceArchive = os.path.join(DEPSRC, name) - if os.path.exists(sourceArchive): - print "Using local copy of %s"%(name,) - - else: - print "Downloading %s"%(name,) - downloadURL('http://www.python.org/ftp/python/doc/%s/%s'%( - getFullVersion(), name), sourceArchive) - print "Archive for %s stored as %s"%(name, sourceArchive) - - extractArchive(os.path.dirname(docdir), sourceArchive) - os.rename( - os.path.join( - os.path.dirname(docdir), 'Python-Docs-%s'%(getFullVersion(),)), - docdir) - - -def buildPython(): - print "Building a universal python" - - buildDir = os.path.join(WORKDIR, '_bld', 'python') - rootDir = os.path.join(WORKDIR, '_root') - - if os.path.exists(buildDir): - shutil.rmtree(buildDir) - if os.path.exists(rootDir): - shutil.rmtree(rootDir) - os.mkdir(buildDir) - os.mkdir(rootDir) - os.mkdir(os.path.join(rootDir, 'empty-dir')) - curdir = os.getcwd() - os.chdir(buildDir) - - # Not sure if this is still needed, the original build script - # claims that parts of the install assume python.exe exists. - os.symlink('python', os.path.join(buildDir, 'python.exe')) - - # Extract the version from the configure file, needed to calculate - # several paths. - version = getVersion() - - print "Running configure..." - runCommand("%s -C --enable-framework --enable-universalsdk=%s LDFLAGS='-g -L%s/libraries/usr/local/lib' OPT='-g -O3 -I%s/libraries/usr/local/include' 2>&1"%( - shellQuote(os.path.join(SRCDIR, 'configure')), - shellQuote(SDKPATH), shellQuote(WORKDIR)[1:-1], - shellQuote(WORKDIR)[1:-1])) - - print "Running make" - runCommand("make") - - print "Runing make frameworkinstall" - runCommand("make frameworkinstall DESTDIR=%s"%( - shellQuote(rootDir))) - - print "Runing make frameworkinstallextras" - runCommand("make frameworkinstallextras DESTDIR=%s"%( - shellQuote(rootDir))) - - print "Copy required shared libraries" - if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): - runCommand("mv %s/* %s"%( - shellQuote(os.path.join( - WORKDIR, 'libraries', 'Library', 'Frameworks', - 'Python.framework', 'Versions', getVersion(), - 'lib')), - shellQuote(os.path.join(WORKDIR, '_root', 'Library', 'Frameworks', - 'Python.framework', 'Versions', getVersion(), - 'lib')))) - - print "Fix file modes" - frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') - for dirpath, dirnames, filenames in os.walk(frmDir): - for dn in dirnames: - os.chmod(os.path.join(dirpath, dn), 0775) - - for fn in filenames: - if os.path.islink(fn): - continue - - # "chmod g+w $fn" - p = os.path.join(dirpath, fn) - st = os.stat(p) - os.chmod(p, stat.S_IMODE(st.st_mode) | stat.S_IXGRP) - - # We added some directories to the search path during the configure - # phase. Remove those because those directories won't be there on - # the end-users system. - path =os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework', - 'Versions', version, 'lib', 'python%s'%(version,), - 'config', 'Makefile') - fp = open(path, 'r') - data = fp.read() - fp.close() - - data = data.replace('-L%s/libraries/usr/local/lib'%(WORKDIR,), '') - data = data.replace('-I%s/libraries/usr/local/include'%(WORKDIR,), '') - fp = open(path, 'w') - fp.write(data) - fp.close() - - # Add symlinks in /usr/local/bin, using relative links - usr_local_bin = os.path.join(rootDir, 'usr', 'local', 'bin') - to_framework = os.path.join('..', '..', '..', 'Library', 'Frameworks', - 'Python.framework', 'Versions', version, 'bin') - if os.path.exists(usr_local_bin): - shutil.rmtree(usr_local_bin) - os.makedirs(usr_local_bin) - for fn in os.listdir( - os.path.join(frmDir, 'Versions', version, 'bin')): - os.symlink(os.path.join(to_framework, fn), - os.path.join(usr_local_bin, fn)) - - os.chdir(curdir) - - - -def patchFile(inPath, outPath): - data = fileContents(inPath) - data = data.replace('$FULL_VERSION', getFullVersion()) - data = data.replace('$VERSION', getVersion()) - data = data.replace('$MACOSX_DEPLOYMENT_TARGET', '10.3 or later') - data = data.replace('$ARCHITECTURES', "i386, ppc") - data = data.replace('$INSTALL_SIZE', installSize()) - fp = open(outPath, 'wb') - fp.write(data) - fp.close() - -def patchScript(inPath, outPath): - data = fileContents(inPath) - data = data.replace('@PYVER@', getVersion()) - fp = open(outPath, 'wb') - fp.write(data) - fp.close() - os.chmod(outPath, 0755) - - - -def packageFromRecipe(targetDir, recipe): - curdir = os.getcwd() - try: - pkgname = recipe['name'] - srcdir = recipe.get('source') - pkgroot = recipe.get('topdir', srcdir) - postflight = recipe.get('postflight') - readme = textwrap.dedent(recipe['readme']) - isRequired = recipe.get('required', True) - - print "- building package %s"%(pkgname,) - - # Substitute some variables - textvars = dict( - VER=getVersion(), - FULLVER=getFullVersion(), - ) - readme = readme % textvars - - if pkgroot is not None: - pkgroot = pkgroot % textvars - else: - pkgroot = '/' - - if srcdir is not None: - srcdir = os.path.join(WORKDIR, '_root', srcdir[1:]) - srcdir = srcdir % textvars - - if postflight is not None: - postflight = os.path.abspath(postflight) - - packageContents = os.path.join(targetDir, pkgname + '.pkg', 'Contents') - os.makedirs(packageContents) - - if srcdir is not None: - os.chdir(srcdir) - runCommand("pax -wf %s . 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) - runCommand("gzip -9 %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.pax')),)) - runCommand("mkbom . %s 2>&1"%(shellQuote(os.path.join(packageContents, 'Archive.bom')),)) - - fn = os.path.join(packageContents, 'PkgInfo') - fp = open(fn, 'w') - fp.write('pmkrpkg1') - fp.close() - - rsrcDir = os.path.join(packageContents, "Resources") - os.mkdir(rsrcDir) - fp = open(os.path.join(rsrcDir, 'ReadMe.txt'), 'w') - fp.write(readme) - fp.close() - - if postflight is not None: - patchScript(postflight, os.path.join(rsrcDir, 'postflight')) - - vers = getFullVersion() - major, minor = map(int, getVersion().split('.', 2)) - pl = Plist( - CFBundleGetInfoString="MacPython.%s %s"%(pkgname, vers,), - CFBundleIdentifier='org.python.MacPython.%s'%(pkgname,), - CFBundleName='MacPython.%s'%(pkgname,), - CFBundleShortVersionString=vers, - IFMajorVersion=major, - IFMinorVersion=minor, - IFPkgFormatVersion=0.10000000149011612, - IFPkgFlagAllowBackRev=False, - IFPkgFlagAuthorizationAction="RootAuthorization", - IFPkgFlagDefaultLocation=pkgroot, - IFPkgFlagFollowLinks=True, - IFPkgFlagInstallFat=True, - IFPkgFlagIsRequired=isRequired, - IFPkgFlagOverwritePermissions=False, - IFPkgFlagRelocatable=False, - IFPkgFlagRestartAction="NoRestart", - IFPkgFlagRootVolumeOnly=True, - IFPkgFlagUpdateInstalledLangauges=False, - ) - writePlist(pl, os.path.join(packageContents, 'Info.plist')) - - pl = Plist( - IFPkgDescriptionDescription=readme, - IFPkgDescriptionTitle=recipe.get('long_name', "MacPython.%s"%(pkgname,)), - IFPkgDescriptionVersion=vers, - ) - writePlist(pl, os.path.join(packageContents, 'Resources', 'Description.plist')) - - finally: - os.chdir(curdir) - - -def makeMpkgPlist(path): - - vers = getFullVersion() - major, minor = map(int, getVersion().split('.', 2)) - - pl = Plist( - CFBundleGetInfoString="MacPython %s"%(vers,), - CFBundleIdentifier='org.python.MacPython', - CFBundleName='MacPython', - CFBundleShortVersionString=vers, - IFMajorVersion=major, - IFMinorVersion=minor, - IFPkgFlagComponentDirectory="Contents/Packages", - IFPkgFlagPackageList=[ - dict( - IFPkgFlagPackageLocation='%s.pkg'%(item['name']), - IFPkgFlagPackageSelection='selected' - ) - for item in PKG_RECIPES - ], - IFPkgFormatVersion=0.10000000149011612, - IFPkgFlagBackgroundScaling="proportional", - IFPkgFlagBackgroundAlignment="left", - ) - - writePlist(pl, path) - - -def buildInstaller(): - - # Zap all compiled files - for dirpath, _, filenames in os.walk(os.path.join(WORKDIR, '_root')): - for fn in filenames: - if fn.endswith('.pyc') or fn.endswith('.pyo'): - os.unlink(os.path.join(dirpath, fn)) - - outdir = os.path.join(WORKDIR, 'installer') - if os.path.exists(outdir): - shutil.rmtree(outdir) - os.mkdir(outdir) - - pkgroot = os.path.join(outdir, 'MacPython.mpkg', 'Contents') - pkgcontents = os.path.join(pkgroot, 'Packages') - os.makedirs(pkgcontents) - for recipe in PKG_RECIPES: - packageFromRecipe(pkgcontents, recipe) - - rsrcDir = os.path.join(pkgroot, 'Resources') - - fn = os.path.join(pkgroot, 'PkgInfo') - fp = open(fn, 'w') - fp.write('pmkrpkg1') - fp.close() - - os.mkdir(rsrcDir) - - makeMpkgPlist(os.path.join(pkgroot, 'Info.plist')) - pl = Plist( - IFPkgDescriptionTitle="Universal MacPython", - IFPkgDescriptionVersion=getVersion(), - ) - - writePlist(pl, os.path.join(pkgroot, 'Resources', 'Description.plist')) - for fn in os.listdir('resources'): - if fn == '.svn': continue - if fn.endswith('.jpg'): - shutil.copy(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) - else: - patchFile(os.path.join('resources', fn), os.path.join(rsrcDir, fn)) - - shutil.copy("../../../LICENSE", os.path.join(rsrcDir, 'License.txt')) - - -def installSize(clear=False, _saved=[]): - if clear: - del _saved[:] - if not _saved: - data = captureCommand("du -ks %s"%( - shellQuote(os.path.join(WORKDIR, '_root')))) - _saved.append("%d"%((0.5 + (int(data.split()[0]) / 1024.0)),)) - return _saved[0] - - -def buildDMG(): - """ - Create DMG containing the rootDir - """ - outdir = os.path.join(WORKDIR, 'diskimage') - if os.path.exists(outdir): - shutil.rmtree(outdir) - - imagepath = os.path.join(outdir, - 'python-%s-macosx'%(getFullVersion(),)) - if INCLUDE_TIMESTAMP: - imagepath = imagepath + '%04d-%02d-%02d'%(time.localtime()[:3]) - imagepath = imagepath + '.dmg' - - os.mkdir(outdir) - runCommand("hdiutil create -volname 'Univeral MacPython %s' -srcfolder %s %s"%( - getFullVersion(), - shellQuote(os.path.join(WORKDIR, 'installer')), - shellQuote(imagepath))) - - return imagepath - - -def setIcon(filePath, icnsPath): - """ - Set the custom icon for the specified file or directory. - - For a directory the icon data is written in a file named 'Icon\r' inside - the directory. For both files and directories write the icon as an 'icns' - resource. Furthermore set kHasCustomIcon in the finder flags for filePath. - """ - ref, isDirectory = Carbon.File.FSPathMakeRef(icnsPath) - icon = Carbon.Icn.ReadIconFile(ref) - del ref - - # - # Open the resource fork of the target, to add the icon later on. - # For directories we use the file 'Icon\r' inside the directory. - # - - ref, isDirectory = Carbon.File.FSPathMakeRef(filePath) - - if isDirectory: - tmpPath = os.path.join(filePath, "Icon\r") - if not os.path.exists(tmpPath): - fp = open(tmpPath, 'w') - fp.close() - - tmpRef, _ = Carbon.File.FSPathMakeRef(tmpPath) - spec = Carbon.File.FSSpec(tmpRef) - - else: - spec = Carbon.File.FSSpec(ref) - - try: - Carbon.Res.HCreateResFile(*spec.as_tuple()) - except MacOS.Error: - pass - - # Try to create the resource fork again, this will avoid problems - # when adding an icon to a directory. I have no idea why this helps, - # but without this adding the icon to a directory will fail sometimes. - try: - Carbon.Res.HCreateResFile(*spec.as_tuple()) - except MacOS.Error: - pass - - refNum = Carbon.Res.FSpOpenResFile(spec, fsRdWrPerm) - - Carbon.Res.UseResFile(refNum) - - # Check if there already is an icon, remove it if there is. - try: - h = Carbon.Res.Get1Resource('icns', kCustomIconResource) - except MacOS.Error: - pass - - else: - h.RemoveResource() - del h - - # Add the icon to the resource for of the target - res = Carbon.Res.Resource(icon) - res.AddResource('icns', kCustomIconResource, '') - res.WriteResource() - res.DetachResource() - Carbon.Res.CloseResFile(refNum) - - # And now set the kHasCustomIcon property for the target. Annoyingly, - # python doesn't seem to have bindings for the API that is needed for - # this. Cop out and call SetFile - os.system("/Developer/Tools/SetFile -a C %s"%( - shellQuote(filePath),)) - - if isDirectory: - os.system('/Developer/Tools/SetFile -a V %s'%( - shellQuote(tmpPath), - )) - -def main(): - # First parse options and check if we can perform our work - parseOptions() - checkEnvironment() - - os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3' - - if os.path.exists(WORKDIR): - shutil.rmtree(WORKDIR) - os.mkdir(WORKDIR) - - # Then build third-party libraries such as sleepycat DB4. - buildLibraries() - - # Now build python itself - buildPython() - buildPythonDocs() - fn = os.path.join(WORKDIR, "_root", "Applications", - "MacPython %s"%(getVersion(),), "Update Shell Profile.command") - shutil.copy("scripts/postflight.patch-profile", fn) - os.chmod(fn, 0755) - - folder = os.path.join(WORKDIR, "_root", "Applications", "MacPython %s"%( - getVersion(),)) - os.chmod(folder, 0755) - setIcon(folder, "../Icons/Python Folder.icns") - - # Create the installer - buildInstaller() - - # And copy the readme into the directory containing the installer - patchFile('resources/ReadMe.txt', os.path.join(WORKDIR, 'installer', 'ReadMe.txt')) - - # Ditto for the license file. - shutil.copy('../../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) - - fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') - print >> fp, "# BUILD INFO" - print >> fp, "# Date:", time.ctime() - print >> fp, "# By:", pwd.getpwuid(os.getuid()).pw_gecos - fp.close() - - # Custom icon for the DMG, shown when the DMG is mounted. - shutil.copy("../Icons/Disk Image.icns", - os.path.join(WORKDIR, "installer", ".VolumeIcon.icns")) - os.system("/Developer/Tools/SetFile -a C %s"%( - os.path.join(WORKDIR, "installer", ".VolumeIcon.icns"))) - - - # And copy it to a DMG - buildDMG() - - -if __name__ == "__main__": - main() diff --git a/Mac/OSX/BuildScript/ncurses-5.5.patch b/Mac/OSX/BuildScript/ncurses-5.5.patch deleted file mode 100644 index 0eab3d3..0000000 --- a/Mac/OSX/BuildScript/ncurses-5.5.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff -r -u ncurses-5.5-orig/test/Makefile.in ncurses-5.5/test/Makefile.in ---- ncurses-5.5-orig/test/Makefile.in 2006-03-24 12:47:40.000000000 +0100 -+++ ncurses-5.5/test/Makefile.in 2006-03-24 12:47:50.000000000 +0100 -@@ -75,7 +75,7 @@ - MATH_LIB = @MATH_LIB@ - - LD = @LD@ --LINK = @LINK_TESTS@ $(LIBTOOL_LINK) $(CC) $(CFLAGS) -+LINK = @LINK_TESTS@ $(LIBTOOL_LINK) $(CC) - - usFLAGS = @LD_MODEL@ @LOCAL_LDFLAGS@ @LDFLAGS@ - -diff -ru ncurses-5.5-orig/ncurses/tinfo/read_entry.c ncurses-5.5/ncurses/tinfo/read_entry.c ---- ncurses-5.5-orig/ncurses/tinfo/read_entry.c 2004-01-11 02:57:05.000000000 +0100 -+++ ncurses-5.5/ncurses/tinfo/read_entry.c 2006-03-25 22:49:39.000000000 +0100 -@@ -474,7 +474,7 @@ - } - - /* truncate the terminal name to prevent buffer overflow */ -- (void) sprintf(ttn, "%c/%.*s", *tn, (int) sizeof(ttn) - 3, tn); -+ (void) sprintf(ttn, "%x/%.*s", *tn, (int) sizeof(ttn) - 3, tn); - - /* This is System V behavior, in conjunction with our requirements for - * writing terminfo entries. -diff -ru ncurses-5.5-orig/configure ncurses-5.5/configure ---- ncurses-5.5-orig/configure 2005-09-24 23:50:50.000000000 +0200 -+++ ncurses-5.5/configure 2006-03-26 22:24:59.000000000 +0200 -@@ -5027,7 +5027,7 @@ - darwin*) - EXTRA_CFLAGS="-no-cpp-precomp" - CC_SHARED_OPTS="-dynamic" -- MK_SHARED_LIB='$(CC) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@' -+ MK_SHARED_LIB='$(CC) $(CFLAGS) -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@' - test "$cf_cv_shlib_version" = auto && cf_cv_shlib_version=abi - cf_cv_shlib_version_infix=yes - ;; diff --git a/Mac/OSX/BuildScript/resources/ReadMe.txt b/Mac/OSX/BuildScript/resources/ReadMe.txt deleted file mode 100644 index 1a6e637..0000000 --- a/Mac/OSX/BuildScript/resources/ReadMe.txt +++ /dev/null @@ -1,31 +0,0 @@ -This package will install MacPython $FULL_VERSION for Mac OS X -$MACOSX_DEPLOYMENT_TARGET for the following -architecture(s): $ARCHITECTURES. - -Separate installers are available for older versions -of Mac OS X, see the homepage, below. - -Installation requires approximately $INSTALL_SIZE MB of disk -space, ignore the message that it will take zero bytes. - -You must install onto your current boot disk, even -though the installer does not enforce this, otherwise -things will not work. - -MacPython consists of the Python programming language -interpreter, plus a set of programs to allow easy -access to it for Mac users (an integrated development -environment, an applet builder), plus a set of pre-built -extension modules that open up specific Macintosh technologies -to Python programs (Carbon, AppleScript, Quicktime, more). - -The installer puts the applications in "MacPython $VERSION" -in your Applications folder, command-line tools in -/usr/local/bin and the underlying machinery in -$PYTHONFRAMEWORKINSTALLDIR. - -More information on MacPython can be found at -http://www.cwi.nl/~jack/macpython and -http://pythonmac.org/. More information on -Python in general can be found at -http://www.python.org. diff --git a/Mac/OSX/BuildScript/resources/Welcome.rtf b/Mac/OSX/BuildScript/resources/Welcome.rtf deleted file mode 100644 index cb65f09..0000000 --- a/Mac/OSX/BuildScript/resources/Welcome.rtf +++ /dev/null @@ -1,15 +0,0 @@ -{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf330 -{\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} -{\colortbl;\red255\green255\blue255;} -\paperw11900\paperh16840\margl1440\margr1440\vieww9920\viewh10660\viewkind0 -\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural - -\f0\fs24 \cf0 This package will install -\f1\b MacPython $FULL_VERSION -\f0\b0 for -\f1\b Mac OS X $MACOSX_DEPLOYMENT_TARGET -\f0\b0 .\ -\ -MacPython consists of the Python programming language interpreter, plus a set of programs to allow easy access to it for Mac users (an integrated development environment, an applet builder), plus a set of pre-built extension modules that open up specific Macintosh technologies to Python programs (Carbon, AppleScript, Quicktime, more).\ -\ -See the ReadMe file for more information.} \ No newline at end of file diff --git a/Mac/OSX/BuildScript/resources/background.jpg b/Mac/OSX/BuildScript/resources/background.jpg deleted file mode 100644 index b3c7640..0000000 Binary files a/Mac/OSX/BuildScript/resources/background.jpg and /dev/null differ diff --git a/Mac/OSX/BuildScript/scripts/postflight.documentation b/Mac/OSX/BuildScript/scripts/postflight.documentation deleted file mode 100755 index 85d400f..0000000 --- a/Mac/OSX/BuildScript/scripts/postflight.documentation +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# FIXME -PYVER="@PYVER@" - -if [ -d /Developer/Documentation ]; then - if [ ! -d /Developer/Documentation/Python ]; then - mkdir -p /Developer/Documentation/Python - fi - - ln -fhs /Library/Frameworks/Python.framework/Versions/${PYVER}/Resources/English.lproj/Documentation "/Developer/Documentation/Python/Reference Documentation" -fi diff --git a/Mac/OSX/BuildScript/scripts/postflight.framework b/Mac/OSX/BuildScript/scripts/postflight.framework deleted file mode 100755 index 532e745..0000000 --- a/Mac/OSX/BuildScript/scripts/postflight.framework +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# -# Recompile the .py files. -# - -PYVER="@PYVER@" -FWK="/Library/Frameworks/Python.framework/Versions/@PYVER@/" - -"${FWK}/bin/python" -Wi -tt \ - "${FWK}/lib/python${PYVER}/compileall.py" \ - -x badsyntax -x site-packages \ - "${FWK}/lib/python${PYVER}" - -"${FWK}/bin/python" -Wi -tt -O \ - "${FWK}/lib/python${PYVER}/compileall.py" \ - -x badsyntax -x site-packages \ - "${FWK}/lib/python${PYVER}" - -"${FWK}/bin/python" -Wi -tt \ - "${FWK}/lib/python${PYVER}/compileall.py" \ - -x badsyntax -x site-packages \ - "${FWK}/Mac/Tools" - -"${FWK}/bin/python" -Wi -tt -O \ - "${FWK}/lib/python${PYVER}/compileall.py" \ - -x badsyntax -x site-packages \ - "${FWK}/Mac/Tools" - - -chown -R admin "${FWK}" -chmod -R g+w "${FWK}" - -exit 0 diff --git a/Mac/OSX/BuildScript/scripts/postflight.patch-profile b/Mac/OSX/BuildScript/scripts/postflight.patch-profile deleted file mode 100755 index 48bf701..0000000 --- a/Mac/OSX/BuildScript/scripts/postflight.patch-profile +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/sh - -echo "This script will update your shell profile when the 'bin' directory" -echo "of python is not early enough of the PATH of your shell." -echo "These changes will be effective only in shell windows that you open" -echo "after running this script." - -PYVER=@PYVER@ -PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/Current" - -# Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH. -BSH="`basename "${SHELL}"`" -case "${BSH}" in -bash|ksh|sh|*csh) - P="`${SHELL} -c 'echo $PATH'`" - ;; -*) - echo "Sorry, I don't know how to patch $BSH shells" - exit 0 - ;; -esac - -# Now ensure that our bin directory is on $P and before /usr/bin at that -for elem in `echo $P | tr ':' ' '` -do - if [ "${elem}" == "${PYTHON_ROOT}/bin" ]; then - echo "All right, you're a python lover already" - exit 0 - elif [ "${elem}" == "/usr/bin" ]; then - break - fi -done - -echo "${PYTHON_ROOT}/bin is not on your PATH or at least not early enough" -case "${BSH}" in -*csh) - # Create backup copy before patching - if [ -f "${HOME}/.cshrc" ]; then - cp -fp "${HOME}/.cshrc" "${HOME}/.cshrc.pysave" - fi - echo "" >> "${HOME}/.cshrc" - echo "# Setting PATH for MacPython ${PYVER}" >> "${HOME}/.cshrc" - echo "# The orginal version is saved in .cshrc.pysave" >> "${HOME}/.cshrc" - echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${HOME}/.cshrc" - exit 0 - ;; -bash) - if [ -e "${HOME}/.profile" ]; then - PR="${HOME}/.profile" - else - PR="${HOME}/.bash_profile" - fi - ;; -*sh) - PR="${HOME}/.profile" - ;; -esac - -# Create backup copy before patching -if [ -f "${PR}" ]; then - cp -fp "${PR}" "${PR}.pysave" -fi -echo "" >> "${PR}" -echo "# Setting PATH for MacPython ${PYVER}" >> "${PR}" -echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}" -echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}" -echo 'export PATH' >> "${PR}" -if [ `id -ur` = 0 ]; then - chown "${LOGNAME}" "${PR}" -fi -exit 0 diff --git a/Mac/OSX/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py b/Mac/OSX/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py deleted file mode 100644 index 58d7307..0000000 --- a/Mac/OSX/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py +++ /dev/null @@ -1,110 +0,0 @@ -"""Suite Help Indexing Tool Suite: Special events that just the Help Indexing Tool supports. -Level 0, version 0 - -Generated from /Developer/Applications/Apple Help Indexing Tool.app -AETE/AEUT resource version 1/1, language 0, script 0 -""" - -import aetools -import MacOS - -_code = 'HIT ' - -class Help_Indexing_Tool_Suite_Events: - - def turn_anchor_indexing(self, _object, _attributes={}, **_arguments): - """turn anchor indexing: Turns anchor indexing on or off. - Required argument: \xd2on\xd3 or \xd2off\xd3, to turn anchor indexing on or off - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'HIT ' - _subcode = 'tAnc' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - _argmap_turn_remote_root = { - 'with_root_url' : 'rURL', - } - - def turn_remote_root(self, _object, _attributes={}, **_arguments): - """turn remote root: Turn usage of remote root for content on the web on or off. If turning \xd2on\xd3, supply a string as second parameter. - Required argument: \xd2on\xd3 or \xd2off\xd3, to turn remote root on or off - Keyword argument with_root_url: The remote root to use, in the form of \xd2http://www.apple.com/help/\xd3. - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'HIT ' - _subcode = 'tRem' - - aetools.keysubst(_arguments, self._argmap_turn_remote_root) - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - def use_tokenizer(self, _object, _attributes={}, **_arguments): - """use tokenizer: Tells the indexing tool which tokenizer to use. - Required argument: Specify \xd2English\xd3, \xd2European\xd3, \xd2Japanese\xd3, \xd2Korean\xd3, or \xd2Simple\xd3. - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'HIT ' - _subcode = 'uTok' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - -class application(aetools.ComponentItem): - """application - Application class """ - want = 'capp' -class _Prop_idleStatus(aetools.NProperty): - """idleStatus - """ - which = 'sIdl' - want = 'bool' -application._superclassnames = [] -application._privpropdict = { - 'idleStatus' : _Prop_idleStatus, -} -application._privelemdict = { -} - -# -# Indices of types declared in this module -# -_classdeclarations = { - 'capp' : application, -} - -_propdeclarations = { - 'sIdl' : _Prop_idleStatus, -} - -_compdeclarations = { -} - -_enumdeclarations = { -} diff --git a/Mac/OSX/Doc/HelpIndexingTool/Miscellaneous_Standards.py b/Mac/OSX/Doc/HelpIndexingTool/Miscellaneous_Standards.py deleted file mode 100644 index 3cf745f..0000000 --- a/Mac/OSX/Doc/HelpIndexingTool/Miscellaneous_Standards.py +++ /dev/null @@ -1,49 +0,0 @@ -"""Suite Miscellaneous Standards: Useful events that aren\xd5t in any other suite -Level 0, version 0 - -Generated from /Developer/Applications/Apple Help Indexing Tool.app -AETE/AEUT resource version 1/1, language 0, script 0 -""" - -import aetools -import MacOS - -_code = 'misc' - -class Miscellaneous_Standards_Events: - - def revert(self, _object, _attributes={}, **_arguments): - """revert: Revert an object to the most recently saved version - Required argument: object to revert - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'misc' - _subcode = 'rvrt' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - -# -# Indices of types declared in this module -# -_classdeclarations = { -} - -_propdeclarations = { -} - -_compdeclarations = { -} - -_enumdeclarations = { -} diff --git a/Mac/OSX/Doc/HelpIndexingTool/Required_Suite.py b/Mac/OSX/Doc/HelpIndexingTool/Required_Suite.py deleted file mode 100644 index eb9fee0..0000000 --- a/Mac/OSX/Doc/HelpIndexingTool/Required_Suite.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Suite Required Suite: Terms that every application should support -Level 1, version 1 - -Generated from /Developer/Applications/Apple Help Indexing Tool.app -AETE/AEUT resource version 1/1, language 0, script 0 -""" - -import aetools -import MacOS - -_code = 'reqd' - -from StdSuites.Required_Suite import * -class Required_Suite_Events(Required_Suite_Events): - - pass - - -# -# Indices of types declared in this module -# -_classdeclarations = { -} - -_propdeclarations = { -} - -_compdeclarations = { -} - -_enumdeclarations = { -} diff --git a/Mac/OSX/Doc/HelpIndexingTool/Standard_Suite.py b/Mac/OSX/Doc/HelpIndexingTool/Standard_Suite.py deleted file mode 100644 index 4f6604c..0000000 --- a/Mac/OSX/Doc/HelpIndexingTool/Standard_Suite.py +++ /dev/null @@ -1,343 +0,0 @@ -"""Suite Standard Suite: Common terms for most applications -Level 1, version 1 - -Generated from /Developer/Applications/Apple Help Indexing Tool.app -AETE/AEUT resource version 1/1, language 0, script 0 -""" - -import aetools -import MacOS - -_code = 'CoRe' - -from StdSuites.Standard_Suite import * -class Standard_Suite_Events(Standard_Suite_Events): - - _argmap_close = { - 'saving' : 'savo', - 'in_' : 'kfil', - } - - def close(self, _object, _attributes={}, **_arguments): - """close: Close an object - Required argument: the objects to close - Keyword argument saving: specifies whether or not changes should be saved before closing - Keyword argument in_: the file in which to save the object - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'core' - _subcode = 'clos' - - aetools.keysubst(_arguments, self._argmap_close) - _arguments['----'] = _object - - aetools.enumsubst(_arguments, 'savo', _Enum_savo) - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - def data_size(self, _object, _attributes={}, **_arguments): - """data size: Return the size in bytes of an object - Required argument: the object whose data size is to be returned - Keyword argument _attributes: AppleEvent attribute dictionary - Returns: the size of the object in bytes - """ - _code = 'core' - _subcode = 'dsiz' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - def get(self, _object, _attributes={}, **_arguments): - """get: Get the data for an object - Required argument: the object whose data is to be returned - Keyword argument _attributes: AppleEvent attribute dictionary - Returns: The data from the object - """ - _code = 'core' - _subcode = 'getd' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - _argmap_make = { - 'new' : 'kocl', - 'at' : 'insh', - 'with_data' : 'data', - 'with_properties' : 'prdt', - } - - def make(self, _no_object=None, _attributes={}, **_arguments): - """make: Make a new element - Keyword argument new: the class of the new element - Keyword argument at: the location at which to insert the element - Keyword argument with_data: the initial data for the element - Keyword argument with_properties: the initial values for the properties of the element - Keyword argument _attributes: AppleEvent attribute dictionary - Returns: Object specifier for the new element - """ - _code = 'core' - _subcode = 'crel' - - aetools.keysubst(_arguments, self._argmap_make) - if _no_object != None: raise TypeError, 'No direct arg expected' - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - def open(self, _object, _attributes={}, **_arguments): - """open: Open the specified object(s) - Required argument: Objects to open. Can be a list of files or an object specifier. - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'aevt' - _subcode = 'odoc' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - def print_(self, _object, _attributes={}, **_arguments): - """print: Print the specified object(s) - Required argument: Objects to print. Can be a list of files or an object specifier. - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'aevt' - _subcode = 'pdoc' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - _argmap_save = { - 'in_' : 'kfil', - 'as' : 'fltp', - } - - def save(self, _object, _attributes={}, **_arguments): - """save: save a set of objects - Required argument: Objects to save. - Keyword argument in_: the file in which to save the object(s) - Keyword argument as: the file type of the document in which to save the data - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'core' - _subcode = 'save' - - aetools.keysubst(_arguments, self._argmap_save) - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - _argmap_set = { - 'to' : 'data', - } - - def set(self, _object, _attributes={}, **_arguments): - """set: Set an object\xd5s data - Required argument: the object to change - Keyword argument to: the new value - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'core' - _subcode = 'setd' - - aetools.keysubst(_arguments, self._argmap_set) - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - -class application(aetools.ComponentItem): - """application - An application program """ - want = 'capp' -# element 'cwin' as ['indx', 'name', 'rele'] -# element 'docu' as ['name'] - -class window(aetools.ComponentItem): - """window - A Window """ - want = 'cwin' -class _Prop_bounds(aetools.NProperty): - """bounds - the boundary rectangle for the window """ - which = 'pbnd' - want = 'qdrt' -class _Prop_closeable(aetools.NProperty): - """closeable - Does the window have a close box? """ - which = 'hclb' - want = 'bool' -class _Prop_floating(aetools.NProperty): - """floating - Does the window float? """ - which = 'isfl' - want = 'bool' -class _Prop_index(aetools.NProperty): - """index - the number of the window """ - which = 'pidx' - want = 'long' -class _Prop_modal(aetools.NProperty): - """modal - Is the window modal? """ - which = 'pmod' - want = 'bool' -class _Prop_name(aetools.NProperty): - """name - the title of the window """ - which = 'pnam' - want = 'itxt' -class _Prop_position(aetools.NProperty): - """position - upper left coordinates of window """ - which = 'ppos' - want = 'QDpt' -class _Prop_resizable(aetools.NProperty): - """resizable - Is the window resizable? """ - which = 'prsz' - want = 'bool' -class _Prop_titled(aetools.NProperty): - """titled - Does the window have a title bar? """ - which = 'ptit' - want = 'bool' -class _Prop_visible(aetools.NProperty): - """visible - is the window visible? """ - which = 'pvis' - want = 'bool' -class _Prop_zoomable(aetools.NProperty): - """zoomable - Is the window zoomable? """ - which = 'iszm' - want = 'bool' -class _Prop_zoomed(aetools.NProperty): - """zoomed - Is the window zoomed? """ - which = 'pzum' - want = 'bool' - -class document(aetools.ComponentItem): - """document - A Document """ - want = 'docu' -class _Prop_modified(aetools.NProperty): - """modified - Has the document been modified since the last save? """ - which = 'imod' - want = 'bool' -application._superclassnames = [] -application._privpropdict = { -} -application._privelemdict = { - 'document' : document, - 'window' : window, -} -window._superclassnames = [] -window._privpropdict = { - 'bounds' : _Prop_bounds, - 'closeable' : _Prop_closeable, - 'floating' : _Prop_floating, - 'index' : _Prop_index, - 'modal' : _Prop_modal, - 'name' : _Prop_name, - 'position' : _Prop_position, - 'resizable' : _Prop_resizable, - 'titled' : _Prop_titled, - 'visible' : _Prop_visible, - 'zoomable' : _Prop_zoomable, - 'zoomed' : _Prop_zoomed, -} -window._privelemdict = { -} -document._superclassnames = [] -document._privpropdict = { - 'modified' : _Prop_modified, - 'name' : _Prop_name, -} -document._privelemdict = { -} -_Enum_savo = { - 'yes' : 'yes ', # Save objects now - 'no' : 'no ', # Do not save objects - 'ask' : 'ask ', # Ask the user whether to save -} - - -# -# Indices of types declared in this module -# -_classdeclarations = { - 'capp' : application, - 'cwin' : window, - 'docu' : document, -} - -_propdeclarations = { - 'hclb' : _Prop_closeable, - 'imod' : _Prop_modified, - 'isfl' : _Prop_floating, - 'iszm' : _Prop_zoomable, - 'pbnd' : _Prop_bounds, - 'pidx' : _Prop_index, - 'pmod' : _Prop_modal, - 'pnam' : _Prop_name, - 'ppos' : _Prop_position, - 'prsz' : _Prop_resizable, - 'ptit' : _Prop_titled, - 'pvis' : _Prop_visible, - 'pzum' : _Prop_zoomed, -} - -_compdeclarations = { -} - -_enumdeclarations = { - 'savo' : _Enum_savo, -} diff --git a/Mac/OSX/Doc/HelpIndexingTool/__init__.py b/Mac/OSX/Doc/HelpIndexingTool/__init__.py deleted file mode 100644 index 5359df5..0000000 --- a/Mac/OSX/Doc/HelpIndexingTool/__init__.py +++ /dev/null @@ -1,78 +0,0 @@ -""" -Package generated from /Developer/Applications/Apple Help Indexing Tool.app -""" -import aetools -Error = aetools.Error -import Standard_Suite -import Help_Indexing_Tool_Suite -import odds_and_ends -import Miscellaneous_Standards -import Required_Suite - - -_code_to_module = { - 'CoRe' : Standard_Suite, - 'HIT ' : Help_Indexing_Tool_Suite, - 'Odds' : odds_and_ends, - 'misc' : Miscellaneous_Standards, - 'reqd' : Required_Suite, -} - - - -_code_to_fullname = { - 'CoRe' : ('HelpIndexingTool.Standard_Suite', 'Standard_Suite'), - 'HIT ' : ('HelpIndexingTool.Help_Indexing_Tool_Suite', 'Help_Indexing_Tool_Suite'), - 'Odds' : ('HelpIndexingTool.odds_and_ends', 'odds_and_ends'), - 'misc' : ('HelpIndexingTool.Miscellaneous_Standards', 'Miscellaneous_Standards'), - 'reqd' : ('HelpIndexingTool.Required_Suite', 'Required_Suite'), -} - -from Standard_Suite import * -from Help_Indexing_Tool_Suite import * -from odds_and_ends import * -from Miscellaneous_Standards import * -from Required_Suite import * - -def getbaseclasses(v): - if not getattr(v, '_propdict', None): - v._propdict = {} - v._elemdict = {} - for superclassname in getattr(v, '_superclassnames', []): - superclass = eval(superclassname) - getbaseclasses(superclass) - v._propdict.update(getattr(superclass, '_propdict', {})) - v._elemdict.update(getattr(superclass, '_elemdict', {})) - v._propdict.update(getattr(v, '_privpropdict', {})) - v._elemdict.update(getattr(v, '_privelemdict', {})) - -import StdSuites - -# -# Set property and element dictionaries now that all classes have been defined -# -getbaseclasses(window) -getbaseclasses(application) -getbaseclasses(document) -getbaseclasses(application) - -# -# Indices of types declared in this module -# -_classdeclarations = { - 'cwin' : window, - 'capp' : application, - 'docu' : document, - 'capp' : application, -} - - -class HelpIndexingTool(Standard_Suite_Events, - Help_Indexing_Tool_Suite_Events, - odds_and_ends_Events, - Miscellaneous_Standards_Events, - Required_Suite_Events, - aetools.TalkTo): - _signature = 'hiti' - - _moduleName = 'HelpIndexingTool' diff --git a/Mac/OSX/Doc/HelpIndexingTool/odds_and_ends.py b/Mac/OSX/Doc/HelpIndexingTool/odds_and_ends.py deleted file mode 100644 index 7ee46f3..0000000 --- a/Mac/OSX/Doc/HelpIndexingTool/odds_and_ends.py +++ /dev/null @@ -1,49 +0,0 @@ -"""Suite odds and ends: Things that should be in some standard suite, but aren\xd5t -Level 1, version 1 - -Generated from /Developer/Applications/Apple Help Indexing Tool.app -AETE/AEUT resource version 1/1, language 0, script 0 -""" - -import aetools -import MacOS - -_code = 'Odds' - -class odds_and_ends_Events: - - def select(self, _object=None, _attributes={}, **_arguments): - """select: Select the specified object - Required argument: the object to select - Keyword argument _attributes: AppleEvent attribute dictionary - """ - _code = 'misc' - _subcode = 'slct' - - if _arguments: raise TypeError, 'No optional args expected' - _arguments['----'] = _object - - - _reply, _arguments, _attributes = self.send(_code, _subcode, - _arguments, _attributes) - if _arguments.get('errn', 0): - raise aetools.Error, aetools.decodeerror(_arguments) - # XXXX Optionally decode result - if _arguments.has_key('----'): - return _arguments['----'] - - -# -# Indices of types declared in this module -# -_classdeclarations = { -} - -_propdeclarations = { -} - -_compdeclarations = { -} - -_enumdeclarations = { -} diff --git a/Mac/OSX/Doc/README b/Mac/OSX/Doc/README deleted file mode 100644 index 4f4d53d..0000000 --- a/Mac/OSX/Doc/README +++ /dev/null @@ -1,35 +0,0 @@ -In this directory you can build the Python documentation in a form that -is suitable for access with Apple Help Viewer. This will enable the -"Python Documentation" menu entries in the MacPython IDE Help menu. - -Unfortunately the procedure to build the docs is not very streamlined. - -First, edit setup.py. At the top, edit MAJOR_VERSION and MINOR_VERSION, -and check that DESTDIR makes sense. The documentation will be installed -inside PythonIDE.app. - -In DocBuild.initialize_options, set self.download to True if you want to -download the docs. Set it to False if you want to build the docs from -the source tree, but this requires LaTex and lots of other stuff. -Doable, but not easy. - -Second, if you want to download the docs you may need to do a couple -more edits. The way the docs are packaged will often change between -major releases. Fiddle DocBuild.downloadDocs to make it do the right -thing (download the docs from python.org, unpack them, rename the -directory to "build/html"). - -After these edits you should be ready to roll. "pythonw setup.py build" -should download and unpack (or build) the docs. Next, it will do some -magic to make the docs indexable. Finally, it will run the Apple Help -Indexing Tool. (This last step is the reason you must use "pythonw" as -opposed to "python"). Usually it will time out while waiting for AHIT to -do its work. Wait until AHIT is done. - -Now you're ready to install with "python setup.py install". - -After this is done test your work. Fire up PythonIDE, and check that -Help->Python Documentation brings up the documentation in the Help Viewer. -Also open an IDE edit window, type something like "import sys", select -"import", and use Help->Lookup in Python Documentation to check that the -index has been generated correctly. diff --git a/Mac/OSX/Doc/setup.py b/Mac/OSX/Doc/setup.py deleted file mode 100644 index bd86a20..0000000 --- a/Mac/OSX/Doc/setup.py +++ /dev/null @@ -1,214 +0,0 @@ -# Build and install an Apple Help Viewer compatible version of the Python -# documentation into the framework. -# Code by Bill Fancher, with some modifications by Jack Jansen. -# -# You must run this as a two-step process -# 1. python setupDocs.py build -# 2. Wait for Apple Help Indexing Tool to finish -# 3. python setupDocs.py install -# -# To do: -# - test whether the docs are available locally before downloading -# - fix buildDocsFromSource -# - Get documentation version from sys.version, fallback to 2.2.1 -# - See if we can somehow detect that Apple Help Indexing Tool is finished -# - data_files to setup() doesn't seem the right way to pass the arguments -# -import sys, os, re -from distutils.cmd import Command -from distutils.command.build import build -from distutils.core import setup -from distutils.file_util import copy_file -from distutils.dir_util import copy_tree -from distutils.log import log -from distutils.spawn import spawn -from distutils import sysconfig, dep_util -from distutils.util import change_root -import HelpIndexingTool -import Carbon.File -import time - -MAJOR_VERSION='2.4' -MINOR_VERSION='2.4.1' -DESTDIR='/Applications/MacPython-%s/PythonIDE.app/Contents/Resources/English.lproj/PythonDocumentation' % MAJOR_VERSION - -class DocBuild(build): - def initialize_options(self): - build.initialize_options(self) - self.build_html = None - self.build_dest = None - self.download = 1 - self.doc_version = MINOR_VERSION # Only needed if download is true - - def finalize_options(self): - build.finalize_options(self) - if self.build_html is None: - self.build_html = os.path.join(self.build_base, 'html') - if self.build_dest is None: - self.build_dest = os.path.join(self.build_base, 'PythonDocumentation') - - def spawn(self, *args): - spawn(args, 1, self.verbose, self.dry_run) - - def downloadDocs(self): - workdir = os.getcwd() - # XXX Note: the next strings may change from version to version - url = 'http://www.python.org/ftp/python/doc/%s/html-%s.tar.bz2' % \ - (self.doc_version,self.doc_version) - tarfile = 'html-%s.tar.bz2' % self.doc_version - dirname = 'Python-Docs-%s' % self.doc_version - - if os.path.exists(self.build_html): - raise RuntimeError, '%s: already exists, please remove and try again' % self.build_html - os.chdir(self.build_base) - self.spawn('curl','-O', url) - self.spawn('tar', '-xjf', tarfile) - os.rename(dirname, 'html') - os.chdir(workdir) -## print "** Please unpack %s" % os.path.join(self.build_base, tarfile) -## print "** Unpack the files into %s" % self.build_html -## raise RuntimeError, "You need to unpack the docs manually" - - def buildDocsFromSource(self): - srcdir = '../../..' - docdir = os.path.join(srcdir, 'Doc') - htmldir = os.path.join(docdir, 'html') - spawn(('make','--directory', docdir, 'html'), 1, self.verbose, self.dry_run) - self.mkpath(self.build_html) - copy_tree(htmldir, self.build_html) - - def ensureHtml(self): - if not os.path.exists(self.build_html): - if self.download: - self.downloadDocs() - else: - self.buildDocsFromSource() - - def hackIndex(self): - ind_html = 'index.html' - #print 'self.build_dest =', self.build_dest - hackedIndex = file(os.path.join(self.build_dest, ind_html),'w') - origIndex = file(os.path.join(self.build_html,ind_html)) - r = re.compile('', re.DOTALL) - hackedIndex.write(r.sub('',origIndex.read())) - - def hackFile(self,d,f): - origPath = os.path.join(d,f) - assert(origPath[:len(self.build_html)] == self.build_html) - outPath = os.path.join(self.build_dest, d[len(self.build_html)+1:], f) - (name, ext) = os.path.splitext(f) - if os.path.isdir(origPath): - self.mkpath(outPath) - elif ext == '.html': - if self.verbose: print 'hacking %s to %s' % (origPath,outPath) - hackedFile = file(outPath, 'w') - origFile = file(origPath,'r') - hackedFile.write(self.r.sub('
    ', origFile.read())) - else: - copy_file(origPath, outPath) - - def hackHtml(self): - self.r = re.compile('
    ') - os.path.walk(self.build_html, self.visit, None) - - def visit(self, dummy, dirname, filenames): - for f in filenames: - self.hackFile(dirname, f) - - def makeHelpIndex(self): - app = '/Developer/Applications/Apple Help Indexing Tool.app' - self.spawn('open', '-a', app , self.build_dest) - print "Please wait until Apple Help Indexing Tool finishes before installing" - - def makeHelpIndex(self): - app = HelpIndexingTool.HelpIndexingTool(start=1) - app.open(Carbon.File.FSSpec(self.build_dest)) - sys.stderr.write("Waiting for Help Indexing Tool to start...") - while 1: - # This is bad design in the suite generation code! - idle = app._get(HelpIndexingTool.Help_Indexing_Tool_Suite._Prop_idleStatus()) - time.sleep(10) - if not idle: break - sys.stderr.write(".") - sys.stderr.write("\n") - sys.stderr.write("Waiting for Help Indexing Tool to finish...") - while 1: - # This is bad design in the suite generation code! - idle = app._get(HelpIndexingTool.Help_Indexing_Tool_Suite._Prop_idleStatus()) - time.sleep(10) - if idle: break - sys.stderr.write(".") - sys.stderr.write("\n") - - - def run(self): - self.ensure_finalized() - self.mkpath(self.build_base) - self.ensureHtml() - if not os.path.isdir(self.build_html): - raise RuntimeError, \ - "Can't find source folder for documentation." - self.mkpath(self.build_dest) - if dep_util.newer(os.path.join(self.build_html,'index.html'), os.path.join(self.build_dest,'index.html')): - self.mkpath(self.build_dest) - self.hackHtml() - self.hackIndex() - self.makeHelpIndex() - -class AHVDocInstall(Command): - description = "install Apple Help Viewer html files" - user_options = [('install-doc=', 'd', - 'directory to install HTML tree'), - ('root=', None, - "install everything relative to this alternate root directory"), - ] - - def initialize_options(self): - self.build_dest = None - self.install_doc = None - self.prefix = None - self.root = None - - def finalize_options(self): - self.set_undefined_options('install', - ('prefix', 'prefix'), - ('root', 'root')) -# import pdb ; pdb.set_trace() - build_cmd = self.get_finalized_command('build') - if self.build_dest == None: - build_cmd = self.get_finalized_command('build') - self.build_dest = build_cmd.build_dest - if self.install_doc == None: - self.install_doc = os.path.join(self.prefix, DESTDIR) - print 'INSTALL', self.build_dest, '->', self.install_doc - - def run(self): - self.finalize_options() - self.ensure_finalized() - print "Running Installer" - instloc = self.install_doc - if self.root: - instloc = change_root(self.root, instloc) - self.mkpath(instloc) - copy_tree(self.build_dest, instloc) - print "Installation complete" - -def mungeVersion(infile, outfile): - i = file(infile,'r') - o = file(outfile,'w') - o.write(re.sub('\$\(VERSION\)',sysconfig.get_config_var('VERSION'),i.read())) - i.close() - o.close() - -def main(): - # turn off warnings when deprecated modules are imported -## import warnings -## warnings.filterwarnings("ignore",category=DeprecationWarning) - setup(name = 'Documentation', - version = '%d.%d' % sys.version_info[:2], - cmdclass = {'install_data':AHVDocInstall, 'build':DocBuild}, - data_files = ['dummy'], - ) - -if __name__ == '__main__': - main() diff --git a/Mac/OSX/Extras.ReadMe.txt b/Mac/OSX/Extras.ReadMe.txt deleted file mode 100644 index 2d7fd42..0000000 --- a/Mac/OSX/Extras.ReadMe.txt +++ /dev/null @@ -1,5 +0,0 @@ -This folder contains examples of Python usage and useful scripts and tools. - -You should be aware that these are not Macintosh-specific but are shared -among Python on all platforms, so there are some that only run on Windows -or Unix or another platform, and/or make little sense on a Macintosh. diff --git a/Mac/OSX/Extras.install.py b/Mac/OSX/Extras.install.py deleted file mode 100644 index ce00af3..0000000 --- a/Mac/OSX/Extras.install.py +++ /dev/null @@ -1,54 +0,0 @@ -"""Recursively copy a directory but skip undesired files and -directories (CVS, backup files, pyc files, etc)""" - -import sys -import os -import shutil - -verbose = 1 -debug = 0 - -def isclean(name): - if name == 'CVS': return 0 - if name == '.cvsignore': return 0 - if name == '.DS_store': return 0 - if name == '.svn': return 0 - if name.endswith('~'): return 0 - if name.endswith('.BAK'): return 0 - if name.endswith('.pyc'): return 0 - if name.endswith('.pyo'): return 0 - if name.endswith('.orig'): return 0 - return 1 - -def copycleandir(src, dst): - for cursrc, dirs, files in os.walk(src): - assert cursrc.startswith(src) - curdst = dst + cursrc[len(src):] - if verbose: - print "mkdir", curdst - if not debug: - if not os.path.exists(curdst): - os.makedirs(curdst) - for fn in files: - if isclean(fn): - if verbose: - print "copy", os.path.join(cursrc, fn), os.path.join(curdst, fn) - if not debug: - shutil.copy2(os.path.join(cursrc, fn), os.path.join(curdst, fn)) - else: - if verbose: - print "skipfile", os.path.join(cursrc, fn) - for i in range(len(dirs)-1, -1, -1): - if not isclean(dirs[i]): - if verbose: - print "skipdir", os.path.join(cursrc, dirs[i]) - del dirs[i] - -def main(): - if len(sys.argv) != 3: - sys.stderr.write("Usage: %s srcdir dstdir\n" % sys.argv[0]) - sys.exit(1) - copycleandir(sys.argv[1], sys.argv[2]) - -if __name__ == '__main__': - main() diff --git a/Mac/OSX/IDLE/Info.plist b/Mac/OSX/IDLE/Info.plist deleted file mode 100644 index bbe2ea1..0000000 --- a/Mac/OSX/IDLE/Info.plist +++ /dev/null @@ -1,55 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleDocumentTypes - - - CFBundleTypeExtensions - - py - pyw - - CFBundleTypeIconFile - PythonSource.icns - CFBundleTypeName - Python Script - CFBundleTypeRole - Editor - - - CFBundleTypeExtensions - - pyc - pyo - - CFBundleTypeIconFile - PythonCompiled.icns - CFBundleTypeName - Python Bytecode Document - CFBundleTypeRole - Editor - - - CFBundleExecutable - IDLE - CFBundleGetInfoString - 2.5, © 001-2006 Python Software Foundation - CFBundleIconFile - IDLE.icns - CFBundleIdentifier - org.python.IDLE - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - IDLE - CFBundlePackageType - APPL - CFBundleShortVersionString - 2.5 - CFBundleVersion - 2.5 - - diff --git a/Mac/OSX/IDLE/Makefile.in b/Mac/OSX/IDLE/Makefile.in deleted file mode 100644 index a96e7ef..0000000 --- a/Mac/OSX/IDLE/Makefile.in +++ /dev/null @@ -1,52 +0,0 @@ -prefix=@prefix@ -CC=@CC@ -LD=@CC@ -BASECFLAGS=@BASECFLAGS@ -OPT=@OPT@ -CFLAGS=$(BASECFLAGS) $(OPT) -LDFLAGS=@LDFLAGS@ -srcdir= @srcdir@ -VERSION= @VERSION@ -UNIVERSALSDK=@UNIVERSALSDK@ -builddir= ../../.. - -RUNSHARED= @RUNSHARED@ -BUILDEXE= @BUILDEXEEXT@ -BUILDPYTHON= ../../../python$(BUILDEXE) - -# Deployment target selected during configure, to be checked -# by distutils -MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ -@EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET - -BUNDLEBULDER=$(srcdir)/../../../Lib/plat-mac/bundlebuilder.py - -PYTHONAPPSDIR=/Applications/MacPython $(VERSION) - -all: IDLE.app - -install: IDLE.app - test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" - -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - cp -PR IDLE.app "$(DESTDIR)$(PYTHONAPPSDIR)" - touch "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" - -clean: - rm -rf IDLE.app - -IDLE.app: \ - $(srcdir)/../Icons/IDLE.icns $(srcdir)/idlemain.py \ - $(srcdir)/../Icons/PythonSource.icns \ - $(srcdir)/../Icons/PythonCompiled.icns - rm -fr IDLE.app - $(RUNSHARED) $(BUILDPYTHON) $(BUNDLEBULDER) \ - --builddir=. \ - --name=IDLE \ - --link-exec \ - --plist=$(srcdir)/Info.plist \ - --mainprogram=$(srcdir)/idlemain.py \ - --iconfile=$(srcdir)/../Icons/IDLE.icns \ - --resource=$(srcdir)/../Icons/PythonSource.icns \ - --resource=$(srcdir)/../Icons/PythonCompiled.icns \ - --python=$(prefix)/Resources/Python.app/Contents/MacOS/Python \ - build diff --git a/Mac/OSX/IDLE/idlemain.py b/Mac/OSX/IDLE/idlemain.py deleted file mode 100644 index aa75d4c..0000000 --- a/Mac/OSX/IDLE/idlemain.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -Bootstrap script for IDLE as an application bundle. -""" -import sys, os - -from idlelib.PyShell import main - -# Change the current directory the user's home directory, that way we'll get -# a more useful default location in the open/save dialogs. -os.chdir(os.path.expanduser('~/Documents')) - - -# Make sure sys.executable points to the python interpreter inside the -# framework, instead of at the helper executable inside the application -# bundle (the latter works, but doesn't allow access to the window server) -sys.executable = os.path.join(sys.prefix, 'bin', 'python') - -# Look for the -psn argument that the launcher adds and remove it, it will -# only confuse the IDLE startup code. -for idx, value in enumerate(sys.argv): - if value.startswith('-psn_'): - del sys.argv[idx] - break - -#argvemulator.ArgvCollector().mainloop() -if __name__ == '__main__': - main() diff --git a/Mac/OSX/Icons/Disk Image.icns b/Mac/OSX/Icons/Disk Image.icns deleted file mode 100644 index 35f16bf..0000000 Binary files a/Mac/OSX/Icons/Disk Image.icns and /dev/null differ diff --git a/Mac/OSX/Icons/IDLE.icns b/Mac/OSX/Icons/IDLE.icns deleted file mode 100644 index c12c9da..0000000 Binary files a/Mac/OSX/Icons/IDLE.icns and /dev/null differ diff --git a/Mac/OSX/Icons/Python Folder.icns b/Mac/OSX/Icons/Python Folder.icns deleted file mode 100644 index ae766ee..0000000 Binary files a/Mac/OSX/Icons/Python Folder.icns and /dev/null differ diff --git a/Mac/OSX/Icons/PythonCompiled.icns b/Mac/OSX/Icons/PythonCompiled.icns deleted file mode 100644 index 7d9f320..0000000 Binary files a/Mac/OSX/Icons/PythonCompiled.icns and /dev/null differ diff --git a/Mac/OSX/Icons/PythonLauncher.icns b/Mac/OSX/Icons/PythonLauncher.icns deleted file mode 100644 index e09fd38..0000000 Binary files a/Mac/OSX/Icons/PythonLauncher.icns and /dev/null differ diff --git a/Mac/OSX/Icons/PythonSource.icns b/Mac/OSX/Icons/PythonSource.icns deleted file mode 100644 index 9e35c1e..0000000 Binary files a/Mac/OSX/Icons/PythonSource.icns and /dev/null differ diff --git a/Mac/OSX/Icons/ReadMe.txt b/Mac/OSX/Icons/ReadMe.txt deleted file mode 100644 index 226836a..0000000 --- a/Mac/OSX/Icons/ReadMe.txt +++ /dev/null @@ -1,3 +0,0 @@ -The icons for use on MacOS X were created by Jacob Rus -with some feedback from the folks on pythonmac-sig@python.org. - diff --git a/Mac/OSX/Makefile.in b/Mac/OSX/Makefile.in deleted file mode 100644 index a44191d..0000000 --- a/Mac/OSX/Makefile.in +++ /dev/null @@ -1,241 +0,0 @@ -# This file can be invoked from the various frameworkinstall... targets in the -# main Makefile. The next couple of variables are overridden on the -# commandline in that case. - -VERSION=@VERSION@ -builddir = ../.. -srcdir = @srcdir@ -prefix=/Library/Frameworks/Python.framework/Versions/$(VERSION) -LIBDEST=$(prefix)/lib/python$(VERSION) -BUILDPYTHON=$(builddir)/python.exe -DESTDIR= - -# These are normally glimpsed from the previous set -bindir=@exec_prefix@/bin -PYTHONAPPSDIR=/Applications/MacPython $(VERSION) -APPINSTALLDIR=$(prefix)/Resources/Python.app - -# Variables for installing the "normal" unix binaries -INSTALLED_PYDOC=$(prefix)/bin/pydoc -INSTALLED_IDLE=$(prefix)/bin/idle -INSTALLED_PYTHON=$(prefix)/bin/python -INSTALLED_PYTHONW=$(prefix)/bin/pythonw -INSTALLED_PYTHONAPP=$(APPINSTALLDIR)/Contents/MacOS/Python - -# Items more-or-less copied from the main Makefile -DIRMODE=755 -FILEMODE=644 -INSTALL=@INSTALL@ -INSTALL_SYMLINK=ln -fsn -INSTALL_PROGRAM=@INSTALL_PROGRAM@ -INSTALL_SCRIPT= @INSTALL_SCRIPT@ -INSTALL_DATA=@INSTALL_DATA@ -LN=@LN@ -STRIPFLAG=-s -CPMAC=/Developer/Tools/CpMac - -APPTEMPLATE=$(srcdir)/../OSXResources/app -APPSUBDIRS=MacOS Resources Resources/English.lproj \ - Resources/English.lproj/Documentation \ - Resources/English.lproj/Documentation/doc \ - Resources/English.lproj/Documentation/ide -DOCDIR=$(srcdir)/../OSXResources/app/Resources/English.lproj/Documentation -DOCINDEX=$(DOCDIR)/"Documentation idx" -CACHERSRC=$(srcdir)/../scripts/cachersrc.py -compileall=$(srcdir)/../../Lib/compileall.py - -installapps: install_Python install_BuildApplet install_PythonLauncher \ - install_IDLE checkapplepython install_pythonw install_versionedtools - -install_pythonw: pythonw - $(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)" - $(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/python$(VERSION)" - ln -sf python$(VERSION) "$(DESTDIR)$(prefix)/bin/python" - ln -sf pythonw$(VERSION) "$(DESTDIR)$(prefix)/bin/pythonw" - -# -# Install unix tools in /usr/local/bin. These are just aliases for the -# actual installation inside the framework. -# -installunixtools: - if [ ! -d "$(DESTDIR)/usr/local/bin" ]; then \ - $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)/usr/local/bin" ;\ - fi - for fn in `ls "$(DESTDIR)$(prefix)/bin/"` ; \ - do \ - ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)/usr/local/bin/$${fn}" ;\ - done - -# By default most tools are installed without a version in their basename, to -# make it easier to install (and use) several python versions side-by-side move -# the tools to a version-specific name and add the non-versioned name as an -# alias. -install_versionedtools: - for fn in idle pydoc python-config ;\ - do \ - if [ -h "$(DESTDIR)$(prefix)/bin/$${fn}" ]; then \ - continue ;\ - fi ;\ - mv "$(DESTDIR)$(prefix)/bin/$${fn}" "$(DESTDIR)$(prefix)/bin/$${fn}$(VERSION)" ;\ - ln -sf "$${fn}$(VERSION)" "$(DESTDIR)$(prefix)/bin/$${fn}" ;\ - done - if [ ! -h "$(DESTDIR)$(prefix)/bin/smtpd.py" ]; then \ - mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py" ;\ - ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py" ;\ - fi - - -pythonw: $(srcdir)/Tools/pythonw.c - $(CC) $(LDFLAGS) -o $@ $(srcdir)/Tools/pythonw.c \ - -DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/Python"' - - -install_PythonLauncher: - cd PythonLauncher && make install DESTDIR=$(DESTDIR) - -install_Python: - @if test ! -f $(DOCINDEX); then \ - echo WARNING: you should run Apple Help Indexing Tool on $(DOCDIR); \ - fi - @for i in "$(PYTHONAPPSDIR)" "$(APPINSTALLDIR)" "$(APPINSTALLDIR)/Contents"; do \ - if test ! -d "$(DESTDIR)$$i"; then \ - echo "Creating directory $(DESTDIR)$$i"; \ - $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$$i"; \ - fi;\ - done - @for i in $(APPSUBDIRS); do \ - if test ! -d "$(DESTDIR)$(APPINSTALLDIR)/Contents/$$i"; then \ - echo "Creating directory $(DESTDIR)$(APPINSTALLDIR)/Contents/$$i"; \ - $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(APPINSTALLDIR)/Contents/$$i"; \ - else true; \ - fi; \ - done - @for d in . $(APPSUBDIRS); \ - do \ - a=$(APPTEMPLATE)/$$d; \ - if test ! -d $$a; then continue; else true; fi; \ - b="$(DESTDIR)$(APPINSTALLDIR)/Contents/$$d"; \ - for i in $$a/*; \ - do \ - case $$i in \ - *CVS) ;; \ - *.svn) ;; \ - *.py[co]) ;; \ - *.orig) ;; \ - *~) ;; \ - *idx) \ - echo $(CPMAC) "$$i" $$b; \ - $(CPMAC) "$$i" "$$b"; \ - ;; \ - *) \ - if test -d $$i; then continue; fi; \ - if test -x $$i; then \ - echo $(INSTALL_SCRIPT) "$$i" "$$b"; \ - $(INSTALL_SCRIPT) "$$i" "$$b"; \ - else \ - echo $(INSTALL_DATA) "$$i" "$$b"; \ - $(INSTALL_DATA) "$$i" "$$b"; \ - fi;; \ - esac; \ - done; \ - done - $(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/Python" - -install_IDLE: - cd IDLE && make install - -install_BuildApplet: - $(BUILDPYTHON) $(srcdir)/../scripts/BuildApplet.py \ - --destroot "$(DESTDIR)" \ - --python $(INSTALLED_PYTHONAPP) \ - --output "$(DESTDIR)$(PYTHONAPPSDIR)/Build Applet.app" \ - $(srcdir)/../scripts/BuildApplet.py - -MACLIBDEST=$(LIBDEST)/plat-mac -MACTOOLSDEST=$(prefix)/Mac/Tools -MACTOOLSSRC=$(srcdir)/Mac/Tools -MACTOOLSSUBDIRS=IDE - -installmacsubtree: - @for i in $(MACTOOLSDEST); \ - do \ - if test ! -d $(DESTDIR)$$i; then \ - echo "Creating directory $(DESTDIR)$$i"; \ - $(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \ - else true; \ - fi; \ - done - @for d in $(MACTOOLSSUBDIRS); \ - do \ - a=$(MACTOOLSSRC)/$$d; \ - if test ! -d $$a; then continue; else true; fi; \ - b=$(DESTDIR)$(MACTOOLSDEST)/$$d; \ - if test ! -d $$b; then \ - echo "Creating directory $$b"; \ - $(INSTALL) -d -m $(DIRMODE) $$b; \ - else true; \ - fi; \ - done - @for d in $(MACTOOLSSUBDIRS); \ - do \ - a=$(MACTOOLSSRC)/$$d; \ - if test ! -d $$a; then continue; else true; fi; \ - b=$(DESTDIR)$(MACTOOLSDEST)/$$d; \ - for i in $$a/*; \ - do \ - case $$i in \ - *CVS) ;; \ - *.svn) ;; \ - *.py[co]) ;; \ - *.orig) ;; \ - *~) ;; \ - *.rsrc) \ - echo $(CPMAC) $$i $$b ; \ - $(CPMAC) $$i $$b ; \ - ;; \ - *) \ - if test -d $$i; then continue; fi; \ - if test -x $$i; then \ - echo $(INSTALL_SCRIPT) $$i $$b; \ - $(INSTALL_SCRIPT) $$i $$b; \ - else \ - echo $(INSTALL_DATA) $$i $$b; \ - $(INSTALL_DATA) $$i $$b; \ - fi;; \ - esac; \ - done; \ - done - - - $(BUILDPYTHON) $(CACHERSRC) -v $(DESTDIR)$(MACLIBDEST) $(DESTDIR)$(MACTOOLSDEST) - $(BUILDPYTHON) -Wi -tt $(compileall) -d $(MACTOOLSDEST) -x badsyntax $(DESTDIR)$(MACTOOLSDEST) - $(BUILDPYTHON) -O -Wi -tt $(compileall) -d $(MACTOOLSDEST) -x badsyntax $(DESTDIR)$(MACTOOLSDEST) - -# -# We use the full name here in stead of $(INSTALLED_PYTHONAPP), because -# the latter may be overridden by Makefile.jaguar when building for a pre-installed -$(INSTALLED_PYTHONAPP)/Contents/MacOS/Python: install_Python - -# $(INSTALLED_PYTHON) has to be done by the main Makefile, we cannot do that here. -# At least this rule will give an error if it doesn't exist. - -installextras: - $(INSTALL) -d "$(DESTDIR)$(PYTHONAPPSDIR)/Extras" - $(INSTALL) $(srcdir)/Mac/OSX/Extras.ReadMe.txt "$(DESTDIR)$(PYTHONAPPSDIR)/Extras/ReadMe.txt" - $(BUILDPYTHON) $(srcdir)/Mac/OSX/Extras.install.py $(srcdir)/Demo \ - "$(DESTDIR)$(PYTHONAPPSDIR)/Extras/Demo" - - -checkapplepython: - @if ! $(BUILDPYTHON) $(srcdir)/fixapplepython23.py -n; then \ - echo "* WARNING: Apple-installed Python 2.3 will have trouble building extensions from now on."; \ - echo "* WARNING: Run $(srcdir)/fixapplepython23.py with \"sudo\" to fix this."; \ - fi - - -clean: - rm pythonw - cd PythonLauncher && make clean - cd IDLE && make clean - - diff --git a/Mac/OSX/PythonLauncher/English.lproj/Credits.rtf b/Mac/OSX/PythonLauncher/English.lproj/Credits.rtf deleted file mode 100644 index 930ca22..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/Credits.rtf +++ /dev/null @@ -1,30 +0,0 @@ -{\rtf1\mac\ansicpg10000\cocoartf100 -{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} -{\colortbl;\red255\green255\blue255;} -\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural - -\f0\b\fs24 \cf0 Engineering: -\f1\b0 \ - Jack Jansen\ -\ - -\f0\b Human Interface Design: -\f1\b0 \ - Jack Jansen\ -\ - -\f0\b Testing: -\f1\b0 \ - Jack Jansen\ - Pythonmac-SIG@python.org\ -\ - -\f0\b Documentation: -\f1\b0 \ - Missing\ -\ - -\f0\b With special thanks to: -\f1\b0 \ - Guido, of course\ -} \ No newline at end of file diff --git a/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/classes.nib b/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/classes.nib deleted file mode 100644 index 47b40ab..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/classes.nib +++ /dev/null @@ -1,12 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {showPreferences = id; }; - CLASS = MyAppDelegate; - LANGUAGE = ObjC; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/info.nib b/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/info.nib deleted file mode 100644 index b96759a..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/info.nib +++ /dev/null @@ -1,21 +0,0 @@ - - - - - IBDocumentLocation - 99 33 356 240 0 0 800 578 - IBEditorPositions - - 29 - 82 396 318 44 0 0 800 578 - - IBFramework Version - 263.2 - IBOpenObjects - - 29 - - IBSystem Version - 5S66 - - diff --git a/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/objects.nib b/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/objects.nib deleted file mode 100644 index 532a5c8..0000000 Binary files a/Mac/OSX/PythonLauncher/English.lproj/MainMenu.nib/objects.nib and /dev/null differ diff --git a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib deleted file mode 100644 index bcdc0cd..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/classes.nib +++ /dev/null @@ -1,26 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {"do_apply" = id; "do_cancel" = id; "do_reset" = id; "do_run" = id; }; - CLASS = MyDocument; - LANGUAGE = ObjC; - OUTLETS = { - commandline = NSTextField; - debug = NSButton; - honourhashbang = NSButton; - inspect = NSButton; - interpreter = NSTextField; - nosite = NSButton; - optimize = NSButton; - others = NSTextField; - scriptargs = NSTextField; - tabs = NSButton; - verbose = NSButton; - "with_terminal" = NSButton; - }; - SUPERCLASS = NSDocument; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib deleted file mode 100644 index e258c72..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/info.nib +++ /dev/null @@ -1,16 +0,0 @@ - - - - - IBDocumentLocation - 398 60 356 240 0 0 1024 746 - IBFramework Version - 291.0 - IBOpenObjects - - 5 - - IBSystem Version - 6L60 - - diff --git a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib b/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib deleted file mode 100644 index 0473a31..0000000 Binary files a/Mac/OSX/PythonLauncher/English.lproj/MyDocument.nib/objects.nib and /dev/null differ diff --git a/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib b/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib deleted file mode 100644 index 467aa8b..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib +++ /dev/null @@ -1,26 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {"do_apply" = id; "do_filetype" = id; "do_reset" = id; }; - CLASS = PreferencesWindowController; - LANGUAGE = ObjC; - OUTLETS = { - commandline = NSTextField; - debug = NSButton; - filetype = NSPopUpButton; - honourhashbang = NSButton; - inspect = NSButton; - interpreter = NSTextField; - nosite = NSButton; - optimize = NSButton; - others = NSTextField; - tabs = NSButton; - verbose = NSButton; - "with_terminal" = NSButton; - }; - SUPERCLASS = NSWindowController; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib b/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib deleted file mode 100644 index bc558f7..0000000 --- a/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib +++ /dev/null @@ -1,16 +0,0 @@ - - - - - IBDocumentLocation - 565 235 519 534 0 0 1280 1002 - IBFramework Version - 364.0 - IBOpenObjects - - 5 - - IBSystem Version - 7H63 - - diff --git a/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib b/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib deleted file mode 100644 index 3dfed33..0000000 Binary files a/Mac/OSX/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib and /dev/null differ diff --git a/Mac/OSX/PythonLauncher/FileSettings.h b/Mac/OSX/PythonLauncher/FileSettings.h deleted file mode 100755 index d807bae..0000000 --- a/Mac/OSX/PythonLauncher/FileSettings.h +++ /dev/null @@ -1,64 +0,0 @@ -// -// FileSettings.h -// PythonLauncher -// -// Created by Jack Jansen on Sun Jul 21 2002. -// Copyright (c) 2002 __MyCompanyName__. All rights reserved. -// - -#import - -@protocol FileSettingsSource -- (NSString *) interpreter; -- (BOOL) honourhashbang; -- (BOOL) debug; -- (BOOL) verbose; -- (BOOL) inspect; -- (BOOL) optimize; -- (BOOL) nosite; -- (BOOL) tabs; -- (NSString *) others; -- (BOOL) with_terminal; -- (NSString *) scriptargs; -@end - -@interface FileSettings : NSObject -{ - NSString *interpreter; // The pathname of the interpreter to use - NSArray *interpreters; // List of known interpreters - BOOL honourhashbang; // #! line overrides interpreter - BOOL debug; // -d option: debug parser - BOOL verbose; // -v option: verbose import - BOOL inspect; // -i option: interactive mode after script - BOOL optimize; // -O option: optimize bytecode - BOOL nosite; // -S option: don't import site.py - BOOL tabs; // -t option: warn about inconsistent tabs - NSString *others; // other options - NSString *scriptargs; // script arguments (not for preferences) - BOOL with_terminal; // Run in terminal window - - FileSettings *origsource; - NSString *prefskey; -} - -+ (id)getDefaultsForFileType: (NSString *)filetype; -+ (id)getFactorySettingsForFileType: (NSString *)filetype; -+ (id)newSettingsForFileType: (NSString *)filetype; - -//- (id)init; -- (id)initForFileType: (NSString *)filetype; -- (id)initForFSDefaultFileType: (NSString *)filetype; -- (id)initForDefaultFileType: (NSString *)filetype; -//- (id)initWithFileSettings: (FileSettings *)source; - -- (void)updateFromSource: (id )source; -- (NSString *)commandLineForScript: (NSString *)script; - -//- (void)applyFactorySettingsForFileType: (NSString *)filetype; -//- (void)saveDefaults; -//- (void)applyUserDefaults: (NSString *)filetype; -- (void)applyValuesFromDict: (NSDictionary *)dict; -- (void)reset; -- (NSArray *) interpreters; - -@end diff --git a/Mac/OSX/PythonLauncher/FileSettings.m b/Mac/OSX/PythonLauncher/FileSettings.m deleted file mode 100755 index fc3937b..0000000 --- a/Mac/OSX/PythonLauncher/FileSettings.m +++ /dev/null @@ -1,298 +0,0 @@ -// -// FileSettings.m -// PythonLauncher -// -// Created by Jack Jansen on Sun Jul 21 2002. -// Copyright (c) 2002 __MyCompanyName__. All rights reserved. -// - -#import "FileSettings.h" - -@implementation FileSettings - -+ (id)getFactorySettingsForFileType: (NSString *)filetype -{ - static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc; - FileSettings **curdefault; - - if ([filetype isEqualToString: @"Python Script"]) { - curdefault = &fsdefault_py; - } else if ([filetype isEqualToString: @"Python GUI Script"]) { - curdefault = &fsdefault_pyw; - } else if ([filetype isEqualToString: @"Python Bytecode Document"]) { - curdefault = &fsdefault_pyc; - } else { - NSLog(@"Funny File Type: %@\n", filetype); - curdefault = &fsdefault_py; - filetype = @"Python Script"; - } - if (!*curdefault) { - *curdefault = [[FileSettings new] initForFSDefaultFileType: filetype]; - } - return *curdefault; -} - -+ (id)getDefaultsForFileType: (NSString *)filetype -{ - static FileSettings *default_py, *default_pyw, *default_pyc; - FileSettings **curdefault; - - if ([filetype isEqualToString: @"Python Script"]) { - curdefault = &default_py; - } else if ([filetype isEqualToString: @"Python GUI Script"]) { - curdefault = &default_pyw; - } else if ([filetype isEqualToString: @"Python Bytecode Document"]) { - curdefault = &default_pyc; - } else { - NSLog(@"Funny File Type: %@\n", filetype); - curdefault = &default_py; - filetype = @"Python Script"; - } - if (!*curdefault) { - *curdefault = [[FileSettings new] initForDefaultFileType: filetype]; - } - return *curdefault; -} - -+ (id)newSettingsForFileType: (NSString *)filetype -{ - FileSettings *cur; - - cur = [FileSettings new]; - [cur initForFileType: filetype]; - return [cur retain]; -} - -- (id)initWithFileSettings: (FileSettings *)source -{ - self = [super init]; - if (!self) return self; - - interpreter = [source->interpreter retain]; - honourhashbang = source->honourhashbang; - debug = source->debug; - verbose = source->verbose; - inspect = source->inspect; - optimize = source->optimize; - nosite = source->nosite; - tabs = source->tabs; - others = [source->others retain]; - scriptargs = [source->scriptargs retain]; - with_terminal = source->with_terminal; - prefskey = source->prefskey; - if (prefskey) [prefskey retain]; - - return self; -} - -- (id)initForFileType: (NSString *)filetype -{ - FileSettings *defaults; - - defaults = [FileSettings getDefaultsForFileType: filetype]; - self = [self initWithFileSettings: defaults]; - origsource = [defaults retain]; - return self; -} - -//- (id)init -//{ -// self = [self initForFileType: @"Python Script"]; -// return self; -//} - -- (id)initForFSDefaultFileType: (NSString *)filetype -{ - int i; - NSString *filename; - NSDictionary *dict; - static NSDictionary *factorySettings; - - self = [super init]; - if (!self) return self; - - if (factorySettings == NULL) { - NSBundle *bdl = [NSBundle mainBundle]; - NSString *path = [ bdl pathForResource: @"factorySettings" - ofType: @"plist"]; - factorySettings = [[NSDictionary dictionaryWithContentsOfFile: - path] retain]; - if (factorySettings == NULL) { - NSLog(@"Missing %@", path); - return NULL; - } - } - dict = [factorySettings objectForKey: filetype]; - if (dict == NULL) { - NSLog(@"factorySettings.plist misses file type \"%@\"", filetype); - interpreter = [@"no default found" retain]; - return NULL; - } - [self applyValuesFromDict: dict]; - interpreters = [dict objectForKey: @"interpreter_list"]; - interpreter = NULL; - for (i=0; i < [interpreters count]; i++) { - filename = [interpreters objectAtIndex: i]; - filename = [filename stringByExpandingTildeInPath]; - if ([[NSFileManager defaultManager] fileExistsAtPath: filename]) { - interpreter = [filename retain]; - break; - } - } - if (interpreter == NULL) - interpreter = [@"no default found" retain]; - origsource = NULL; - return self; -} - -- (void)applyUserDefaults: (NSString *)filetype -{ - NSUserDefaults *defaults; - NSDictionary *dict; - - defaults = [NSUserDefaults standardUserDefaults]; - dict = [defaults dictionaryForKey: filetype]; - if (!dict) - return; - [self applyValuesFromDict: dict]; -} - -- (id)initForDefaultFileType: (NSString *)filetype -{ - FileSettings *fsdefaults; - - fsdefaults = [FileSettings getFactorySettingsForFileType: filetype]; - self = [self initWithFileSettings: fsdefaults]; - if (!self) return self; - interpreters = [fsdefaults->interpreters retain]; - scriptargs = [@"" retain]; - [self applyUserDefaults: filetype]; - prefskey = [filetype retain]; - return self; -} - -- (void)reset -{ - if (origsource) { - [self updateFromSource: origsource]; - } else { - FileSettings *fsdefaults; - fsdefaults = [FileSettings getFactorySettingsForFileType: prefskey]; - [self updateFromSource: fsdefaults]; - } -} - -- (void)updateFromSource: (id )source -{ - interpreter = [[source interpreter] retain]; - honourhashbang = [source honourhashbang]; - debug = [source debug]; - verbose = [source verbose]; - inspect = [source inspect]; - optimize = [source optimize]; - nosite = [source nosite]; - tabs = [source tabs]; - others = [[source others] retain]; - scriptargs = [[source scriptargs] retain]; - with_terminal = [source with_terminal]; - // And if this is a user defaults object we also save the - // values - if (!origsource) { - NSUserDefaults *defaults; - NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: - interpreter, @"interpreter", - [NSNumber numberWithBool: honourhashbang], @"honourhashbang", - [NSNumber numberWithBool: debug], @"debug", - [NSNumber numberWithBool: verbose], @"verbose", - [NSNumber numberWithBool: inspect], @"inspect", - [NSNumber numberWithBool: optimize], @"optimize", - [NSNumber numberWithBool: nosite], @"nosite", - [NSNumber numberWithBool: nosite], @"nosite", - others, @"others", - scriptargs, @"scriptargs", - [NSNumber numberWithBool: with_terminal], @"with_terminal", - nil]; - defaults = [NSUserDefaults standardUserDefaults]; - [defaults setObject: dict forKey: prefskey]; - } -} - -- (void)applyValuesFromDict: (NSDictionary *)dict -{ - id value; - - value = [dict objectForKey: @"interpreter"]; - if (value) interpreter = [value retain]; - value = [dict objectForKey: @"honourhashbang"]; - if (value) honourhashbang = [value boolValue]; - value = [dict objectForKey: @"debug"]; - if (value) debug = [value boolValue]; - value = [dict objectForKey: @"verbose"]; - if (value) verbose = [value boolValue]; - value = [dict objectForKey: @"inspect"]; - if (value) inspect = [value boolValue]; - value = [dict objectForKey: @"optimize"]; - if (value) optimize = [value boolValue]; - value = [dict objectForKey: @"nosite"]; - if (value) nosite = [value boolValue]; - value = [dict objectForKey: @"nosite"]; - if (value) tabs = [value boolValue]; - value = [dict objectForKey: @"others"]; - if (value) others = [value retain]; - value = [dict objectForKey: @"scriptargs"]; - if (value) scriptargs = [value retain]; - value = [dict objectForKey: @"with_terminal"]; - if (value) with_terminal = [value boolValue]; -} - -- (NSString *)commandLineForScript: (NSString *)script -{ - NSString *cur_interp = NULL; - char hashbangbuf[1024]; - FILE *fp; - char *p; - - if (honourhashbang && - (fp=fopen([script cString], "r")) && - fgets(hashbangbuf, sizeof(hashbangbuf), fp) && - strncmp(hashbangbuf, "#!", 2) == 0 && - (p=strchr(hashbangbuf, '\n'))) { - *p = '\0'; - p = hashbangbuf + 2; - while (*p == ' ') p++; - cur_interp = [NSString stringWithCString: p]; - } - if (!cur_interp) - cur_interp = interpreter; - - return [NSString stringWithFormat: - @"\"%@\"%s%s%s%s%s%s %@ \"%@\" %@ %s", - cur_interp, - debug?" -d":"", - verbose?" -v":"", - inspect?" -i":"", - optimize?" -O":"", - nosite?" -S":"", - tabs?" -t":"", - others, - script, - scriptargs, - with_terminal? "&& echo Exit status: $? && exit 1" : " &"]; -} - -- (NSArray *) interpreters { return interpreters;}; - -// FileSettingsSource protocol -- (NSString *) interpreter { return interpreter;}; -- (BOOL) honourhashbang { return honourhashbang; }; -- (BOOL) debug { return debug;}; -- (BOOL) verbose { return verbose;}; -- (BOOL) inspect { return inspect;}; -- (BOOL) optimize { return optimize;}; -- (BOOL) nosite { return nosite;}; -- (BOOL) tabs { return tabs;}; -- (NSString *) others { return others;}; -- (NSString *) scriptargs { return scriptargs;}; -- (BOOL) with_terminal { return with_terminal;}; - -@end diff --git a/Mac/OSX/PythonLauncher/Info.plist b/Mac/OSX/PythonLauncher/Info.plist deleted file mode 100644 index 1dd795f..0000000 --- a/Mac/OSX/PythonLauncher/Info.plist +++ /dev/null @@ -1,65 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleDocumentTypes - - - CFBundleTypeExtensions - - py - pyw - - CFBundleTypeIconFile - PythonSource.icns - CFBundleTypeName - Python Script - CFBundleTypeRole - Viewer - NSDocumentClass - MyDocument - - - CFBundleTypeExtensions - - pyc - pyo - - CFBundleTypeIconFile - PythonCompiled.icns - CFBundleTypeName - Python Bytecode Document - CFBundleTypeRole - Viewer - NSDocumentClass - MyDocument - - - CFBundleExecutable - PythonLauncher - CFBundleGetInfoString - 2.5, © 001-2006 Python Software Foundation - CFBundleIconFile - PythonLauncher.icns - CFBundleIdentifier - org.python.PythonLauncher - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - Python Launcher - CFBundlePackageType - APPL - CFBundleShortVersionString - 2.5 - CFBundleSignature - PytL - CFBundleVersion - 2.5 - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication - - diff --git a/Mac/OSX/PythonLauncher/Makefile.in b/Mac/OSX/PythonLauncher/Makefile.in deleted file mode 100644 index e6dacb3..0000000 --- a/Mac/OSX/PythonLauncher/Makefile.in +++ /dev/null @@ -1,78 +0,0 @@ -CC=@CC@ -LD=@CC@ -BASECFLAGS=@BASECFLAGS@ -OPT=@OPT@ -CFLAGS=$(BASECFLAGS) $(OPT) -LDFLAGS=@LDFLAGS@ -srcdir= @srcdir@ -VERSION= @VERSION@ -UNIVERSALSDK=@UNIVERSALSDK@ -builddir= ../../.. - -RUNSHARED= @RUNSHARED@ -BUILDEXE= @BUILDEXEEXT@ -BUILDPYTHON= ../../../python$(BUILDEXE) - -# Deployment target selected during configure, to be checked -# by distutils -MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ -@EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET - -BUNDLEBULDER=$(srcdir)/../../../Lib/plat-mac/bundlebuilder.py - -PYTHONAPPSDIR=/Applications/MacPython $(VERSION) -OBJECTS=FileSettings.o MyAppDelegate.o MyDocument.o PreferencesWindowController.o doscript.o main.o - -all: Python\ Launcher.app - -install: Python\ Launcher.app - test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" - -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" - touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" - -clean: - rm -f *.o "Python Launcher" - rm -rf "Python Launcher.app" - -Python\ Launcher.app: \ - Python\ Launcher $(srcdir)/../Icons/PythonLauncher.icns \ - $(srcdir)/../Icons/PythonSource.icns \ - $(srcdir)/../Icons/PythonCompiled.icns \ - $(srcdir)/factorySettings.plist - rm -fr "Python Launcher.app" - $(RUNSHARED) $(BUILDPYTHON) $(BUNDLEBULDER) \ - --builddir=. \ - --name="Python Launcher" \ - --executable="Python Launcher" \ - --iconfile=$(srcdir)/../Icons/PythonLauncher.icns \ - --bundle-id=org.python.PythonLauncher \ - --resource=$(srcdir)/../Icons/PythonSource.icns \ - --resource=$(srcdir)/../Icons/PythonCompiled.icns \ - --resource=$(srcdir)/English.lproj \ - --resource=$(srcdir)/factorySettings.plist \ - --plist=$(srcdir)/Info.plist \ - build - find "Python Launcher.app" -name '.svn' -print0 | xargs -0 rm -r - - -FileSettings.o: $(srcdir)/FileSettings.m - $(CC) $(CFLAGS) -o $@ -c $(srcdir)/FileSettings.m - -MyAppDelegate.o: $(srcdir)/MyAppDelegate.m - $(CC) $(CFLAGS) -o $@ -c $(srcdir)/MyAppDelegate.m - -MyDocument.o: $(srcdir)/MyDocument.m - $(CC) $(CFLAGS) -o $@ -c $(srcdir)/MyDocument.m - -PreferencesWindowController.o: $(srcdir)/PreferencesWindowController.m - $(CC) $(CFLAGS) -o $@ -c $(srcdir)/PreferencesWindowController.m - -doscript.o: $(srcdir)/doscript.m - $(CC) $(CFLAGS) -o $@ -c $(srcdir)/doscript.m - -main.o: $(srcdir)/main.m - $(CC) $(CFLAGS) -o $@ -c $(srcdir)/main.m - -Python\ Launcher: $(OBJECTS) - $(CC) $(LDFLAGS) -o "Python Launcher" $(OBJECTS) -framework AppKit -framework Carbon diff --git a/Mac/OSX/PythonLauncher/MyAppDelegate.h b/Mac/OSX/PythonLauncher/MyAppDelegate.h deleted file mode 100644 index 097b541..0000000 --- a/Mac/OSX/PythonLauncher/MyAppDelegate.h +++ /dev/null @@ -1,15 +0,0 @@ -/* MyAppDelegate */ - -#import - -@interface MyAppDelegate : NSObject -{ - BOOL initial_action_done; - BOOL should_terminate; -} -- (id)init; -- (IBAction)showPreferences:(id)sender; -- (BOOL)shouldShowUI; -- (BOOL)shouldTerminate; -- (void)testFileTypeBinding; -@end diff --git a/Mac/OSX/PythonLauncher/MyAppDelegate.m b/Mac/OSX/PythonLauncher/MyAppDelegate.m deleted file mode 100644 index a5ba751..0000000 --- a/Mac/OSX/PythonLauncher/MyAppDelegate.m +++ /dev/null @@ -1,96 +0,0 @@ -#import "MyAppDelegate.h" -#import "PreferencesWindowController.h" -#import -#import - -@implementation MyAppDelegate - -- (id)init -{ - self = [super init]; - initial_action_done = NO; - should_terminate = NO; - return self; -} - -- (IBAction)showPreferences:(id)sender -{ - [PreferencesWindowController getPreferencesWindow]; -} - -- (void)applicationDidFinishLaunching:(NSNotification *)notification -{ - // Test that the file mappings are correct - [self testFileTypeBinding]; - // If we were opened because of a file drag or doubleclick - // we've set initial_action_done in shouldShowUI - // Otherwise we open a preferences dialog. - if (!initial_action_done) { - initial_action_done = YES; - [self showPreferences: self]; - } -} - -- (BOOL)shouldShowUI -{ - // if this call comes before applicationDidFinishLaunching: we - // should terminate immedeately after starting the script. - if (!initial_action_done) - should_terminate = YES; - initial_action_done = YES; - if( GetCurrentKeyModifiers() & optionKey ) - return YES; - return NO; -} - -- (BOOL)shouldTerminate -{ - return should_terminate; -} - -- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender -{ - return NO; -} - -- (void)testFileTypeBinding -{ - NSURL *ourUrl; - OSStatus err; - FSRef appRef; - NSURL *appUrl; - static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL}; - NSString **ext_p; - int i; - - if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"]) - return; - ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]]; - for( ext_p = extensions; *ext_p; ext_p++ ) { - err = LSGetApplicationForInfo( - kLSUnknownType, - kLSUnknownCreator, - (CFStringRef)*ext_p, - kLSRolesViewer, - &appRef, - (CFURLRef *)&appUrl); - if (err || ![appUrl isEqual: ourUrl] ) { - i = NSRunAlertPanel(@"File type binding", - @"PythonLauncher is not the default application for all " \ - @"Python script types. You should fix this with the " \ - @"Finder's \"Get Info\" command.\n\n" \ - @"See \"Changing the application that opens a file\" in " \ - @"Mac Help for details.", - @"OK", - @"Don't show this warning again", - NULL); - if ( i == 0 ) { // Don't show again - [[NSUserDefaults standardUserDefaults] - setObject:@"YES" forKey:@"SkipFileBindingTest"]; - } - return; - } - } -} - -@end diff --git a/Mac/OSX/PythonLauncher/MyDocument.h b/Mac/OSX/PythonLauncher/MyDocument.h deleted file mode 100755 index 00c1bae..0000000 --- a/Mac/OSX/PythonLauncher/MyDocument.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// MyDocument.h -// PythonLauncher -// -// Created by Jack Jansen on Fri Jul 19 2002. -// Copyright (c) 2002 __MyCompanyName__. All rights reserved. -// - - -#import - -#import "FileSettings.h" - -@interface MyDocument : NSDocument -{ - IBOutlet NSTextField *interpreter; - IBOutlet NSButton *honourhashbang; - IBOutlet NSButton *debug; - IBOutlet NSButton *verbose; - IBOutlet NSButton *inspect; - IBOutlet NSButton *optimize; - IBOutlet NSButton *nosite; - IBOutlet NSButton *tabs; - IBOutlet NSTextField *others; - IBOutlet NSButton *with_terminal; - IBOutlet NSTextField *scriptargs; - IBOutlet NSTextField *commandline; - - NSString *script; - NSString *filetype; - FileSettings *settings; -} - -- (IBAction)do_run:(id)sender; -- (IBAction)do_cancel:(id)sender; -- (IBAction)do_reset:(id)sender; -- (IBAction)do_apply:(id)sender; - -- (void)controlTextDidChange:(NSNotification *)aNotification; - -@end diff --git a/Mac/OSX/PythonLauncher/MyDocument.m b/Mac/OSX/PythonLauncher/MyDocument.m deleted file mode 100755 index 5acc2dc..0000000 --- a/Mac/OSX/PythonLauncher/MyDocument.m +++ /dev/null @@ -1,175 +0,0 @@ -// -// MyDocument.m -// PythonLauncher -// -// Created by Jack Jansen on Fri Jul 19 2002. -// Copyright (c) 2002 __MyCompanyName__. All rights reserved. -// - -#import "MyDocument.h" -#import "MyAppDelegate.h" -#import "doscript.h" - -@implementation MyDocument - -- (id)init -{ - self = [super init]; - if (self) { - - // Add your subclass-specific initialization here. - // If an error occurs here, send a [self dealloc] message and return nil. - script = [@".py" retain]; - filetype = [@"Python Script" retain]; - settings = NULL; - } - return self; -} - -- (NSString *)windowNibName -{ - // Override returning the nib file name of the document - // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. - return @"MyDocument"; -} - -- (void)close -{ - NSApplication *app = [NSApplication sharedApplication]; - [super close]; - if ([[app delegate] shouldTerminate]) - [app terminate: self]; -} - -- (void)load_defaults -{ -// if (settings) [settings release]; - settings = [FileSettings newSettingsForFileType: filetype]; -} - -- (void)update_display -{ -// [[self window] setTitle: script]; - - [interpreter setStringValue: [settings interpreter]]; - [honourhashbang setState: [settings honourhashbang]]; - [debug setState: [settings debug]]; - [verbose setState: [settings verbose]]; - [inspect setState: [settings inspect]]; - [optimize setState: [settings optimize]]; - [nosite setState: [settings nosite]]; - [tabs setState: [settings tabs]]; - [others setStringValue: [settings others]]; - [scriptargs setStringValue: [settings scriptargs]]; - [with_terminal setState: [settings with_terminal]]; - - [commandline setStringValue: [settings commandLineForScript: script]]; -} - -- (void)update_settings -{ - [settings updateFromSource: self]; -} - -- (BOOL)run -{ - const char *cmdline; - int sts; - - cmdline = [[settings commandLineForScript: script] cString]; - if ([settings with_terminal]) { - sts = doscript(cmdline); - } else { - sts = system(cmdline); - } - if (sts) { - NSLog(@"Exit status: %d\n", sts); - return NO; - } - return YES; -} - -- (void)windowControllerDidLoadNib:(NSWindowController *) aController -{ - [super windowControllerDidLoadNib:aController]; - // Add any code here that need to be executed once the windowController has loaded the document's window. - [self load_defaults]; - [self update_display]; -} - -- (NSData *)dataRepresentationOfType:(NSString *)aType -{ - // Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead. - return nil; -} - -- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type; -{ - // Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead. - BOOL show_ui; - - // ask the app delegate whether we should show the UI or not. - show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI]; - [script release]; - script = [fileName retain]; - [filetype release]; - filetype = [type retain]; -// if (settings) [settings release]; - settings = [FileSettings newSettingsForFileType: filetype]; - if (show_ui) { - [self update_display]; - return YES; - } else { - [self run]; - [self close]; - return NO; - } -} - -- (IBAction)do_run:(id)sender -{ - [self update_settings]; - [self update_display]; - if ([self run]) - [self close]; -} - -- (IBAction)do_cancel:(id)sender -{ - [self close]; -} - - -- (IBAction)do_reset:(id)sender -{ - [settings reset]; - [self update_display]; -} - -- (IBAction)do_apply:(id)sender -{ - [self update_settings]; - [self update_display]; -} - -// FileSettingsSource protocol -- (NSString *) interpreter { return [interpreter stringValue];}; -- (BOOL) honourhashbang { return [honourhashbang state];}; -- (BOOL) debug { return [debug state];}; -- (BOOL) verbose { return [verbose state];}; -- (BOOL) inspect { return [inspect state];}; -- (BOOL) optimize { return [optimize state];}; -- (BOOL) nosite { return [nosite state];}; -- (BOOL) tabs { return [tabs state];}; -- (NSString *) others { return [others stringValue];}; -- (NSString *) scriptargs { return [scriptargs stringValue];}; -- (BOOL) with_terminal { return [with_terminal state];}; - -// Delegates -- (void)controlTextDidChange:(NSNotification *)aNotification -{ - [self update_settings]; - [self update_display]; -}; - -@end diff --git a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib deleted file mode 100644 index 467aa8b..0000000 --- a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/classes.nib +++ /dev/null @@ -1,26 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {"do_apply" = id; "do_filetype" = id; "do_reset" = id; }; - CLASS = PreferencesWindowController; - LANGUAGE = ObjC; - OUTLETS = { - commandline = NSTextField; - debug = NSButton; - filetype = NSPopUpButton; - honourhashbang = NSButton; - inspect = NSButton; - interpreter = NSTextField; - nosite = NSButton; - optimize = NSButton; - others = NSTextField; - tabs = NSButton; - verbose = NSButton; - "with_terminal" = NSButton; - }; - SUPERCLASS = NSWindowController; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib deleted file mode 100644 index bc558f7..0000000 --- a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/info.nib +++ /dev/null @@ -1,16 +0,0 @@ - - - - - IBDocumentLocation - 565 235 519 534 0 0 1280 1002 - IBFramework Version - 364.0 - IBOpenObjects - - 5 - - IBSystem Version - 7H63 - - diff --git a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib b/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib deleted file mode 100644 index 3dfed33..0000000 Binary files a/Mac/OSX/PythonLauncher/PreferenceWindow.nib/objects.nib and /dev/null differ diff --git a/Mac/OSX/PythonLauncher/PreferencesWindowController.h b/Mac/OSX/PythonLauncher/PreferencesWindowController.h deleted file mode 100644 index 6346996..0000000 --- a/Mac/OSX/PythonLauncher/PreferencesWindowController.h +++ /dev/null @@ -1,38 +0,0 @@ -/* PreferencesWindowController */ - -#import - -#import "FileSettings.h" - -@interface PreferencesWindowController : NSWindowController -{ - IBOutlet NSPopUpButton *filetype; - IBOutlet NSComboBox *interpreter; - IBOutlet NSButton *honourhashbang; - IBOutlet NSButton *debug; - IBOutlet NSButton *verbose; - IBOutlet NSButton *inspect; - IBOutlet NSButton *optimize; - IBOutlet NSButton *nosite; - IBOutlet NSButton *tabs; - IBOutlet NSTextField *others; - IBOutlet NSButton *with_terminal; - IBOutlet NSTextField *commandline; - - FileSettings *settings; -} - -+ getPreferencesWindow; - -- (IBAction)do_reset:(id)sender; -- (IBAction)do_apply:(id)sender; -- (IBAction)do_filetype:(id)sender; - -- (void)controlTextDidChange:(NSNotification *)aNotification; - -- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString; -- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index; -- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox; - - -@end diff --git a/Mac/OSX/PythonLauncher/PreferencesWindowController.m b/Mac/OSX/PythonLauncher/PreferencesWindowController.m deleted file mode 100644 index 311c375..0000000 --- a/Mac/OSX/PythonLauncher/PreferencesWindowController.m +++ /dev/null @@ -1,121 +0,0 @@ -#import "PreferencesWindowController.h" - -@implementation PreferencesWindowController - -+ getPreferencesWindow -{ - static PreferencesWindowController *_singleton; - - if (!_singleton) - _singleton = [[PreferencesWindowController alloc] init]; - [_singleton showWindow: _singleton]; - return _singleton; -} - -- (id) init -{ - self = [self initWithWindowNibName: @"PreferenceWindow"]; - return self; -} - -- (void)load_defaults -{ - NSString *title = [filetype titleOfSelectedItem]; - - settings = [FileSettings getDefaultsForFileType: title]; -} - -- (void)update_display -{ -// [[self window] setTitle: script]; - - [interpreter reloadData]; - [interpreter setStringValue: [settings interpreter]]; - [honourhashbang setState: [settings honourhashbang]]; - [debug setState: [settings debug]]; - [verbose setState: [settings verbose]]; - [inspect setState: [settings inspect]]; - [optimize setState: [settings optimize]]; - [nosite setState: [settings nosite]]; - [tabs setState: [settings tabs]]; - [others setStringValue: [settings others]]; - [with_terminal setState: [settings with_terminal]]; - // Not scriptargs, it isn't for preferences - - [commandline setStringValue: [settings commandLineForScript: @""]]; -} - -- (void) windowDidLoad -{ - [super windowDidLoad]; - [self load_defaults]; - [self update_display]; -} - -- (void)update_settings -{ - [settings updateFromSource: self]; -} - -- (IBAction)do_filetype:(id)sender -{ - [self load_defaults]; - [self update_display]; -} - -- (IBAction)do_reset:(id)sender -{ - [settings reset]; - [self update_display]; -} - -- (IBAction)do_apply:(id)sender -{ - [self update_settings]; - [self update_display]; -} - -// FileSettingsSource protocol -- (NSString *) interpreter { return [interpreter stringValue];}; -- (BOOL) honourhashbang { return [honourhashbang state]; }; -- (BOOL) debug { return [debug state];}; -- (BOOL) verbose { return [verbose state];}; -- (BOOL) inspect { return [inspect state];}; -- (BOOL) optimize { return [optimize state];}; -- (BOOL) nosite { return [nosite state];}; -- (BOOL) tabs { return [tabs state];}; -- (NSString *) others { return [others stringValue];}; -- (BOOL) with_terminal { return [with_terminal state];}; -- (NSString *) scriptargs { return @"";}; - -// Delegates -- (void)controlTextDidChange:(NSNotification *)aNotification -{ - [self update_settings]; - [self update_display]; -}; - -// NSComboBoxDataSource protocol -- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString -{ - NSArray *interp_list = [settings interpreters]; - unsigned int rv = [interp_list indexOfObjectIdenticalTo: aString]; - return rv; -} - -- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index -{ - NSArray *interp_list = [settings interpreters]; - id rv = [interp_list objectAtIndex: index]; - return rv; -} - -- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox -{ - NSArray *interp_list = [settings interpreters]; - int rv = [interp_list count]; - return rv; -} - - -@end diff --git a/Mac/OSX/PythonLauncher/doscript.h b/Mac/OSX/PythonLauncher/doscript.h deleted file mode 100644 index eef0b56..0000000 --- a/Mac/OSX/PythonLauncher/doscript.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * doscript.h - * PythonLauncher - * - * Created by Jack Jansen on Wed Jul 31 2002. - * Copyright (c) 2002 __MyCompanyName__. All rights reserved. - * - */ - -#include - -extern int doscript(const char *command); \ No newline at end of file diff --git a/Mac/OSX/PythonLauncher/doscript.m b/Mac/OSX/PythonLauncher/doscript.m deleted file mode 100644 index 3e4e223..0000000 --- a/Mac/OSX/PythonLauncher/doscript.m +++ /dev/null @@ -1,118 +0,0 @@ -/* - * doscript.c - * PythonLauncher - * - * Created by Jack Jansen on Wed Jul 31 2002. - * Copyright (c) 2002 __MyCompanyName__. All rights reserved. - * - */ - -#import -#import -#import "doscript.h" - -/* I assume I could pick these up from somewhere, but where... */ -#define CREATOR 'trmx' - -#define ACTIVATE_CMD 'misc' -#define ACTIVATE_SUITE 'actv' - -#define DOSCRIPT_CMD 'dosc' -#define DOSCRIPT_SUITE 'core' -#define WITHCOMMAND 'cmnd' - -/* ... and there's probably also a better way to do this... */ -#define START_TERMINAL "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal &" - -extern int -doscript(const char *command) -{ - OSErr err; - AppleEvent theAEvent, theReply; - AEAddressDesc terminalAddress; - AEDesc commandDesc; - OSType terminalCreator = CREATOR; - - /* set up locals */ - AECreateDesc(typeNull, NULL, 0, &theAEvent); - AECreateDesc(typeNull, NULL, 0, &terminalAddress); - AECreateDesc(typeNull, NULL, 0, &theReply); - AECreateDesc(typeNull, NULL, 0, &commandDesc); - - /* create the "activate" event for Terminal */ - err = AECreateDesc(typeApplSignature, (Ptr) &terminalCreator, - sizeof(terminalCreator), &terminalAddress); - if (err != noErr) { - NSLog(@"doscript: AECreateDesc: error %d\n", err); - goto bail; - } - err = AECreateAppleEvent(ACTIVATE_SUITE, ACTIVATE_CMD, - &terminalAddress, kAutoGenerateReturnID, - kAnyTransactionID, &theAEvent); - - if (err != noErr) { - NSLog(@"doscript: AECreateAppleEvent(activate): error %d\n", err); - goto bail; - } - /* send the event */ - err = AESend(&theAEvent, &theReply, kAEWaitReply, - kAENormalPriority, kAEDefaultTimeout, NULL, NULL); - if ( err == -600 ) { - int count=10; - /* If it failed with "no such process" try to start Terminal */ - err = system(START_TERMINAL); - if ( err ) { - NSLog(@"doscript: system(): %s\n", strerror(errno)); - goto bail; - } - do { - sleep(1); - /* send the event again */ - err = AESend(&theAEvent, &theReply, kAEWaitReply, - kAENormalPriority, kAEDefaultTimeout, NULL, NULL); - } while (err == -600 && --count > 0); - if ( err == -600 ) - NSLog(@"doscript: Could not activate Terminal\n"); - } - if (err != noErr) { - NSLog(@"doscript: AESend(activate): error %d\n", err); - goto bail; - } - - /* create the "doscript with command" event for Terminal */ - err = AECreateAppleEvent(DOSCRIPT_SUITE, DOSCRIPT_CMD, - &terminalAddress, kAutoGenerateReturnID, - kAnyTransactionID, &theAEvent); - if (err != noErr) { - NSLog(@"doscript: AECreateAppleEvent(doscript): error %d\n", err); - goto bail; - } - - /* add the command to the apple event */ - err = AECreateDesc(typeChar, command, strlen(command), &commandDesc); - if (err != noErr) { - NSLog(@"doscript: AECreateDesc(command): error %d\n", err); - goto bail; - } - err = AEPutParamDesc(&theAEvent, WITHCOMMAND, &commandDesc); - if (err != noErr) { - NSLog(@"doscript: AEPutParamDesc: error %d\n", err); - goto bail; - } - - /* send the command event to Terminal.app */ - err = AESend(&theAEvent, &theReply, kAEWaitReply, - kAENormalPriority, kAEDefaultTimeout, NULL, NULL); - - if (err != noErr) { - NSLog(@"doscript: AESend(docommand): error %d\n", err); - goto bail; - } - /* clean up and leave */ -bail: - AEDisposeDesc(&commandDesc); - AEDisposeDesc(&theAEvent); - AEDisposeDesc(&terminalAddress); - AEDisposeDesc(&theReply); - return err; -} diff --git a/Mac/OSX/PythonLauncher/factorySettings.plist b/Mac/OSX/PythonLauncher/factorySettings.plist deleted file mode 100644 index 1202421..0000000 --- a/Mac/OSX/PythonLauncher/factorySettings.plist +++ /dev/null @@ -1,87 +0,0 @@ - - - - - Python GUI Script - - debug - - inspect - - interpreter_list - - /usr/local/bin/pythonw - /usr/bin/pythonw - /sw/bin/pythonw - - honourhashbang - - nosite - - optimize - - others - - verbose - - with_terminal - - - Python Script - - debug - - inspect - - interpreter_list - - /usr/local/bin/pythonw - /usr/local/bin/python - /usr/bin/pythonw - /usr/bin/python - /sw/bin/pythonw - /sw/bin/python - - honourhashbang - - nosite - - optimize - - others - - verbose - - with_terminal - - - Python Bytecode Document - - debug - - inspect - - interpreter_list - - /usr/local/bin/pythonw - /usr/local/bin/python - /usr/bin/pythonw - /usr/bin/python - /sw/bin/pythonw - /sw/bin/python - - honourhashbang - - nosite - - optimize - - others - - verbose - - with_terminal - - - - diff --git a/Mac/OSX/PythonLauncher/main.m b/Mac/OSX/PythonLauncher/main.m deleted file mode 100755 index 6841433..0000000 --- a/Mac/OSX/PythonLauncher/main.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// main.m -// PythonLauncher -// -// Created by Jack Jansen on Fri Jul 19 2002. -// Copyright (c) 2002 __MyCompanyName__. All rights reserved. -// - -#import -#include - -int main(int argc, const char *argv[]) -{ - char *home = getenv("HOME"); - if (home) chdir(home); - return NSApplicationMain(argc, argv); -} diff --git a/Mac/OSX/README b/Mac/OSX/README deleted file mode 100644 index 1e58b02..0000000 --- a/Mac/OSX/README +++ /dev/null @@ -1,167 +0,0 @@ -============ -MacOSX Notes -============ - -This document provides a quick overview of some Mac OS X specific features in -the Python distribution. - - -Building and using a universal binary of Python on Mac OS X -=========================================================== - -1. What is a universal binary ------------------------------ - -A universal binary build of Python contains object code for both PPC and i386 -and can therefore run at native speed on both classic powerpc based macs and -the newer intel based macs. - -2. How do I build a universal binary ------------------------------------- - -You can enable universal binaries by specifying the "--enable-universalsdk" -flag to configure:: - - $ ./configure --enable-universalsdk - $ make - $ make install - -This flag can be used a framework build of python, but also with a classic -unix build. Either way you will have to build python on Mac OS X 10.4 (or later) -with Xcode 2.1 (or later). You also have to install the 10.4u SDK when -installing Xcode. - - -Building and using a framework-based Python on Mac OS X. -======================================================== - - -1. Why would I want a framework Python instead of a normal static Python? --------------------------------------------------------------------------- - -The main reason is because you want to create GUI programs in Python. With the -exception of X11/XDarwin-based GUI toolkits all GUI programs need to be run -from a fullblown MacOSX application (a ".app" bundle). - -While it is technically possible to create a .app without using frameworks you -will have to do the work yourself if you really want this. - -A second reason for using frameworks is that they put Python-related items in -only two places: "/Library/Framework/Python.framework" and -"/Applications/MacPython 2.5". This simplifies matters for users installing -Python from a binary distribution if they want to get rid of it again. Moreover, -due to the way frameworks work a user without admin privileges can install a -binary distribution in his or her home directory without recompilation. - -2. How does a framework Python differ from a normal static Python? ------------------------------------------------------------------- - -In everyday use there is no difference, except that things are stored in -a different place. If you look in /Library/Frameworks/Python.framework -you will see lots of relative symlinks, see the Apple documentation for -details. If you are used to a normal unix Python file layout go down to -Versions/Current and you will see the familiar bin and lib directories. - -3. Do I need extra packages? ----------------------------- - -Yes, probably. If you want Tkinter support you need to get the OSX AquaTk -distribution, this is installed by default on Mac OS X 10.4 or later. If -you want wxPython you need to get that. If you want Cocoa you need to get -PyObjC. - -4. How do I build a framework Python? -------------------------------------- - -This directory contains a Makefile that will create a couple of python-related -applications (fullblown OSX .app applications, that is) in -"/Applications/MacPython 2.3", and a hidden helper application Python.app -inside the Python.framework, and unix tools "python" and "pythonw" into -/usr/local/bin. In addition it has a target "installmacsubtree" that installs -the relevant portions of the Mac subtree into the Python.framework. - -It is normally invoked indirectly through the main Makefile, as the last step -in the sequence - - 1. ./configure --enable-framework - - 2. make - - 3. make install - -This sequence will put the framework in /Library/Framework/Python.framework, -the applications in /Applications/MacPython 2.5 and the unix tools in -/usr/local/bin. - -Installing in another place, for instance $HOME/Library/Frameworks if you have -no admin privileges on your machine, has only been tested very lightly. This -can be done by configuring with --enable-framework=$HOME/Library/Frameworks. -The other two directories, /Applications/MacPython-2.3 and /usr/local/bin, will -then also be deposited in $HOME. This is sub-optimal for the unix tools, which -you would want in $HOME/bin, but there is no easy way to fix this right now. - -Note that there are no references to the actual locations in the code or -resource files, so you are free to move things around afterwards. For example, -you could use --enable-framework=/tmp/newversion/Library/Frameworks and use -/tmp/newversion as the basis for an installer or something. - -If you want to install some part, but not all, read the main Makefile. The -frameworkinstall is composed of a couple of sub-targets that install the -framework itself, the Mac subtree, the applications and the unix tools. - -There is an extra target frameworkinstallextras that is not part of the -normal frameworkinstall which installs the Demo and Tools directories -into /Applications/MacPython-2.3, this is useful for binary distributions. - -What do all these programs do? -=============================== - -"IDLE.app" is an integrated development environment for Python: editor, -debugger, etc. - -"PythonLauncher.app" is a helper application that will handle things when you -double-click a .py, .pyc or .pyw file. For the first two it creates a Terminal -window and runs the scripts with the normal command-line Python. For the -latter it runs the script in the Python.app interpreter so the script can do -GUI-things. Keep the "alt" key depressed while dragging or double-clicking a -script to set runtime options. These options can be set once and for all -through PythonLauncher's preferences dialog. - -"BuildApplet.app" creates an applet from a Python script. Drop the script on it -and out comes a full-featured MacOS application. There is much more to this, -to be supplied later. Some useful (but outdated) info can be found in -Mac/Demo. - -The commandline scripts /usr/local/bin/python and pythonw can be used to run -non-GUI and GUI python scripts from the command line, respectively. - -How do I create a binary distribution? -====================================== - -Go to the directory "Mac/OSX/BuildScript". There you'll find a script -"build-installer.py" that does all the work. This will download and build -a number of 3th-party libaries, configures and builds a framework Python, -installs it, creates the installer pacakge files and then packs this in a -DMG image. - -The script will build a universal binary, you'll therefore have to run this -script on Mac OS X 10.4 or later and with Xcode 2.1 or later installed. - -All of this is normally done completely isolated in /tmp/_py, so it does not -use your normal build directory nor does it install into /. - -Because of the way the script locates the files it needs you have to run it -from within the BuildScript directory. The script accepts a number of -command-line arguments, run it with --help for more information. - -Odds and ends -============= - -Something to take note of is that the ".rsrc" files in the distribution are -not actually resource files, they're AppleSingle encoded resource files. The -macresource module and the Mac/OSX/Makefile cater for this, and create -".rsrc.df.rsrc" files on the fly that are normal datafork-based resource -files. - - Jack Jansen, Jack.Jansen@cwi.nl, 15-Jul-2004. - Ronald Oussoren, RonaldOussoren@mac.com, 26-May-2006 diff --git a/Mac/OSX/Tools/pythonw.c b/Mac/OSX/Tools/pythonw.c deleted file mode 100644 index e70a76f..0000000 --- a/Mac/OSX/Tools/pythonw.c +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This wrapper program executes a python executable hidden inside an - * application bundle inside the Python framework. This is needed to run - * GUI code: some GUI API's don't work unless the program is inside an - * application bundle. - */ -#include -#include - -static char Python[] = PYTHONWEXECUTABLE; - -int main(int argc, char **argv) { - argv[0] = Python; - execv(Python, argv); - err(1, "execv: %s", Python); - /* NOTREACHED */ -} diff --git a/Mac/OSX/fixapplepython23.py b/Mac/OSX/fixapplepython23.py deleted file mode 100644 index 181181e..0000000 --- a/Mac/OSX/fixapplepython23.py +++ /dev/null @@ -1,118 +0,0 @@ -"""fixapplepython23 - Fix Apple-installed Python 2.3 (on Mac OS X 10.3) - -Python 2.3 (and 2.3.X for X<5) have the problem that building an extension -for a framework installation may accidentally pick up the framework -of a newer Python, in stead of the one that was used to build the extension. - -This script modifies the Makefile (in .../lib/python2.3/config) to use -the newer method of linking extensions with "-undefined dynamic_lookup" -which fixes this problem. - -The script will first check all prerequisites, and return a zero exit -status also when nothing needs to be fixed. -""" -import sys -import os -import gestalt - -MAKEFILE='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/Makefile' -CHANGES=(( - 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n', - 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n' - ),( - 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n', - 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n' - ),( - 'CC=\t\tgcc\n', - 'CC=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc\n' - ),( - 'CXX=\t\tc++\n', - 'CXX=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++\n' -)) - -GCC_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc' -GXX_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++' -SCRIPT="""#!/bin/sh -export MACOSX_DEPLOYMENT_TARGET=10.3 -exec %s "${@}" -""" - -def findline(lines, start): - """return line starting with given string or -1""" - for i in range(len(lines)): - if lines[i][:len(start)] == start: - return i - return -1 - -def fix(makefile, do_apply): - """Fix the Makefile, if required.""" - fixed = False - lines = open(makefile).readlines() - - for old, new in CHANGES: - i = findline(lines, new) - if i >= 0: - # Already fixed - continue - i = findline(lines, old) - if i < 0: - print 'fixapplepython23: Python installation not fixed (appears broken)' - print 'fixapplepython23: missing line:', old - return 2 - lines[i] = new - fixed = True - - if fixed: - if do_apply: - print 'fixapplepython23: Fix to Apple-installed Python 2.3 applied' - os.rename(makefile, makefile + '~') - open(makefile, 'w').writelines(lines) - return 0 - else: - print 'fixapplepython23: Fix to Apple-installed Python 2.3 should be applied' - return 1 - else: - print 'fixapplepython23: No fix needed, appears to have been applied before' - return 0 - -def makescript(filename, compiler): - """Create a wrapper script for a compiler""" - dirname = os.path.split(filename)[0] - if not os.access(dirname, os.X_OK): - os.mkdir(dirname, 0755) - fp = open(filename, 'w') - fp.write(SCRIPT % compiler) - fp.close() - os.chmod(filename, 0755) - print 'fixapplepython23: Created', filename - -def main(): - # Check for -n option - if len(sys.argv) > 1 and sys.argv[1] == '-n': - do_apply = False - else: - do_apply = True - # First check OS version - if gestalt.gestalt('sysv') < 0x1030: - print 'fixapplepython23: no fix needed on MacOSX < 10.3' - sys.exit(0) - # Test that a framework Python is indeed installed - if not os.path.exists(MAKEFILE): - print 'fixapplepython23: Python framework does not appear to be installed (?), nothing fixed' - sys.exit(0) - # Check that we can actually write the file - if do_apply and not os.access(MAKEFILE, os.W_OK): - print 'fixapplepython23: No write permission, please run with "sudo"' - sys.exit(2) - # Create the shell scripts - if do_apply: - if not os.access(GCC_SCRIPT, os.X_OK): - makescript(GCC_SCRIPT, "gcc") - if not os.access(GXX_SCRIPT, os.X_OK): - makescript(GXX_SCRIPT, "g++") - # Finally fix the makefile - rv = fix(MAKEFILE, do_apply) - sys.exit(rv) - -if __name__ == '__main__': - main() diff --git a/Mac/OSXResources/app/Info.plist b/Mac/OSXResources/app/Info.plist deleted file mode 100644 index 387bbed..0000000 --- a/Mac/OSXResources/app/Info.plist +++ /dev/null @@ -1,60 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleDocumentTypes - - - CFBundleTypeOSTypes - - **** - fold - disk - - CFBundleTypeRole - Viewer - - - CFBundleExecutable - Python - CFBundleGetInfoString - 2.5alpha0, (c) 2004 Python Software Foundation. - CFBundleHelpBookFolder - - Documentation - PythonDocumentation - - CFBundleHelpBookName - MacPython Help - CFBundleHelpTOCFile - index.html - CFBundleIconFile - PythonInterpreter.icns - CFBundleIdentifier - org.python.python - CFBundleInfoDictionaryVersion - 6.0 - CFBundleLongVersionString - 2.5alpha0, (c) 2004 Python Software Foundation. - CFBundleName - Python - CFBundlePackageType - APPL - CFBundleShortVersionString - 2.5alpha0 - CFBundleSignature - PytX - CFBundleVersion - 2.5alpha0 - CSResourcesFileMapped - - LSRequiresCarbon - - NSAppleScriptEnabled - - NSHumanReadableCopyright - (c) 2004 Python Software Foundation. - - diff --git a/Mac/OSXResources/app/PkgInfo b/Mac/OSXResources/app/PkgInfo deleted file mode 100644 index 67c491a..0000000 --- a/Mac/OSXResources/app/PkgInfo +++ /dev/null @@ -1 +0,0 @@ -APPLPytX \ No newline at end of file diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/PackageManager.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/PackageManager.gif deleted file mode 100644 index 2b93dc8..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/PackageManager.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/community.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/community.html deleted file mode 100644 index 140a38b..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/community.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - What is MacPython? - - - - - - - - - - -
    - - -

    MacPython Community

    -
    -
    - -

    Web Sites

    - -

    The MacPython homepage, -www.cwi.nl/~jack/macpython.html -is where you can find installers, documents, links to useful packages and more. -And, of course, -www.python.org has a much larger collection -of material on Python that is not Mac-specific.

    - -

    News groups and Mailing lists

    - -

    There are a lot of mailing lists on Python. Some of the more interesting -ones are:

    -
      -
    • python-help@python.org where -you can send questions for individual support. Please check the websites mentioned -above first, though!
    • -
    • The comp.lang.python newsgroup for general -discussion. Also available as a -mailing list.
    • -
    • The comp.lang.python.announce -newsgroup for announcements. Low-volume and moderated. Also available as a -mailing list.
    • -
    • Last but not least, the pythonmac-sig -mailing list is specifically for MacPython. Discussions on the implementation of new -features, but beginners questions are welcome too.
    • -
    - -

    In addition there are Python Special Interest Group -mailing lists on a wide variety of topics such as image processing, numerical algorithms -and more.

    - -

    More

    - -

    An index of conferences, Wiki's, bookshops and more can be found at the -Community section of the Python website.

    - -

    If you find a bug you are kindly requested to report it, preferrably through the -automatic bug tracker at www.python.org

    - -

    If you want to become an active developer you are very welcome! Join the -pythonmac-sig mailing list mentioned above, and read the -Developer section on the Python website.

    - - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/doc/index.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/doc/index.html deleted file mode 100644 index 2ce7357..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/doc/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Python Language Documentation - - - -

    Python Language and runtime documentation

    - -

    This volume of documentation is rather big (17 Megabytes) and contains -a tutorial, full description of the Python library (all the modules -and packages included), formal description of the language and more.

    - -

    You can view it online, where -you can also download PDFs for printing, or you can download and install it -through the Package Manager for viewing and -searching via Apple Help Viewer.

    - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/finder.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/finder.html deleted file mode 100644 index a8877ba..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/finder.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - Python and the Finder - - - - - -

    Running Python scripts from the Finder

    - - - - - -
    - - -

    The application PythonLauncher will start a Python interpreter - when you drop a Python source file onto it, any file with a .py - or .pyw extension. If you set PythonLauncher as the default - application to open a file -( -tell me more) this also works when you double click a Python script.

    - -

    PythonLauncher has preferences per filetype for selecting - the interpreter to use, and how to launch it: in a Terminal window - or not, etc. Holding the Option key while launching your script will - bring up a window that allows changing these settings for a single - run.

    -
    -
    - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/gui.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/gui.html deleted file mode 100644 index 252c78c..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/gui.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - - Creating a User Interface with MacPython - - - - - -

    Creating a User Interface with MacPython

    - -

    There are a number of packages that allow creation of a user interface -for your Python code, each of which has its own merits:

    - -
      -
    • The Carbon package gives low-level access to the old Macintosh toolbox - calls for windows, events, dialogs and more. The FrameWork module - wraps these in a minimal framework. For documentation see the Macintosh - Library section of the Python Language and runtime - documentation and the Human Interface Toolbox section of - Apple's Carbon Documentation. - This solution is compatible with MacPython-OS9.
    • -
    • The W framework is built on top of this, and easier to use. - The MacPython IDE uses W. Some documentation is available on - Corran Webster's website. - Compatible with MacPython-OS9.
    • -
    - -

    For new work, however, one of the following packages may be better suited. -They may be available out of the box in this distribution, otherwise you -can install them through the Package Manager:

    - -
      -
    • PyObjC allows complete access to Cocoa. - In technical terms it is a - bidirectional bridge between Python and Objectve-C, similar to Apple's Java - bridge. Probably the best choice for Mac OS X-only applications, but at the - time of this writing PyObjC is still in beta.
    • - -
    • wxPython gives Python programs - access to the wxWindows GUI toolkit. Many people consider this - the best open source cross-platform GUI solution available today.
    • - -
    • Tkinter is the oldest cross-platform GUI toolkit for Python, bridging Python - to Tcl/Tk. If you install AquaTk it creates a native user interface on Mac OS X. - Documented in the Library section, Tkinter subsection of the - Python Language and runtime documentation. Tkinter - is not available for MacPython-OS9.
    • -
    - - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/IDE.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/IDE.gif deleted file mode 100644 index da9325d..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/IDE.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif deleted file mode 100644 index baa400e..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/hello_world.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/hello_world.gif deleted file mode 100644 index c7390af..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/hello_world.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/index.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/index.html deleted file mode 100644 index a169f5e..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/index.html +++ /dev/null @@ -1,222 +0,0 @@ - - - - One Day of MacPython IDE Toying - - - - -

    One Day of MacPython IDE Toying

    - - - - - -
    - - -

    This document gives a very basic introduction to the - MacPython Integrated Development Environment (IDE) on Mac OS. It was - written specifically for MacPython 2.3 on Mac OS X, but most of - it is applicable to MacPython-OS9 too. It is based on - "One - Day of IDLE Toying" by Danny Yoo, which you should read if - you want to use the cross-platform IDLE Python development - environment.

    - -
    -
    -
    - -

    Ok, let's assume that we've already installed Python. (If not, we can -visit: http://www.cwi.nl/~jack/macpython.html -or http://python.org -and download the most recent Python interpreter. Get the Mac OSX binary -installer.) The first thing we'd like to do is actually start running it! -We can do this by opening up the IDE, which should be in Applications -under the newly-created MacPython program folder:

    image of IDE icon

    - -

    - -

    The IDE starts up and shows an interactive window:

    -

    image of new window

    - -

    If the window does not show up (because you have run the IDE before -and closed it: it remembers that between runs) open it with the Windows->Python Interactive -menu entry.

    - -

    This is the interactive window to the IDE, it allows us to enter -commands directly into Python, and as soon as we enter a command, -Python will execute it and spit its result back to us. We'll be -using this interactive window a lot when we're exploring Python: it's -very nice because we get back our results immediately. If it helps, -we can think of it as a very powerful calculator.

    - -

    - -

    Let's try something now! As per tradition, let's get Python to say -the immortal words, "Hello World". image of hello world program

    Those '>>>' signs act as a prompt -for us: Python is ready to read in a new command by giving us that -visual cue. Also, we notice that as we enter commands, Python will -give us its output immediately. -

    - -

    - -

    Ok, this seems pretty simple enough. Let's try a few more -commands. If we look below:

    - -

    image of command window

    - -

    we'll see the result of running a few more commands. Don't worry -too much about knowing the exact rules for making programs yet: the -idea is that we can experiment with Python by typing in commands. If -things don't work, then we can correct the mistake, and try it -again.

    - -

    If you got to this point, you now know enough to start playing -around with Python! Crack open one of the tutorials from the Python For Beginners web -page, and start exploring with the interpreter. No time limit here. *grin*

    - -

    - -

    Now that we've paddled long enough, we might be asking: ok, this is -neat, but if we close down Python and start it up again, how do we get -the computer to remember what we typed?

    - -

    The solution is a little subtle: we can't directly save what's in -the interpreter window, because it will include both our commands and -the system's responses. What we'd like is to make a prepared file, -with just our own commands, and to be able to save that file as a -document. When we're in the mood, we can later open that file and -"run" Python over it, saving us the time of retyping the whole -thing over again.

    - -

    Let's try this. First, let's start with a clean slate by opening -up a new window.

    - -

    image of making new window

    - -

    Here's the result of that menu command:

    - -

    image of new window

    - -

    We notice that there's nothing in this new window. What this means -is that this file is purely for our commands: Python won't interject -with its own responses as we enter the program, that is, not until we -tell it to. This is called an edit window, and it is very similar -to edit windows in other editors such as TextEdit or BBEdit.

    - -

    - -

    What we wanted to do before was save some of the stuff we had -tried out on the interpreter window. Let's do that by typing (or -copy/pasting) those commands into our edit window.

    -

    image of entering commands

    - -

    Ok, we're done with copying and pasting. -One big thing to notice -is that we're careful to get rid of the ">>>" -prompts because they're not really part of our program. The -interpreter uses them just to tell us that we're in the interpreter, -but now that we're editing in a separate file, we can remove the -artifacts that the interpreter introduces. -I have added -an extra empty print statement so our output ends with a newline. -

    - -

    - -

    Let's save the file now. The Save command is located under the File menu:

    -

    image of saving file

    - - -

    - -

    Now that we've saved the program, how do we run the program? Use the -Run All button at the top of the editing window, or the equivalent -menu command Python->Run Window. The output will appear in a new -window called Output Window.

    - -

    By the way, one thing to notice is that I made a typo: I didn't -quite copy exactly what I had entered in the interpreter window -before. Does this affect things?

    - -

    image of syntax error

    - -

    Ooops. Here is an example of what Python calls a "syntax error". -Python sees that we made a typo, and warns us to take a much closer -look at our program. The designers of Python feel that having the -system point out the error is better than trying to guess at what the -programmer meant. Press the Edit button and you will be brought to -the trouble spot.

    - -

    Python is often perceptive enough to direct us toward the problem, -and in this case, it's telling us that we forgot to put something at -the end of this line. In this case, we need to add a -quotation mark at the end. Let's add that in now.

    - -

    Other errors, which usually occur later, when your program has -already done something, result in a different dialog that allows you -to look at variables and such in addition to showing you where -the error occurred.

    - -

    - -

    Ok, let's say that we fixed that silly typo. Let's try to run the -program again. This gives us a new window, the Output window, showing -the output of our program:

    -

    image of output window

    - -

    - -

    As we play with Python, we'll find ourselves "switching modes" -between the Interpreter window and the edit window. However, -if we try anything more complicated than two or three lines it -is often a good idea to work in an edit window. Align -your edit and output window such that you can see them at the same time.

    - -

    This is pretty much all we need to know about the MacPython IDE to actually do -interesting things. There is a lot more to the IDE, here is a quick -breakdown of things to see and explore:

    - -
      -
    • All sorts of edit commands such as find and replace can be - used in the editor windows. See the Edit menu.
    • - -
    • The bottom of the edit window has the scrollbar, but at the - left are two navigation devices: a line number box that you can type - numbers into to quickly go to a specific place, and a popup menu - that lists all classes, functions and methods in your file.
    • - -
    • Above the vertical scrollbar you find another popup menu, this - influences how the Run command works. You should try the debugger - some time! If you do, and you wonder what the new small column on - the left of your script is: you can click in it to make Python stop - when it reaches this line so you can inspect things. The profiler - is also nifty: it shows you where your program is spending its time.
    • - -
    • The module browser (Python->Module Browser) shows you all Python - modules currently loaded. You can look at the contents of the module with - Browse... and (for modules written in Python) at the source with Source...
    • - -
    • The Package Manager (under the File menu, also available as a - separate application) allows you to easily install Python extension packages - for all sorts of things: scientific computation, image processing, - building user interfaces and more.
    • - -
    • The Help menu gives you quick access to both the Python documentation, - if you have installed it with the Package Manager, and the Apple Developer - documentation.
    • - -
    • The File->Save as Applet menu command saves your script as a MacOSX - application. This allows you to create a script that you can drop files on, - and much more. The IDE itself is such an applet, completely written in Python.
    • - -
    - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif deleted file mode 100644 index e7cca3d..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif deleted file mode 100644 index d2022c8..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif deleted file mode 100644 index 7268a84..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif deleted file mode 100644 index dd6cca3..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/output_window.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/output_window.gif deleted file mode 100644 index 568dcb5..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/output_window.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif deleted file mode 100644 index 6e5c926..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif deleted file mode 100644 index 1dba570..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif deleted file mode 100644 index 2e95b87..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/index.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/index.html deleted file mode 100644 index ef12c10..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/index.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - MacPython Help - - - - - - - -

    MacPython Help

    - - - - - -
    - - -

    Choose a topic, or enter keywords into the search field:

    - - -
    -
    - - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/intro.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/intro.html deleted file mode 100644 index f0ab371..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/intro.html +++ /dev/null @@ -1,76 +0,0 @@ - - - - - What is MacPython? - - - - - -

    What is MacPython?

    - - - - - -
    - - -

    Python is a programming language. MacPython is a package containing -that programming language plus Mac-specific tools and extensions.

    - -
    -
    - -

    The Python Language

    -

    The Python programming language is available for many hardware -platforms, and most general documentation is Unix- or Windows-centered. Keep -this in mind when reading the rest of this help, or information on the web. -

    - -

    The Python website, www.python.org, -has a Beginners Guide section including an -executive summary on -the language and a -comparison of Python -to other languages. Or read the (rather longwinded) Python -Tutorial in the Python Language and runtime documentation.

    - -

    MacPython contains a complete unix interpreter so -if you are familiar with Python on unix you should feel right at home.

    - -

    MacPython additions

    - -

    The MacPython Integrated Development Environment (IDE) allows -easy editing, running and debugging of scripts. Read the -Introduction -to the IDE to whet your appetite.

    - -

    MacPython comes with lots of modules that allow access to -MacOS-specific technology, such as Carbon, Quicktime and AppleScript. -See the Macintosh -Modules section of the -Python Language and runtime documentation, -but please keep in mind that some information there still pertains to -Mac OS 9. - -Full access to the Cocoa APIs -and tools such as Interface Builder is available separately through the -Package Manager.

    - -

    The Package Manager also gives you access to extension -packages for cross-platform GUI development (Tkinter, wxPython, PyOpenGL), -image processing (PIL), scientific -computing (Numeric) and much more. PyObjC deserves a special mention: it allows -transparent access to Cocoa and Interface Builder, similar to what Java provides, -thereby making Python a first class citizen in the Mac OS X developer world.

    - -

    Python scripts can be saved as applets, semi-standalone applications -that work just like a normal application. Additionally you can even create -true standalone application that have everything embedded and can be -shipped to anyone, without the need to install Python. You do not -need to install the Apple Developer Tools for this.

    - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/packman.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/packman.html deleted file mode 100644 index 355e0da..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/packman.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - Python Package Manager - - - - - -

    Installing additional Python Packages

    - - - - - -
    - - -

    The Python Package Manager helps you installing additional - packages that enhance Python. It determines the exact MacOS version - and Python version you have and uses that information to download - a database that has packages that are test and tried on that - combination. In other words: if something is in your Package Manager - window but does not work you are free to blame the database maintainer.

    - -

    PackageManager then checks which of the packages you have installed - and which ones not. This should also work when you have installed packages - outside of PackageManager. - You can select packages and install them, and PackageManager will work - out the requirements and install these too.

    - -

    Often PackageManager will list a package in two flavors: binary - and source. Binary should always work, source will only work if - you have installed the Apple Developer Tools. PackageManager will warn - you about this, and also about other external dependencies.

    - -

    PackageManager is available as a separate application and also - as a function of the IDE, through the File->Package Manager menu - entry.

    - -

    Troubleshooting

    - -

    If package manager fails to open the database first check that you are - connected to the internet. If you are connected then the problem - could be that there is no database (yet?) for your version of Mac OS X. - You may be able to find an alternative - database that works for your system at - http://www.python.org/packman. - In the standalone Package Manager you can then open such an alternative database - with the File->Open URL... command, but you should realize that - you are now on untested ground.

    - -

    Another potential problem source is that you are behind a firewall. This version - of PackageManager uses the Unix method of setting a firewall: you need to set the - environment variable http_proxy to "http://proxyhost:port". - See Apple Technical - Q&A QA1067 for instructions.

    - -
    -
    - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/python.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/python.gif deleted file mode 100644 index 3d4aa5d..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/python.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/pythonsmall.gif b/Mac/OSXResources/app/Resources/English.lproj/Documentation/pythonsmall.gif deleted file mode 100644 index 440225e..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/Documentation/pythonsmall.gif and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/scripting.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/scripting.html deleted file mode 100644 index 16321cb..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/scripting.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - - Controlling other Applications from MacPython - - - - - -

    Controlling other Applications from MacPython

    - -

    Python has a fairly complete implementation of the Open Scripting -Architecure (OSA, also commonly referred to as AppleScript), allowing -you to control scriptable applications from your Python program, -and with a fairly pythonic interface. This piece of -Python:

    - -
    
    -import Finder
    -
    -f = Finder.Finder()
    -print f.get(f.window(1).name)
    -
    - -

    is identical to the following piece of AppleScript:

    - -
    
    -tell application "Finder"
    -	get name of window 1
    -end tell
    -
    - -

    To send AppleEvents to an application you must first create the Python -modules interfacing to the terminology of the application (what -Script Editor calls the "Dictionary"). Use the IDE menu command -File->Generate OSA Suite... for this. For more control run

    - -
    -pythonw .../Lib/plat-mac/gensuitemodule.py --help -
    - -

    from a terminal window.

    - -

    Creating a scriptable application in Python

    - -You can also create a scriptable application in Python, but this is not -very well documented. For Carbon -applications you should look at the MiniAEFrame module. - - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/Documentation/shell.html b/Mac/OSXResources/app/Resources/English.lproj/Documentation/shell.html deleted file mode 100644 index 56f5646..0000000 --- a/Mac/OSXResources/app/Resources/English.lproj/Documentation/shell.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - Python and the Unix Shell - - - - - -

    Running Python scripts from the Unix Shell

    - - - - - -
    - - -

    MacPython 2.3 installs a perfectly normal Unix commandline - python interpreter in /usr/local/bin/python. As of Mac OS X 10.2, however, - /usr/local/bin is not on the search path of your shell. Moreover, - Apple's python 2.2, which lives in /usr/bin is on your - search path, so this can lead to confusion.

    - -

    If you use tcsh you should add the following line - to the file .login in your home directory and restart Terminal: -
    - setenv PATH /usr/local/bin:$PATH -

    - -

    If you use bash or zsh - you should add the following line - to the file .profile in your home directory and restart Terminal: -
    - export PATH=/usr/local/bin:$PATH -

    - -

    GUI scripts

    - -

    Due to the way MacOS handles windowing applications you need to run - all scripts that use the window manager (be it through - Carbon, Cocoa, Tkinter, wxPython, PyOpenGL or anything else) with the - pythonw interpreter, also installed in /usr/local/bin.

    - -

    Running with python results in an inability to bring the - script to the front, or interacting with it.

    -
    -
    - - diff --git a/Mac/OSXResources/app/Resources/English.lproj/InfoPlist.strings b/Mac/OSXResources/app/Resources/English.lproj/InfoPlist.strings deleted file mode 100644 index f8a8bc1..0000000 Binary files a/Mac/OSXResources/app/Resources/English.lproj/InfoPlist.strings and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/PythonApplet.icns b/Mac/OSXResources/app/Resources/PythonApplet.icns deleted file mode 100644 index c8aad9f..0000000 Binary files a/Mac/OSXResources/app/Resources/PythonApplet.icns and /dev/null differ diff --git a/Mac/OSXResources/app/Resources/PythonInterpreter.icns b/Mac/OSXResources/app/Resources/PythonInterpreter.icns deleted file mode 100644 index e09fd38..0000000 Binary files a/Mac/OSXResources/app/Resources/PythonInterpreter.icns and /dev/null differ diff --git a/Mac/OSXResources/framework/English.lproj/InfoPlist.strings b/Mac/OSXResources/framework/English.lproj/InfoPlist.strings deleted file mode 100644 index cc24bfc..0000000 Binary files a/Mac/OSXResources/framework/English.lproj/InfoPlist.strings and /dev/null differ diff --git a/Mac/OSXResources/framework/Info.plist b/Mac/OSXResources/framework/Info.plist deleted file mode 100644 index 302ff48..0000000 --- a/Mac/OSXResources/framework/Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - Python - CFBundleGetInfoString - Python Runtime and Library - CFBundleIdentifier - org.python.python - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - Python - CFBundlePackageType - FMWK - CFBundleShortVersionString - 2.5 - CFBundleSignature - ???? - CFBundleVersion - 2.5 - - diff --git a/Mac/OSXResources/framework/version.plist b/Mac/OSXResources/framework/version.plist deleted file mode 100644 index 7527442..0000000 --- a/Mac/OSXResources/framework/version.plist +++ /dev/null @@ -1,18 +0,0 @@ - - - - - BuildVersion - 1 - CFBundleShortVersionString - 2.5alpha0 - CFBundleVersion - 2.5alpha0 - ProjectName - Python - ReleaseStatus - alfa - SourceVersion - 2.4a0 - - diff --git a/Mac/OSXResources/iconsrc/IDE.psd b/Mac/OSXResources/iconsrc/IDE.psd deleted file mode 100644 index b9637b9..0000000 Binary files a/Mac/OSXResources/iconsrc/IDE.psd and /dev/null differ diff --git a/Mac/OSXResources/iconsrc/PackageManager.psd b/Mac/OSXResources/iconsrc/PackageManager.psd deleted file mode 100644 index 42f41b1..0000000 Binary files a/Mac/OSXResources/iconsrc/PackageManager.psd and /dev/null differ diff --git a/Mac/OSXResources/iconsrc/PythonApplet.psd b/Mac/OSXResources/iconsrc/PythonApplet.psd deleted file mode 100644 index 7458b52..0000000 Binary files a/Mac/OSXResources/iconsrc/PythonApplet.psd and /dev/null differ diff --git a/Mac/OSXResources/iconsrc/PythonCompiled.psd b/Mac/OSXResources/iconsrc/PythonCompiled.psd deleted file mode 100755 index 61fc4d1..0000000 Binary files a/Mac/OSXResources/iconsrc/PythonCompiled.psd and /dev/null differ diff --git a/Mac/OSXResources/iconsrc/PythonIcon.psd b/Mac/OSXResources/iconsrc/PythonIcon.psd deleted file mode 100755 index d818dc6..0000000 Binary files a/Mac/OSXResources/iconsrc/PythonIcon.psd and /dev/null differ diff --git a/Mac/OSXResources/iconsrc/PythonSource.psd b/Mac/OSXResources/iconsrc/PythonSource.psd deleted file mode 100755 index eba8f28..0000000 Binary files a/Mac/OSXResources/iconsrc/PythonSource.psd and /dev/null differ diff --git a/Mac/OSXResources/iconsrc/PythonWSource.psd b/Mac/OSXResources/iconsrc/PythonWSource.psd deleted file mode 100644 index 2b84d94..0000000 Binary files a/Mac/OSXResources/iconsrc/PythonWSource.psd and /dev/null differ diff --git a/Mac/PythonLauncher/English.lproj/Credits.rtf b/Mac/PythonLauncher/English.lproj/Credits.rtf new file mode 100644 index 0000000..930ca22 --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/Credits.rtf @@ -0,0 +1,30 @@ +{\rtf1\mac\ansicpg10000\cocoartf100 +{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural + +\f0\b\fs24 \cf0 Engineering: +\f1\b0 \ + Jack Jansen\ +\ + +\f0\b Human Interface Design: +\f1\b0 \ + Jack Jansen\ +\ + +\f0\b Testing: +\f1\b0 \ + Jack Jansen\ + Pythonmac-SIG@python.org\ +\ + +\f0\b Documentation: +\f1\b0 \ + Missing\ +\ + +\f0\b With special thanks to: +\f1\b0 \ + Guido, of course\ +} \ No newline at end of file diff --git a/Mac/PythonLauncher/English.lproj/MainMenu.nib/classes.nib b/Mac/PythonLauncher/English.lproj/MainMenu.nib/classes.nib new file mode 100644 index 0000000..47b40ab --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/MainMenu.nib/classes.nib @@ -0,0 +1,12 @@ +{ + IBClasses = ( + {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, + { + ACTIONS = {showPreferences = id; }; + CLASS = MyAppDelegate; + LANGUAGE = ObjC; + SUPERCLASS = NSObject; + } + ); + IBVersion = 1; +} \ No newline at end of file diff --git a/Mac/PythonLauncher/English.lproj/MainMenu.nib/info.nib b/Mac/PythonLauncher/English.lproj/MainMenu.nib/info.nib new file mode 100644 index 0000000..b96759a --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/MainMenu.nib/info.nib @@ -0,0 +1,21 @@ + + + + + IBDocumentLocation + 99 33 356 240 0 0 800 578 + IBEditorPositions + + 29 + 82 396 318 44 0 0 800 578 + + IBFramework Version + 263.2 + IBOpenObjects + + 29 + + IBSystem Version + 5S66 + + diff --git a/Mac/PythonLauncher/English.lproj/MainMenu.nib/objects.nib b/Mac/PythonLauncher/English.lproj/MainMenu.nib/objects.nib new file mode 100644 index 0000000..532a5c8 Binary files /dev/null and b/Mac/PythonLauncher/English.lproj/MainMenu.nib/objects.nib differ diff --git a/Mac/PythonLauncher/English.lproj/MyDocument.nib/classes.nib b/Mac/PythonLauncher/English.lproj/MyDocument.nib/classes.nib new file mode 100644 index 0000000..bcdc0cd --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/MyDocument.nib/classes.nib @@ -0,0 +1,26 @@ +{ + IBClasses = ( + {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, + { + ACTIONS = {"do_apply" = id; "do_cancel" = id; "do_reset" = id; "do_run" = id; }; + CLASS = MyDocument; + LANGUAGE = ObjC; + OUTLETS = { + commandline = NSTextField; + debug = NSButton; + honourhashbang = NSButton; + inspect = NSButton; + interpreter = NSTextField; + nosite = NSButton; + optimize = NSButton; + others = NSTextField; + scriptargs = NSTextField; + tabs = NSButton; + verbose = NSButton; + "with_terminal" = NSButton; + }; + SUPERCLASS = NSDocument; + } + ); + IBVersion = 1; +} \ No newline at end of file diff --git a/Mac/PythonLauncher/English.lproj/MyDocument.nib/info.nib b/Mac/PythonLauncher/English.lproj/MyDocument.nib/info.nib new file mode 100644 index 0000000..e258c72 --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/MyDocument.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBDocumentLocation + 398 60 356 240 0 0 1024 746 + IBFramework Version + 291.0 + IBOpenObjects + + 5 + + IBSystem Version + 6L60 + + diff --git a/Mac/PythonLauncher/English.lproj/MyDocument.nib/objects.nib b/Mac/PythonLauncher/English.lproj/MyDocument.nib/objects.nib new file mode 100644 index 0000000..0473a31 Binary files /dev/null and b/Mac/PythonLauncher/English.lproj/MyDocument.nib/objects.nib differ diff --git a/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib b/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib new file mode 100644 index 0000000..467aa8b --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/classes.nib @@ -0,0 +1,26 @@ +{ + IBClasses = ( + {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, + { + ACTIONS = {"do_apply" = id; "do_filetype" = id; "do_reset" = id; }; + CLASS = PreferencesWindowController; + LANGUAGE = ObjC; + OUTLETS = { + commandline = NSTextField; + debug = NSButton; + filetype = NSPopUpButton; + honourhashbang = NSButton; + inspect = NSButton; + interpreter = NSTextField; + nosite = NSButton; + optimize = NSButton; + others = NSTextField; + tabs = NSButton; + verbose = NSButton; + "with_terminal" = NSButton; + }; + SUPERCLASS = NSWindowController; + } + ); + IBVersion = 1; +} \ No newline at end of file diff --git a/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib b/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib new file mode 100644 index 0000000..bc558f7 --- /dev/null +++ b/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/info.nib @@ -0,0 +1,16 @@ + + + + + IBDocumentLocation + 565 235 519 534 0 0 1280 1002 + IBFramework Version + 364.0 + IBOpenObjects + + 5 + + IBSystem Version + 7H63 + + diff --git a/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib b/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib new file mode 100644 index 0000000..3dfed33 Binary files /dev/null and b/Mac/PythonLauncher/English.lproj/PreferenceWindow.nib/objects.nib differ diff --git a/Mac/PythonLauncher/FileSettings.h b/Mac/PythonLauncher/FileSettings.h new file mode 100755 index 0000000..d807bae --- /dev/null +++ b/Mac/PythonLauncher/FileSettings.h @@ -0,0 +1,64 @@ +// +// FileSettings.h +// PythonLauncher +// +// Created by Jack Jansen on Sun Jul 21 2002. +// Copyright (c) 2002 __MyCompanyName__. All rights reserved. +// + +#import + +@protocol FileSettingsSource +- (NSString *) interpreter; +- (BOOL) honourhashbang; +- (BOOL) debug; +- (BOOL) verbose; +- (BOOL) inspect; +- (BOOL) optimize; +- (BOOL) nosite; +- (BOOL) tabs; +- (NSString *) others; +- (BOOL) with_terminal; +- (NSString *) scriptargs; +@end + +@interface FileSettings : NSObject +{ + NSString *interpreter; // The pathname of the interpreter to use + NSArray *interpreters; // List of known interpreters + BOOL honourhashbang; // #! line overrides interpreter + BOOL debug; // -d option: debug parser + BOOL verbose; // -v option: verbose import + BOOL inspect; // -i option: interactive mode after script + BOOL optimize; // -O option: optimize bytecode + BOOL nosite; // -S option: don't import site.py + BOOL tabs; // -t option: warn about inconsistent tabs + NSString *others; // other options + NSString *scriptargs; // script arguments (not for preferences) + BOOL with_terminal; // Run in terminal window + + FileSettings *origsource; + NSString *prefskey; +} + ++ (id)getDefaultsForFileType: (NSString *)filetype; ++ (id)getFactorySettingsForFileType: (NSString *)filetype; ++ (id)newSettingsForFileType: (NSString *)filetype; + +//- (id)init; +- (id)initForFileType: (NSString *)filetype; +- (id)initForFSDefaultFileType: (NSString *)filetype; +- (id)initForDefaultFileType: (NSString *)filetype; +//- (id)initWithFileSettings: (FileSettings *)source; + +- (void)updateFromSource: (id )source; +- (NSString *)commandLineForScript: (NSString *)script; + +//- (void)applyFactorySettingsForFileType: (NSString *)filetype; +//- (void)saveDefaults; +//- (void)applyUserDefaults: (NSString *)filetype; +- (void)applyValuesFromDict: (NSDictionary *)dict; +- (void)reset; +- (NSArray *) interpreters; + +@end diff --git a/Mac/PythonLauncher/FileSettings.m b/Mac/PythonLauncher/FileSettings.m new file mode 100755 index 0000000..fc3937b --- /dev/null +++ b/Mac/PythonLauncher/FileSettings.m @@ -0,0 +1,298 @@ +// +// FileSettings.m +// PythonLauncher +// +// Created by Jack Jansen on Sun Jul 21 2002. +// Copyright (c) 2002 __MyCompanyName__. All rights reserved. +// + +#import "FileSettings.h" + +@implementation FileSettings + ++ (id)getFactorySettingsForFileType: (NSString *)filetype +{ + static FileSettings *fsdefault_py, *fsdefault_pyw, *fsdefault_pyc; + FileSettings **curdefault; + + if ([filetype isEqualToString: @"Python Script"]) { + curdefault = &fsdefault_py; + } else if ([filetype isEqualToString: @"Python GUI Script"]) { + curdefault = &fsdefault_pyw; + } else if ([filetype isEqualToString: @"Python Bytecode Document"]) { + curdefault = &fsdefault_pyc; + } else { + NSLog(@"Funny File Type: %@\n", filetype); + curdefault = &fsdefault_py; + filetype = @"Python Script"; + } + if (!*curdefault) { + *curdefault = [[FileSettings new] initForFSDefaultFileType: filetype]; + } + return *curdefault; +} + ++ (id)getDefaultsForFileType: (NSString *)filetype +{ + static FileSettings *default_py, *default_pyw, *default_pyc; + FileSettings **curdefault; + + if ([filetype isEqualToString: @"Python Script"]) { + curdefault = &default_py; + } else if ([filetype isEqualToString: @"Python GUI Script"]) { + curdefault = &default_pyw; + } else if ([filetype isEqualToString: @"Python Bytecode Document"]) { + curdefault = &default_pyc; + } else { + NSLog(@"Funny File Type: %@\n", filetype); + curdefault = &default_py; + filetype = @"Python Script"; + } + if (!*curdefault) { + *curdefault = [[FileSettings new] initForDefaultFileType: filetype]; + } + return *curdefault; +} + ++ (id)newSettingsForFileType: (NSString *)filetype +{ + FileSettings *cur; + + cur = [FileSettings new]; + [cur initForFileType: filetype]; + return [cur retain]; +} + +- (id)initWithFileSettings: (FileSettings *)source +{ + self = [super init]; + if (!self) return self; + + interpreter = [source->interpreter retain]; + honourhashbang = source->honourhashbang; + debug = source->debug; + verbose = source->verbose; + inspect = source->inspect; + optimize = source->optimize; + nosite = source->nosite; + tabs = source->tabs; + others = [source->others retain]; + scriptargs = [source->scriptargs retain]; + with_terminal = source->with_terminal; + prefskey = source->prefskey; + if (prefskey) [prefskey retain]; + + return self; +} + +- (id)initForFileType: (NSString *)filetype +{ + FileSettings *defaults; + + defaults = [FileSettings getDefaultsForFileType: filetype]; + self = [self initWithFileSettings: defaults]; + origsource = [defaults retain]; + return self; +} + +//- (id)init +//{ +// self = [self initForFileType: @"Python Script"]; +// return self; +//} + +- (id)initForFSDefaultFileType: (NSString *)filetype +{ + int i; + NSString *filename; + NSDictionary *dict; + static NSDictionary *factorySettings; + + self = [super init]; + if (!self) return self; + + if (factorySettings == NULL) { + NSBundle *bdl = [NSBundle mainBundle]; + NSString *path = [ bdl pathForResource: @"factorySettings" + ofType: @"plist"]; + factorySettings = [[NSDictionary dictionaryWithContentsOfFile: + path] retain]; + if (factorySettings == NULL) { + NSLog(@"Missing %@", path); + return NULL; + } + } + dict = [factorySettings objectForKey: filetype]; + if (dict == NULL) { + NSLog(@"factorySettings.plist misses file type \"%@\"", filetype); + interpreter = [@"no default found" retain]; + return NULL; + } + [self applyValuesFromDict: dict]; + interpreters = [dict objectForKey: @"interpreter_list"]; + interpreter = NULL; + for (i=0; i < [interpreters count]; i++) { + filename = [interpreters objectAtIndex: i]; + filename = [filename stringByExpandingTildeInPath]; + if ([[NSFileManager defaultManager] fileExistsAtPath: filename]) { + interpreter = [filename retain]; + break; + } + } + if (interpreter == NULL) + interpreter = [@"no default found" retain]; + origsource = NULL; + return self; +} + +- (void)applyUserDefaults: (NSString *)filetype +{ + NSUserDefaults *defaults; + NSDictionary *dict; + + defaults = [NSUserDefaults standardUserDefaults]; + dict = [defaults dictionaryForKey: filetype]; + if (!dict) + return; + [self applyValuesFromDict: dict]; +} + +- (id)initForDefaultFileType: (NSString *)filetype +{ + FileSettings *fsdefaults; + + fsdefaults = [FileSettings getFactorySettingsForFileType: filetype]; + self = [self initWithFileSettings: fsdefaults]; + if (!self) return self; + interpreters = [fsdefaults->interpreters retain]; + scriptargs = [@"" retain]; + [self applyUserDefaults: filetype]; + prefskey = [filetype retain]; + return self; +} + +- (void)reset +{ + if (origsource) { + [self updateFromSource: origsource]; + } else { + FileSettings *fsdefaults; + fsdefaults = [FileSettings getFactorySettingsForFileType: prefskey]; + [self updateFromSource: fsdefaults]; + } +} + +- (void)updateFromSource: (id )source +{ + interpreter = [[source interpreter] retain]; + honourhashbang = [source honourhashbang]; + debug = [source debug]; + verbose = [source verbose]; + inspect = [source inspect]; + optimize = [source optimize]; + nosite = [source nosite]; + tabs = [source tabs]; + others = [[source others] retain]; + scriptargs = [[source scriptargs] retain]; + with_terminal = [source with_terminal]; + // And if this is a user defaults object we also save the + // values + if (!origsource) { + NSUserDefaults *defaults; + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: + interpreter, @"interpreter", + [NSNumber numberWithBool: honourhashbang], @"honourhashbang", + [NSNumber numberWithBool: debug], @"debug", + [NSNumber numberWithBool: verbose], @"verbose", + [NSNumber numberWithBool: inspect], @"inspect", + [NSNumber numberWithBool: optimize], @"optimize", + [NSNumber numberWithBool: nosite], @"nosite", + [NSNumber numberWithBool: nosite], @"nosite", + others, @"others", + scriptargs, @"scriptargs", + [NSNumber numberWithBool: with_terminal], @"with_terminal", + nil]; + defaults = [NSUserDefaults standardUserDefaults]; + [defaults setObject: dict forKey: prefskey]; + } +} + +- (void)applyValuesFromDict: (NSDictionary *)dict +{ + id value; + + value = [dict objectForKey: @"interpreter"]; + if (value) interpreter = [value retain]; + value = [dict objectForKey: @"honourhashbang"]; + if (value) honourhashbang = [value boolValue]; + value = [dict objectForKey: @"debug"]; + if (value) debug = [value boolValue]; + value = [dict objectForKey: @"verbose"]; + if (value) verbose = [value boolValue]; + value = [dict objectForKey: @"inspect"]; + if (value) inspect = [value boolValue]; + value = [dict objectForKey: @"optimize"]; + if (value) optimize = [value boolValue]; + value = [dict objectForKey: @"nosite"]; + if (value) nosite = [value boolValue]; + value = [dict objectForKey: @"nosite"]; + if (value) tabs = [value boolValue]; + value = [dict objectForKey: @"others"]; + if (value) others = [value retain]; + value = [dict objectForKey: @"scriptargs"]; + if (value) scriptargs = [value retain]; + value = [dict objectForKey: @"with_terminal"]; + if (value) with_terminal = [value boolValue]; +} + +- (NSString *)commandLineForScript: (NSString *)script +{ + NSString *cur_interp = NULL; + char hashbangbuf[1024]; + FILE *fp; + char *p; + + if (honourhashbang && + (fp=fopen([script cString], "r")) && + fgets(hashbangbuf, sizeof(hashbangbuf), fp) && + strncmp(hashbangbuf, "#!", 2) == 0 && + (p=strchr(hashbangbuf, '\n'))) { + *p = '\0'; + p = hashbangbuf + 2; + while (*p == ' ') p++; + cur_interp = [NSString stringWithCString: p]; + } + if (!cur_interp) + cur_interp = interpreter; + + return [NSString stringWithFormat: + @"\"%@\"%s%s%s%s%s%s %@ \"%@\" %@ %s", + cur_interp, + debug?" -d":"", + verbose?" -v":"", + inspect?" -i":"", + optimize?" -O":"", + nosite?" -S":"", + tabs?" -t":"", + others, + script, + scriptargs, + with_terminal? "&& echo Exit status: $? && exit 1" : " &"]; +} + +- (NSArray *) interpreters { return interpreters;}; + +// FileSettingsSource protocol +- (NSString *) interpreter { return interpreter;}; +- (BOOL) honourhashbang { return honourhashbang; }; +- (BOOL) debug { return debug;}; +- (BOOL) verbose { return verbose;}; +- (BOOL) inspect { return inspect;}; +- (BOOL) optimize { return optimize;}; +- (BOOL) nosite { return nosite;}; +- (BOOL) tabs { return tabs;}; +- (NSString *) others { return others;}; +- (NSString *) scriptargs { return scriptargs;}; +- (BOOL) with_terminal { return with_terminal;}; + +@end diff --git a/Mac/PythonLauncher/Info.plist.in b/Mac/PythonLauncher/Info.plist.in new file mode 100644 index 0000000..3c726d7 --- /dev/null +++ b/Mac/PythonLauncher/Info.plist.in @@ -0,0 +1,65 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + py + pyw + + CFBundleTypeIconFile + PythonSource.icns + CFBundleTypeName + Python Script + CFBundleTypeRole + Viewer + NSDocumentClass + MyDocument + + + CFBundleTypeExtensions + + pyc + pyo + + CFBundleTypeIconFile + PythonCompiled.icns + CFBundleTypeName + Python Bytecode Document + CFBundleTypeRole + Viewer + NSDocumentClass + MyDocument + + + CFBundleExecutable + PythonLauncher + CFBundleGetInfoString + %VERSION%, © 001-2006 Python Software Foundation + CFBundleIconFile + PythonLauncher.icns + CFBundleIdentifier + org.python.PythonLauncher + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Python Launcher + CFBundlePackageType + APPL + CFBundleShortVersionString + %VERSION% + CFBundleSignature + PytL + CFBundleVersion + %VERSION% + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/Mac/PythonLauncher/Makefile.in b/Mac/PythonLauncher/Makefile.in new file mode 100644 index 0000000..b4b126c --- /dev/null +++ b/Mac/PythonLauncher/Makefile.in @@ -0,0 +1,81 @@ +CC=@CC@ +LD=@CC@ +BASECFLAGS=@BASECFLAGS@ +OPT=@OPT@ +CFLAGS=$(BASECFLAGS) $(OPT) +LDFLAGS=@LDFLAGS@ +srcdir= @srcdir@ +VERSION= @VERSION@ +UNIVERSALSDK=@UNIVERSALSDK@ +builddir= ../.. + +RUNSHARED= @RUNSHARED@ +BUILDEXE= @BUILDEXEEXT@ +BUILDPYTHON= $(builddir)/python$(BUILDEXE) + +# Deployment target selected during configure, to be checked +# by distutils +MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ +@EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET + +BUNDLEBULDER=$(srcdir)/../../Lib/plat-mac/bundlebuilder.py + +PYTHONAPPSDIR=/Applications/MacPython $(VERSION) +OBJECTS=FileSettings.o MyAppDelegate.o MyDocument.o PreferencesWindowController.o doscript.o main.o + +all: Python\ Launcher.app + +install: Python\ Launcher.app + test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" + -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" + cp -r "Python Launcher.app" "$(DESTDIR)$(PYTHONAPPSDIR)" + touch "$(DESTDIR)$(PYTHONAPPSDIR)/Python Launcher.app" + +clean: + rm -f *.o "Python Launcher" + rm -rf "Python Launcher.app" + +Python\ Launcher.app: Info.plist \ + Python\ Launcher $(srcdir)/../Icons/PythonLauncher.icns \ + $(srcdir)/../Icons/PythonSource.icns \ + $(srcdir)/../Icons/PythonCompiled.icns \ + $(srcdir)/factorySettings.plist + rm -fr "Python Launcher.app" + $(RUNSHARED) $(BUILDPYTHON) $(BUNDLEBULDER) \ + --builddir=. \ + --name="Python Launcher" \ + --executable="Python Launcher" \ + --iconfile=$(srcdir)/../Icons/PythonLauncher.icns \ + --bundle-id=org.python.PythonLauncher \ + --resource=$(srcdir)/../Icons/PythonSource.icns \ + --resource=$(srcdir)/../Icons/PythonCompiled.icns \ + --resource=$(srcdir)/English.lproj \ + --resource=$(srcdir)/factorySettings.plist \ + --plist Info.plist \ + build + find "Python Launcher.app" -name '.svn' -print0 | xargs -0 rm -r + + +FileSettings.o: $(srcdir)/FileSettings.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/FileSettings.m + +MyAppDelegate.o: $(srcdir)/MyAppDelegate.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/MyAppDelegate.m + +MyDocument.o: $(srcdir)/MyDocument.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/MyDocument.m + +PreferencesWindowController.o: $(srcdir)/PreferencesWindowController.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/PreferencesWindowController.m + +doscript.o: $(srcdir)/doscript.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/doscript.m + +main.o: $(srcdir)/main.m + $(CC) $(CFLAGS) -o $@ -c $(srcdir)/main.m + +Python\ Launcher: $(OBJECTS) + $(CC) $(LDFLAGS) -o "Python Launcher" $(OBJECTS) -framework AppKit -framework Carbon + +Info.plist: $(srcdir)/Info.plist.in + sed 's/%VERSION%/'"`$(RUNSHARED) $(BUILDPYTHON) -c 'import platform; print platform.python_version()'`"'/g' < $(srcdir)/Info.plist.in > Info.plist diff --git a/Mac/PythonLauncher/MyAppDelegate.h b/Mac/PythonLauncher/MyAppDelegate.h new file mode 100644 index 0000000..097b541 --- /dev/null +++ b/Mac/PythonLauncher/MyAppDelegate.h @@ -0,0 +1,15 @@ +/* MyAppDelegate */ + +#import + +@interface MyAppDelegate : NSObject +{ + BOOL initial_action_done; + BOOL should_terminate; +} +- (id)init; +- (IBAction)showPreferences:(id)sender; +- (BOOL)shouldShowUI; +- (BOOL)shouldTerminate; +- (void)testFileTypeBinding; +@end diff --git a/Mac/PythonLauncher/MyAppDelegate.m b/Mac/PythonLauncher/MyAppDelegate.m new file mode 100644 index 0000000..a5ba751 --- /dev/null +++ b/Mac/PythonLauncher/MyAppDelegate.m @@ -0,0 +1,96 @@ +#import "MyAppDelegate.h" +#import "PreferencesWindowController.h" +#import +#import + +@implementation MyAppDelegate + +- (id)init +{ + self = [super init]; + initial_action_done = NO; + should_terminate = NO; + return self; +} + +- (IBAction)showPreferences:(id)sender +{ + [PreferencesWindowController getPreferencesWindow]; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification +{ + // Test that the file mappings are correct + [self testFileTypeBinding]; + // If we were opened because of a file drag or doubleclick + // we've set initial_action_done in shouldShowUI + // Otherwise we open a preferences dialog. + if (!initial_action_done) { + initial_action_done = YES; + [self showPreferences: self]; + } +} + +- (BOOL)shouldShowUI +{ + // if this call comes before applicationDidFinishLaunching: we + // should terminate immedeately after starting the script. + if (!initial_action_done) + should_terminate = YES; + initial_action_done = YES; + if( GetCurrentKeyModifiers() & optionKey ) + return YES; + return NO; +} + +- (BOOL)shouldTerminate +{ + return should_terminate; +} + +- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender +{ + return NO; +} + +- (void)testFileTypeBinding +{ + NSURL *ourUrl; + OSStatus err; + FSRef appRef; + NSURL *appUrl; + static NSString *extensions[] = { @"py", @"pyw", @"pyc", NULL}; + NSString **ext_p; + int i; + + if ([[NSUserDefaults standardUserDefaults] boolForKey: @"SkipFileBindingTest"]) + return; + ourUrl = [NSURL fileURLWithPath: [[NSBundle mainBundle] bundlePath]]; + for( ext_p = extensions; *ext_p; ext_p++ ) { + err = LSGetApplicationForInfo( + kLSUnknownType, + kLSUnknownCreator, + (CFStringRef)*ext_p, + kLSRolesViewer, + &appRef, + (CFURLRef *)&appUrl); + if (err || ![appUrl isEqual: ourUrl] ) { + i = NSRunAlertPanel(@"File type binding", + @"PythonLauncher is not the default application for all " \ + @"Python script types. You should fix this with the " \ + @"Finder's \"Get Info\" command.\n\n" \ + @"See \"Changing the application that opens a file\" in " \ + @"Mac Help for details.", + @"OK", + @"Don't show this warning again", + NULL); + if ( i == 0 ) { // Don't show again + [[NSUserDefaults standardUserDefaults] + setObject:@"YES" forKey:@"SkipFileBindingTest"]; + } + return; + } + } +} + +@end diff --git a/Mac/PythonLauncher/MyDocument.h b/Mac/PythonLauncher/MyDocument.h new file mode 100755 index 0000000..00c1bae --- /dev/null +++ b/Mac/PythonLauncher/MyDocument.h @@ -0,0 +1,41 @@ +// +// MyDocument.h +// PythonLauncher +// +// Created by Jack Jansen on Fri Jul 19 2002. +// Copyright (c) 2002 __MyCompanyName__. All rights reserved. +// + + +#import + +#import "FileSettings.h" + +@interface MyDocument : NSDocument +{ + IBOutlet NSTextField *interpreter; + IBOutlet NSButton *honourhashbang; + IBOutlet NSButton *debug; + IBOutlet NSButton *verbose; + IBOutlet NSButton *inspect; + IBOutlet NSButton *optimize; + IBOutlet NSButton *nosite; + IBOutlet NSButton *tabs; + IBOutlet NSTextField *others; + IBOutlet NSButton *with_terminal; + IBOutlet NSTextField *scriptargs; + IBOutlet NSTextField *commandline; + + NSString *script; + NSString *filetype; + FileSettings *settings; +} + +- (IBAction)do_run:(id)sender; +- (IBAction)do_cancel:(id)sender; +- (IBAction)do_reset:(id)sender; +- (IBAction)do_apply:(id)sender; + +- (void)controlTextDidChange:(NSNotification *)aNotification; + +@end diff --git a/Mac/PythonLauncher/MyDocument.m b/Mac/PythonLauncher/MyDocument.m new file mode 100755 index 0000000..5acc2dc --- /dev/null +++ b/Mac/PythonLauncher/MyDocument.m @@ -0,0 +1,175 @@ +// +// MyDocument.m +// PythonLauncher +// +// Created by Jack Jansen on Fri Jul 19 2002. +// Copyright (c) 2002 __MyCompanyName__. All rights reserved. +// + +#import "MyDocument.h" +#import "MyAppDelegate.h" +#import "doscript.h" + +@implementation MyDocument + +- (id)init +{ + self = [super init]; + if (self) { + + // Add your subclass-specific initialization here. + // If an error occurs here, send a [self dealloc] message and return nil. + script = [@".py" retain]; + filetype = [@"Python Script" retain]; + settings = NULL; + } + return self; +} + +- (NSString *)windowNibName +{ + // Override returning the nib file name of the document + // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead. + return @"MyDocument"; +} + +- (void)close +{ + NSApplication *app = [NSApplication sharedApplication]; + [super close]; + if ([[app delegate] shouldTerminate]) + [app terminate: self]; +} + +- (void)load_defaults +{ +// if (settings) [settings release]; + settings = [FileSettings newSettingsForFileType: filetype]; +} + +- (void)update_display +{ +// [[self window] setTitle: script]; + + [interpreter setStringValue: [settings interpreter]]; + [honourhashbang setState: [settings honourhashbang]]; + [debug setState: [settings debug]]; + [verbose setState: [settings verbose]]; + [inspect setState: [settings inspect]]; + [optimize setState: [settings optimize]]; + [nosite setState: [settings nosite]]; + [tabs setState: [settings tabs]]; + [others setStringValue: [settings others]]; + [scriptargs setStringValue: [settings scriptargs]]; + [with_terminal setState: [settings with_terminal]]; + + [commandline setStringValue: [settings commandLineForScript: script]]; +} + +- (void)update_settings +{ + [settings updateFromSource: self]; +} + +- (BOOL)run +{ + const char *cmdline; + int sts; + + cmdline = [[settings commandLineForScript: script] cString]; + if ([settings with_terminal]) { + sts = doscript(cmdline); + } else { + sts = system(cmdline); + } + if (sts) { + NSLog(@"Exit status: %d\n", sts); + return NO; + } + return YES; +} + +- (void)windowControllerDidLoadNib:(NSWindowController *) aController +{ + [super windowControllerDidLoadNib:aController]; + // Add any code here that need to be executed once the windowController has loaded the document's window. + [self load_defaults]; + [self update_display]; +} + +- (NSData *)dataRepresentationOfType:(NSString *)aType +{ + // Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead. + return nil; +} + +- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type; +{ + // Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead. + BOOL show_ui; + + // ask the app delegate whether we should show the UI or not. + show_ui = [[[NSApplication sharedApplication] delegate] shouldShowUI]; + [script release]; + script = [fileName retain]; + [filetype release]; + filetype = [type retain]; +// if (settings) [settings release]; + settings = [FileSettings newSettingsForFileType: filetype]; + if (show_ui) { + [self update_display]; + return YES; + } else { + [self run]; + [self close]; + return NO; + } +} + +- (IBAction)do_run:(id)sender +{ + [self update_settings]; + [self update_display]; + if ([self run]) + [self close]; +} + +- (IBAction)do_cancel:(id)sender +{ + [self close]; +} + + +- (IBAction)do_reset:(id)sender +{ + [settings reset]; + [self update_display]; +} + +- (IBAction)do_apply:(id)sender +{ + [self update_settings]; + [self update_display]; +} + +// FileSettingsSource protocol +- (NSString *) interpreter { return [interpreter stringValue];}; +- (BOOL) honourhashbang { return [honourhashbang state];}; +- (BOOL) debug { return [debug state];}; +- (BOOL) verbose { return [verbose state];}; +- (BOOL) inspect { return [inspect state];}; +- (BOOL) optimize { return [optimize state];}; +- (BOOL) nosite { return [nosite state];}; +- (BOOL) tabs { return [tabs state];}; +- (NSString *) others { return [others stringValue];}; +- (NSString *) scriptargs { return [scriptargs stringValue];}; +- (BOOL) with_terminal { return [with_terminal state];}; + +// Delegates +- (void)controlTextDidChange:(NSNotification *)aNotification +{ + [self update_settings]; + [self update_display]; +}; + +@end diff --git a/Mac/PythonLauncher/PreferencesWindowController.h b/Mac/PythonLauncher/PreferencesWindowController.h new file mode 100644 index 0000000..6346996 --- /dev/null +++ b/Mac/PythonLauncher/PreferencesWindowController.h @@ -0,0 +1,38 @@ +/* PreferencesWindowController */ + +#import + +#import "FileSettings.h" + +@interface PreferencesWindowController : NSWindowController +{ + IBOutlet NSPopUpButton *filetype; + IBOutlet NSComboBox *interpreter; + IBOutlet NSButton *honourhashbang; + IBOutlet NSButton *debug; + IBOutlet NSButton *verbose; + IBOutlet NSButton *inspect; + IBOutlet NSButton *optimize; + IBOutlet NSButton *nosite; + IBOutlet NSButton *tabs; + IBOutlet NSTextField *others; + IBOutlet NSButton *with_terminal; + IBOutlet NSTextField *commandline; + + FileSettings *settings; +} + ++ getPreferencesWindow; + +- (IBAction)do_reset:(id)sender; +- (IBAction)do_apply:(id)sender; +- (IBAction)do_filetype:(id)sender; + +- (void)controlTextDidChange:(NSNotification *)aNotification; + +- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString; +- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index; +- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox; + + +@end diff --git a/Mac/PythonLauncher/PreferencesWindowController.m b/Mac/PythonLauncher/PreferencesWindowController.m new file mode 100644 index 0000000..311c375 --- /dev/null +++ b/Mac/PythonLauncher/PreferencesWindowController.m @@ -0,0 +1,121 @@ +#import "PreferencesWindowController.h" + +@implementation PreferencesWindowController + ++ getPreferencesWindow +{ + static PreferencesWindowController *_singleton; + + if (!_singleton) + _singleton = [[PreferencesWindowController alloc] init]; + [_singleton showWindow: _singleton]; + return _singleton; +} + +- (id) init +{ + self = [self initWithWindowNibName: @"PreferenceWindow"]; + return self; +} + +- (void)load_defaults +{ + NSString *title = [filetype titleOfSelectedItem]; + + settings = [FileSettings getDefaultsForFileType: title]; +} + +- (void)update_display +{ +// [[self window] setTitle: script]; + + [interpreter reloadData]; + [interpreter setStringValue: [settings interpreter]]; + [honourhashbang setState: [settings honourhashbang]]; + [debug setState: [settings debug]]; + [verbose setState: [settings verbose]]; + [inspect setState: [settings inspect]]; + [optimize setState: [settings optimize]]; + [nosite setState: [settings nosite]]; + [tabs setState: [settings tabs]]; + [others setStringValue: [settings others]]; + [with_terminal setState: [settings with_terminal]]; + // Not scriptargs, it isn't for preferences + + [commandline setStringValue: [settings commandLineForScript: @""]]; +} + +- (void) windowDidLoad +{ + [super windowDidLoad]; + [self load_defaults]; + [self update_display]; +} + +- (void)update_settings +{ + [settings updateFromSource: self]; +} + +- (IBAction)do_filetype:(id)sender +{ + [self load_defaults]; + [self update_display]; +} + +- (IBAction)do_reset:(id)sender +{ + [settings reset]; + [self update_display]; +} + +- (IBAction)do_apply:(id)sender +{ + [self update_settings]; + [self update_display]; +} + +// FileSettingsSource protocol +- (NSString *) interpreter { return [interpreter stringValue];}; +- (BOOL) honourhashbang { return [honourhashbang state]; }; +- (BOOL) debug { return [debug state];}; +- (BOOL) verbose { return [verbose state];}; +- (BOOL) inspect { return [inspect state];}; +- (BOOL) optimize { return [optimize state];}; +- (BOOL) nosite { return [nosite state];}; +- (BOOL) tabs { return [tabs state];}; +- (NSString *) others { return [others stringValue];}; +- (BOOL) with_terminal { return [with_terminal state];}; +- (NSString *) scriptargs { return @"";}; + +// Delegates +- (void)controlTextDidChange:(NSNotification *)aNotification +{ + [self update_settings]; + [self update_display]; +}; + +// NSComboBoxDataSource protocol +- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString +{ + NSArray *interp_list = [settings interpreters]; + unsigned int rv = [interp_list indexOfObjectIdenticalTo: aString]; + return rv; +} + +- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index +{ + NSArray *interp_list = [settings interpreters]; + id rv = [interp_list objectAtIndex: index]; + return rv; +} + +- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox +{ + NSArray *interp_list = [settings interpreters]; + int rv = [interp_list count]; + return rv; +} + + +@end diff --git a/Mac/PythonLauncher/doscript.h b/Mac/PythonLauncher/doscript.h new file mode 100644 index 0000000..eef0b56 --- /dev/null +++ b/Mac/PythonLauncher/doscript.h @@ -0,0 +1,12 @@ +/* + * doscript.h + * PythonLauncher + * + * Created by Jack Jansen on Wed Jul 31 2002. + * Copyright (c) 2002 __MyCompanyName__. All rights reserved. + * + */ + +#include + +extern int doscript(const char *command); \ No newline at end of file diff --git a/Mac/PythonLauncher/doscript.m b/Mac/PythonLauncher/doscript.m new file mode 100644 index 0000000..3e4e223 --- /dev/null +++ b/Mac/PythonLauncher/doscript.m @@ -0,0 +1,118 @@ +/* + * doscript.c + * PythonLauncher + * + * Created by Jack Jansen on Wed Jul 31 2002. + * Copyright (c) 2002 __MyCompanyName__. All rights reserved. + * + */ + +#import +#import +#import "doscript.h" + +/* I assume I could pick these up from somewhere, but where... */ +#define CREATOR 'trmx' + +#define ACTIVATE_CMD 'misc' +#define ACTIVATE_SUITE 'actv' + +#define DOSCRIPT_CMD 'dosc' +#define DOSCRIPT_SUITE 'core' +#define WITHCOMMAND 'cmnd' + +/* ... and there's probably also a better way to do this... */ +#define START_TERMINAL "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal &" + +extern int +doscript(const char *command) +{ + OSErr err; + AppleEvent theAEvent, theReply; + AEAddressDesc terminalAddress; + AEDesc commandDesc; + OSType terminalCreator = CREATOR; + + /* set up locals */ + AECreateDesc(typeNull, NULL, 0, &theAEvent); + AECreateDesc(typeNull, NULL, 0, &terminalAddress); + AECreateDesc(typeNull, NULL, 0, &theReply); + AECreateDesc(typeNull, NULL, 0, &commandDesc); + + /* create the "activate" event for Terminal */ + err = AECreateDesc(typeApplSignature, (Ptr) &terminalCreator, + sizeof(terminalCreator), &terminalAddress); + if (err != noErr) { + NSLog(@"doscript: AECreateDesc: error %d\n", err); + goto bail; + } + err = AECreateAppleEvent(ACTIVATE_SUITE, ACTIVATE_CMD, + &terminalAddress, kAutoGenerateReturnID, + kAnyTransactionID, &theAEvent); + + if (err != noErr) { + NSLog(@"doscript: AECreateAppleEvent(activate): error %d\n", err); + goto bail; + } + /* send the event */ + err = AESend(&theAEvent, &theReply, kAEWaitReply, + kAENormalPriority, kAEDefaultTimeout, NULL, NULL); + if ( err == -600 ) { + int count=10; + /* If it failed with "no such process" try to start Terminal */ + err = system(START_TERMINAL); + if ( err ) { + NSLog(@"doscript: system(): %s\n", strerror(errno)); + goto bail; + } + do { + sleep(1); + /* send the event again */ + err = AESend(&theAEvent, &theReply, kAEWaitReply, + kAENormalPriority, kAEDefaultTimeout, NULL, NULL); + } while (err == -600 && --count > 0); + if ( err == -600 ) + NSLog(@"doscript: Could not activate Terminal\n"); + } + if (err != noErr) { + NSLog(@"doscript: AESend(activate): error %d\n", err); + goto bail; + } + + /* create the "doscript with command" event for Terminal */ + err = AECreateAppleEvent(DOSCRIPT_SUITE, DOSCRIPT_CMD, + &terminalAddress, kAutoGenerateReturnID, + kAnyTransactionID, &theAEvent); + if (err != noErr) { + NSLog(@"doscript: AECreateAppleEvent(doscript): error %d\n", err); + goto bail; + } + + /* add the command to the apple event */ + err = AECreateDesc(typeChar, command, strlen(command), &commandDesc); + if (err != noErr) { + NSLog(@"doscript: AECreateDesc(command): error %d\n", err); + goto bail; + } + err = AEPutParamDesc(&theAEvent, WITHCOMMAND, &commandDesc); + if (err != noErr) { + NSLog(@"doscript: AEPutParamDesc: error %d\n", err); + goto bail; + } + + /* send the command event to Terminal.app */ + err = AESend(&theAEvent, &theReply, kAEWaitReply, + kAENormalPriority, kAEDefaultTimeout, NULL, NULL); + + if (err != noErr) { + NSLog(@"doscript: AESend(docommand): error %d\n", err); + goto bail; + } + /* clean up and leave */ +bail: + AEDisposeDesc(&commandDesc); + AEDisposeDesc(&theAEvent); + AEDisposeDesc(&terminalAddress); + AEDisposeDesc(&theReply); + return err; +} diff --git a/Mac/PythonLauncher/factorySettings.plist b/Mac/PythonLauncher/factorySettings.plist new file mode 100644 index 0000000..1202421 --- /dev/null +++ b/Mac/PythonLauncher/factorySettings.plist @@ -0,0 +1,87 @@ + + + + + Python GUI Script + + debug + + inspect + + interpreter_list + + /usr/local/bin/pythonw + /usr/bin/pythonw + /sw/bin/pythonw + + honourhashbang + + nosite + + optimize + + others + + verbose + + with_terminal + + + Python Script + + debug + + inspect + + interpreter_list + + /usr/local/bin/pythonw + /usr/local/bin/python + /usr/bin/pythonw + /usr/bin/python + /sw/bin/pythonw + /sw/bin/python + + honourhashbang + + nosite + + optimize + + others + + verbose + + with_terminal + + + Python Bytecode Document + + debug + + inspect + + interpreter_list + + /usr/local/bin/pythonw + /usr/local/bin/python + /usr/bin/pythonw + /usr/bin/python + /sw/bin/pythonw + /sw/bin/python + + honourhashbang + + nosite + + optimize + + others + + verbose + + with_terminal + + + + diff --git a/Mac/PythonLauncher/main.m b/Mac/PythonLauncher/main.m new file mode 100755 index 0000000..6841433 --- /dev/null +++ b/Mac/PythonLauncher/main.m @@ -0,0 +1,17 @@ +// +// main.m +// PythonLauncher +// +// Created by Jack Jansen on Fri Jul 19 2002. +// Copyright (c) 2002 __MyCompanyName__. All rights reserved. +// + +#import +#include + +int main(int argc, const char *argv[]) +{ + char *home = getenv("HOME"); + if (home) chdir(home); + return NSApplicationMain(argc, argv); +} diff --git a/Mac/README b/Mac/README new file mode 100644 index 0000000..1e58b02 --- /dev/null +++ b/Mac/README @@ -0,0 +1,167 @@ +============ +MacOSX Notes +============ + +This document provides a quick overview of some Mac OS X specific features in +the Python distribution. + + +Building and using a universal binary of Python on Mac OS X +=========================================================== + +1. What is a universal binary +----------------------------- + +A universal binary build of Python contains object code for both PPC and i386 +and can therefore run at native speed on both classic powerpc based macs and +the newer intel based macs. + +2. How do I build a universal binary +------------------------------------ + +You can enable universal binaries by specifying the "--enable-universalsdk" +flag to configure:: + + $ ./configure --enable-universalsdk + $ make + $ make install + +This flag can be used a framework build of python, but also with a classic +unix build. Either way you will have to build python on Mac OS X 10.4 (or later) +with Xcode 2.1 (or later). You also have to install the 10.4u SDK when +installing Xcode. + + +Building and using a framework-based Python on Mac OS X. +======================================================== + + +1. Why would I want a framework Python instead of a normal static Python? +-------------------------------------------------------------------------- + +The main reason is because you want to create GUI programs in Python. With the +exception of X11/XDarwin-based GUI toolkits all GUI programs need to be run +from a fullblown MacOSX application (a ".app" bundle). + +While it is technically possible to create a .app without using frameworks you +will have to do the work yourself if you really want this. + +A second reason for using frameworks is that they put Python-related items in +only two places: "/Library/Framework/Python.framework" and +"/Applications/MacPython 2.5". This simplifies matters for users installing +Python from a binary distribution if they want to get rid of it again. Moreover, +due to the way frameworks work a user without admin privileges can install a +binary distribution in his or her home directory without recompilation. + +2. How does a framework Python differ from a normal static Python? +------------------------------------------------------------------ + +In everyday use there is no difference, except that things are stored in +a different place. If you look in /Library/Frameworks/Python.framework +you will see lots of relative symlinks, see the Apple documentation for +details. If you are used to a normal unix Python file layout go down to +Versions/Current and you will see the familiar bin and lib directories. + +3. Do I need extra packages? +---------------------------- + +Yes, probably. If you want Tkinter support you need to get the OSX AquaTk +distribution, this is installed by default on Mac OS X 10.4 or later. If +you want wxPython you need to get that. If you want Cocoa you need to get +PyObjC. + +4. How do I build a framework Python? +------------------------------------- + +This directory contains a Makefile that will create a couple of python-related +applications (fullblown OSX .app applications, that is) in +"/Applications/MacPython 2.3", and a hidden helper application Python.app +inside the Python.framework, and unix tools "python" and "pythonw" into +/usr/local/bin. In addition it has a target "installmacsubtree" that installs +the relevant portions of the Mac subtree into the Python.framework. + +It is normally invoked indirectly through the main Makefile, as the last step +in the sequence + + 1. ./configure --enable-framework + + 2. make + + 3. make install + +This sequence will put the framework in /Library/Framework/Python.framework, +the applications in /Applications/MacPython 2.5 and the unix tools in +/usr/local/bin. + +Installing in another place, for instance $HOME/Library/Frameworks if you have +no admin privileges on your machine, has only been tested very lightly. This +can be done by configuring with --enable-framework=$HOME/Library/Frameworks. +The other two directories, /Applications/MacPython-2.3 and /usr/local/bin, will +then also be deposited in $HOME. This is sub-optimal for the unix tools, which +you would want in $HOME/bin, but there is no easy way to fix this right now. + +Note that there are no references to the actual locations in the code or +resource files, so you are free to move things around afterwards. For example, +you could use --enable-framework=/tmp/newversion/Library/Frameworks and use +/tmp/newversion as the basis for an installer or something. + +If you want to install some part, but not all, read the main Makefile. The +frameworkinstall is composed of a couple of sub-targets that install the +framework itself, the Mac subtree, the applications and the unix tools. + +There is an extra target frameworkinstallextras that is not part of the +normal frameworkinstall which installs the Demo and Tools directories +into /Applications/MacPython-2.3, this is useful for binary distributions. + +What do all these programs do? +=============================== + +"IDLE.app" is an integrated development environment for Python: editor, +debugger, etc. + +"PythonLauncher.app" is a helper application that will handle things when you +double-click a .py, .pyc or .pyw file. For the first two it creates a Terminal +window and runs the scripts with the normal command-line Python. For the +latter it runs the script in the Python.app interpreter so the script can do +GUI-things. Keep the "alt" key depressed while dragging or double-clicking a +script to set runtime options. These options can be set once and for all +through PythonLauncher's preferences dialog. + +"BuildApplet.app" creates an applet from a Python script. Drop the script on it +and out comes a full-featured MacOS application. There is much more to this, +to be supplied later. Some useful (but outdated) info can be found in +Mac/Demo. + +The commandline scripts /usr/local/bin/python and pythonw can be used to run +non-GUI and GUI python scripts from the command line, respectively. + +How do I create a binary distribution? +====================================== + +Go to the directory "Mac/OSX/BuildScript". There you'll find a script +"build-installer.py" that does all the work. This will download and build +a number of 3th-party libaries, configures and builds a framework Python, +installs it, creates the installer pacakge files and then packs this in a +DMG image. + +The script will build a universal binary, you'll therefore have to run this +script on Mac OS X 10.4 or later and with Xcode 2.1 or later installed. + +All of this is normally done completely isolated in /tmp/_py, so it does not +use your normal build directory nor does it install into /. + +Because of the way the script locates the files it needs you have to run it +from within the BuildScript directory. The script accepts a number of +command-line arguments, run it with --help for more information. + +Odds and ends +============= + +Something to take note of is that the ".rsrc" files in the distribution are +not actually resource files, they're AppleSingle encoded resource files. The +macresource module and the Mac/OSX/Makefile cater for this, and create +".rsrc.df.rsrc" files on the fly that are normal datafork-based resource +files. + + Jack Jansen, Jack.Jansen@cwi.nl, 15-Jul-2004. + Ronald Oussoren, RonaldOussoren@mac.com, 26-May-2006 diff --git a/Mac/Resources/app/Info.plist b/Mac/Resources/app/Info.plist new file mode 100644 index 0000000..387bbed --- /dev/null +++ b/Mac/Resources/app/Info.plist @@ -0,0 +1,60 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleDocumentTypes + + + CFBundleTypeOSTypes + + **** + fold + disk + + CFBundleTypeRole + Viewer + + + CFBundleExecutable + Python + CFBundleGetInfoString + 2.5alpha0, (c) 2004 Python Software Foundation. + CFBundleHelpBookFolder + + Documentation + PythonDocumentation + + CFBundleHelpBookName + MacPython Help + CFBundleHelpTOCFile + index.html + CFBundleIconFile + PythonInterpreter.icns + CFBundleIdentifier + org.python.python + CFBundleInfoDictionaryVersion + 6.0 + CFBundleLongVersionString + 2.5alpha0, (c) 2004 Python Software Foundation. + CFBundleName + Python + CFBundlePackageType + APPL + CFBundleShortVersionString + 2.5alpha0 + CFBundleSignature + PytX + CFBundleVersion + 2.5alpha0 + CSResourcesFileMapped + + LSRequiresCarbon + + NSAppleScriptEnabled + + NSHumanReadableCopyright + (c) 2004 Python Software Foundation. + + diff --git a/Mac/Resources/app/PkgInfo b/Mac/Resources/app/PkgInfo new file mode 100644 index 0000000..67c491a --- /dev/null +++ b/Mac/Resources/app/PkgInfo @@ -0,0 +1 @@ +APPLPytX \ No newline at end of file diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/PackageManager.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/PackageManager.gif new file mode 100644 index 0000000..2b93dc8 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/PackageManager.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/community.html b/Mac/Resources/app/Resources/English.lproj/Documentation/community.html new file mode 100644 index 0000000..140a38b --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/community.html @@ -0,0 +1,69 @@ + + + + + What is MacPython? + + + + + + + + + + +
    + + +

    MacPython Community

    +
    +
    + +

    Web Sites

    + +

    The MacPython homepage, +www.cwi.nl/~jack/macpython.html +is where you can find installers, documents, links to useful packages and more. +And, of course, +www.python.org has a much larger collection +of material on Python that is not Mac-specific.

    + +

    News groups and Mailing lists

    + +

    There are a lot of mailing lists on Python. Some of the more interesting +ones are:

    +
      +
    • python-help@python.org where +you can send questions for individual support. Please check the websites mentioned +above first, though!
    • +
    • The comp.lang.python newsgroup for general +discussion. Also available as a +mailing list.
    • +
    • The comp.lang.python.announce +newsgroup for announcements. Low-volume and moderated. Also available as a +mailing list.
    • +
    • Last but not least, the pythonmac-sig +mailing list is specifically for MacPython. Discussions on the implementation of new +features, but beginners questions are welcome too.
    • +
    + +

    In addition there are Python Special Interest Group +mailing lists on a wide variety of topics such as image processing, numerical algorithms +and more.

    + +

    More

    + +

    An index of conferences, Wiki's, bookshops and more can be found at the +Community section of the Python website.

    + +

    If you find a bug you are kindly requested to report it, preferrably through the +automatic bug tracker at www.python.org

    + +

    If you want to become an active developer you are very welcome! Join the +pythonmac-sig mailing list mentioned above, and read the +Developer section on the Python website.

    + + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/doc/index.html b/Mac/Resources/app/Resources/English.lproj/Documentation/doc/index.html new file mode 100644 index 0000000..2ce7357 --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/doc/index.html @@ -0,0 +1,21 @@ + + + + + Python Language Documentation + + + +

    Python Language and runtime documentation

    + +

    This volume of documentation is rather big (17 Megabytes) and contains +a tutorial, full description of the Python library (all the modules +and packages included), formal description of the language and more.

    + +

    You can view it online, where +you can also download PDFs for printing, or you can download and install it +through the Package Manager for viewing and +searching via Apple Help Viewer.

    + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/finder.html b/Mac/Resources/app/Resources/English.lproj/Documentation/finder.html new file mode 100644 index 0000000..a8877ba --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/finder.html @@ -0,0 +1,36 @@ + + + + + Python and the Finder + + + + + +

    Running Python scripts from the Finder

    + + + + + +
    + + +

    The application PythonLauncher will start a Python interpreter + when you drop a Python source file onto it, any file with a .py + or .pyw extension. If you set PythonLauncher as the default + application to open a file +( +tell me more) this also works when you double click a Python script.

    + +

    PythonLauncher has preferences per filetype for selecting + the interpreter to use, and how to launch it: in a Terminal window + or not, etc. Holding the Option key while launching your script will + bring up a window that allows changing these settings for a single + run.

    +
    +
    + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/gui.html b/Mac/Resources/app/Resources/English.lproj/Documentation/gui.html new file mode 100644 index 0000000..252c78c --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/gui.html @@ -0,0 +1,54 @@ + + + + + Creating a User Interface with MacPython + + + + + +

    Creating a User Interface with MacPython

    + +

    There are a number of packages that allow creation of a user interface +for your Python code, each of which has its own merits:

    + +
      +
    • The Carbon package gives low-level access to the old Macintosh toolbox + calls for windows, events, dialogs and more. The FrameWork module + wraps these in a minimal framework. For documentation see the Macintosh + Library section of the Python Language and runtime + documentation and the Human Interface Toolbox section of + Apple's Carbon Documentation. + This solution is compatible with MacPython-OS9.
    • +
    • The W framework is built on top of this, and easier to use. + The MacPython IDE uses W. Some documentation is available on + Corran Webster's website. + Compatible with MacPython-OS9.
    • +
    + +

    For new work, however, one of the following packages may be better suited. +They may be available out of the box in this distribution, otherwise you +can install them through the Package Manager:

    + +
      +
    • PyObjC allows complete access to Cocoa. + In technical terms it is a + bidirectional bridge between Python and Objectve-C, similar to Apple's Java + bridge. Probably the best choice for Mac OS X-only applications, but at the + time of this writing PyObjC is still in beta.
    • + +
    • wxPython gives Python programs + access to the wxWindows GUI toolkit. Many people consider this + the best open source cross-platform GUI solution available today.
    • + +
    • Tkinter is the oldest cross-platform GUI toolkit for Python, bridging Python + to Tcl/Tk. If you install AquaTk it creates a native user interface on Mac OS X. + Documented in the Library section, Tkinter subsection of the + Python Language and runtime documentation. Tkinter + is not available for MacPython-OS9.
    • +
    + + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/IDE.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/IDE.gif new file mode 100644 index 0000000..da9325d Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/IDE.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif new file mode 100644 index 0000000..baa400e Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/entering_in_new_window.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/hello_world.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/hello_world.gif new file mode 100644 index 0000000..c7390af Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/hello_world.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/index.html b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/index.html new file mode 100644 index 0000000..a169f5e --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/index.html @@ -0,0 +1,222 @@ + + + + One Day of MacPython IDE Toying + + + + +

    One Day of MacPython IDE Toying

    + + + + + +
    + + +

    This document gives a very basic introduction to the + MacPython Integrated Development Environment (IDE) on Mac OS. It was + written specifically for MacPython 2.3 on Mac OS X, but most of + it is applicable to MacPython-OS9 too. It is based on + "One + Day of IDLE Toying" by Danny Yoo, which you should read if + you want to use the cross-platform IDLE Python development + environment.

    + +
    +
    +
    + +

    Ok, let's assume that we've already installed Python. (If not, we can +visit: http://www.cwi.nl/~jack/macpython.html +or http://python.org +and download the most recent Python interpreter. Get the Mac OSX binary +installer.) The first thing we'd like to do is actually start running it! +We can do this by opening up the IDE, which should be in Applications +under the newly-created MacPython program folder:

    image of IDE icon

    + +

    + +

    The IDE starts up and shows an interactive window:

    +

    image of new window

    + +

    If the window does not show up (because you have run the IDE before +and closed it: it remembers that between runs) open it with the Windows->Python Interactive +menu entry.

    + +

    This is the interactive window to the IDE, it allows us to enter +commands directly into Python, and as soon as we enter a command, +Python will execute it and spit its result back to us. We'll be +using this interactive window a lot when we're exploring Python: it's +very nice because we get back our results immediately. If it helps, +we can think of it as a very powerful calculator.

    + +

    + +

    Let's try something now! As per tradition, let's get Python to say +the immortal words, "Hello World". image of hello world program

    Those '>>>' signs act as a prompt +for us: Python is ready to read in a new command by giving us that +visual cue. Also, we notice that as we enter commands, Python will +give us its output immediately. +

    + +

    + +

    Ok, this seems pretty simple enough. Let's try a few more +commands. If we look below:

    + +

    image of command window

    + +

    we'll see the result of running a few more commands. Don't worry +too much about knowing the exact rules for making programs yet: the +idea is that we can experiment with Python by typing in commands. If +things don't work, then we can correct the mistake, and try it +again.

    + +

    If you got to this point, you now know enough to start playing +around with Python! Crack open one of the tutorials from the Python For Beginners web +page, and start exploring with the interpreter. No time limit here. *grin*

    + +

    + +

    Now that we've paddled long enough, we might be asking: ok, this is +neat, but if we close down Python and start it up again, how do we get +the computer to remember what we typed?

    + +

    The solution is a little subtle: we can't directly save what's in +the interpreter window, because it will include both our commands and +the system's responses. What we'd like is to make a prepared file, +with just our own commands, and to be able to save that file as a +document. When we're in the mood, we can later open that file and +"run" Python over it, saving us the time of retyping the whole +thing over again.

    + +

    Let's try this. First, let's start with a clean slate by opening +up a new window.

    + +

    image of making new window

    + +

    Here's the result of that menu command:

    + +

    image of new window

    + +

    We notice that there's nothing in this new window. What this means +is that this file is purely for our commands: Python won't interject +with its own responses as we enter the program, that is, not until we +tell it to. This is called an edit window, and it is very similar +to edit windows in other editors such as TextEdit or BBEdit.

    + +

    + +

    What we wanted to do before was save some of the stuff we had +tried out on the interpreter window. Let's do that by typing (or +copy/pasting) those commands into our edit window.

    +

    image of entering commands

    + +

    Ok, we're done with copying and pasting. +One big thing to notice +is that we're careful to get rid of the ">>>" +prompts because they're not really part of our program. The +interpreter uses them just to tell us that we're in the interpreter, +but now that we're editing in a separate file, we can remove the +artifacts that the interpreter introduces. +I have added +an extra empty print statement so our output ends with a newline. +

    + +

    + +

    Let's save the file now. The Save command is located under the File menu:

    +

    image of saving file

    + + +

    + +

    Now that we've saved the program, how do we run the program? Use the +Run All button at the top of the editing window, or the equivalent +menu command Python->Run Window. The output will appear in a new +window called Output Window.

    + +

    By the way, one thing to notice is that I made a typo: I didn't +quite copy exactly what I had entered in the interpreter window +before. Does this affect things?

    + +

    image of syntax error

    + +

    Ooops. Here is an example of what Python calls a "syntax error". +Python sees that we made a typo, and warns us to take a much closer +look at our program. The designers of Python feel that having the +system point out the error is better than trying to guess at what the +programmer meant. Press the Edit button and you will be brought to +the trouble spot.

    + +

    Python is often perceptive enough to direct us toward the problem, +and in this case, it's telling us that we forgot to put something at +the end of this line. In this case, we need to add a +quotation mark at the end. Let's add that in now.

    + +

    Other errors, which usually occur later, when your program has +already done something, result in a different dialog that allows you +to look at variables and such in addition to showing you where +the error occurred.

    + +

    + +

    Ok, let's say that we fixed that silly typo. Let's try to run the +program again. This gives us a new window, the Output window, showing +the output of our program:

    +

    image of output window

    + +

    + +

    As we play with Python, we'll find ourselves "switching modes" +between the Interpreter window and the edit window. However, +if we try anything more complicated than two or three lines it +is often a good idea to work in an edit window. Align +your edit and output window such that you can see them at the same time.

    + +

    This is pretty much all we need to know about the MacPython IDE to actually do +interesting things. There is a lot more to the IDE, here is a quick +breakdown of things to see and explore:

    + +
      +
    • All sorts of edit commands such as find and replace can be + used in the editor windows. See the Edit menu.
    • + +
    • The bottom of the edit window has the scrollbar, but at the + left are two navigation devices: a line number box that you can type + numbers into to quickly go to a specific place, and a popup menu + that lists all classes, functions and methods in your file.
    • + +
    • Above the vertical scrollbar you find another popup menu, this + influences how the Run command works. You should try the debugger + some time! If you do, and you wonder what the new small column on + the left of your script is: you can click in it to make Python stop + when it reaches this line so you can inspect things. The profiler + is also nifty: it shows you where your program is spending its time.
    • + +
    • The module browser (Python->Module Browser) shows you all Python + modules currently loaded. You can look at the contents of the module with + Browse... and (for modules written in Python) at the source with Source...
    • + +
    • The Package Manager (under the File menu, also available as a + separate application) allows you to easily install Python extension packages + for all sorts of things: scientific computation, image processing, + building user interfaces and more.
    • + +
    • The Help menu gives you quick access to both the Python documentation, + if you have installed it with the Package Manager, and the Apple Developer + documentation.
    • + +
    • The File->Save as Applet menu command saves your script as a MacOSX + application. This allows you to create a script that you can drop files on, + and much more. The IDE itself is such an applet, completely written in Python.
    • + +
    + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif new file mode 100644 index 0000000..e7cca3d Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/loading_ide.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif new file mode 100644 index 0000000..d2022c8 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/making_new_window.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif new file mode 100644 index 0000000..7268a84 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_ide_window.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif new file mode 100644 index 0000000..dd6cca3 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/new_window_made.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/output_window.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/output_window.gif new file mode 100644 index 0000000..568dcb5 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/output_window.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif new file mode 100644 index 0000000..6e5c926 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/saving_edited_file.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif new file mode 100644 index 0000000..1dba570 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/simple_commands.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif new file mode 100644 index 0000000..2e95b87 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/ide/syntax_error.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/index.html b/Mac/Resources/app/Resources/English.lproj/Documentation/index.html new file mode 100644 index 0000000..ef12c10 --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/index.html @@ -0,0 +1,51 @@ + + + + + MacPython Help + + + + + + + +

    MacPython Help

    + + + + + +
    + + +

    Choose a topic, or enter keywords into the search field:

    + + +
    +
    + + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/intro.html b/Mac/Resources/app/Resources/English.lproj/Documentation/intro.html new file mode 100644 index 0000000..f0ab371 --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/intro.html @@ -0,0 +1,76 @@ + + + + + What is MacPython? + + + + + +

    What is MacPython?

    + + + + + +
    + + +

    Python is a programming language. MacPython is a package containing +that programming language plus Mac-specific tools and extensions.

    + +
    +
    + +

    The Python Language

    +

    The Python programming language is available for many hardware +platforms, and most general documentation is Unix- or Windows-centered. Keep +this in mind when reading the rest of this help, or information on the web. +

    + +

    The Python website, www.python.org, +has a Beginners Guide section including an +executive summary on +the language and a +comparison of Python +to other languages. Or read the (rather longwinded) Python +Tutorial in the Python Language and runtime documentation.

    + +

    MacPython contains a complete unix interpreter so +if you are familiar with Python on unix you should feel right at home.

    + +

    MacPython additions

    + +

    The MacPython Integrated Development Environment (IDE) allows +easy editing, running and debugging of scripts. Read the +Introduction +to the IDE to whet your appetite.

    + +

    MacPython comes with lots of modules that allow access to +MacOS-specific technology, such as Carbon, Quicktime and AppleScript. +See the Macintosh +Modules section of the +Python Language and runtime documentation, +but please keep in mind that some information there still pertains to +Mac OS 9. + +Full access to the Cocoa APIs +and tools such as Interface Builder is available separately through the +Package Manager.

    + +

    The Package Manager also gives you access to extension +packages for cross-platform GUI development (Tkinter, wxPython, PyOpenGL), +image processing (PIL), scientific +computing (Numeric) and much more. PyObjC deserves a special mention: it allows +transparent access to Cocoa and Interface Builder, similar to what Java provides, +thereby making Python a first class citizen in the Mac OS X developer world.

    + +

    Python scripts can be saved as applets, semi-standalone applications +that work just like a normal application. Additionally you can even create +true standalone application that have everything embedded and can be +shipped to anyone, without the need to install Python. You do not +need to install the Apple Developer Tools for this.

    + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/packman.html b/Mac/Resources/app/Resources/English.lproj/Documentation/packman.html new file mode 100644 index 0000000..355e0da --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/packman.html @@ -0,0 +1,64 @@ + + + + + Python Package Manager + + + + + +

    Installing additional Python Packages

    + + + + + +
    + + +

    The Python Package Manager helps you installing additional + packages that enhance Python. It determines the exact MacOS version + and Python version you have and uses that information to download + a database that has packages that are test and tried on that + combination. In other words: if something is in your Package Manager + window but does not work you are free to blame the database maintainer.

    + +

    PackageManager then checks which of the packages you have installed + and which ones not. This should also work when you have installed packages + outside of PackageManager. + You can select packages and install them, and PackageManager will work + out the requirements and install these too.

    + +

    Often PackageManager will list a package in two flavors: binary + and source. Binary should always work, source will only work if + you have installed the Apple Developer Tools. PackageManager will warn + you about this, and also about other external dependencies.

    + +

    PackageManager is available as a separate application and also + as a function of the IDE, through the File->Package Manager menu + entry.

    + +

    Troubleshooting

    + +

    If package manager fails to open the database first check that you are + connected to the internet. If you are connected then the problem + could be that there is no database (yet?) for your version of Mac OS X. + You may be able to find an alternative + database that works for your system at + http://www.python.org/packman. + In the standalone Package Manager you can then open such an alternative database + with the File->Open URL... command, but you should realize that + you are now on untested ground.

    + +

    Another potential problem source is that you are behind a firewall. This version + of PackageManager uses the Unix method of setting a firewall: you need to set the + environment variable http_proxy to "http://proxyhost:port". + See Apple Technical + Q&A QA1067 for instructions.

    + +
    +
    + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/python.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/python.gif new file mode 100644 index 0000000..3d4aa5d Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/python.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/pythonsmall.gif b/Mac/Resources/app/Resources/English.lproj/Documentation/pythonsmall.gif new file mode 100644 index 0000000..440225e Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/Documentation/pythonsmall.gif differ diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/scripting.html b/Mac/Resources/app/Resources/English.lproj/Documentation/scripting.html new file mode 100644 index 0000000..16321cb --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/scripting.html @@ -0,0 +1,53 @@ + + + + + Controlling other Applications from MacPython + + + + + +

    Controlling other Applications from MacPython

    + +

    Python has a fairly complete implementation of the Open Scripting +Architecure (OSA, also commonly referred to as AppleScript), allowing +you to control scriptable applications from your Python program, +and with a fairly pythonic interface. This piece of +Python:

    + +
    
    +import Finder
    +
    +f = Finder.Finder()
    +print f.get(f.window(1).name)
    +
    + +

    is identical to the following piece of AppleScript:

    + +
    
    +tell application "Finder"
    +	get name of window 1
    +end tell
    +
    + +

    To send AppleEvents to an application you must first create the Python +modules interfacing to the terminology of the application (what +Script Editor calls the "Dictionary"). Use the IDE menu command +File->Generate OSA Suite... for this. For more control run

    + +
    +pythonw .../Lib/plat-mac/gensuitemodule.py --help +
    + +

    from a terminal window.

    + +

    Creating a scriptable application in Python

    + +You can also create a scriptable application in Python, but this is not +very well documented. For Carbon +applications you should look at the MiniAEFrame module. + + + diff --git a/Mac/Resources/app/Resources/English.lproj/Documentation/shell.html b/Mac/Resources/app/Resources/English.lproj/Documentation/shell.html new file mode 100644 index 0000000..56f5646 --- /dev/null +++ b/Mac/Resources/app/Resources/English.lproj/Documentation/shell.html @@ -0,0 +1,52 @@ + + + + + Python and the Unix Shell + + + + + +

    Running Python scripts from the Unix Shell

    + + + + + +
    + + +

    MacPython 2.3 installs a perfectly normal Unix commandline + python interpreter in /usr/local/bin/python. As of Mac OS X 10.2, however, + /usr/local/bin is not on the search path of your shell. Moreover, + Apple's python 2.2, which lives in /usr/bin is on your + search path, so this can lead to confusion.

    + +

    If you use tcsh you should add the following line + to the file .login in your home directory and restart Terminal: +
    + setenv PATH /usr/local/bin:$PATH +

    + +

    If you use bash or zsh + you should add the following line + to the file .profile in your home directory and restart Terminal: +
    + export PATH=/usr/local/bin:$PATH +

    + +

    GUI scripts

    + +

    Due to the way MacOS handles windowing applications you need to run + all scripts that use the window manager (be it through + Carbon, Cocoa, Tkinter, wxPython, PyOpenGL or anything else) with the + pythonw interpreter, also installed in /usr/local/bin.

    + +

    Running with python results in an inability to bring the + script to the front, or interacting with it.

    +
    +
    + + diff --git a/Mac/Resources/app/Resources/English.lproj/InfoPlist.strings b/Mac/Resources/app/Resources/English.lproj/InfoPlist.strings new file mode 100644 index 0000000..f8a8bc1 Binary files /dev/null and b/Mac/Resources/app/Resources/English.lproj/InfoPlist.strings differ diff --git a/Mac/Resources/app/Resources/PythonApplet.icns b/Mac/Resources/app/Resources/PythonApplet.icns new file mode 100644 index 0000000..c8aad9f Binary files /dev/null and b/Mac/Resources/app/Resources/PythonApplet.icns differ diff --git a/Mac/Resources/app/Resources/PythonInterpreter.icns b/Mac/Resources/app/Resources/PythonInterpreter.icns new file mode 100644 index 0000000..e09fd38 Binary files /dev/null and b/Mac/Resources/app/Resources/PythonInterpreter.icns differ diff --git a/Mac/Resources/framework/English.lproj/InfoPlist.strings b/Mac/Resources/framework/English.lproj/InfoPlist.strings new file mode 100644 index 0000000..cc24bfc Binary files /dev/null and b/Mac/Resources/framework/English.lproj/InfoPlist.strings differ diff --git a/Mac/Resources/framework/Info.plist b/Mac/Resources/framework/Info.plist new file mode 100644 index 0000000..302ff48 --- /dev/null +++ b/Mac/Resources/framework/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + Python + CFBundleGetInfoString + Python Runtime and Library + CFBundleIdentifier + org.python.python + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Python + CFBundlePackageType + FMWK + CFBundleShortVersionString + 2.5 + CFBundleSignature + ???? + CFBundleVersion + 2.5 + + diff --git a/Mac/Resources/framework/version.plist b/Mac/Resources/framework/version.plist new file mode 100644 index 0000000..7527442 --- /dev/null +++ b/Mac/Resources/framework/version.plist @@ -0,0 +1,18 @@ + + + + + BuildVersion + 1 + CFBundleShortVersionString + 2.5alpha0 + CFBundleVersion + 2.5alpha0 + ProjectName + Python + ReleaseStatus + alfa + SourceVersion + 2.4a0 + + diff --git a/Mac/Resources/iconsrc/IDE.psd b/Mac/Resources/iconsrc/IDE.psd new file mode 100644 index 0000000..b9637b9 Binary files /dev/null and b/Mac/Resources/iconsrc/IDE.psd differ diff --git a/Mac/Resources/iconsrc/PackageManager.psd b/Mac/Resources/iconsrc/PackageManager.psd new file mode 100644 index 0000000..42f41b1 Binary files /dev/null and b/Mac/Resources/iconsrc/PackageManager.psd differ diff --git a/Mac/Resources/iconsrc/PythonApplet.psd b/Mac/Resources/iconsrc/PythonApplet.psd new file mode 100644 index 0000000..7458b52 Binary files /dev/null and b/Mac/Resources/iconsrc/PythonApplet.psd differ diff --git a/Mac/Resources/iconsrc/PythonCompiled.psd b/Mac/Resources/iconsrc/PythonCompiled.psd new file mode 100755 index 0000000..61fc4d1 Binary files /dev/null and b/Mac/Resources/iconsrc/PythonCompiled.psd differ diff --git a/Mac/Resources/iconsrc/PythonIcon.psd b/Mac/Resources/iconsrc/PythonIcon.psd new file mode 100755 index 0000000..d818dc6 Binary files /dev/null and b/Mac/Resources/iconsrc/PythonIcon.psd differ diff --git a/Mac/Resources/iconsrc/PythonSource.psd b/Mac/Resources/iconsrc/PythonSource.psd new file mode 100755 index 0000000..eba8f28 Binary files /dev/null and b/Mac/Resources/iconsrc/PythonSource.psd differ diff --git a/Mac/Resources/iconsrc/PythonWSource.psd b/Mac/Resources/iconsrc/PythonWSource.psd new file mode 100644 index 0000000..2b84d94 Binary files /dev/null and b/Mac/Resources/iconsrc/PythonWSource.psd differ diff --git a/Mac/Tools/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py b/Mac/Tools/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py new file mode 100644 index 0000000..58d7307 --- /dev/null +++ b/Mac/Tools/Doc/HelpIndexingTool/Help_Indexing_Tool_Suite.py @@ -0,0 +1,110 @@ +"""Suite Help Indexing Tool Suite: Special events that just the Help Indexing Tool supports. +Level 0, version 0 + +Generated from /Developer/Applications/Apple Help Indexing Tool.app +AETE/AEUT resource version 1/1, language 0, script 0 +""" + +import aetools +import MacOS + +_code = 'HIT ' + +class Help_Indexing_Tool_Suite_Events: + + def turn_anchor_indexing(self, _object, _attributes={}, **_arguments): + """turn anchor indexing: Turns anchor indexing on or off. + Required argument: \xd2on\xd3 or \xd2off\xd3, to turn anchor indexing on or off + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'HIT ' + _subcode = 'tAnc' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + _argmap_turn_remote_root = { + 'with_root_url' : 'rURL', + } + + def turn_remote_root(self, _object, _attributes={}, **_arguments): + """turn remote root: Turn usage of remote root for content on the web on or off. If turning \xd2on\xd3, supply a string as second parameter. + Required argument: \xd2on\xd3 or \xd2off\xd3, to turn remote root on or off + Keyword argument with_root_url: The remote root to use, in the form of \xd2http://www.apple.com/help/\xd3. + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'HIT ' + _subcode = 'tRem' + + aetools.keysubst(_arguments, self._argmap_turn_remote_root) + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + def use_tokenizer(self, _object, _attributes={}, **_arguments): + """use tokenizer: Tells the indexing tool which tokenizer to use. + Required argument: Specify \xd2English\xd3, \xd2European\xd3, \xd2Japanese\xd3, \xd2Korean\xd3, or \xd2Simple\xd3. + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'HIT ' + _subcode = 'uTok' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + +class application(aetools.ComponentItem): + """application - Application class """ + want = 'capp' +class _Prop_idleStatus(aetools.NProperty): + """idleStatus - """ + which = 'sIdl' + want = 'bool' +application._superclassnames = [] +application._privpropdict = { + 'idleStatus' : _Prop_idleStatus, +} +application._privelemdict = { +} + +# +# Indices of types declared in this module +# +_classdeclarations = { + 'capp' : application, +} + +_propdeclarations = { + 'sIdl' : _Prop_idleStatus, +} + +_compdeclarations = { +} + +_enumdeclarations = { +} diff --git a/Mac/Tools/Doc/HelpIndexingTool/Miscellaneous_Standards.py b/Mac/Tools/Doc/HelpIndexingTool/Miscellaneous_Standards.py new file mode 100644 index 0000000..3cf745f --- /dev/null +++ b/Mac/Tools/Doc/HelpIndexingTool/Miscellaneous_Standards.py @@ -0,0 +1,49 @@ +"""Suite Miscellaneous Standards: Useful events that aren\xd5t in any other suite +Level 0, version 0 + +Generated from /Developer/Applications/Apple Help Indexing Tool.app +AETE/AEUT resource version 1/1, language 0, script 0 +""" + +import aetools +import MacOS + +_code = 'misc' + +class Miscellaneous_Standards_Events: + + def revert(self, _object, _attributes={}, **_arguments): + """revert: Revert an object to the most recently saved version + Required argument: object to revert + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'misc' + _subcode = 'rvrt' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + +# +# Indices of types declared in this module +# +_classdeclarations = { +} + +_propdeclarations = { +} + +_compdeclarations = { +} + +_enumdeclarations = { +} diff --git a/Mac/Tools/Doc/HelpIndexingTool/Required_Suite.py b/Mac/Tools/Doc/HelpIndexingTool/Required_Suite.py new file mode 100644 index 0000000..eb9fee0 --- /dev/null +++ b/Mac/Tools/Doc/HelpIndexingTool/Required_Suite.py @@ -0,0 +1,32 @@ +"""Suite Required Suite: Terms that every application should support +Level 1, version 1 + +Generated from /Developer/Applications/Apple Help Indexing Tool.app +AETE/AEUT resource version 1/1, language 0, script 0 +""" + +import aetools +import MacOS + +_code = 'reqd' + +from StdSuites.Required_Suite import * +class Required_Suite_Events(Required_Suite_Events): + + pass + + +# +# Indices of types declared in this module +# +_classdeclarations = { +} + +_propdeclarations = { +} + +_compdeclarations = { +} + +_enumdeclarations = { +} diff --git a/Mac/Tools/Doc/HelpIndexingTool/Standard_Suite.py b/Mac/Tools/Doc/HelpIndexingTool/Standard_Suite.py new file mode 100644 index 0000000..4f6604c --- /dev/null +++ b/Mac/Tools/Doc/HelpIndexingTool/Standard_Suite.py @@ -0,0 +1,343 @@ +"""Suite Standard Suite: Common terms for most applications +Level 1, version 1 + +Generated from /Developer/Applications/Apple Help Indexing Tool.app +AETE/AEUT resource version 1/1, language 0, script 0 +""" + +import aetools +import MacOS + +_code = 'CoRe' + +from StdSuites.Standard_Suite import * +class Standard_Suite_Events(Standard_Suite_Events): + + _argmap_close = { + 'saving' : 'savo', + 'in_' : 'kfil', + } + + def close(self, _object, _attributes={}, **_arguments): + """close: Close an object + Required argument: the objects to close + Keyword argument saving: specifies whether or not changes should be saved before closing + Keyword argument in_: the file in which to save the object + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'core' + _subcode = 'clos' + + aetools.keysubst(_arguments, self._argmap_close) + _arguments['----'] = _object + + aetools.enumsubst(_arguments, 'savo', _Enum_savo) + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + def data_size(self, _object, _attributes={}, **_arguments): + """data size: Return the size in bytes of an object + Required argument: the object whose data size is to be returned + Keyword argument _attributes: AppleEvent attribute dictionary + Returns: the size of the object in bytes + """ + _code = 'core' + _subcode = 'dsiz' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + def get(self, _object, _attributes={}, **_arguments): + """get: Get the data for an object + Required argument: the object whose data is to be returned + Keyword argument _attributes: AppleEvent attribute dictionary + Returns: The data from the object + """ + _code = 'core' + _subcode = 'getd' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + _argmap_make = { + 'new' : 'kocl', + 'at' : 'insh', + 'with_data' : 'data', + 'with_properties' : 'prdt', + } + + def make(self, _no_object=None, _attributes={}, **_arguments): + """make: Make a new element + Keyword argument new: the class of the new element + Keyword argument at: the location at which to insert the element + Keyword argument with_data: the initial data for the element + Keyword argument with_properties: the initial values for the properties of the element + Keyword argument _attributes: AppleEvent attribute dictionary + Returns: Object specifier for the new element + """ + _code = 'core' + _subcode = 'crel' + + aetools.keysubst(_arguments, self._argmap_make) + if _no_object != None: raise TypeError, 'No direct arg expected' + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + def open(self, _object, _attributes={}, **_arguments): + """open: Open the specified object(s) + Required argument: Objects to open. Can be a list of files or an object specifier. + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'aevt' + _subcode = 'odoc' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + def print_(self, _object, _attributes={}, **_arguments): + """print: Print the specified object(s) + Required argument: Objects to print. Can be a list of files or an object specifier. + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'aevt' + _subcode = 'pdoc' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + _argmap_save = { + 'in_' : 'kfil', + 'as' : 'fltp', + } + + def save(self, _object, _attributes={}, **_arguments): + """save: save a set of objects + Required argument: Objects to save. + Keyword argument in_: the file in which to save the object(s) + Keyword argument as: the file type of the document in which to save the data + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'core' + _subcode = 'save' + + aetools.keysubst(_arguments, self._argmap_save) + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + _argmap_set = { + 'to' : 'data', + } + + def set(self, _object, _attributes={}, **_arguments): + """set: Set an object\xd5s data + Required argument: the object to change + Keyword argument to: the new value + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'core' + _subcode = 'setd' + + aetools.keysubst(_arguments, self._argmap_set) + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + +class application(aetools.ComponentItem): + """application - An application program """ + want = 'capp' +# element 'cwin' as ['indx', 'name', 'rele'] +# element 'docu' as ['name'] + +class window(aetools.ComponentItem): + """window - A Window """ + want = 'cwin' +class _Prop_bounds(aetools.NProperty): + """bounds - the boundary rectangle for the window """ + which = 'pbnd' + want = 'qdrt' +class _Prop_closeable(aetools.NProperty): + """closeable - Does the window have a close box? """ + which = 'hclb' + want = 'bool' +class _Prop_floating(aetools.NProperty): + """floating - Does the window float? """ + which = 'isfl' + want = 'bool' +class _Prop_index(aetools.NProperty): + """index - the number of the window """ + which = 'pidx' + want = 'long' +class _Prop_modal(aetools.NProperty): + """modal - Is the window modal? """ + which = 'pmod' + want = 'bool' +class _Prop_name(aetools.NProperty): + """name - the title of the window """ + which = 'pnam' + want = 'itxt' +class _Prop_position(aetools.NProperty): + """position - upper left coordinates of window """ + which = 'ppos' + want = 'QDpt' +class _Prop_resizable(aetools.NProperty): + """resizable - Is the window resizable? """ + which = 'prsz' + want = 'bool' +class _Prop_titled(aetools.NProperty): + """titled - Does the window have a title bar? """ + which = 'ptit' + want = 'bool' +class _Prop_visible(aetools.NProperty): + """visible - is the window visible? """ + which = 'pvis' + want = 'bool' +class _Prop_zoomable(aetools.NProperty): + """zoomable - Is the window zoomable? """ + which = 'iszm' + want = 'bool' +class _Prop_zoomed(aetools.NProperty): + """zoomed - Is the window zoomed? """ + which = 'pzum' + want = 'bool' + +class document(aetools.ComponentItem): + """document - A Document """ + want = 'docu' +class _Prop_modified(aetools.NProperty): + """modified - Has the document been modified since the last save? """ + which = 'imod' + want = 'bool' +application._superclassnames = [] +application._privpropdict = { +} +application._privelemdict = { + 'document' : document, + 'window' : window, +} +window._superclassnames = [] +window._privpropdict = { + 'bounds' : _Prop_bounds, + 'closeable' : _Prop_closeable, + 'floating' : _Prop_floating, + 'index' : _Prop_index, + 'modal' : _Prop_modal, + 'name' : _Prop_name, + 'position' : _Prop_position, + 'resizable' : _Prop_resizable, + 'titled' : _Prop_titled, + 'visible' : _Prop_visible, + 'zoomable' : _Prop_zoomable, + 'zoomed' : _Prop_zoomed, +} +window._privelemdict = { +} +document._superclassnames = [] +document._privpropdict = { + 'modified' : _Prop_modified, + 'name' : _Prop_name, +} +document._privelemdict = { +} +_Enum_savo = { + 'yes' : 'yes ', # Save objects now + 'no' : 'no ', # Do not save objects + 'ask' : 'ask ', # Ask the user whether to save +} + + +# +# Indices of types declared in this module +# +_classdeclarations = { + 'capp' : application, + 'cwin' : window, + 'docu' : document, +} + +_propdeclarations = { + 'hclb' : _Prop_closeable, + 'imod' : _Prop_modified, + 'isfl' : _Prop_floating, + 'iszm' : _Prop_zoomable, + 'pbnd' : _Prop_bounds, + 'pidx' : _Prop_index, + 'pmod' : _Prop_modal, + 'pnam' : _Prop_name, + 'ppos' : _Prop_position, + 'prsz' : _Prop_resizable, + 'ptit' : _Prop_titled, + 'pvis' : _Prop_visible, + 'pzum' : _Prop_zoomed, +} + +_compdeclarations = { +} + +_enumdeclarations = { + 'savo' : _Enum_savo, +} diff --git a/Mac/Tools/Doc/HelpIndexingTool/__init__.py b/Mac/Tools/Doc/HelpIndexingTool/__init__.py new file mode 100644 index 0000000..5359df5 --- /dev/null +++ b/Mac/Tools/Doc/HelpIndexingTool/__init__.py @@ -0,0 +1,78 @@ +""" +Package generated from /Developer/Applications/Apple Help Indexing Tool.app +""" +import aetools +Error = aetools.Error +import Standard_Suite +import Help_Indexing_Tool_Suite +import odds_and_ends +import Miscellaneous_Standards +import Required_Suite + + +_code_to_module = { + 'CoRe' : Standard_Suite, + 'HIT ' : Help_Indexing_Tool_Suite, + 'Odds' : odds_and_ends, + 'misc' : Miscellaneous_Standards, + 'reqd' : Required_Suite, +} + + + +_code_to_fullname = { + 'CoRe' : ('HelpIndexingTool.Standard_Suite', 'Standard_Suite'), + 'HIT ' : ('HelpIndexingTool.Help_Indexing_Tool_Suite', 'Help_Indexing_Tool_Suite'), + 'Odds' : ('HelpIndexingTool.odds_and_ends', 'odds_and_ends'), + 'misc' : ('HelpIndexingTool.Miscellaneous_Standards', 'Miscellaneous_Standards'), + 'reqd' : ('HelpIndexingTool.Required_Suite', 'Required_Suite'), +} + +from Standard_Suite import * +from Help_Indexing_Tool_Suite import * +from odds_and_ends import * +from Miscellaneous_Standards import * +from Required_Suite import * + +def getbaseclasses(v): + if not getattr(v, '_propdict', None): + v._propdict = {} + v._elemdict = {} + for superclassname in getattr(v, '_superclassnames', []): + superclass = eval(superclassname) + getbaseclasses(superclass) + v._propdict.update(getattr(superclass, '_propdict', {})) + v._elemdict.update(getattr(superclass, '_elemdict', {})) + v._propdict.update(getattr(v, '_privpropdict', {})) + v._elemdict.update(getattr(v, '_privelemdict', {})) + +import StdSuites + +# +# Set property and element dictionaries now that all classes have been defined +# +getbaseclasses(window) +getbaseclasses(application) +getbaseclasses(document) +getbaseclasses(application) + +# +# Indices of types declared in this module +# +_classdeclarations = { + 'cwin' : window, + 'capp' : application, + 'docu' : document, + 'capp' : application, +} + + +class HelpIndexingTool(Standard_Suite_Events, + Help_Indexing_Tool_Suite_Events, + odds_and_ends_Events, + Miscellaneous_Standards_Events, + Required_Suite_Events, + aetools.TalkTo): + _signature = 'hiti' + + _moduleName = 'HelpIndexingTool' diff --git a/Mac/Tools/Doc/HelpIndexingTool/odds_and_ends.py b/Mac/Tools/Doc/HelpIndexingTool/odds_and_ends.py new file mode 100644 index 0000000..7ee46f3 --- /dev/null +++ b/Mac/Tools/Doc/HelpIndexingTool/odds_and_ends.py @@ -0,0 +1,49 @@ +"""Suite odds and ends: Things that should be in some standard suite, but aren\xd5t +Level 1, version 1 + +Generated from /Developer/Applications/Apple Help Indexing Tool.app +AETE/AEUT resource version 1/1, language 0, script 0 +""" + +import aetools +import MacOS + +_code = 'Odds' + +class odds_and_ends_Events: + + def select(self, _object=None, _attributes={}, **_arguments): + """select: Select the specified object + Required argument: the object to select + Keyword argument _attributes: AppleEvent attribute dictionary + """ + _code = 'misc' + _subcode = 'slct' + + if _arguments: raise TypeError, 'No optional args expected' + _arguments['----'] = _object + + + _reply, _arguments, _attributes = self.send(_code, _subcode, + _arguments, _attributes) + if _arguments.get('errn', 0): + raise aetools.Error, aetools.decodeerror(_arguments) + # XXXX Optionally decode result + if _arguments.has_key('----'): + return _arguments['----'] + + +# +# Indices of types declared in this module +# +_classdeclarations = { +} + +_propdeclarations = { +} + +_compdeclarations = { +} + +_enumdeclarations = { +} diff --git a/Mac/Tools/Doc/README b/Mac/Tools/Doc/README new file mode 100644 index 0000000..4f4d53d --- /dev/null +++ b/Mac/Tools/Doc/README @@ -0,0 +1,35 @@ +In this directory you can build the Python documentation in a form that +is suitable for access with Apple Help Viewer. This will enable the +"Python Documentation" menu entries in the MacPython IDE Help menu. + +Unfortunately the procedure to build the docs is not very streamlined. + +First, edit setup.py. At the top, edit MAJOR_VERSION and MINOR_VERSION, +and check that DESTDIR makes sense. The documentation will be installed +inside PythonIDE.app. + +In DocBuild.initialize_options, set self.download to True if you want to +download the docs. Set it to False if you want to build the docs from +the source tree, but this requires LaTex and lots of other stuff. +Doable, but not easy. + +Second, if you want to download the docs you may need to do a couple +more edits. The way the docs are packaged will often change between +major releases. Fiddle DocBuild.downloadDocs to make it do the right +thing (download the docs from python.org, unpack them, rename the +directory to "build/html"). + +After these edits you should be ready to roll. "pythonw setup.py build" +should download and unpack (or build) the docs. Next, it will do some +magic to make the docs indexable. Finally, it will run the Apple Help +Indexing Tool. (This last step is the reason you must use "pythonw" as +opposed to "python"). Usually it will time out while waiting for AHIT to +do its work. Wait until AHIT is done. + +Now you're ready to install with "python setup.py install". + +After this is done test your work. Fire up PythonIDE, and check that +Help->Python Documentation brings up the documentation in the Help Viewer. +Also open an IDE edit window, type something like "import sys", select +"import", and use Help->Lookup in Python Documentation to check that the +index has been generated correctly. diff --git a/Mac/Tools/Doc/setup.py b/Mac/Tools/Doc/setup.py new file mode 100644 index 0000000..bd86a20 --- /dev/null +++ b/Mac/Tools/Doc/setup.py @@ -0,0 +1,214 @@ +# Build and install an Apple Help Viewer compatible version of the Python +# documentation into the framework. +# Code by Bill Fancher, with some modifications by Jack Jansen. +# +# You must run this as a two-step process +# 1. python setupDocs.py build +# 2. Wait for Apple Help Indexing Tool to finish +# 3. python setupDocs.py install +# +# To do: +# - test whether the docs are available locally before downloading +# - fix buildDocsFromSource +# - Get documentation version from sys.version, fallback to 2.2.1 +# - See if we can somehow detect that Apple Help Indexing Tool is finished +# - data_files to setup() doesn't seem the right way to pass the arguments +# +import sys, os, re +from distutils.cmd import Command +from distutils.command.build import build +from distutils.core import setup +from distutils.file_util import copy_file +from distutils.dir_util import copy_tree +from distutils.log import log +from distutils.spawn import spawn +from distutils import sysconfig, dep_util +from distutils.util import change_root +import HelpIndexingTool +import Carbon.File +import time + +MAJOR_VERSION='2.4' +MINOR_VERSION='2.4.1' +DESTDIR='/Applications/MacPython-%s/PythonIDE.app/Contents/Resources/English.lproj/PythonDocumentation' % MAJOR_VERSION + +class DocBuild(build): + def initialize_options(self): + build.initialize_options(self) + self.build_html = None + self.build_dest = None + self.download = 1 + self.doc_version = MINOR_VERSION # Only needed if download is true + + def finalize_options(self): + build.finalize_options(self) + if self.build_html is None: + self.build_html = os.path.join(self.build_base, 'html') + if self.build_dest is None: + self.build_dest = os.path.join(self.build_base, 'PythonDocumentation') + + def spawn(self, *args): + spawn(args, 1, self.verbose, self.dry_run) + + def downloadDocs(self): + workdir = os.getcwd() + # XXX Note: the next strings may change from version to version + url = 'http://www.python.org/ftp/python/doc/%s/html-%s.tar.bz2' % \ + (self.doc_version,self.doc_version) + tarfile = 'html-%s.tar.bz2' % self.doc_version + dirname = 'Python-Docs-%s' % self.doc_version + + if os.path.exists(self.build_html): + raise RuntimeError, '%s: already exists, please remove and try again' % self.build_html + os.chdir(self.build_base) + self.spawn('curl','-O', url) + self.spawn('tar', '-xjf', tarfile) + os.rename(dirname, 'html') + os.chdir(workdir) +## print "** Please unpack %s" % os.path.join(self.build_base, tarfile) +## print "** Unpack the files into %s" % self.build_html +## raise RuntimeError, "You need to unpack the docs manually" + + def buildDocsFromSource(self): + srcdir = '../../..' + docdir = os.path.join(srcdir, 'Doc') + htmldir = os.path.join(docdir, 'html') + spawn(('make','--directory', docdir, 'html'), 1, self.verbose, self.dry_run) + self.mkpath(self.build_html) + copy_tree(htmldir, self.build_html) + + def ensureHtml(self): + if not os.path.exists(self.build_html): + if self.download: + self.downloadDocs() + else: + self.buildDocsFromSource() + + def hackIndex(self): + ind_html = 'index.html' + #print 'self.build_dest =', self.build_dest + hackedIndex = file(os.path.join(self.build_dest, ind_html),'w') + origIndex = file(os.path.join(self.build_html,ind_html)) + r = re.compile('', re.DOTALL) + hackedIndex.write(r.sub('',origIndex.read())) + + def hackFile(self,d,f): + origPath = os.path.join(d,f) + assert(origPath[:len(self.build_html)] == self.build_html) + outPath = os.path.join(self.build_dest, d[len(self.build_html)+1:], f) + (name, ext) = os.path.splitext(f) + if os.path.isdir(origPath): + self.mkpath(outPath) + elif ext == '.html': + if self.verbose: print 'hacking %s to %s' % (origPath,outPath) + hackedFile = file(outPath, 'w') + origFile = file(origPath,'r') + hackedFile.write(self.r.sub('
    ', origFile.read())) + else: + copy_file(origPath, outPath) + + def hackHtml(self): + self.r = re.compile('
    ') + os.path.walk(self.build_html, self.visit, None) + + def visit(self, dummy, dirname, filenames): + for f in filenames: + self.hackFile(dirname, f) + + def makeHelpIndex(self): + app = '/Developer/Applications/Apple Help Indexing Tool.app' + self.spawn('open', '-a', app , self.build_dest) + print "Please wait until Apple Help Indexing Tool finishes before installing" + + def makeHelpIndex(self): + app = HelpIndexingTool.HelpIndexingTool(start=1) + app.open(Carbon.File.FSSpec(self.build_dest)) + sys.stderr.write("Waiting for Help Indexing Tool to start...") + while 1: + # This is bad design in the suite generation code! + idle = app._get(HelpIndexingTool.Help_Indexing_Tool_Suite._Prop_idleStatus()) + time.sleep(10) + if not idle: break + sys.stderr.write(".") + sys.stderr.write("\n") + sys.stderr.write("Waiting for Help Indexing Tool to finish...") + while 1: + # This is bad design in the suite generation code! + idle = app._get(HelpIndexingTool.Help_Indexing_Tool_Suite._Prop_idleStatus()) + time.sleep(10) + if idle: break + sys.stderr.write(".") + sys.stderr.write("\n") + + + def run(self): + self.ensure_finalized() + self.mkpath(self.build_base) + self.ensureHtml() + if not os.path.isdir(self.build_html): + raise RuntimeError, \ + "Can't find source folder for documentation." + self.mkpath(self.build_dest) + if dep_util.newer(os.path.join(self.build_html,'index.html'), os.path.join(self.build_dest,'index.html')): + self.mkpath(self.build_dest) + self.hackHtml() + self.hackIndex() + self.makeHelpIndex() + +class AHVDocInstall(Command): + description = "install Apple Help Viewer html files" + user_options = [('install-doc=', 'd', + 'directory to install HTML tree'), + ('root=', None, + "install everything relative to this alternate root directory"), + ] + + def initialize_options(self): + self.build_dest = None + self.install_doc = None + self.prefix = None + self.root = None + + def finalize_options(self): + self.set_undefined_options('install', + ('prefix', 'prefix'), + ('root', 'root')) +# import pdb ; pdb.set_trace() + build_cmd = self.get_finalized_command('build') + if self.build_dest == None: + build_cmd = self.get_finalized_command('build') + self.build_dest = build_cmd.build_dest + if self.install_doc == None: + self.install_doc = os.path.join(self.prefix, DESTDIR) + print 'INSTALL', self.build_dest, '->', self.install_doc + + def run(self): + self.finalize_options() + self.ensure_finalized() + print "Running Installer" + instloc = self.install_doc + if self.root: + instloc = change_root(self.root, instloc) + self.mkpath(instloc) + copy_tree(self.build_dest, instloc) + print "Installation complete" + +def mungeVersion(infile, outfile): + i = file(infile,'r') + o = file(outfile,'w') + o.write(re.sub('\$\(VERSION\)',sysconfig.get_config_var('VERSION'),i.read())) + i.close() + o.close() + +def main(): + # turn off warnings when deprecated modules are imported +## import warnings +## warnings.filterwarnings("ignore",category=DeprecationWarning) + setup(name = 'Documentation', + version = '%d.%d' % sys.version_info[:2], + cmdclass = {'install_data':AHVDocInstall, 'build':DocBuild}, + data_files = ['dummy'], + ) + +if __name__ == '__main__': + main() diff --git a/Mac/Tools/fixapplepython23.py b/Mac/Tools/fixapplepython23.py new file mode 100644 index 0000000..ef352ce --- /dev/null +++ b/Mac/Tools/fixapplepython23.py @@ -0,0 +1,119 @@ +#!/usr/bin/python +"""fixapplepython23 - Fix Apple-installed Python 2.3 (on Mac OS X 10.3) + +Python 2.3 (and 2.3.X for X<5) have the problem that building an extension +for a framework installation may accidentally pick up the framework +of a newer Python, in stead of the one that was used to build the extension. + +This script modifies the Makefile (in .../lib/python2.3/config) to use +the newer method of linking extensions with "-undefined dynamic_lookup" +which fixes this problem. + +The script will first check all prerequisites, and return a zero exit +status also when nothing needs to be fixed. +""" +import sys +import os +import gestalt + +MAKEFILE='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/Makefile' +CHANGES=(( + 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n', + 'LDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n' + ),( + 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -framework $(PYTHONFRAMEWORK)\n', + 'BLDSHARED=\t$(CC) $(LDFLAGS) -bundle -undefined dynamic_lookup\n' + ),( + 'CC=\t\tgcc\n', + 'CC=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc\n' + ),( + 'CXX=\t\tc++\n', + 'CXX=\t\t/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++\n' +)) + +GCC_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-gcc' +GXX_SCRIPT='/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config/PantherPythonFix/run-g++' +SCRIPT="""#!/bin/sh +export MACOSX_DEPLOYMENT_TARGET=10.3 +exec %s "${@}" +""" + +def findline(lines, start): + """return line starting with given string or -1""" + for i in range(len(lines)): + if lines[i][:len(start)] == start: + return i + return -1 + +def fix(makefile, do_apply): + """Fix the Makefile, if required.""" + fixed = False + lines = open(makefile).readlines() + + for old, new in CHANGES: + i = findline(lines, new) + if i >= 0: + # Already fixed + continue + i = findline(lines, old) + if i < 0: + print 'fixapplepython23: Python installation not fixed (appears broken)' + print 'fixapplepython23: missing line:', old + return 2 + lines[i] = new + fixed = True + + if fixed: + if do_apply: + print 'fixapplepython23: Fix to Apple-installed Python 2.3 applied' + os.rename(makefile, makefile + '~') + open(makefile, 'w').writelines(lines) + return 0 + else: + print 'fixapplepython23: Fix to Apple-installed Python 2.3 should be applied' + return 1 + else: + print 'fixapplepython23: No fix needed, appears to have been applied before' + return 0 + +def makescript(filename, compiler): + """Create a wrapper script for a compiler""" + dirname = os.path.split(filename)[0] + if not os.access(dirname, os.X_OK): + os.mkdir(dirname, 0755) + fp = open(filename, 'w') + fp.write(SCRIPT % compiler) + fp.close() + os.chmod(filename, 0755) + print 'fixapplepython23: Created', filename + +def main(): + # Check for -n option + if len(sys.argv) > 1 and sys.argv[1] == '-n': + do_apply = False + else: + do_apply = True + # First check OS version + if gestalt.gestalt('sysv') < 0x1030: + print 'fixapplepython23: no fix needed on MacOSX < 10.3' + sys.exit(0) + # Test that a framework Python is indeed installed + if not os.path.exists(MAKEFILE): + print 'fixapplepython23: Python framework does not appear to be installed (?), nothing fixed' + sys.exit(0) + # Check that we can actually write the file + if do_apply and not os.access(MAKEFILE, os.W_OK): + print 'fixapplepython23: No write permission, please run with "sudo"' + sys.exit(2) + # Create the shell scripts + if do_apply: + if not os.access(GCC_SCRIPT, os.X_OK): + makescript(GCC_SCRIPT, "gcc") + if not os.access(GXX_SCRIPT, os.X_OK): + makescript(GXX_SCRIPT, "g++") + # Finally fix the makefile + rv = fix(MAKEFILE, do_apply) + sys.exit(rv) + +if __name__ == '__main__': + main() diff --git a/Mac/Tools/pythonw.c b/Mac/Tools/pythonw.c new file mode 100644 index 0000000..e70a76f --- /dev/null +++ b/Mac/Tools/pythonw.c @@ -0,0 +1,17 @@ +/* + * This wrapper program executes a python executable hidden inside an + * application bundle inside the Python framework. This is needed to run + * GUI code: some GUI API's don't work unless the program is inside an + * application bundle. + */ +#include +#include + +static char Python[] = PYTHONWEXECUTABLE; + +int main(int argc, char **argv) { + argv[0] = Python; + execv(Python, argv); + err(1, "execv: %s", Python); + /* NOTREACHED */ +} diff --git a/Mac/scripts/BuildApplet.py b/Mac/scripts/BuildApplet.py index 756218f..e71ebc1 100644 --- a/Mac/scripts/BuildApplet.py +++ b/Mac/scripts/BuildApplet.py @@ -16,6 +16,18 @@ import EasyDialogs import buildtools import getopt +if not sys.executable.startswith(sys.exec_prefix): + # Oh, the joys of using a python script to bootstrap applicatin bundles + # sys.executable points inside the current application bundle. Because this + # path contains blanks (two of them actually) this path isn't usable on + # #! lines. Reset sys.executable to point to the embedded python interpreter + sys.executable = os.path.join(sys.prefix, + 'Resources/Python.app/Contents/MacOS/Python') + + # Just in case we're not in a framework: + if not os.path.exists(sys.executable): + sys.executable = os.path.join(sys.exec_prefix, 'bin/python') + def main(): try: buildapplet() diff --git a/Makefile.pre.in b/Makefile.pre.in index a33034d..f822838 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -370,12 +370,12 @@ libpython$(VERSION).so: $(LIBRARY_OBJS) fi libpython$(VERSION).sl: $(LIBRARY_OBJS) - $(LDSHARED) -o $@ $(LIBRARY_OBJS) $(LIBC) $(LIBM) + $(LDSHARED) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) # This rule is here for OPENSTEP/Rhapsody/MacOSX. It builds a temporary # minimal framework (not including the Lib directory and such) in the current # directory. -RESSRCDIR=$(srcdir)/Mac/OSXResources/framework +RESSRCDIR=$(srcdir)/Mac/Resources/framework $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \ $(LIBRARY) \ $(RESSRCDIR)/Info.plist \ @@ -619,8 +619,8 @@ memtest: all platform install: @FRAMEWORKINSTALLFIRST@ altinstall bininstall maninstall @FRAMEWORKINSTALLLAST@ # Install almost everything without disturbing previous versions -altinstall: altbininstall libinstall inclinstall libainstall \ - sharedinstall oldsharedinstall +altinstall: @FRAMEWORKALTINSTALLFIRST@ altbininstall libinstall inclinstall libainstall \ + sharedinstall oldsharedinstall @FRAMEWORKALTINSTALLLAST@ # Install shared libraries enabled by Setup DESTDIRS= $(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED) @@ -899,7 +899,7 @@ sharedinstall: # Here are a couple of targets for MacOSX again, to install a full # framework-based Python. frameworkinstall installs everything, the # subtargets install specific parts. Much of the actual work is offloaded to -# the Makefile in Mac/OSX +# the Makefile in Mac # # # This target is here for backward compatiblity, previous versions of Python @@ -940,22 +940,23 @@ frameworkinstallstructure: $(LDLIBRARY) # This installs Mac/Lib into the framework frameworkinstallmaclib: - cd Mac/OSX && $(MAKE) installmacsubtree DESTDIR="$(DESTDIR)" + cd Mac && $(MAKE) installmacsubtree DESTDIR="$(DESTDIR)" # This installs the IDE, the Launcher and other apps into /Applications frameworkinstallapps: - cd Mac/OSX && $(MAKE) installapps DESTDIR="$(DESTDIR)" + cd Mac && $(MAKE) installapps DESTDIR="$(DESTDIR)" # This install the unix python and pythonw tools in /usr/local/bin frameworkinstallunixtools: - cd Mac/OSX && $(MAKE) installunixtools DESTDIR="$(DESTDIR)" + cd Mac && $(MAKE) installunixtools DESTDIR="$(DESTDIR)" + +frameworkaltinstallunixtools: + cd Mac && $(MAKE) altinstallunixtools DESTDIR="$(DESTDIR)" # This installs the Demos and Tools into the applications directory. # It is not part of a normal frameworkinstall frameworkinstallextras: - $(MAKE) -f Mac/OSX/Makefile installextras \ - $(RUNSHARED) BUILDPYTHON=./$(BUILDPYTHON) DIRMODE=$(DIRMODE) FILEMODE=$(FILEMODE) \ - srcdir=$(srcdir) builddir=. DESTDIR=$(DESTDIR) + cd Mac && Make installextras DESTDIR="$(DESTDIR)" # This installs a few of the useful scripts in Tools/scripts scriptsinstall: @@ -1083,6 +1084,7 @@ Python/thread.o: @THREADHEADERS@ .PHONY: maninstall libinstall inclinstall libainstall sharedinstall .PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure .PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools -.PHONY: recheck autoconf clean clobber distclean smelly funny +.PHONY: frameworkaltinstallunixtools recheck autoconf clean clobber distclean +.PHONY: smelly funny # IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/Misc/SpecialBuilds.txt b/Misc/SpecialBuilds.txt index e0b3315..952ca42 100644 --- a/Misc/SpecialBuilds.txt +++ b/Misc/SpecialBuilds.txt @@ -96,16 +96,16 @@ dynamically allocated memory blocks. The special bit patterns are: Strings of these bytes are unlikely to be valid addresses, floats, or 7-bit ASCII strings. -8 bytes are added at each end of each block of N bytes requested. The -memory layout is like so, where p represents the address returned by a -malloc-like or realloc-like function (p[i:j] means the slice of bytes -from *(p+i) inclusive up to *(p+j) exclusive; note that the treatment -of negative indices differs from a Python slice): - -p[-8:-4] - Number of bytes originally asked for. 4-byte unsigned integer, - big-endian (easier to read in a memory dump). -p[-4:0] +Let S = sizeof(size_t). 2*S bytes are added at each end of each block of N +bytes requested. The memory layout is like so, where p represents the +address returned by a malloc-like or realloc-like function (p[i:j] means +the slice of bytes from *(p+i) inclusive up to *(p+j) exclusive; note that +the treatment of negative indices differs from a Python slice): + +p[-2*S:-S] + Number of bytes originally asked for. This is a size_t, big-endian + (easier to read in a memory dump). +p[-S:0] Copies of FORBIDDENBYTE. Used to catch under- writes and reads. p[0:N] The requested memory, filled with copies of CLEANBYTE, used to catch @@ -116,12 +116,12 @@ p[0:N] DEADBYTE, to catch reference to freed memory. When a realloc- like function is called requesting a smaller memory block, the excess old bytes are also filled with DEADBYTE. -p[N:N+4] +p[N:N+S] Copies of FORBIDDENBYTE. Used to catch over- writes and reads. -p[N+4:N+8] +p[N+S:N+2*S] A serial number, incremented by 1 on each call to a malloc-like or realloc-like function. - 4-byte unsigned integer, big-endian. + Big-endian size_t. If "bad memory" is detected later, the serial number gives an excellent way to set a breakpoint on the next run, to capture the instant at which this block was passed out. The static function @@ -145,6 +145,10 @@ envar PYTHONMALLOCSTATS If this envar exists, a report of pymalloc summary statistics is printed to stderr whenever a new arena is allocated, and also by Py_Finalize(). + +Changed in 2.5: The number of extra bytes allocated is 4*sizeof(size_t). +Before it was 16 on all boxes, reflecting that Python couldn't make use of +allocations >= 2**32 bytes even on 64-bit boxes before 2.5. --------------------------------------------------------------------------- Py_DEBUG introduced in 1.5 named DEBUG before 1.5 @@ -251,7 +255,7 @@ is not defined by the architecture specification, so you'll need to find the manual for your specific processor. For the 750CX, 750CXe and 750FX (all sold as the G3) we find: - The time base counter is clocked at a frequency that is + The time base counter is clocked at a frequency that is one-fourth that of the bus clock. This build is enabled by the --with-tsc flag to configure. diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c index e18e072..a640d52 100644 --- a/Modules/_bsddb.c +++ b/Modules/_bsddb.c @@ -61,13 +61,14 @@ * * http://www.python.org/peps/pep-0291.html * - * This module contains 5 types: + * This module contains 6 types: * * DB (Database) * DBCursor (Database Cursor) * DBEnv (database environment) * DBTxn (An explicit database transaction) * DBLock (A lock handle) + * DBSequence (Sequence) * */ @@ -97,7 +98,7 @@ #error "eek! DBVER can't handle minor versions > 9" #endif -#define PY_BSDDB_VERSION "4.4.2" +#define PY_BSDDB_VERSION "4.4.4" static char *rcs_id = "$Id$"; @@ -285,7 +286,17 @@ typedef struct { #endif } DBLockObject; - +#if (DBVER >= 43) +typedef struct { + PyObject_HEAD + DB_SEQUENCE* sequence; + DBObject* mydb; +#ifdef HAVE_WEAKREF + PyObject *in_weakreflist; /* List of weak references */ +#endif +} DBSequenceObject; +static PyTypeObject DBSequence_Type; +#endif static PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, DBLock_Type; @@ -294,6 +305,9 @@ static PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, DBLock_Type; #define DBEnvObject_Check(v) ((v)->ob_type == &DBEnv_Type) #define DBTxnObject_Check(v) ((v)->ob_type == &DBTxn_Type) #define DBLockObject_Check(v) ((v)->ob_type == &DBLock_Type) +#if (DBVER >= 43) +#define DBSequenceObject_Check(v) ((v)->ob_type == &DBSequence_Type) +#endif /* --------------------------------------------------------------------- */ @@ -324,6 +338,10 @@ static PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, DBLock_Type; #define CHECK_CURSOR_NOT_CLOSED(curs) \ _CHECK_OBJECT_NOT_CLOSED(curs->dbc, DBCursorClosedError, DBCursor) +#if (DBVER >= 43) +#define CHECK_SEQUENCE_NOT_CLOSED(curs) \ + _CHECK_OBJECT_NOT_CLOSED(curs->sequence, DBError, DBSequence) +#endif #define CHECK_DBFLAG(mydb, flag) (((mydb)->flags & (flag)) || \ (((mydb)->myenvobj != NULL) && ((mydb)->myenvobj->flags & (flag)))) @@ -724,7 +742,17 @@ static void _addIntToDict(PyObject* dict, char *name, int value) Py_XDECREF(v); } +#if (DBVER >= 43) +/* add an db_seq_t to a dictionary using the given name as a key */ +static void _addDb_seq_tToDict(PyObject* dict, char *name, db_seq_t value) +{ + PyObject* v = PyLong_FromLongLong(value); + if (!v || PyDict_SetItemString(dict, name, v)) + PyErr_Clear(); + Py_XDECREF(v); +} +#endif @@ -777,7 +805,7 @@ newDBObject(DBEnvObject* arg, int flags) MYDB_END_ALLOW_THREADS; /* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs * list so that a DBEnv can refuse to close without aborting any open - * open DBTxns and closing any open DBs first. */ + * DBTxns and closing any open DBs first. */ if (makeDBError(err)) { if (self->myenvobj) { Py_DECREF(self->myenvobj); @@ -1029,6 +1057,48 @@ DBLock_dealloc(DBLockObject* self) } +#if (DBVER >= 43) +static DBSequenceObject* +newDBSequenceObject(DBObject* mydb, int flags) +{ + int err; + DBSequenceObject* self = PyObject_New(DBSequenceObject, &DBSequence_Type); + if (self == NULL) + return NULL; + Py_INCREF(mydb); + self->mydb = mydb; +#ifdef HAVE_WEAKREF + self->in_weakreflist = NULL; +#endif + + + MYDB_BEGIN_ALLOW_THREADS; + err = db_sequence_create(&self->sequence, self->mydb->db, flags); + MYDB_END_ALLOW_THREADS; + if (makeDBError(err)) { + Py_DECREF(self->mydb); + PyObject_Del(self); + self = NULL; + } + + return self; +} + + +static void +DBSequence_dealloc(DBSequenceObject* self) +{ +#ifdef HAVE_WEAKREF + if (self->in_weakreflist != NULL) { + PyObject_ClearWeakRefs((PyObject *) self); + } +#endif + + Py_DECREF(self->mydb); + PyObject_Del(self); +} +#endif + /* --------------------------------------------------------------------- */ /* DB methods */ @@ -2614,7 +2684,7 @@ DB_set_encrypt(DBObject* self, PyObject* args, PyObject* kwargs) Py_ssize_t DB_length(DBObject* self) { int err; - long size = 0; + Py_ssize_t size = 0; int flags = 0; void* sp; @@ -2627,10 +2697,11 @@ Py_ssize_t DB_length(DBObject* self) if (self->haveStat) { /* Has the stat function been called recently? If so, we can use the cached value. */ - flags = DB_CACHED_COUNTS; + flags = DB_FAST_STAT; } MYDB_BEGIN_ALLOW_THREADS; +redo_stat_for_length: #if (DBVER >= 43) err = self->db->stat(self->db, /*txnid*/ NULL, &sp, flags); #elif (DBVER >= 33) @@ -2638,6 +2709,20 @@ Py_ssize_t DB_length(DBObject* self) #else err = self->db->stat(self->db, &sp, NULL, flags); #endif + + /* All the stat structures have matching fields upto the ndata field, + so we can use any of them for the type cast */ + size = ((DB_BTREE_STAT*)sp)->bt_ndata; + + /* A size of 0 could mean that BerkeleyDB no longer had the stat values cached. + * redo a full stat to make sure. + * Fixes SF python bug 1493322, pybsddb bug 1184012 + */ + if (size == 0 && (flags & DB_FAST_STAT)) { + flags = 0; + goto redo_stat_for_length; + } + MYDB_END_ALLOW_THREADS; if (err) @@ -2645,9 +2730,6 @@ Py_ssize_t DB_length(DBObject* self) self->haveStat = 1; - /* All the stat structures have matching fields upto the ndata field, - so we can use any of them for the type cast */ - size = ((DB_BTREE_STAT*)sp)->bt_ndata; free(sp); return size; } @@ -3124,8 +3206,8 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs) int dlen = -1; int doff = -1; DBT key, pkey, data; - static char* kwnames[] = { "key","data", "flags", "dlen", "doff", - NULL }; + static char* kwnames_keyOnly[] = { "key", "flags", "dlen", "doff", NULL }; + static char* kwnames[] = { "key", "data", "flags", "dlen", "doff", NULL }; CLEAR_DBT(key); CLEAR_DBT(data); @@ -3134,7 +3216,7 @@ DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs) { PyErr_Clear(); if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii:pget", - &kwnames[1], + kwnames_keyOnly, &keyobj, &flags, &dlen, &doff)) { PyErr_Clear(); @@ -4294,6 +4376,93 @@ DBEnv_lock_put(DBEnvObject* self, PyObject* args) RETURN_NONE(); } +#if (DBVER >= 44) +static PyObject* +DBEnv_lsn_reset(DBEnvObject* self, PyObject* args, PyObject* kwargs) +{ + int err; + char *file; + u_int32_t flags = 0; + static char* kwnames[] = { "file", "flags", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "z|i:lsn_reset", kwnames, + &file, &flags)) + return NULL; + CHECK_ENV_NOT_CLOSED(self); + + MYDB_BEGIN_ALLOW_THREADS; + err = self->db_env->lsn_reset(self->db_env, file, flags); + MYDB_END_ALLOW_THREADS; + RETURN_IF_ERR(); + RETURN_NONE(); +} +#endif /* DBVER >= 4.4 */ + +#if (DBVER >= 40) +static PyObject* +DBEnv_log_stat(DBEnvObject* self, PyObject* args) +{ + int err; + DB_LOG_STAT* statp = NULL; + PyObject* d = NULL; + u_int32_t flags = 0; + + if (!PyArg_ParseTuple(args, "|i:log_stat", &flags)) + return NULL; + CHECK_ENV_NOT_CLOSED(self); + + MYDB_BEGIN_ALLOW_THREADS; + err = self->db_env->log_stat(self->db_env, &statp, flags); + MYDB_END_ALLOW_THREADS; + RETURN_IF_ERR(); + + /* Turn the stat structure into a dictionary */ + d = PyDict_New(); + if (d == NULL) { + if (statp) + free(statp); + return NULL; + } + +#define MAKE_ENTRY(name) _addIntToDict(d, #name, statp->st_##name) + + MAKE_ENTRY(magic); + MAKE_ENTRY(version); + MAKE_ENTRY(mode); + MAKE_ENTRY(lg_bsize); +#if (DBVER >= 44) + MAKE_ENTRY(lg_size); + MAKE_ENTRY(record); +#endif +#if (DBVER <= 40) + MAKE_ENTRY(lg_max); +#endif + MAKE_ENTRY(w_mbytes); + MAKE_ENTRY(w_bytes); + MAKE_ENTRY(wc_mbytes); + MAKE_ENTRY(wc_bytes); + MAKE_ENTRY(wcount); + MAKE_ENTRY(wcount_fill); +#if (DBVER >= 44) + MAKE_ENTRY(rcount); +#endif + MAKE_ENTRY(scount); + MAKE_ENTRY(cur_file); + MAKE_ENTRY(cur_offset); + MAKE_ENTRY(disk_file); + MAKE_ENTRY(disk_offset); + MAKE_ENTRY(maxcommitperflush); + MAKE_ENTRY(mincommitperflush); + MAKE_ENTRY(regsize); + MAKE_ENTRY(region_wait); + MAKE_ENTRY(region_nowait); + +#undef MAKE_ENTRY + free(statp); + return d; +} /* DBEnv_log_stat */ +#endif /* DBVER >= 4.0 for log_stat method */ + static PyObject* DBEnv_lock_stat(DBEnvObject* self, PyObject* args) @@ -4371,7 +4540,7 @@ DBEnv_log_archive(DBEnvObject* self, PyObject* args) { int flags=0; int err; - char **log_list_start, **log_list; + char **log_list = NULL; PyObject* list; PyObject* item = NULL; @@ -4391,10 +4560,14 @@ DBEnv_log_archive(DBEnvObject* self, PyObject* args) RETURN_IF_ERR(); list = PyList_New(0); - if (list == NULL) + if (list == NULL) { + if (log_list) + free(log_list); return NULL; + } if (log_list) { + char **log_list_start; for (log_list_start = log_list; *log_list != NULL; ++log_list) { item = PyString_FromString (*log_list); if (item == NULL) { @@ -4624,6 +4797,294 @@ DBTxn_id(DBTxnObject* self, PyObject* args) return PyInt_FromLong(id); } +#if (DBVER >= 43) +/* --------------------------------------------------------------------- */ +/* DBSequence methods */ + + +static PyObject* +DBSequence_close(DBSequenceObject* self, PyObject* args) +{ + int err, flags=0; + if (!PyArg_ParseTuple(args,"|i:close", &flags)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->close(self->sequence, flags); + self->sequence = NULL; + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + + RETURN_NONE(); +} + +static PyObject* +DBSequence_get(DBSequenceObject* self, PyObject* args, PyObject* kwargs) +{ + int err, flags = 0; + int delta = 1; + db_seq_t value; + PyObject *txnobj = NULL; + DB_TXN *txn = NULL; + static char* kwnames[] = {"delta", "txn", "flags", NULL }; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iOi:get", kwnames, &delta, &txnobj, &flags)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + if (!checkTxnObj(txnobj, &txn)) + return NULL; + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->get(self->sequence, txn, delta, &value, flags); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + return PyLong_FromLongLong(value); + +} + +static PyObject* +DBSequence_get_dbp(DBSequenceObject* self, PyObject* args) +{ + if (!PyArg_ParseTuple(args,":get_dbp")) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + Py_INCREF(self->mydb); + return (PyObject* )self->mydb; +} + +static PyObject* +DBSequence_get_key(DBSequenceObject* self, PyObject* args) +{ + int err; + DBT key; + CHECK_SEQUENCE_NOT_CLOSED(self) + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->get_key(self->sequence, &key); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + + return PyString_FromStringAndSize(key.data, key.size); +} + +static PyObject* +DBSequence_init_value(DBSequenceObject* self, PyObject* args) +{ + int err; + db_seq_t value; + if (!PyArg_ParseTuple(args,"L:init_value", &value)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->initial_value(self->sequence, value); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + + RETURN_NONE(); +} + +static PyObject* +DBSequence_open(DBSequenceObject* self, PyObject* args, PyObject* kwargs) +{ + int err, flags = 0; + PyObject* keyobj; + PyObject *txnobj = NULL; + DB_TXN *txn = NULL; + DBT key; + + static char* kwnames[] = {"key", "txn", "flags", NULL }; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:open", kwnames, &keyobj, &txnobj, &flags)) + return NULL; + + if (!checkTxnObj(txnobj, &txn)) + return NULL; + + if (!make_key_dbt(self->mydb, keyobj, &key, NULL)) + return NULL; + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->open(self->sequence, txn, &key, flags); + MYDB_END_ALLOW_THREADS + + CLEAR_DBT(key); + RETURN_IF_ERR(); + + RETURN_NONE(); +} + +static PyObject* +DBSequence_remove(DBSequenceObject* self, PyObject* args, PyObject* kwargs) +{ + int err, flags = 0; + PyObject *txnobj = NULL; + DB_TXN *txn = NULL; + + static char* kwnames[] = {"txn", "flags", NULL }; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oi:remove", kwnames, &txnobj, &flags)) + return NULL; + + if (!checkTxnObj(txnobj, &txn)) + return NULL; + + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->remove(self->sequence, txn, flags); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + RETURN_NONE(); +} + +static PyObject* +DBSequence_set_cachesize(DBSequenceObject* self, PyObject* args) +{ + int err, size; + if (!PyArg_ParseTuple(args,"i:set_cachesize", &size)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->set_cachesize(self->sequence, size); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + RETURN_NONE(); +} + +static PyObject* +DBSequence_get_cachesize(DBSequenceObject* self, PyObject* args) +{ + int err, size; + if (!PyArg_ParseTuple(args,":get_cachesize")) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->get_cachesize(self->sequence, &size); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + return PyInt_FromLong(size); +} + +static PyObject* +DBSequence_set_flags(DBSequenceObject* self, PyObject* args) +{ + int err, flags = 0; + if (!PyArg_ParseTuple(args,"i:set_flags", &flags)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->set_flags(self->sequence, flags); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + RETURN_NONE(); + +} + +static PyObject* +DBSequence_get_flags(DBSequenceObject* self, PyObject* args) +{ + unsigned int flags; + int err; + if (!PyArg_ParseTuple(args,":get_flags")) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->get_flags(self->sequence, &flags); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + return PyInt_FromLong((int)flags); +} + +static PyObject* +DBSequence_set_range(DBSequenceObject* self, PyObject* args) +{ + int err; + db_seq_t min, max; + if (!PyArg_ParseTuple(args,"(LL):set_range", &min, &max)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->set_range(self->sequence, min, max); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + RETURN_NONE(); +} + +static PyObject* +DBSequence_get_range(DBSequenceObject* self, PyObject* args) +{ + int err; + db_seq_t min, max; + if (!PyArg_ParseTuple(args,":get_range")) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self) + + MYDB_BEGIN_ALLOW_THREADS + err = self->sequence->get_range(self->sequence, &min, &max); + MYDB_END_ALLOW_THREADS + + RETURN_IF_ERR(); + return Py_BuildValue("(LL)", min, max); +} + +static PyObject* +DBSequence_stat(DBSequenceObject* self, PyObject* args, PyObject* kwargs) +{ + int err, flags = 0; + DB_SEQUENCE_STAT* sp = NULL; + PyObject* dict_stat; + static char* kwnames[] = {"flags", NULL }; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat", kwnames, &flags)) + return NULL; + CHECK_SEQUENCE_NOT_CLOSED(self); + + MYDB_BEGIN_ALLOW_THREADS; + err = self->sequence->stat(self->sequence, &sp, flags); + MYDB_END_ALLOW_THREADS; + RETURN_IF_ERR(); + + if ((dict_stat = PyDict_New()) == NULL) { + free(sp); + return NULL; + } + + +#define MAKE_INT_ENTRY(name) _addIntToDict(dict_stat, #name, sp->st_##name) +#define MAKE_LONG_LONG_ENTRY(name) _addDb_seq_tToDict(dict_stat, #name, sp->st_##name) + + MAKE_INT_ENTRY(wait); + MAKE_INT_ENTRY(nowait); + MAKE_LONG_LONG_ENTRY(current); + MAKE_LONG_LONG_ENTRY(value); + MAKE_LONG_LONG_ENTRY(last_value); + MAKE_LONG_LONG_ENTRY(min); + MAKE_LONG_LONG_ENTRY(max); + MAKE_INT_ENTRY(cache_size); + MAKE_INT_ENTRY(flags); + +#undef MAKE_INT_ENTRY +#undef MAKE_LONG_LONG_ENTRY + + free(sp); + return dict_stat; +} +#endif + + /* --------------------------------------------------------------------- */ /* Method definition tables and type objects */ @@ -4777,6 +5238,12 @@ static PyMethodDef DBEnv_methods[] = { {"lock_put", (PyCFunction)DBEnv_lock_put, METH_VARARGS}, {"lock_stat", (PyCFunction)DBEnv_lock_stat, METH_VARARGS}, {"log_archive", (PyCFunction)DBEnv_log_archive, METH_VARARGS}, +#if (DBVER >= 40) + {"log_stat", (PyCFunction)DBEnv_log_stat, METH_VARARGS}, +#endif +#if (DBVER >= 44) + {"lsn_reset", (PyCFunction)DBEnv_lsn_reset, METH_VARARGS|METH_KEYWORDS}, +#endif {"set_get_returns_none",(PyCFunction)DBEnv_set_get_returns_none, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; @@ -4791,6 +5258,27 @@ static PyMethodDef DBTxn_methods[] = { }; +#if (DBVER >= 43) +static PyMethodDef DBSequence_methods[] = { + {"close", (PyCFunction)DBSequence_close, METH_VARARGS}, + {"get", (PyCFunction)DBSequence_get, METH_VARARGS|METH_KEYWORDS}, + {"get_dbp", (PyCFunction)DBSequence_get_dbp, METH_VARARGS}, + {"get_key", (PyCFunction)DBSequence_get_key, METH_VARARGS}, + {"init_value", (PyCFunction)DBSequence_init_value, METH_VARARGS}, + {"open", (PyCFunction)DBSequence_open, METH_VARARGS|METH_KEYWORDS}, + {"remove", (PyCFunction)DBSequence_remove, METH_VARARGS|METH_KEYWORDS}, + {"set_cachesize", (PyCFunction)DBSequence_set_cachesize, METH_VARARGS}, + {"get_cachesize", (PyCFunction)DBSequence_get_cachesize, METH_VARARGS}, + {"set_flags", (PyCFunction)DBSequence_set_flags, METH_VARARGS}, + {"get_flags", (PyCFunction)DBSequence_get_flags, METH_VARARGS}, + {"set_range", (PyCFunction)DBSequence_set_range, METH_VARARGS}, + {"get_range", (PyCFunction)DBSequence_get_range, METH_VARARGS}, + {"stat", (PyCFunction)DBSequence_stat, METH_VARARGS|METH_KEYWORDS}, + {NULL, NULL} /* sentinel */ +}; +#endif + + static PyObject* DB_getattr(DBObject* self, char *name) { @@ -4831,6 +5319,14 @@ DBLock_getattr(DBLockObject* self, char *name) return NULL; } +#if (DBVER >= 43) +static PyObject* +DBSequence_getattr(DBSequenceObject* self, char *name) +{ + return Py_FindMethod(DBSequence_methods, (PyObject* )self, name); +} +#endif + static PyTypeObject DB_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ @@ -4994,6 +5490,39 @@ static PyTypeObject DBLock_Type = { #endif }; +#if (DBVER >= 43) +static PyTypeObject DBSequence_Type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "DBSequence", /*tp_name*/ + sizeof(DBSequenceObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)DBSequence_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc)DBSequence_getattr,/*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ +#ifdef HAVE_WEAKREF + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + offsetof(DBSequenceObject, in_weakreflist), /* tp_weaklistoffset */ +#endif +}; +#endif /* --------------------------------------------------------------------- */ /* Module-level functions */ @@ -5027,6 +5556,25 @@ DBEnv_construct(PyObject* self, PyObject* args) return (PyObject* )newDBEnvObject(flags); } +#if (DBVER >= 43) +static PyObject* +DBSequence_construct(PyObject* self, PyObject* args, PyObject* kwargs) +{ + PyObject* dbobj = NULL; + int flags = 0; + static char* kwnames[] = { "db", "flags", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:DBSequence", kwnames, &dbobj, &flags)) + return NULL; + if (dbobj == Py_None) + dbobj = NULL; + else if (dbobj && !DBObject_Check(dbobj)) { + makeTypeError("DB", dbobj); + return NULL; + } + return (PyObject* )newDBSequenceObject((DBObject*)dbobj, flags); +} +#endif static char bsddb_version_doc[] = "Returns a tuple of major, minor, and patch release numbers of the\n\ @@ -5047,9 +5595,12 @@ bsddb_version(PyObject* self, PyObject* args) /* List of functions defined in the module */ static PyMethodDef bsddb_methods[] = { - {"DB", (PyCFunction)DB_construct, METH_VARARGS | METH_KEYWORDS }, - {"DBEnv", (PyCFunction)DBEnv_construct, METH_VARARGS}, - {"version", (PyCFunction)bsddb_version, METH_VARARGS, bsddb_version_doc}, + {"DB", (PyCFunction)DB_construct, METH_VARARGS | METH_KEYWORDS }, + {"DBEnv", (PyCFunction)DBEnv_construct, METH_VARARGS}, +#if (DBVER >= 43) + {"DBSequence", (PyCFunction)DBSequence_construct, METH_VARARGS | METH_KEYWORDS }, +#endif + {"version", (PyCFunction)bsddb_version, METH_VARARGS, bsddb_version_doc}, {NULL, NULL} /* sentinel */ }; @@ -5081,6 +5632,9 @@ DL_EXPORT(void) init_bsddb(void) DBEnv_Type.ob_type = &PyType_Type; DBTxn_Type.ob_type = &PyType_Type; DBLock_Type.ob_type = &PyType_Type; +#if (DBVER >= 43) + DBSequence_Type.ob_type = &PyType_Type; +#endif #if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE) @@ -5247,6 +5801,9 @@ DL_EXPORT(void) init_bsddb(void) ADD_INT(d, DB_ARCH_ABS); ADD_INT(d, DB_ARCH_DATA); ADD_INT(d, DB_ARCH_LOG); +#if (DBVER >= 42) + ADD_INT(d, DB_ARCH_REMOVE); +#endif ADD_INT(d, DB_BTREE); ADD_INT(d, DB_HASH); @@ -5368,6 +5925,9 @@ DL_EXPORT(void) init_bsddb(void) #if (DBVER >= 43) ADD_INT(d, DB_LOG_INMEMORY); ADD_INT(d, DB_BUFFER_SMALL); + ADD_INT(d, DB_SEQ_DEC); + ADD_INT(d, DB_SEQ_INC); + ADD_INT(d, DB_SEQ_WRAP); #endif #if (DBVER >= 41) diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index 080fa74..32fa82f 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -792,6 +792,15 @@ charmap_encode(PyObject *self, return v; } +static PyObject* +charmap_build(PyObject *self, PyObject *args) +{ + PyObject *map; + if (!PyArg_ParseTuple(args, "U:charmap_build", &map)) + return NULL; + return PyUnicode_BuildEncodingMap(map); +} + #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) static PyObject * @@ -897,6 +906,7 @@ static PyMethodDef _codecs_functions[] = { {"ascii_decode", ascii_decode, METH_VARARGS}, {"charmap_encode", charmap_encode, METH_VARARGS}, {"charmap_decode", charmap_decode, METH_VARARGS}, + {"charmap_build", charmap_build, METH_VARARGS}, {"readbuffer_encode", readbuffer_encode, METH_VARARGS}, {"charbuffer_encode", charbuffer_encode, METH_VARARGS}, #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 8c29c55..4baf3aa 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -199,45 +199,16 @@ if (x == NULL) _AddTraceback(what, __FILE__, __LINE__ - 1), PyErr_Print() result = PyObject_CallObject(callable, arglist); CHECK("'calling callback function'", result); - if ((restype != &ffi_type_void) - && result && result != Py_None) { /* XXX What is returned for Py_None ? */ - /* another big endian hack */ - union { - char c; - short s; - int i; - long l; - } r; + if ((restype != &ffi_type_void) && result && result != Py_None) { PyObject *keep; assert(setfunc); - switch (restype->size) { - case 1: - keep = setfunc(&r, result, 0); - CHECK("'converting callback result'", keep); - *(ffi_arg *)mem = r.c; - break; - case SIZEOF_SHORT: - keep = setfunc(&r, result, 0); - CHECK("'converting callback result'", keep); - *(ffi_arg *)mem = r.s; - break; - case SIZEOF_INT: - keep = setfunc(&r, result, 0); - CHECK("'converting callback result'", keep); - *(ffi_arg *)mem = r.i; - break; -#if (SIZEOF_LONG != SIZEOF_INT) - case SIZEOF_LONG: - keep = setfunc(&r, result, 0); - CHECK("'converting callback result'", keep); - *(ffi_arg *)mem = r.l; - break; +#ifdef WORDS_BIGENDIAN + /* See the corresponding code in callproc.c, around line 961 */ + if (restype->type != FFI_TYPE_FLOAT && restype->size < sizeof(ffi_arg)) + mem = (char *)mem + sizeof(ffi_arg) - restype->size; #endif - default: - keep = setfunc(mem, result, 0); - CHECK("'converting callback result'", keep); - break; - } + keep = setfunc(mem, result, 0); + CHECK("'converting callback result'", keep); /* keep is an object we have to keep alive so that the result stays valid. If there is no such object, the setfunc will have returned Py_None. diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 8163f49..8108498 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -964,7 +964,14 @@ PyObject *_CallProc(PPROC pProc, address cannot simply be used as result pointer, instead we must adjust the pointer value: */ - if (rtype->size < sizeof(ffi_arg)) + /* + XXX I should find out and clarify why this is needed at all, + especially why adjusting for ffi_type_float must be avoided on + 64-bit platforms. + */ + if (rtype->type != FFI_TYPE_FLOAT + && rtype->type != FFI_TYPE_STRUCT + && rtype->size < sizeof(ffi_arg)) resbuf = (char *)resbuf + sizeof(ffi_arg) - rtype->size; #endif diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 7bef412..ae0290f 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -1,5 +1,4 @@ #include "Python.h" -#include "structmember.h" #include #ifdef MS_WIN32 @@ -208,14 +207,30 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type) self->index, self->size, src->b_ptr + self->offset); } -static PyMemberDef CField_members[] = { - { "offset", T_UINT, - offsetof(CFieldObject, offset), READONLY, - "offset in bytes of this field"}, - { "size", T_UINT, - offsetof(CFieldObject, size), READONLY, - "size in bytes of this field"}, - { NULL }, +static PyObject * +CField_get_offset(PyObject *self, void *data) +{ +#if (PY_VERSION_HEX < 0x02050000) + return PyInt_FromLong(((CFieldObject *)self)->offset); +#else + return PyInt_FromSsize_t(((CFieldObject *)self)->offset); +#endif +} + +static PyObject * +CField_get_size(PyObject *self, void *data) +{ +#if (PY_VERSION_HEX < 0x02050000) + return PyInt_FromLong(((CFieldObject *)self)->size); +#else + return PyInt_FromSsize_t(((CFieldObject *)self)->size); +#endif +} + +static PyGetSetDef CField_getset[] = { + { "offset", CField_get_offset, NULL, "offset in bytes of this field" }, + { "size", CField_get_size, NULL, "size in bytes of this field" }, + { NULL, NULL, NULL, NULL }, }; static int @@ -298,8 +313,8 @@ PyTypeObject CField_Type = { 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ - CField_members, /* tp_members */ - 0, /* tp_getset */ + 0, /* tp_members */ + CField_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ (descrgetfunc)CField_get, /* tp_descr_get */ diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 871aa18..dda5042 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1476,7 +1476,7 @@ treebuilder_new(void) } static PyObject* -treebuilder(PyObject* _self, PyObject* args) +treebuilder(PyObject* self_, PyObject* args) { if (!PyArg_ParseTuple(args, ":TreeBuilder")) return NULL; @@ -2201,7 +2201,7 @@ expat_unknown_encoding_handler(XMLParserObject *self, const XML_Char *name, /* constructor and destructor */ static PyObject* -xmlparser(PyObject* _self, PyObject* args, PyObject* kw) +xmlparser(PyObject* self_, PyObject* args, PyObject* kw) { XMLParserObject* self; /* FIXME: does this need to be static? */ diff --git a/Modules/_struct.c b/Modules/_struct.c index fd550c9..3a44bde 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1572,8 +1572,7 @@ s_pack(PyObject *self, PyObject *args) soself = (PyStructObject *)self; assert(PyStruct_Check(self)); assert(soself->s_codes != NULL); - if (args == NULL || !PyTuple_Check(args) || - PyTuple_GET_SIZE(args) != soself->s_len) + if (PyTuple_GET_SIZE(args) != soself->s_len) { PyErr_Format(StructError, "pack requires exactly %zd arguments", soself->s_len); @@ -1594,16 +1593,16 @@ s_pack(PyObject *self, PyObject *args) return result; } -PyDoc_STRVAR(s_pack_to__doc__, -"S.pack_to(buffer, offset, v1, v2, ...)\n\ +PyDoc_STRVAR(s_pack_into__doc__, +"S.pack_into(buffer, offset, v1, v2, ...)\n\ \n\ -Pack the values v2, v2, ... according to this Struct's format, write \n\ +Pack the values v1, v2, ... according to this Struct's format, write \n\ the packed bytes into the writable buffer buf starting at offset. Note\n\ that the offset is not an optional argument. See struct.__doc__ for \n\ more on format strings."); static PyObject * -s_pack_to(PyObject *self, PyObject *args) +s_pack_into(PyObject *self, PyObject *args) { PyStructObject *soself; char *buffer; @@ -1613,11 +1612,10 @@ s_pack_to(PyObject *self, PyObject *args) soself = (PyStructObject *)self; assert(PyStruct_Check(self)); assert(soself->s_codes != NULL); - if (args == NULL || !PyTuple_Check(args) || - PyTuple_GET_SIZE(args) != (soself->s_len + 2)) + if (PyTuple_GET_SIZE(args) != (soself->s_len + 2)) { PyErr_Format(StructError, - "pack_to requires exactly %zd arguments", + "pack_into requires exactly %zd arguments", (soself->s_len + 2)); return NULL; } @@ -1630,7 +1628,7 @@ s_pack_to(PyObject *self, PyObject *args) assert( buffer_len >= 0 ); /* Extract the offset from the first argument */ - offset = PyInt_AsLong(PyTuple_GET_ITEM(args, 1)); + offset = PyInt_AsSsize_t(PyTuple_GET_ITEM(args, 1)); /* Support negative offsets. */ if (offset < 0) @@ -1639,7 +1637,7 @@ s_pack_to(PyObject *self, PyObject *args) /* Check boundaries */ if (offset < 0 || (buffer_len - offset) < soself->s_size) { PyErr_Format(StructError, - "pack_to requires a buffer of at least %zd bytes", + "pack_into requires a buffer of at least %zd bytes", soself->s_size); return NULL; } @@ -1668,10 +1666,11 @@ s_get_size(PyStructObject *self, void *unused) /* List of functions */ static struct PyMethodDef s_methods[] = { - {"pack", (PyCFunction)s_pack, METH_VARARGS, s_pack__doc__}, - {"pack_to", (PyCFunction)s_pack_to, METH_VARARGS, s_pack_to__doc__}, - {"unpack", (PyCFunction)s_unpack, METH_O, s_unpack__doc__}, - {"unpack_from", (PyCFunction)s_unpack_from, METH_KEYWORDS, s_unpack_from__doc__}, + {"pack", s_pack, METH_VARARGS, s_pack__doc__}, + {"pack_into", s_pack_into, METH_VARARGS, s_pack_into__doc__}, + {"unpack", s_unpack, METH_O, s_unpack__doc__}, + {"unpack_from", (PyCFunction)s_unpack_from, METH_KEYWORDS, + s_unpack_from__doc__}, {NULL, NULL} /* sentinel */ }; diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 77583b7..cec83f5 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -1274,13 +1274,13 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) and perform processing there. */ static PyObject * -Tkapp_Call(PyObject *_self, PyObject *args) +Tkapp_Call(PyObject *selfptr, PyObject *args) { Tcl_Obj *objStore[ARGSZ]; Tcl_Obj **objv = NULL; int objc, i; PyObject *res = NULL; - TkappObject *self = (TkappObject*)_self; + TkappObject *self = (TkappObject*)selfptr; /* Could add TCL_EVAL_GLOBAL if wrapped by GlobalCall... */ int flags = TCL_EVAL_DIRECT; @@ -1326,7 +1326,7 @@ Tkapp_Call(PyObject *_self, PyObject *args) ENTER_OVERLAP if (i == TCL_ERROR) - Tkinter_Error(_self); + Tkinter_Error(selfptr); else res = Tkapp_CallResult(self); @@ -1542,12 +1542,12 @@ var_proc(VarEvent* ev, int flags) } static PyObject* -var_invoke(EventFunc func, PyObject *_self, PyObject *args, int flags) +var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags) { - TkappObject *self = (TkappObject*)_self; + TkappObject *self = (TkappObject*)selfptr; #ifdef WITH_THREAD if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { - TkappObject *self = (TkappObject*)_self; + TkappObject *self = (TkappObject*)selfptr; VarEvent *ev; PyObject *res, *exc_type, *exc_val; @@ -1559,7 +1559,7 @@ var_invoke(EventFunc func, PyObject *_self, PyObject *args, int flags) ev = (VarEvent*)ckalloc(sizeof(VarEvent)); - ev->self = _self; + ev->self = selfptr; ev->args = args; ev->flags = flags; ev->func = func; @@ -1579,7 +1579,7 @@ var_invoke(EventFunc func, PyObject *_self, PyObject *args, int flags) } #endif /* Tcl is not threaded, or this is the interpreter thread. */ - return func(_self, args, flags); + return func(selfptr, args, flags); } static PyObject * @@ -2079,9 +2079,9 @@ Tkapp_CommandProc(CommandEvent *ev, int flags) } static PyObject * -Tkapp_CreateCommand(PyObject *_self, PyObject *args) +Tkapp_CreateCommand(PyObject *selfptr, PyObject *args) { - TkappObject *self = (TkappObject*)_self; + TkappObject *self = (TkappObject*)selfptr; PythonCmd_ClientData *data; char *cmdName; PyObject *func; @@ -2105,7 +2105,7 @@ Tkapp_CreateCommand(PyObject *_self, PyObject *args) return PyErr_NoMemory(); Py_XINCREF(self); Py_XINCREF(func); - data->self = _self; + data->self = selfptr; data->func = func; if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { @@ -2139,9 +2139,9 @@ Tkapp_CreateCommand(PyObject *_self, PyObject *args) static PyObject * -Tkapp_DeleteCommand(PyObject *_self, PyObject *args) +Tkapp_DeleteCommand(PyObject *selfptr, PyObject *args) { - TkappObject *self = (TkappObject*)_self; + TkappObject *self = (TkappObject*)selfptr; char *cmdName; int err; @@ -2502,10 +2502,10 @@ Tkapp_CreateTimerHandler(PyObject *self, PyObject *args) /** Event Loop **/ static PyObject * -Tkapp_MainLoop(PyObject *_self, PyObject *args) +Tkapp_MainLoop(PyObject *selfptr, PyObject *args) { int threshold = 0; - TkappObject *self = (TkappObject*)_self; + TkappObject *self = (TkappObject*)selfptr; #ifdef WITH_THREAD PyThreadState *tstate = PyThreadState_Get(); #endif diff --git a/Modules/cjkcodecs/_codecs_jp.c b/Modules/cjkcodecs/_codecs_jp.c index 9b8d324..f49a10b 100644 --- a/Modules/cjkcodecs/_codecs_jp.c +++ b/Modules/cjkcodecs/_codecs_jp.c @@ -639,10 +639,11 @@ DECODER(shift_jis_2004) REQUIRE_OUTBUF(1) JISX0201_DECODE(c, **outbuf) else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)){ - unsigned char c1, c2 = IN2; + unsigned char c1, c2; ucs4_t code; REQUIRE_INBUF(2) + c2 = IN2; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 2; diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 847a194..262abe8 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -104,9 +104,9 @@ gettimeout() -- return timeout or None\n\ listen(n) -- start listening for incoming connections\n\ makefile([mode, [bufsize]]) -- return a file object for the socket [*]\n\ recv(buflen[, flags]) -- receive data\n\ -recv_buf(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\ +recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\ recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\ -recvfrom_buf(buffer[, nbytes, [, flags])\n\ +recvfrom_into(buffer[, nbytes, [, flags])\n\ -- receive data and sender\'s address (into a buffer)\n\ sendall(data[, flags]) -- send all data\n\ send(data[, flags]) -- send data, may not send all of it\n\ @@ -2139,17 +2139,18 @@ The mode and buffersize arguments are as for the built-in open() function."); #endif /* NO_DUP */ /* - * This is the guts of the recv() and recv_buf() methods, which reads into a + * This is the guts of the recv() and recv_into() methods, which reads into a * char buffer. If you have any inc/def ref to do to the objects that contain * the buffer, do it in the caller. This function returns the number of bytes * succesfully read. If there was an error, it returns -1. Note that it is * also possible that we return a number of bytes smaller than the request * bytes. */ -static int +static ssize_t sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags) { - int timeout, outlen = 0; + ssize_t outlen = 0; + int timeout; #ifdef __VMS int remaining, nread; char *read_buf; @@ -2225,7 +2226,8 @@ sock_recv_guts(PySocketSockObject *s, char* cbuf, int len, int flags) static PyObject * sock_recv(PySocketSockObject *s, PyObject *args) { - int recvlen, flags = 0, outlen; + int recvlen, flags = 0; + ssize_t outlen; PyObject *buf; if (!PyArg_ParseTuple(args, "i|i:recv", &recvlen, &flags)) @@ -2243,7 +2245,7 @@ sock_recv(PySocketSockObject *s, PyObject *args) return NULL; /* Call the guts */ - outlen = sock_recv_guts(s, PyString_AsString(buf), recvlen, flags); + outlen = sock_recv_guts(s, PyString_AS_STRING(buf), recvlen, flags); if (outlen < 0) { /* An error occured, release the string and return an error. */ @@ -2270,19 +2272,20 @@ at least one byte is available or until the remote end is closed. When\n\ the remote end is closed and all data is read, return the empty string."); -/* s.recv_buf(buffer, [nbytes [,flags]]) method */ +/* s.recv_into(buffer, [nbytes [,flags]]) method */ static PyObject* -sock_recv_buf(PySocketSockObject *s, PyObject *args, PyObject *kwds) +sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; - int recvlen = 0, flags = 0, readlen; + int recvlen = 0, flags = 0; + ssize_t readlen; char *buf; int buflen; /* Get the buffer's memory */ - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#|ii:recv", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recv", kwlist, &buf, &buflen, &recvlen, &flags)) return NULL; assert(buf != 0 && buflen > 0); @@ -2313,11 +2316,11 @@ sock_recv_buf(PySocketSockObject *s, PyObject *args, PyObject *kwds) /* Return the number of bytes read. Note that we do not do anything special here in the case that readlen < recvlen. */ - return PyInt_FromLong(readlen); + return PyInt_FromSsize_t(readlen); } -PyDoc_STRVAR(recv_buf_doc, -"recv_buf(buffer, [nbytes[, flags]]) -> nbytes_read\n\ +PyDoc_STRVAR(recv_into_doc, +"recv_into(buffer, [nbytes[, flags]]) -> nbytes_read\n\ \n\ A version of recv() that stores its data into a buffer rather than creating \n\ a new string. Receive up to buffersize bytes from the socket. If buffersize \n\ @@ -2327,7 +2330,7 @@ See recv() for documentation about the flags."); /* - * This is the guts of the recv() and recv_buf() methods, which reads into a + * This is the guts of the recv() and recv_into() methods, which reads into a * char buffer. If you have any inc/def ref to do to the objects that contain * the buffer, do it in the caller. This function returns the number of bytes * succesfully read. If there was an error, it returns -1. Note that it is @@ -2337,12 +2340,13 @@ See recv() for documentation about the flags."); * 'addr' is a return value for the address object. Note that you must decref * it yourself. */ -static int +static ssize_t sock_recvfrom_guts(PySocketSockObject *s, char* cbuf, int len, int flags, PyObject** addr) { sock_addr_t addrbuf; - int n = 0, timeout; + int timeout; + ssize_t n = 0; socklen_t addrlen; *addr = NULL; @@ -2398,7 +2402,8 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args) PyObject *buf = NULL; PyObject *addr = NULL; PyObject *ret = NULL; - int recvlen, outlen, flags = 0; + int recvlen, flags = 0; + ssize_t outlen; if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags)) return NULL; @@ -2435,21 +2440,21 @@ PyDoc_STRVAR(recvfrom_doc, Like recv(buffersize, flags) but also return the sender's address info."); -/* s.recvfrom_buf(buffer[, nbytes [,flags]]) method */ +/* s.recvfrom_into(buffer[, nbytes [,flags]]) method */ static PyObject * -sock_recvfrom_buf(PySocketSockObject *s, PyObject *args, PyObject* kwds) +sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds) { static char *kwlist[] = {"buffer", "nbytes", "flags", 0}; - int recvlen = 0, flags = 0, readlen; + int recvlen = 0, flags = 0; + ssize_t readlen; char *buf; int buflen; PyObject *addr = NULL; - PyObject *ret = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#|ii:recvfrom", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "w#|ii:recvfrom", kwlist, &buf, &buflen, &recvlen, &flags)) return NULL; assert(buf != 0 && buflen > 0); @@ -2467,22 +2472,19 @@ sock_recvfrom_buf(PySocketSockObject *s, PyObject *args, PyObject* kwds) readlen = sock_recvfrom_guts(s, buf, recvlen, flags, &addr); if (readlen < 0) { /* Return an error */ - goto finally; + Py_XDECREF(addr); + return NULL; } /* Return the number of bytes read and the address. Note that we do not do anything special here in the case that readlen < recvlen. */ - ret = Py_BuildValue("lO", readlen, addr); - -finally: - Py_XDECREF(addr); - return ret; + return Py_BuildValue("lN", readlen, addr); } -PyDoc_STRVAR(recvfrom_buf_doc, -"recvfrom_buf(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\ +PyDoc_STRVAR(recvfrom_into_doc, +"recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\ \n\ -Like recv_buf(buffer[, nbytes[, flags]]) but also return the sender's address info."); +Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info."); /* s.send(data [,flags]) method */ @@ -2711,12 +2713,12 @@ static PyMethodDef sock_methods[] = { #endif {"recv", (PyCFunction)sock_recv, METH_VARARGS, recv_doc}, - {"recv_buf", (PyCFunction)sock_recv_buf, METH_VARARGS | METH_KEYWORDS, - recv_buf_doc}, + {"recv_into", (PyCFunction)sock_recv_into, METH_VARARGS | METH_KEYWORDS, + recv_into_doc}, {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS, recvfrom_doc}, - {"recvfrom_buf", (PyCFunction)sock_recvfrom_buf, METH_VARARGS | METH_KEYWORDS, - recvfrom_buf_doc}, + {"recvfrom_into", (PyCFunction)sock_recvfrom_into, METH_VARARGS | METH_KEYWORDS, + recvfrom_into_doc}, {"send", (PyCFunction)sock_send, METH_VARARGS, send_doc}, {"sendall", (PyCFunction)sock_sendall, METH_VARARGS, diff --git a/Objects/abstract.c b/Objects/abstract.c index 13a9473..6b76ba6 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -216,7 +216,8 @@ PyObject_DelItemString(PyObject *o, char *key) return ret; } -int PyObject_AsCharBuffer(PyObject *obj, +int +PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) { diff --git a/Objects/classobject.c b/Objects/classobject.c index 79656f5..aab35c7 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -2217,9 +2217,17 @@ instancemethod_dealloc(register PyMethodObject *im) static int instancemethod_compare(PyMethodObject *a, PyMethodObject *b) { - if (a->im_self != b->im_self) + int cmp; + cmp = PyObject_Compare(a->im_func, b->im_func); + if (cmp) + return cmp; + + if (a->im_self == b->im_self) + return 0; + if (a->im_self == NULL || b->im_self == NULL) return (a->im_self < b->im_self) ? -1 : 1; - return PyObject_Compare(a->im_func, b->im_func); + else + return PyObject_Compare(a->im_self, b->im_self); } static PyObject * @@ -2295,7 +2303,10 @@ instancemethod_hash(PyMethodObject *a) y = PyObject_Hash(a->im_func); if (y == -1) return -1; - return x ^ y; + x = x ^ y; + if (x == -1) + x = -2; + return x; } static int diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 561ba4a5..606ef05 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -901,16 +901,28 @@ wrapper_dealloc(wrapperobject *wp) static int wrapper_compare(wrapperobject *a, wrapperobject *b) { - if (a->descr == b->descr) { - if (a->self == b->self) - return 0; - else - return (a->self < b->self) ? -1 : 1; - } + if (a->descr == b->descr) + return PyObject_Compare(a->self, b->self); else return (a->descr < b->descr) ? -1 : 1; } +static long +wrapper_hash(wrapperobject *wp) +{ + int x, y; + x = _Py_HashPointer(wp->descr); + if (x == -1) + return -1; + y = PyObject_Hash(wp->self); + if (y == -1) + return -1; + x = x ^ y; + if (x == -1) + x = -2; + return x; +} + static PyObject * wrapper_repr(wrapperobject *wp) { @@ -1008,7 +1020,7 @@ static PyTypeObject wrappertype = { 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ - 0, /* tp_hash */ + (hashfunc)wrapper_hash, /* tp_hash */ (ternaryfunc)wrapper_call, /* tp_call */ 0, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 3b79307..369365b 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -851,7 +851,6 @@ WindowsError_str(PyWindowsErrorObject *self) PyTuple_SET_ITEM(tuple, 1, Py_None); } - Py_INCREF(repr); PyTuple_SET_ITEM(tuple, 2, repr); rtnval = PyString_Format(fmt, tuple); diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 997792a..0f7572f 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -1640,6 +1640,20 @@ file_self(PyFileObject *f) return (PyObject *)f; } +static PyObject * +file_exit(PyFileObject *f, PyObject *args) +{ + PyObject *ret = file_close(f); + if (!ret) + /* If error occurred, pass through */ + return NULL; + Py_DECREF(ret); + /* We cannot return the result of close since a true + * value will be interpreted as "yes, swallow the + * exception if one was raised inside the with block". */ + Py_RETURN_NONE; +} + PyDoc_STRVAR(readline_doc, "readline([size]) -> next line from the file, as a string.\n" "\n" @@ -1721,6 +1735,9 @@ PyDoc_STRVAR(isatty_doc, PyDoc_STRVAR(enter_doc, "__enter__() -> self."); +PyDoc_STRVAR(exit_doc, + "__exit__(*excinfo) -> None. Closes the file."); + static PyMethodDef file_methods[] = { {"readline", (PyCFunction)file_readline, METH_VARARGS, readline_doc}, {"read", (PyCFunction)file_read, METH_VARARGS, read_doc}, @@ -1738,7 +1755,7 @@ static PyMethodDef file_methods[] = { {"close", (PyCFunction)file_close, METH_NOARGS, close_doc}, {"isatty", (PyCFunction)file_isatty, METH_NOARGS, isatty_doc}, {"__enter__", (PyCFunction)file_self, METH_NOARGS, enter_doc}, - {"__exit__", (PyCFunction)file_close, METH_VARARGS, close_doc}, + {"__exit__", (PyCFunction)file_exit, METH_VARARGS, exit_doc}, {NULL, NULL} /* sentinel */ }; diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index a393cbc..0ca8f2b 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -491,13 +491,13 @@ static struct arena_object* usable_arenas = NULL; #define INITIAL_ARENA_OBJECTS 16 /* Number of arenas allocated that haven't been free()'d. */ -static ulong narenas_currently_allocated = 0; +static size_t narenas_currently_allocated = 0; #ifdef PYMALLOC_DEBUG /* Total number of times malloc() called to allocate an arena. */ -static ulong ntimes_arena_allocated = 0; +static size_t ntimes_arena_allocated = 0; /* High water mark (max value ever seen) for narenas_currently_allocated. */ -static ulong narenas_highwater = 0; +static size_t narenas_highwater = 0; #endif /* Allocate a new arena. If we run out of memory, return NULL. Else @@ -1220,39 +1220,45 @@ PyObject_Free(void *p) #define DEADBYTE 0xDB /* dead (newly freed) memory */ #define FORBIDDENBYTE 0xFB /* untouchable bytes at each end of a block */ -static ulong serialno = 0; /* incremented on each debug {m,re}alloc */ +static size_t serialno = 0; /* incremented on each debug {m,re}alloc */ /* serialno is always incremented via calling this routine. The point is - to supply a single place to set a breakpoint. -*/ + * to supply a single place to set a breakpoint. + */ static void bumpserialno(void) { ++serialno; } +#define SST SIZEOF_SIZE_T -/* Read 4 bytes at p as a big-endian ulong. */ -static ulong -read4(const void *p) +/* Read sizeof(size_t) bytes at p as a big-endian size_t. */ +static size_t +read_size_t(const void *p) { const uchar *q = (const uchar *)p; - return ((ulong)q[0] << 24) | - ((ulong)q[1] << 16) | - ((ulong)q[2] << 8) | - (ulong)q[3]; + size_t result = *q++; + int i; + + for (i = SST; --i > 0; ++q) + result = (result << 8) | *q; + return result; } -/* Write the 4 least-significant bytes of n as a big-endian unsigned int, - MSB at address p, LSB at p+3. */ +/* Write n as a big-endian size_t, MSB at address p, LSB at + * p + sizeof(size_t) - 1. + */ static void -write4(void *p, ulong n) +write_size_t(void *p, size_t n) { - uchar *q = (uchar *)p; - q[0] = (uchar)((n >> 24) & 0xff); - q[1] = (uchar)((n >> 16) & 0xff); - q[2] = (uchar)((n >> 8) & 0xff); - q[3] = (uchar)( n & 0xff); + uchar *q = (uchar *)p + SST - 1; + int i; + + for (i = SST; --i >= 0; --q) { + *q = (uchar)(n & 0xff); + n >>= 8; + } } #ifdef Py_DEBUG @@ -1280,25 +1286,25 @@ pool_is_in_list(const poolp target, poolp list) #endif /* Py_DEBUG */ -/* The debug malloc asks for 16 extra bytes and fills them with useful stuff, - here calling the underlying malloc's result p: +/* Let S = sizeof(size_t). The debug malloc asks for 4*S extra bytes and + fills them with useful stuff, here calling the underlying malloc's result p: -p[0:4] - Number of bytes originally asked for. 4-byte unsigned integer, - big-endian (easier to read in a memory dump). -p[4:8] +p[0: S] + Number of bytes originally asked for. This is a size_t, big-endian (easier + to read in a memory dump). +p[S: 2*S] Copies of FORBIDDENBYTE. Used to catch under- writes and reads. -p[8:8+n] +p[2*S: 2*S+n] The requested memory, filled with copies of CLEANBYTE. Used to catch reference to uninitialized memory. - &p[8] is returned. Note that this is 8-byte aligned if pymalloc + &p[2*S] is returned. Note that this is 8-byte aligned if pymalloc handled the request itself. -p[8+n:8+n+4] +p[2*S+n: 2*S+n+S] Copies of FORBIDDENBYTE. Used to catch over- writes and reads. -p[8+n+4:8+n+8] +p[2*S+n+S: 2*S+n+2*S] A serial number, incremented by 1 on each call to _PyObject_DebugMalloc and _PyObject_DebugRealloc. - 4-byte unsigned integer, big-endian. + This is a big-endian size_t. If "bad memory" is detected later, the serial number gives an excellent way to set a breakpoint on the next run, to capture the instant at which this block was passed out. @@ -1308,41 +1314,33 @@ void * _PyObject_DebugMalloc(size_t nbytes) { uchar *p; /* base address of malloc'ed block */ - uchar *tail; /* p + 8 + nbytes == pointer to tail pad bytes */ - size_t total; /* nbytes + 16 */ + uchar *tail; /* p + 2*SST + nbytes == pointer to tail pad bytes */ + size_t total; /* nbytes + 4*SST */ bumpserialno(); - total = nbytes + 16; -#if SIZEOF_SIZE_T < 8 - /* XXX do this check only on 32-bit machines */ - if (total < nbytes || (total >> 31) > 1) { - /* overflow, or we can't represent it in 4 bytes */ - /* Obscure: can't do (total >> 32) != 0 instead, because - C doesn't define what happens for a right-shift of 32 - when size_t is a 32-bit type. At least C guarantees - size_t is an unsigned type. */ + total = nbytes + 4*SST; + if (total < nbytes) + /* overflow: can't represent total as a size_t */ return NULL; - } -#endif p = (uchar *)PyObject_Malloc(total); if (p == NULL) return NULL; - write4(p, (ulong)nbytes); - p[4] = p[5] = p[6] = p[7] = FORBIDDENBYTE; + write_size_t(p, nbytes); + memset(p + SST, FORBIDDENBYTE, SST); if (nbytes > 0) - memset(p+8, CLEANBYTE, nbytes); + memset(p + 2*SST, CLEANBYTE, nbytes); - tail = p + 8 + nbytes; - tail[0] = tail[1] = tail[2] = tail[3] = FORBIDDENBYTE; - write4(tail + 4, serialno); + tail = p + 2*SST + nbytes; + memset(tail, FORBIDDENBYTE, SST); + write_size_t(tail + SST, serialno); - return p+8; + return p + 2*SST; } -/* The debug free first checks the 8 bytes on each end for sanity (in +/* The debug free first checks the 2*SST bytes on each end for sanity (in particular, that the FORBIDDENBYTEs are still intact). Then fills the original bytes with DEADBYTE. Then calls the underlying free. @@ -1350,16 +1348,16 @@ _PyObject_DebugMalloc(size_t nbytes) void _PyObject_DebugFree(void *p) { - uchar *q = (uchar *)p; + uchar *q = (uchar *)p - 2*SST; /* address returned from malloc */ size_t nbytes; if (p == NULL) return; _PyObject_DebugCheckAddress(p); - nbytes = read4(q-8); + nbytes = read_size_t(q); if (nbytes > 0) memset(q, DEADBYTE, nbytes); - PyObject_Free(q-8); + PyObject_Free(q); } void * @@ -1367,20 +1365,20 @@ _PyObject_DebugRealloc(void *p, size_t nbytes) { uchar *q = (uchar *)p; uchar *tail; - size_t total; /* nbytes + 16 */ + size_t total; /* nbytes + 4*SST */ size_t original_nbytes; + int i; if (p == NULL) return _PyObject_DebugMalloc(nbytes); _PyObject_DebugCheckAddress(p); bumpserialno(); - original_nbytes = read4(q-8); - total = nbytes + 16; - if (total < nbytes || (total >> 31) > 1) { - /* overflow, or we can't represent it in 4 bytes */ + original_nbytes = read_size_t(q - 2*SST); + total = nbytes + 4*SST; + if (total < nbytes) + /* overflow: can't represent total as a size_t */ return NULL; - } if (nbytes < original_nbytes) { /* shrinking: mark old extra memory dead */ @@ -1388,19 +1386,17 @@ _PyObject_DebugRealloc(void *p, size_t nbytes) } /* Resize and add decorations. */ - q = (uchar *)PyObject_Realloc(q-8, total); + q = (uchar *)PyObject_Realloc(q - 2*SST, total); if (q == NULL) return NULL; - write4(q, (ulong)nbytes); - assert(q[4] == FORBIDDENBYTE && - q[5] == FORBIDDENBYTE && - q[6] == FORBIDDENBYTE && - q[7] == FORBIDDENBYTE); - q += 8; + write_size_t(q, nbytes); + for (i = 0; i < SST; ++i) + assert(q[SST + i] == FORBIDDENBYTE); + q += 2*SST; tail = q + nbytes; - tail[0] = tail[1] = tail[2] = tail[3] = FORBIDDENBYTE; - write4(tail + 4, serialno); + memset(tail, FORBIDDENBYTE, SST); + write_size_t(tail + SST, serialno); if (nbytes > original_nbytes) { /* growing: mark new extra memory clean */ @@ -1420,7 +1416,7 @@ _PyObject_DebugCheckAddress(const void *p) { const uchar *q = (const uchar *)p; char *msg; - ulong nbytes; + size_t nbytes; const uchar *tail; int i; @@ -1433,16 +1429,16 @@ _PyObject_DebugCheckAddress(const void *p) * corruption, the number-of-bytes field may be nuts, and checking * the tail could lead to a segfault then. */ - for (i = 4; i >= 1; --i) { + for (i = SST; i >= 1; --i) { if (*(q-i) != FORBIDDENBYTE) { msg = "bad leading pad byte"; goto error; } } - nbytes = read4(q-8); + nbytes = read_size_t(q - 2*SST); tail = q + nbytes; - for (i = 0; i < 4; ++i) { + for (i = 0; i < SST; ++i) { if (tail[i] != FORBIDDENBYTE) { msg = "bad trailing pad byte"; goto error; @@ -1462,28 +1458,33 @@ _PyObject_DebugDumpAddress(const void *p) { const uchar *q = (const uchar *)p; const uchar *tail; - ulong nbytes, serial; + size_t nbytes, serial; int i; + int ok; fprintf(stderr, "Debug memory block at address p=%p:\n", p); if (p == NULL) return; - nbytes = read4(q-8); - fprintf(stderr, " %lu bytes originally requested\n", nbytes); + nbytes = read_size_t(q - 2*SST); + fprintf(stderr, " %" PY_FORMAT_SIZE_T "u bytes originally " + "requested\n", nbytes); /* In case this is nuts, check the leading pad bytes first. */ - fputs(" The 4 pad bytes at p-4 are ", stderr); - if (*(q-4) == FORBIDDENBYTE && - *(q-3) == FORBIDDENBYTE && - *(q-2) == FORBIDDENBYTE && - *(q-1) == FORBIDDENBYTE) { - fputs("FORBIDDENBYTE, as expected.\n", stderr); + fprintf(stderr, " The %d pad bytes at p-%d are ", SST, SST); + ok = 1; + for (i = 1; i <= SST; ++i) { + if (*(q-i) != FORBIDDENBYTE) { + ok = 0; + break; + } } + if (ok) + fputs("FORBIDDENBYTE, as expected.\n", stderr); else { fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n", FORBIDDENBYTE); - for (i = 4; i >= 1; --i) { + for (i = SST; i >= 1; --i) { const uchar byte = *(q-i); fprintf(stderr, " at p-%d: 0x%02x", i, byte); if (byte != FORBIDDENBYTE) @@ -1498,17 +1499,20 @@ _PyObject_DebugDumpAddress(const void *p) } tail = q + nbytes; - fprintf(stderr, " The 4 pad bytes at tail=%p are ", tail); - if (tail[0] == FORBIDDENBYTE && - tail[1] == FORBIDDENBYTE && - tail[2] == FORBIDDENBYTE && - tail[3] == FORBIDDENBYTE) { - fputs("FORBIDDENBYTE, as expected.\n", stderr); + fprintf(stderr, " The %d pad bytes at tail=%p are ", SST, tail); + ok = 1; + for (i = 0; i < SST; ++i) { + if (tail[i] != FORBIDDENBYTE) { + ok = 0; + break; + } } + if (ok) + fputs("FORBIDDENBYTE, as expected.\n", stderr); else { fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n", FORBIDDENBYTE); - for (i = 0; i < 4; ++i) { + for (i = 0; i < SST; ++i) { const uchar byte = tail[i]; fprintf(stderr, " at tail+%d: 0x%02x", i, byte); @@ -1518,12 +1522,12 @@ _PyObject_DebugDumpAddress(const void *p) } } - serial = read4(tail+4); - fprintf(stderr, " The block was made by call #%lu to " - "debug malloc/realloc.\n", serial); + serial = read_size_t(tail + SST); + fprintf(stderr, " The block was made by call #%" PY_FORMAT_SIZE_T + "u to debug malloc/realloc.\n", serial); if (nbytes > 0) { - int i = 0; + i = 0; fputs(" Data at p:", stderr); /* print up to 8 bytes at the start */ while (q < tail && i < 8) { @@ -1546,12 +1550,12 @@ _PyObject_DebugDumpAddress(const void *p) } } -static ulong -printone(const char* msg, ulong value) +static size_t +printone(const char* msg, size_t value) { int i, k; char buf[100]; - ulong origvalue = value; + size_t origvalue = value; fputs(msg, stderr); for (i = (int)strlen(msg); i < 35; ++i) @@ -1564,8 +1568,8 @@ printone(const char* msg, ulong value) buf[i--] = '\n'; k = 3; do { - ulong nextvalue = value / 10UL; - uint digit = value - nextvalue * 10UL; + size_t nextvalue = value / 10; + uint digit = (uint)(value - nextvalue * 10); value = nextvalue; buf[i--] = (char)(digit + '0'); --k; @@ -1592,28 +1596,28 @@ _PyObject_DebugMallocStats(void) uint i; const uint numclasses = SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT; /* # of pools, allocated blocks, and free blocks per class index */ - ulong numpools[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; - ulong numblocks[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; - ulong numfreeblocks[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; + size_t numpools[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; + size_t numblocks[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; + size_t numfreeblocks[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; /* total # of allocated bytes in used and full pools */ - ulong allocated_bytes = 0; + size_t allocated_bytes = 0; /* total # of available bytes in used pools */ - ulong available_bytes = 0; + size_t available_bytes = 0; /* # of free pools + pools not yet carved out of current arena */ uint numfreepools = 0; /* # of bytes for arena alignment padding */ - ulong arena_alignment = 0; + size_t arena_alignment = 0; /* # of bytes in used and full pools used for pool_headers */ - ulong pool_header_bytes = 0; + size_t pool_header_bytes = 0; /* # of bytes in used and full pools wasted due to quantization, * i.e. the necessarily leftover space at the ends of used and * full pools. */ - ulong quantization = 0; + size_t quantization = 0; /* # of arenas actually allocated. */ - ulong narenas = 0; + size_t narenas = 0; /* running total -- should equal narenas * ARENA_SIZE */ - ulong total; + size_t total; char buf[128]; fprintf(stderr, "Small block threshold = %d, in %u size classes.\n", @@ -1678,15 +1682,18 @@ _PyObject_DebugMallocStats(void) stderr); for (i = 0; i < numclasses; ++i) { - ulong p = numpools[i]; - ulong b = numblocks[i]; - ulong f = numfreeblocks[i]; + size_t p = numpools[i]; + size_t b = numblocks[i]; + size_t f = numfreeblocks[i]; uint size = INDEX2SIZE(i); if (p == 0) { assert(b == 0 && f == 0); continue; } - fprintf(stderr, "%5u %6u %11lu %15lu %13lu\n", + fprintf(stderr, "%5u %6u " + "%11" PY_FORMAT_SIZE_T "u " + "%15" PY_FORMAT_SIZE_T "u " + "%13" PY_FORMAT_SIZE_T "u\n", i, size, p, b, f); allocated_bytes += b * size; available_bytes += f * size; @@ -1702,7 +1709,8 @@ _PyObject_DebugMallocStats(void) (void)printone("# arenas allocated current", narenas); PyOS_snprintf(buf, sizeof(buf), - "%lu arenas * %d bytes/arena", narenas, ARENA_SIZE); + "%" PY_FORMAT_SIZE_T "u arenas * %d bytes/arena", + narenas, ARENA_SIZE); (void)printone(buf, narenas * ARENA_SIZE); fputc('\n', stderr); @@ -1712,7 +1720,7 @@ _PyObject_DebugMallocStats(void) PyOS_snprintf(buf, sizeof(buf), "%u unused pools * %d bytes", numfreepools, POOL_SIZE); - total += printone(buf, (ulong)numfreepools * POOL_SIZE); + total += printone(buf, (size_t)numfreepools * POOL_SIZE); total += printone("# bytes lost to pool headers", pool_header_bytes); total += printone("# bytes lost to quantization", quantization); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 6cdb0fc..dcc9274 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3057,6 +3057,221 @@ PyObject *PyUnicode_DecodeCharmap(const char *s, return NULL; } +/* Charmap encoding: the lookup table */ + +struct encoding_map{ + PyObject_HEAD + unsigned char level1[32]; + int count2, count3; + unsigned char level23[1]; +}; + +static PyObject* +encoding_map_size(PyObject *obj, PyObject* args) +{ + struct encoding_map *map = (struct encoding_map*)obj; + return PyInt_FromLong(sizeof(*map) - 1 + 16*map->count2 + + 128*map->count3); +} + +static PyMethodDef encoding_map_methods[] = { + {"size", encoding_map_size, METH_NOARGS, + PyDoc_STR("Return the size (in bytes) of this object") }, + { 0 } +}; + +static void +encoding_map_dealloc(PyObject* o) +{ + PyObject_FREE(o); +} + +static PyTypeObject EncodingMapType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "EncodingMap", /*tp_name*/ + sizeof(struct encoding_map), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + encoding_map_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + encoding_map_methods, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + 0, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ +}; + +PyObject* +PyUnicode_BuildEncodingMap(PyObject* string) +{ + Py_UNICODE *decode; + PyObject *result; + struct encoding_map *mresult; + int i; + int need_dict = 0; + unsigned char level1[32]; + unsigned char level2[512]; + unsigned char *mlevel1, *mlevel2, *mlevel3; + int count2 = 0, count3 = 0; + + if (!PyUnicode_Check(string) || PyUnicode_GetSize(string) != 256) { + PyErr_BadArgument(); + return NULL; + } + decode = PyUnicode_AS_UNICODE(string); + memset(level1, 0xFF, sizeof level1); + memset(level2, 0xFF, sizeof level2); + + /* If there isn't a one-to-one mapping of NULL to \0, + or if there are non-BMP characters, we need to use + a mapping dictionary. */ + if (decode[0] != 0) + need_dict = 1; + for (i = 1; i < 256; i++) { + int l1, l2; + if (decode[i] == 0 + #ifdef Py_UNICODE_WIDE + || decode[i] > 0xFFFF + #endif + ) { + need_dict = 1; + break; + } + if (decode[i] == 0xFFFE) + /* unmapped character */ + continue; + l1 = decode[i] >> 11; + l2 = decode[i] >> 7; + if (level1[l1] == 0xFF) + level1[l1] = count2++; + if (level2[l2] == 0xFF) + level2[l2] = count3++; + } + + if (count2 >= 0xFF || count3 >= 0xFF) + need_dict = 1; + + if (need_dict) { + PyObject *result = PyDict_New(); + PyObject *key, *value; + if (!result) + return NULL; + for (i = 0; i < 256; i++) { + key = value = NULL; + key = PyInt_FromLong(decode[i]); + value = PyInt_FromLong(i); + if (!key || !value) + goto failed1; + if (PyDict_SetItem(result, key, value) == -1) + goto failed1; + Py_DECREF(key); + Py_DECREF(value); + } + return result; + failed1: + Py_XDECREF(key); + Py_XDECREF(value); + Py_DECREF(result); + return NULL; + } + + /* Create a three-level trie */ + result = PyObject_MALLOC(sizeof(struct encoding_map) + + 16*count2 + 128*count3 - 1); + if (!result) + return PyErr_NoMemory(); + PyObject_Init(result, &EncodingMapType); + mresult = (struct encoding_map*)result; + mresult->count2 = count2; + mresult->count3 = count3; + mlevel1 = mresult->level1; + mlevel2 = mresult->level23; + mlevel3 = mresult->level23 + 16*count2; + memcpy(mlevel1, level1, 32); + memset(mlevel2, 0xFF, 16*count2); + memset(mlevel3, 0, 128*count3); + count3 = 0; + for (i = 1; i < 256; i++) { + int o1, o2, o3, i2, i3; + if (decode[i] == 0xFFFE) + /* unmapped character */ + continue; + o1 = decode[i]>>11; + o2 = (decode[i]>>7) & 0xF; + i2 = 16*mlevel1[o1] + o2; + if (mlevel2[i2] == 0xFF) + mlevel2[i2] = count3++; + o3 = decode[i] & 0x7F; + i3 = 128*mlevel2[i2] + o3; + mlevel3[i3] = i; + } + return result; +} + +static int +encoding_map_lookup(Py_UNICODE c, PyObject *mapping) +{ + struct encoding_map *map = (struct encoding_map*)mapping; + int l1 = c>>11; + int l2 = (c>>7) & 0xF; + int l3 = c & 0x7F; + int i; + +#ifdef Py_UNICODE_WIDE + if (c > 0xFFFF) { + return -1; + } +#endif + if (c == 0) + return 0; + /* level 1*/ + i = map->level1[l1]; + if (i == 0xFF) { + return -1; + } + /* level 2*/ + i = map->level23[16*i+l2]; + if (i == 0xFF) { + return -1; + } + /* level 3 */ + i = map->level23[16*map->count2 + 128*i + l3]; + if (i == 0) { + return -1; + } + return i; +} + /* Lookup the character ch in the mapping. If the character can't be found, Py_None is returned (or NULL, if another error occurred). */ @@ -3102,6 +3317,22 @@ static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping) } } +static int +charmapencode_resize(PyObject **outobj, Py_ssize_t *outpos, Py_ssize_t requiredsize) +{ + Py_ssize_t outsize = PyString_GET_SIZE(*outobj); + /* exponentially overallocate to minimize reallocations */ + if (requiredsize < 2*outsize) + requiredsize = 2*outsize; + if (_PyString_Resize(outobj, requiredsize)) { + return 0; + } + return 1; +} + +typedef enum charmapencode_result { + enc_SUCCESS, enc_FAILED, enc_EXCEPTION +}charmapencode_result; /* lookup the character, put the result in the output string and adjust various state variables. Reallocate the output string if not enough space is available. Return a new reference to the object that @@ -3109,51 +3340,59 @@ static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping) (in which case no character was written) or NULL, if a reallocation error occurred. The caller must decref the result */ static -PyObject *charmapencode_output(Py_UNICODE c, PyObject *mapping, +charmapencode_result charmapencode_output(Py_UNICODE c, PyObject *mapping, PyObject **outobj, Py_ssize_t *outpos) { - PyObject *rep = charmapencode_lookup(c, mapping); + PyObject *rep; + char *outstart; + Py_ssize_t outsize = PyString_GET_SIZE(*outobj); + if (mapping->ob_type == &EncodingMapType) { + int res = encoding_map_lookup(c, mapping); + Py_ssize_t requiredsize = *outpos+1; + if (res == -1) + return enc_FAILED; + if (outsizeob_type == &EncodingMapType) { + int res = encoding_map_lookup(p[collendpos], mapping); + if (res != -1) + break; + ++collendpos; + continue; + } + + rep = charmapencode_lookup(p[collendpos], mapping); + if (rep==NULL) return -1; - else if (x!=Py_None) { - Py_DECREF(x); + else if (rep!=Py_None) { + Py_DECREF(rep); break; } - Py_DECREF(x); + Py_DECREF(rep); ++collendpos; } /* cache callback name lookup @@ -3210,15 +3458,13 @@ int charmap_encoding_error( case 2: /* replace */ for (collpos = collstartpos; collpos0; ++uni2) { x = charmapencode_output(*uni2, mapping, res, respos); - if (x==NULL) { - Py_DECREF(repunicode); + if (x==enc_EXCEPTION) { return -1; } - else if (x==Py_None) { + else if (x==enc_FAILED) { Py_DECREF(repunicode); - Py_DECREF(x); raise_encode_exception(exceptionObject, encoding, p, size, collstartpos, collendpos, reason); return -1; } - Py_DECREF(x); } *inpos = newpos; Py_DECREF(repunicode); @@ -3304,22 +3545,20 @@ PyObject *PyUnicode_EncodeCharmap(const Py_UNICODE *p, while (inpos adjust input position */ ++inpos; - Py_DECREF(x); } /* Resize if we allocated to much */ diff --git a/PC/_subprocess.c b/PC/_subprocess.c index 0e4ee5f..f048bc2 100644 --- a/PC/_subprocess.c +++ b/PC/_subprocess.c @@ -250,19 +250,23 @@ static int getint(PyObject* obj, char* name) { PyObject* value; + int ret; value = PyObject_GetAttrString(obj, name); if (! value) { PyErr_Clear(); /* FIXME: propagate error? */ return 0; } - return (int) PyInt_AsLong(value); + ret = (int) PyInt_AsLong(value); + Py_DECREF(value); + return ret; } static HANDLE gethandle(PyObject* obj, char* name) { sp_handle_object* value; + HANDLE ret; value = (sp_handle_object*) PyObject_GetAttrString(obj, name); if (! value) { @@ -270,8 +274,11 @@ gethandle(PyObject* obj, char* name) return NULL; } if (value->ob_type != &sp_handle_type) - return NULL; - return value->handle; + ret = NULL; + else + ret = value->handle; + Py_DECREF(value); + return ret; } static PyObject* diff --git a/PC/py.ico b/PC/py.ico index 114864a..3357aef 100644 Binary files a/PC/py.ico and b/PC/py.ico differ diff --git a/PC/pyc.ico b/PC/pyc.ico index 8155b99..f7bd2b1 100644 Binary files a/PC/pyc.ico and b/PC/pyc.ico differ diff --git a/PC/pycon.ico b/PC/pycon.ico index 7faa7ce..1ab629e 100644 Binary files a/PC/pycon.ico and b/PC/pycon.ico differ diff --git a/Parser/node.c b/Parser/node.c index 97f887a..d133a0d 100644 --- a/Parser/node.c +++ b/Parser/node.c @@ -65,7 +65,7 @@ fancy_roundup(int n) * reported that, with this scheme, 89% of PyObject_REALLOC calls in * PyNode_AddChild passed 1 for the size, and 9% passed 4. So this usually * wastes very little memory, but is very effective at sidestepping - * platform-realloc disasters on vulnernable platforms. + * platform-realloc disasters on vulnerable platforms. * * Note that this would be straightforward if a node stored its current * capacity. The code is tricky to avoid that. diff --git a/Python/compile.c b/Python/compile.c index 199cac5..6d96006 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2141,7 +2141,7 @@ static int compiler_if(struct compiler *c, stmt_ty s) { basicblock *end, *next; - + int constant; assert(s->kind == If_kind); end = compiler_new_block(c); if (end == NULL) @@ -2149,15 +2149,27 @@ compiler_if(struct compiler *c, stmt_ty s) next = compiler_new_block(c); if (next == NULL) return 0; - VISIT(c, expr, s->v.If.test); - ADDOP_JREL(c, JUMP_IF_FALSE, next); - ADDOP(c, POP_TOP); - VISIT_SEQ(c, stmt, s->v.If.body); - ADDOP_JREL(c, JUMP_FORWARD, end); - compiler_use_next_block(c, next); - ADDOP(c, POP_TOP); - if (s->v.If.orelse) - VISIT_SEQ(c, stmt, s->v.If.orelse); + + constant = expr_constant(s->v.If.test); + /* constant = 0: "if 0" + * constant = 1: "if 1", "if 2", ... + * constant = -1: rest */ + if (constant == 0) { + if (s->v.If.orelse) + VISIT_SEQ(c, stmt, s->v.If.orelse); + } else if (constant == 1) { + VISIT_SEQ(c, stmt, s->v.If.body); + } else { + VISIT(c, expr, s->v.If.test); + ADDOP_JREL(c, JUMP_IF_FALSE, next); + ADDOP(c, POP_TOP); + VISIT_SEQ(c, stmt, s->v.If.body); + ADDOP_JREL(c, JUMP_FORWARD, end); + compiler_use_next_block(c, next); + ADDOP(c, POP_TOP); + if (s->v.If.orelse) + VISIT_SEQ(c, stmt, s->v.If.orelse); + } compiler_use_next_block(c, end); return 1; } @@ -2623,10 +2635,6 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s) if (c->u->u_ste->ste_type != FunctionBlock) return compiler_error(c, "'return' outside function"); if (s->v.Return.value) { - if (c->u->u_ste->ste_generator) { - return compiler_error(c, - "'return' with argument inside generator"); - } VISIT(c, expr, s->v.Return.value); } else @@ -3334,6 +3342,13 @@ expr_constant(expr_ty e) return PyObject_IsTrue(e->v.Num.n); case Str_kind: return PyObject_IsTrue(e->v.Str.s); + case Name_kind: + /* __debug__ is not assignable, so we can optimize + * it away in if and while statements */ + if (strcmp(PyString_AS_STRING(e->v.Name.id), + "__debug__") == 0) + return ! Py_OptimizeFlag; + /* fall through */ default: return -1; } diff --git a/Python/symtable.c b/Python/symtable.c index 184723d..1dc2a2e 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -13,6 +13,8 @@ #define IMPORT_STAR_WARNING "import * only allowed at module level" +#define RETURN_VAL_IN_GENERATOR \ + "'return' with argument inside generator" /* XXX(nnorwitz): change name since static? */ static PySTEntryObject * @@ -66,6 +68,7 @@ PySTEntry_New(struct symtable *st, identifier name, _Py_block_ty block, ste->ste_nested = 1; ste->ste_child_free = 0; ste->ste_generator = 0; + ste->ste_returns_value = 0; if (PyDict_SetItem(st->st_symbols, ste->ste_id, (PyObject *)ste) < 0) goto fail; @@ -944,8 +947,17 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) break; } case Return_kind: - if (s->v.Return.value) + if (s->v.Return.value) { VISIT(st, expr, s->v.Return.value); + st->st_cur->ste_returns_value = 1; + if (st->st_cur->ste_generator) { + PyErr_SetString(PyExc_SyntaxError, + RETURN_VAL_IN_GENERATOR); + PyErr_SyntaxLocation(st->st_filename, + s->lineno); + return 0; + } + } break; case Delete_kind: VISIT_SEQ(st, expr, s->v.Delete.targets); @@ -1136,6 +1148,13 @@ symtable_visit_expr(struct symtable *st, expr_ty e) if (e->v.Yield.value) VISIT(st, expr, e->v.Yield.value); st->st_cur->ste_generator = 1; + if (st->st_cur->ste_returns_value) { + PyErr_SetString(PyExc_SyntaxError, + RETURN_VAL_IN_GENERATOR); + PyErr_SyntaxLocation(st->st_filename, + e->lineno); + return 0; + } break; case Compare_kind: VISIT(st, expr, e->v.Compare.left); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4c92a90..fe47fd1 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1027,7 +1027,7 @@ _PySys_Init(void) PyObject *sysin, *sysout, *syserr; char *s; #ifdef MS_WINDOWS - char buf[10]; + char buf[128]; #endif m = Py_InitModule3("sys", sys_methods, sys_doc); diff --git a/Python/thread.c b/Python/thread.c index 5e7fc6c..c9356dc 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -75,7 +75,8 @@ static int initialized; static void PyThread__init_thread(void); /* Forward */ -void PyThread_init_thread(void) +void +PyThread_init_thread(void) { #ifdef Py_DEBUG char *p = getenv("THREADDEBUG"); diff --git a/Python/thread_nt.h b/Python/thread_nt.h index 5141053..0b7e84e 100644 --- a/Python/thread_nt.h +++ b/Python/thread_nt.h @@ -16,7 +16,8 @@ typedef struct NRMUTEX { typedef PVOID WINAPI interlocked_cmp_xchg_t(PVOID *dest, PVOID exc, PVOID comperand) ; /* Sorry mate, but we haven't got InterlockedCompareExchange in Win95! */ -static PVOID WINAPI interlocked_cmp_xchg(PVOID *dest, PVOID exc, PVOID comperand) +static PVOID WINAPI +interlocked_cmp_xchg(PVOID *dest, PVOID exc, PVOID comperand) { static LONG spinlock = 0 ; PVOID result ; @@ -54,8 +55,10 @@ static PVOID WINAPI interlocked_cmp_xchg(PVOID *dest, PVOID exc, PVOID comperand return result ; } ; -static interlocked_cmp_xchg_t *ixchg ; -BOOL InitializeNonRecursiveMutex(PNRMUTEX mutex) +static interlocked_cmp_xchg_t *ixchg; + +BOOL +InitializeNonRecursiveMutex(PNRMUTEX mutex) { if (!ixchg) { @@ -76,14 +79,16 @@ BOOL InitializeNonRecursiveMutex(PNRMUTEX mutex) #endif #define InterlockedCompareExchange(dest,exchange,comperand) (ixchg((dest), (exchange), (comperand))) -VOID DeleteNonRecursiveMutex(PNRMUTEX mutex) +VOID +DeleteNonRecursiveMutex(PNRMUTEX mutex) { /* No in-use check */ CloseHandle(mutex->hevent) ; mutex->hevent = NULL ; /* Just in case */ } -DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) +DWORD +EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) { /* Assume that the thread waits successfully */ DWORD ret ; @@ -104,7 +109,8 @@ DWORD EnterNonRecursiveMutex(PNRMUTEX mutex, BOOL wait) return ret ; } -BOOL LeaveNonRecursiveMutex(PNRMUTEX mutex) +BOOL +LeaveNonRecursiveMutex(PNRMUTEX mutex) { /* We don't own the mutex */ mutex->thread_id = 0 ; @@ -113,7 +119,8 @@ BOOL LeaveNonRecursiveMutex(PNRMUTEX mutex) SetEvent(mutex->hevent) ; /* Other threads are waiting, wake one on them up */ } -PNRMUTEX AllocNonRecursiveMutex(void) +PNRMUTEX +AllocNonRecursiveMutex(void) { PNRMUTEX mutex = (PNRMUTEX)malloc(sizeof(NRMUTEX)) ; if (mutex && !InitializeNonRecursiveMutex(mutex)) @@ -124,7 +131,8 @@ PNRMUTEX AllocNonRecursiveMutex(void) return mutex ; } -void FreeNonRecursiveMutex(PNRMUTEX mutex) +void +FreeNonRecursiveMutex(PNRMUTEX mutex) { if (mutex) { @@ -138,7 +146,8 @@ long PyThread_get_thread_ident(void); /* * Initialization of the C package, should not be needed. */ -static void PyThread__init_thread(void) +static void +PyThread__init_thread(void) { } @@ -209,7 +218,8 @@ PyThread_start_new_thread(void (*func)(void *), void *arg) * Return the thread Id instead of an handle. The Id is said to uniquely identify the * thread in the system */ -long PyThread_get_thread_ident(void) +long +PyThread_get_thread_ident(void) { if (!initialized) PyThread_init_thread(); @@ -217,7 +227,8 @@ long PyThread_get_thread_ident(void) return GetCurrentThreadId(); } -static void do_PyThread_exit_thread(int no_cleanup) +static void +do_PyThread_exit_thread(int no_cleanup) { dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); if (!initialized) @@ -228,18 +239,21 @@ static void do_PyThread_exit_thread(int no_cleanup) _endthread(); } -void PyThread_exit_thread(void) +void +PyThread_exit_thread(void) { do_PyThread_exit_thread(0); } -void PyThread__exit_thread(void) +void +PyThread__exit_thread(void) { do_PyThread_exit_thread(1); } #ifndef NO_EXIT_PROG -static void do_PyThread_exit_prog(int status, int no_cleanup) +static void +do_PyThread_exit_prog(int status, int no_cleanup) { dprintf(("PyThread_exit_prog(%d) called\n", status)); if (!initialized) @@ -249,12 +263,14 @@ static void do_PyThread_exit_prog(int status, int no_cleanup) exit(status); } -void PyThread_exit_prog(int status) +void +PyThread_exit_prog(int status) { do_PyThread_exit_prog(status, 0); } -void PyThread__exit_prog(int status) +void +PyThread__exit_prog(int status) { do_PyThread_exit_prog(status, 1); } @@ -265,7 +281,8 @@ void PyThread__exit_prog(int status) * I [Dag] tried to implement it with mutex but I could find a way to * tell whether a thread already own the lock or not. */ -PyThread_type_lock PyThread_allocate_lock(void) +PyThread_type_lock +PyThread_allocate_lock(void) { PNRMUTEX aLock; @@ -280,7 +297,8 @@ PyThread_type_lock PyThread_allocate_lock(void) return (PyThread_type_lock) aLock; } -void PyThread_free_lock(PyThread_type_lock aLock) +void +PyThread_free_lock(PyThread_type_lock aLock) { dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); @@ -293,7 +311,8 @@ void PyThread_free_lock(PyThread_type_lock aLock) * and 0 if the lock was not acquired. This means a 0 is returned * if the lock has already been acquired by this thread! */ -int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) +int +PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) { int success ; @@ -306,7 +325,8 @@ int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) return success; } -void PyThread_release_lock(PyThread_type_lock aLock) +void +PyThread_release_lock(PyThread_type_lock aLock) { dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); diff --git a/Python/thread_os2.h b/Python/thread_os2.h index a18ce6f..86e91c1 100644 --- a/Python/thread_os2.h +++ b/Python/thread_os2.h @@ -238,7 +238,8 @@ PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) return 1; } -void PyThread_release_lock(PyThread_type_lock aLock) +void +PyThread_release_lock(PyThread_type_lock aLock) { #if !defined(PYCC_GCC) type_os2_lock lock = (type_os2_lock)aLock; diff --git a/Tools/unicode/Makefile b/Tools/unicode/Makefile index fbd3557..35744ad 100644 --- a/Tools/unicode/Makefile +++ b/Tools/unicode/Makefile @@ -78,7 +78,7 @@ cjk: build/ ### Cleanup clean: - $(RM) build/* + $(RM) -f build/* distclean: clean $(RM) -rf MAPPINGS/ diff --git a/Tools/unicode/gencodec.py b/Tools/unicode/gencodec.py index 0aef207..dabcd72 100644 --- a/Tools/unicode/gencodec.py +++ b/Tools/unicode/gencodec.py @@ -270,6 +270,11 @@ def codegen(name, map, encodingname, comments=1): comments=comments, precisions=(4, 2)) + if decoding_table_code: + suffix = 'table' + else: + suffix = 'map' + l = [ '''\ """ Python Character Mapping Codec %s generated from '%s' with gencodec.py. @@ -283,30 +288,20 @@ import codecs class Codec(codecs.Codec): def encode(self,input,errors='strict'): - return codecs.charmap_encode(input,errors,encoding_map) - - def decode(self,input,errors='strict'):''' % (encodingname, name) - ] - if decoding_table_code: - l.append('''\ - return codecs.charmap_decode(input,errors,decoding_table)''') - else: - l.append('''\ - return codecs.charmap_decode(input,errors,decoding_map)''') + return codecs.charmap_encode(input,errors,encoding_%s) - l.append(''' + def decode(self,input,errors='strict'): + return codecs.charmap_decode(input,errors,decoding_%s) +''' % (encodingname, name, suffix, suffix)] + l.append('''\ class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): - return codecs.charmap_encode(input,self.errors,encoding_map)[0] + return codecs.charmap_encode(input,self.errors,encoding_%s)[0] class IncrementalDecoder(codecs.IncrementalDecoder): - def decode(self, input, final=False):''') - if decoding_table_code: - l.append('''\ - return codecs.charmap_decode(input,self.errors,decoding_table)[0]''') - else: - l.append('''\ - return codecs.charmap_decode(input,self.errors,decoding_map)[0]''') + def decode(self, input, final=False): + return codecs.charmap_decode(input,self.errors,decoding_%s)[0]''' % + (suffix, suffix)) l.append(''' class StreamWriter(Codec,codecs.StreamWriter): @@ -319,13 +314,13 @@ class StreamReader(Codec,codecs.StreamReader): def getregentry(): return codecs.CodecInfo( - Codec().encode, - Codec().decode, name=%r, - streamwriter=StreamWriter, - streamreader=StreamReader, + encode=Codec().encode, + decode=Codec().decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, + streamreader=StreamReader, + streamwriter=StreamWriter, ) ''' % encodingname.replace('_', '-')) @@ -342,10 +337,16 @@ def getregentry(): l.extend(decoding_table_code) # Add encoding map - l.append(''' + if decoding_table_code: + l.append(''' +### Encoding table +encoding_table=codecs.charmap_build(decoding_table) +''') + else: + l.append(''' ### Encoding Map ''') - l.extend(encoding_map_code) + l.extend(encoding_map_code) # Final new-line l.append('') diff --git a/Tools/webchecker/webchecker.py b/Tools/webchecker/webchecker.py index 990159c..7199da8 100755 --- a/Tools/webchecker/webchecker.py +++ b/Tools/webchecker/webchecker.py @@ -784,7 +784,7 @@ class MyHTMLParser(sgmllib.SGMLParser): self.url = url sgmllib.SGMLParser.__init__(self) - def check_name_id( self, attributes ): + def check_name_id(self, attributes): """ Check the name or id attributes on an element. """ # We must rescue the NAME or id (name is deprecated in XHTML) @@ -799,7 +799,7 @@ class MyHTMLParser(sgmllib.SGMLParser): else: self.names.append(value) break - def unknown_starttag( self, tag, attributes ): + def unknown_starttag(self, tag, attributes): """ In XHTML, you can have id attributes on any element. """ self.check_name_id(attributes) diff --git a/configure b/configure index 56ed6c2..b02ebc6 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 46491 . +# From configure.in Revision: 46753 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59e for python 3.0. # @@ -648,6 +648,9 @@ PYTHONFRAMEWORKPREFIX PYTHONFRAMEWORKINSTALLDIR FRAMEWORKINSTALLFIRST FRAMEWORKINSTALLLAST +FRAMEWORKALTINSTALLFIRST +FRAMEWORKALTINSTALLLAST +FRAMEWORKUNIXTOOLSPREFIX MACHDEP SGI_ABI EXTRAPLATDIR @@ -1874,6 +1877,13 @@ if test "${enable_framework+set}" = set; then PYTHONFRAMEWORKINSTALLDIR= FRAMEWORKINSTALLFIRST= FRAMEWORKINSTALLLAST= + FRAMEWORKALTINSTALLFIRST= + FRAMEWORKALTINSTALLLAST= + if test "x${prefix}" = "xNONE"; then + FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}" + else + FRAMEWORKUNIXTOOLSPREFIX="${prefix}" + fi enable_framework= ;; *) @@ -1883,15 +1893,22 @@ if test "${enable_framework+set}" = set; then PYTHONFRAMEWORKINSTALLDIR=$PYTHONFRAMEWORKPREFIX/$PYTHONFRAMEWORKDIR FRAMEWORKINSTALLFIRST="frameworkinstallstructure" FRAMEWORKINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools" + FRAMEWORKALTINSTALLFIRST="${FRAMEWORKINSTALLFIRST} bininstall maninstall" + FRAMEWORKALTINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkaltinstallunixtools" + if test "x${prefix}" = "xNONE" ; then + FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}" + else + FRAMEWORKUNIXTOOLSPREFIX="${prefix}" + fi prefix=$PYTHONFRAMEWORKINSTALLDIR/Versions/$VERSION # Add makefiles for Mac specific code to the list of output # files: - ac_config_files="$ac_config_files Mac/OSX/Makefile" + ac_config_files="$ac_config_files Mac/Makefile" - ac_config_files="$ac_config_files Mac/OSX/PythonLauncher/Makefile" + ac_config_files="$ac_config_files Mac/PythonLauncher/Makefile" - ac_config_files="$ac_config_files Mac/OSX/IDLE/Makefile" + ac_config_files="$ac_config_files Mac/IDLE/Makefile" esac @@ -1903,6 +1920,13 @@ else PYTHONFRAMEWORKINSTALLDIR= FRAMEWORKINSTALLFIRST= FRAMEWORKINSTALLLAST= + FRAMEWORKALTINSTALLFIRST= + FRAMEWORKALTINSTALLLAST= + if test "x${prefix}" = "xNONE" ; then + FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}" + else + FRAMEWORKUNIXTOOLSPREFIX="${prefix}" + fi enable_framework= fi @@ -1914,6 +1938,9 @@ fi + + + ##AC_ARG_WITH(dyld, ## AC_HELP_STRING(--with-dyld, ## Use (OpenStep|Rhapsody) dynamic linker)) @@ -26168,9 +26195,9 @@ for ac_config_target in $ac_config_targets do case $ac_config_target in "pyconfig.h") CONFIG_HEADERS="$CONFIG_HEADERS pyconfig.h" ;; - "Mac/OSX/Makefile") CONFIG_FILES="$CONFIG_FILES Mac/OSX/Makefile" ;; - "Mac/OSX/PythonLauncher/Makefile") CONFIG_FILES="$CONFIG_FILES Mac/OSX/PythonLauncher/Makefile" ;; - "Mac/OSX/IDLE/Makefile") CONFIG_FILES="$CONFIG_FILES Mac/OSX/IDLE/Makefile" ;; + "Mac/Makefile") CONFIG_FILES="$CONFIG_FILES Mac/Makefile" ;; + "Mac/PythonLauncher/Makefile") CONFIG_FILES="$CONFIG_FILES Mac/PythonLauncher/Makefile" ;; + "Mac/IDLE/Makefile") CONFIG_FILES="$CONFIG_FILES Mac/IDLE/Makefile" ;; "Makefile.pre") CONFIG_FILES="$CONFIG_FILES Makefile.pre" ;; "Modules/Setup.config") CONFIG_FILES="$CONFIG_FILES Modules/Setup.config" ;; @@ -26281,6 +26308,9 @@ PYTHONFRAMEWORKPREFIX!$PYTHONFRAMEWORKPREFIX$ac_delim PYTHONFRAMEWORKINSTALLDIR!$PYTHONFRAMEWORKINSTALLDIR$ac_delim FRAMEWORKINSTALLFIRST!$FRAMEWORKINSTALLFIRST$ac_delim FRAMEWORKINSTALLLAST!$FRAMEWORKINSTALLLAST$ac_delim +FRAMEWORKALTINSTALLFIRST!$FRAMEWORKALTINSTALLFIRST$ac_delim +FRAMEWORKALTINSTALLLAST!$FRAMEWORKALTINSTALLLAST$ac_delim +FRAMEWORKUNIXTOOLSPREFIX!$FRAMEWORKUNIXTOOLSPREFIX$ac_delim MACHDEP!$MACHDEP$ac_delim SGI_ABI!$SGI_ABI$ac_delim EXTRAPLATDIR!$EXTRAPLATDIR$ac_delim @@ -26328,9 +26358,6 @@ CFLAGSFORSHARED!$CFLAGSFORSHARED$ac_delim SHLIBS!$SHLIBS$ac_delim USE_SIGNAL_MODULE!$USE_SIGNAL_MODULE$ac_delim SIGNAL_OBJS!$SIGNAL_OBJS$ac_delim -USE_THREAD_MODULE!$USE_THREAD_MODULE$ac_delim -LDLAST!$LDLAST$ac_delim -THREADOBJ!$THREADOBJ$ac_delim _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then @@ -26372,6 +26399,9 @@ _ACEOF ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF +USE_THREAD_MODULE!$USE_THREAD_MODULE$ac_delim +LDLAST!$LDLAST$ac_delim +THREADOBJ!$THREADOBJ$ac_delim DLINCLDIR!$DLINCLDIR$ac_delim DYNLOADFILE!$DYNLOADFILE$ac_delim MACHDEP_OBJS!$MACHDEP_OBJS$ac_delim @@ -26390,7 +26420,7 @@ SRCDIRS!$SRCDIRS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 16; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 19; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 diff --git a/configure.in b/configure.in index 6afc340..d9626f9 100644 --- a/configure.in +++ b/configure.in @@ -99,6 +99,13 @@ AC_ARG_ENABLE(framework, PYTHONFRAMEWORKINSTALLDIR= FRAMEWORKINSTALLFIRST= FRAMEWORKINSTALLLAST= + FRAMEWORKALTINSTALLFIRST= + FRAMEWORKALTINSTALLLAST= + if test "x${prefix}" = "xNONE"; then + FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}" + else + FRAMEWORKUNIXTOOLSPREFIX="${prefix}" + fi enable_framework= ;; *) @@ -108,13 +115,20 @@ AC_ARG_ENABLE(framework, PYTHONFRAMEWORKINSTALLDIR=$PYTHONFRAMEWORKPREFIX/$PYTHONFRAMEWORKDIR FRAMEWORKINSTALLFIRST="frameworkinstallstructure" FRAMEWORKINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools" + FRAMEWORKALTINSTALLFIRST="${FRAMEWORKINSTALLFIRST} bininstall maninstall" + FRAMEWORKALTINSTALLLAST="frameworkinstallmaclib frameworkinstallapps frameworkaltinstallunixtools" + if test "x${prefix}" = "xNONE" ; then + FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}" + else + FRAMEWORKUNIXTOOLSPREFIX="${prefix}" + fi prefix=$PYTHONFRAMEWORKINSTALLDIR/Versions/$VERSION # Add makefiles for Mac specific code to the list of output # files: - AC_CONFIG_FILES(Mac/OSX/Makefile) - AC_CONFIG_FILES(Mac/OSX/PythonLauncher/Makefile) - AC_CONFIG_FILES(Mac/OSX/IDLE/Makefile) + AC_CONFIG_FILES(Mac/Makefile) + AC_CONFIG_FILES(Mac/PythonLauncher/Makefile) + AC_CONFIG_FILES(Mac/IDLE/Makefile) esac ],[ PYTHONFRAMEWORK= @@ -123,6 +137,13 @@ AC_ARG_ENABLE(framework, PYTHONFRAMEWORKINSTALLDIR= FRAMEWORKINSTALLFIRST= FRAMEWORKINSTALLLAST= + FRAMEWORKALTINSTALLFIRST= + FRAMEWORKALTINSTALLLAST= + if test "x${prefix}" = "xNONE" ; then + FRAMEWORKUNIXTOOLSPREFIX="${ac_default_prefix}" + else + FRAMEWORKUNIXTOOLSPREFIX="${prefix}" + fi enable_framework= ]) AC_SUBST(PYTHONFRAMEWORK) @@ -131,6 +152,9 @@ AC_SUBST(PYTHONFRAMEWORKPREFIX) AC_SUBST(PYTHONFRAMEWORKINSTALLDIR) AC_SUBST(FRAMEWORKINSTALLFIRST) AC_SUBST(FRAMEWORKINSTALLLAST) +AC_SUBST(FRAMEWORKALTINSTALLFIRST) +AC_SUBST(FRAMEWORKALTINSTALLLAST) +AC_SUBST(FRAMEWORKUNIXTOOLSPREFIX) ##AC_ARG_WITH(dyld, ## AC_HELP_STRING(--with-dyld, diff --git a/setup.py b/setup.py index 9b2fac4..bd9b8b8 100644 --- a/setup.py +++ b/setup.py @@ -582,7 +582,9 @@ class PyBuildExt(build_ext): # The _md5 module implements the RSA Data Security, Inc. MD5 # Message-Digest Algorithm, described in RFC 1321. The # necessary files md5.c and md5.h are included here. - exts.append( Extension('_md5', ['md5module.c', 'md5.c']) ) + exts.append( Extension('_md5', + sources = ['md5module.c', 'md5.c'], + depends = ['md5.h']) ) if (openssl_ver < 0x00908000): # OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash @@ -1095,29 +1097,6 @@ class PyBuildExt(build_ext): extra_link_args=['-framework', 'QuickTime', '-framework', 'Carbon']) ) - # As there is no standardized place (yet) to put - # user-installed Mac libraries on OSX, we search for "waste" - # in parent directories of the Python source tree. You - # should put a symlink to your Waste installation in the - # same folder as your python source tree. Or modify the - # next few lines:-) - waste_incs = find_file("WASTE.h", [], - ['../'*n + 'waste/C_C++ Headers' for n in (0,1,2,3,4)]) - waste_libs = find_library_file(self.compiler, "WASTE", [], - ["../"*n + "waste/Static Libraries" for n in (0,1,2,3,4)]) - if waste_incs != None and waste_libs != None: - exts.append( Extension('waste', - ['waste/wastemodule.c'] + [ - os.path.join(srcdir, d) for d in - 'Mac/Wastemods/WEObjectHandlers.c', - 'Mac/Wastemods/WETabHooks.c', - 'Mac/Wastemods/WETabs.c' - ], - include_dirs = waste_incs + [os.path.join(srcdir, 'Mac/Wastemods')], - library_dirs = waste_libs, - libraries = ['WASTE'], - extra_link_args = ['-framework', 'Carbon'], - ) ) self.extensions.extend(exts) -- cgit v0.12