관리-도구
편집 파일: buf.cpython-311.pyc
� �܋f� � �2 � d Z ddlZdgZ G d� d� � ZdS )zCModule with a simple buffer implementation using the memory manager� N�SlidingWindowMapBufferc �z � e Zd ZdZdZddej dfd�Zd� Zd� Z d� Z d � Zd � Zd� Z ddej dfd�Zd � Zd� ZdS )r a A buffer like object which allows direct byte-wise object and slicing into memory of a mapped file. The mapping is controlled by the provided cursor. The buffer is relative, that is if you map an offset, index 0 will map to the first byte at the offset you used during initialization or begin_access **Note:** Although this type effectively hides the fact that there are mapped windows underneath, it can unfortunately not be used in any non-pure python method which needs a buffer or string)�_c�_sizeNr c �j � || _ |r'| � ||||� � st d� � �dS dS )ae Initalize the instance to operate on the given cursor. :param cursor: if not None, the associated cursor to the file you want to access If None, you have call begin_access before using the buffer and provide a cursor :param offset: absolute offset in bytes :param size: the total size of the mapping. Defaults to the maximum possible size From that point on, the __len__ of the buffer will be the given size or the file size. If the size is larger than the mappable area, you can only access the actually available area, although the length of the buffer is reported to be your given size. Hence it is in your own interest to provide a proper size ! :param flags: Additional flags to be passed to os.open :raise ValueError: if the buffer could not achieve a valid statezJFailed to allocate the buffer - probably the given offset is out of boundsN)r �begin_access� ValueError)�self�cursor�offset�size�flagss �Z/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/smmap/buf.py�__init__zSlidingWindowMapBuffer.__init__ sW � � ���� k�$�+�+�F�F�D�%�H�H� k��i�j�j�j� k� k� k� k� c �. � | � � � d S �N�� end_access�r s r �__del__zSlidingWindowMapBuffer.__del__( � � ��������r c � � | S r � r s r � __enter__z SlidingWindowMapBuffer.__enter__+ s � ��r c �. � | � � � d S r r )r �exc_type� exc_value� tracebacks r �__exit__zSlidingWindowMapBuffer.__exit__. r r c � � | j S r )r r s r �__len__zSlidingWindowMapBuffer.__len__1 s � ��z�r c � � t |t � � r)| � |j pd|j p| j � � S | j }|� � � sJ �|dk r | j |z }|� |� � s|� |d� � |� � � ||� � � z S )Nr � )� isinstance�slice�__getslice__�start�stopr r �is_valid�includes_ofs� use_region�buffer� ofs_begin)r �i�cs r �__getitem__z"SlidingWindowMapBuffer.__getitem__4 s� � ��a���� I��$�$�Q�W�\��1�6�3G�T�Z�H�H�H��G���z�z�|�|���|��q�5�5�� �Q��A��~�~�a� � � � �L�L��A�����x�x�z�z�!�a�k�k�m�m�+�,�,r c �4 � | j }|� � � sJ �|dk r | j |z }|t j k r| j }|dk r | j |z }|� � � |k rN||� � � k r6|� � � }|� � � ||z ||z � S ||z }|}t � � }|r�|� ||� � |� � � sJ �|� � � d |� }|t |� � z }|t |� � z }t |d� � r|� � � }|� |� � |��t � � � |� � S )Nr �tobytes)r r* r �sys�maxsizer. �ofs_endr- �listr, �len�hasattrr3 �append�bytes�join) r r/ �jr0 �b�l�ofs�md�ds r r'