mirror of
https://github.com/python/cpython.git
synced 2024-11-26 03:14:27 +08:00
d8faa3654c
svn+ssh://pythondev@svn.python.org/python/trunk ........ r53954 | jeremy.hylton | 2007-02-26 10:41:18 -0800 (Mon, 26 Feb 2007) | 10 lines Do not copy free variables to locals in class namespaces. Fixes bug 1569356, but at the cost of a minor incompatibility in locals(). Add test that verifies that the class namespace is not polluted. Also clarify the behavior in the library docs. Along the way, cleaned up the dict_to_map and map_to_dict implementations and added some comments that explain what they do. ........ r53955 | jeremy.hylton | 2007-02-26 11:00:20 -0800 (Mon, 26 Feb 2007) | 2 lines Fix assertion. ........ r53969 | neal.norwitz | 2007-02-26 14:41:45 -0800 (Mon, 26 Feb 2007) | 3 lines When printing an unraisable error, don't print exceptions. before the name. This duplicates the behavior whening normally printing exceptions. ........ r53970 | andrew.kuchling | 2007-02-26 15:02:47 -0800 (Mon, 26 Feb 2007) | 1 line Markup fix ........ r53975 | neal.norwitz | 2007-02-26 15:48:27 -0800 (Mon, 26 Feb 2007) | 3 lines SF #1669182, 2.5 was already fixed. Just assert in 2.6 since string exceptions are gone. ........ r53976 | andrew.kuchling | 2007-02-26 15:54:17 -0800 (Mon, 26 Feb 2007) | 1 line Add some items ........ r53981 | jeremy.hylton | 2007-02-26 17:01:59 -0800 (Mon, 26 Feb 2007) | 4 lines Fix long-standing bug in name mangling for package imports Reported by Mike Verdone. ........ r53993 | jeremy.hylton | 2007-02-27 08:00:06 -0800 (Tue, 27 Feb 2007) | 2 lines tabify ........ r53994 | jeremy.hylton | 2007-02-27 08:13:23 -0800 (Tue, 27 Feb 2007) | 5 lines tabify Note that ast.c still has a mix of tabs and spaces, because it attempts to use four-space indents for more of the new code. ........ r53996 | jeremy.hylton | 2007-02-27 09:24:48 -0800 (Tue, 27 Feb 2007) | 2 lines whitespace normalization ........ r53997 | jeremy.hylton | 2007-02-27 10:29:45 -0800 (Tue, 27 Feb 2007) | 24 lines Add checking for a number of metaclass error conditions. We add some new rules that are required for preserving internal invariants of types. 1. If type (or a subclass of type) appears in bases, it must appear before any non-type bases. If a non-type base (like a regular new-style class) occurred first, it could trick type into allocating the new class an __dict__ which must be impossible. 2. There are several checks that are made of bases when creating a type. Those checks are now repeated when assigning to __bases__. We also add the restriction that assignment to __bases__ may not change the metaclass of the type. Add new tests for these cases and for a few other oddball errors that were no previously tested. Remove a crasher test that was fixed. Also some internal refactoring: Extract the code to find the most derived metaclass of a type and its bases. It is now needed in two places. Rewrite the TypeError checks in test_descr to use doctest. The tests now clearly show what exception they expect to see. ........ r53998 | jeremy.hylton | 2007-02-27 10:33:31 -0800 (Tue, 27 Feb 2007) | 2 lines Add news about changes to metaclasses and __bases__ error checking. ........ r54016 | armin.rigo | 2007-02-28 01:25:29 -0800 (Wed, 28 Feb 2007) | 3 lines Modify the segfaulting example to show why r53997 is not a solution to it. ........ r54022 | brett.cannon | 2007-02-28 10:15:00 -0800 (Wed, 28 Feb 2007) | 2 lines Add a test for instantiating SyntaxError with no arguments. ........ r54026 | raymond.hettinger | 2007-02-28 10:27:41 -0800 (Wed, 28 Feb 2007) | 1 line Docstring nit. ........ r54033 | raymond.hettinger | 2007-02-28 10:37:52 -0800 (Wed, 28 Feb 2007) | 1 line Prepare collections module for pure python code entries. ........ r54053 | raymond.hettinger | 2007-02-28 22:16:43 -0800 (Wed, 28 Feb 2007) | 1 line Add collections.NamedTuple ........ r54054 | neal.norwitz | 2007-02-28 23:04:41 -0800 (Wed, 28 Feb 2007) | 1 line Add Pat and Eric for work on PEP 3101 in the sandbox ........ r54061 | andrew.kuchling | 2007-03-01 06:36:12 -0800 (Thu, 01 Mar 2007) | 1 line Add NamedTuple ........ r54080 | georg.brandl | 2007-03-02 06:37:12 -0800 (Fri, 02 Mar 2007) | 2 lines Bug #1628895: some better tries to find HTML documentation in pydoc. ........ r54086 | raymond.hettinger | 2007-03-02 11:20:46 -0800 (Fri, 02 Mar 2007) | 1 line Fix embarrassing typo and fix constantification of None ........ r54088 | georg.brandl | 2007-03-02 12:30:14 -0800 (Fri, 02 Mar 2007) | 2 lines Bugs #1668032, #1668036, #1669304: clarify behavior of PyMem_Realloc and _Resize. ........ r54114 | georg.brandl | 2007-03-04 09:18:54 -0800 (Sun, 04 Mar 2007) | 2 lines Fix a bug in test_dict and test_userdict, found at the PyPy sprint. ........ r54124 | skip.montanaro | 2007-03-04 12:52:28 -0800 (Sun, 04 Mar 2007) | 2 lines Teach setup.py how to find Berkeley DB on Macs using MacPorts. ........ r54125 | skip.montanaro | 2007-03-04 12:54:12 -0800 (Sun, 04 Mar 2007) | 1 line note MacPorts/BerkDB change in setup.py ........ r54136 | neal.norwitz | 2007-03-04 23:52:01 -0800 (Sun, 04 Mar 2007) | 1 line Added Pete for 3101 too ........ r54138 | facundo.batista | 2007-03-05 08:31:54 -0800 (Mon, 05 Mar 2007) | 1 line Minor corrections to docs, and an explanation comentary ........ r54139 | georg.brandl | 2007-03-05 14:28:08 -0800 (Mon, 05 Mar 2007) | 3 lines Patch #1674228: when assigning a slice (old-style), check for the sq_ass_slice instead of the sq_slice slot. ........ r54149 | georg.brandl | 2007-03-06 01:33:01 -0800 (Tue, 06 Mar 2007) | 3 lines Nit: a struct field is set to GenericAlloc, not GenericAlloc(). ........ r54150 | georg.brandl | 2007-03-06 02:02:47 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1671450: add a section about subclassing builtin types to the "extending and embedding" tutorial. ........ r54152 | martin.v.loewis | 2007-03-06 02:41:24 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1121142: Implement ZipFile.open. ........ r54154 | georg.brandl | 2007-03-06 03:51:14 -0800 (Tue, 06 Mar 2007) | 2 lines A test case for the fix in #1674228. ........ r54156 | georg.brandl | 2007-03-06 03:52:24 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1672481: fix bug in idlelib.MultiCall. ........ r54159 | georg.brandl | 2007-03-06 04:17:50 -0800 (Tue, 06 Mar 2007) | 1 line Bug #1674503: close the file opened by execfile() in an error condition. ........ r54160 | georg.brandl | 2007-03-06 05:32:52 -0800 (Tue, 06 Mar 2007) | 3 lines Fix another reincarnation of bug #1576657 in defaultdict. ........ r54162 | georg.brandl | 2007-03-06 05:35:00 -0800 (Tue, 06 Mar 2007) | 2 lines A test case for the defaultdict KeyError bug. ........ r54164 | georg.brandl | 2007-03-06 05:37:45 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1663234: you can now run doctest on test files and modules using "python -m doctest [-v] filename ...". ........ r54165 | martin.v.loewis | 2007-03-06 06:43:00 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #912410: Replace HTML entity references for attribute values in HTMLParser. ........ r54166 | skip.montanaro | 2007-03-06 07:41:38 -0800 (Tue, 06 Mar 2007) | 1 line patch 1673619 - identify extension modules which cannot be built ........ r54167 | guido.van.rossum | 2007-03-06 07:50:01 -0800 (Tue, 06 Mar 2007) | 5 lines Patch #1646728: datetime.fromtimestamp fails with negative fractional times. With unittest. Somebody please backport to 2.5. ........ r54169 | georg.brandl | 2007-03-06 09:49:14 -0800 (Tue, 06 Mar 2007) | 2 lines Fix cmp vs. key argument for list.sort. ........ r54170 | georg.brandl | 2007-03-06 10:21:32 -0800 (Tue, 06 Mar 2007) | 2 lines Small nit, found by Neal. ........ r54171 | georg.brandl | 2007-03-06 10:29:58 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1602128: clarify that richcmp methods can return NotImplemented and should return True or False otherwise. ........ r54173 | georg.brandl | 2007-03-06 10:41:12 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1638879: don't accept strings with embedded NUL bytes in long(). ........ r54175 | georg.brandl | 2007-03-06 10:47:31 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #1673121: update README wrt. OSX default shell. ........ r54177 | georg.brandl | 2007-03-06 10:59:11 -0800 (Tue, 06 Mar 2007) | 3 lines Patch #1654417: make operator.{get,set,del}slice use the full range of Py_ssize_t. ........ r54180 | walter.doerwald | 2007-03-06 12:38:57 -0800 (Tue, 06 Mar 2007) | 4 lines Patch for bug #1633621: if curses.resizeterm() or curses.resize_term() is called, update _curses.LINES, _curses.COLS, curses.LINES and curses.COLS. ........ r54182 | walter.doerwald | 2007-03-06 13:15:24 -0800 (Tue, 06 Mar 2007) | 2 lines Document change to curses. ........ r54188 | georg.brandl | 2007-03-06 16:34:46 -0800 (Tue, 06 Mar 2007) | 5 lines Variant of patch #697613: don't exit the interpreter on a SystemExit exception if the -i command line option or PYTHONINSPECT environment variable is given, but break into the interactive interpreter just like on other exceptions or normal program exit. (backport) ........ r54189 | georg.brandl | 2007-03-06 16:40:28 -0800 (Tue, 06 Mar 2007) | 4 lines Patch #703779: unset __file__ in __main__ after running a file. This makes the filenames the warning module prints much more sensible when a PYTHONSTARTUP file is used. ........ r54192 | george.yoshida | 2007-03-06 20:21:18 -0800 (Tue, 06 Mar 2007) | 2 lines add versionadded info ........ r54195 | georg.brandl | 2007-03-06 23:39:06 -0800 (Tue, 06 Mar 2007) | 2 lines Patch #812285: allow multiple auth schemes in AbstractBasicAuthHandler. ........ r54197 | georg.brandl | 2007-03-07 00:31:51 -0800 (Wed, 07 Mar 2007) | 3 lines Patch #1001604: glob.glob() now returns unicode filenames if it was given a unicode argument and os.listdir() returns unicode filenames. ........ r54199 | georg.brandl | 2007-03-07 01:09:40 -0800 (Wed, 07 Mar 2007) | 3 lines Patches #1550273, #1550272: fix a few bugs in unittest and add a comprehensive test suite for the module. ........ r54201 | georg.brandl | 2007-03-07 01:21:06 -0800 (Wed, 07 Mar 2007) | 3 lines Patch #787789: allow to pass custom TestRunner instances to unittest's main() function. ........ r54202 | georg.brandl | 2007-03-07 01:34:45 -0800 (Wed, 07 Mar 2007) | 2 lines Patch #1669331: clarify shutil.copyfileobj() behavior wrt. file position. ........ r54204 | martin.v.loewis | 2007-03-07 03:04:33 -0800 (Wed, 07 Mar 2007) | 2 lines Bug #1115886: os.path.splitext('.cshrc') gives now ('.cshrc', ''). ........ r54206 | georg.brandl | 2007-03-07 03:37:42 -0800 (Wed, 07 Mar 2007) | 2 lines Patch #1675471: convert test_pty to unittest. ........ r54207 | georg.brandl | 2007-03-07 03:54:49 -0800 (Wed, 07 Mar 2007) | 4 lines Add some sanity checks to unittest.TestSuite's addTest(s) methods. Fixes #878275. ........ r54209 | guido.van.rossum | 2007-03-07 07:16:29 -0800 (Wed, 07 Mar 2007) | 3 lines Windows doesn't support negative timestamps. Skip the tests involving them if os.name == "nt". ........ r54219 | martin.v.loewis | 2007-03-08 05:42:43 -0800 (Thu, 08 Mar 2007) | 2 lines Add missing ) in parenthical remark. ........ r54220 | georg.brandl | 2007-03-08 09:49:06 -0800 (Thu, 08 Mar 2007) | 2 lines Fix #1676656: \em is different from \emph... ........ r54222 | georg.brandl | 2007-03-08 10:37:31 -0800 (Thu, 08 Mar 2007) | 2 lines Add a NEWS entry for rev. 54207,8. ........ r54225 | raymond.hettinger | 2007-03-08 11:24:27 -0800 (Thu, 08 Mar 2007) | 1 line SF 1676321: empty() returned wrong result ........ r54227 | collin.winter | 2007-03-08 11:58:14 -0800 (Thu, 08 Mar 2007) | 1 line Backported r54226 from p3yk: Move test_unittest, test_doctest and test_doctest2 higher up in the testing order. ........ r54230 | raymond.hettinger | 2007-03-08 13:33:47 -0800 (Thu, 08 Mar 2007) | 1 line SF #1637850: make_table in difflib did not work with unicode ........ r54232 | collin.winter | 2007-03-08 14:16:25 -0800 (Thu, 08 Mar 2007) | 1 line Patch #1668482: don't use '-' in mkstemp ........ r54233 | brett.cannon | 2007-03-08 15:58:11 -0800 (Thu, 08 Mar 2007) | 10 lines Introduce test.test_support.TransientResource. It's a context manager to surround calls to resources that may or may not be available. Specifying the expected exception and attributes to be raised if the resource is not available prevents overly broad catching of exceptions. This is meant to help suppress spurious failures by raising test.test_support.ResourceDenied if the exception matches. It would probably be good to go through the various network tests and surround the calls to catch connection timeouts (as done with test_socket_ssl in this commit). ........ r54234 | collin.winter | 2007-03-08 19:15:56 -0800 (Thu, 08 Mar 2007) | 1 line Patch #1481079: Support of HTTP_REFERER in CGIHTTPServer.py ........ r54235 | collin.winter | 2007-03-08 19:26:32 -0800 (Thu, 08 Mar 2007) | 1 line Add NEWS item for patch #1481079 (r54234). ........ r54237 | neal.norwitz | 2007-03-08 21:59:01 -0800 (Thu, 08 Mar 2007) | 1 line Fix SF #1676971, Complex OverflowError has a typo ........ r54239 | georg.brandl | 2007-03-09 04:58:41 -0800 (Fri, 09 Mar 2007) | 2 lines Typo. ........ r54240 | martin.v.loewis | 2007-03-09 07:35:55 -0800 (Fri, 09 Mar 2007) | 2 lines Patch #957003: Implement smtplib.LMTP. ........ r54243 | collin.winter | 2007-03-09 10:09:10 -0800 (Fri, 09 Mar 2007) | 2 lines Bug #1629566: clarify the docs on the return values of parsedate() and parsedate_tz() in email.utils and rfc822. ........ r54244 | thomas.heller | 2007-03-09 11:21:28 -0800 (Fri, 09 Mar 2007) | 3 lines Fix bug #1646630: ctypes.string_at(buf, 0) and ctypes.wstring_at(buf, 0) returned string up to the first NUL character. ........ r54245 | martin.v.loewis | 2007-03-09 11:36:01 -0800 (Fri, 09 Mar 2007) | 2 lines Add Ziga Seilnacht. ........ r54247 | collin.winter | 2007-03-09 12:33:07 -0800 (Fri, 09 Mar 2007) | 2 lines Patch #1491866: change the complex() constructor to allow parthensized forms. This means complex(repr(x)) now works instead of raising a ValueError. ........ r54248 | thomas.heller | 2007-03-09 12:39:22 -0800 (Fri, 09 Mar 2007) | 7 lines Bug #1651235: When a tuple was passed to a ctypes function call, Python would crash instead of raising an error. The crash was caused by a section of code that should have been removed long ago, at that time ctypes had other ways to pass parameters to function calls. ........ r54250 | collin.winter | 2007-03-09 15:30:39 -0800 (Fri, 09 Mar 2007) | 1 line Hashing simplification pointed out by Thomas Wouters. ........ r54252 | collin.winter | 2007-03-09 18:23:40 -0800 (Fri, 09 Mar 2007) | 5 lines * Unlink test files before and after each test; hopefully this will cut down on recent buildbot failures in test_islink. * Drop safe_remove() in favor of test_support.unlink(). * Fix the indentation of test_samefile so that it runs. ........ r54253 | collin.winter | 2007-03-09 18:51:26 -0800 (Fri, 09 Mar 2007) | 3 lines Bug #1531963: Make SocketServer.TCPServer's server_address always be equal to calling getsockname() on the server's socket. Will backport. ........ r54254 | neal.norwitz | 2007-03-09 19:19:18 -0800 (Fri, 09 Mar 2007) | 4 lines Simplify a little by handling the TCP case first. Update to use predominant style of spaces around = in args list and print to stderr if debugging. ........ r54256 | collin.winter | 2007-03-09 19:35:34 -0800 (Fri, 09 Mar 2007) | 1 line Add proper attribution for a bug fix. ........ r54257 | georg.brandl | 2007-03-09 23:38:14 -0800 (Fri, 09 Mar 2007) | 2 lines Typos. ........ r54260 | collin.winter | 2007-03-10 06:33:32 -0800 (Sat, 10 Mar 2007) | 1 line Convert an assert to a raise so it works even in the presence of -O. ........ r54262 | collin.winter | 2007-03-10 06:41:48 -0800 (Sat, 10 Mar 2007) | 2 lines Patch #1599845: Add an option to disable the implicit calls to server_bind() and server_activate() in the constructors for TCPServer, SimpleXMLRPCServer and DocXMLRPCServer. ........ r54268 | georg.brandl | 2007-03-11 00:28:46 -0800 (Sun, 11 Mar 2007) | 2 lines Add missing "return" statements in exception handler. ........ r54270 | ziga.seilnacht | 2007-03-11 08:54:54 -0700 (Sun, 11 Mar 2007) | 3 lines Patch #1675981: remove unreachable code from type.__new__() method. __dict__ and __weakref__ are removed from the slots tuple earlier in the code, in the loop that mangles slot names. Will backport. ........ r54271 | collin.winter | 2007-03-11 09:00:20 -0700 (Sun, 11 Mar 2007) | 3 lines Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number. Will backport. ........ r54274 | vinay.sajip | 2007-03-11 11:32:07 -0700 (Sun, 11 Mar 2007) | 1 line Fix resource leak reported in SF #1516995. ........ r54278 | collin.winter | 2007-03-11 18:55:54 -0700 (Sun, 11 Mar 2007) | 4 lines Patch #1678662: ftp.python.org does not exist. So the testcode in urllib.py must use a more stable FTP. Will backport. ........ r54280 | barry.warsaw | 2007-03-11 20:20:01 -0700 (Sun, 11 Mar 2007) | 8 lines Tokio Kikuchi's fix for SF bug #1629369; folding whitespace allowed in the display name of an email address, e.g. Foo \tBar <foo@example.com> Test case added by Barry. ........ r54282 | skip.montanaro | 2007-03-11 20:30:50 -0700 (Sun, 11 Mar 2007) | 4 lines Sane humans would call these invalid tests, but Andrew McNamara pointed out that given the inputs in these tests Excel does indeed produce the output these tests expect. Document that for future confused folks. ........ r54283 | martin.v.loewis | 2007-03-12 03:50:39 -0700 (Mon, 12 Mar 2007) | 2 lines Bug #1675511: Use -Kpic instead of -xcode=pic32 on Solaris/x86. ........ r54285 | martin.v.loewis | 2007-03-12 04:01:10 -0700 (Mon, 12 Mar 2007) | 2 lines Patch #1677862: Require a space or tab after import in .pth files. ........ r54287 | georg.brandl | 2007-03-12 06:17:36 -0700 (Mon, 12 Mar 2007) | 8 lines Backport from Py3k branch: Patch #1591665: implement the __dir__() special function lookup in PyObject_Dir. Had to change a few bits of the patch because classobjs and __methods__ are still in Py2.6. ........ r54288 | georg.brandl | 2007-03-12 07:30:05 -0700 (Mon, 12 Mar 2007) | 3 lines Bug #1678647: write a newline after printing an exception in any case, even when converting the value to a string failed. ........ r54290 | collin.winter | 2007-03-12 08:57:19 -0700 (Mon, 12 Mar 2007) | 1 line Patch #1678088: convert test_operations to use unittest, fold the result into test_dict. ........ r54291 | collin.winter | 2007-03-12 09:11:39 -0700 (Mon, 12 Mar 2007) | 3 lines Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167. Will backport. ........ r54292 | georg.brandl | 2007-03-12 09:15:09 -0700 (Mon, 12 Mar 2007) | 2 lines Typo fix. ........ r54295 | collin.winter | 2007-03-12 10:24:07 -0700 (Mon, 12 Mar 2007) | 1 line Patch #1670993: Refactor test_threadedtempfile.py to use unittest. ........ r54296 | tim.peters | 2007-03-12 11:07:52 -0700 (Mon, 12 Mar 2007) | 2 lines Whitespace normalization. ........ r54297 | tim.peters | 2007-03-12 11:09:22 -0700 (Mon, 12 Mar 2007) | 2 lines Set missing svn:eol-style property on text files. ........ r54315 | brett.cannon | 2007-03-12 19:34:09 -0700 (Mon, 12 Mar 2007) | 8 lines Add test.test_support.transient_internet . Returns a context manager that nests test.test_support.TransientResource context managers that capture exceptions raised when the Internet connection is flaky. Initially using in test_socket_ssl but should probably be expanded to cover any test that should not raise the captured exceptions if the Internet connection works. ........ r54316 | brett.cannon | 2007-03-12 20:05:40 -0700 (Mon, 12 Mar 2007) | 2 lines Fix a typo where the variable name was not updated. ........ r54318 | neal.norwitz | 2007-03-12 21:59:58 -0700 (Mon, 12 Mar 2007) | 1 line Add Jerry Seutter for a bunch of his recent patches refactoring tests ........ r54319 | neal.norwitz | 2007-03-12 22:07:14 -0700 (Mon, 12 Mar 2007) | 7 lines Add some other acks for recent checkins: Brian Leair - 922167 Tomer Filiba - 1591665 Jeremy Jones - 1192590 ........ r54321 | neal.norwitz | 2007-03-12 22:31:38 -0700 (Mon, 12 Mar 2007) | 9 lines Fix some style nits: * lines too long * wrong indentation * space after a function name * wrong function name in error string * simplifying some logic Also add an error check to PyDict_SetItemString. ........ r54322 | georg.brandl | 2007-03-13 00:23:16 -0700 (Tue, 13 Mar 2007) | 2 lines Typo and grammar fixes. ........ r54323 | georg.brandl | 2007-03-13 00:50:57 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1679379: add documentation for fnmatch.translate(). ........ r54325 | georg.brandl | 2007-03-13 00:57:51 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1642844: comments to clarify the complexobject constructor. ........ r54326 | georg.brandl | 2007-03-13 01:14:27 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1668100: urllib2 now correctly raises URLError instead of OSError if accessing a local file via the file:// protocol fails. ........ r54327 | georg.brandl | 2007-03-13 02:32:11 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1635454: the csv.DictWriter class now includes the offending field names in its exception message if you try to write a record with a dictionary containing fields not in the CSV field names list. ........ r54328 | georg.brandl | 2007-03-13 02:41:31 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1555098: use str.join() instead of repeated string concatenation in robotparser. ........ r54329 | georg.brandl | 2007-03-13 03:06:48 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to pydoc's help keywords. ........ r54331 | georg.brandl | 2007-03-13 03:19:22 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1569798: fix a bug in distutils when building Python from a directory within sys.exec_prefix. ........ r54333 | martin.v.loewis | 2007-03-13 03:24:00 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1449244: Support Unicode strings in email.message.Message.{set_charset,get_content_charset}. Will backport. ........ r54335 | lars.gustaebel | 2007-03-13 03:47:19 -0700 (Tue, 13 Mar 2007) | 34 lines This is the implementation of POSIX.1-2001 (pax) format read/write support. The TarInfo class now contains all necessary logic to process and create tar header data which has been moved there from the TarFile class. The fromtarfile() method was added. The new path and linkpath properties are aliases for the name and linkname attributes in correspondence to the pax naming scheme. The TarFile constructor and classmethods now accept a number of keyword arguments which could only be set as attributes before (e.g. dereference, ignore_zeros). The encoding and pax_headers arguments were added for pax support. There is a new tarinfo keyword argument that allows using subclassed TarInfo objects in TarFile. The boolean TarFile.posix attribute is deprecated, because now three tar formats are supported. Instead, the desired format for writing is specified using the constants USTAR_FORMAT, GNU_FORMAT and PAX_FORMAT as the format keyword argument. This change affects TarInfo.tobuf() as well. The test suite has been heavily reorganized and partially rewritten. A new testtar.tar was added that contains sample data in many formats from 4 different tar programs. Some bugs and quirks that also have been fixed: Directory names do no longer have a trailing slash in TarInfo.name or TarFile.getnames(). Adding the same file twice does not create a hardlink file member. The TarFile constructor does no longer need a name argument. The TarFile._mode attribute was renamed to mode and contains either 'r', 'w' or 'a'. ........ r54336 | georg.brandl | 2007-03-13 05:34:25 -0700 (Tue, 13 Mar 2007) | 3 lines Bug #1622896: fix a rare corner case where the bz2 module raised an error in spite of a succesful compression. ........ r54338 | lars.gustaebel | 2007-03-13 08:47:07 -0700 (Tue, 13 Mar 2007) | 3 lines Quick fix for tests that fail on systems with an encoding other than 'iso8859-1'. ........ r54339 | georg.brandl | 2007-03-13 10:43:32 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1603688: ConfigParser.SafeConfigParser now checks values that are set for invalid interpolation sequences that would lead to errors on reading back those values. ........ r54341 | georg.brandl | 2007-03-13 11:15:41 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1581073: add a flag to textwrap that prevents the dropping of whitespace while wrapping. ........ r54343 | georg.brandl | 2007-03-13 11:24:40 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1605192: list allowed states in error messages for imaplib. ........ r54344 | georg.brandl | 2007-03-13 11:31:49 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1537850: tempfile.NamedTemporaryFile now has a "delete" parameter which can be set to False to prevent the default delete-on-close behavior. ........ r54345 | collin.winter | 2007-03-13 11:53:04 -0700 (Tue, 13 Mar 2007) | 9 lines Add acks for recent patch checkins: Arvin Schnell - 1668482 S?\195?\169bastien Martini - 1481079 Heiko Wundram - 1491866 Damon Kohler - 1545011 Peter Parente - 1599845 Bjorn Lindqvist - 1678662 ........ r54346 | georg.brandl | 2007-03-13 12:00:36 -0700 (Tue, 13 Mar 2007) | 2 lines Acks for recent patches. ........ r54347 | georg.brandl | 2007-03-13 12:18:18 -0700 (Tue, 13 Mar 2007) | 3 lines Fix a tab. ........ r54348 | georg.brandl | 2007-03-13 12:32:21 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1533909: the timeit module now accepts callables in addition to strings for the code to time and the setup code. Also added two convenience functions for instantiating a Timer and calling its methods. ........ r54352 | georg.brandl | 2007-03-13 13:02:57 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1530482: add pydoc.render_doc() which returns the documentation for a thing instead of paging it to stdout, which pydoc.doc() does. ........ r54357 | thomas.heller | 2007-03-13 13:42:52 -0700 (Tue, 13 Mar 2007) | 1 line Patch #1649190: Adding support for _Bool to ctypes as c_bool, by David Remahl. ........ r54358 | georg.brandl | 2007-03-13 13:46:32 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1444529: the builtin compile() now accepts keyword arguments. (backport) ........ r54359 | thomas.heller | 2007-03-13 14:01:39 -0700 (Tue, 13 Mar 2007) | 1 line Add versionadded marker for ctypes.c_bool. ........ r54360 | georg.brandl | 2007-03-13 14:08:15 -0700 (Tue, 13 Mar 2007) | 3 lines Patch #1393667: pdb now has a "run" command which restarts the debugged Python program, optionally with different arguments. ........ r54361 | georg.brandl | 2007-03-13 14:32:01 -0700 (Tue, 13 Mar 2007) | 3 lines Deprecate commands.getstatus(). ........ r54362 | georg.brandl | 2007-03-13 14:32:56 -0700 (Tue, 13 Mar 2007) | 2 lines NEWS entry for getstatus() deprecation. ........ r54363 | georg.brandl | 2007-03-13 14:58:44 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #1429539: pdb now correctly initializes the __main__ module for the debugged script, which means that imports from __main__ work correctly now. ........ r54364 | georg.brandl | 2007-03-13 15:07:36 -0700 (Tue, 13 Mar 2007) | 4 lines Patch #957650: "%var%" environment variable references are now properly expanded in ntpath.expandvars(), also "~user" home directory references are recognized and handled on Windows. ........ r54365 | georg.brandl | 2007-03-13 15:16:30 -0700 (Tue, 13 Mar 2007) | 2 lines Patch #1194449: correctly detect unbound methods in pydoc. ........ r54367 | georg.brandl | 2007-03-13 15:49:43 -0700 (Tue, 13 Mar 2007) | 5 lines Patch #1185447: binascii.b2a_qp() now correctly quotes binary characters with ASCII value less than 32. Also, it correctly quotes dots only if they occur on a single line, as opposed to the previous behavior of quoting dots if they are the second character of any line. ........ r54368 | collin.winter | 2007-03-13 16:02:15 -0700 (Tue, 13 Mar 2007) | 1 line Inline PyImport_GetModulesReloading(). ........ r54371 | barry.warsaw | 2007-03-13 21:59:50 -0700 (Tue, 13 Mar 2007) | 6 lines SF bug #1582282; decode_header() incorrectly splits not-conformant RFC 2047-like headers where there is no whitespace between encoded words. This fix changes the matching regexp to include a trailing lookahead assertion that the closing ?= must be followed by whitespace, newline, or end-of-string. This also changes the regexp to add the MULTILINE flag. ........ r54372 | gregory.p.smith | 2007-03-14 00:17:40 -0700 (Wed, 14 Mar 2007) | 2 lines correct order and names of the less often used keyword parameters. ........ r54373 | gregory.p.smith | 2007-03-14 00:19:50 -0700 (Wed, 14 Mar 2007) | 5 lines Its time to stop listing (Unix, Windows) when we really mean "everything but Mac OS 9" now that nobody is likely to use Python on Mac OS 9 and most of the (Mac) platform items are all OS X special API specific since OS X is unixy enough for these modules to be available out of the box. ........ r54376 | georg.brandl | 2007-03-14 01:27:52 -0700 (Wed, 14 Mar 2007) | 4 lines Bug #767111: fix long-standing bug in urllib which caused an AttributeError instead of an IOError when the server's response didn't contain a valid HTTP status line. ........ r54378 | ziga.seilnacht | 2007-03-14 05:24:09 -0700 (Wed, 14 Mar 2007) | 4 lines Patch #1680015: Don't modify __slots__ tuple if it contains an unicode name. Remove a reference leak that happened if the name could not be converted to string. Will backport. ........ r54386 | martin.v.loewis | 2007-03-14 13:02:31 -0700 (Wed, 14 Mar 2007) | 3 lines Patch #1559413: Fix test_cmd_line if sys.executable contains a space. Will backport. ........ r54389 | brett.cannon | 2007-03-14 14:40:13 -0700 (Wed, 14 Mar 2007) | 3 lines Note how test_socket_ssl has various exceptions that deal with a flaky Net connection are silenced. ........ r54390 | brett.cannon | 2007-03-14 14:44:15 -0700 (Wed, 14 Mar 2007) | 2 lines Raise ResourceDenied in test_urllib2net when the Net connection goes bad. ........ r54391 | neal.norwitz | 2007-03-14 21:41:20 -0700 (Wed, 14 Mar 2007) | 1 line Wrap a long line and fix a typo (is -> if) ........ r54392 | georg.brandl | 2007-03-15 00:38:14 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1680978: consistently use "alive" instead of "active" in the thread lib doc. ........ r54394 | georg.brandl | 2007-03-15 00:41:30 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1681153: the wave module now closes a file object it opened if initialization failed. ........ r54397 | ziga.seilnacht | 2007-03-15 04:44:55 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1462488: prevent a segfault in object_reduce_ex() by splitting the implementation for __reduce__ and __reduce_ex__ into two separate functions. Fixes bug #931877. Will backport. ........ r54404 | collin.winter | 2007-03-15 21:11:30 -0700 (Thu, 15 Mar 2007) | 3 lines Patch #1642547: Fix an error/crash when encountering syntax errors in complex if statements. Will backport. ........ r54406 | georg.brandl | 2007-03-16 00:55:09 -0700 (Fri, 16 Mar 2007) | 5 lines Bug #1681228: the webbrowser module now correctly uses the default GNOME or KDE browser, depending on whether there is a session of one of those present. Also, it tries the Windows default browser before trying Mozilla variants. (backport) ........ r54407 | georg.brandl | 2007-03-16 01:22:40 -0700 (Fri, 16 Mar 2007) | 4 lines Patch #1273829: os.walk() now has a "followlinks" parameter. If set to True (which is not the default), it visits symlinks pointing to directories. ........ r54408 | georg.brandl | 2007-03-16 01:24:21 -0700 (Fri, 16 Mar 2007) | 2 lines Add \versionadded tag. ........ r54409 | georg.brandl | 2007-03-16 01:33:47 -0700 (Fri, 16 Mar 2007) | 2 lines RFE #1670167: fix in isinstance() docs. ........ r54412 | ziga.seilnacht | 2007-03-16 04:59:38 -0700 (Fri, 16 Mar 2007) | 3 lines Patch #1623563: allow __class__ assignment for classes with __slots__. The old and the new class are still required to have the same slot names, but the order in which they are specified is not relevant. ........ r54413 | ziga.seilnacht | 2007-03-16 05:11:11 -0700 (Fri, 16 Mar 2007) | 2 lines Whitespace cleanup. Also remove the empty lines from the previous check in. ........ r54414 | jeremy.hylton | 2007-03-16 07:49:11 -0700 (Fri, 16 Mar 2007) | 2 lines Remove warning: funcion declaration isn't a prototype ........ r54415 | jeremy.hylton | 2007-03-16 08:59:47 -0700 (Fri, 16 Mar 2007) | 11 lines Clean up formatting of this file. The file should now follow PEP 7, except that it uses 4 space indents (in the style of Py3k). This particular code would be really hard to read with the regular tab idents. Other changes: - reflow long lines - change multi-line conditionals to have test at end of line ........ r54417 | collin.winter | 2007-03-16 14:13:35 -0700 (Fri, 16 Mar 2007) | 1 line Patch #1676994: Refactor test_popen2 to use unittest. ........ r54418 | collin.winter | 2007-03-16 14:15:35 -0700 (Fri, 16 Mar 2007) | 1 line Remove test/output/test_popen2 (missed in r54417). ........ r54419 | collin.winter | 2007-03-16 15:16:08 -0700 (Fri, 16 Mar 2007) | 1 line Patch 1339796: add a relpath() function to os.path. ........ r54421 | georg.brandl | 2007-03-17 09:08:45 -0700 (Sat, 17 Mar 2007) | 5 lines Patch #1675423: PyComplex_AsCComplex() now tries to convert an object to complex using its __complex__() method before falling back to the __float__() method. Therefore, the functions in the cmath module now can operate on objects that define a __complex__() method. (backport) ........ r54423 | gregory.p.smith | 2007-03-17 15:33:35 -0700 (Sat, 17 Mar 2007) | 2 lines move note to the correct section ........ r54426 | georg.brandl | 2007-03-18 01:25:00 -0700 (Sun, 18 Mar 2007) | 2 lines Patch #1682878: the new socket methods are recv_into and recvfrom_into, not *_buf. ........ r54432 | georg.brandl | 2007-03-18 11:28:25 -0700 (Sun, 18 Mar 2007) | 2 lines Patch #1678339: test case for bug in difflib. ........ r54439 | collin.winter | 2007-03-19 11:52:08 -0700 (Mon, 19 Mar 2007) | 1 line Patch #1630118: add a SpooledTemporaryFile class to tempfile. ........ r54441 | georg.brandl | 2007-03-19 12:02:48 -0700 (Mon, 19 Mar 2007) | 2 lines Patch #1683328: fixes and enhancements for "unparse" demo. ........ r54456 | neal.norwitz | 2007-03-19 22:07:28 -0700 (Mon, 19 Mar 2007) | 1 line Add some doc that was left out from some change to platform.py ........ r54457 | neal.norwitz | 2007-03-19 22:08:23 -0700 (Mon, 19 Mar 2007) | 1 line Add a comment about 3k migration ........ r54458 | neal.norwitz | 2007-03-19 22:21:21 -0700 (Mon, 19 Mar 2007) | 1 line Get rid of deprecation warning when testing commands.getstatus() ........ r54459 | neal.norwitz | 2007-03-19 22:23:09 -0700 (Mon, 19 Mar 2007) | 4 lines Try backing out 54407 to see if it corrects the problems on the Windows buildbots. This rev was backported, so we will need to keep both branches in sync, pending the outcome of the test after this checkin. ........ r54460 | neal.norwitz | 2007-03-19 23:13:25 -0700 (Mon, 19 Mar 2007) | 1 line Try to make this test more resistant to dropping from previous runs (ie, files that may exist but cause the test to fail). Should be backported (assuming it works :-) ........ r54461 | neal.norwitz | 2007-03-19 23:16:26 -0700 (Mon, 19 Mar 2007) | 1 line Try to make this test more resistant to dropping from previous runs (ie, files that may exist but cause the test to fail). Should be backported (assuming it works :-) ........ r54462 | neal.norwitz | 2007-03-19 23:53:17 -0700 (Mon, 19 Mar 2007) | 5 lines Try to be a little more resilient to errors. This might help the test pass, but my guess is that it won't. I'm guessing that some other test is leaving this file open which means it can't be removed under Windows AFAIK. ........ r54463 | neal.norwitz | 2007-03-20 01:14:57 -0700 (Tue, 20 Mar 2007) | 8 lines Try to get test_urllib to pass on Windows by closing the file. I'm guessing that's the problem. h.getfile() must be called *after* h.getreply() and the fp can be None. I'm not entirely convinced this is the best fix (or even correct). The buildbots will tell us if things improve or not. I don't know if this needs to be backported (assuming it actually works). ........ r54465 | raymond.hettinger | 2007-03-20 14:27:24 -0700 (Tue, 20 Mar 2007) | 1 line Extend work on rev 52962 and 53829 eliminating redundant PyObject_Hash() calls and fixing set/dict interoperability. ........ r54468 | georg.brandl | 2007-03-20 16:05:14 -0700 (Tue, 20 Mar 2007) | 2 lines Fix for glob.py if filesystem encoding is None. ........ r54479 | neal.norwitz | 2007-03-20 23:39:48 -0700 (Tue, 20 Mar 2007) | 1 line Remove unused file spotted by Paul Hankin ........ r54480 | georg.brandl | 2007-03-21 02:00:39 -0700 (Wed, 21 Mar 2007) | 3 lines Patch #1682205: a TypeError while unpacking an iterable is no longer masked by a generic one with the message "unpack non-sequence". ........ r54482 | georg.brandl | 2007-03-21 02:10:29 -0700 (Wed, 21 Mar 2007) | 2 lines New test for rev. 54407 which only uses directories under TESTFN. ........ r54483 | georg.brandl | 2007-03-21 02:16:53 -0700 (Wed, 21 Mar 2007) | 2 lines Patch #1684834: document some utility C API functions. ........ r54485 | georg.brandl | 2007-03-21 04:51:25 -0700 (Wed, 21 Mar 2007) | 2 lines Fix #1684254: split BROWSER contents with shlex to avoid displaying 'URL'. ........ r54487 | andrew.kuchling | 2007-03-21 07:32:43 -0700 (Wed, 21 Mar 2007) | 1 line Add comments on maintenance of this file ........ r54489 | andrew.kuchling | 2007-03-21 09:57:32 -0700 (Wed, 21 Mar 2007) | 1 line Fix sentence, and fix typo in example ........ r54490 | andrew.kuchling | 2007-03-21 09:59:20 -0700 (Wed, 21 Mar 2007) | 1 line Put code examples at left margin instead of indenting them ........ r54491 | facundo.batista | 2007-03-21 12:41:24 -0700 (Wed, 21 Mar 2007) | 1 line Minor clarification, saying that blocking means no timeout (from bug #882297) ........ r54492 | ziga.seilnacht | 2007-03-21 13:07:56 -0700 (Wed, 21 Mar 2007) | 2 lines Bug #1675967: re patterns pickled with older Python versions can now be unpickled. Will backport. ........ r54495 | raymond.hettinger | 2007-03-21 13:33:57 -0700 (Wed, 21 Mar 2007) | 1 line Add test and fix for fromkeys() optional argument. ........ r54524 | georg.brandl | 2007-03-22 01:05:45 -0700 (Thu, 22 Mar 2007) | 2 lines Bug #1685704: use -m switch in timeit docs. ........ r54533 | thomas.heller | 2007-03-22 12:44:31 -0700 (Thu, 22 Mar 2007) | 5 lines Back out "Patch #1643874: memory leak in ctypes fixed." The code in this patch leaves no way to give up the ownership of a BSTR instance. ........ r54538 | thomas.heller | 2007-03-22 13:34:37 -0700 (Thu, 22 Mar 2007) | 2 lines Explain the purpose of the b_needsfree flag (forward ported from release25-maint). ........ r54539 | guido.van.rossum | 2007-03-22 21:58:42 -0700 (Thu, 22 Mar 2007) | 12 lines - Bug #1683368: The object.__init__() and object.__new__() methods are now stricter in rejecting excess arguments. The only time when either allows excess arguments is when it is not overridden and the other one is. For backwards compatibility, when both are overridden, it is a deprecation warning (for now; maybe a Py3k warning later). When merging this into 3.0, the warnings should become errors. Note: without the change to string.py, lots of spurious warnings happen. What's going on there? ........ r54540 | neal.norwitz | 2007-03-22 22:17:23 -0700 (Thu, 22 Mar 2007) | 1 line Add Mark Dickinson for SF # 1675423. ........ r54541 | martin.v.loewis | 2007-03-23 03:35:49 -0700 (Fri, 23 Mar 2007) | 3 lines Patch #1686451: Fix return type for PySequence_{Count,Index,Fast_GET_SIZE}. Will backport. ........ r54543 | martin.v.loewis | 2007-03-23 06:27:15 -0700 (Fri, 23 Mar 2007) | 3 lines Bug #978833: Revert r50844, as it broke _socketobject.dup. Will backport. ........ r54545 | guido.van.rossum | 2007-03-23 11:53:03 -0700 (Fri, 23 Mar 2007) | 8 lines Add a type.__init__() method that enforces the same signature as type.__new__(), and then calls object.__init__(cls), just to be anal. This allows us to restore the code in string.py's _TemplateMetaclass that called super(...).__init__(name, bases, dct), which I commented out yesterday since it broke due to the stricter argument checking added to object.__init__(). ........ r54546 | facundo.batista | 2007-03-23 11:54:07 -0700 (Fri, 23 Mar 2007) | 4 lines Added a 'create_connect()' function to socket.py, which creates a connection with an optional timeout, and modified httplib.py to use this function in HTTPConnection. Applies patch 1676823. ........ r54547 | guido.van.rossum | 2007-03-23 12:39:01 -0700 (Fri, 23 Mar 2007) | 2 lines Add note about type.__init__(). ........ r54553 | thomas.heller | 2007-03-23 12:55:27 -0700 (Fri, 23 Mar 2007) | 5 lines Prevent creation (followed by a segfault) of array types when the size overflows the valid Py_ssize_t range. Check return values of PyMem_Malloc. Will backport to release25-maint. ........ r54555 | facundo.batista | 2007-03-23 13:23:08 -0700 (Fri, 23 Mar 2007) | 6 lines Surrounded with try/finally to socket's default timeout setting changes in the tests, so failing one test won't produce strange results in others. Also relaxed the timeout settings in the test (where actually the value didn't mean anything). ........ r54556 | collin.winter | 2007-03-23 15:24:39 -0700 (Fri, 23 Mar 2007) | 1 line Make test_relpath() pass on Windows. ........ r54559 | ziga.seilnacht | 2007-03-24 07:24:26 -0700 (Sat, 24 Mar 2007) | 6 lines Patch #1489771: update syntax rules in Python Reference Manual. Python 2.5 added support for explicit relative import statements and yield expressions, which were missing in the manual. Also fix grammar productions that used the names from the Grammar file, markup that broke the generated grammar.txt, and wrap some lines that broke the pdf output. Will backport. ........ r54565 | georg.brandl | 2007-03-24 15:20:34 -0700 (Sat, 24 Mar 2007) | 2 lines Remove typo accent. ........ r54566 | georg.brandl | 2007-03-24 15:27:56 -0700 (Sat, 24 Mar 2007) | 2 lines Revert accidental change. ........ r54567 | brett.cannon | 2007-03-24 18:32:36 -0700 (Sat, 24 Mar 2007) | 3 lines Change the docs to no longer claim that unittest is preferred over doctest for regression tests. ........ r54568 | facundo.batista | 2007-03-24 18:53:21 -0700 (Sat, 24 Mar 2007) | 4 lines Redone the tests, using the infrastructure already present for threading and socket serving. ........ r54570 | facundo.batista | 2007-03-24 20:20:05 -0700 (Sat, 24 Mar 2007) | 3 lines Closing the HTTP connection after each test, and listening more. ........ r54572 | georg.brandl | 2007-03-25 11:44:35 -0700 (Sun, 25 Mar 2007) | 2 lines Markup fix. ........ r54573 | georg.brandl | 2007-03-25 12:04:55 -0700 (Sun, 25 Mar 2007) | 2 lines Markup fix. ........ r54580 | facundo.batista | 2007-03-26 13:18:31 -0700 (Mon, 26 Mar 2007) | 5 lines Added an optional timeout to FTP class. Also I started a test_ftplib.py file to test the ftp lib (right now I included a basic test, the timeout one, and nothing else). ........ r54581 | georg.brandl | 2007-03-26 13:28:28 -0700 (Mon, 26 Mar 2007) | 2 lines Some nits. ........ r54582 | facundo.batista | 2007-03-26 13:56:09 -0700 (Mon, 26 Mar 2007) | 4 lines Forgot to add the file before the previous commit, here go the ftplib tests. ........ r54585 | facundo.batista | 2007-03-27 11:23:21 -0700 (Tue, 27 Mar 2007) | 5 lines Added an optional timeout to poplib.POP3. Also created a test_poplib.py file with a basic test and the timeout ones. Docs are also updated. ........ r54586 | facundo.batista | 2007-03-27 11:50:29 -0700 (Tue, 27 Mar 2007) | 3 lines The basic test cases of poplib.py. ........ r54594 | facundo.batista | 2007-03-27 20:45:20 -0700 (Tue, 27 Mar 2007) | 4 lines Bug 1688393. Adds a control of negative values in socket.recvfrom, which caused an ugly crash. ........ r54599 | facundo.batista | 2007-03-28 11:25:54 -0700 (Wed, 28 Mar 2007) | 5 lines Added timeout to smtplib (to SMTP and SMTP_SSL). Also created the test_smtplib.py file, with a basic test and the timeout ones. Docs are updated too. ........ r54603 | collin.winter | 2007-03-28 16:34:06 -0700 (Wed, 28 Mar 2007) | 3 lines Consolidate patches #1690164, 1683397, and 1690169, all of which refactor XML-related test suites. The patches are applied together because they use a common output/xmltests file. Thanks to Jerry Seutter for all three patches. ........ r54604 | collin.winter | 2007-03-28 19:28:16 -0700 (Wed, 28 Mar 2007) | 1 line Make test_zipfile clean up its temporary files properly. ........ r54605 | georg.brandl | 2007-03-29 00:41:32 -0700 (Thu, 29 Mar 2007) | 2 lines These are actually methods. ........ r54606 | georg.brandl | 2007-03-29 05:42:07 -0700 (Thu, 29 Mar 2007) | 4 lines In Windows' time.clock(), when QueryPerformanceFrequency() fails, the C lib's clock() is used, but it must be divided by CLOCKS_PER_SEC as for the POSIX implementation (thanks to #pypy). ........ r54608 | facundo.batista | 2007-03-29 11:22:35 -0700 (Thu, 29 Mar 2007) | 5 lines Added timout parameter to telnetlib.Telnet. Also created test_telnetlib.py with a basic test and timeout ones. Docs are also updated. ........ r54613 | facundo.batista | 2007-03-30 06:00:35 -0700 (Fri, 30 Mar 2007) | 4 lines Added the posibility to pass the timeout to FTP.connect, not only when instantiating the class. Docs and tests are updated. ........ r54614 | collin.winter | 2007-03-30 07:01:25 -0700 (Fri, 30 Mar 2007) | 1 line Bug #1688274: add documentation for C-level class objects. ........ r54615 | marc-andre.lemburg | 2007-03-30 08:01:42 -0700 (Fri, 30 Mar 2007) | 4 lines Bump the patch level version of distutils since there were a few bug fixes since the 2.5.0 release. ........ r54617 | georg.brandl | 2007-03-30 08:49:05 -0700 (Fri, 30 Mar 2007) | 2 lines Markup fix. ........ r54618 | georg.brandl | 2007-03-30 10:39:39 -0700 (Fri, 30 Mar 2007) | 2 lines Label name fix. ........ r54619 | georg.brandl | 2007-03-30 10:47:21 -0700 (Fri, 30 Mar 2007) | 2 lines Duplicate label fix. ........ r54620 | georg.brandl | 2007-03-30 10:48:39 -0700 (Fri, 30 Mar 2007) | 2 lines Markup fix. ........ r54623 | andrew.kuchling | 2007-03-30 11:00:15 -0700 (Fri, 30 Mar 2007) | 1 line Add item. (Oops, accidentally checked this in on my branch) ........ r54624 | georg.brandl | 2007-03-30 12:01:38 -0700 (Fri, 30 Mar 2007) | 2 lines Duplicate label fix. ........ r54625 | georg.brandl | 2007-03-30 12:14:02 -0700 (Fri, 30 Mar 2007) | 2 lines Markup fix. ........ r54629 | georg.brandl | 2007-03-31 03:17:31 -0700 (Sat, 31 Mar 2007) | 2 lines repair string literal. ........ r54630 | georg.brandl | 2007-03-31 04:54:58 -0700 (Sat, 31 Mar 2007) | 2 lines Markup fix. ........ r54631 | georg.brandl | 2007-03-31 04:58:36 -0700 (Sat, 31 Mar 2007) | 2 lines Duplicate label fix. ........ r54632 | georg.brandl | 2007-03-31 04:59:54 -0700 (Sat, 31 Mar 2007) | 2 lines Typo fix. ........ r54633 | neal.norwitz | 2007-03-31 11:54:18 -0700 (Sat, 31 Mar 2007) | 1 line Fix method names. Will backport. ........ r54634 | georg.brandl | 2007-03-31 11:56:11 -0700 (Sat, 31 Mar 2007) | 4 lines Bug #1655392: don't add -L/usr/lib/pythonX.Y/config to the LDFLAGS returned by python-config if Python was built with --enable-shared because that prevented the shared library from being used. ........ r54637 | collin.winter | 2007-03-31 12:31:34 -0700 (Sat, 31 Mar 2007) | 1 line Shut up an occaisonal buildbot error due to test files being left around. ........ r54644 | neal.norwitz | 2007-04-01 11:24:22 -0700 (Sun, 01 Apr 2007) | 11 lines SF #1685563, MSVCCompiler creates redundant and long PATH strings If MSVCCompiler.initialize() was called multiple times, the path would get duplicated. On Windows, this is a problem because the path is limited to 4k. There's no benefit in adding a path multiple times, so prevent that from occuring. We also normalize the path before checking for duplicates so things like /a and /a/ won't both be stored. Will backport. ........ r54646 | brett.cannon | 2007-04-01 11:47:27 -0700 (Sun, 01 Apr 2007) | 8 lines time.strptime's caching of its locale object was being recreated when the locale changed but not used during the function call it was recreated during. The test in this checkin is untested (OS X does not have the proper locale support for me to test), although the fix for the bug this deals with was tested by the OP (#1290505). Once the buildbots verify the test at least doesn't fail it becomes a backport candidate. ........ r54647 | brett.cannon | 2007-04-01 12:46:19 -0700 (Sun, 01 Apr 2007) | 3 lines Fix the test for recreating the locale cache object by not worrying about if one of the test locales cannot be set. ........ r54649 | georg.brandl | 2007-04-01 14:29:15 -0700 (Sun, 01 Apr 2007) | 2 lines Fix a lot of markup and meta-information glitches. ........ r54650 | georg.brandl | 2007-04-01 14:39:52 -0700 (Sun, 01 Apr 2007) | 2 lines Another fix. ........ r54651 | georg.brandl | 2007-04-01 15:39:10 -0700 (Sun, 01 Apr 2007) | 2 lines Lots of explicit class names for method and member descs. ........ r54652 | georg.brandl | 2007-04-01 15:40:12 -0700 (Sun, 01 Apr 2007) | 2 lines Explicit class names. ........ r54653 | georg.brandl | 2007-04-01 15:47:31 -0700 (Sun, 01 Apr 2007) | 2 lines Some semantic fixes. ........ r54654 | georg.brandl | 2007-04-01 16:29:10 -0700 (Sun, 01 Apr 2007) | 2 lines Remove bogus entry. ........ r54655 | georg.brandl | 2007-04-01 16:31:30 -0700 (Sun, 01 Apr 2007) | 2 lines Fix the class name of strings. ........ r54658 | raymond.hettinger | 2007-04-02 10:29:30 -0700 (Mon, 02 Apr 2007) | 1 line SF #1693079: Cannot save empty array in shelve ........ r54663 | raymond.hettinger | 2007-04-02 15:54:21 -0700 (Mon, 02 Apr 2007) | 3 lines Array module's buffer interface can now handle empty arrays. ........ r54664 | guido.van.rossum | 2007-04-02 16:55:37 -0700 (Mon, 02 Apr 2007) | 5 lines Fix warnings about object.__init__() signature. Two (test_array and test_descr) were bug IMO; the third (copy_reg) is a work-around which recognizes that object.__init__() doesn't do anything. ........ r54666 | raymond.hettinger | 2007-04-02 17:02:11 -0700 (Mon, 02 Apr 2007) | 1 line SF 1602378 Clarify docstrings for bisect ........ r54668 | raymond.hettinger | 2007-04-02 18:39:43 -0700 (Mon, 02 Apr 2007) | 3 lines SF #1382213: Tutorial section 9.5.1 ignores MRO for new-style classes ........ r54669 | matthias.klose | 2007-04-02 21:35:59 -0700 (Mon, 02 Apr 2007) | 4 lines - Fix an off-by-one bug in locale.strxfrm(). patch taken from http://bugs.debian.org/416934. ........ r54671 | georg.brandl | 2007-04-03 00:04:27 -0700 (Tue, 03 Apr 2007) | 9 lines Fix the strange case of \begin{methoddesc}[NNTP]{...} where \ifx#1\@undefined ended up comparing N and N, therefore executing the true part of the conditional, blowing up at \@undefined. ........ r54672 | facundo.batista | 2007-04-03 07:05:08 -0700 (Tue, 03 Apr 2007) | 4 lines Now using unittest for the tests infraestructure. Also split the tests in those who need the network, and that who doesn't. ........ r54673 | walter.doerwald | 2007-04-03 09:08:10 -0700 (Tue, 03 Apr 2007) | 4 lines Move the functionality for catching warnings in test_warnings.py into a separate class to that reusing the functionality in test_structmembers.py doesn't rerun the tests from test_warnings.py. ........ r54674 | walter.doerwald | 2007-04-03 09:16:24 -0700 (Tue, 03 Apr 2007) | 2 lines Document that CatchWarningTests is reused by test_structmembers.py. ........ r54675 | walter.doerwald | 2007-04-03 09:53:43 -0700 (Tue, 03 Apr 2007) | 4 lines Add tests for the filename. Test that the stacklevel is handled correctly. ........ r54676 | facundo.batista | 2007-04-03 10:29:48 -0700 (Tue, 03 Apr 2007) | 6 lines Added a SSL server to test_socket_ssl.py to be able to test locally. Now, it checks if have openssl available and run those specific tests (it starts openssl at the beggining of all the tests and then kills it at the end). ........ r54677 | walter.doerwald | 2007-04-03 11:33:29 -0700 (Tue, 03 Apr 2007) | 6 lines Implement a contextmanager test.test_support.catch_warning that can be used to catch the last warning issued by the warning framework. Change test_warnings.py and test_structmembers.py to use this new contextmanager. ........ r54678 | facundo.batista | 2007-04-03 14:15:34 -0700 (Tue, 03 Apr 2007) | 4 lines Changed the whole structure of startup and checking if the server is available. Hope to not get more false alarms. ........ r54681 | facundo.batista | 2007-04-04 07:10:40 -0700 (Wed, 04 Apr 2007) | 4 lines Fixed the way that the .pem files are looked for, and changed how to kill the process in win32 to use the _handle attribute. ........ r54682 | guido.van.rossum | 2007-04-04 10:43:02 -0700 (Wed, 04 Apr 2007) | 4 lines Fix a race condition in this test -- instead of assuming that it will take the test server thread at most 0.5 seconds to get ready, use an event variable. ........ r54683 | collin.winter | 2007-04-04 11:14:17 -0700 (Wed, 04 Apr 2007) | 1 line Clean up imports. ........ r54684 | collin.winter | 2007-04-04 11:16:24 -0700 (Wed, 04 Apr 2007) | 1 line Stop using test_support.verify(). ........ r54685 | martin.v.loewis | 2007-04-04 11:30:36 -0700 (Wed, 04 Apr 2007) | 2 lines Bug #1686475: Support stat'ing open files on Windows again. Will backport to 2.5. ........ r54687 | collin.winter | 2007-04-04 11:33:40 -0700 (Wed, 04 Apr 2007) | 1 line Make test_getopt use unittest. ........ r54688 | collin.winter | 2007-04-04 11:36:30 -0700 (Wed, 04 Apr 2007) | 1 line Make test_softspace use unittest. ........ r54689 | ziga.seilnacht | 2007-04-04 11:38:47 -0700 (Wed, 04 Apr 2007) | 2 lines Fix WalkTests.test_traversal() on Windows. The cleanup in MakedirTests.setUp() can now be removed. ........ r54695 | raymond.hettinger | 2007-04-05 11:00:03 -0700 (Thu, 05 Apr 2007) | 3 lines Bug #1563759: struct.unpack doens't support buffer protocol objects ........ r54697 | collin.winter | 2007-04-05 13:05:07 -0700 (Thu, 05 Apr 2007) | 1 line Convert test_long_future to use unittest. ........ r54698 | collin.winter | 2007-04-05 13:08:56 -0700 (Thu, 05 Apr 2007) | 1 line Convert test_normalization to use unittest. ........ r54699 | andrew.kuchling | 2007-04-05 18:11:58 -0700 (Thu, 05 Apr 2007) | 1 line Some grammar fixes ........ r54704 | collin.winter | 2007-04-06 12:27:40 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_stringprep to use unittest. ........ r54705 | collin.winter | 2007-04-06 12:32:32 -0700 (Fri, 06 Apr 2007) | 1 line Import cleanup in test_crypt. ........ r54706 | collin.winter | 2007-04-06 13:00:05 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_gc to use unittest. ........ r54707 | collin.winter | 2007-04-06 13:03:11 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_module to use unittest. ........ r54711 | collin.winter | 2007-04-06 21:40:43 -0700 (Fri, 06 Apr 2007) | 1 line Convert test_fileinput to use unittest. ........ r54712 | brett.cannon | 2007-04-07 21:29:32 -0700 (Sat, 07 Apr 2007) | 5 lines Doc that file.next() has undefined behaviour when called on a file opened with 'w'. Closes bug #1569057. To be backported once 2.5 branch is unfrozen. ........ r54726 | vinay.sajip | 2007-04-09 09:16:10 -0700 (Mon, 09 Apr 2007) | 1 line Added optional timeout to SocketHandler.makeSocket (SF #1695948) ........ r54727 | ziga.seilnacht | 2007-04-09 12:10:29 -0700 (Mon, 09 Apr 2007) | 3 lines Patch #1695862: remove old test directory that causes test_urllib failures on Windows buildbots. The change is a one time fix and will be removed after a successful buildbot run. ........ r54729 | facundo.batista | 2007-04-09 20:00:37 -0700 (Mon, 09 Apr 2007) | 3 lines Minor fix to the tests pass ok even with -O. ........ r54730 | collin.winter | 2007-04-09 21:44:49 -0700 (Mon, 09 Apr 2007) | 1 line Typo fix. ........ r54732 | facundo.batista | 2007-04-10 05:58:45 -0700 (Tue, 10 Apr 2007) | 5 lines General clean-up. Lot of margin corrections, comments, some typos. Exceptions now are raised in the new style. And a mockup class is now also new style. Thanks Santiago Pereson. ........ r54741 | georg.brandl | 2007-04-10 14:39:38 -0700 (Tue, 10 Apr 2007) | 2 lines Repair a duplicate label and some obsolete uses of \setindexsubitem. ........ r54746 | andrew.kuchling | 2007-04-11 06:39:00 -0700 (Wed, 11 Apr 2007) | 1 line Add window.chgat() method, submitted via e-mail by Fabian Kreutz ........ r54747 | andrew.kuchling | 2007-04-11 06:42:25 -0700 (Wed, 11 Apr 2007) | 1 line Point readers at the patch submission instructions ........ r54748 | andrew.kuchling | 2007-04-11 06:47:13 -0700 (Wed, 11 Apr 2007) | 1 line Describe undocumented third argument to touchline() ........ r54757 | georg.brandl | 2007-04-11 10:16:24 -0700 (Wed, 11 Apr 2007) | 3 lines Add some missing NULL checks which trigger crashes on low-memory conditions. Found by Victor Stinner. Will backport when 2.5 branch is unfrozen. ........ r54760 | raymond.hettinger | 2007-04-11 11:40:58 -0700 (Wed, 11 Apr 2007) | 1 line SF 1191699: Make slices picklable ........ r54762 | georg.brandl | 2007-04-11 12:25:11 -0700 (Wed, 11 Apr 2007) | 2 lines Exceptions are no longer old-style instances. Fix accordingly. ........ r54763 | georg.brandl | 2007-04-11 16:28:44 -0700 (Wed, 11 Apr 2007) | 2 lines Repair missing spaces after \UNIX. ........ r54772 | raymond.hettinger | 2007-04-11 21:10:00 -0700 (Wed, 11 Apr 2007) | 1 line SF 1193128: Let str.translate(None) be an identity transformation ........ r54784 | georg.brandl | 2007-04-12 00:01:19 -0700 (Thu, 12 Apr 2007) | 2 lines Patch #1698951: clarify deprecation message in rexec and Bastion ........ r54785 | ziga.seilnacht | 2007-04-12 01:46:51 -0700 (Thu, 12 Apr 2007) | 2 lines Patch #1695862: remove the cleanup code, now that Windows buildbots are green again. ........ r54786 | walter.doerwald | 2007-04-12 03:35:00 -0700 (Thu, 12 Apr 2007) | 3 lines Fix utf-8-sig incremental decoder, which didn't recognise a BOM when the first chunk fed to the decoder started with a BOM, but was longer than 3 bytes. ........ r54807 | barry.warsaw | 2007-04-13 11:47:14 -0700 (Fri, 13 Apr 2007) | 8 lines Port r54805 from python25-maint branch: Add code to read from master_fd in the parent, breaking when we get an OSError (EIO can occur on Linux) or there's no more data to read. Without this, test_pty.py can hang on the waitpid() because the child is blocking on the stdout write. This will definitely happen on Mac OS X and could potentially happen on other platforms. See the comment for details. ........ r54812 | kristjan.jonsson | 2007-04-13 15:07:33 -0700 (Fri, 13 Apr 2007) | 1 line Fix a bug when using the __lltrace__ opcode tracer, and a problem sith signed chars in frameobject.c which can occur with opcodes > 127 ........ r54814 | kristjan.jonsson | 2007-04-13 15:20:13 -0700 (Fri, 13 Apr 2007) | 1 line Fix potential crash in path manipulation on windows ........ r54816 | trent.mick | 2007-04-13 16:22:05 -0700 (Fri, 13 Apr 2007) | 4 lines Add the necessary dependency for the Windows VC6 build to ensure 'pythoncore' is built before '_ctypes' is attempted. Will backport to 2.5 once it is unfrozen for 2.5.1. ........ r54825 | neal.norwitz | 2007-04-13 22:25:50 -0700 (Fri, 13 Apr 2007) | 3 lines When __slots__ are set to a unicode string, make it work the same as setting a plain string, ie don't expand to single letter identifiers. ........ r54841 | neal.norwitz | 2007-04-16 00:37:55 -0700 (Mon, 16 Apr 2007) | 1 line SF #1701207, Fix bogus assertion (and test it!) ........ r54844 | collin.winter | 2007-04-16 15:10:32 -0700 (Mon, 16 Apr 2007) | 1 line Check the availability of the urlfetch resource earlier than before. ........ r54849 | martin.v.loewis | 2007-04-16 22:02:01 -0700 (Mon, 16 Apr 2007) | 2 lines Add Travis Oliphant. ........ r54873 | brett.cannon | 2007-04-18 20:44:17 -0700 (Wed, 18 Apr 2007) | 2 lines Silence a compiler warning about incompatible pointer types. ........ r54874 | neal.norwitz | 2007-04-18 22:52:37 -0700 (Wed, 18 Apr 2007) | 2 lines SF #1703270, add missing declaration in readline.c to avoid compiler warning. ........ r54875 | armin.rigo | 2007-04-19 07:44:48 -0700 (Thu, 19 Apr 2007) | 8 lines Revert r53997 as per http://mail.python.org/pipermail/python-dev/2007-March/071796.html . I've kept a couple of still-valid extra tests in test_descr, but didn't bother to sort through the new comments and refactorings added in r53997 to see if some of them could be kept. If so, they could go in a follow-up check-in. ........ r54876 | armin.rigo | 2007-04-19 07:56:48 -0700 (Thu, 19 Apr 2007) | 2 lines Fix a usage of the dangerous pattern decref - modify field - incref. ........ r54884 | neal.norwitz | 2007-04-19 22:20:38 -0700 (Thu, 19 Apr 2007) | 9 lines Add an optional address to copy the failure mails to. Detect a conflict in the only file that should have outstanding changes when this script is run. This doesn't matter on the trunk, but does when run on a branch. Trunk always has the date set to today in boilerplate.tex. Each time a release is cut with a different date, a conflict occurs. (We could copy a known good version, but then we would lose changes to this file.) ........ r54918 | georg.brandl | 2007-04-21 13:35:38 -0700 (Sat, 21 Apr 2007) | 3 lines Bug #1704790: bind name "sys" locally in __del__ method so that it is not cleared before __del__ is run. ........ r54920 | facundo.batista | 2007-04-21 18:18:56 -0700 (Sat, 21 Apr 2007) | 5 lines Added tests for other methods of SSL object. Now we cover all the object methods. This is the final step to close the #451607 bug. ........ r54927 | facundo.batista | 2007-04-23 10:08:31 -0700 (Mon, 23 Apr 2007) | 5 lines As specified in RFC 2616, 2xx code indicates that the client's request was successfully received, understood, and accepted. Now in these cases no error is raised. Also fixed tests. ........ r54929 | collin.winter | 2007-04-23 20:43:46 -0700 (Mon, 23 Apr 2007) | 1 line Convert PyUnit -> unittest. ........ r54931 | collin.winter | 2007-04-23 21:09:52 -0700 (Mon, 23 Apr 2007) | 1 line Remove code that hasn't been called in years. ........ r54932 | neal.norwitz | 2007-04-23 21:53:12 -0700 (Mon, 23 Apr 2007) | 1 line Fix SF #1703110, Incorrect example for add_password() (use uri, not host) ........ r54934 | georg.brandl | 2007-04-24 03:36:42 -0700 (Tue, 24 Apr 2007) | 2 lines Some new year updates. ........ r54938 | facundo.batista | 2007-04-24 06:54:38 -0700 (Tue, 24 Apr 2007) | 4 lines Added a comment about last change in urllib2.py (all 2xx responses are ok now). ........ r54939 | georg.brandl | 2007-04-24 08:10:09 -0700 (Tue, 24 Apr 2007) | 2 lines Bug #1705717: error in sys.argv docs. ........ r54941 | georg.brandl | 2007-04-24 08:27:13 -0700 (Tue, 24 Apr 2007) | 4 lines Bug #1706381: Specifying the SWIG option "-c++" in the setup.py file (as opposed to the command line) will now write file names ending in ".cpp" too. ........ r54944 | raymond.hettinger | 2007-04-24 15:13:43 -0700 (Tue, 24 Apr 2007) | 1 line Fix markup ........ r54945 | kristjan.jonsson | 2007-04-24 17:10:50 -0700 (Tue, 24 Apr 2007) | 1 line Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition ........ r54947 | kristjan.jonsson | 2007-04-24 17:17:39 -0700 (Tue, 24 Apr 2007) | 1 line Make pythoncore compile cleanly with VisualStudio 2005. Used an explicit typecast to get a 64 bit integer, and undefined the Yield macro that conflicts with winbase.h ........ r54948 | kristjan.jonsson | 2007-04-24 17:19:26 -0700 (Tue, 24 Apr 2007) | 1 line Remove obsolete comment. Importing of .dll files has been discontinued, only .pyd files supported on windows now. ........ r54949 | georg.brandl | 2007-04-24 23:24:59 -0700 (Tue, 24 Apr 2007) | 2 lines Patch #1698768: updated the "using Python on the Mac" intro. ........ r54951 | georg.brandl | 2007-04-24 23:25:55 -0700 (Tue, 24 Apr 2007) | 2 lines Markup fix. ........ r54953 | neal.norwitz | 2007-04-24 23:30:05 -0700 (Tue, 24 Apr 2007) | 3 lines Whitespace normalization. Ugh, we really need to do this more often. You might want to review this change as it's my first time. Be gentle. :-) ........ r54956 | collin.winter | 2007-04-25 10:29:52 -0700 (Wed, 25 Apr 2007) | 1 line Standardize on test.test_support.run_unittest() (as opposed to a mix of run_unittest() and run_suite()). Also, add functionality to run_unittest() that admits usage of unittest.TestLoader.loadTestsFromModule(). ........ r54957 | collin.winter | 2007-04-25 10:37:35 -0700 (Wed, 25 Apr 2007) | 1 line Remove functionality from test_datetime.test_main() that does reference count checking; 'regrtest.py -R' is the way to do this kind of testing. ........ r54958 | collin.winter | 2007-04-25 10:57:53 -0700 (Wed, 25 Apr 2007) | 1 line Change test_support.have_unicode to use True/False instead of 1/0. ........ r54959 | tim.peters | 2007-04-25 11:47:18 -0700 (Wed, 25 Apr 2007) | 2 lines Whitespace normalization. ........ r54960 | tim.peters | 2007-04-25 11:48:35 -0700 (Wed, 25 Apr 2007) | 2 lines Set missing svn:eol-style property on text files. ........ r54961 | collin.winter | 2007-04-25 11:54:36 -0700 (Wed, 25 Apr 2007) | 1 line Import and raise statement cleanup. ........ r54969 | collin.winter | 2007-04-25 13:41:34 -0700 (Wed, 25 Apr 2007) | 1 line Convert test_ossaudiodev to use unittest. ........ r54974 | collin.winter | 2007-04-25 14:50:25 -0700 (Wed, 25 Apr 2007) | 1 line Fix an issue related to the unittest conversion. ........ r54979 | fred.drake | 2007-04-25 21:42:19 -0700 (Wed, 25 Apr 2007) | 1 line fix some markup errors ........ r54982 | kristjan.jonsson | 2007-04-26 02:15:08 -0700 (Thu, 26 Apr 2007) | 1 line Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile. ........ r54983 | kristjan.jonsson | 2007-04-26 06:44:16 -0700 (Thu, 26 Apr 2007) | 1 line The locale "En" appears not to be valid on windows underi VisualStudio.2005. Added "English" to the test_locale.py to make the testsuite pass for that build ........ r54984 | steve.holden | 2007-04-26 07:23:12 -0700 (Thu, 26 Apr 2007) | 1 line Minor wording change on slicing aide-memoire. ........ r54985 | kristjan.jonsson | 2007-04-26 08:24:54 -0700 (Thu, 26 Apr 2007) | 1 line Accomodate 64 bit time_t in the _bsddb module. ........
2766 lines
69 KiB
C
2766 lines
69 KiB
C
|
|
/* Dictionary object implementation using a hash table */
|
|
|
|
/* The distribution includes a separate file, Objects/dictnotes.txt,
|
|
describing explorations into dictionary design and optimization.
|
|
It covers typical dictionary use patterns, the parameters for
|
|
tuning dictionaries, and several ideas for possible optimizations.
|
|
*/
|
|
|
|
#include "Python.h"
|
|
|
|
typedef PyDictEntry dictentry;
|
|
typedef PyDictObject dictobject;
|
|
|
|
/* Set a key error with the specified argument, wrapping it in a
|
|
* tuple automatically so that tuple keys are not unpacked as the
|
|
* exception arguments. */
|
|
static void
|
|
set_key_error(PyObject *arg)
|
|
{
|
|
PyObject *tup;
|
|
tup = PyTuple_Pack(1, arg);
|
|
if (!tup)
|
|
return; /* caller will expect error to be set anyway */
|
|
PyErr_SetObject(PyExc_KeyError, tup);
|
|
Py_DECREF(tup);
|
|
}
|
|
|
|
/* Define this out if you don't want conversion statistics on exit. */
|
|
#undef SHOW_CONVERSION_COUNTS
|
|
|
|
/* See large comment block below. This must be >= 1. */
|
|
#define PERTURB_SHIFT 5
|
|
|
|
/*
|
|
Major subtleties ahead: Most hash schemes depend on having a "good" hash
|
|
function, in the sense of simulating randomness. Python doesn't: its most
|
|
important hash functions (for strings and ints) are very regular in common
|
|
cases:
|
|
|
|
>>> map(hash, (0, 1, 2, 3))
|
|
[0, 1, 2, 3]
|
|
>>> map(hash, ("namea", "nameb", "namec", "named"))
|
|
[-1658398457, -1658398460, -1658398459, -1658398462]
|
|
>>>
|
|
|
|
This isn't necessarily bad! To the contrary, in a table of size 2**i, taking
|
|
the low-order i bits as the initial table index is extremely fast, and there
|
|
are no collisions at all for dicts indexed by a contiguous range of ints.
|
|
The same is approximately true when keys are "consecutive" strings. So this
|
|
gives better-than-random behavior in common cases, and that's very desirable.
|
|
|
|
OTOH, when collisions occur, the tendency to fill contiguous slices of the
|
|
hash table makes a good collision resolution strategy crucial. Taking only
|
|
the last i bits of the hash code is also vulnerable: for example, consider
|
|
the list [i << 16 for i in range(20000)] as a set of keys. Since ints are
|
|
their own hash codes, and this fits in a dict of size 2**15, the last 15 bits
|
|
of every hash code are all 0: they *all* map to the same table index.
|
|
|
|
But catering to unusual cases should not slow the usual ones, so we just take
|
|
the last i bits anyway. It's up to collision resolution to do the rest. If
|
|
we *usually* find the key we're looking for on the first try (and, it turns
|
|
out, we usually do -- the table load factor is kept under 2/3, so the odds
|
|
are solidly in our favor), then it makes best sense to keep the initial index
|
|
computation dirt cheap.
|
|
|
|
The first half of collision resolution is to visit table indices via this
|
|
recurrence:
|
|
|
|
j = ((5*j) + 1) mod 2**i
|
|
|
|
For any initial j in range(2**i), repeating that 2**i times generates each
|
|
int in range(2**i) exactly once (see any text on random-number generation for
|
|
proof). By itself, this doesn't help much: like linear probing (setting
|
|
j += 1, or j -= 1, on each loop trip), it scans the table entries in a fixed
|
|
order. This would be bad, except that's not the only thing we do, and it's
|
|
actually *good* in the common cases where hash keys are consecutive. In an
|
|
example that's really too small to make this entirely clear, for a table of
|
|
size 2**3 the order of indices is:
|
|
|
|
0 -> 1 -> 6 -> 7 -> 4 -> 5 -> 2 -> 3 -> 0 [and here it's repeating]
|
|
|
|
If two things come in at index 5, the first place we look after is index 2,
|
|
not 6, so if another comes in at index 6 the collision at 5 didn't hurt it.
|
|
Linear probing is deadly in this case because there the fixed probe order
|
|
is the *same* as the order consecutive keys are likely to arrive. But it's
|
|
extremely unlikely hash codes will follow a 5*j+1 recurrence by accident,
|
|
and certain that consecutive hash codes do not.
|
|
|
|
The other half of the strategy is to get the other bits of the hash code
|
|
into play. This is done by initializing a (unsigned) vrbl "perturb" to the
|
|
full hash code, and changing the recurrence to:
|
|
|
|
j = (5*j) + 1 + perturb;
|
|
perturb >>= PERTURB_SHIFT;
|
|
use j % 2**i as the next table index;
|
|
|
|
Now the probe sequence depends (eventually) on every bit in the hash code,
|
|
and the pseudo-scrambling property of recurring on 5*j+1 is more valuable,
|
|
because it quickly magnifies small differences in the bits that didn't affect
|
|
the initial index. Note that because perturb is unsigned, if the recurrence
|
|
is executed often enough perturb eventually becomes and remains 0. At that
|
|
point (very rarely reached) the recurrence is on (just) 5*j+1 again, and
|
|
that's certain to find an empty slot eventually (since it generates every int
|
|
in range(2**i), and we make sure there's always at least one empty slot).
|
|
|
|
Selecting a good value for PERTURB_SHIFT is a balancing act. You want it
|
|
small so that the high bits of the hash code continue to affect the probe
|
|
sequence across iterations; but you want it large so that in really bad cases
|
|
the high-order hash bits have an effect on early iterations. 5 was "the
|
|
best" in minimizing total collisions across experiments Tim Peters ran (on
|
|
both normal and pathological cases), but 4 and 6 weren't significantly worse.
|
|
|
|
Historical: Reimer Behrends contributed the idea of using a polynomial-based
|
|
approach, using repeated multiplication by x in GF(2**n) where an irreducible
|
|
polynomial for each table size was chosen such that x was a primitive root.
|
|
Christian Tismer later extended that to use division by x instead, as an
|
|
efficient way to get the high bits of the hash code into play. This scheme
|
|
also gave excellent collision statistics, but was more expensive: two if-tests
|
|
were required inside the loop; computing "the next" index took about the same
|
|
number of operations but without as much potential parallelism (e.g.,
|
|
computing 5*j can go on at the same time as computing 1+perturb in the above,
|
|
and then shifting perturb can be done while the table index is being masked);
|
|
and the dictobject struct required a member to hold the table's polynomial.
|
|
In Tim's experiments the current scheme ran faster, produced equally good
|
|
collision statistics, needed less code & used less memory.
|
|
|
|
Theoretical Python 2.5 headache: hash codes are only C "long", but
|
|
sizeof(Py_ssize_t) > sizeof(long) may be possible. In that case, and if a
|
|
dict is genuinely huge, then only the slots directly reachable via indexing
|
|
by a C long can be the first slot in a probe sequence. The probe sequence
|
|
will still eventually reach every slot in the table, but the collision rate
|
|
on initial probes may be much higher than this scheme was designed for.
|
|
Getting a hash code as fat as Py_ssize_t is the only real cure. But in
|
|
practice, this probably won't make a lick of difference for many years (at
|
|
which point everyone will have terabytes of RAM on 64-bit boxes).
|
|
*/
|
|
|
|
/* Object used as dummy key to fill deleted entries */
|
|
static PyObject *dummy = NULL; /* Initialized by first call to newdictobject() */
|
|
|
|
#ifdef Py_REF_DEBUG
|
|
PyObject *
|
|
_PyDict_Dummy(void)
|
|
{
|
|
return dummy;
|
|
}
|
|
#endif
|
|
|
|
/* forward declarations */
|
|
static dictentry *
|
|
lookdict_string(dictobject *mp, PyObject *key, long hash);
|
|
|
|
#ifdef SHOW_CONVERSION_COUNTS
|
|
static long created = 0L;
|
|
static long converted = 0L;
|
|
|
|
static void
|
|
show_counts(void)
|
|
{
|
|
fprintf(stderr, "created %ld string dicts\n", created);
|
|
fprintf(stderr, "converted %ld to normal dicts\n", converted);
|
|
fprintf(stderr, "%.2f%% conversion rate\n", (100.0*converted)/created);
|
|
}
|
|
#endif
|
|
|
|
/* Initialization macros.
|
|
There are two ways to create a dict: PyDict_New() is the main C API
|
|
function, and the tp_new slot maps to dict_new(). In the latter case we
|
|
can save a little time over what PyDict_New does because it's guaranteed
|
|
that the PyDictObject struct is already zeroed out.
|
|
Everyone except dict_new() should use EMPTY_TO_MINSIZE (unless they have
|
|
an excellent reason not to).
|
|
*/
|
|
|
|
#define INIT_NONZERO_DICT_SLOTS(mp) do { \
|
|
(mp)->ma_table = (mp)->ma_smalltable; \
|
|
(mp)->ma_mask = PyDict_MINSIZE - 1; \
|
|
} while(0)
|
|
|
|
#define EMPTY_TO_MINSIZE(mp) do { \
|
|
memset((mp)->ma_smalltable, 0, sizeof((mp)->ma_smalltable)); \
|
|
(mp)->ma_used = (mp)->ma_fill = 0; \
|
|
INIT_NONZERO_DICT_SLOTS(mp); \
|
|
} while(0)
|
|
|
|
/* Dictionary reuse scheme to save calls to malloc, free, and memset */
|
|
#define MAXFREEDICTS 80
|
|
static PyDictObject *free_dicts[MAXFREEDICTS];
|
|
static int num_free_dicts = 0;
|
|
|
|
PyObject *
|
|
PyDict_New(void)
|
|
{
|
|
register dictobject *mp;
|
|
if (dummy == NULL) { /* Auto-initialize dummy */
|
|
dummy = PyString_FromString("<dummy key>");
|
|
if (dummy == NULL)
|
|
return NULL;
|
|
#ifdef SHOW_CONVERSION_COUNTS
|
|
Py_AtExit(show_counts);
|
|
#endif
|
|
}
|
|
if (num_free_dicts) {
|
|
mp = free_dicts[--num_free_dicts];
|
|
assert (mp != NULL);
|
|
assert (mp->ob_type == &PyDict_Type);
|
|
_Py_NewReference((PyObject *)mp);
|
|
if (mp->ma_fill) {
|
|
EMPTY_TO_MINSIZE(mp);
|
|
}
|
|
assert (mp->ma_used == 0);
|
|
assert (mp->ma_table == mp->ma_smalltable);
|
|
assert (mp->ma_mask == PyDict_MINSIZE - 1);
|
|
} else {
|
|
mp = PyObject_GC_New(dictobject, &PyDict_Type);
|
|
if (mp == NULL)
|
|
return NULL;
|
|
EMPTY_TO_MINSIZE(mp);
|
|
}
|
|
mp->ma_lookup = lookdict_string;
|
|
#ifdef SHOW_CONVERSION_COUNTS
|
|
++created;
|
|
#endif
|
|
_PyObject_GC_TRACK(mp);
|
|
return (PyObject *)mp;
|
|
}
|
|
|
|
/*
|
|
The basic lookup function used by all operations.
|
|
This is based on Algorithm D from Knuth Vol. 3, Sec. 6.4.
|
|
Open addressing is preferred over chaining since the link overhead for
|
|
chaining would be substantial (100% with typical malloc overhead).
|
|
|
|
The initial probe index is computed as hash mod the table size. Subsequent
|
|
probe indices are computed as explained earlier.
|
|
|
|
All arithmetic on hash should ignore overflow.
|
|
|
|
The details in this version are due to Tim Peters, building on many past
|
|
contributions by Reimer Behrends, Jyrki Alakuijala, Vladimir Marangozov and
|
|
Christian Tismer.
|
|
|
|
lookdict() is general-purpose, and may return NULL if (and only if) a
|
|
comparison raises an exception (this was new in Python 2.5).
|
|
lookdict_string() below is specialized to string keys, comparison of which can
|
|
never raise an exception; that function can never return NULL. For both, when
|
|
the key isn't found a dictentry* is returned for which the me_value field is
|
|
NULL; this is the slot in the dict at which the key would have been found, and
|
|
the caller can (if it wishes) add the <key, value> pair to the returned
|
|
dictentry*.
|
|
*/
|
|
static dictentry *
|
|
lookdict(dictobject *mp, PyObject *key, register long hash)
|
|
{
|
|
register size_t i;
|
|
register size_t perturb;
|
|
register dictentry *freeslot;
|
|
register size_t mask = (size_t)mp->ma_mask;
|
|
dictentry *ep0 = mp->ma_table;
|
|
register dictentry *ep;
|
|
register int cmp;
|
|
PyObject *startkey;
|
|
|
|
i = (size_t)hash & mask;
|
|
ep = &ep0[i];
|
|
if (ep->me_key == NULL || ep->me_key == key)
|
|
return ep;
|
|
|
|
if (ep->me_key == dummy)
|
|
freeslot = ep;
|
|
else {
|
|
if (ep->me_hash == hash) {
|
|
startkey = ep->me_key;
|
|
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
|
if (cmp < 0)
|
|
return NULL;
|
|
if (ep0 == mp->ma_table && ep->me_key == startkey) {
|
|
if (cmp > 0)
|
|
return ep;
|
|
}
|
|
else {
|
|
/* The compare did major nasty stuff to the
|
|
* dict: start over.
|
|
* XXX A clever adversary could prevent this
|
|
* XXX from terminating.
|
|
*/
|
|
return lookdict(mp, key, hash);
|
|
}
|
|
}
|
|
freeslot = NULL;
|
|
}
|
|
|
|
/* In the loop, me_key == dummy is by far (factor of 100s) the
|
|
least likely outcome, so test for that last. */
|
|
for (perturb = hash; ; perturb >>= PERTURB_SHIFT) {
|
|
i = (i << 2) + i + perturb + 1;
|
|
ep = &ep0[i & mask];
|
|
if (ep->me_key == NULL)
|
|
return freeslot == NULL ? ep : freeslot;
|
|
if (ep->me_key == key)
|
|
return ep;
|
|
if (ep->me_hash == hash && ep->me_key != dummy) {
|
|
startkey = ep->me_key;
|
|
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
|
|
if (cmp < 0)
|
|
return NULL;
|
|
if (ep0 == mp->ma_table && ep->me_key == startkey) {
|
|
if (cmp > 0)
|
|
return ep;
|
|
}
|
|
else {
|
|
/* The compare did major nasty stuff to the
|
|
* dict: start over.
|
|
* XXX A clever adversary could prevent this
|
|
* XXX from terminating.
|
|
*/
|
|
return lookdict(mp, key, hash);
|
|
}
|
|
}
|
|
else if (ep->me_key == dummy && freeslot == NULL)
|
|
freeslot = ep;
|
|
}
|
|
assert(0); /* NOT REACHED */
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Hacked up version of lookdict which can assume keys are always strings;
|
|
* this assumption allows testing for errors during PyObject_RichCompareBool()
|
|
* to be dropped; string-string comparisons never raise exceptions. This also
|
|
* means we don't need to go through PyObject_RichCompareBool(); we can always
|
|
* use _PyString_Eq() directly.
|
|
*
|
|
* This is valuable because dicts with only string keys are very common.
|
|
*/
|
|
static dictentry *
|
|
lookdict_string(dictobject *mp, PyObject *key, register long hash)
|
|
{
|
|
register size_t i;
|
|
register size_t perturb;
|
|
register dictentry *freeslot;
|
|
register size_t mask = (size_t)mp->ma_mask;
|
|
dictentry *ep0 = mp->ma_table;
|
|
register dictentry *ep;
|
|
|
|
/* Make sure this function doesn't have to handle non-string keys,
|
|
including subclasses of str; e.g., one reason to subclass
|
|
strings is to override __eq__, and for speed we don't cater to
|
|
that here. */
|
|
if (!PyString_CheckExact(key)) {
|
|
#ifdef SHOW_CONVERSION_COUNTS
|
|
++converted;
|
|
#endif
|
|
mp->ma_lookup = lookdict;
|
|
return lookdict(mp, key, hash);
|
|
}
|
|
i = hash & mask;
|
|
ep = &ep0[i];
|
|
if (ep->me_key == NULL || ep->me_key == key)
|
|
return ep;
|
|
if (ep->me_key == dummy)
|
|
freeslot = ep;
|
|
else {
|
|
if (ep->me_hash == hash && _PyString_Eq(ep->me_key, key))
|
|
return ep;
|
|
freeslot = NULL;
|
|
}
|
|
|
|
/* In the loop, me_key == dummy is by far (factor of 100s) the
|
|
least likely outcome, so test for that last. */
|
|
for (perturb = hash; ; perturb >>= PERTURB_SHIFT) {
|
|
i = (i << 2) + i + perturb + 1;
|
|
ep = &ep0[i & mask];
|
|
if (ep->me_key == NULL)
|
|
return freeslot == NULL ? ep : freeslot;
|
|
if (ep->me_key == key
|
|
|| (ep->me_hash == hash
|
|
&& ep->me_key != dummy
|
|
&& _PyString_Eq(ep->me_key, key)))
|
|
return ep;
|
|
if (ep->me_key == dummy && freeslot == NULL)
|
|
freeslot = ep;
|
|
}
|
|
assert(0); /* NOT REACHED */
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
Internal routine to insert a new item into the table.
|
|
Used both by the internal resize routine and by the public insert routine.
|
|
Eats a reference to key and one to value.
|
|
Returns -1 if an error occurred, or 0 on success.
|
|
*/
|
|
static int
|
|
insertdict(register dictobject *mp, PyObject *key, long hash, PyObject *value)
|
|
{
|
|
PyObject *old_value;
|
|
register dictentry *ep;
|
|
typedef PyDictEntry *(*lookupfunc)(PyDictObject *, PyObject *, long);
|
|
|
|
assert(mp->ma_lookup != NULL);
|
|
ep = mp->ma_lookup(mp, key, hash);
|
|
if (ep == NULL) {
|
|
Py_DECREF(key);
|
|
Py_DECREF(value);
|
|
return -1;
|
|
}
|
|
if (ep->me_value != NULL) {
|
|
old_value = ep->me_value;
|
|
ep->me_value = value;
|
|
Py_DECREF(old_value); /* which **CAN** re-enter */
|
|
Py_DECREF(key);
|
|
}
|
|
else {
|
|
if (ep->me_key == NULL)
|
|
mp->ma_fill++;
|
|
else {
|
|
assert(ep->me_key == dummy);
|
|
Py_DECREF(dummy);
|
|
}
|
|
ep->me_key = key;
|
|
ep->me_hash = (Py_ssize_t)hash;
|
|
ep->me_value = value;
|
|
mp->ma_used++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
Internal routine used by dictresize() to insert an item which is
|
|
known to be absent from the dict. This routine also assumes that
|
|
the dict contains no deleted entries. Besides the performance benefit,
|
|
using insertdict() in dictresize() is dangerous (SF bug #1456209).
|
|
Note that no refcounts are changed by this routine; if needed, the caller
|
|
is responsible for incref'ing `key` and `value`.
|
|
*/
|
|
static void
|
|
insertdict_clean(register dictobject *mp, PyObject *key, long hash,
|
|
PyObject *value)
|
|
{
|
|
register size_t i;
|
|
register size_t perturb;
|
|
register size_t mask = (size_t)mp->ma_mask;
|
|
dictentry *ep0 = mp->ma_table;
|
|
register dictentry *ep;
|
|
|
|
i = hash & mask;
|
|
ep = &ep0[i];
|
|
for (perturb = hash; ep->me_key != NULL; perturb >>= PERTURB_SHIFT) {
|
|
i = (i << 2) + i + perturb + 1;
|
|
ep = &ep0[i & mask];
|
|
}
|
|
assert(ep->me_value == NULL);
|
|
mp->ma_fill++;
|
|
ep->me_key = key;
|
|
ep->me_hash = (Py_ssize_t)hash;
|
|
ep->me_value = value;
|
|
mp->ma_used++;
|
|
}
|
|
|
|
/*
|
|
Restructure the table by allocating a new table and reinserting all
|
|
items again. When entries have been deleted, the new table may
|
|
actually be smaller than the old one.
|
|
*/
|
|
static int
|
|
dictresize(dictobject *mp, Py_ssize_t minused)
|
|
{
|
|
Py_ssize_t newsize;
|
|
dictentry *oldtable, *newtable, *ep;
|
|
Py_ssize_t i;
|
|
int is_oldtable_malloced;
|
|
dictentry small_copy[PyDict_MINSIZE];
|
|
|
|
assert(minused >= 0);
|
|
|
|
/* Find the smallest table size > minused. */
|
|
for (newsize = PyDict_MINSIZE;
|
|
newsize <= minused && newsize > 0;
|
|
newsize <<= 1)
|
|
;
|
|
if (newsize <= 0) {
|
|
PyErr_NoMemory();
|
|
return -1;
|
|
}
|
|
|
|
/* Get space for a new table. */
|
|
oldtable = mp->ma_table;
|
|
assert(oldtable != NULL);
|
|
is_oldtable_malloced = oldtable != mp->ma_smalltable;
|
|
|
|
if (newsize == PyDict_MINSIZE) {
|
|
/* A large table is shrinking, or we can't get any smaller. */
|
|
newtable = mp->ma_smalltable;
|
|
if (newtable == oldtable) {
|
|
if (mp->ma_fill == mp->ma_used) {
|
|
/* No dummies, so no point doing anything. */
|
|
return 0;
|
|
}
|
|
/* We're not going to resize it, but rebuild the
|
|
table anyway to purge old dummy entries.
|
|
Subtle: This is *necessary* if fill==size,
|
|
as lookdict needs at least one virgin slot to
|
|
terminate failing searches. If fill < size, it's
|
|
merely desirable, as dummies slow searches. */
|
|
assert(mp->ma_fill > mp->ma_used);
|
|
memcpy(small_copy, oldtable, sizeof(small_copy));
|
|
oldtable = small_copy;
|
|
}
|
|
}
|
|
else {
|
|
newtable = PyMem_NEW(dictentry, newsize);
|
|
if (newtable == NULL) {
|
|
PyErr_NoMemory();
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
/* Make the dict empty, using the new table. */
|
|
assert(newtable != oldtable);
|
|
mp->ma_table = newtable;
|
|
mp->ma_mask = newsize - 1;
|
|
memset(newtable, 0, sizeof(dictentry) * newsize);
|
|
mp->ma_used = 0;
|
|
i = mp->ma_fill;
|
|
mp->ma_fill = 0;
|
|
|
|
/* Copy the data over; this is refcount-neutral for active entries;
|
|
dummy entries aren't copied over, of course */
|
|
for (ep = oldtable; i > 0; ep++) {
|
|
if (ep->me_value != NULL) { /* active entry */
|
|
--i;
|
|
insertdict_clean(mp, ep->me_key, (long)ep->me_hash,
|
|
ep->me_value);
|
|
}
|
|
else if (ep->me_key != NULL) { /* dummy entry */
|
|
--i;
|
|
assert(ep->me_key == dummy);
|
|
Py_DECREF(ep->me_key);
|
|
}
|
|
/* else key == value == NULL: nothing to do */
|
|
}
|
|
|
|
if (is_oldtable_malloced)
|
|
PyMem_DEL(oldtable);
|
|
return 0;
|
|
}
|
|
|
|
/* Note that, for historical reasons, PyDict_GetItem() suppresses all errors
|
|
* that may occur (originally dicts supported only string keys, and exceptions
|
|
* weren't possible). So, while the original intent was that a NULL return
|
|
* meant the key wasn't present, in reality it can mean that, or that an error
|
|
* (suppressed) occurred while computing the key's hash, or that some error
|
|
* (suppressed) occurred when comparing keys in the dict's internal probe
|
|
* sequence. A nasty example of the latter is when a Python-coded comparison
|
|
* function hits a stack-depth error, which can cause this to return NULL
|
|
* even if the key is present.
|
|
*/
|
|
PyObject *
|
|
PyDict_GetItem(PyObject *op, PyObject *key)
|
|
{
|
|
long hash;
|
|
dictobject *mp = (dictobject *)op;
|
|
dictentry *ep;
|
|
PyThreadState *tstate;
|
|
if (!PyDict_Check(op))
|
|
return NULL;
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1)
|
|
{
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1) {
|
|
PyErr_Clear();
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
/* We can arrive here with a NULL tstate during initialization:
|
|
try running "python -Wi" for an example related to string
|
|
interning. Let's just hope that no exception occurs then... */
|
|
tstate = _PyThreadState_Current;
|
|
if (tstate != NULL && tstate->curexc_type != NULL) {
|
|
/* preserve the existing exception */
|
|
PyObject *err_type, *err_value, *err_tb;
|
|
PyErr_Fetch(&err_type, &err_value, &err_tb);
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
/* ignore errors */
|
|
PyErr_Restore(err_type, err_value, err_tb);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
}
|
|
else {
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL) {
|
|
PyErr_Clear();
|
|
return NULL;
|
|
}
|
|
}
|
|
return ep->me_value;
|
|
}
|
|
|
|
/* Variant of PyDict_GetItem() that doesn't suppress exceptions.
|
|
This returns NULL *with* an exception set if an exception occurred.
|
|
It returns NULL *without* an exception set if the key wasn't present.
|
|
*/
|
|
PyObject *
|
|
PyDict_GetItemWithError(PyObject *op, PyObject *key)
|
|
{
|
|
long hash;
|
|
dictobject *mp = (dictobject *)op;
|
|
dictentry *ep;
|
|
|
|
if (!PyDict_Check(op)) {
|
|
PyErr_BadInternalCall();
|
|
return NULL;
|
|
}
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1)
|
|
{
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1) {
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
return ep->me_value;
|
|
}
|
|
|
|
/* CAUTION: PyDict_SetItem() must guarantee that it won't resize the
|
|
* dictionary if it's merely replacing the value for an existing key.
|
|
* This means that it's safe to loop over a dictionary with PyDict_Next()
|
|
* and occasionally replace a value -- but you can't insert new keys or
|
|
* remove them.
|
|
*/
|
|
int
|
|
PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
|
|
{
|
|
register dictobject *mp;
|
|
register long hash;
|
|
register Py_ssize_t n_used;
|
|
|
|
if (!PyDict_Check(op)) {
|
|
PyErr_BadInternalCall();
|
|
return -1;
|
|
}
|
|
assert(key);
|
|
assert(value);
|
|
mp = (dictobject *)op;
|
|
if (PyString_CheckExact(key)) {
|
|
hash = ((PyStringObject *)key)->ob_shash;
|
|
if (hash == -1)
|
|
hash = PyObject_Hash(key);
|
|
}
|
|
else {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return -1;
|
|
}
|
|
assert(mp->ma_fill <= mp->ma_mask); /* at least one empty slot */
|
|
n_used = mp->ma_used;
|
|
Py_INCREF(value);
|
|
Py_INCREF(key);
|
|
if (insertdict(mp, key, hash, value) != 0)
|
|
return -1;
|
|
/* If we added a key, we can safely resize. Otherwise just return!
|
|
* If fill >= 2/3 size, adjust size. Normally, this doubles or
|
|
* quaduples the size, but it's also possible for the dict to shrink
|
|
* (if ma_fill is much larger than ma_used, meaning a lot of dict
|
|
* keys have been * deleted).
|
|
*
|
|
* Quadrupling the size improves average dictionary sparseness
|
|
* (reducing collisions) at the cost of some memory and iteration
|
|
* speed (which loops over every possible entry). It also halves
|
|
* the number of expensive resize operations in a growing dictionary.
|
|
*
|
|
* Very large dictionaries (over 50K items) use doubling instead.
|
|
* This may help applications with severe memory constraints.
|
|
*/
|
|
if (!(mp->ma_used > n_used && mp->ma_fill*3 >= (mp->ma_mask+1)*2))
|
|
return 0;
|
|
return dictresize(mp, (mp->ma_used > 50000 ? 2 : 4) * mp->ma_used);
|
|
}
|
|
|
|
int
|
|
PyDict_DelItem(PyObject *op, PyObject *key)
|
|
{
|
|
register dictobject *mp;
|
|
register long hash;
|
|
register dictentry *ep;
|
|
PyObject *old_value, *old_key;
|
|
|
|
if (!PyDict_Check(op)) {
|
|
PyErr_BadInternalCall();
|
|
return -1;
|
|
}
|
|
assert(key);
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return -1;
|
|
}
|
|
mp = (dictobject *)op;
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return -1;
|
|
if (ep->me_value == NULL) {
|
|
set_key_error(key);
|
|
return -1;
|
|
}
|
|
old_key = ep->me_key;
|
|
Py_INCREF(dummy);
|
|
ep->me_key = dummy;
|
|
old_value = ep->me_value;
|
|
ep->me_value = NULL;
|
|
mp->ma_used--;
|
|
Py_DECREF(old_value);
|
|
Py_DECREF(old_key);
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
PyDict_Clear(PyObject *op)
|
|
{
|
|
dictobject *mp;
|
|
dictentry *ep, *table;
|
|
int table_is_malloced;
|
|
Py_ssize_t fill;
|
|
dictentry small_copy[PyDict_MINSIZE];
|
|
#ifdef Py_DEBUG
|
|
Py_ssize_t i, n;
|
|
#endif
|
|
|
|
if (!PyDict_Check(op))
|
|
return;
|
|
mp = (dictobject *)op;
|
|
#ifdef Py_DEBUG
|
|
n = mp->ma_mask + 1;
|
|
i = 0;
|
|
#endif
|
|
|
|
table = mp->ma_table;
|
|
assert(table != NULL);
|
|
table_is_malloced = table != mp->ma_smalltable;
|
|
|
|
/* This is delicate. During the process of clearing the dict,
|
|
* decrefs can cause the dict to mutate. To avoid fatal confusion
|
|
* (voice of experience), we have to make the dict empty before
|
|
* clearing the slots, and never refer to anything via mp->xxx while
|
|
* clearing.
|
|
*/
|
|
fill = mp->ma_fill;
|
|
if (table_is_malloced)
|
|
EMPTY_TO_MINSIZE(mp);
|
|
|
|
else if (fill > 0) {
|
|
/* It's a small table with something that needs to be cleared.
|
|
* Afraid the only safe way is to copy the dict entries into
|
|
* another small table first.
|
|
*/
|
|
memcpy(small_copy, table, sizeof(small_copy));
|
|
table = small_copy;
|
|
EMPTY_TO_MINSIZE(mp);
|
|
}
|
|
/* else it's a small table that's already empty */
|
|
|
|
/* Now we can finally clear things. If C had refcounts, we could
|
|
* assert that the refcount on table is 1 now, i.e. that this function
|
|
* has unique access to it, so decref side-effects can't alter it.
|
|
*/
|
|
for (ep = table; fill > 0; ++ep) {
|
|
#ifdef Py_DEBUG
|
|
assert(i < n);
|
|
++i;
|
|
#endif
|
|
if (ep->me_key) {
|
|
--fill;
|
|
Py_DECREF(ep->me_key);
|
|
Py_XDECREF(ep->me_value);
|
|
}
|
|
#ifdef Py_DEBUG
|
|
else
|
|
assert(ep->me_value == NULL);
|
|
#endif
|
|
}
|
|
|
|
if (table_is_malloced)
|
|
PyMem_DEL(table);
|
|
}
|
|
|
|
/*
|
|
* Iterate over a dict. Use like so:
|
|
*
|
|
* Py_ssize_t i;
|
|
* PyObject *key, *value;
|
|
* i = 0; # important! i should not otherwise be changed by you
|
|
* while (PyDict_Next(yourdict, &i, &key, &value)) {
|
|
* Refer to borrowed references in key and value.
|
|
* }
|
|
*
|
|
* CAUTION: In general, it isn't safe to use PyDict_Next in a loop that
|
|
* mutates the dict. One exception: it is safe if the loop merely changes
|
|
* the values associated with the keys (but doesn't insert new keys or
|
|
* delete keys), via PyDict_SetItem().
|
|
*/
|
|
int
|
|
PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
|
|
{
|
|
register Py_ssize_t i;
|
|
register Py_ssize_t mask;
|
|
register dictentry *ep;
|
|
|
|
if (!PyDict_Check(op))
|
|
return 0;
|
|
i = *ppos;
|
|
if (i < 0)
|
|
return 0;
|
|
ep = ((dictobject *)op)->ma_table;
|
|
mask = ((dictobject *)op)->ma_mask;
|
|
while (i <= mask && ep[i].me_value == NULL)
|
|
i++;
|
|
*ppos = i+1;
|
|
if (i > mask)
|
|
return 0;
|
|
if (pkey)
|
|
*pkey = ep[i].me_key;
|
|
if (pvalue)
|
|
*pvalue = ep[i].me_value;
|
|
return 1;
|
|
}
|
|
|
|
/* Internal version of PyDict_Next that returns a hash value in addition to the key and value.*/
|
|
int
|
|
_PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue, long *phash)
|
|
{
|
|
register Py_ssize_t i;
|
|
register Py_ssize_t mask;
|
|
register dictentry *ep;
|
|
|
|
if (!PyDict_Check(op))
|
|
return 0;
|
|
i = *ppos;
|
|
if (i < 0)
|
|
return 0;
|
|
ep = ((dictobject *)op)->ma_table;
|
|
mask = ((dictobject *)op)->ma_mask;
|
|
while (i <= mask && ep[i].me_value == NULL)
|
|
i++;
|
|
*ppos = i+1;
|
|
if (i > mask)
|
|
return 0;
|
|
*phash = (long)(ep[i].me_hash);
|
|
if (pkey)
|
|
*pkey = ep[i].me_key;
|
|
if (pvalue)
|
|
*pvalue = ep[i].me_value;
|
|
return 1;
|
|
}
|
|
|
|
/* Methods */
|
|
|
|
static void
|
|
dict_dealloc(register dictobject *mp)
|
|
{
|
|
register dictentry *ep;
|
|
Py_ssize_t fill = mp->ma_fill;
|
|
PyObject_GC_UnTrack(mp);
|
|
Py_TRASHCAN_SAFE_BEGIN(mp)
|
|
for (ep = mp->ma_table; fill > 0; ep++) {
|
|
if (ep->me_key) {
|
|
--fill;
|
|
Py_DECREF(ep->me_key);
|
|
Py_XDECREF(ep->me_value);
|
|
}
|
|
}
|
|
if (mp->ma_table != mp->ma_smalltable)
|
|
PyMem_DEL(mp->ma_table);
|
|
if (num_free_dicts < MAXFREEDICTS && mp->ob_type == &PyDict_Type)
|
|
free_dicts[num_free_dicts++] = mp;
|
|
else
|
|
mp->ob_type->tp_free((PyObject *)mp);
|
|
Py_TRASHCAN_SAFE_END(mp)
|
|
}
|
|
|
|
static int
|
|
dict_print(register dictobject *mp, register FILE *fp, register int flags)
|
|
{
|
|
register Py_ssize_t i;
|
|
register Py_ssize_t any;
|
|
int status;
|
|
|
|
status = Py_ReprEnter((PyObject*)mp);
|
|
if (status != 0) {
|
|
if (status < 0)
|
|
return status;
|
|
fprintf(fp, "{...}");
|
|
return 0;
|
|
}
|
|
|
|
fprintf(fp, "{");
|
|
any = 0;
|
|
for (i = 0; i <= mp->ma_mask; i++) {
|
|
dictentry *ep = mp->ma_table + i;
|
|
PyObject *pvalue = ep->me_value;
|
|
if (pvalue != NULL) {
|
|
/* Prevent PyObject_Repr from deleting value during
|
|
key format */
|
|
Py_INCREF(pvalue);
|
|
if (any++ > 0)
|
|
fprintf(fp, ", ");
|
|
if (PyObject_Print((PyObject *)ep->me_key, fp, 0)!=0) {
|
|
Py_DECREF(pvalue);
|
|
Py_ReprLeave((PyObject*)mp);
|
|
return -1;
|
|
}
|
|
fprintf(fp, ": ");
|
|
if (PyObject_Print(pvalue, fp, 0) != 0) {
|
|
Py_DECREF(pvalue);
|
|
Py_ReprLeave((PyObject*)mp);
|
|
return -1;
|
|
}
|
|
Py_DECREF(pvalue);
|
|
}
|
|
}
|
|
fprintf(fp, "}");
|
|
Py_ReprLeave((PyObject*)mp);
|
|
return 0;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_repr(dictobject *mp)
|
|
{
|
|
Py_ssize_t i;
|
|
PyObject *s, *temp, *colon = NULL;
|
|
PyObject *pieces = NULL, *result = NULL;
|
|
PyObject *key, *value;
|
|
|
|
i = Py_ReprEnter((PyObject *)mp);
|
|
if (i != 0) {
|
|
return i > 0 ? PyString_FromString("{...}") : NULL;
|
|
}
|
|
|
|
if (mp->ma_used == 0) {
|
|
result = PyString_FromString("{}");
|
|
goto Done;
|
|
}
|
|
|
|
pieces = PyList_New(0);
|
|
if (pieces == NULL)
|
|
goto Done;
|
|
|
|
colon = PyString_FromString(": ");
|
|
if (colon == NULL)
|
|
goto Done;
|
|
|
|
/* Do repr() on each key+value pair, and insert ": " between them.
|
|
Note that repr may mutate the dict. */
|
|
i = 0;
|
|
while (PyDict_Next((PyObject *)mp, &i, &key, &value)) {
|
|
int status;
|
|
/* Prevent repr from deleting value during key format. */
|
|
Py_INCREF(value);
|
|
s = PyObject_Repr(key);
|
|
PyString_Concat(&s, colon);
|
|
PyString_ConcatAndDel(&s, PyObject_Repr(value));
|
|
Py_DECREF(value);
|
|
if (s == NULL)
|
|
goto Done;
|
|
status = PyList_Append(pieces, s);
|
|
Py_DECREF(s); /* append created a new ref */
|
|
if (status < 0)
|
|
goto Done;
|
|
}
|
|
|
|
/* Add "{}" decorations to the first and last items. */
|
|
assert(PyList_GET_SIZE(pieces) > 0);
|
|
s = PyString_FromString("{");
|
|
if (s == NULL)
|
|
goto Done;
|
|
temp = PyList_GET_ITEM(pieces, 0);
|
|
PyString_ConcatAndDel(&s, temp);
|
|
PyList_SET_ITEM(pieces, 0, s);
|
|
if (s == NULL)
|
|
goto Done;
|
|
|
|
s = PyString_FromString("}");
|
|
if (s == NULL)
|
|
goto Done;
|
|
temp = PyList_GET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1);
|
|
PyString_ConcatAndDel(&temp, s);
|
|
PyList_SET_ITEM(pieces, PyList_GET_SIZE(pieces) - 1, temp);
|
|
if (temp == NULL)
|
|
goto Done;
|
|
|
|
/* Paste them all together with ", " between. */
|
|
s = PyString_FromString(", ");
|
|
if (s == NULL)
|
|
goto Done;
|
|
result = _PyString_Join(s, pieces);
|
|
Py_DECREF(s);
|
|
|
|
Done:
|
|
Py_XDECREF(pieces);
|
|
Py_XDECREF(colon);
|
|
Py_ReprLeave((PyObject *)mp);
|
|
return result;
|
|
}
|
|
|
|
static Py_ssize_t
|
|
dict_length(dictobject *mp)
|
|
{
|
|
return mp->ma_used;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_subscript(dictobject *mp, register PyObject *key)
|
|
{
|
|
PyObject *v;
|
|
long hash;
|
|
dictentry *ep;
|
|
assert(mp->ma_table != NULL);
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return NULL;
|
|
}
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
v = ep->me_value;
|
|
if (v == NULL) {
|
|
if (!PyDict_CheckExact(mp)) {
|
|
/* Look up __missing__ method if we're a subclass. */
|
|
PyObject *missing;
|
|
static PyObject *missing_str = NULL;
|
|
if (missing_str == NULL)
|
|
missing_str =
|
|
PyString_InternFromString("__missing__");
|
|
missing = _PyType_Lookup(mp->ob_type, missing_str);
|
|
if (missing != NULL)
|
|
return PyObject_CallFunctionObjArgs(missing,
|
|
(PyObject *)mp, key, NULL);
|
|
}
|
|
set_key_error(key);
|
|
return NULL;
|
|
}
|
|
else
|
|
Py_INCREF(v);
|
|
return v;
|
|
}
|
|
|
|
static int
|
|
dict_ass_sub(dictobject *mp, PyObject *v, PyObject *w)
|
|
{
|
|
if (w == NULL)
|
|
return PyDict_DelItem((PyObject *)mp, v);
|
|
else
|
|
return PyDict_SetItem((PyObject *)mp, v, w);
|
|
}
|
|
|
|
static PyMappingMethods dict_as_mapping = {
|
|
(lenfunc)dict_length, /*mp_length*/
|
|
(binaryfunc)dict_subscript, /*mp_subscript*/
|
|
(objobjargproc)dict_ass_sub, /*mp_ass_subscript*/
|
|
};
|
|
|
|
static PyObject *
|
|
dict_keys(register dictobject *mp)
|
|
{
|
|
register PyObject *v;
|
|
register Py_ssize_t i, j;
|
|
dictentry *ep;
|
|
Py_ssize_t mask, n;
|
|
|
|
again:
|
|
n = mp->ma_used;
|
|
v = PyList_New(n);
|
|
if (v == NULL)
|
|
return NULL;
|
|
if (n != mp->ma_used) {
|
|
/* Durnit. The allocations caused the dict to resize.
|
|
* Just start over, this shouldn't normally happen.
|
|
*/
|
|
Py_DECREF(v);
|
|
goto again;
|
|
}
|
|
ep = mp->ma_table;
|
|
mask = mp->ma_mask;
|
|
for (i = 0, j = 0; i <= mask; i++) {
|
|
if (ep[i].me_value != NULL) {
|
|
PyObject *key = ep[i].me_key;
|
|
Py_INCREF(key);
|
|
PyList_SET_ITEM(v, j, key);
|
|
j++;
|
|
}
|
|
}
|
|
assert(j == n);
|
|
return v;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_values(register dictobject *mp)
|
|
{
|
|
register PyObject *v;
|
|
register Py_ssize_t i, j;
|
|
dictentry *ep;
|
|
Py_ssize_t mask, n;
|
|
|
|
again:
|
|
n = mp->ma_used;
|
|
v = PyList_New(n);
|
|
if (v == NULL)
|
|
return NULL;
|
|
if (n != mp->ma_used) {
|
|
/* Durnit. The allocations caused the dict to resize.
|
|
* Just start over, this shouldn't normally happen.
|
|
*/
|
|
Py_DECREF(v);
|
|
goto again;
|
|
}
|
|
ep = mp->ma_table;
|
|
mask = mp->ma_mask;
|
|
for (i = 0, j = 0; i <= mask; i++) {
|
|
if (ep[i].me_value != NULL) {
|
|
PyObject *value = ep[i].me_value;
|
|
Py_INCREF(value);
|
|
PyList_SET_ITEM(v, j, value);
|
|
j++;
|
|
}
|
|
}
|
|
assert(j == n);
|
|
return v;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_items(register dictobject *mp)
|
|
{
|
|
register PyObject *v;
|
|
register Py_ssize_t i, j, n;
|
|
Py_ssize_t mask;
|
|
PyObject *item, *key, *value;
|
|
dictentry *ep;
|
|
|
|
/* Preallocate the list of tuples, to avoid allocations during
|
|
* the loop over the items, which could trigger GC, which
|
|
* could resize the dict. :-(
|
|
*/
|
|
again:
|
|
n = mp->ma_used;
|
|
v = PyList_New(n);
|
|
if (v == NULL)
|
|
return NULL;
|
|
for (i = 0; i < n; i++) {
|
|
item = PyTuple_New(2);
|
|
if (item == NULL) {
|
|
Py_DECREF(v);
|
|
return NULL;
|
|
}
|
|
PyList_SET_ITEM(v, i, item);
|
|
}
|
|
if (n != mp->ma_used) {
|
|
/* Durnit. The allocations caused the dict to resize.
|
|
* Just start over, this shouldn't normally happen.
|
|
*/
|
|
Py_DECREF(v);
|
|
goto again;
|
|
}
|
|
/* Nothing we do below makes any function calls. */
|
|
ep = mp->ma_table;
|
|
mask = mp->ma_mask;
|
|
for (i = 0, j = 0; i <= mask; i++) {
|
|
if ((value=ep[i].me_value) != NULL) {
|
|
key = ep[i].me_key;
|
|
item = PyList_GET_ITEM(v, j);
|
|
Py_INCREF(key);
|
|
PyTuple_SET_ITEM(item, 0, key);
|
|
Py_INCREF(value);
|
|
PyTuple_SET_ITEM(item, 1, value);
|
|
j++;
|
|
}
|
|
}
|
|
assert(j == n);
|
|
return v;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_fromkeys(PyObject *cls, PyObject *args)
|
|
{
|
|
PyObject *seq;
|
|
PyObject *value = Py_None;
|
|
PyObject *it; /* iter(seq) */
|
|
PyObject *key;
|
|
PyObject *d;
|
|
int status;
|
|
|
|
if (!PyArg_UnpackTuple(args, "fromkeys", 1, 2, &seq, &value))
|
|
return NULL;
|
|
|
|
d = PyObject_CallObject(cls, NULL);
|
|
if (d == NULL)
|
|
return NULL;
|
|
|
|
if (PyDict_CheckExact(d) && PyAnySet_CheckExact(seq)) {
|
|
dictobject *mp = (dictobject *)d;
|
|
Py_ssize_t pos = 0;
|
|
PyObject *key;
|
|
long hash;
|
|
|
|
if (dictresize(mp, PySet_GET_SIZE(seq)))
|
|
return NULL;
|
|
|
|
while (_PySet_NextEntry(seq, &pos, &key, &hash)) {
|
|
Py_INCREF(key);
|
|
Py_INCREF(value);
|
|
if (insertdict(mp, key, hash, value))
|
|
return NULL;
|
|
}
|
|
return d;
|
|
}
|
|
|
|
it = PyObject_GetIter(seq);
|
|
if (it == NULL){
|
|
Py_DECREF(d);
|
|
return NULL;
|
|
}
|
|
|
|
for (;;) {
|
|
key = PyIter_Next(it);
|
|
if (key == NULL) {
|
|
if (PyErr_Occurred())
|
|
goto Fail;
|
|
break;
|
|
}
|
|
status = PyObject_SetItem(d, key, value);
|
|
Py_DECREF(key);
|
|
if (status < 0)
|
|
goto Fail;
|
|
}
|
|
|
|
Py_DECREF(it);
|
|
return d;
|
|
|
|
Fail:
|
|
Py_DECREF(it);
|
|
Py_DECREF(d);
|
|
return NULL;
|
|
}
|
|
|
|
static int
|
|
dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, char *methname)
|
|
{
|
|
PyObject *arg = NULL;
|
|
int result = 0;
|
|
|
|
if (!PyArg_UnpackTuple(args, methname, 0, 1, &arg))
|
|
result = -1;
|
|
|
|
else if (arg != NULL) {
|
|
if (PyObject_HasAttrString(arg, "keys"))
|
|
result = PyDict_Merge(self, arg, 1);
|
|
else
|
|
result = PyDict_MergeFromSeq2(self, arg, 1);
|
|
}
|
|
if (result == 0 && kwds != NULL)
|
|
result = PyDict_Merge(self, kwds, 1);
|
|
return result;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_update(PyObject *self, PyObject *args, PyObject *kwds)
|
|
{
|
|
if (dict_update_common(self, args, kwds, "update") != -1)
|
|
Py_RETURN_NONE;
|
|
return NULL;
|
|
}
|
|
|
|
/* Update unconditionally replaces existing items.
|
|
Merge has a 3rd argument 'override'; if set, it acts like Update,
|
|
otherwise it leaves existing items unchanged.
|
|
|
|
PyDict_{Update,Merge} update/merge from a mapping object.
|
|
|
|
PyDict_MergeFromSeq2 updates/merges from any iterable object
|
|
producing iterable objects of length 2.
|
|
*/
|
|
|
|
int
|
|
PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override)
|
|
{
|
|
PyObject *it; /* iter(seq2) */
|
|
Py_ssize_t i; /* index into seq2 of current element */
|
|
PyObject *item; /* seq2[i] */
|
|
PyObject *fast; /* item as a 2-tuple or 2-list */
|
|
|
|
assert(d != NULL);
|
|
assert(PyDict_Check(d));
|
|
assert(seq2 != NULL);
|
|
|
|
it = PyObject_GetIter(seq2);
|
|
if (it == NULL)
|
|
return -1;
|
|
|
|
for (i = 0; ; ++i) {
|
|
PyObject *key, *value;
|
|
Py_ssize_t n;
|
|
|
|
fast = NULL;
|
|
item = PyIter_Next(it);
|
|
if (item == NULL) {
|
|
if (PyErr_Occurred())
|
|
goto Fail;
|
|
break;
|
|
}
|
|
|
|
/* Convert item to sequence, and verify length 2. */
|
|
fast = PySequence_Fast(item, "");
|
|
if (fast == NULL) {
|
|
if (PyErr_ExceptionMatches(PyExc_TypeError))
|
|
PyErr_Format(PyExc_TypeError,
|
|
"cannot convert dictionary update "
|
|
"sequence element #%zd to a sequence",
|
|
i);
|
|
goto Fail;
|
|
}
|
|
n = PySequence_Fast_GET_SIZE(fast);
|
|
if (n != 2) {
|
|
PyErr_Format(PyExc_ValueError,
|
|
"dictionary update sequence element #%zd "
|
|
"has length %zd; 2 is required",
|
|
i, n);
|
|
goto Fail;
|
|
}
|
|
|
|
/* Update/merge with this (key, value) pair. */
|
|
key = PySequence_Fast_GET_ITEM(fast, 0);
|
|
value = PySequence_Fast_GET_ITEM(fast, 1);
|
|
if (override || PyDict_GetItem(d, key) == NULL) {
|
|
int status = PyDict_SetItem(d, key, value);
|
|
if (status < 0)
|
|
goto Fail;
|
|
}
|
|
Py_DECREF(fast);
|
|
Py_DECREF(item);
|
|
}
|
|
|
|
i = 0;
|
|
goto Return;
|
|
Fail:
|
|
Py_XDECREF(item);
|
|
Py_XDECREF(fast);
|
|
i = -1;
|
|
Return:
|
|
Py_DECREF(it);
|
|
return Py_SAFE_DOWNCAST(i, Py_ssize_t, int);
|
|
}
|
|
|
|
int
|
|
PyDict_Update(PyObject *a, PyObject *b)
|
|
{
|
|
return PyDict_Merge(a, b, 1);
|
|
}
|
|
|
|
int
|
|
PyDict_Merge(PyObject *a, PyObject *b, int override)
|
|
{
|
|
register PyDictObject *mp, *other;
|
|
register Py_ssize_t i;
|
|
dictentry *entry;
|
|
|
|
/* We accept for the argument either a concrete dictionary object,
|
|
* or an abstract "mapping" object. For the former, we can do
|
|
* things quite efficiently. For the latter, we only require that
|
|
* PyMapping_Keys() and PyObject_GetItem() be supported.
|
|
*/
|
|
if (a == NULL || !PyDict_Check(a) || b == NULL) {
|
|
PyErr_BadInternalCall();
|
|
return -1;
|
|
}
|
|
mp = (dictobject*)a;
|
|
if (PyDict_CheckExact(b)) {
|
|
other = (dictobject*)b;
|
|
if (other == mp || other->ma_used == 0)
|
|
/* a.update(a) or a.update({}); nothing to do */
|
|
return 0;
|
|
if (mp->ma_used == 0)
|
|
/* Since the target dict is empty, PyDict_GetItem()
|
|
* always returns NULL. Setting override to 1
|
|
* skips the unnecessary test.
|
|
*/
|
|
override = 1;
|
|
/* Do one big resize at the start, rather than
|
|
* incrementally resizing as we insert new items. Expect
|
|
* that there will be no (or few) overlapping keys.
|
|
*/
|
|
if ((mp->ma_fill + other->ma_used)*3 >= (mp->ma_mask+1)*2) {
|
|
if (dictresize(mp, (mp->ma_used + other->ma_used)*2) != 0)
|
|
return -1;
|
|
}
|
|
for (i = 0; i <= other->ma_mask; i++) {
|
|
entry = &other->ma_table[i];
|
|
if (entry->me_value != NULL &&
|
|
(override ||
|
|
PyDict_GetItem(a, entry->me_key) == NULL)) {
|
|
Py_INCREF(entry->me_key);
|
|
Py_INCREF(entry->me_value);
|
|
if (insertdict(mp, entry->me_key,
|
|
(long)entry->me_hash,
|
|
entry->me_value) != 0)
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
/* Do it the generic, slower way */
|
|
PyObject *keys = PyMapping_Keys(b);
|
|
PyObject *iter;
|
|
PyObject *key, *value;
|
|
int status;
|
|
|
|
if (keys == NULL)
|
|
/* Docstring says this is equivalent to E.keys() so
|
|
* if E doesn't have a .keys() method we want
|
|
* AttributeError to percolate up. Might as well
|
|
* do the same for any other error.
|
|
*/
|
|
return -1;
|
|
|
|
iter = PyObject_GetIter(keys);
|
|
Py_DECREF(keys);
|
|
if (iter == NULL)
|
|
return -1;
|
|
|
|
for (key = PyIter_Next(iter); key; key = PyIter_Next(iter)) {
|
|
if (!override && PyDict_GetItem(a, key) != NULL) {
|
|
Py_DECREF(key);
|
|
continue;
|
|
}
|
|
value = PyObject_GetItem(b, key);
|
|
if (value == NULL) {
|
|
Py_DECREF(iter);
|
|
Py_DECREF(key);
|
|
return -1;
|
|
}
|
|
status = PyDict_SetItem(a, key, value);
|
|
Py_DECREF(key);
|
|
Py_DECREF(value);
|
|
if (status < 0) {
|
|
Py_DECREF(iter);
|
|
return -1;
|
|
}
|
|
}
|
|
Py_DECREF(iter);
|
|
if (PyErr_Occurred())
|
|
/* Iterator completed, via error */
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_copy(register dictobject *mp)
|
|
{
|
|
return PyDict_Copy((PyObject*)mp);
|
|
}
|
|
|
|
PyObject *
|
|
PyDict_Copy(PyObject *o)
|
|
{
|
|
PyObject *copy;
|
|
|
|
if (o == NULL || !PyDict_Check(o)) {
|
|
PyErr_BadInternalCall();
|
|
return NULL;
|
|
}
|
|
copy = PyDict_New();
|
|
if (copy == NULL)
|
|
return NULL;
|
|
if (PyDict_Merge(copy, o, 1) == 0)
|
|
return copy;
|
|
Py_DECREF(copy);
|
|
return NULL;
|
|
}
|
|
|
|
Py_ssize_t
|
|
PyDict_Size(PyObject *mp)
|
|
{
|
|
if (mp == NULL || !PyDict_Check(mp)) {
|
|
PyErr_BadInternalCall();
|
|
return -1;
|
|
}
|
|
return ((dictobject *)mp)->ma_used;
|
|
}
|
|
|
|
PyObject *
|
|
PyDict_Keys(PyObject *mp)
|
|
{
|
|
if (mp == NULL || !PyDict_Check(mp)) {
|
|
PyErr_BadInternalCall();
|
|
return NULL;
|
|
}
|
|
return dict_keys((dictobject *)mp);
|
|
}
|
|
|
|
PyObject *
|
|
PyDict_Values(PyObject *mp)
|
|
{
|
|
if (mp == NULL || !PyDict_Check(mp)) {
|
|
PyErr_BadInternalCall();
|
|
return NULL;
|
|
}
|
|
return dict_values((dictobject *)mp);
|
|
}
|
|
|
|
PyObject *
|
|
PyDict_Items(PyObject *mp)
|
|
{
|
|
if (mp == NULL || !PyDict_Check(mp)) {
|
|
PyErr_BadInternalCall();
|
|
return NULL;
|
|
}
|
|
return dict_items((dictobject *)mp);
|
|
}
|
|
|
|
/* Return 1 if dicts equal, 0 if not, -1 if error.
|
|
* Gets out as soon as any difference is detected.
|
|
* Uses only Py_EQ comparison.
|
|
*/
|
|
static int
|
|
dict_equal(dictobject *a, dictobject *b)
|
|
{
|
|
Py_ssize_t i;
|
|
|
|
if (a->ma_used != b->ma_used)
|
|
/* can't be equal if # of entries differ */
|
|
return 0;
|
|
|
|
/* Same # of entries -- check all of 'em. Exit early on any diff. */
|
|
for (i = 0; i <= a->ma_mask; i++) {
|
|
PyObject *aval = a->ma_table[i].me_value;
|
|
if (aval != NULL) {
|
|
int cmp;
|
|
PyObject *bval;
|
|
PyObject *key = a->ma_table[i].me_key;
|
|
/* temporarily bump aval's refcount to ensure it stays
|
|
alive until we're done with it */
|
|
Py_INCREF(aval);
|
|
/* ditto for key */
|
|
Py_INCREF(key);
|
|
bval = PyDict_GetItemWithError((PyObject *)b, key);
|
|
Py_DECREF(key);
|
|
if (bval == NULL) {
|
|
Py_DECREF(aval);
|
|
if (PyErr_Occurred())
|
|
return -1;
|
|
return 0;
|
|
}
|
|
cmp = PyObject_RichCompareBool(aval, bval, Py_EQ);
|
|
Py_DECREF(aval);
|
|
if (cmp <= 0) /* error or not equal */
|
|
return cmp;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_richcompare(PyObject *v, PyObject *w, int op)
|
|
{
|
|
int cmp;
|
|
PyObject *res;
|
|
|
|
if (!PyDict_Check(v) || !PyDict_Check(w)) {
|
|
res = Py_NotImplemented;
|
|
}
|
|
else if (op == Py_EQ || op == Py_NE) {
|
|
cmp = dict_equal((dictobject *)v, (dictobject *)w);
|
|
if (cmp < 0)
|
|
return NULL;
|
|
res = (cmp == (op == Py_EQ)) ? Py_True : Py_False;
|
|
}
|
|
else
|
|
res = Py_NotImplemented;
|
|
Py_INCREF(res);
|
|
return res;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_contains(register dictobject *mp, PyObject *key)
|
|
{
|
|
long hash;
|
|
dictentry *ep;
|
|
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return NULL;
|
|
}
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
return PyBool_FromLong(ep->me_value != NULL);
|
|
}
|
|
|
|
static PyObject *
|
|
dict_get(register dictobject *mp, PyObject *args)
|
|
{
|
|
PyObject *key;
|
|
PyObject *failobj = Py_None;
|
|
PyObject *val = NULL;
|
|
long hash;
|
|
dictentry *ep;
|
|
|
|
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj))
|
|
return NULL;
|
|
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return NULL;
|
|
}
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
val = ep->me_value;
|
|
if (val == NULL)
|
|
val = failobj;
|
|
Py_INCREF(val);
|
|
return val;
|
|
}
|
|
|
|
|
|
static PyObject *
|
|
dict_setdefault(register dictobject *mp, PyObject *args)
|
|
{
|
|
PyObject *key;
|
|
PyObject *failobj = Py_None;
|
|
PyObject *val = NULL;
|
|
long hash;
|
|
dictentry *ep;
|
|
|
|
if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
|
|
return NULL;
|
|
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return NULL;
|
|
}
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
val = ep->me_value;
|
|
if (val == NULL) {
|
|
val = failobj;
|
|
if (PyDict_SetItem((PyObject*)mp, key, failobj))
|
|
val = NULL;
|
|
}
|
|
Py_XINCREF(val);
|
|
return val;
|
|
}
|
|
|
|
|
|
static PyObject *
|
|
dict_clear(register dictobject *mp)
|
|
{
|
|
PyDict_Clear((PyObject *)mp);
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_pop(dictobject *mp, PyObject *args)
|
|
{
|
|
long hash;
|
|
dictentry *ep;
|
|
PyObject *old_value, *old_key;
|
|
PyObject *key, *deflt = NULL;
|
|
|
|
if(!PyArg_UnpackTuple(args, "pop", 1, 2, &key, &deflt))
|
|
return NULL;
|
|
if (mp->ma_used == 0) {
|
|
if (deflt) {
|
|
Py_INCREF(deflt);
|
|
return deflt;
|
|
}
|
|
PyErr_SetString(PyExc_KeyError,
|
|
"pop(): dictionary is empty");
|
|
return NULL;
|
|
}
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return NULL;
|
|
}
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
if (ep == NULL)
|
|
return NULL;
|
|
if (ep->me_value == NULL) {
|
|
if (deflt) {
|
|
Py_INCREF(deflt);
|
|
return deflt;
|
|
}
|
|
set_key_error(key);
|
|
return NULL;
|
|
}
|
|
old_key = ep->me_key;
|
|
Py_INCREF(dummy);
|
|
ep->me_key = dummy;
|
|
old_value = ep->me_value;
|
|
ep->me_value = NULL;
|
|
mp->ma_used--;
|
|
Py_DECREF(old_key);
|
|
return old_value;
|
|
}
|
|
|
|
static PyObject *
|
|
dict_popitem(dictobject *mp)
|
|
{
|
|
Py_ssize_t i = 0;
|
|
dictentry *ep;
|
|
PyObject *res;
|
|
|
|
/* Allocate the result tuple before checking the size. Believe it
|
|
* or not, this allocation could trigger a garbage collection which
|
|
* could empty the dict, so if we checked the size first and that
|
|
* happened, the result would be an infinite loop (searching for an
|
|
* entry that no longer exists). Note that the usual popitem()
|
|
* idiom is "while d: k, v = d.popitem()". so needing to throw the
|
|
* tuple away if the dict *is* empty isn't a significant
|
|
* inefficiency -- possible, but unlikely in practice.
|
|
*/
|
|
res = PyTuple_New(2);
|
|
if (res == NULL)
|
|
return NULL;
|
|
if (mp->ma_used == 0) {
|
|
Py_DECREF(res);
|
|
PyErr_SetString(PyExc_KeyError,
|
|
"popitem(): dictionary is empty");
|
|
return NULL;
|
|
}
|
|
/* Set ep to "the first" dict entry with a value. We abuse the hash
|
|
* field of slot 0 to hold a search finger:
|
|
* If slot 0 has a value, use slot 0.
|
|
* Else slot 0 is being used to hold a search finger,
|
|
* and we use its hash value as the first index to look.
|
|
*/
|
|
ep = &mp->ma_table[0];
|
|
if (ep->me_value == NULL) {
|
|
i = ep->me_hash;
|
|
/* The hash field may be a real hash value, or it may be a
|
|
* legit search finger, or it may be a once-legit search
|
|
* finger that's out of bounds now because it wrapped around
|
|
* or the table shrunk -- simply make sure it's in bounds now.
|
|
*/
|
|
if (i > mp->ma_mask || i < 1)
|
|
i = 1; /* skip slot 0 */
|
|
while ((ep = &mp->ma_table[i])->me_value == NULL) {
|
|
i++;
|
|
if (i > mp->ma_mask)
|
|
i = 1;
|
|
}
|
|
}
|
|
PyTuple_SET_ITEM(res, 0, ep->me_key);
|
|
PyTuple_SET_ITEM(res, 1, ep->me_value);
|
|
Py_INCREF(dummy);
|
|
ep->me_key = dummy;
|
|
ep->me_value = NULL;
|
|
mp->ma_used--;
|
|
assert(mp->ma_table[0].me_value == NULL);
|
|
mp->ma_table[0].me_hash = i + 1; /* next place to start */
|
|
return res;
|
|
}
|
|
|
|
static int
|
|
dict_traverse(PyObject *op, visitproc visit, void *arg)
|
|
{
|
|
Py_ssize_t i = 0;
|
|
PyObject *pk;
|
|
PyObject *pv;
|
|
|
|
while (PyDict_Next(op, &i, &pk, &pv)) {
|
|
Py_VISIT(pk);
|
|
Py_VISIT(pv);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
dict_tp_clear(PyObject *op)
|
|
{
|
|
PyDict_Clear(op);
|
|
return 0;
|
|
}
|
|
|
|
|
|
extern PyTypeObject PyDictIterKey_Type; /* Forward */
|
|
extern PyTypeObject PyDictIterValue_Type; /* Forward */
|
|
extern PyTypeObject PyDictIterItem_Type; /* Forward */
|
|
static PyObject *dictiter_new(dictobject *, PyTypeObject *);
|
|
|
|
#if 0
|
|
static PyObject *
|
|
dict_iterkeys(dictobject *dict)
|
|
{
|
|
return dictiter_new(dict, &PyDictIterKey_Type);
|
|
}
|
|
|
|
static PyObject *
|
|
dict_itervalues(dictobject *dict)
|
|
{
|
|
return dictiter_new(dict, &PyDictIterValue_Type);
|
|
}
|
|
|
|
static PyObject *
|
|
dict_iteritems(dictobject *dict)
|
|
{
|
|
return dictiter_new(dict, &PyDictIterItem_Type);
|
|
}
|
|
#endif
|
|
|
|
|
|
PyDoc_STRVAR(contains__doc__,
|
|
"D.__contains__(k) -> True if D has a key k, else False");
|
|
|
|
PyDoc_STRVAR(getitem__doc__, "x.__getitem__(y) <==> x[y]");
|
|
|
|
PyDoc_STRVAR(get__doc__,
|
|
"D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.");
|
|
|
|
PyDoc_STRVAR(setdefault_doc__,
|
|
"D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D");
|
|
|
|
PyDoc_STRVAR(pop__doc__,
|
|
"D.pop(k[,d]) -> v, remove specified key and return the corresponding value\n\
|
|
If key is not found, d is returned if given, otherwise KeyError is raised");
|
|
|
|
PyDoc_STRVAR(popitem__doc__,
|
|
"D.popitem() -> (k, v), remove and return some (key, value) pair as a\n\
|
|
2-tuple; but raise KeyError if D is empty");
|
|
|
|
#if 0
|
|
PyDoc_STRVAR(keys__doc__,
|
|
"D.keys() -> list of D's keys");
|
|
|
|
PyDoc_STRVAR(items__doc__,
|
|
"D.items() -> list of D's (key, value) pairs, as 2-tuples");
|
|
|
|
PyDoc_STRVAR(values__doc__,
|
|
"D.values() -> list of D's values");
|
|
#endif
|
|
|
|
PyDoc_STRVAR(update__doc__,
|
|
"D.update(E, **F) -> None. Update D from E and F: for k in E: D[k] = E[k]\
|
|
\n(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]");
|
|
|
|
PyDoc_STRVAR(fromkeys__doc__,
|
|
"dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n\
|
|
v defaults to None.");
|
|
|
|
PyDoc_STRVAR(clear__doc__,
|
|
"D.clear() -> None. Remove all items from D.");
|
|
|
|
PyDoc_STRVAR(copy__doc__,
|
|
"D.copy() -> a shallow copy of D");
|
|
|
|
#if 0
|
|
PyDoc_STRVAR(iterkeys__doc__,
|
|
"D.iterkeys() -> an iterator over the keys of D");
|
|
|
|
PyDoc_STRVAR(itervalues__doc__,
|
|
"D.itervalues() -> an iterator over the values of D");
|
|
|
|
PyDoc_STRVAR(iteritems__doc__,
|
|
"D.iteritems() -> an iterator over the (key, value) items of D");
|
|
#endif
|
|
|
|
/* Forward */
|
|
static PyObject *dictkeys_new(PyObject *);
|
|
static PyObject *dictitems_new(PyObject *);
|
|
static PyObject *dictvalues_new(PyObject *);
|
|
|
|
PyDoc_STRVAR(keys__doc__, "D.keys() -> a set-like object for D's keys");
|
|
PyDoc_STRVAR(items__doc__, "D.items() -> a set-like object for D's items");
|
|
PyDoc_STRVAR(values__doc__, "D.values() -> a set-like object for D's values");
|
|
|
|
static PyMethodDef mapp_methods[] = {
|
|
{"__contains__",(PyCFunction)dict_contains, METH_O | METH_COEXIST,
|
|
contains__doc__},
|
|
{"__getitem__", (PyCFunction)dict_subscript, METH_O | METH_COEXIST,
|
|
getitem__doc__},
|
|
{"get", (PyCFunction)dict_get, METH_VARARGS,
|
|
get__doc__},
|
|
{"setdefault", (PyCFunction)dict_setdefault, METH_VARARGS,
|
|
setdefault_doc__},
|
|
{"pop", (PyCFunction)dict_pop, METH_VARARGS,
|
|
pop__doc__},
|
|
{"popitem", (PyCFunction)dict_popitem, METH_NOARGS,
|
|
popitem__doc__},
|
|
#if 0
|
|
{"keys", (PyCFunction)dict_keys, METH_NOARGS,
|
|
keys__doc__},
|
|
{"items", (PyCFunction)dict_items, METH_NOARGS,
|
|
items__doc__},
|
|
{"values", (PyCFunction)dict_values, METH_NOARGS,
|
|
values__doc__},
|
|
#endif
|
|
{"keys", (PyCFunction)dictkeys_new, METH_NOARGS,
|
|
keys__doc__},
|
|
{"items", (PyCFunction)dictitems_new, METH_NOARGS,
|
|
items__doc__},
|
|
{"values", (PyCFunction)dictvalues_new, METH_NOARGS,
|
|
values__doc__},
|
|
{"update", (PyCFunction)dict_update, METH_VARARGS | METH_KEYWORDS,
|
|
update__doc__},
|
|
{"fromkeys", (PyCFunction)dict_fromkeys, METH_VARARGS | METH_CLASS,
|
|
fromkeys__doc__},
|
|
{"clear", (PyCFunction)dict_clear, METH_NOARGS,
|
|
clear__doc__},
|
|
{"copy", (PyCFunction)dict_copy, METH_NOARGS,
|
|
copy__doc__},
|
|
#if 0
|
|
{"iterkeys", (PyCFunction)dict_iterkeys, METH_NOARGS,
|
|
iterkeys__doc__},
|
|
{"itervalues", (PyCFunction)dict_itervalues, METH_NOARGS,
|
|
itervalues__doc__},
|
|
{"iteritems", (PyCFunction)dict_iteritems, METH_NOARGS,
|
|
iteritems__doc__},
|
|
#endif
|
|
{NULL, NULL} /* sentinel */
|
|
};
|
|
|
|
/* Return 1 if `key` is in dict `op`, 0 if not, and -1 on error. */
|
|
int
|
|
PyDict_Contains(PyObject *op, PyObject *key)
|
|
{
|
|
long hash;
|
|
dictobject *mp = (dictobject *)op;
|
|
dictentry *ep;
|
|
|
|
if (!PyString_CheckExact(key) ||
|
|
(hash = ((PyStringObject *) key)->ob_shash) == -1) {
|
|
hash = PyObject_Hash(key);
|
|
if (hash == -1)
|
|
return -1;
|
|
}
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
return ep == NULL ? -1 : (ep->me_value != NULL);
|
|
}
|
|
|
|
/* Internal version of PyDict_Contains used when the hash value is already known */
|
|
int
|
|
_PyDict_Contains(PyObject *op, PyObject *key, long hash)
|
|
{
|
|
dictobject *mp = (dictobject *)op;
|
|
dictentry *ep;
|
|
|
|
ep = (mp->ma_lookup)(mp, key, hash);
|
|
return ep == NULL ? -1 : (ep->me_value != NULL);
|
|
}
|
|
|
|
/* Hack to implement "key in dict" */
|
|
static PySequenceMethods dict_as_sequence = {
|
|
0, /* sq_length */
|
|
0, /* sq_concat */
|
|
0, /* sq_repeat */
|
|
0, /* sq_item */
|
|
0, /* sq_slice */
|
|
0, /* sq_ass_item */
|
|
0, /* sq_ass_slice */
|
|
PyDict_Contains, /* sq_contains */
|
|
0, /* sq_inplace_concat */
|
|
0, /* sq_inplace_repeat */
|
|
};
|
|
|
|
static PyObject *
|
|
dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|
{
|
|
PyObject *self;
|
|
|
|
assert(type != NULL && type->tp_alloc != NULL);
|
|
self = type->tp_alloc(type, 0);
|
|
if (self != NULL) {
|
|
PyDictObject *d = (PyDictObject *)self;
|
|
/* It's guaranteed that tp->alloc zeroed out the struct. */
|
|
assert(d->ma_table == NULL && d->ma_fill == 0 && d->ma_used == 0);
|
|
INIT_NONZERO_DICT_SLOTS(d);
|
|
d->ma_lookup = lookdict_string;
|
|
#ifdef SHOW_CONVERSION_COUNTS
|
|
++created;
|
|
#endif
|
|
}
|
|
return self;
|
|
}
|
|
|
|
static int
|
|
dict_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|
{
|
|
return dict_update_common(self, args, kwds, "dict");
|
|
}
|
|
|
|
static PyObject *
|
|
dict_iter(dictobject *dict)
|
|
{
|
|
return dictiter_new(dict, &PyDictIterKey_Type);
|
|
}
|
|
|
|
PyDoc_STRVAR(dictionary_doc,
|
|
"dict() -> new empty dictionary.\n"
|
|
"dict(mapping) -> new dictionary initialized from a mapping object's\n"
|
|
" (key, value) pairs.\n"
|
|
"dict(seq) -> new dictionary initialized as if via:\n"
|
|
" d = {}\n"
|
|
" for k, v in seq:\n"
|
|
" d[k] = v\n"
|
|
"dict(**kwargs) -> new dictionary initialized with the name=value pairs\n"
|
|
" in the keyword argument list. For example: dict(one=1, two=2)");
|
|
|
|
PyTypeObject PyDict_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0,
|
|
"dict",
|
|
sizeof(dictobject),
|
|
0,
|
|
(destructor)dict_dealloc, /* tp_dealloc */
|
|
(printfunc)dict_print, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
(reprfunc)dict_repr, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
&dict_as_sequence, /* tp_as_sequence */
|
|
&dict_as_mapping, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
0, /* tp_str */
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
|
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_DICT_SUBCLASS, /* tp_flags */
|
|
dictionary_doc, /* tp_doc */
|
|
dict_traverse, /* tp_traverse */
|
|
dict_tp_clear, /* tp_clear */
|
|
dict_richcompare, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
(getiterfunc)dict_iter, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
mapp_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 */
|
|
dict_init, /* tp_init */
|
|
PyType_GenericAlloc, /* tp_alloc */
|
|
dict_new, /* tp_new */
|
|
PyObject_GC_Del, /* tp_free */
|
|
};
|
|
|
|
/* For backward compatibility with old dictionary interface */
|
|
|
|
PyObject *
|
|
PyDict_GetItemString(PyObject *v, const char *key)
|
|
{
|
|
PyObject *kv, *rv;
|
|
kv = PyString_FromString(key);
|
|
if (kv == NULL)
|
|
return NULL;
|
|
rv = PyDict_GetItem(v, kv);
|
|
Py_DECREF(kv);
|
|
return rv;
|
|
}
|
|
|
|
int
|
|
PyDict_SetItemString(PyObject *v, const char *key, PyObject *item)
|
|
{
|
|
PyObject *kv;
|
|
int err;
|
|
kv = PyString_FromString(key);
|
|
if (kv == NULL)
|
|
return -1;
|
|
PyString_InternInPlace(&kv); /* XXX Should we really? */
|
|
err = PyDict_SetItem(v, kv, item);
|
|
Py_DECREF(kv);
|
|
return err;
|
|
}
|
|
|
|
int
|
|
PyDict_DelItemString(PyObject *v, const char *key)
|
|
{
|
|
PyObject *kv;
|
|
int err;
|
|
kv = PyString_FromString(key);
|
|
if (kv == NULL)
|
|
return -1;
|
|
err = PyDict_DelItem(v, kv);
|
|
Py_DECREF(kv);
|
|
return err;
|
|
}
|
|
|
|
/* Dictionary iterator types */
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
dictobject *di_dict; /* Set to NULL when iterator is exhausted */
|
|
Py_ssize_t di_used;
|
|
Py_ssize_t di_pos;
|
|
PyObject* di_result; /* reusable result tuple for iteritems */
|
|
Py_ssize_t len;
|
|
} dictiterobject;
|
|
|
|
static PyObject *
|
|
dictiter_new(dictobject *dict, PyTypeObject *itertype)
|
|
{
|
|
dictiterobject *di;
|
|
di = PyObject_New(dictiterobject, itertype);
|
|
if (di == NULL)
|
|
return NULL;
|
|
Py_INCREF(dict);
|
|
di->di_dict = dict;
|
|
di->di_used = dict->ma_used;
|
|
di->di_pos = 0;
|
|
di->len = dict->ma_used;
|
|
if (itertype == &PyDictIterItem_Type) {
|
|
di->di_result = PyTuple_Pack(2, Py_None, Py_None);
|
|
if (di->di_result == NULL) {
|
|
Py_DECREF(di);
|
|
return NULL;
|
|
}
|
|
}
|
|
else
|
|
di->di_result = NULL;
|
|
return (PyObject *)di;
|
|
}
|
|
|
|
static void
|
|
dictiter_dealloc(dictiterobject *di)
|
|
{
|
|
Py_XDECREF(di->di_dict);
|
|
Py_XDECREF(di->di_result);
|
|
PyObject_Del(di);
|
|
}
|
|
|
|
static PyObject *
|
|
dictiter_len(dictiterobject *di)
|
|
{
|
|
Py_ssize_t len = 0;
|
|
if (di->di_dict != NULL && di->di_used == di->di_dict->ma_used)
|
|
len = di->len;
|
|
return PyInt_FromSize_t(len);
|
|
}
|
|
|
|
PyDoc_STRVAR(length_hint_doc,
|
|
"Private method returning an estimate of len(list(it)).");
|
|
|
|
static PyMethodDef dictiter_methods[] = {
|
|
{"__length_hint__", (PyCFunction)dictiter_len, METH_NOARGS,
|
|
length_hint_doc},
|
|
{NULL, NULL} /* sentinel */
|
|
};
|
|
|
|
static PyObject *dictiter_iternextkey(dictiterobject *di)
|
|
{
|
|
PyObject *key;
|
|
register Py_ssize_t i, mask;
|
|
register dictentry *ep;
|
|
dictobject *d = di->di_dict;
|
|
|
|
if (d == NULL)
|
|
return NULL;
|
|
assert (PyDict_Check(d));
|
|
|
|
if (di->di_used != d->ma_used) {
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"dictionary changed size during iteration");
|
|
di->di_used = -1; /* Make this state sticky */
|
|
return NULL;
|
|
}
|
|
|
|
i = di->di_pos;
|
|
if (i < 0)
|
|
goto fail;
|
|
ep = d->ma_table;
|
|
mask = d->ma_mask;
|
|
while (i <= mask && ep[i].me_value == NULL)
|
|
i++;
|
|
di->di_pos = i+1;
|
|
if (i > mask)
|
|
goto fail;
|
|
di->len--;
|
|
key = ep[i].me_key;
|
|
Py_INCREF(key);
|
|
return key;
|
|
|
|
fail:
|
|
Py_DECREF(d);
|
|
di->di_dict = NULL;
|
|
return NULL;
|
|
}
|
|
|
|
PyTypeObject PyDictIterKey_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0, /* ob_size */
|
|
"dictionary-keyiterator", /* tp_name */
|
|
sizeof(dictiterobject), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
/* methods */
|
|
(destructor)dictiter_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 */
|
|
PyObject_GenericGetAttr, /* 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 */
|
|
PyObject_SelfIter, /* tp_iter */
|
|
(iternextfunc)dictiter_iternextkey, /* tp_iternext */
|
|
dictiter_methods, /* tp_methods */
|
|
0,
|
|
};
|
|
|
|
static PyObject *dictiter_iternextvalue(dictiterobject *di)
|
|
{
|
|
PyObject *value;
|
|
register Py_ssize_t i, mask;
|
|
register dictentry *ep;
|
|
dictobject *d = di->di_dict;
|
|
|
|
if (d == NULL)
|
|
return NULL;
|
|
assert (PyDict_Check(d));
|
|
|
|
if (di->di_used != d->ma_used) {
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"dictionary changed size during iteration");
|
|
di->di_used = -1; /* Make this state sticky */
|
|
return NULL;
|
|
}
|
|
|
|
i = di->di_pos;
|
|
mask = d->ma_mask;
|
|
if (i < 0 || i > mask)
|
|
goto fail;
|
|
ep = d->ma_table;
|
|
while ((value=ep[i].me_value) == NULL) {
|
|
i++;
|
|
if (i > mask)
|
|
goto fail;
|
|
}
|
|
di->di_pos = i+1;
|
|
di->len--;
|
|
Py_INCREF(value);
|
|
return value;
|
|
|
|
fail:
|
|
Py_DECREF(d);
|
|
di->di_dict = NULL;
|
|
return NULL;
|
|
}
|
|
|
|
PyTypeObject PyDictIterValue_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0, /* ob_size */
|
|
"dictionary-valueiterator", /* tp_name */
|
|
sizeof(dictiterobject), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
/* methods */
|
|
(destructor)dictiter_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 */
|
|
PyObject_GenericGetAttr, /* 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 */
|
|
PyObject_SelfIter, /* tp_iter */
|
|
(iternextfunc)dictiter_iternextvalue, /* tp_iternext */
|
|
dictiter_methods, /* tp_methods */
|
|
0,
|
|
};
|
|
|
|
static PyObject *dictiter_iternextitem(dictiterobject *di)
|
|
{
|
|
PyObject *key, *value, *result = di->di_result;
|
|
register Py_ssize_t i, mask;
|
|
register dictentry *ep;
|
|
dictobject *d = di->di_dict;
|
|
|
|
if (d == NULL)
|
|
return NULL;
|
|
assert (PyDict_Check(d));
|
|
|
|
if (di->di_used != d->ma_used) {
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
"dictionary changed size during iteration");
|
|
di->di_used = -1; /* Make this state sticky */
|
|
return NULL;
|
|
}
|
|
|
|
i = di->di_pos;
|
|
if (i < 0)
|
|
goto fail;
|
|
ep = d->ma_table;
|
|
mask = d->ma_mask;
|
|
while (i <= mask && ep[i].me_value == NULL)
|
|
i++;
|
|
di->di_pos = i+1;
|
|
if (i > mask)
|
|
goto fail;
|
|
|
|
if (result->ob_refcnt == 1) {
|
|
Py_INCREF(result);
|
|
Py_DECREF(PyTuple_GET_ITEM(result, 0));
|
|
Py_DECREF(PyTuple_GET_ITEM(result, 1));
|
|
} else {
|
|
result = PyTuple_New(2);
|
|
if (result == NULL)
|
|
return NULL;
|
|
}
|
|
di->len--;
|
|
key = ep[i].me_key;
|
|
value = ep[i].me_value;
|
|
Py_INCREF(key);
|
|
Py_INCREF(value);
|
|
PyTuple_SET_ITEM(result, 0, key);
|
|
PyTuple_SET_ITEM(result, 1, value);
|
|
return result;
|
|
|
|
fail:
|
|
Py_DECREF(d);
|
|
di->di_dict = NULL;
|
|
return NULL;
|
|
}
|
|
|
|
PyTypeObject PyDictIterItem_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0, /* ob_size */
|
|
"dictionary-itemiterator", /* tp_name */
|
|
sizeof(dictiterobject), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
/* methods */
|
|
(destructor)dictiter_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 */
|
|
PyObject_GenericGetAttr, /* 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 */
|
|
PyObject_SelfIter, /* tp_iter */
|
|
(iternextfunc)dictiter_iternextitem, /* tp_iternext */
|
|
dictiter_methods, /* tp_methods */
|
|
0,
|
|
};
|
|
|
|
|
|
/***********************************************/
|
|
/* View objects for keys(), items(), values(). */
|
|
/***********************************************/
|
|
|
|
/* The instance lay-out is the same for all three; but the type differs. */
|
|
|
|
typedef struct {
|
|
PyObject_HEAD
|
|
dictobject *dv_dict;
|
|
} dictviewobject;
|
|
|
|
|
|
static void
|
|
dictview_dealloc(dictviewobject *dv)
|
|
{
|
|
Py_XDECREF(dv->dv_dict);
|
|
PyObject_Del(dv);
|
|
}
|
|
|
|
static Py_ssize_t
|
|
dictview_len(dictviewobject *dv)
|
|
{
|
|
Py_ssize_t len = 0;
|
|
if (dv->dv_dict != NULL)
|
|
len = dv->dv_dict->ma_used;
|
|
return len;
|
|
}
|
|
|
|
static PyObject *
|
|
dictview_new(PyObject *dict, PyTypeObject *type)
|
|
{
|
|
dictviewobject *dv;
|
|
if (dict == NULL) {
|
|
PyErr_BadInternalCall();
|
|
return NULL;
|
|
}
|
|
if (!PyDict_Check(dict)) {
|
|
/* XXX Get rid of this restriction later */
|
|
PyErr_Format(PyExc_TypeError,
|
|
"%s() requires a dict argument, not '%s'",
|
|
type->tp_name, dict->ob_type->tp_name);
|
|
return NULL;
|
|
}
|
|
dv = PyObject_New(dictviewobject, type);
|
|
if (dv == NULL)
|
|
return NULL;
|
|
Py_INCREF(dict);
|
|
dv->dv_dict = (dictobject *)dict;
|
|
return (PyObject *)dv;
|
|
}
|
|
|
|
/* TODO(guido): The views objects are not complete:
|
|
|
|
* support more set operations
|
|
* support arbitrary mappings?
|
|
- either these should be static or exported in dictobject.h
|
|
- if public then they should probably be in builtins
|
|
*/
|
|
|
|
/* Forward */
|
|
PyTypeObject PyDictKeys_Type;
|
|
PyTypeObject PyDictItems_Type;
|
|
PyTypeObject PyDictValues_Type;
|
|
|
|
#define PyDictKeys_Check(obj) ((obj)->ob_type == &PyDictKeys_Type)
|
|
#define PyDictItems_Check(obj) ((obj)->ob_type == &PyDictItems_Type)
|
|
#define PyDictValues_Check(obj) ((obj)->ob_type == &PyDictValues_Type)
|
|
|
|
/* This excludes Values, since they are not sets. */
|
|
# define PyDictViewSet_Check(obj) \
|
|
(PyDictKeys_Check(obj) || PyDictItems_Check(obj))
|
|
|
|
static int
|
|
all_contained_in(PyObject *self, PyObject *other)
|
|
{
|
|
PyObject *iter = PyObject_GetIter(self);
|
|
int ok = 1;
|
|
|
|
if (iter == NULL)
|
|
return -1;
|
|
for (;;) {
|
|
PyObject *next = PyIter_Next(iter);
|
|
if (next == NULL) {
|
|
if (PyErr_Occurred())
|
|
ok = -1;
|
|
break;
|
|
}
|
|
ok = PySequence_Contains(other, next);
|
|
Py_DECREF(next);
|
|
if (ok <= 0)
|
|
break;
|
|
}
|
|
Py_DECREF(iter);
|
|
return ok;
|
|
}
|
|
|
|
static PyObject *
|
|
dictview_richcompare(PyObject *self, PyObject *other, int op)
|
|
{
|
|
assert(self != NULL);
|
|
assert(PyDictViewSet_Check(self));
|
|
assert(other != NULL);
|
|
if ((op == Py_EQ || op == Py_NE) &&
|
|
(PyAnySet_Check(other) || PyDictViewSet_Check(other)))
|
|
{
|
|
Py_ssize_t len_self, len_other;
|
|
int ok;
|
|
PyObject *result;
|
|
|
|
len_self = PyObject_Size(self);
|
|
if (len_self < 0)
|
|
return NULL;
|
|
len_other = PyObject_Size(other);
|
|
if (len_other < 0)
|
|
return NULL;
|
|
if (len_self != len_other)
|
|
ok = 0;
|
|
else if (len_self == 0)
|
|
ok = 1;
|
|
else
|
|
ok = all_contained_in(self, other);
|
|
if (ok < 0)
|
|
return NULL;
|
|
if (ok == (op == Py_EQ))
|
|
result = Py_True;
|
|
else
|
|
result = Py_False;
|
|
Py_INCREF(result);
|
|
return result;
|
|
}
|
|
else {
|
|
Py_INCREF(Py_NotImplemented);
|
|
return Py_NotImplemented;
|
|
}
|
|
}
|
|
|
|
/*** dict_keys ***/
|
|
|
|
static PyObject *
|
|
dictkeys_iter(dictviewobject *dv)
|
|
{
|
|
if (dv->dv_dict == NULL) {
|
|
Py_RETURN_NONE;
|
|
}
|
|
return dictiter_new(dv->dv_dict, &PyDictIterKey_Type);
|
|
}
|
|
|
|
static int
|
|
dictkeys_contains(dictviewobject *dv, PyObject *obj)
|
|
{
|
|
if (dv->dv_dict == NULL)
|
|
return 0;
|
|
return PyDict_Contains((PyObject *)dv->dv_dict, obj);
|
|
}
|
|
|
|
static PySequenceMethods dictkeys_as_sequence = {
|
|
(lenfunc)dictview_len, /* sq_length */
|
|
0, /* sq_concat */
|
|
0, /* sq_repeat */
|
|
0, /* sq_item */
|
|
0, /* sq_slice */
|
|
0, /* sq_ass_item */
|
|
0, /* sq_ass_slice */
|
|
(objobjproc)dictkeys_contains, /* sq_contains */
|
|
};
|
|
|
|
static PyMethodDef dictkeys_methods[] = {
|
|
{NULL, NULL} /* sentinel */
|
|
};
|
|
|
|
PyTypeObject PyDictKeys_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0, /* ob_size */
|
|
"dict_keys", /* tp_name */
|
|
sizeof(dictviewobject), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
/* methods */
|
|
(destructor)dictview_dealloc, /* tp_dealloc */
|
|
0, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
0, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
&dictkeys_as_sequence, /* tp_as_sequence */
|
|
0, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
0, /* tp_str */
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
0, /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
dictview_richcompare, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
(getiterfunc)dictkeys_iter, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
dictkeys_methods, /* tp_methods */
|
|
0,
|
|
};
|
|
|
|
static PyObject *
|
|
dictkeys_new(PyObject *dict)
|
|
{
|
|
return dictview_new(dict, &PyDictKeys_Type);
|
|
}
|
|
|
|
/*** dict_items ***/
|
|
|
|
static PyObject *
|
|
dictitems_iter(dictviewobject *dv)
|
|
{
|
|
if (dv->dv_dict == NULL) {
|
|
Py_RETURN_NONE;
|
|
}
|
|
return dictiter_new(dv->dv_dict, &PyDictIterItem_Type);
|
|
}
|
|
|
|
static int
|
|
dictitems_contains(dictviewobject *dv, PyObject *obj)
|
|
{
|
|
PyObject *key, *value, *found;
|
|
if (dv->dv_dict == NULL)
|
|
return 0;
|
|
if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 2)
|
|
return 0;
|
|
key = PyTuple_GET_ITEM(obj, 0);
|
|
value = PyTuple_GET_ITEM(obj, 1);
|
|
found = PyDict_GetItem((PyObject *)dv->dv_dict, key);
|
|
if (found == NULL) {
|
|
if (PyErr_Occurred())
|
|
return -1;
|
|
return 0;
|
|
}
|
|
return PyObject_RichCompareBool(value, found, Py_EQ);
|
|
}
|
|
|
|
static PySequenceMethods dictitems_as_sequence = {
|
|
(lenfunc)dictview_len, /* sq_length */
|
|
0, /* sq_concat */
|
|
0, /* sq_repeat */
|
|
0, /* sq_item */
|
|
0, /* sq_slice */
|
|
0, /* sq_ass_item */
|
|
0, /* sq_ass_slice */
|
|
(objobjproc)dictitems_contains, /* sq_contains */
|
|
};
|
|
|
|
static PyMethodDef dictitems_methods[] = {
|
|
{NULL, NULL} /* sentinel */
|
|
};
|
|
|
|
PyTypeObject PyDictItems_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0, /* ob_size */
|
|
"dict_items", /* tp_name */
|
|
sizeof(dictviewobject), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
/* methods */
|
|
(destructor)dictview_dealloc, /* tp_dealloc */
|
|
0, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
0, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
&dictitems_as_sequence, /* tp_as_sequence */
|
|
0, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
0, /* tp_str */
|
|
PyObject_GenericGetAttr, /* tp_getattro */
|
|
0, /* tp_setattro */
|
|
0, /* tp_as_buffer */
|
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
0, /* tp_doc */
|
|
0, /* tp_traverse */
|
|
0, /* tp_clear */
|
|
dictview_richcompare, /* tp_richcompare */
|
|
0, /* tp_weaklistoffset */
|
|
(getiterfunc)dictitems_iter, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
dictitems_methods, /* tp_methods */
|
|
0,
|
|
};
|
|
|
|
static PyObject *
|
|
dictitems_new(PyObject *dict)
|
|
{
|
|
return dictview_new(dict, &PyDictItems_Type);
|
|
}
|
|
|
|
/*** dict_values ***/
|
|
|
|
static PyObject *
|
|
dictvalues_iter(dictviewobject *dv)
|
|
{
|
|
if (dv->dv_dict == NULL) {
|
|
Py_RETURN_NONE;
|
|
}
|
|
return dictiter_new(dv->dv_dict, &PyDictIterValue_Type);
|
|
}
|
|
|
|
static PySequenceMethods dictvalues_as_sequence = {
|
|
(lenfunc)dictview_len, /* sq_length */
|
|
0, /* sq_concat */
|
|
0, /* sq_repeat */
|
|
0, /* sq_item */
|
|
0, /* sq_slice */
|
|
0, /* sq_ass_item */
|
|
0, /* sq_ass_slice */
|
|
(objobjproc)0, /* sq_contains */
|
|
};
|
|
|
|
static PyMethodDef dictvalues_methods[] = {
|
|
{NULL, NULL} /* sentinel */
|
|
};
|
|
|
|
PyTypeObject PyDictValues_Type = {
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
0, /* ob_size */
|
|
"dict_values", /* tp_name */
|
|
sizeof(dictviewobject), /* tp_basicsize */
|
|
0, /* tp_itemsize */
|
|
/* methods */
|
|
(destructor)dictview_dealloc, /* tp_dealloc */
|
|
0, /* tp_print */
|
|
0, /* tp_getattr */
|
|
0, /* tp_setattr */
|
|
0, /* tp_compare */
|
|
0, /* tp_repr */
|
|
0, /* tp_as_number */
|
|
&dictvalues_as_sequence, /* tp_as_sequence */
|
|
0, /* tp_as_mapping */
|
|
0, /* tp_hash */
|
|
0, /* tp_call */
|
|
0, /* tp_str */
|
|
PyObject_GenericGetAttr, /* 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 */
|
|
(getiterfunc)dictvalues_iter, /* tp_iter */
|
|
0, /* tp_iternext */
|
|
dictvalues_methods, /* tp_methods */
|
|
0,
|
|
};
|
|
|
|
static PyObject *
|
|
dictvalues_new(PyObject *dict)
|
|
{
|
|
return dictview_new(dict, &PyDictValues_Type);
|
|
}
|