コード例 #1
0
ファイル: resource.py プロジェクト: Eveler/dmsic
    def say_hello_with_sleep(ctx, name, times, seconds):
        """Sends multiple hello messages by waiting given number of seconds
        inbetween."""

        times = [times]  # Workaround for Python 2's lacking of nonlocal

        def _cb(response):
            if times[0] > 0:
                response.append(
                    "Hello %s, sleeping for %f seconds for %d more time(s)." %
                    (name, seconds, times[0]))
                times[0] -= 1
                return deferLater(reactor, seconds, _cb, response)

        return Iterable.Push(_cb)
コード例 #2
0
    def say_hello(ctx, name, times):
        # workaround for Python2's lacking of nonlocal
        times = [times]

        def _cb(push):
            # This callback is called immediately after the function returns.

            if times[0] > 0:
                times[0] -= 1

                data = u'Hello, %s' % name
                print data

                # The object passed to the append() method is immediately
                # serialized to bytes and pushed to the response stream's
                # file-like object.
                push.append(data)

                # When a push-callback returns anything other than a deferred,
                # the response gets closed.
                return deferLater(reactor, 1, _cb, push)

        # This is Spyne's way of returning NOT_DONE_YET
        return Iterable.Push(_cb)
コード例 #3
0
    def say_hello_forever(ctx, name):
        def _cb(push):
            push.append(u'Hello, %s' % name)
            return deferLater(reactor, 0.1, _cb, push)

        return Iterable.Push(_cb)