
    Yf
                         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dS )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dS )
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                 f    t          j        | t                                 g | _        d| _        d S )Nreactorr   )r   __init__object_written
_freeSpaceselfs    [/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_filedescriptor.pyr   zMemoryFile.__init__   s.    fhh7777    c                     d S N r   s    r   startWritingzMemoryFile.startWriting"       r   c                     d S r   r   r   s    r   stopWritingzMemoryFile.stopWriting%   r   r   c                     t          | j        t          |                    }|r2| xj        |z  c_        | 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(   sX     4?CII66 	6OO|+OOM  m|m!4555r   N)	__name__
__module____qualname____doc__	connectedr   r   r   r!   r   r   r   r   r      sa          I  
    
 
 
 
 
r   r   c                   $    e Zd ZdZd Zd Zd ZdS )FileDescriptorTestsz&
    Tests for L{FileDescriptor}.
    c                     t          t                                }|                     t          |j        d           dS )zF
        L{FileDescriptor.write} doesn't accept unicode data.
        r
   fooN)r   r   assertRaises	TypeErrorwriter   fileDescriptors     r   $test_writeWithUnicodeRaisesExceptionz8FileDescriptorTests.test_writeWithUnicodeRaisesException:   s9     (999)^%95AAAAAr   c                     t          t                                }|                     t          |j        g d           dS )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   sK     (999~35L5L5L	
 	
 	
 	
 	
r   c                 `    |                      t          t          t                               dS )zF
        L{FileDescriptor} should implement L{IPushProducer}.
        N)
assertTruer   r   r   r   s    r   $test_implementInterfaceIPushProducerz8FileDescriptorTests.test_implementInterfaceIPushProducerJ   s&     	M>BBCCCCCr   N)r"   r#   r$   r%   r0   r4   r7   r   r   r   r(   r(   5   sS         B B B
 
 
D D D D Dr   r(   c                       e Zd ZdZd ZdS )WriteDescriptorTestszN
    Tests for L{FileDescriptor}'s implementation of L{IWriteDescriptor}.
    c                     t                      }|                    d           |                     |                                           dS )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   sG      \\
)))*,,../////r   N)r"   r#   r$   r%   r>   r   r   r   r9   r9   Q   s-         0 0 0 0 0r   r9   N)r%   zope.interface.verifyr   twisted.internet.abstractr   twisted.internet.interfacesr   twisted.trial.unittestr   r   r(   r9   r   r   r   <module>rC      s    
 . - - - - - 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6" " " " " " " "JD D D D D- D D D80 0 0 0 0. 0 0 0 0 0r   