Ϫf zdZddlmZddlmZddlmZddlmZGddeZ Gdd eZ Gd d eZ y ) zA Whitebox tests for L{twisted.internet.abstract.FileDescriptor}. ) verifyClass)FileDescriptor) IPushProducer)SynchronousTestCasec,eZdZdZdZdZdZdZdZy) MemoryFilea- A L{FileDescriptor} customization which writes to a Python list in memory with certain limitations. @ivar _written: A C{list} of C{bytes} which have been accepted as written. @ivar _freeSpace: A C{int} giving the number of bytes which will be accepted by future writes. Tc^tj|tg|_d|_y)Nreactorr)r__init__object_written _freeSpaceselfs K/usr/lib/python3/dist-packages/twisted/internet/test/test_filedescriptor.pyr zMemoryFile.__init__s"fh7 cyNrs r startWritingzMemoryFile.startWriting" rcyrrrs r stopWritingzMemoryFile.stopWriting%rrct|jt|}|r3|xj|zc_|jj |d||S)z Copy at most C{self._freeSpace} bytes from C{data} into C{self._written}. @return: A C{int} indicating how many bytes were copied from C{data}. N)minrlenrappend)rdata acceptLengths r writeSomeDatazMemoryFile.writeSomeData(sH 4??CI6  OO| +O MM m|!4 5rN) __name__ __module__ __qualname____doc__ connectedr rrr!rrrrrs"I    rrc"eZdZdZdZdZdZy)FileDescriptorTestsz& Tests for L{FileDescriptor}. cntt}|jt|jdy)zF L{FileDescriptor.write} doesn't accept unicode data. r fooN)rr assertRaises TypeErrorwriterfileDescriptors r$test_writeWithUnicodeRaisesExceptionz8FileDescriptorTests.test_writeWithUnicodeRaisesException:s((9 )^%9%95Arcrtt}|jt|jgdy)zN L{FileDescriptor.writeSequence} doesn't accept unicode data. r )sfoobarsbazN)rr r+r, writeSequencer.s r,test_writeSequenceWithUnicodeRaisesExceptionz@FileDescriptorTests.test_writeSequenceWithUnicodeRaisesExceptionAs,(9  ~335L rcJ|jttty)zF L{FileDescriptor} should implement L{IPushProducer}. N) assertTruerrrrs r$test_implementInterfaceIPushProducerz8FileDescriptorTests.test_implementInterfaceIPushProducerJs  M>BCrN)r"r#r$r%r0r4r7rrrr(r(5sB Drr(ceZdZdZdZy)WriteDescriptorTestszN Tests for L{FileDescriptor}'s implementation of L{IWriteDescriptor}. cxt}|jd|j|jy)z When L{FileDescriptor.writeSomeData} returns C{0} to indicate no more data can be written immediately, L{FileDescriptor.doWrite} returns L{None}. s hello, worldN)rr- assertIsNonedoWrite)r descriptors rtest_kernelBufferFullz*WriteDescriptorTests.test_kernelBufferFullVs0  \ ) *,,./rN)r"r#r$r%r>rrrr9r9Qs 0rr9N) r%zope.interface.verifyrtwisted.internet.abstractrtwisted.internet.interfacesrtwisted.trial.unittestrrr(r9rrrrCsA .456""JD-D8 0. 0r