Ticket #3802: twisted-3802.2.patch

File twisted-3802.2.patch, 5.6 KB (added by Lucas Taylor, 12 years ago)

Patch addresses review

  • twisted/internet/interfaces.py

     
    408408        """
    409409
    410410
     411
     412class IReactorWin32Events(Interface):
     413    """
     414    Win32 Event API methods
     415    """
     416   
     417    def addEvent(event, fd, action):
     418        """
     419        Add a new win32 event to the event loop.
     420
     421        @param event: a Win32 event object created using win32event.CreateEvent()
     422
     423        @param fd: an instance of L{twisted.internet.abstract.FileDescriptor}
     424
     425        @param action: a string that is a method name of the fd instance.
     426                       This method is called in response to the event.
     427
     428        @return: None
     429        """
     430
     431    def removeEvent(event):
     432        """
     433        Remove an event.
     434
     435        @param event: a Win32 event object added using L{IReactorWin32Events.addEvent}
     436
     437        @return: None
     438        """
     439
     440
     441
    411442class IReactorUDP(Interface):
    412443    """
    413444    UDP socket methods.
  • twisted/internet/win32eventreactor.py

     
    1 # Copyright (c) 2001-2007 Twisted Matrix Laboratories.
     1# Copyright (c) 2001-2010 Twisted Matrix Laboratories.
    22# See LICENSE for details.
    33
    44
    55"""
    66A win32event based implementation of the Twisted main loop.
    77
    8 This requires win32all or ActivePython to be installed.
     8This requires pywin32 (formerly win32all) or ActivePython to be installed.
    99
     10To install the event loop (and you should do this before any connections,
     11listeners or connectors are added)::
     12
     13    from twisted.internet import win32eventreactor
     14    win32eventreactor.install()
     15
    1016Maintainer: Itamar Shtull-Trauring
    1117
    1218
     
    5864from twisted.internet import posixbase
    5965from twisted.python import log, threadable, failure
    6066from twisted.internet.interfaces import IReactorFDSet, IReactorProcess
     67from twisted.internet.interfaces import IReactorWin32Events
    6168
    6269from twisted.internet._dumbwin32proc import Process
    6370
     
    7683    @ivar _events: A dictionary mapping win32 event object to tuples of
    7784        L{FileDescriptor} instances and event masks.
    7885    """
    79     implements(IReactorFDSet, IReactorProcess)
     86    implements(IReactorFDSet, IReactorProcess, IReactorWin32Events)
    8087
    8188    dummyEvent = CreateEvent(None, 0, 0, None)
    8289
  • twisted/internet/test/test_win32eventreactor.py

     
     1# Copyright (c) 2010 Twisted Matrix Laboratories.
     2# See LICENSE for details.
     3
     4"""
     5Tests for L{twisted.internet.win32eventreactor} and supporting code.
     6"""
     7
     8from twisted.trial import unittest
     9from twisted.internet import reactor
     10from twisted.internet.interfaces import IReactorWin32Events
     11
     12from zope.interface.verify import verifyObject
     13
     14class win32eventreactorTestCase(unittest.TestCase):
     15    """IReactorWin32Events"""
     16
     17    def test_provides_interface(self):
     18        verifyObject(IReactorWin32Events, reactor)
     19
     20
     21
     22if reactor.__class__.__name__ != 'Win32Reactor':
     23    win32eventreactorTestCase.skip = 'This test only applies to win32eventreactor'
  • twisted/internet/_win32serialport.py

     
    2121from twisted.protocols import basic
    2222from twisted.internet import abstract
    2323from twisted.python import log
     24from twisted.internet.interfaces import IReactorWin32Events
    2425
    2526# sibling imports
    2627from serialport import BaseSerialPort
     
    3435    def __init__(self, protocol, deviceNameOrPortNumber, reactor,
    3536        baudrate = 9600, bytesize = EIGHTBITS, parity = PARITY_NONE,
    3637        stopbits = STOPBITS_ONE, xonxoff = 0, rtscts = 0):
     38
     39        if not IReactorWin32Events.providedBy(reactor):
     40            raise ValueError(
     41                "SerialPort on Windows requires a reactor that "
     42                "implements IReactorWin32Events, e.g. win32eventreactor.")
     43       
    3744        self._serial = serial.Serial(deviceNameOrPortNumber, baudrate=baudrate,
    3845                                     bytesize=bytesize, parity=parity,
    3946                                     stopbits=stopbits, timeout=None,
     
    5259        self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None)
    5360        self._overlappedWrite = win32file.OVERLAPPED()
    5461        self._overlappedWrite.hEvent = win32event.CreateEvent(None, 0, 0, None)
    55        
     62
    5663        self.reactor.addEvent(self._overlappedRead.hEvent, self, 'serialReadEvent')
    5764        self.reactor.addEvent(self._overlappedWrite.hEvent, self, 'serialWriteEvent')
    5865
  • twisted/internet/serialport.py

     
    44
    55"""
    66Serial Port Protocol
     7
     8pySerial is required for all platforms: http://pyserial.sourceforge.net/
     9
     10Windows requires the use of a reactor that supports
     11L{twisted.internet.interfaces.IReactorWin32Events}
     12e.g. L{twisted.internet.win32eventreactor}
     13
     14pywin32 (previously win32all) is also required for Windows:
     15http://sourceforge.net/projects/pywin32/
    716"""
    817
    918# http://twistedmatrix.com/trac/ticket/3725#comment:24