Ticket #4065: callable-not-supported.diff

File callable-not-supported.diff, 9.1 KB (added by Carlos Valiente, 8 years ago)
  • twisted/internet/base.py

    === modified file 'twisted/internet/base.py'
     
    614614    def addSystemEventTrigger(self, _phase, _eventType, _f, *args, **kw):
    615615        """See twisted.internet.interfaces.IReactorCore.addSystemEventTrigger.
    616616        """
    617         assert callable(_f), "%s is not callable" % _f
     617        assert hasattr(_f, "__call__"), "%s is not callable" % _f
    618618        if _eventType not in self._eventTriggers:
    619619            self._eventTriggers[_eventType] = _ThreePhaseEvent()
    620620        return (_eventType, self._eventTriggers[_eventType].addTrigger(
     
    671671    def callLater(self, _seconds, _f, *args, **kw):
    672672        """See twisted.internet.interfaces.IReactorTime.callLater.
    673673        """
    674         assert callable(_f), "%s is not callable" % _f
     674        assert hasattr(_f, "__call__"), "%s is not callable" % _f
    675675        assert sys.maxint >= _seconds >= 0, \
    676676               "%s is not greater than or equal to 0 seconds" % (_seconds,)
    677677        tple = DelayedCall(self.seconds() + _seconds, _f, args, kw,
     
    896896            """
    897897            See L{twisted.internet.interfaces.IReactorThreads.callFromThread}.
    898898            """
    899             assert callable(f), "%s is not callable" % (f,)
     899            assert hasattr(f, "__call__"), "%s is not callable" % (f,)
    900900            # lists are thread-safe in CPython, but not in Jython
    901901            # this is probably a bug in Jython, but until fixed this code
    902902            # won't work in Jython.
     
    957957    else:
    958958        # This is for signal handlers.
    959959        def callFromThread(self, f, *args, **kw):
    960             assert callable(f), "%s is not callable" % (f,)
     960            assert hasattr(f, "__call__"), "%s is not callable" % (f,)
    961961            # See comment in the other callFromThread implementation.
    962962            self.threadCallQueue.append((f, args, kw))
    963963
  • twisted/internet/defer.py

    === modified file 'twisted/internet/defer.py'
     
    171171
    172172        These will be executed when the 'master' callback is run.
    173173        """
    174         assert callable(callback)
    175         assert errback == None or callable(errback)
     174        assert hasattr(callback, "__call__")
     175        assert errback == None or hasattr(errback, "__call__")
    176176        cbs = ((callback, callbackArgs, callbackKeywords),
    177177               (errback or (passthru), errbackArgs, errbackKeywords))
    178178        self.callbacks.append(cbs)
  • twisted/mail/imap4.py

    === modified file 'twisted/mail/imap4.py'
     
    622622
    623623    def __doCommand(self, tag, handler, args, parseargs, line, uid):
    624624        for (i, arg) in enumerate(parseargs):
    625             if callable(arg):
     625            if hasattr(arg, "__call__"):
    626626                parseargs = parseargs[i+1:]
    627627                maybeDeferred(arg, self, line).addCallback(
    628628                    self.__cbDispatch, tag, handler, args,
  • twisted/mail/test/test_mail.py

    === modified file 'twisted/mail/test/test_mail.py'
     
    640640            )
    641641
    642642    def _cbValidateTo(self, result):
    643         self.failUnless(callable(result))
     643        self.failUnless(hasattr(result, "__call__"))
    644644
    645645    def testValidateToBadUsername(self):
    646646        user = smtp.User('resu@test.domain', 'helo', None, 'wherever@whatever')
     
    763763            user.protocol.transport = empty()
    764764            user.protocol.transport.getPeer = lambda: peer
    765765
    766             self.failUnless(callable(domain.exists(user)))
     766            self.failUnless(hasattr(domain.exists(user), "__call__"))
    767767
    768768        for peer in dontRelay:
    769769            user = empty()
  • twisted/manhole/service.py

    === modified file 'twisted/manhole/service.py'
     
    119119        kw = {}
    120120    if localNS is None:
    121121        localNS = globalNS
    122     if (globalNS is None) and (not callable(command)):
     122    if (globalNS is None) and (not hasattr(command, "__call__")):
    123123        raise ValueError("Need a namespace to evaluate the command in.")
    124124
    125125    try:
     
    128128        sys.stdout = fakeout
    129129        sys.stderr = fakeerr
    130130        try:
    131             if callable(command):
     131            if hasattr(command, "__call__"):
    132132                val = apply(command, args, kw)
    133133            else:
    134134                try:
  • twisted/python/log.py

    === modified file 'twisted/python/log.py'
     
    250250        @param other: A callable object that will be called with each new log
    251251            message (a dict).
    252252        """
    253         assert callable(other)
     253        assert hasattr(other, "__call__")
    254254        self.observers.append(other)
    255255
    256256    def removeObserver(self, other):
  • twisted/python/zshcomp.py

    === modified file 'twisted/python/zshcomp.py'
     
    526526        @return: C{str}
    527527        """
    528528        if long in self.actions:
    529             if callable(self.actions[long]):
     529            if hasattr(self.actions[long], "__call__"):
    530530                action = self.actions[long]()
    531531            else:
    532532                action = self.actions[long]
  • twisted/spread/pb.py

    === modified file 'twisted/spread/pb.py'
     
    279279
    280280        This callback will be called with one argument, this instance.
    281281        """
    282         assert callable(callback)
     282        assert hasattr(callback, "__call__")
    283283        self.disconnectCallbacks.append(callback)
    284284        if len(self.disconnectCallbacks) == 1:
    285285            self.broker.notifyOnDisconnect(self._disconnected)
     
    605605
    606606    def notifyOnDisconnect(self, notifier):
    607607        """Call the given callback when the Broker disconnects."""
    608         assert callable(notifier)
     608        assert hasattr(notifier, "__call__")
    609609        self.disconnects.append(notifier)
    610610
    611611    def notifyOnFail(self, notifier):
    612612        """Call the given callback if the Broker fails to connect."""
    613         assert callable(notifier)
     613        assert hasattr(notifier, "__call__")
    614614        self.failures.append(notifier)
    615615
    616616    def notifyOnConnect(self, notifier):
    617617        """Call the given callback when the Broker connects."""
    618         assert callable(notifier)
     618        assert hasattr(notifier, "__call__")
    619619        if self.connects is None:
    620620            try:
    621621                notifier()
  • twisted/spread/util.py

    === modified file 'twisted/spread/util.py'
     
    9292        Create a pager with a Reference to a remote collector and
    9393        an optional callable to invoke upon completion.
    9494        """
    95         if callable(callback):
     95        if hasattr(callback, "__call__"):
    9696            self.callback = callback
    9797            self.callbackArgs = args
    9898            self.callbackKeyword = kw
  • twisted/trial/test/test_assertions.py

    === modified file 'twisted/trial/test/test_assertions.py'
     
    640640
    641641    def test_equalSpelling(self):
    642642        for name, value in vars(self).items():
    643             if not callable(value):
     643            if not hasattr(value, "__call__"):
    644644                continue
    645645            if name.endswith('Equal'):
    646646                self.failUnless(hasattr(self, name+'s'),
  • twisted/trial/test/test_pyunitcompat.py

    === modified file 'twisted/trial/test/test_pyunitcompat.py'
     
    5050        """
    5151        Tests must be callable in order to be used with Python's unittest.py.
    5252        """
    53         self.assertTrue(callable(self.test),
     53        self.assertTrue(hasattr(self.test, "__call__"),
    5454                        "%r is not callable." % (self.test,))
    5555
    5656
  • twisted/web/xmlrpc.py

    === modified file 'twisted/web/xmlrpc.py'
     
    179179        if not f:
    180180            raise NoSuchFunction(self.NOT_FOUND,
    181181                "function %s not found" % functionPath)
    182         elif not callable(f):
     182        elif not hasattr(f, "__call__"):
    183183            raise NoSuchFunction(self.NOT_FOUND,
    184184                "function %s not callable" % functionPath)
    185185        else:
  • twisted/web2/xmlrpc.py

    === modified file 'twisted/web2/xmlrpc.py'
     
    131131        f = getattr(self, "xmlrpc_%s" % functionPath, None)
    132132        if not f:
    133133            raise NoSuchFunction(self.NOT_FOUND, "function %s not found" % functionPath)
    134         elif not callable(f):
     134        elif not hasattr(f, "__call__"):
    135135            raise NoSuchFunction(self.NOT_FOUND, "function %s not callable" % functionPath)
    136136        else:
    137137            return f