Ticket #3802: twisted-3802.patch

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

See comments below

  • twisted/internet/interfaces.py

     
    387387        @return: An object which provides L{IListeningPort}.
    388388        """
    389389
     390class IReactorWin32Events(Interface):
     391    """
     392    Win32 Event API methods
     393    """
     394   
     395    def addEvent(event, fd, action):
     396        """
     397        Add a new win32 event to the event loop.
     398       
     399        @param event: a Win32 event object created using win32event.CreateEvent()
     400       
     401        @param fd: an instance of L{twisted.internet.abstract.FileDescriptor}
     402       
     403        @param action: a callable, called in response to the registered event
     404       
     405        @return: None
     406        """
    390407
     408    def removeEvent(event):
     409        """
     410        Remove an event.
     411       
     412        @param event: a Win32 event object added using L{IReactorWin32Events.addEvent}
     413       
     414        @return: None
     415        """
     416
     417
     418
    391419class IReactorUDP(Interface):
    392420    """
    393421    UDP socket methods.
  • twisted/internet/win32eventreactor.py

     
    5757# Twisted imports
    5858from twisted.internet import posixbase
    5959from twisted.python import log, threadable, failure
    60 from twisted.internet.interfaces import IReactorFDSet, IReactorProcess
     60from twisted.internet.interfaces import IReactorFDSet, IReactorProcess, IReactorWin32Events
    6161
    6262from twisted.internet._dumbwin32proc import Process
    6363
     
    7676    @ivar _events: A dictionary mapping win32 event object to tuples of
    7777        L{FileDescriptor} instances and event masks.
    7878    """
    79     implements(IReactorFDSet, IReactorProcess)
     79    implements(IReactorFDSet, IReactorProcess, IReactorWin32Events)
    8080
    8181    dummyEvent = CreateEvent(None, 0, 0, None)
    8282
  • 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        assert IReactorWin32Events.providedBy(reactor), "win32eventreactor needs to be installed for use with SerialPort on Win32. e.g.\nfrom twisted.internet import win32eventreactor\nwin32eventreactor.install()"
     40       
    3741        self._serial = serial.Serial(deviceNameOrPortNumber, baudrate=baudrate,
    3842                                     bytesize=bytesize, parity=parity,
    3943                                     stopbits=stopbits, timeout=None,
     
    5256        self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None)
    5357        self._overlappedWrite = win32file.OVERLAPPED()
    5458        self._overlappedWrite.hEvent = win32event.CreateEvent(None, 0, 0, None)
    55        
     59
    5660        self.reactor.addEvent(self._overlappedRead.hEvent, self, 'serialReadEvent')
    5761        self.reactor.addEvent(self._overlappedWrite.hEvent, self, 'serialWriteEvent')
    5862