文件操作 - path.cpython-311.pyc
返回文件管理
返回主菜单
删除本文件
文件: /usr/lib/python3/dist-packages/ipython_genutils/__pycache__/path.cpython-311.pyc
编辑文件内容
� ��X � � � d Z ddlZddlZddlZddlZddlZddlmZ ej � � Z dd�Z d� Z ej Zn # e $ r dZY nw xY wd� Zd � Zd d�ZdS )z Utilities for path handling. � N� )� py3compatc �V � | � d� � � d� � } t j � | � � r!t j � | � � r| S |�d}nt |t j � � r|f}|D ]�}|dk rt j � � }t t j � || � � � � }t j � |� � r!t j � |� � c S ��t d| �d|��� � �)a� Find a file by looking through a sequence of paths. This iterates through a sequence of paths looking for a file and returns the full, absolute path of the first occurence of the file. If no set of path dirs is given, the filename is tested as is, after running through :func:`expandvars` and :func:`expanduser`. Thus a simple call:: filefind('myfile.txt') will find the file in the current working dir, but:: filefind('~/myfile.txt') Will find the file in the users home directory. This function does not automatically try any paths, such as the cwd or the user's home directory. Parameters ---------- filename : str The filename to look for. path_dirs : str, None or sequence of str The sequence of paths to look for the file in. If None, the filename need to be absolute or be in the cwd. If a string, the string is put into a sequence and the searched. If a sequence, walk through each element and join with ``filename``, calling :func:`expandvars` and :func:`expanduser` before testing for existence. Returns ------- Raises :exc:`IOError` or returns absolute path to file. �"�'N)� �.zFile z, does not exist in any of the search paths: ) �strip�os�path�isabs�isfile� isinstancer �string_types�getcwd�expand_path�join�abspath�IOError)�filename� path_dirsr �testnames �7/usr/lib/python3/dist-packages/ipython_genutils/path.py�filefindr s � �D �~�~�c�"�"�(�(��-�-�H� �w�}�}�X��� �2�7�>�>�(�#;�#;� ������ � � �I�y�5� 6� 6� !��L� �� -� -���3�;�;�y�/�1�1���r�w�|�|�D�(�;�;�<�<�� �7�>�>�(�#�#� -��7�?�?�8�,�,�,�,�,� -� �'��8�8�Y�Y�(� *� *� *� c � � t j dk r| � dd� � } t j � t j � | � � � � } t j dk r| � dd� � } | S )z�Expand $VARS and ~names in a string, like a shell :Examples: In [2]: os.environ['FOO']='test' In [3]: expand_path('variable FOO is $FOO') Out[3]: 'variable FOO is test' �ntz$\�IPYTHON_TEMP)r �name�replacer � expandvars� expanduser)�ss r r r K sj � � �w��}�}� �I�I�e�^�,�,�� ����2�7�-�-�a�0�0�1�1�A� �w��}�}� �I�I�n�e�,�,���Hr i� c � � t t d� � st S d} t j | |� � n# t $ r}|j }Y d}~nd}~ww xY w|S )z�Hard links ``src`` to ``dst``, returning 0 or errno. Note that the special errno ``ENOLINK`` will be returned if ``os.link`` isn't supported by the operating system. �linkr N)�hasattrr �ENOLINKr% �OSError�errno)�src�dst� link_errno�es r r% r% g sp � � �2�v��� ����J�� ���S������� � � ��W� � � � � � ����������s �6 � A� A�Ac � � t j � |� � r=t j � |t j � | � � � � }t | |� � }|t j k r�t j | � � j t j |� � j k rdS |dt j dd� � fz z } t | |� � n,# t j |� � n# t $ r Y nw xY w� xY wt j ||� � dS |dk rt! j | |� � dS dS )a+ Attempts to hardlink ``src`` to ``dst``, copying if the link fails. Attempts to maintain the semantics of ``shutil.copy``. Because ``os.link`` does not overwrite files, a unique temporary file will be used if the target already exists, then that file will be moved into place. Nz -temp-%04Xr i r )r r �isdirr �basenamer% r) �EEXIST�stat�st_ino�random�randint�link_or_copy�remover( �rename�shutil�copy)r* r+ r, �new_dsts r r6 r6 x s= � � �w�}�}�S��� 7��g�l�l�3��� 0� 0�� 5� 5�6�6���c�3���J��U�\�!�!� �7�3�<�<��"�'�#�,�,�"5�5�5� �F���v�~�a��'?�'?�&B�B�B�� ���g�&�&�&�&�� � �� �'�"�"�"�"��� � � ��� �������� � �'�3������ �q��� ��C������� �s0 �C! �!D �$C9�8D �9 D�D �D�D �� c �4 � t j � | � � sG t j | |�� � dS # t $ r!}|j t j k r� Y d}~dS d}~ww xY wt j � | � � st d| z � � �dS )z�ensure that a directory exists If it doesn't exist, try to create it and protect against a race condition if another process is doing the same. The default permissions are 755, which differ from os.makedirs default of 777. )�modeNz %r exists but is not a directory) r r �exists�makedirsr( r) r1 r/ r )r r>