@@ -0,0 +1,3385 @@
+#!/usr/bin/env python%0A# -*- encoding: utf-8 -*-%0A#%0A# Copyright (c) 2016 ASMlover. All rights reserved.%0A#%0A# Redistribution and use in source and binary forms, with or without%0A# modification, are permitted provided that the following conditions%0A# are met:%0A#%0A#  * Redistributions of source code must retain the above copyright%0A#    notice, this list ofconditions and the following disclaimer.%0A#%0A#  * Redistributions in binary form must reproduce the above copyright%0A#    notice, this list of conditions and the following disclaimer in%0A#    the documentation and/or other materialsprovided with the%0A#    distribution.%0A#%0A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%0A# %22AS IS%22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%0A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS%0A# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE%0A# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,%0A# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,%0A# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;%0A# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER%0A# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT%0A# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN%0A# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE%0A# POSSIBILITY OF SUCH DAMAGE.%0A%0Aimport asyncore%0Aimport errno%0Aimport heapq%0Aimport time%0Aimport traceback%0Aimport sys%0A%0AaioTasks = %5B%5D%0AaioCancelledNum = 0%0A%0Aclass CallerDelay(object):%0A    %22%22%22call a function later%22%22%22%0A    def __init__(self, seconds, target, *args, **kwargs):%0A        assert callable(target), '%25s is not callable' %25 target%0A        assert sys.maxint %3E= seconds %3E= 0, '%25s is not %3E= 0' %25 seconds%0A%0A        self.delayTime = seconds%0A        self.target = target%0A        self.args = args%0A        self.kwargs = kwargs%0A        self.errorBack = kwargs.pop('errorBack', None)%0A        self.repush = False%0A        self.timeout = time.time() + self.delayTime%0A        self.cancelled = False%0A        self.expired = False%0A        heapq.heappush(aioTasks, self)%0A%0A    def __le__(self, other):%0A        return self.timeout %3C= other.timeout%0A%0A    def call(self):%0A        assert not self.cancelled, 'Already cancelled'%0A        try:%0A            try:%0A                self.target(*self.args, **self.kwargs)%0A            except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):%0A                raise%0A            except:%0A                if self.errorBack:%0A                    self.errorBack()%0A                else:%0A                    raise%0A        finally:%0A            if not self.cancelled:%0A                self.expire()%0A%0A    def reset(self):%0A        assert not self.cancelled, 'Already cancelled'%0A        self.timeout = time.time() + self.delayTime%0A        self.repush = True%0A%0A    def delay(self, seconds):%0A        assert not self.cancelled, 'Already cancelled'%0A        assert sys.maxint %3E= seconds %3E= 0, '%25s is not %3E= 0' %25 seconds%0A%0A        self.delayTime = seconds%0A        newTime = time.time() + self.delayTime%0A        if newTime %3E self.timeout:%0A            self.timeout = newTime%0A            self.repush = True%0A        else:%0A            self.timeout = newTime%0A            heapq.heapify(aioTasks)%0A%0A    def cancel(self):%0A        pass%0A%0A    def expire(self):%0A        pass%0A%0Adef loop(timeout=0.1, usePoll=True, map=None, count=None):%0A    pass%0A

add async io module