
    Vh
                     z    d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d de      Z	 G d d	e      Z
 G d
 de      Zy)zA
Whitebox tests for L{twisted.internet.abstract.FileDescriptor}.
    )verifyClass)FileDescriptor)IPushProducer)SynchronousTestCasec                   ,    e Zd ZdZdZd Zd Zd Zd Zy)
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                 ^    t        j                  | t                      g | _        d| _        y )Nreactorr   )r   __init__object_written
_freeSpaceselfs    Y/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_filedescriptor.pyr   zMemoryFile.__init__   s"    fh7    c                      y N r   s    r   startWritingzMemoryFile.startWriting"       r   c                      y r   r   r   s    r   stopWritingzMemoryFile.stopWriting%   r   r   c                     t        | j                  t        |            }|r3| xj                  |z  c_        | j                  j	                  |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)minr   lenr   append)r   dataacceptLengths      r   writeSomeDatazMemoryFile.writeSomeData(   sH     4??CI6OO|+OMM  m|!45r   N)	__name__
__module____qualname____doc__	connectedr   r   r   r!   r   r   r   r   r      s"     I

r   r   c                   "    e Zd ZdZd Zd Zd Zy)FileDescriptorTestsz&
    Tests for L{FileDescriptor}.
    c                 n    t        t                     }| j                  t        |j                  d       y)zF
        L{FileDescriptor.write} doesn't accept unicode data.
        r
   fooN)r   r   assertRaises	TypeErrorwriter   fileDescriptors     r   $test_writeWithUnicodeRaisesExceptionz8FileDescriptorTests.test_writeWithUnicodeRaisesException:   s(     (9)^%9%95Ar   c                 r    t        t                     }| j                  t        |j                  g d       y)zN
        L{FileDescriptor.writeSequence} doesn't accept unicode data.
        r
   )s   foobars   bazN)r   r   r+   r,   writeSequencer.   s     r   ,test_writeSequenceWithUnicodeRaisesExceptionz@FileDescriptorTests.test_writeSequenceWithUnicodeRaisesExceptionA   s,     (9~335L	
r   c                 J    | j                  t        t        t                     y)zF
        L{FileDescriptor} should implement L{IPushProducer}.
        N)
assertTruer   r   r   r   s    r   $test_implementInterfaceIPushProducerz8FileDescriptorTests.test_implementInterfaceIPushProducerJ   s     	M>BCr   N)r"   r#   r$   r%   r0   r4   r7   r   r   r   r(   r(   5   s    B
Dr   r(   c                       e Zd ZdZd Zy)WriteDescriptorTestszN
    Tests for L{FileDescriptor}'s implementation of L{IWriteDescriptor}.
    c                 x    t               }|j                  d       | j                  |j                                y)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)r   r-   assertIsNonedoWrite)r   
descriptors     r   test_kernelBufferFullz*WriteDescriptorTests.test_kernelBufferFullV   s0      \
)*,,./r   N)r"   r#   r$   r%   r>   r   r   r   r9   r9   Q   s    0r   r9   N)r%   zope.interface.verifyr   twisted.internet.abstractr   twisted.internet.interfacesr   twisted.trial.unittestr   r   r(   r9   r   r   r   <module>rC      sA   
 . 4 5 6" "JD- D80. 0r   