当前位置: 首页>>代码示例>>Python>>正文


Python engine.Engine类代码示例

本文整理汇总了Python中pants.engine.Engine的典型用法代码示例。如果您正苦于以下问题:Python Engine类的具体用法?Python Engine怎么用?Python Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestEngineInstallPoller

class TestEngineInstallPoller(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()

    def test_custom_poller(self):
        poller = MagicMock()
        self.engine._poller = None
        self.engine._channels = {}
        self.engine._install_poller(poller)
        self.assertTrue(self.engine._poller is poller)

    @unittest.skip("Not yet implemented.")
    def test_custom_poller_with_existing_channels(self):
        self.fail("Not yet implemented.")

    @unittest.skip("Not yet implemented.")
    def test_custom_poller_with_existing_channels_and_poller(self):
        self.fail("Not yet implemented.")

    @unittest.skip("Not yet implemented.")
    @unittest.skipUnless(hasattr(select, "epoll"), "epoll-specific functionality.")
    def test_defaulting_to_epoll(self):
        self.fail("Not yet implemented.")

    @unittest.skip("Not yet implemented.")
    @unittest.skipIf(hasattr(select, "epoll"), "kqueue-specific functionality.")
    @unittest.skipUnless(hasattr(select, "kqueue"), "kqueue-specific functionality.")
    def test_defaulting_to_kqueue(self):
        self.fail("Not yet implemented.")

    @unittest.skip("Not yet implemented.")
    @unittest.skipIf(hasattr(select, "epoll"), "select-specific functionality.")
    @unittest.skipIf(hasattr(select, "kqueue"), "select-specific functionality.")
    def test_defaulting_to_select(self):
        self.fail("Not yet implemented.")
开发者ID:larbing,项目名称:pants,代码行数:35,代码来源:test_engine.py

示例2: install

def install(app=None, timeout=0.02):
    """
    Creates a :class:`~PySide.QtCore.QTimer` instance that will be triggered
    continuously to call :func:`Engine.poll() <pants.engine.Engine.poll>`,
    ensuring that Pants remains responsive.

    =========  ========  ============
    Argument   Default   Description
    =========  ========  ============
    app        None      *Optional.* The :class:`~PySide.QtCore.QCoreApplication` to attach to. If no application is provided, it will attempt to find an existing application in memory, or, failing that, create a new application instance.
    timeout    ``0.02``  *Optional.* The maximum time to wait, in seconds, before running :func:`Engine.poll() <pants.engine.Engine.poll>`.
    =========  ========  ============
    """
    global timer
    global _timeout

    Engine.instance()._install_poller(_Qt())

    if app is None:
        app = QCoreApplication.instance()
    if app is None:
        app = QCoreApplication([])

    _timeout = timeout * 1000

    timer = QTimer(app)
    timer.timeout.connect(do_poll)
    timer.start(_timeout)
开发者ID:ixokai,项目名称:pants,代码行数:28,代码来源:qt.py

示例3: test_channel_is_modified_on_poller

 def test_channel_is_modified_on_poller(self):
     engine = Engine()
     channel = MagicMock()
     channel.fileno = "foo"
     channel._events = "bar"
     engine._poller.modify = MagicMock()
     engine.modify_channel(channel)
     engine._poller.modify.assert_called_once_with(channel.fileno, channel._events)
开发者ID:larbing,项目名称:pants,代码行数:8,代码来源:test_engine.py

示例4: process

 def process(self):
     """
     Block until the queued requests finish.
     """
     if not self._requests:
         return
     
     self._processing = True
     from pants.engine import Engine
     Engine.instance().start()
开发者ID:chris-statzer,项目名称:ganos,代码行数:10,代码来源:http.py

示例5: close

    def close(self):
        """
        Close the channel.
        """
        if self._socket is None:
            return

        Engine.instance().remove_channel(self)
        self._socket_close()
        self._safely_call(self.on_close)
开发者ID:ixokai,项目名称:pants,代码行数:10,代码来源:_channel.py

示例6: callback

            def callback(*a,**kw):
                if kw:
                    if a:
                        a = a + (kw, )
                    else:
                        a = kw

                if isinstance(a, tuple) and len(a) == 1:
                    a = a[0]

                data.append(a)
                Engine.instance().stop()
开发者ID:Sureiya,项目名称:pants,代码行数:12,代码来源:dns.py

示例7: TestEngineRemoveChannel

class TestEngineRemoveChannel(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.poller = MagicMock()
        self.poller.remove = MagicMock()
        self.engine._poller = self.poller
        self.channel = MagicMock()
        self.channel.fileno = "foo"
        self.channel._events = "bar"
        self.engine._channels[self.channel.fileno] = self.channel

    def test_channel_is_removed_from_engine(self):
        self.engine.remove_channel(self.channel)
        self.assertFalse(self.channel.fileno in self.engine._channels)

    def test_channel_is_removed_from_poller(self):
        self.engine.remove_channel(self.channel)
        self.poller.remove.assert_called_once_with(self.channel.fileno, self.channel._events)

    def test_removing_channel_from_poller_raises_IOError(self):
        self.poller.remove = MagicMock(side_effect=IOError())
        self.engine.remove_channel(self.channel)
        self.poller.remove.assert_called_once_with(self.channel.fileno, self.channel._events)

    def test_removing_channel_from_poller_raises_OSError(self):
        self.poller.remove = MagicMock(side_effect=OSError())
        self.engine.remove_channel(self.channel)
        self.poller.remove.assert_called_once_with(self.channel.fileno, self.channel._events)

    def test_removing_channel_from_poller_raises_unknown(self):
        self.poller.remove = MagicMock(side_effect=Exception())
        self.assertRaises(Exception, self.engine.remove_channel, self.channel)
        self.poller.remove.assert_called_once_with(self.channel.fileno, self.channel._events)
开发者ID:larbing,项目名称:pants,代码行数:33,代码来源:test_engine.py

示例8: _handle_events

    def _handle_events(self, events):
        """
        Handle events raised on the channel.

        =========  ============
        Argument   Description
        =========  ============
        events     The events in the form of an integer.
        =========  ============
        """
        if self._socket is None:
            log.warning("Received events for closed %s #%d." %
                    (self.__class__.__name__, self.fileno))
            return

        if events & Engine.READ:
            self._wait_for_read_event = False
            self._handle_read_event()
            if self._socket is None:
                return

        if events & Engine.WRITE:
            self._wait_for_write_event = False
            self._handle_write_event()
            if self._socket is None:
                return

        if events & Engine.ERROR:
            err, errstr = self._get_socket_error()
            if err != 0:
                log.error("Error on %s #%d: %s (%d)" %
                        (self.__class__.__name__, self.fileno, errstr, err))
            self.close()
            return

        if events & Engine.HANGUP:
            log.debug("Hang up on %s #%d." %
                    (self.__class__.__name__, self.fileno))
            self.close()
            return

        events = Engine.ERROR | Engine.HANGUP
        if self._wait_for_read_event:
            events |= Engine.READ
        if self._wait_for_write_event:
            events |= Engine.WRITE
        if events != self._events:
            self._events = events
            Engine.instance().modify_channel(self)
开发者ID:ixokai,项目名称:pants,代码行数:49,代码来源:_channel.py

示例9: TestEngineStop

class TestEngineStop(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()

    def test_when_running(self):
        self.engine._shutdown = False
        self.engine._running = True
        self.engine.stop()
        self.assertTrue(self.engine._shutdown)

    def test_when_not_running(self):
        self.engine._shutdown = False
        self.engine._running = False
        self.engine.stop()
        self.assertFalse(self.engine._shutdown)
开发者ID:larbing,项目名称:pants,代码行数:15,代码来源:test_engine.py

示例10: _handle_events

 def _handle_events(self, events):
     """
     Args:
         events: The events raised on the channel.
     """
     if not self.active():
         log.warning("Received events for closed channel %d." % self.fileno)
         return
     
     # Read event.
     if events & Engine.READ:
         if self._listening:
             self._handle_accept_event()
         elif not self._connected:
             self._handle_connect_event()
         else:
             self._handle_read_event()
         if not self.active():
             return
     
     # Write event.
     if events & Engine.WRITE:
         if not self._connected:
             self._handle_connect_event()
         else:
             self._handle_write_event()
         if not self.active():
             return
     
     # Error event.
     if events & Engine.ERROR:
         self.close_immediately()
         return
     
     # Update events.
     events = Engine.ERROR
     if self.readable():
         events |= Engine.READ
     if self.writable():
         events |= Engine.WRITE
     elif self._closing:
         # Done writing, so close.
         self.close_immediately()
         return
     
     if events != self._events:
         self._events = events
         Engine.instance().modify_channel(self)
开发者ID:chris-statzer,项目名称:ganos,代码行数:48,代码来源:channel.py

示例11: start_event

def start_event(owner, delay, event_func, data=None, arg='', *args, **kwargs):
    """
    Schedule a new event to trigger after ``delay`` seconds. Owners may be any
    Python object, but should be an instance of one of:
    :class:`account.Account`, :class:`char.Char`, :class:`exit.Exit`,
    :class:`mudsock.Mudsock`, :class:`obj.Obj`, or :class:`room.Room`.

    If the owner *is* one of those classes, any currently pending events are
    de-scheduled automatically when the owner is destroyed.

    Event functions should take a minimum of three arguments: the event owner,
    ``data``, and ``arg``. This is for compatibility with NakedMud. You may
    provide additional positional and keyword arguments if you wish.

    Returns a callable that de-schedules the event when called.

    ===========  ============
    Argument     Description
    ===========  ============
    owner        The object that owns the event.
    delay        How long, in seconds, to wait before the event function should be called.
    event_func   The function to be called.
    data         *Optional.* Any Python object to be provided to the event function.
    arg          *Optional.* A string to be provided to the event function.
    ===========  ============
    """
    if not owner in __queued__:
        __queued__[owner] = []

    event = Engine.instance().defer(delay, event_func, owner, data, arg, *args, **kwargs)
    __queued__[owner].append(event)
    return event
开发者ID:stendec,项目名称:NakedSun,代码行数:32,代码来源:event.py

示例12: setUp

 def setUp(self):
     self.engine = Engine()
     self.poller = MagicMock()
     self.poller.add = MagicMock()
     self.engine._poller = self.poller
     self.channel = MagicMock()
     self.channel.fileno = "foo"
     self.channel._events = "bar"
开发者ID:larbing,项目名称:pants,代码行数:8,代码来源:test_engine.py

示例13: setUp

    def setUp(self):
        self.app = Application()
        self.init_app(self.app)

        engine = Engine.instance()
        self.server = HTTPServer(self.app, engine=engine)
        self.server.listen(('127.0.0.1', 4040))
        PantsTestCase.setUp(self, engine)
开发者ID:Sureiya,项目名称:pants,代码行数:8,代码来源:test_web_application.py

示例14: close_immediately

 def close_immediately(self):
     """
     Close the socket immediately.
     
     Any pending data will not be sent.
     """
     if not self.active():
         return
     
     if self._write_file:
         self._write_file.close()
         self._write_file = None
         self._write_file_left = None
     
     Engine.instance().remove_channel(self)
     self._socket_close()
     self._update_addr()
     self._safely_call(self.handle_close)
开发者ID:chris-statzer,项目名称:ganos,代码行数:18,代码来源:channel.py

示例15: TestEngineAddChannel

class TestEngineAddChannel(unittest.TestCase):
    def setUp(self):
        self.engine = Engine()
        self.poller = MagicMock()
        self.poller.add = MagicMock()
        self.engine._poller = self.poller
        self.channel = MagicMock()
        self.channel.fileno = "foo"
        self.channel._events = "bar"

    def test_channel_is_added_to_engine(self):
        self.engine.add_channel(self.channel)
        self.assertTrue(self.channel.fileno in self.engine._channels)
        self.assertEqual(self.engine._channels[self.channel.fileno], self.channel)

    def test_channel_is_added_to_poller(self):
        self.engine.add_channel(self.channel)
        self.poller.add.assert_called_once_with(self.channel.fileno, self.channel._events)
开发者ID:larbing,项目名称:pants,代码行数:18,代码来源:test_engine.py


注:本文中的pants.engine.Engine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。