Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
smb.cpython-313.pyc184 linesDownload Raw Back to __pycache__
1�

2�j�;���SrSSKrSSKrSSKrSSKJrJr SSKrSSKr	SSK3Jr SSKJ
r
 "SS\5rS	rS4rSr"SS
5rg)z�5This module contains SMBFileSystem class responsible for handling access to6Windows Samba network shares by using package smbprotocol7�N)�S_ISDIR�S_ISLNK�)�AbstractFileSystem��infer_storage_optionsc��^�\rSrSrSrSrSU4Sjjr\S5rSr	\8S5r\S5r
SS	jrSS9jrSrSrS
rSrSSjrSSjrSrSrSSjrSrU=r$)�
SMBFileSystem�a�Allow reading and writing to Windows and Samba network shares.10 11When using `fsspec.open()` for getting a file-like object the URI12should be specified as this format:13``smb://workgroup;user:password@server:port/share/folder/file.csv``.14 15Example::16 17    >>> import fsspec18    >>> with fsspec.open(19    ...     'smb://myuser:mypassword@myserver.com/' 'share/folder/file.csv'20    ... ) as smbfile:21    ...     df = pd.read_csv(smbfile, sep='|', header=None)22 23Note that you need to pass in a valid hostname or IP address for the host24component of the URL. Do not use the Windows/NetBIOS machine name for the25host component.26 27The first component of the path in the URL points to the name of the shared28folder. Subsequent path components will point to the directory/folder/file.29 30The URL components ``workgroup`` , ``user``, ``password`` and ``port`` may be31optional.32 33.. note::34 35    For working this source require `smbprotocol`_ to be installed, e.g.::36 37        $ pip install smbprotocol38        # or39        # pip install smbprotocol[kerberos]40 41.. _smbprotocol: https://github.com/jborean93/smbprotocol#requirements42 43Note: if using this with the ``open`` or ``open_files``, with full URLs,44there is no way to tell if a path is relative, so all paths are assumed45to be absolute.46�smbc�<>�[T
U]"S0UD6 XlX lX0lX@lXPlX`lURSS5Ul	Xpl47X�lU	S:a[S5eX�l
U48S:a[S5eX�lX�lUR!5 g)	a�49You can use _get_kwargs_from_urls to get some kwargs from50a reasonable SMB url.51 52Authentication will be anonymous or integrated if username/password are not53given.54 55Parameters56----------57host: str58    The remote server name/ip to connect to59port: int or None60    Port to connect with. Usually 445, sometimes 139.61username: str or None62    Username to connect with. Required if Kerberos auth is not being used.63password: str or None64    User's password on the server, if using username65timeout: int66    Connection timeout in seconds67encrypt: bool68    Whether to force encryption or not, once this has been set to True69    the session cannot be changed back to False.70share_access: str or None71    Specifies the default access applied to file open operations72    performed with this file system object.73    This affects whether other processes can concurrently open a handle74    to the same file.75 76    - None (the default): exclusively locks the file until closed.77    - 'r': Allow other handles to be opened with read access.78    - 'w': Allow other handles to be opened with write access.79    - 'd': Allow other handles to be opened with delete access.80register_session_retries: int81    Number of retries to register a session with the server. Retries are not performed82    for authentication errors, as they are considered as invalid credentials and not network83    issues. If set to negative value, no register attempts will be performed.84register_session_retry_wait: int85    Time in seconds to wait between each retry. Number must be non-negative.86register_session_retry_factor: int87    Base factor for the wait time between each retry. The wait time88    is calculated using exponential function. For factor=1 all wait times89    will be equal to `register_session_retry_wait`. For any number of retries,90    the last wait time will be equal to `register_session_retry_wait` and for retries>191    the first wait time will be equal to `register_session_retry_wait / factor`.92    Number must be equal to or greater than 1. Optimal factor is 10.93auto_mkdir: bool94    Whether, when opening a file, the directory containing it should95    be created (if it doesn't already exist). This is assumed by pyarrow96    and zarr-python code.97�temppath�rz:register_session_retry_wait must be a non-negative integer�zSregister_session_retry_factor must be a positive integer equal to or greater than 1N�)�super�__init__�host�port�username�password�timeout�encrypt�popr�share_access�register_session_retries�98ValueError�register_session_retry_wait�register_session_retry_factor�99auto_mkdir�_connect)�selfrrrrrrrrrrr �kwargs�	__class__s             ��`D:\code\apps\devtools\python\user_packages\Python313\site-packages\fsspec/implementations/smb.pyr�SMBFileSystem.__init__?s����B	���"�6�"��	��	� �
� �
������100�101�:�r�2��
�(��(@�%�&��*��L��
�,G�(�(�1�,��5��
�.K�*�$���
�
��c�8�URcS$UR$)N��r�r"s r%�_port�SMBFileSystem._port�s���i�i�'�s�6�T�Y�Y�6r'c102�p^^^�SSKnURS::ag/nURmURS-103mURm[	UUU4Sj[STS-555n[URS-5HYn[R"URURURURURURS9  g USe![RR [RR"4a e[$aAn[&R("S[+U55(aUR-U5 SnAO,eSnAf[.anUR-U5 SnAOSnAff=fX@R:dGMUR1[3U55 GM:)Nr�����rc3�@># �UHnTUT-S-104-T-v� M g7f)rNr)�.0�n�factor�n_waits�	wait_times  ���r%�	<genexpr>�)SMBFileSystem._connect.<locals>.<genexpr>�s'����105�=R��F�q�7�{�Q��'�)�3�=R�s�)rrrr�connection_timeoutz
\[Errno -\d+])�timerrr�iter�range�	smbclient�register_sessionrrrr,rr�smbprotocol�106exceptions�SMBAuthenticationError�LogonFailurer�re�findall�str�append�	Exception�sleep�next)	r"r9�retried_errors�107wait_times�attempt�excr3r4r5s	      @@@r%r!�SMBFileSystem._connect�s������(�(�B�.�����4�4�	��)�)�A�-�	��3�3���108�=B�1�g�PQ�k�=R�109�110�111��T�:�:�Q�>�?�G�
+��*�*��I�I�!�]�]�!�]�]���� �L�L�'+�|�|�
��@�L�R� � ��5�&�&�=�=��&�&�3�3��
���	
��:�:�.��C��9�9�#�)�)�#�.�.����
+��%�%�c�*�*��
+��112�6�6�6��113�114�4�115�+�,s,�AC � AF�"6E�E�
F�+F�Fc��[U5S$)N�pathr)�clsrOs  r%�_strip_protocol�SMBFileSystem._strip_protocol�s��$�T�*�6�2�2r'c�d�[U5nURSS5 URSS5 U$)NrO�protocol)rr)rO�outs  r%�_get_kwargs_from_urls�#SMBFileSystem._get_kwargs_from_urls�s/��$�D�)�����������116�D�!��117r'c���[URU5nU(a%[R"U4SURS.UD6 g[R118"U4SUR0UD6 g)NF��exist_okrr)�_as_unc_pathrr<�makedirsr,�mkdir)r"rO�create_parentsr#�wpaths     r%r]�SMBFileSystem.mkdir�sM���T�Y�Y��-������u�P�u�4�:�:�P��P��O�O�E�=��119�120�=�f�=r'c��[U5(a6[URU5n[R"X2UR121S9 gg)NrY)�_share_has_pathr[rr<r\r,)r"rOrZr_s    r%r\�SMBFileSystem.makedirs�s6���4� � � ����D�1�E����u�d�j�j�I�!r'c��[U5(a5[URU5n[R"X R122S9 gg�Nr*)rbr[rr<�rmdirr,)r"rOr_s   r%rf�SMBFileSystem.rmdir�s2���4� � � ����D�1�E��O�O�E�123�124�3�!r'c�~�[URU5n[R"U4SUR0UD6n[UR5(aSnO[UR5(aSnOSnUS:XaUS-OUURUURURURURS.nU$)Nr�	directory�link�file�/)�name�size�type�uid�gidr9�mtime)
r[rr<�statr,r�st_moder�st_size�st_uid�st_gid�st_atime�st_mtime)r"rOr#r_�stats�stype�ress       r%�info�SMBFileSystem.info�s����T�Y�Y��-�����u�@�4�:�:�@��@���5�=�=�!�!��E�
�U�]�]�
#�
#��E��E�"'�;�"6�D�3�J�D��M�M���<�<��<�<��N�N��^�^�125���126r'c���[URU5n[R"X RS9n[127R128R
UR[129RRS9$)z=Return the created timestamp of a file as a datetime.datetimer*��tz)130r[rr<rsr,�datetime�
fromtimestamp�st_ctime�timezone�utc�r"rOr_rzs    r%�created�SMBFileSystem.created�P���T�Y�Y��-�����u�:�:�6��� � �.�.�u�~�~�(�BS�BS�BW�BW�.�X�Xr'c���[URU5n[R"X RS9n[131R132R
UR[133RRS9$)z>Return the modified timestamp of a file as a datetime.datetimer*r�)134r[rr<rsr,r�r�ryr�r�r�s    r%�modified�SMBFileSystem.modifiedr�r'c�>�[URU5n[R"U4SUR0UD6nUVs/sH%nSRUR
S5U/5PM' nnU(a UVs/sHo�RU5PM nnU$s snfs snf)Nrrl)r[rr<�listdirr,�join�rstripr})	r"rO�detailr#�unc�listed�p�dirs�ds	         r%�ls�SMBFileSystem.lss����4�9�9�d�+���"�"�3�B�T�Z�Z�B�6�B��9?�@��A����$�+�+�c�*�A�.�/���@��*.�/�$�Q�I�I�a�L�$�D�/����A��/s�,B�7Bc���UR(a%SU;aURURU5SS9 UbUS:�aUOSn[URU5nURSUR5n	SU;a?USLa:[URXR5n135[X�U4URUS.UD6$[R"UU4UU	URS	.UD6$)136z�137block_size: int or None138    If 0, no buffering, 1, line buffering, >1, buffer that many bytes139 140Notes141-----142By specifying 'share_access' in 'kwargs' it is possible to override the143default shared access setting applied in the constructor of this object.144�wT�rZrr/rF)r�145block_size)�	bufferingrr)
r r\�_parentr[rrr�
_as_temp_pathr�
SMBFileOpenerr,r<�	open_file)r"rO�moder��146autocommit�
cache_optionsr#�blsr_r�temps           r%�_open�SMBFileSystem._open s���$�?�?�s�d�{��M�M�$�,�,�t�,�t�M�<�&�2�z�Q��j�B���T�Y�Y��-���z�z�.�$�2C�2C�D���$�;�:��.� ����D�-�-�@�D� ��T��(,�147�148�s��FL��
��"�"���149��%����150��
151�	152r'c��[URU5n[URU5nUR(aURUR	U5SS9 [153R"XE4SUR0UD6 g)z0Copy within two locations in the same filesystemTr�rN)r[rr r\r�r<�copyfiler,)r"�path1�path2r#�wpath1�wpath2s      r%�copy�SMBFileSystem.copyEs^���d�i�i��/���d�i�i��/���?�?��M�M�$�,�,�u�-��M�=����6�E��154�155�E�f�Er'c�<�[U5(a�[URU5n[R"X R156S9n[
UR5(a[R"X R157S9 g[R"X R158S9 ggre)159rbr[rr<rsr,rrtrf�remover�s    r%�_rm�SMBFileSystem._rmMse���4� � � ����D�1�E��N�N�5�z�z�:�E��u�}�}�%�%�����J�J�7�� � ��Z�Z�8�
!r'c��[URU5n[URU5n[R"Xg4SUR0UD6 g)Nr)r[rr<�renamer,)r"r�r��	recursive�maxdepthr#r�r�s        r%�mv�SMBFileSystem.mvVs>���d�i�i��/���d�i�i��/������C�d�j�j�C�F�Cr')r rrrrrrrrrrr)160NNN�<NN�r�161F)T)F)�rbr/TN)NN)�__name__�162__module__�__qualname__�__firstlineno__�__doc__rTr�propertyr,r!�classmethodrQ�staticmethodrVr]r\rfr}r�r�r�r�r�r�r��__static_attributes__�
__classcell__)r$s@r%r163r164s����%�N�H�������!"�$%�&(��W�r�7��7�<!�|�3��3�����>�J�1654�166�(Y�Y������
#167�JF�9�D�Dr'r168c�8�URSS5nSUU3nU$)Nrl�\z\\)�replace)rrO�rpathr�s    r%r[r[\s'���L�L��d�#�E����u�g�169�C��Jr'c�~�URS5SnSUUS[R"53n[X5nU$)Nrlr)�split�uuid�uuid4r[)rrOr�share�	temp_filer�s      r%r�r�bs?���J�J�s�O�A��E��E�7�8�*�A�d�j�j�l�^�4�I�170�t�171'�C��Jr'c�d�URS5nURS5(aUS:�$US:�$)Nrlrr)�count�endswith)rO�partss  r%rbrbis2���J�J�s�O�E��}�}�S����q�y���1�9�r'c�R�\rSrSrSrSSjrSrSrSrSr	Sr172S	rS173rSr
Srg
)r�ipz/writes to remote temporary file, move on commitc��XlX lX0lXPlX`lSUlSUlX@lUR5 g�NF)	rOr�r�r�r#�smbfile�174_incontextrr�)r"rOr�r�rr�r#s       r%r�SMBFileOpener.__init__ss7���	��	��	�$�����������	��175�176�r'c���URbURR(aS[R"URUR1774URURS.URD6Ulgg)N)rr�)	r��closedr<r�r�r�rr�r#r+s r%r��SMBFileOpener._open~s`���<�<��4�<�<�#6�#6�$�.�.��	�	��	�	���Y�Y��/�/�	�178�+�+��D�L�$7r'c�l�[R"URURURS9 g)z(Move temp file to definitive on success.r*N)r<r�r�rOrr+s r%�commit�SMBFileOpener.commit�s"��	���$�)�)�T�Y�Y�T�Y�Y�?r'c�V�[R"URURS9 g)z Remove the temp file on failure.r*N)r<r�r�rr+s r%�discard�SMBFileOpener.discard�s�����������3r'c��UR$�N)rOr+s r%�179__fspath__�SMBFileOpener.__fspath__�s���y�y�r'c�6�URR5$r�)r��__iter__r+s r%r��SMBFileOpener.__iter__�s���|�|�$�$�&�&r'c�.�[URU5$r�)�getattrr�)r"�items  r%�__getattr__�SMBFileOpener.__getattr__�s���t�|�|�T�*�*r'c�D�SUlURR5$)NT)r�r��	__enter__r+s r%r��SMBFileOpener.__enter__�s������|�|�%�%�'�'r'c�J�SUlURRXU5 gr�)r�r��__exit__)r"�exc_type�	exc_value�	tracebacks    r%r��SMBFileOpener.__exit__�s����������h�9�=r')r�r�r#r�rOrr�r�N)r)r/)r�r�r�r�r�rr�r�r�r�r�r�r�r�r�rr'r%r�r�ps3��9�	��@�1804��'�+�(�>r'r�)r�r�rBr�rsrrr<�smbprotocol.exceptionsr>rr�utilsrr181r[r�rbr�rr'r%�<module>r�sO���182�	��!���!�)�183ED�&�ED�P184���0>�0>r'
codekingpro/portable-devtools · Team Ai