U e5dD@sddgZddlmZddlZddlZddlZddlZddlZejdkrTddl Z dZ n ddl Z dZ ej ej BZdZe rzd Znd Zd d ZGd ddZdZGdddZdS) SharedMemory ShareableList)partialNntFTz/psm_Zwnsm_cCs"tttd}tt|}|S)N)_SHM_SAFE_NAME_LENGTHlen_SHM_NAME_PREFIXsecretsZ token_hex)nbytesnamer5/usr/lib64/python3.8/multiprocessing/shared_memory.py_make_filename&src@seZdZdZdZdZdZejZ dZ e r*dndZ dddZ d d Zd d Zd dZeddZeddZeddZddZddZdS)rNiTFrc Csl|dkstd|r0ttjB|_|dkr0td|dkrL|jtj@sLtdtrH|dkrt}ztj ||j|j d|_ Wnt k rYqZYnX||_ qqZn.|jrd|n|}tj ||j|j d|_ ||_ z<|r|rt|j |t|j }|j}t|j ||_Wn tk r*|YnXddlm}||j d n|r|dkr^tn|}ttjtjtj|d ?d @|d @|}zXt}|tjkr|dk rt t j!t"t j!|tjnWqNtjd ||d |_W5t|X||_ qVqNnX||_ t#tj$d|}zt%|tj$ddd} W5t|Xt&| }tjd ||d |_||_'t(|j|_)dS)Nrz!'size' must be a positive integerz4'size' must be a positive number different from zeroz&'name' can only be None if create=True)mode/)register shared_memory lr)ZtagnameF)* ValueError_O_CREXosO_RDWR_flagsO_EXCL _USE_POSIXr _posixshmemZshm_open_mode_fdFileExistsError_name_prepend_leading_slash ftruncatefstatst_sizemmap_mmapOSErrorunlinkresource_trackerr_winapiZCreateFileMappingZINVALID_HANDLE_VALUEZNULLZPAGE_READWRITEZ CloseHandleZ GetLastErrorZERROR_ALREADY_EXISTSerrnoZEEXISTstrerrorZOpenFileMappingZ FILE_MAP_READZ MapViewOfFileZVirtualQuerySize_size memoryview_buf) selfr createsizeZstatsrZ temp_nameZh_mapZlast_error_codeZp_bufrrr__init__Is             zSharedMemory.__init__cCs&z |Wntk r YnXdSN)closer*r3rrr__del__s zSharedMemory.__del__cCs|j|jd|jffS)NF) __class__r r5r9rrr __reduce__s zSharedMemory.__reduce__cCs|jjd|jd|jdS)N(z, size=))r;__name__r r5r9rrr__repr__szSharedMemory.__repr__cCs|jSr7)r2r9rrrbufszSharedMemory.bufcCs.|j}tr*|jr*|jdr*|jdd}|S)Nrr)r#rr$ startswith)r3Z reported_namerrrr s   zSharedMemory.namecCs|jSr7)r0r9rrrr5szSharedMemory.sizecCsX|jdk r|jd|_|jdk r4|jd|_trT|jdkrTt|jd|_dS)Nrr)r2releaser)r8rr!rr9rrrr8s     zSharedMemory.closecCs2tr.|jr.ddlm}t|j||jddS)Nr) unregisterr)rr#r,rDrZ shm_unlink)r3rDrrrr+s   zSharedMemory.unlink)NFr)r? __module__ __qualname__r#r!r)r2rrrr rr$r6r:r<r@propertyrAr r5r8r+rrrrr0s&  l     utf8c @s eZdZedededededdjdiZ dZ dd d d d d d d d Z e ddZ d5ddddZddZddZddZddZddZddZdd Zd!d"Zed#d$Zed%d&Zed'd(Zed)d*Zed+d,Zed-d.Zed/d0Zd1d2Zd3d4Z dS)6rqdzxxxxxxx?z%dsNzxxxxxx?xcCs|Sr7rvaluerrr zShareableList.cCs|dtSN)rstripdecode _encodingrLrrrrN rOcCs |dSrP)rRrLrrrrN rOcCsdSr7r)Z_valuerrrrN rO)rrrcCs:t|ttdjfsdSt|tr$dSt|tr2dSdSdS)NrrrrU) isinstancestrbytesr;rLrrr_extract_recreation_codes  z&ShareableList._extract_recreation_coder csr|dk rvfdd|D}t|_tfdd|D_fdd|D}tdjd|jj }nd}|dk r|dkrt |_ nt |d |d _ |dk rNt tj djj jd jfjtj d|j jjffd d|Dtj jj jjffd d|Dtj j j jjf|n t_tjj jd_dS)NcsPg|]H}t|ttfs$jt|n&jt|jt|jdfqS)r)rVrWrX_types_mappingtype _alignmentr .0itemr9rr s   z*ShareableList.__init__..c3s0|](}|ddkrjnt|ddVqdS)rsN)r]int)r_fmtr9rr *sz)ShareableList.__init__..csg|]}|qSr)rYr^r9rrra.srIrKT)r4r5rc3s&|]}t|tr|n|VqdSr7)rVrWencoder_v_encrrreMsc3s|]}|VqdSr7)rgrhrjrrreSs)r _list_lentuple_allocated_bytesstructZcalcsize_format_size_metainfojoin_format_packing_metainfo_format_back_transform_codesrshmrT pack_intorA_offset_data_start_offset_packing_formats_offset_back_transform_codes unpack_from)r3Zsequencer Z_formatsZ_recreation_codesZrequested_sizer)rkr3rr6sz        zShareableList.__init__cCsj|dkr |n||j}||jks*|jdkr2tdtd|jj|j|dd}|d}|t }|S)Nr Requested position out of range.8srKrQ) rl IndexErrorroryrtrArwrRrSrT)r3positionrird fmt_as_strrrr_get_packing_formatds   z!ShareableList._get_packing_formatcCs\|dkr |n||j}||jks*|jdkr2tdtd|jj|j|d}|j|}|S)Nrrzb)rlr|roryrtrArx_back_transforms_mapping)r3r}transform_codeZtransform_functionrrr_get_back_transformts z!ShareableList._get_back_transformcCs~|dkr |n||j}||jks*|jdkr2tdtd|jj|j|d|t| |}td|jj|j ||dS)Nrrzr{rKr) rlr|rorurtrArwrgrTrYrx)r3r}r~rMrrrr!_set_packing_format_and_transforms   z/ShareableList._set_packing_format_and_transformcCsjz6|jt|jd|}t|||jj|\}Wntk rRtdYnX| |}||}|S)Nzindex out of range) rvsumrnroryrrtrAr|r)r3r}offsetriZback_transformrrr __getitem__s  zShareableList.__getitem__cCsz&|jt|jd|}||}Wntk rBtdYnXt|ttfsf|jt |}|}nZt|trz| t n|}t ||j|krt d|ddkr|}n|jt|j|f}||||t||jj||dS)Nzassignment index out of rangez(bytes/str item exceeds available storagerrb)rvrrnrr|rVrWrXr[r\rgrTr rrrorurtrA)r3r}rMrZcurrent_formatZ new_formatZ encoded_valuerrr __setitem__s6  zShareableList.__setitem__cCst|j|jjddfS)NrZr)rr;rtr r9rrrr<szShareableList.__reduce__cCstd|jjddS)NrIr)roryrtrAr9rrr__len__szShareableList.__len__cCs"|jjdt|d|jjdS)Nr=z, name=r>)r;r?listrtr r9rrrr@szShareableList.__repr__csdfddtjDS)Nrfc3s|]}|VqdSr7)r)r_ir9rrresz'ShareableList.format..)rqrangerlr9rr9rformatszShareableList.formatcCs |jdS)NrIrlr9rrrrpsz#ShareableList._format_size_metainfocCs d|jS)Nr{rr9rrrrrsz&ShareableList._format_packing_metainfocCs d|jS)Nrrr9rrrrssz*ShareableList._format_back_transform_codescCs|jddS)NrrKrr9rrrrvsz ShareableList._offset_data_startcCs|jt|jSr7)rvrrnr9rrrrwsz%ShareableList._offset_packing_formatscCs|j|jdS)NrK)rwrlr9rrrrxsz*ShareableList._offset_back_transform_codescstfdd|DS)Nc3s|]}|kVqdSr7r)r_entryrLrrresz&ShareableList.count..)r)r3rMrrLrcountszShareableList.countcCs4t|D]\}}||kr|Sqt|ddS)Nz not in this container) enumerater)r3rMr}rrrrindexs zShareableList.index)N)!r?rErFrcfloatboolrWrXr;r[r]r staticmethodrYr6rrrrrr<rr@rGrrprrrsrvrwrxrrrrrrrs\  F       )__all__ functoolsrr(rr.ror r r-rrO_CREATrrrr rrrTrrrrrs*    E