HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/smmap/__pycache__/util.cpython-310.pyc
o

;j4�@sxdZddlZddlZddlmZmZddlmZgd�Zdd�Zdd	�ZGd
d�d�Z	Gdd
�d
�Z
Gdd�de�ZdS)zlModule containing a memory memory manager which provides a sliding window on a number of memory mapped files�N)�mmap�ACCESS_READ��ALLOCATIONGRANULARITY)�
align_to_mmap�	is_64_bit�	MapWindow�	MapRegion�
MapRegionListrcCs$|tt}|r||kr|t7}|S)a=
    Align the given integer number to the closest page offset, which usually is 4096 bytes.

    :param round_up: if True, the next higher multiple of page size is used, otherwise
        the lower page_size will be used (i.e. if True, 1 becomes 4096, otherwise it becomes 0)
    :return: num rounded to closest pager)�numZround_up�res�r
�>/opt/saltstack/salt/lib/python3.10/site-packages/smmap/util.pyrsrcCs
tjdkS)zO:return: True if the system is 64 bit. Otherwise it can be assumed to be 32 bitl��)�sys�maxsizer
r
r
rrs
rc@sPeZdZdZdZdd�Zdd�Zedd��Zd	d
�Z	dd�Z
d
d�Zdd�ZdS)rzWUtility type which is used to snap windows towards each other, and to adjust their size��ofs�sizecCs||_||_dS�Nr)�self�offsetrr
r
r�__init__-�
zMapWindow.__init__cCsd|j|jfS)NzMapWindow(%i, %i)r�rr
r
r�__repr__1szMapWindow.__repr__cCs||j|���S)z!:return: new window from a region��_br)�clsZregionr
r
r�from_region4szMapWindow.from_regioncC�|j|jSrrrr
r
r�ofs_end9�zMapWindow.ofs_endcCs8t|jd�}|j|j|7_||_t|jd�|_dS)z<Assures the previous window area is contained in the new oner�N)rrr)rZnofsr
r
r�align<szMapWindow.aligncCsJ|j|��}||j}||t||�8}|j|8_|j|7_dS)z�Adjust the offset to start where the given window on our left ends if possible,
        but don't make yourself larger than max_size.
        The resize will assure that the new window still contains the old window areaN)rr r�min)r�window�max_sizeZrofsZnsizer
r
r�extend_left_toCs

zMapWindow.extend_left_tocCs t|j|j|��|�|_dS)zpAdjust the size to make our window end where the right window begins, but don't
        get larger than max_sizeN)r$rrr )rr%r&r
r
r�extend_right_toMs zMapWindow.extend_right_toN)
�__name__�
__module__�__qualname__�__doc__�	__slots__rr�classmethodrr r#r'r(r
r
r
rr%s

rc@steZdZdZgd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
ddd�Zdd�ZdS)r	z{Defines a mapped region of memory, aligned to pagesizes

    **Note:** deallocates used region automatically on destruction)r�_mf�_uc�_size�__weakref__rc
	Cs�||_d|_d|_t|t�r|}nt�|tjttdd�B|B�}z1t	t
|d�}|}|}tt�|�j
||�}	t||	fi|��|_t|j�|_Wt|t�rQt�|�nt|t�r]t�|�ww|��dS)a�Initialize a region, allocate the memory map
        :param path_or_fd: path to the file to map, or the opened file descriptor
        :param ofs: **aligned** offset into the file to be mapped
        :param size: if size is larger then the file on disk, the whole file will be
            allocated the the size automatically adjusted
        :param flags: additional flags to be given when opening the file.
        :raise Exception: if no memory can be allocatedr�O_BINARY)�accessrN)rr1r0�
isinstance�int�os�open�O_RDONLY�getattr�dictrr$�fstat�st_sizerr/�len�str�close�increment_client_count)
r�
path_or_fdrr�flags�fd�kwargsZcorrected_sizeZsizeofsZactual_sizer
r
rrcs(


�
��zMapRegion.__init__cCsd|j|��fS)NzMapRegion<%i, %i>rrr
r
rr�szMapRegion.__repr__cC�|jS)z':return: a buffer containing the memory�r/rr
r
r�buffer��zMapRegion.buffercCrF)z+:return: a memory map containing the memoryrGrr
r
r�map�rIz
MapRegion.mapcCrF)z>:return: absolute byte offset to the first byte of the mapping)rrr
r
r�	ofs_begin�rIzMapRegion.ofs_begincCrF)z1:return: total size of the mapped region in bytes)r1rr
r
rr�rIzMapRegion.sizecCr)zE:return: Absolute offset to one byte beyond the mapping into the file�rr1rr
r
rr �szMapRegion.ofs_endcCs"|j|ko|j|jkSS)zB:return: True if the given offset can be read in our mapped regionrL�rrr
r
r�includes_ofs�s"zMapRegion.includes_ofscCrF)z6:return: number of clients currently using this region)r0rr
r
r�client_count�rIzMapRegion.client_countr"cCsB|j|7_|jdksJd|j��|��dkr|��dSdS)z�Adjust the usage count by the given positive or negative offset.
        If usage count equals 0, we will auto-release our resources
        :return: True if we released resources, False otherwise. In the latter case, we can still be used���z<Increments must match decrements, usage counter negative: %irTF)r0rO�releaserMr
r
rrA�sz MapRegion.increment_client_countcCs|j��dS)zbRelease all resources this instance might hold. Must only be called if there usage_count() is zeroN)r/r@rr
r
rrQ�szMapRegion.releaseN)r)r")r)r*r+r,r-rrrHrJrKrr rNrOrArQr
r
r
rr	Ss
'
r	cs<eZdZdZdZ�fdd�Zdd�Zdd�Zd	d
�Z�Z	S)r
zFList of MapRegion instances associating a path with a list of regions.��_path_or_fd�
_file_sizecst��|�Sr)�super�__new__)r�path��	__class__r
rrV�r!zMapRegionList.__new__cCs||_d|_dSrrR)rrBr
r
rr�rzMapRegionList.__init__cCrF)z3:return: path or file descriptor we are attached to)rSrr
r
rrB�rIzMapRegionList.path_or_fdcCsB|jdurt|jt�rt�|j�j|_|jSt�|j�j|_|jS)z :return: size of file we managerN)rTr5rSr?r7�statr=r<rr
r
r�	file_size�s
�zMapRegionList.file_size)
r)r*r+r,r-rVrrBr[�
__classcell__r
r
rXrr
�sr
)
r,r7rrrr�__all__rrrr	�listr
r
r
r
r�<module>s	.m