Ticket #5544: 5544.patch
| File 5544.patch, 13.2 KB (added by zomux, 15 months ago) |
|---|
-
twisted/test/test_reflect.py
532 532 reflect.safe_repr(X()) 533 533 534 534 535 def test_unsignedID(self):536 """537 L{unsignedID} is used to print ID of the object in case of error, not538 standard ID value which can be negative.539 """540 class X(BTBase):541 breakRepr = True542 543 ids = {X: 100}544 def fakeID(obj):545 try:546 return ids[obj]547 except (TypeError, KeyError):548 return id(obj)549 self.addCleanup(util.setIDFunction, util.setIDFunction(fakeID))550 551 xRepr = reflect.safe_repr(X)552 self.assertIn("0x64", xRepr)553 554 555 535 def test_brokenClassStr(self): 556 536 class X(BTBase): 557 537 breakStr = True -
twisted/test/test_defer.py
11 11 from twisted.internet import reactor, defer 12 12 from twisted.internet.task import Clock 13 13 from twisted.python import failure, log 14 from twisted.python.util import unsignedID15 14 16 15 class GenericError(Exception): 17 16 pass … … 872 871 representation of the internal Python ID. 873 872 """ 874 873 d = defer.Deferred() 875 address = hex( unsignedID(d))874 address = hex(id(d)) 876 875 self.assertEqual( 877 876 repr(d), '<Deferred at %s>' % (address,)) 878 877 … … 886 885 d.callback('orange') 887 886 self.assertEqual( 888 887 repr(d), "<Deferred at %s current result: 'orange'>" % ( 889 hex( unsignedID(d))))888 hex(id(d)))) 890 889 891 890 892 891 def test_reprWithChaining(self): … … 900 899 b.chainDeferred(a) 901 900 self.assertEqual( 902 901 repr(a), "<Deferred at %s waiting on Deferred at %s>" % ( 903 hex( unsignedID(a)), hex(unsignedID(b))))902 hex(id(a)), hex(id(b)))) 904 903 905 904 906 905 def test_boundedStackDepth(self): -
twisted/test/test_amp.py
11 11 12 12 from zope.interface.verify import verifyObject 13 13 14 from twisted.python.util import setIDFunction15 14 from twisted.python import filepath 16 15 from twisted.python.failure import Failure 17 16 from twisted.protocols import amp … … 1357 1356 otherProto = TestProto(None, "outgoing data") 1358 1357 a = amp.AMP() 1359 1358 a.innerProtocol = otherProto 1360 def fakeID(obj):1361 return {a: 0x1234}.get(obj, id(obj))1362 self.addCleanup(setIDFunction, setIDFunction(fakeID))1363 1359 1364 1360 self.assertEqual( 1365 repr(a), "<AMP inner <TestProto #%d> at 0x1234>" % (1366 otherProto.instanceId, ))1361 repr(a), "<AMP inner <TestProto #%d> at %s>" % ( 1362 otherProto.instanceId,hex(id(a)))) 1367 1363 1368 1364 1369 1365 def test_innerProtocolNotInRepr(self): … … 1372 1368 is set. 1373 1369 """ 1374 1370 a = amp.AMP() 1375 def fakeID(obj): 1376 return {a: 0x4321}.get(obj, id(obj)) 1377 self.addCleanup(setIDFunction, setIDFunction(fakeID)) 1378 self.assertEqual(repr(a), "<AMP at 0x4321>") 1371 1372 self.assertEqual(repr(a), "<AMP at %s>" % hex(id(a))) 1379 1373 1380 1374 1381 1375 def test_simpleSSLRepr(self): -
twisted/python/util.py
764 764 continue 765 765 raise 766 766 767 _idFunction = id768 767 769 def setIDFunction(idFunction):770 """771 Change the function used by L{unsignedID} to determine the integer id value772 of an object. This is largely useful for testing to give L{unsignedID}773 deterministic, easily-controlled behavior.774 768 775 @param idFunction: A function with the signature of L{id}.776 @return: The previous function being used by L{unsignedID}.777 """778 global _idFunction779 oldIDFunction = _idFunction780 _idFunction = idFunction781 return oldIDFunction782 783 784 # A value about twice as large as any Python int, to which negative values785 # from id() will be added, moving them into a range which should begin just786 # above where positive values from id() leave off.787 _HUGEINT = (sys.maxint + 1L) * 2L788 def unsignedID(obj):789 """790 Return the id of an object as an unsigned number so that its hex791 representation makes sense.792 793 This is mostly necessary in Python 2.4 which implements L{id} to sometimes794 return a negative value. Python 2.3 shares this behavior, but also795 implements hex and the %x format specifier to represent negative values as796 though they were positive ones, obscuring the behavior of L{id}. Python797 2.5's implementation of L{id} always returns positive values.798 """799 rval = _idFunction(obj)800 if rval < 0:801 rval += _HUGEINT802 return rval803 804 805 769 def mergeFunctionMetadata(f, g): 806 770 """ 807 771 Overwrite C{g}'s name and docstring with values from C{f}. Update … … 978 942 "getPassword", "println", "makeStatBar", "OrderedDict", 979 943 "InsensitiveDict", "spewer", "searchupwards", "LineLog", 980 944 "raises", "IntervalDifferential", "FancyStrMixin", "FancyEqMixin", 981 "switchUID", "SubclassableCStringIO", " unsignedID", "mergeFunctionMetadata",945 "switchUID", "SubclassableCStringIO", "mergeFunctionMetadata", 982 946 "nameToLabel", "uidFromString", "gidFromString", "runAsEffectiveUser", 983 947 ] -
twisted/python/reflect.py
29 29 except ImportError: 30 30 from StringIO import StringIO 31 31 32 from twisted.python.util import unsignedID33 32 from twisted.python.deprecate import deprecated, deprecatedModuleAttribute 34 33 from twisted.python.deprecate import _fullyQualifiedName as fullyQualifiedName 35 34 from twisted.python.versions import Version … … 536 535 try: 537 536 return str(c) 538 537 except: 539 return '<BROKEN CLASS AT 0x%x>' % unsignedID(c)538 return '<BROKEN CLASS AT 0x%x>' % id(c) 540 539 541 540 542 541 … … 552 551 className = _determineClassName(o) 553 552 tbValue = io.getvalue() 554 553 return "<%s instance at 0x%x with %s error:\n %s>" % ( 555 className, unsignedID(o), formatter.__name__, tbValue)554 className, id(o), formatter.__name__, tbValue) 556 555 557 556 558 557 -
twisted/python/test/test_util.py
777 777 778 778 779 779 780 class UnsignedIDTests(unittest.TestCase):781 """782 Tests for L{util.unsignedID} and L{util.setIDFunction}.783 """784 def setUp(self):785 """786 Save the value of L{util._idFunction} and arrange for it to be restored787 after the test runs.788 """789 self.addCleanup(setattr, util, '_idFunction', util._idFunction)790 791 792 def test_setIDFunction(self):793 """794 L{util.setIDFunction} returns the last value passed to it.795 """796 value = object()797 previous = util.setIDFunction(value)798 result = util.setIDFunction(previous)799 self.assertIdentical(value, result)800 801 802 def test_unsignedID(self):803 """804 L{util.unsignedID} uses the function passed to L{util.setIDFunction} to805 determine the unique integer id of an object and then adjusts it to be806 positive if necessary.807 """808 foo = object()809 bar = object()810 811 # A fake object identity mapping812 objects = {foo: 17, bar: -73}813 def fakeId(obj):814 return objects[obj]815 816 util.setIDFunction(fakeId)817 818 self.assertEqual(util.unsignedID(foo), 17)819 self.assertEqual(util.unsignedID(bar), (sys.maxint + 1) * 2 - 73)820 821 822 def test_defaultIDFunction(self):823 """824 L{util.unsignedID} uses the built in L{id} by default.825 """826 obj = object()827 idValue = id(obj)828 if idValue < 0:829 idValue += (sys.maxint + 1) * 2830 831 self.assertEqual(util.unsignedID(obj), idValue)832 833 834 835 780 class InitGroupsTests(unittest.TestCase): 836 781 """ 837 782 Tests for L{util.initgroups}. -
twisted/protocols/amp.py
182 182 from zope.interface import Interface, implements 183 183 184 184 from twisted.python.compat import set 185 from twisted.python.util import unsignedID186 185 from twisted.python.reflect import accumulateClassDict 187 186 from twisted.python.failure import Failure 188 187 from twisted.python import log, filepath … … 2274 2273 else: 2275 2274 innerRepr = '' 2276 2275 return '<%s%s at 0x%x>' % ( 2277 self.__class__.__name__, innerRepr, unsignedID(self))2276 self.__class__.__name__, innerRepr, id(self)) 2278 2277 2279 2278 2280 2279 def makeConnection(self, transport): -
twisted/topfiles/5544.removal
1 twisted.python.util.unsignedID , deprecated after Python 2.5 , removed. 2 twisted.python.util.setIDFunction , the function used by unsignedID , removed -
twisted/internet/defer.py
23 23 24 24 # Twisted imports 25 25 from twisted.python import log, failure, lockfile 26 from twisted.python.util import unsignedID,mergeFunctionMetadata26 from twisted.python.util import mergeFunctionMetadata 27 27 28 28 29 29 … … 607 607 """ 608 608 cname = self.__class__.__name__ 609 609 result = getattr(self, 'result', _NO_RESULT) 610 myID = hex( unsignedID(self))610 myID = hex(id(self)) 611 611 if self._chainedTo is not None: 612 result = ' waiting on Deferred at %s' % (hex( unsignedID(self._chainedTo)),)612 result = ' waiting on Deferred at %s' % (hex(id(self._chainedTo)),) 613 613 elif result is _NO_RESULT: 614 614 result = '' 615 615 else: -
twisted/internet/tcp.py
92 92 from twisted.internet import base, address, fdesc 93 93 from twisted.internet.task import deferLater 94 94 from twisted.python import log, failure, reflect 95 from twisted.python.util import unsignedID96 95 from twisted.internet.error import CannotListenError 97 96 from twisted.internet import abstract, main, interfaces, error 98 97 … … 709 708 710 709 711 710 def __repr__(self): 712 s = '<%s to %s at %x>' % (self.__class__, self.addr, unsignedID(self))711 s = '<%s to %s at %x>' % (self.__class__, self.addr, id(self)) 713 712 return s 714 713 715 714 -
twisted/internet/test/test_base.py
11 11 from zope.interface import implements 12 12 13 13 from twisted.python.threadpool import ThreadPool 14 from twisted.python.util import setIDFunction15 14 from twisted.internet.interfaces import IReactorTime, IReactorThreads 16 15 from twisted.internet.error import DNSLookupError 17 16 from twisted.internet.base import ThreadedResolver, DelayedCall … … 188 187 def nothing(): 189 188 pass 190 189 dc = DelayedCall(12, nothing, (3, ), {"A": 5}, None, None, lambda: 1.5) 191 ids = {dc: 200} 192 def fakeID(obj): 193 try: 194 return ids[obj] 195 except (TypeError, KeyError): 196 return id(obj) 197 self.addCleanup(setIDFunction, setIDFunction(fakeID)) 190 198 191 self.assertEqual( 199 192 str(dc), 200 "<DelayedCall 0xc8 [10.5s] called=0 cancelled=0 nothing(3, A=5)>")193 "<DelayedCall %s [10.5s] called=0 cancelled=0 nothing(3, A=5)>" % hex(id(dc))) 201 194 202 195 203 196 def test_lt(self): -
twisted/internet/base.py
16 16 import traceback 17 17 18 18 from twisted.python.compat import set 19 from twisted.python.util import unsignedID20 19 from twisted.internet.interfaces import IReactorCore, IReactorTime, IReactorThreads 21 20 from twisted.internet.interfaces import IResolverSimple, IReactorPluggableResolver 22 21 from twisted.internet.interfaces import IConnector, IDelayedCall … … 186 185 187 186 now = self.seconds() 188 187 L = ["<DelayedCall 0x%x [%ss] called=%s cancelled=%s" % ( 189 unsignedID(self), self.time - now, self.called,188 id(self), self.time - now, self.called, 190 189 self.cancelled)] 191 190 if func is not None: 192 191 L.extend((" ", func, "("))
