Index: Python/Python-ast.c =================================================================== --- Python/Python-ast.c (Revision 52823) +++ Python/Python-ast.c (Arbeitskopie) @@ -3008,7 +3008,7 @@ if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return; - if (PyModule_AddStringConstant(m, "__version__", "51773") < 0) + if (PyModule_AddStringConstant(m, "__version__", "52491") < 0) return; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (Revision 52823) +++ Python/bltinmodule.c (Arbeitskopie) @@ -849,19 +849,6 @@ static PyObject * -builtin_id(PyObject *self, PyObject *v) -{ - return PyLong_FromVoidPtr(v); -} - -PyDoc_STRVAR(id_doc, -"id(object) -> integer\n\ -\n\ -Return the identity of an object. This is guaranteed to be unique among\n\ -simultaneously existing objects. (Hint: it's the object's memory address.)"); - - -static PyObject * builtin_map(PyObject *self, PyObject *args) { typedef struct { @@ -1119,31 +1106,6 @@ static PyObject * -builtin_intern(PyObject *self, PyObject *args) -{ - PyObject *s; - if (!PyArg_ParseTuple(args, "S:intern", &s)) - return NULL; - if (!PyString_CheckExact(s)) { - PyErr_SetString(PyExc_TypeError, - "can't intern subclass of string"); - return NULL; - } - Py_INCREF(s); - PyString_InternInPlace(&s); - return s; -} - -PyDoc_STRVAR(intern_doc, -"intern(string) -> string\n\ -\n\ -``Intern'' the given string. This enters the string in the (global)\n\ -table of interned strings whose purpose is to speed up dictionary lookups.\n\ -Return the string itself or the previously interned string object with the\n\ -same value."); - - -static PyObject * builtin_iter(PyObject *self, PyObject *args) { PyObject *v, *w = NULL; @@ -2000,8 +1962,6 @@ {"hasattr", builtin_hasattr, METH_VARARGS, hasattr_doc}, {"hash", builtin_hash, METH_O, hash_doc}, {"hex", builtin_hex, METH_O, hex_doc}, - {"id", builtin_id, METH_O, id_doc}, - {"intern", builtin_intern, METH_VARARGS, intern_doc}, {"isinstance", builtin_isinstance, METH_VARARGS, isinstance_doc}, {"issubclass", builtin_issubclass, METH_VARARGS, issubclass_doc}, {"iter", builtin_iter, METH_VARARGS, iter_doc}, Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (Revision 52823) +++ Python/sysmodule.c (Arbeitskopie) @@ -264,6 +264,45 @@ #endif + +static PyObject * +sys_id(PyObject *self, PyObject *v) +{ + return PyLong_FromVoidPtr(v); +} + +PyDoc_STRVAR(id_doc, +"id(object) -> integer\n\ +\n\ +Return the identity of an object. This is guaranteed to be unique among\n\ +simultaneously existing objects. (Hint: it's the object's memory address.)"); + + +static PyObject * +sys_intern(PyObject *self, PyObject *args) +{ + PyObject *s; + if (!PyArg_ParseTuple(args, "S:intern", &s)) + return NULL; + if (!PyString_CheckExact(s)) { + PyErr_SetString(PyExc_TypeError, + "can't intern subclass of string"); + return NULL; + } + Py_INCREF(s); + PyString_InternInPlace(&s); + return s; +} + +PyDoc_STRVAR(intern_doc, +"intern(string) -> string\n\ +\n\ +``Intern'' the given string. This enters the string in the (global)\n\ +table of interned strings whose purpose is to speed up dictionary lookups.\n\ +Return the string itself or the previously interned string object with the\n\ +same value."); + + /* * Cached interned string objects used for calling the profile and * trace functions. Initialized by trace_init(). @@ -772,6 +811,8 @@ {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, getwindowsversion_doc}, #endif /* MS_WINDOWS */ + {"id", sys_id, METH_O, id_doc}, + {"intern", sys_intern, METH_VARARGS, intern_doc}, #ifdef USE_MALLOPT {"mdebug", sys_mdebug, METH_VARARGS}, #endif Index: Include/stringobject.h =================================================================== --- Include/stringobject.h (Revision 52823) +++ Include/stringobject.h (Arbeitskopie) @@ -28,7 +28,7 @@ Interning strings (ob_sstate) tries to ensure that only one string object with a given value exists, so equality tests can be one pointer comparison. This is generally restricted to strings that "look like" - Python identifiers, although the intern() builtin can be used to force + Python identifiers, although the sys.intern() function can be used to force interning of any string. Together, these sped the interpreter by up to 20%. */ Index: Demo/imputil/importers.py =================================================================== --- Demo/imputil/importers.py (Revision 52823) +++ Demo/imputil/importers.py (Arbeitskopie) @@ -204,7 +204,7 @@ return '<%s.%s for "%s" at 0x%x>' % (self.__class__.__module__, self.__class__.__name__, self.dir, - id(self)) + sys.id(self)) ###################################################################### Index: Demo/threads/Coroutine.py =================================================================== --- Demo/threads/Coroutine.py (Revision 52823) +++ Demo/threads/Coroutine.py (Arbeitskopie) @@ -66,6 +66,7 @@ # current implementation consumes a thread for each coroutine that # may be resumed. +import sys import thread import sync @@ -81,10 +82,10 @@ return 'coroutine for func ' + self.f.func_name def __hash__(self): - return id(self) + return sys.id(self) def __cmp__(x,y): - return cmp(id(x), id(y)) + return cmp(sys.id(x), sys.id(y)) def resume(self): self.e.post() Index: Misc/python-mode.el =================================================================== --- Misc/python-mode.el (Revision 52823) +++ Misc/python-mode.el (Arbeitskopie) @@ -382,7 +382,7 @@ "delattr" "dict" "dir" "divmod" "enumerate" "eval" "execfile" "exit" "file" "filter" "float" "getattr" "globals" "hasattr" - "hash" "hex" "id" "int" "intern" + "hash" "hex" "int" "isinstance" "issubclass" "iter" "len" "license" "list" "locals" "long" "map" "max" "min" "object" "oct" "open" "ord" "pow" "property" "range" Index: Tools/scripts/fixdiv.py =================================================================== --- Tools/scripts/fixdiv.py (Revision 52823) +++ Tools/scripts/fixdiv.py (Arbeitskopie) @@ -198,7 +198,7 @@ list = warnings.get(filename) if list is None: warnings[filename] = list = [] - list.append((int(lineno), intern(what))) + list.append((int(lineno), sys.intern(what))) f.close() return warnings Index: Tools/pybench/Strings.py =================================================================== --- Tools/pybench/Strings.py (Revision 52823) +++ Tools/pybench/Strings.py (Arbeitskopie) @@ -1,5 +1,6 @@ from pybench import Test from string import join +import sys class ConcatStrings(Test): @@ -174,7 +175,7 @@ def test(self): # Make sure the strings *are* interned - s = intern(join(map(str,range(10)))) + s = sys.intern(join(map(str,range(10)))) t = s for i in xrange(self.rounds): @@ -240,7 +241,7 @@ def calibrate(self): - s = intern(join(map(str,range(10)))) + s = sys.intern(join(map(str,range(10)))) t = s for i in xrange(self.rounds): Index: Tools/bgen/bgen/bgenGenerator.py =================================================================== --- Tools/bgen/bgen/bgenGenerator.py (Revision 52823) +++ Tools/bgen/bgen/bgenGenerator.py (Arbeitskopie) @@ -2,6 +2,7 @@ from bgenType import * from bgenVariable import * +import sys Error = "bgenGenerator.Error" @@ -78,7 +79,7 @@ def __cmp__(self, other): if not hasattr(other, 'name'): - return cmp(id(self), id(other)) + return cmp(sys.id(self), sys.id(other)) return cmp(self.name, other.name) _stringify_map = {'\n': '\\n', '\t': '\\t', '\r': '\\r', '\b': '\\b', Index: Mac/Demo/imgbrowse/mac_image.py =================================================================== --- Mac/Demo/imgbrowse/mac_image.py (Revision 52823) +++ Mac/Demo/imgbrowse/mac_image.py (Arbeitskopie) @@ -1,6 +1,7 @@ """mac_image - Helper routines (hacks) for images""" import imgformat from Carbon import Qd +import sys import time import struct import MacOS @@ -14,7 +15,7 @@ fmtinfo = _fmt_to_mac[fmt] rv = struct.pack("lHhhhhhhlllhhhhlll", - id(data)+MacOS.string_id_to_buffer, # HACK HACK!! + sys.id(data)+MacOS.string_id_to_buffer, # HACK HACK!! w*2 + 0x8000, 0, 0, h, w, 0, Index: Doc/lib/libdoctest.tex =================================================================== --- Doc/lib/libdoctest.tex (Revision 52823) +++ Doc/lib/libdoctest.tex (Arbeitskopie) @@ -816,7 +816,7 @@ Another bad idea is to print things that embed an object address, like \begin{verbatim} ->>> id(1.0) # certain to fail some of the time +>>> sys.id(1.0) # certain to fail some of the time 7948648 >>> class C: pass >>> C() # the default repr() for instances embeds an address Index: Doc/lib/libpprint.tex =================================================================== --- Doc/lib/libpprint.tex (Revision 52823) +++ Doc/lib/libpprint.tex (Arbeitskopie) @@ -195,7 +195,7 @@ string, a flag indicating whether the result is readable, and a flag indicating whether recursion was detected. The first argument is the object to be presented. The second is a dictionary which contains the -\function{id()} of objects that are part of the current presentation +\function{sys.id()} of objects that are part of the current presentation context (direct and indirect containers for \var{object} that are affecting the presentation) as the keys; if an object needs to be presented which is already represented in \var{context}, the third Index: Doc/lib/libsys.tex =================================================================== --- Doc/lib/libsys.tex (Revision 52823) +++ Doc/lib/libsys.tex (Arbeitskopie) @@ -340,6 +340,29 @@ \versionadded{1.5.2} \end{datadesc} +\begin{funcdesc}{id}{object} + Return the ``identity'' of an object. This is an integer (or long + integer) which is guaranteed to be unique and constant for this + object during its lifetime. Two objects with non-overlapping lifetimes + may have the same \function{id()} value. (Implementation + note: this is the address of the object.) +\end{funcdesc} + +\begin{funcdesc}{intern}{string} + Enter \var{string} in the table of ``interned'' strings and return + the interned string -- which is \var{string} itself or a copy. + Interning strings is useful to gain a little performance on + dictionary lookup -- if the keys in a dictionary are interned, and + the lookup key is interned, the key comparisons (after hashing) can + be done by a pointer compare instead of a string compare. Normally, + the names used in Python programs are automatically interned, and + the dictionaries used to hold module, class or instance attributes + have interned keys. \versionchanged[Interned strings are not + immortal (like they used to be in Python 2.2 and before); + you must keep a reference to the return value of \function{intern()} + around to benefit from it]{2.3} +\end{funcdesc} + \begin{datadesc}{last_type} \dataline{last_value} \dataline{last_traceback} Index: Doc/lib/libweakref.tex =================================================================== --- Doc/lib/libweakref.tex (Revision 52823) +++ Doc/lib/libweakref.tex (Arbeitskopie) @@ -322,12 +322,12 @@ % Example contributed by Tim Peters. \begin{verbatim} -import weakref +import weakref, sys _id2obj_dict = weakref.WeakValueDictionary() def remember(obj): - oid = id(obj) + oid = sys.id(obj) _id2obj_dict[oid] = obj return oid Index: Doc/lib/libfuncs.tex =================================================================== --- Doc/lib/libfuncs.tex (Revision 52823) +++ Doc/lib/libfuncs.tex (Arbeitskopie) @@ -537,14 +537,6 @@ \versionchanged[Formerly only returned an unsigned literal]{2.4} \end{funcdesc} -\begin{funcdesc}{id}{object} - Return the ``identity'' of an object. This is an integer (or long - integer) which is guaranteed to be unique and constant for this - object during its lifetime. Two objects with non-overlapping lifetimes - may have the same \function{id()} value. (Implementation - note: this is the address of the object.) -\end{funcdesc} - \begin{funcdesc}{int}{\optional{x\optional{, radix}}} Convert a string or number to a plain integer. If the argument is a string, it must contain a possibly signed decimal number @@ -1262,17 +1254,3 @@ argument). \end{funcdesc} -\begin{funcdesc}{intern}{string} - Enter \var{string} in the table of ``interned'' strings and return - the interned string -- which is \var{string} itself or a copy. - Interning strings is useful to gain a little performance on - dictionary lookup -- if the keys in a dictionary are interned, and - the lookup key is interned, the key comparisons (after hashing) can - be done by a pointer compare instead of a string compare. Normally, - the names used in Python programs are automatically interned, and - the dictionaries used to hold module, class or instance attributes - have interned keys. \versionchanged[Interned strings are not - immortal (like they used to be in Python 2.2 and before); - you must keep a reference to the return value of \function{intern()} - around to benefit from it]{2.3} -\end{funcdesc} Index: Doc/tut/glossary.tex =================================================================== --- Doc/tut/glossary.tex (Revision 52823) +++ Doc/tut/glossary.tex (Arbeitskopie) @@ -258,7 +258,8 @@ \index{mutable} \item[mutable] -Mutable objects can change their value but keep their \function{id()}. +Mutable objects can change their value but keep their identity, as +returned by \function{sys.id()}. See also \emph{immutable}. \index{namespace} Index: Doc/tut/tut.tex =================================================================== --- Doc/tut/tut.tex (Revision 52823) +++ Doc/tut/tut.tex (Arbeitskopie) @@ -2700,7 +2700,7 @@ 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'execfile', 'exit', 'file', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', - 'id', 'int', 'intern', 'isinstance', 'issubclass', 'iter', + 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range', 'reload', 'repr', 'reversed', 'round', 'set', Index: Lib/idlelib/rpc.py =================================================================== --- Lib/idlelib/rpc.py (Revision 52823) +++ Lib/idlelib/rpc.py (Arbeitskopie) @@ -483,7 +483,7 @@ pass def remoteref(obj): - oid = id(obj) + oid = sys.id(obj) objecttable[oid] = obj return RemoteProxy(oid) Index: Lib/idlelib/RemoteObjectBrowser.py =================================================================== --- Lib/idlelib/RemoteObjectBrowser.py (Revision 52823) +++ Lib/idlelib/RemoteObjectBrowser.py (Arbeitskopie) @@ -1,3 +1,4 @@ +import sys import rpc def remote_object_tree_item(item): @@ -2,3 +3,3 @@ wrapper = WrappedObjectTreeItem(item) - oid = id(wrapper) + oid = sys.id(wrapper) rpc.objecttable[oid] = wrapper Index: Lib/idlelib/RemoteDebugger.py =================================================================== --- Lib/idlelib/RemoteDebugger.py (Revision 52823) +++ Lib/idlelib/RemoteDebugger.py (Arbeitskopie) @@ -40,7 +40,7 @@ tracebacktable = {} def wrap_frame(frame): - fid = id(frame) + fid = sys.id(frame) frametable[fid] = frame return fid @@ -51,7 +51,7 @@ else: traceback = info[2] assert isinstance(traceback, types.TracebackType) - traceback_id = id(traceback) + traceback_id = sys.id(traceback) tracebacktable[traceback_id] = traceback modified_info = (info[0], info[1], traceback_id) return modified_info @@ -131,21 +131,21 @@ def frame_globals(self, fid): frame = frametable[fid] dict = frame.f_globals - did = id(dict) + did = sys.id(dict) dicttable[did] = dict return did def frame_locals(self, fid): frame = frametable[fid] dict = frame.f_locals - did = id(dict) + did = sys.id(dict) dicttable[did] = dict return did def frame_code(self, fid): frame = frametable[fid] code = frame.f_code - cid = id(code) + cid = sys.id(code) codetable[cid] = code return cid Index: Lib/xmlrpclib.py =================================================================== --- Lib/xmlrpclib.py (Revision 52823) +++ Lib/xmlrpclib.py (Arbeitskopie) @@ -136,7 +136,7 @@ name (None if not present). """ -import re, string, time, operator +import sys, re, string, time, operator from types import * @@ -343,7 +343,7 @@ return self.value def __repr__(self): - return "" % (repr(self.value), id(self)) + return "" % (repr(self.value), sys.id(self)) def decode(self, data): data = str(data) @@ -648,7 +648,7 @@ dispatch[UnicodeType] = dump_unicode def dump_array(self, value, write): - i = id(value) + i = sys.id(value) if i in self.memo: raise TypeError, "cannot marshal recursive sequences" self.memo[i] = None @@ -662,7 +662,7 @@ dispatch[ListType] = dump_array def dump_struct(self, value, write, escape=escape): - i = id(value) + i = sys.id(value) if i in self.memo: raise TypeError, "cannot marshal recursive dictionaries" self.memo[i] = None @@ -939,7 +939,7 @@ self.__call_list = [] def __repr__(self): - return "" % id(self) + return "" % sys.id(self) __str__ = __repr__ Index: Lib/optparse.py =================================================================== --- Lib/optparse.py (Revision 52823) +++ Lib/optparse.py (Arbeitskopie) @@ -71,7 +71,7 @@ import textwrap def _repr(self): - return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self) + return "<%s at 0x%x: %s>" % (self.__class__.__name__, sys.id(self), self) # This file was generated from: Index: Lib/gzip.py =================================================================== --- Lib/gzip.py (Revision 52823) +++ Lib/gzip.py (Arbeitskopie) @@ -129,7 +129,7 @@ def __repr__(self): s = repr(self.fileobj) - return '' + return '' % (s[1:-1], sys.id(self)) def _init_write(self, filename): if filename[-3:] != '.gz': Index: Lib/copy.py =================================================================== --- Lib/copy.py (Revision 52823) +++ Lib/copy.py (Arbeitskopie) @@ -48,6 +48,7 @@ "pickle" for information on these methods. """ +import sys import types from copy_reg import dispatch_table @@ -130,7 +131,7 @@ if memo is None: memo = {} - d = id(x) + d = sys.id(x) y = memo.get(d, _nil) if y is not _nil: return y @@ -202,7 +203,7 @@ def _deepcopy_list(x, memo): y = [] - memo[id(x)] = y + memo[sys.id(x)] = y for a in x: y.append(deepcopy(a, memo)) return y @@ -212,7 +213,7 @@ y = [] for a in x: y.append(deepcopy(a, memo)) - d = id(x) + d = sys.id(x) try: return memo[d] except KeyError: @@ -229,7 +230,7 @@ def _deepcopy_dict(x, memo): y = {} - memo[id(x)] = y + memo[sys.id(x)] = y for key, value in x.iteritems(): y[deepcopy(key, memo)] = deepcopy(value, memo) return y @@ -248,10 +249,10 @@ the memo itself... """ try: - memo[id(memo)].append(x) + memo[sys.id(memo)].append(x) except KeyError: # aha, this is the first one :-) - memo[id(memo)]=[x] + memo[sys.id(memo)]=[x] def _reconstruct(x, info, deep, memo=None): if isinstance(info, str): @@ -277,7 +278,7 @@ if deep: args = deepcopy(args, memo) y = callable(*args) - memo[id(x)] = y + memo[sys.id(x)] = y if listiter is not None: for item in listiter: if deep: Index: Lib/asyncore.py =================================================================== --- Lib/asyncore.py (Revision 52823) +++ Lib/asyncore.py (Arbeitskopie) @@ -235,7 +235,7 @@ status.append('%s:%d' % self.addr) except TypeError: status.append(repr(self.addr)) - return '<%s at %#x>' % (' '.join(status), id(self)) + return '<%s at %#x>' % (' '.join(status), sys.id(self)) def add_channel(self, map=None): #self.log_info('adding channel %s' % self) @@ -406,7 +406,7 @@ try: self_repr = repr(self) except: - self_repr = '<__repr__(self) failed for object at %0x>' % id(self) + self_repr = '<__repr__(self) failed for object at %0x>' % sys.id(self) self.log_info( 'uncaptured python exception, closing channel %s (%s:%s %s)' % ( Index: Lib/ctypes/test/test_cast.py =================================================================== --- Lib/ctypes/test/test_cast.py (Revision 52823) +++ Lib/ctypes/test/test_cast.py (Arbeitskopie) @@ -39,12 +39,12 @@ p = cast(array, POINTER(c_char_p)) # array and p share a common _objects attribute self.failUnless(p._objects is array._objects) - self.failUnlessEqual(array._objects, {'0': "foo bar", id(array): array}) + self.failUnlessEqual(array._objects, {'0': "foo bar", sys.id(array): array}) p[0] = "spam spam" - self.failUnlessEqual(p._objects, {'0': "spam spam", id(array): array}) + self.failUnlessEqual(p._objects, {'0': "spam spam", sys.id(array): array}) self.failUnless(array._objects is p._objects) p[1] = "foo bar" - self.failUnlessEqual(p._objects, {'1': 'foo bar', '0': "spam spam", id(array): array}) + self.failUnlessEqual(p._objects, {'1': 'foo bar', '0': "spam spam", sys.id(array): array}) self.failUnless(array._objects is p._objects) def test_other(self): Index: Lib/ctypes/test/test_internals.py =================================================================== --- Lib/ctypes/test/test_internals.py (Revision 52823) +++ Lib/ctypes/test/test_internals.py (Arbeitskopie) @@ -1,7 +1,7 @@ # This tests the internal _objects attribute import unittest from ctypes import * -from sys import getrefcount as grc +from sys import id, getrefcount as grc # XXX This test must be reviewed for correctness!!! Index: Lib/ctypes/test/test_python_api.py =================================================================== --- Lib/ctypes/test/test_python_api.py (Revision 52823) +++ Lib/ctypes/test/test_python_api.py (Arbeitskopie) @@ -9,7 +9,7 @@ ################################################################ -from sys import getrefcount as grc +from sys import id, getrefcount as grc class PythonAPITestCase(unittest.TestCase): Index: Lib/ctypes/test/test_prototypes.py =================================================================== --- Lib/ctypes/test/test_prototypes.py (Revision 52823) +++ Lib/ctypes/test/test_prototypes.py (Arbeitskopie) @@ -25,7 +25,7 @@ testdll = CDLL(_ctypes_test.__file__) # Return machine address `a` as a (possibly long) non-negative integer. -# Starting with Python 2.5, id(anything) is always non-negative, and +# Starting with Python 2.5, sys.id(anything) is always non-negative, and # the ctypes addressof() inherits that via PyLong_FromVoidPtr(). def positive_address(a): if a >= 0: Index: Lib/ctypes/__init__.py =================================================================== --- Lib/ctypes/__init__.py (Revision 52823) +++ Lib/ctypes/__init__.py (Arbeitskopie) @@ -217,7 +217,7 @@ klass = type(_Pointer)("LP_%s" % cls, (_Pointer,), {}) - _pointer_type_cache[id(klass)] = klass + _pointer_type_cache[_sys.id(klass)] = klass return klass else: name = "LP_%s" % cls.__name__ @@ -270,12 +270,12 @@ if _pointer_type_cache.get(cls, None) is not None: raise RuntimeError, \ "This type already exists in the cache" - if id(pointer) not in _pointer_type_cache: + if _sys.id(pointer) not in _pointer_type_cache: raise RuntimeError, \ "What's this???" pointer.set_type(cls) _pointer_type_cache[cls] = pointer - del _pointer_type_cache[id(pointer)] + del _pointer_type_cache[_sys.id(pointer)] def pointer(inst): @@ -317,7 +317,7 @@ return "<%s '%s', handle %x at %x>" % \ (self.__class__.__name__, self._name, (self._handle & (_sys.maxint*2 + 1)), - id(self) & (_sys.maxint*2 + 1)) + _sys.id(self) & (_sys.maxint*2 + 1)) def __getattr__(self, name): if name.startswith('__') and name.endswith('__'): Index: Lib/weakref.py =================================================================== --- Lib/weakref.py (Revision 52823) +++ Lib/weakref.py (Arbeitskopie) @@ -9,6 +9,7 @@ # they are called this instead of "ref" to avoid name collisions with # the module-global ref() function imported from _weakref. +import sys import UserDict from _weakref import ( @@ -65,7 +66,7 @@ return o is not None def __repr__(self): - return "" % id(self) + return "" % sys.id(self) def __setitem__(self, key, value): self.data[key] = KeyedRef(value, self._remove, key) @@ -236,7 +237,7 @@ return self.data[ref(key)] def __repr__(self): - return "" % id(self) + return "" % sys.id(self) def __setitem__(self, key, value): self.data[ref(key, self._remove)] = value Index: Lib/posixfile.py =================================================================== --- Lib/posixfile.py (Revision 52823) +++ Lib/posixfile.py (Arbeitskopie) @@ -53,6 +53,7 @@ query only """ +import sys class _posixfile_: """File wrapper class that provides extra POSIX file routines.""" @@ -66,7 +67,7 @@ file = self._file_ return "<%s posixfile '%s', mode '%s' at %s>" % \ (self.states[file.closed], file.name, file.mode, \ - hex(id(self))[2:]) + hex(sys.id(self))[2:]) # # Initialization routines Index: Lib/bsddb/__init__.py =================================================================== --- Lib/bsddb/__init__.py (Revision 52823) +++ Lib/bsddb/__init__.py (Arbeitskopie) @@ -76,7 +76,7 @@ class _iter_mixin(UserDict.DictMixin): def _make_iter_cursor(self): cur = _DeadlockWrap(self.db.cursor) - key = id(cur) + key = sys.id(cur) self._cursor_refs[key] = ref(cur, self._gen_cref_cleaner(key)) return cur Index: Lib/urllib.py =================================================================== --- Lib/urllib.py (Revision 52823) +++ Lib/urllib.py (Arbeitskopie) @@ -910,7 +910,7 @@ def __repr__(self): return '<%s at %r whose fp = %r>' % (self.__class__.__name__, - id(self), self.fp) + sys.id(self), self.fp) def close(self): self.read = None Index: Lib/cProfile.py =================================================================== --- Lib/cProfile.py (Revision 52823) +++ Lib/cProfile.py (Arbeitskopie) @@ -6,6 +6,7 @@ __all__ = ["run", "runctx", "help", "Profile"] +import sys import _lsprof # ____________________________________________________________ @@ -103,7 +104,7 @@ tt = entry.inlinetime # tottime column of pstats ct = entry.totaltime # cumtime column of pstats callers = {} - callersdicts[id(entry.code)] = callers + callersdicts[sys.id(entry.code)] = callers self.stats[func] = cc, nc, tt, ct, callers # subcall information for entry in entries: @@ -111,7 +112,7 @@ func = label(entry.code) for subentry in entry.calls: try: - callers = callersdicts[id(subentry.code)] + callers = callersdicts[sys.id(subentry.code)] except KeyError: continue nc = subentry.callcount Index: Lib/repr.py =================================================================== --- Lib/repr.py (Revision 52823) +++ Lib/repr.py (Arbeitskopie) @@ -3,6 +3,7 @@ __all__ = ["Repr","repr"] import __builtin__ +import sys from itertools import islice class Repr: @@ -106,7 +107,7 @@ # Bugs in x.__repr__() can cause arbitrary # exceptions -- then make up something except: - return '<%s instance at %x>' % (x.__class__.__name__, id(x)) + return '<%s instance at %x>' % (x.__class__.__name__, sys.id(x)) if len(s) > self.maxother: i = max(0, (self.maxother-3)//2) j = max(0, self.maxother-3-i) Index: Lib/tarfile.py =================================================================== --- Lib/tarfile.py (Revision 52823) +++ Lib/tarfile.py (Arbeitskopie) @@ -816,7 +816,7 @@ self.offset_data = 0 # the file's data starts here def __repr__(self): - return "<%s %r at %#x>" % (self.__class__.__name__,self.name,id(self)) + return "<%s %r at %#x>" % (self.__class__.__name__, self.name, sys.id(self)) @classmethod def frombuf(cls, buf): Index: Lib/lib-tk/tkFont.py =================================================================== --- Lib/lib-tk/tkFont.py (Revision 52823) +++ Lib/lib-tk/tkFont.py (Arbeitskopie) @@ -8,7 +8,7 @@ __version__ = "0.9" -import Tkinter +import Tkinter, sys # weight/slant NORMAL = "normal" @@ -72,7 +72,7 @@ else: font = self._set(options) if not name: - name = "font" + str(id(self)) + name = "font" + str(sys.id(self)) self.name = name if exists: Index: Lib/lib-tk/Canvas.py =================================================================== --- Lib/lib-tk/Canvas.py (Revision 52823) +++ Lib/lib-tk/Canvas.py (Arbeitskopie) @@ -4,8 +4,8 @@ # It's best to use the Tkinter.Canvas class directly. from Tkinter import Canvas, _cnfmerge, _flatten +import sys - class CanvasItem: def __init__(self, canvas, itemType, *args, **kw): self.canvas = canvas @@ -120,7 +120,7 @@ class Group: def __init__(self, canvas, tag=None): if not tag: - tag = 'Group%d' % id(self) + tag = 'Group%d' % sys.id(self) self.tag = self.id = tag self.canvas = canvas self.canvas.dtag(self.tag) Index: Lib/lib-tk/Tkinter.py =================================================================== --- Lib/lib-tk/Tkinter.py (Revision 52823) +++ Lib/lib-tk/Tkinter.py (Arbeitskopie) @@ -1080,7 +1080,7 @@ be executed. An optional function SUBST can be given which will be executed before FUNC.""" f = CallWrapper(func, subst, self).__call__ - name = repr(id(f)) + name = repr(sys.id(f)) try: func = func.im_func except AttributeError: @@ -1904,7 +1904,7 @@ name = cnf['name'] del cnf['name'] if not name: - name = repr(id(self)) + name = repr(sys.id(self)) self._name = name if master._w=='.': self._w = '.' + name @@ -3213,7 +3213,7 @@ if not name: Image._last_id += 1 name = "pyimage%r" % (Image._last_id,) # tk itself would use image - # The following is needed for systems where id(x) + # The following is needed for systems where sys.id(x) # can return a negative number, such as Linux/m68k: if name[0] == '-': name = '_' + name[1:] if kw and cnf: cnf = _cnfmerge((cnf, kw)) Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (Revision 52823) +++ Lib/doctest.py (Arbeitskopie) @@ -472,9 +472,9 @@ def __lt__(self, other): if not isinstance(other, DocTest): return NotImplemented - return ((self.name, self.filename, self.lineno, id(self)) + return ((self.name, self.filename, self.lineno, sys.id(self)) < - (other.name, other.filename, other.lineno, id(other))) + (other.name, other.filename, other.lineno, sys.id(other))) ###################################################################### ## 3. DocTestParser @@ -858,9 +858,9 @@ print 'Finding tests in %s' % name # If we've already processed this object, then ignore it. - if id(obj) in seen: + if sys.id(obj) in seen: return - seen[id(obj)] = 1 + seen[sys.id(obj)] = 1 # Find a test for this object, and add it to the list of tests. test = self._get_test(obj, name, module, globs, source_lines) Index: Lib/pprint.py =================================================================== --- Lib/pprint.py (Revision 52823) +++ Lib/pprint.py (Arbeitskopie) @@ -43,7 +43,7 @@ # cache these for faster access: _commajoin = ", ".join -_id = id +_id = _sys.id _len = len _type = type Index: Lib/_threading_local.py =================================================================== --- Lib/_threading_local.py (Revision 52823) +++ Lib/_threading_local.py (Arbeitskopie) @@ -133,6 +133,8 @@ >>> del mydata """ +import sys + __all__ = ["local"] # We need to use objects from the threading module, but the threading @@ -150,7 +152,7 @@ def __new__(cls, *args, **kw): self = object.__new__(cls) - key = '_local__key', 'thread.local.' + str(id(self)) + key = '_local__key', 'thread.local.' + str(sys.id(self)) object.__setattr__(self, '_local__key', key) object.__setattr__(self, '_local__args', (args, kw)) object.__setattr__(self, '_local__lock', RLock()) Index: Lib/sets.py =================================================================== --- Lib/sets.py (Revision 52823) +++ Lib/sets.py (Arbeitskopie) @@ -55,6 +55,7 @@ # improvements. from __future__ import generators +import sys try: from itertools import ifilter, ifilterfalse except ImportError: @@ -177,7 +178,7 @@ # itself. from copy import deepcopy result = self.__class__() - memo[id(self)] = result + memo[sys.id(self)] = result data = result._data value = True for elt in self: Index: Lib/test/test_extcall.py =================================================================== --- Lib/test/test_extcall.py (Revision 52823) +++ Lib/test/test_extcall.py (Arbeitskopie) @@ -1,5 +1,6 @@ from test.test_support import verify, verbose, TestFailed, sortdict from UserList import UserList +import sys def e(a, b): print a, b @@ -240,9 +241,9 @@ # A PyCFunction that takes only positional parameters should allow an # empty keyword dictionary to pass without a complaint, but raise a # TypeError if the dictionary is non-empty. -id(1, **{}) +sys.id(1, **{}) try: - id(1, **{"foo": 1}) + sys.id(1, **{"foo": 1}) except TypeError: pass else: Index: Lib/test/test_repr.py =================================================================== --- Lib/test/test_repr.py (Revision 52823) +++ Lib/test/test_repr.py (Arbeitskopie) @@ -107,7 +107,7 @@ eq(r(i2), expected) i3 = ClassWithFailingRepr() - eq(r(i3), (""%id(i3))) + eq(r(i3), ("" % sys.id(i3))) s = r(ClassWithFailingRepr) self.failUnless(s.startswith(">> tupleids = map(id, ((i,i) for i in xrange(10))) + >>> tupleids = map(sys.id, ((i,i) for i in xrange(10))) >>> int(max(tupleids) - min(tupleids)) 0 Index: Lib/test/test_gc.py =================================================================== --- Lib/test/test_gc.py (Revision 52823) +++ Lib/test/test_gc.py (Arbeitskopie) @@ -110,7 +110,7 @@ pass a = A() a.a = a - id_a = id(a) + id_a = sys.id(a) b = B() b.b = b gc.collect() @@ -118,7 +118,7 @@ del b expect_nonzero(gc.collect(), "finalizer") for obj in gc.garbage: - if id(obj) == id_a: + if sys.id(obj) == id_a: del obj.a break else: @@ -134,7 +134,7 @@ pass a = A() a.a = a - id_a = id(a) + id_a = sys.id(a) b = B() b.b = b gc.collect() @@ -142,7 +142,7 @@ del b expect_nonzero(gc.collect(), "finalizer") for obj in gc.garbage: - if id(obj) == id_a: + if sys.id(obj) == id_a: del obj.a break else: @@ -177,7 +177,7 @@ L = [] L.append(L) - id_L = id(L) + id_L = sys.id(L) debug = gc.get_debug() gc.set_debug(debug | gc.DEBUG_SAVEALL) @@ -187,7 +187,7 @@ vereq(len(gc.garbage), 1) obj = gc.garbage.pop() - vereq(id(obj), id_L) + vereq(sys.id(obj), id_L) def test_del(): # __del__ methods can trigger collection, make this to happen Index: Lib/test/test_compare.py =================================================================== --- Lib/test/test_compare.py (Revision 52823) +++ Lib/test/test_compare.py (Arbeitskopie) @@ -30,13 +30,13 @@ self.assertNotEqual(a, b) def test_id_comparisons(self): - # Ensure default comparison compares id() of args + # Ensure default comparison compares sys.id() of args L = [] for i in range(10): L.insert(len(L)//2, Empty()) for a in L: for b in L: - self.assertEqual(a == b, id(a) == id(b), + self.assertEqual(a == b, sys.id(a) == sys.id(b), 'a=%r, b=%r' % (a, b)) def test_main(): Index: Lib/test/test_compile.py =================================================================== --- Lib/test/test_compile.py (Revision 52823) +++ Lib/test/test_compile.py (Arbeitskopie) @@ -318,7 +318,7 @@ f2 = lambda x=2: x return f1, f2 f1, f2 = f() - self.assertNotEqual(id(f1.func_code), id(f2.func_code)) + self.assertNotEqual(sys.id(f1.func_code), sys.id(f2.func_code)) def test_unicode_encoding(self): code = u"# -*- coding: utf-8 -*-\npass\n" Index: Lib/test/list_tests.py =================================================================== --- Lib/test/list_tests.py (Revision 52823) +++ Lib/test/list_tests.py (Arbeitskopie) @@ -26,7 +26,7 @@ # Mutables always return a new object b = self.type2test(a) - self.assertNotEqual(id(a), id(b)) + self.assertNotEqual(sys.id(a), sys.id(b)) self.assertEqual(a, b) def test_repr(self): @@ -473,9 +473,9 @@ u *= 0 self.assertEqual(u, self.type2test([])) s = self.type2test([]) - oldid = id(s) + oldid = sys.id(s) s *= 10 - self.assertEqual(id(s), oldid) + self.assertEqual(sys.id(s), oldid) def test_extendedslicing(self): # subscript Index: Lib/test/test_sort.py =================================================================== --- Lib/test/test_sort.py (Revision 52823) +++ Lib/test/test_sort.py (Arbeitskopie) @@ -226,7 +226,7 @@ del data[:] data[:] = range(20) def __lt__(self, other): - return id(self) < id(other) + return sys.id(self) < sys.id(other) self.assertRaises(ValueError, data.sort, key=SortKiller) def test_key_with_mutating_del_and_exception(self): Index: Lib/test/test_marshal.py =================================================================== --- Lib/test/test_marshal.py (Revision 52823) +++ Lib/test/test_marshal.py (Arbeitskopie) @@ -190,7 +190,7 @@ new = marshal.loads(marshal.dumps(t)) self.assertEqual(t, new) self.assert_(isinstance(new, constructor)) - self.assertNotEqual(id(t), id(new)) + self.assertNotEqual(sys.id(t), sys.id(new)) marshal.dump(t, open(test_support.TESTFN, "wb")) new = marshal.load(open(test_support.TESTFN, "rb")) self.assertEqual(t, new) Index: Lib/test/test_deque.py =================================================================== --- Lib/test/test_deque.py (Revision 52823) +++ Lib/test/test_deque.py (Arbeitskopie) @@ -7,6 +7,7 @@ from cStringIO import StringIO import random import os +import sys BIG = 100000 @@ -328,7 +329,7 @@ def test_roundtrip_iter_init(self): d = deque(xrange(200)) e = deque(d) - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) self.assertEqual(list(d), list(e)) def test_pickle(self): @@ -336,7 +337,7 @@ for i in (0, 1, 2): s = pickle.dumps(d, i) e = pickle.loads(s) - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) self.assertEqual(list(d), list(e)) def test_pickle_recursive(self): @@ -344,8 +345,8 @@ d.append(d) for i in (0, 1, 2): e = pickle.loads(pickle.dumps(d, i)) - self.assertNotEqual(id(d), id(e)) - self.assertEqual(id(e), id(e[-1])) + self.assertNotEqual(sys.id(d), sys.id(e)) + self.assertEqual(sys.id(e), sys.id(e[-1])) def test_deepcopy(self): mut = [10] @@ -353,7 +354,7 @@ e = copy.deepcopy(d) self.assertEqual(list(d), list(e)) mut[0] = 11 - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) self.assertNotEqual(list(d), list(e)) def test_copy(self): @@ -362,7 +363,7 @@ e = copy.copy(d) self.assertEqual(list(d), list(e)) mut[0] = 11 - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) self.assertEqual(list(d), list(e)) def test_reversed(self): @@ -441,7 +442,7 @@ s = pickle.dumps(d) e = pickle.loads(s) - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) self.assertEqual(type(d), type(e)) self.assertEqual(list(d), list(e)) @@ -450,16 +451,16 @@ d.append(d) e = pickle.loads(pickle.dumps(d)) - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) self.assertEqual(type(d), type(e)) dd = d.pop() ee = e.pop() - self.assertEqual(id(e), id(ee)) + self.assertEqual(sys.id(e), sys.id(ee)) self.assertEqual(d, e) d.x = d e = pickle.loads(pickle.dumps(d)) - self.assertEqual(id(e), id(e.x)) + self.assertEqual(sys.id(e), sys.id(e.x)) d = DequeWithBadIter('abc') self.assertRaises(TypeError, pickle.dumps, d) Index: Lib/test/test_strptime.py =================================================================== --- Lib/test/test_strptime.py (Revision 52823) +++ Lib/test/test_strptime.py (Arbeitskopie) @@ -474,9 +474,9 @@ _strptime.strptime("10", "%d") _strptime.strptime("2005", "%Y") _strptime._TimeRE_cache.locale_time.lang = "Ni" - original_time_re = id(_strptime._TimeRE_cache) + original_time_re = sys.id(_strptime._TimeRE_cache) _strptime.strptime("10", "%d") - self.failIfEqual(original_time_re, id(_strptime._TimeRE_cache)) + self.failIfEqual(original_time_re, sys.id(_strptime._TimeRE_cache)) self.failUnlessEqual(len(_strptime._regex_cache), 1) def test_regex_cleanup(self): @@ -495,11 +495,11 @@ def test_new_localetime(self): # A new LocaleTime instance should be created when a new TimeRE object # is created. - locale_time_id = id(_strptime._TimeRE_cache.locale_time) + locale_time_id = sys.id(_strptime._TimeRE_cache.locale_time) _strptime._TimeRE_cache.locale_time.lang = "Ni" _strptime.strptime("10", "%d") self.failIfEqual(locale_time_id, - id(_strptime._TimeRE_cache.locale_time)) + sys.id(_strptime._TimeRE_cache.locale_time)) def test_main(): Index: Lib/test/seq_tests.py =================================================================== --- Lib/test/seq_tests.py (Revision 52823) +++ Lib/test/seq_tests.py (Arbeitskopie) @@ -2,6 +2,7 @@ Tests common to tuple, list and UserList.UserList """ +import sys import unittest from test import test_support @@ -304,7 +305,7 @@ for n in xrange(-3, 5): self.assertEqual(self.type2test(s*n), self.type2test(s)*n) self.assertEqual(self.type2test(s)*(-4), self.type2test([])) - self.assertEqual(id(s), id(s*1)) + self.assertEqual(sys.id(s), sys.id(s*1)) def test_subscript(self): a = self.type2test([10, 11]) Index: Lib/test/test_decimal.py =================================================================== --- Lib/test/test_decimal.py (Revision 52823) +++ Lib/test/test_decimal.py (Arbeitskopie) @@ -396,25 +396,25 @@ d = Decimal(45) e = Decimal(d) self.assertEqual(str(e), '45') - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) #very large positive d = Decimal(500000123) e = Decimal(d) self.assertEqual(str(e), '500000123') - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) #negative d = Decimal(-45) e = Decimal(d) self.assertEqual(str(e), '-45') - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) #zero d = Decimal(0) e = Decimal(d) self.assertEqual(str(e), '0') - self.assertNotEqual(id(d), id(e)) + self.assertNotEqual(sys.id(d), sys.id(e)) def test_explicit_context_create_decimal(self): @@ -850,9 +850,9 @@ def test_copy_and_deepcopy_methods(self): d = Decimal('43.24') c = copy.copy(d) - self.assertEqual(id(c), id(d)) + self.assertEqual(sys.id(c), sys.id(d)) dc = copy.deepcopy(d) - self.assertEqual(id(dc), id(d)) + self.assertEqual(sys.id(dc), sys.id(d)) def test_hash_method(self): #just that it's hashable @@ -1053,9 +1053,9 @@ # All copies should be deep c = Context() d = c.copy() - self.assertNotEqual(id(c), id(d)) - self.assertNotEqual(id(c.flags), id(d.flags)) - self.assertNotEqual(id(c.traps), id(d.traps)) + self.assertNotEqual(sys.id(c), sys.id(d)) + self.assertNotEqual(sys.id(c.flags), sys.id(d.flags)) + self.assertNotEqual(sys.id(c.traps), sys.id(d.traps)) def test_main(arith=False, verbose=None): """ Execute the tests. Index: Lib/test/test_weakref.py =================================================================== --- Lib/test/test_weakref.py (Revision 52823) +++ Lib/test/test_weakref.py (Arbeitskopie) @@ -671,7 +671,7 @@ class MyRef(weakref.ref): pass o = Object(42) - r1 = MyRef(o, id) + r1 = MyRef(o, sys.id) r2 = MyRef(o, str) self.assert_(r1 is not r2) refs = weakref.getweakrefs(o) @@ -1111,7 +1111,7 @@ >>> import weakref >>> _id2obj_dict = weakref.WeakValueDictionary() >>> def remember(obj): -... oid = id(obj) +... oid = sys.id(obj) ... _id2obj_dict[oid] = obj ... return oid ... Index: Lib/test/test_enumerate.py =================================================================== --- Lib/test/test_enumerate.py (Revision 52823) +++ Lib/test/test_enumerate.py (Arbeitskopie) @@ -105,8 +105,8 @@ def test_tuple_reuse(self): # Tests an implementation detail where tuple is reused # whenever nothing else holds a reference to it - self.assertEqual(len(set(map(id, list(enumerate(self.seq))))), len(self.seq)) - self.assertEqual(len(set(map(id, enumerate(self.seq)))), min(1,len(self.seq))) + self.assertEqual(len(set(map(sys.id, list(enumerate(self.seq))))), len(self.seq)) + self.assertEqual(len(set(map(sys.id, enumerate(self.seq)))), min(1,len(self.seq))) class MyEnum(enumerate): pass Index: Lib/test/test_copy.py =================================================================== --- Lib/test/test_copy.py (Revision 52823) +++ Lib/test/test_copy.py (Arbeitskopie) @@ -313,7 +313,7 @@ memo = {} x = 42 y = copy.deepcopy(x, memo) - self.assert_(memo[id(x)] is x) + self.assert_(memo[sys.id(x)] is x) def test_deepcopy_inst_vanilla(self): class C: Index: Lib/test/test_class.py =================================================================== --- Lib/test/test_class.py (Revision 52823) +++ Lib/test/test_class.py (Arbeitskopie) @@ -1,5 +1,6 @@ "Test the functionality of Python classes implementing operators." +import sys from test.test_support import TestFailed testmeths = [ @@ -66,7 +67,7 @@ class AllTests: def __hash__(self, *args): print "__hash__:", args - return hash(id(self)) + return hash(sys.id(self)) def __str__(self, *args): print "__str__:", args Index: Lib/test/test_builtin.py =================================================================== --- Lib/test/test_builtin.py (Revision 52823) +++ Lib/test/test_builtin.py (Arbeitskopie) @@ -648,16 +648,6 @@ self.assertEqual(hex(-16L), '-0x10') self.assertRaises(TypeError, hex, {}) - def test_id(self): - id(None) - id(1) - id(1L) - id(1.0) - id('spam') - id((0,1,2,3)) - id([0,1,2,3]) - id({'spam': 1, 'eggs': 2, 'ham': 3}) - def test_int(self): self.assertEqual(int(314), 314) self.assertEqual(int(3.14), 3) @@ -829,30 +819,6 @@ self.assertEqual(int(Foo4()), 42L) self.assertRaises(TypeError, int, Foo5()) - def test_intern(self): - self.assertRaises(TypeError, intern) - s = "never interned before" - self.assert_(intern(s) is s) - s2 = s.swapcase().swapcase() - self.assert_(intern(s2) is s) - - # Subclasses of string can't be interned, because they - # provide too much opportunity for insane things to happen. - # We don't want them in the interned dict and if they aren't - # actually interned, we don't want to create the appearance - # that they are by allowing intern() to succeeed. - class S(str): - def __hash__(self): - return 123 - - self.assertRaises(TypeError, intern, S("abc")) - - # It's still safe to pass these strings to routines that - # call intern internally, e.g. PyObject_SetAttr(). - s = S("abc") - setattr(s, s, s) - self.assertEqual(getattr(s, s), s) - def test_iter(self): self.assertRaises(TypeError, iter) self.assertRaises(TypeError, iter, 42, 42) Index: Lib/test/test_funcattrs.py =================================================================== --- Lib/test/test_funcattrs.py (Revision 52823) +++ Lib/test/test_funcattrs.py (Arbeitskopie) @@ -1,5 +1,6 @@ from test.test_support import verbose, TestFailed, verify import types +import sys class F: def a(self): @@ -133,10 +134,10 @@ # im_func may not be a Python method! import new -F.id = new.instancemethod(id, None, F) +F.id = new.instancemethod(sys.id, None, F) eff = F() -if eff.id() != id(eff): +if eff.id() != sys.id(eff): raise TestFailed try: Index: Lib/test/test_sys.py =================================================================== --- Lib/test/test_sys.py (Revision 52823) +++ Lib/test/test_sys.py (Arbeitskopie) @@ -350,6 +350,41 @@ # the test runs under regrtest. self.assert_(sys.__stdout__.encoding == sys.__stderr__.encoding) + def test_id(self): + sys.id(None) + sys.id(1) + sys.id(1L) + sys.id(1.0) + sys.id('spam') + sys.id((0,1,2,3)) + sys.id([0,1,2,3]) + sys.id({'spam': 1, 'eggs': 2, 'ham': 3}) + + def test_intern(self): + self.assertRaises(TypeError, sys.intern) + s = "never interned before" + self.assert_(sys.intern(s) is s) + s2 = s.swapcase().swapcase() + self.assert_(sys.intern(s2) is s) + + # Subclasses of string can't be interned, because they + # provide too much opportunity for insane things to happen. + # We don't want them in the interned dict and if they aren't + # actually interned, we don't want to create the appearance + # that they are by allowing intern() to succeeed. + class S(str): + def __hash__(self): + return 123 + + self.assertRaises(TypeError, sys.intern, S("abc")) + + # It's still safe to pass these strings to routines that + # call intern internally, e.g. PyObject_SetAttr(). + s = S("abc") + setattr(s, s, s) + self.assertEqual(getattr(s, s), s) + + def test_main(): test.test_support.run_unittest(SysModuleTest) Index: Lib/codecs.py =================================================================== --- Lib/codecs.py (Revision 52823) +++ Lib/codecs.py (Arbeitskopie) @@ -87,7 +87,8 @@ return self def __repr__(self): - return "<%s.%s object for encoding %s at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, id(self)) + return "<%s.%s object for encoding %s at 0x%x>" % (self.__class__.__module__, + self.__class__.__name__, self.name, sys.id(self)) class Codec: Index: Lib/plat-mac/Audio_mac.py =================================================================== --- Lib/plat-mac/Audio_mac.py (Revision 52823) +++ Lib/plat-mac/Audio_mac.py (Arbeitskopie) @@ -1,6 +1,8 @@ QSIZE = 100000 error='Audio_mac.error' +import sys + class Play_Audio_mac: def __init__(self, qsize=QSIZE): @@ -57,7 +59,7 @@ import audioop data = audioop.add(data, '\x80'*len(data), 1) h1 = struct.pack('llHhllbbl', - id(data)+MacOS.string_id_to_buffer, + sys.id(data)+MacOS.string_id_to_buffer, self._nchannels, self._outrate, 0, 0, Index: Lib/plat-mac/plistlib.py =================================================================== --- Lib/plat-mac/plistlib.py (Revision 52823) +++ Lib/plat-mac/plistlib.py (Arbeitskopie) @@ -61,6 +61,7 @@ import binascii import datetime from cStringIO import StringIO +import sys import re @@ -380,7 +381,7 @@ elif isinstance(other, str): return self.data == other else: - return id(self) == id(other) + return sys.id(self) == sys.id(other) def __repr__(self): return "%s(%s)" % (self.__class__.__name__, repr(self.data)) Index: Lib/plat-mac/PixMapWrapper.py =================================================================== --- Lib/plat-mac/PixMapWrapper.py (Revision 52823) +++ Lib/plat-mac/PixMapWrapper.py (Arbeitskopie) @@ -7,6 +7,7 @@ from Carbon import Qd from Carbon import QuickDraw +import sys import struct import MacOS import img @@ -66,7 +67,7 @@ def __init__(self): self.__dict__['data'] = '' self._header = struct.pack("lhhhhhhhlllhhhhlll", - id(self.data)+MacOS.string_id_to_buffer, + sys.id(self.data)+MacOS.string_id_to_buffer, 0, # rowBytes 0, 0, 0, 0, # bounds 0, # pmVersion @@ -96,7 +97,7 @@ raise 'UseErr', "don't assign to .baseAddr -- assign to .data instead" elif attr == 'data': self.__dict__['data'] = val - self._stuff('baseAddr', id(self.data) + MacOS.string_id_to_buffer) + self._stuff('baseAddr', sys.id(self.data) + MacOS.string_id_to_buffer) elif attr == 'rowBytes': # high bit is always set for some odd reason self._stuff('rowBytes', val | 0x8000) Index: Lib/plat-mac/pimp.py =================================================================== --- Lib/plat-mac/pimp.py (Revision 52823) +++ Lib/plat-mac/pimp.py (Arbeitskopie) @@ -564,7 +564,7 @@ """Compare two packages, where the "better" package sorts lower.""" if not isinstance(other, PimpPackage): - return cmp(id(self), id(other)) + return cmp(sys.id(self), sys.id(other)) if self.name() != other.name(): return cmp(self.name(), other.name()) if self.version() != other.version(): Index: Lib/pickle.py =================================================================== --- Lib/pickle.py (Revision 52823) +++ Lib/pickle.py (Arbeitskopie) @@ -241,10 +241,10 @@ # growable) array, indexed by memo key. if self.fast: return - assert id(obj) not in self.memo + assert sys.id(obj) not in self.memo memo_len = len(self.memo) self.write(self.put(memo_len)) - self.memo[id(obj)] = memo_len, obj + self.memo[sys.id(obj)] = memo_len, obj # Return a PUT (BINPUT, LONG_BINPUT) opcode string, with argument i. def put(self, i, pack=struct.pack): @@ -274,7 +274,7 @@ return # Check the memo - x = self.memo.get(id(obj)) + x = self.memo.get(sys.id(obj)) if x: self.write(self.get(x[0])) return @@ -547,8 +547,8 @@ for element in obj: save(element) # Subtle. Same as in the big comment below. - if id(obj) in memo: - get = self.get(memo[id(obj)][0]) + if sys.id(obj) in memo: + get = self.get(memo[sys.id(obj)][0]) write(POP * n + get) else: write(_tuplesize2code[n]) @@ -561,7 +561,7 @@ for element in obj: save(element) - if id(obj) in memo: + if sys.id(obj) in memo: # Subtle. d was not in memo when we entered save_tuple(), so # the process of saving the tuple's elements must have saved # the tuple itself: the tuple is recursive. The proper action @@ -569,7 +569,7 @@ # simply GET the tuple (it's already constructed). This check # could have been done in the "for element" loop instead, but # recursive tuples are a rare thing. - get = self.get(memo[id(obj)][0]) + get = self.get(memo[sys.id(obj)][0]) if proto: write(POP_MARK + get) else: # proto 0 -- POP_MARK not available @@ -745,10 +745,10 @@ the memo itself... """ try: - memo[id(memo)].append(x) + memo[sys.id(memo)].append(x) except KeyError: # aha, this is the first one :-) - memo[id(memo)]=[x] + memo[sys.id(memo)]=[x] # A cache for whichmodule(), mapping a function object to the name of Index: Lib/xml/dom/expatbuilder.py =================================================================== --- Lib/xml/dom/expatbuilder.py (Revision 52823) +++ Lib/xml/dom/expatbuilder.py (Arbeitskopie) @@ -27,6 +27,7 @@ # calling any methods on the node object if it exists. (A rather # nice speedup is achieved this way as well!) +import sys from xml.dom import xmlbuilder, minidom, Node from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE from xml.parsers import expat @@ -144,7 +145,7 @@ self._filter = None # This *really* doesn't do anything in this case, so # override it with something fast & minimal. - self._finish_start_element = id + self._finish_start_element = sys.id self._parser = None self.reset() @@ -263,7 +264,7 @@ self._parser.CommentHandler = self.comment_handler self._parser.ProcessingInstructionHandler = self.pi_handler if not (self._elem_info or self._filter): - self._finish_end_element = id + self._finish_end_element = sys.id def pi_handler(self, target, data): node = self.document.createProcessingInstruction(target, data) @@ -349,7 +350,7 @@ def first_element_handler(self, name, attributes): if self._filter is None and not self._elem_info: - self._finish_end_element = id + self._finish_end_element = sys.id self.getParser().StartElementHandler = self.start_element_handler self.start_element_handler(name, attributes) Index: Lib/xml/dom/minidom.py =================================================================== --- Lib/xml/dom/minidom.py (Revision 52823) +++ Lib/xml/dom/minidom.py (Arbeitskopie) @@ -14,6 +14,7 @@ * SAX 2 namespaces """ +import sys import xml.dom from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE, domreg @@ -520,7 +521,7 @@ if self._attrs is getattr(other, "_attrs", None): return 0 else: - return cmp(id(self), id(other)) + return cmp(sys.id(self), sys.id(other)) def __getitem__(self, attname_or_tuple): if isinstance(attname_or_tuple, tuple): @@ -796,7 +797,7 @@ self, namespaceURI, localName, NodeList()) def __repr__(self): - return "" % (self.tagName, id(self)) + return "" % (self.tagName, sys.id(self)) def writexml(self, writer, indent="", addindent="", newl=""): # indent = current indentation Index: Lib/xml/etree/ElementTree.py =================================================================== --- Lib/xml/etree/ElementTree.py (Revision 52823) +++ Lib/xml/etree/ElementTree.py (Arbeitskopie) @@ -168,7 +168,7 @@ self._children = [] def __repr__(self): - return "" % (self.tag, id(self)) + return "" % (self.tag, sys.id(self)) ## # Creates a new element object of the same type as this element.