← Back
Editing: test_filedescriptor.cpython-38.pyc
U W[� � @ sx d Z ddlmZmZ ddlmZ ddlmZ ddlm Z ddl mZ G dd� de�ZG d d � d e�Z G dd� de�Zd S )zA Whitebox tests for L{twisted.internet.abstract.FileDescriptor}. � )�division�absolute_import)�verifyClass)�FileDescriptor)� IPushProducer)�SynchronousTestCasec @ s4 e Zd ZdZdZdd� 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. Tc C s t j| t� d� g | _d| _d S )N�Zreactorr )r �__init__�object�_written� _freeSpace��self� r �K/usr/lib/python3/dist-packages/twisted/internet/test/test_filedescriptor.pyr s zMemoryFile.__init__c C s d S �Nr r r r r �startWriting$ s zMemoryFile.startWritingc C s d S r r r r r r �stopWriting( s zMemoryFile.stopWritingc C s: t | jt|��}|r6| 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 �dataZacceptLengthr r r � writeSomeData, s zMemoryFile.writeSomeDataN) �__name__� __module__�__qualname__�__doc__Z connectedr r r r r r r r r s r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �FileDescriptorTestsz& Tests for L{FileDescriptor}. c C s t t� d�}| �t|jd� dS )zF L{FileDescriptor.write} doesn't accept unicode data. r ZfooN)r r �assertRaises� TypeError�write�r ZfileDescriptorr r r �$test_writeWithUnicodeRaisesException>