\goC 2 d Z ddlZdgZ G d d ZdS )zCModule with a simple buffer implementation using the memory manager NSlidingWindowMapBufferc z e Zd ZdZdZddej dfdZd Zd Z d Z
d Zd
Zd Z
ddej dfdZd
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)selfcursoroffsetsizeflagss [/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/smmap/buf.py__init__zSlidingWindowMapBuffer.__init__ sW k$++FFD%HH kijjj k k k k c . | d S N
end_accessr
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
zr c t |t r)| |j pd|j p| j S | j }| sJ |dk r
| j |z }| | s| |d |
|| z
S )Nr )
isinstanceslice__getslice__startstopr r is_validincludes_ofs
use_regionbuffer ofs_begin)r
ics r __getitem__z"SlidingWindowMapBuffer.__getitem__4 s a I$$QW\163GTZHHHGzz|||q55
QA~~a
LLAxxzz!akkmm+,,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 sysmaxsizer. ofs_endr- listr, lenhasattrr3 appendbytesjoin) r
r/ jr0 blofsmdds r r' z#SlidingWindowMapBuffer.__getslice__@ sv G zz|||q55
QA
Aq55
QA
KKMMQQ__
A88::a!eAEk**AAC B
S!$$$zz||##|HHJJrrNs1vv
SVV 1i(( $ A !
77<<###r c < |r|| _ | j | j rr| j ||| }|r@|| j k r| j |z
}|| _ |S dS )aU Call this before the first use of this instance. The method was already
called by the constructor in case sufficient information was provided.
For more information no the parameters, see the __init__ method
:param path: if cursor is None the existing one will be used.
:return: True if the buffer can be usedNF)r
is_associatedr, r* file_sizer )r
r r r
r ress r r z#SlidingWindowMapBuffer.begin_accessd s DG 747#8#8#:#:'$$VT599BBDDC
"
$'++----7,,..7D!
Jur c X d| _ | j | j dS dS )a Call this method once you are done using the instance. It is automatically
called on destruction, and should be called just in time to allow system
resources to be freed.
Once you called end_access, you must call begin access before reusing this instance!r N)r r unuse_regionr s r r z!SlidingWindowMapBuffer.end_access s5
7G """"" r c | j S )zC:return: the currently set cursor which provides access to the data)r r s r r zSlidingWindowMapBuffer.cursor s wr )__name__
__module____qualname____doc__ __slots__r4 r5 r r r r r" r1 r' r r r r r r r r s I
#13;a k k k k"
-
-
- $ $ $H #'qs{! 8# # # r )rM r4 __all__r r r r