HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_filedescriptor.cpython-310.pyc
o

�b�
�@shdZddlmZddlmZddlmZddlmZGdd�de�Z	Gdd	�d	e�Z
Gd
d�de�ZdS)
zA
Whitebox tests for L{twisted.internet.abstract.FileDescriptor}.
�)�verifyClass)�FileDescriptor)�
IPushProducer)�SynchronousTestCasec@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�
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.
    TcCs tj|t�d�g|_d|_dS)N��reactorr)r�__init__�object�_written�
_freeSpace��self�r�K/usr/lib/python3/dist-packages/twisted/internet/test/test_filedescriptor.pyr	s
zMemoryFile.__init__cC�dS�Nrr
rrr�startWriting"�zMemoryFile.startWritingcCrrrr
rrr�stopWriting%rzMemoryFile.stopWritingcCs:t|jt|��}|r|j|8_|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�acceptLengthrrr�
writeSomeData(s
zMemoryFile.writeSomeDataN)	�__name__�
__module__�__qualname__�__doc__�	connectedr	rrrrrrrrs
rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�FileDescriptorTestsz&
    Tests for L{FileDescriptor}.
    cCs tt�d�}|�t|jd�dS)zF
        L{FileDescriptor.write} doesn't accept unicode data.
        r�fooN)rr
�assertRaises�	TypeError�write�r�fileDescriptorrrr�$test_writeWithUnicodeRaisesException:sz8FileDescriptorTests.test_writeWithUnicodeRaisesExceptioncCs$tt�d�}|�t|jgd��dS)zN
        L{FileDescriptor.writeSequence} doesn't accept unicode data.
        r)sfoo�barsbazN)rr
r#r$�
writeSequencer&rrr�,test_writeSequenceWithUnicodeRaisesExceptionAs�z@FileDescriptorTests.test_writeSequenceWithUnicodeRaisesExceptioncCs|�ttt��dS)zF
        L{FileDescriptor} should implement L{IPushProducer}.
        N)�
assertTruerrrr
rrr�$test_implementInterfaceIPushProducerJsz8FileDescriptorTests.test_implementInterfaceIPushProducerN)rrrrr(r+r-rrrrr!5s
	r!c@seZdZdZdd�ZdS)�WriteDescriptorTestszN
    Tests for L{FileDescriptor}'s implementation of L{IWriteDescriptor}.
    cCs"t�}|�d�|�|���dS)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%�assertIsNone�doWrite)r�
descriptorrrr�test_kernelBufferFullVs
z*WriteDescriptorTests.test_kernelBufferFullN)rrrrr2rrrrr.Qsr.N)r�zope.interface.verifyr�twisted.internet.abstractr�twisted.internet.interfacesr�twisted.trial.unittestrrr!r.rrrr�<module>s%