File: //usr/lib/python3/dist-packages/twisted/python/__pycache__/filepath.cpython-38.pyc
U
W[� � @ s� d Z ddlmZmZ ddlZddlZddlZddlZddlm Z m
Z
mZmZm
Z
ddlmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZ ddlmZmZmZ dd lmZmZmZ dd
lm Z m!Z!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* dd
l+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl1m4Z4m5Z5m6Z6 ddl1m7Z7 ddl8m9Z9 ej:ej;B ej<B e6B Z=dd� Z>e?ej@de>�ZAejBZCejDZEG dd� de$�ZFG dd� deG�ZHG dd� deG�ZIG dd� deJ�ZKG dd � d eKe7�ZLd!d"� ZMG d#d$� d$eN�ZOG d%d&� d&e9eN�ZPG d'd(� d(e9eN�ZQG d)d*� d*eN�ZRd6d+d,�ZSd7d-d.�ZTd8d/d0�ZUe(e&eF�G d1d2� d2eO���ZVe,e0d3d4dd�d5�eVjW�ZXeYeXeX�eV_WeVeV_ZdS )9z1
Object-oriented filesystem path representation.
� )�division�absolute_importN)�isabs�exists�normpath�abspath�splitext)�basename�dirname�join)�listdir�utime�stat)�S_ISREG�S_ISDIR�S_IMODE�S_ISBLK�S_ISSOCK)�S_IRUSR�S_IWUSR�S_IXUSR)�S_IRGRP�S_IWGRP�S_IXGRP)�S_IROTH�S_IWOTH�S_IXOTH)� Interface� Attribute�implementer)�
comparable�cmp�unicode)�
deprecated)�platform)�Version)�ERROR_FILE_NOT_FOUND�ERROR_PATH_NOT_FOUND)�ERROR_INVALID_NAME�ERROR_DIRECTORY�O_BINARY)�WindowsError)�FancyEqMixinc C s dS )z�
Always return C{False} if the operating system does not support symlinks.
@param path: A path string.
@type path: L{str}
@return: C{False}
@rtype: L{bool}
F� ��pathr- r- �9/usr/lib/python3/dist-packages/twisted/python/filepath.py�_stub_islink1 s
r1 �islinkc @ s� e Zd ZdZed�Zdd� Zd!dd�Zdd � Zd
d� Z dd
� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd S )"� IFilePatha�
File path object.
A file path represents a location for a file-like-object and can be
organized into a hierarchy; a file path can can children which are
themselves file paths.
A file path has a name which unique identifies it in the context of its
parent (if it has one); a file path can not have two children with the same
name. This name is referred to as the file path's "base name".
A series of such names can be used to locate nested children of a file
path; such a series is referred to as the child's "path", relative to the
parent. In this case, each name in the path is referred to as a "path
segment"; the child's base name is the segment in the path.
When representing a file path as a string, a "path separator" is used to
delimit the path segments within the string. For a file system path, that
would be C{os.sep}.
Note that the values of child names may be restricted. For example, a file
system path will not allow the use of the path separator in a name, and
certain names (e.g. C{"."} and C{".."}) may be reserved or have special
meanings.
@since: 12.1
z3The path separator to use in string representationsc C s dS )a�
Obtain a direct child of this file path. The child may or may not
exist.
@param name: the name of a child of this path. C{name} must be a direct
child of this path and may not contain a path separator.
@return: the child of this path with the given C{name}.
@raise InsecurePath: if C{name} describes a file path that is not a
direct child of this file path.
Nr- ��namer- r- r0 �childb s zIFilePath.child�rc C s dS )z�
Opens this file path with the given mode.
@return: a file-like object.
@raise Exception: if this file path cannot be opened.
Nr- )�moder- r- r0 �openn s zIFilePath.openc C s dS )zT
Clear any cached information about the state of this path on disk.
Nr- r- r- r- r0 �changedv s zIFilePath.changedc C s dS )z�
Retrieve the size of this file in bytes.
@return: the size of the file at this file path in bytes.
@raise Exception: if the size cannot be obtained.
Nr- r- r- r- r0 �getsize{ s zIFilePath.getsizec C s dS )��
Retrieve the time of last access from this file.
@return: a number of seconds from the epoch.
@rtype: L{float}
Nr- r- r- r- r0 �getModificationTime� s zIFilePath.getModificationTimec C s dS )��
Retrieve the time of the last status change for this file.
@return: a number of seconds from the epoch.
@rtype: L{float}
Nr- r- r- r- r0 �getStatusChangeTime� s zIFilePath.getStatusChangeTimec C s dS )��
Retrieve the time that this file was last accessed.
@return: a number of seconds from the epoch.
@rtype: L{float}
Nr- r- r- r- r0 �
getAccessTime� s zIFilePath.getAccessTimec C s dS )z�
Check if this file path exists.
@return: C{True} if the file at this file path exists, C{False}
otherwise.
@rtype: L{bool}
Nr- r- r- r- r0 r � s zIFilePath.existsc C s dS )z�
Check if this file path refers to a directory.
@return: C{True} if the file at this file path is a directory, C{False}
otherwise.
Nr- r- r- r- r0 �isdir� s zIFilePath.isdirc C s dS )z�
Check if this file path refers to a regular file.
@return: C{True} if the file at this file path is a regular file,
C{False} otherwise.
Nr- r- r- r- r0 �isfile� s zIFilePath.isfilec C s dS )z�
List the children of this path object.
@return: a sequence of the children of the directory at this file path.
@raise Exception: if the file at this file path is not a directory.
Nr- r- r- r- r0 �children� s zIFilePath.childrenc C s dS )z�
Retrieve the final component of the file path's path (everything
after the final path separator).
@return: the base name of this file path.
@rtype: L{str}
Nr- r- r- r- r0 r � s zIFilePath.basenamec C s dS )zV
A file path for the directory containing the file at this file path.
Nr- r- r- r- r0 �parent� s zIFilePath.parentc C s dS )a$
A file path for the directory containing the file at this file path.
@param name: the name of a sibling of this path. C{name} must be a
direct sibling of this path and may not contain a path separator.
@return: a sibling file path of this one.
Nr- r4 r- r- r0 �sibling� s zIFilePath.siblingN)r7 )�__name__�
__module__�__qualname__�__doc__r �sepr6 r9 r: r; r= r? rA r rB rC rD r rE rF r- r- r- r0 r3 D s
r3 c @ s e Zd ZdZdS )�InsecurePathzP
Error that is raised when the path provided to L{FilePath} is invalid.
N�rG rH rI rJ r- r- r- r0 rL � s rL c @ s e Zd ZdZdS )� LinkErrorz�
An error with symlinks - either that there are cyclical symlinks or that
symlink are not supported on this platform.
NrM r- r- r- r0 rN � s rN c @ s e Zd ZdZdd� ZdS )�UnlistableErrora�
An exception which is used to distinguish between errors which mean 'this
is not a directory you can list' and other, more catastrophic errors.
This error will try to look as much like the original error as possible,
while still being catchable as an independent type.
@ivar originalException: the actual original exception instance, either an
L{OSError} or a L{WindowsError}.
c C s | j �|j � || _dS )zq
Create an UnlistableError exception.
@param originalException: an instance of OSError.
N)�__dict__�update�originalException)�selfrR r- r- r0 �__init__� s zUnlistableError.__init__N)rG rH rI rJ rT r- r- r- r0 rO � s
rO c @ s e Zd ZdZdS )�_WindowsUnlistableErrora*
This exception is raised on Windows, for compatibility with previous
releases of FilePath where unportable programs may have done "except
WindowsError:" around a call to children().
It is private because all application code may portably catch
L{UnlistableError} instead.
NrM r- r- r- r0 rU � s rU c C s t td��dd� }t| |�S )a
Compute a string usable as a new, temporary filename.
@param path: The path that the new temporary filename should be able to be
concatenated with.
@return: A pseudorandom, 16 byte string for use in secure filenames.
@rtype: the type of C{path}
� N)�armor�randomBytes�_coerceToFilesystemEncoding)r/ ZsecureishStringr- r- r0 �_secureEnoughString s
rZ c @ sj e Zd ZdZdd� Zdd� Zdd� Zdd d
�Zdd� Zd
d� Z dd� Z
dd� Zdd� Zdd� Z
dd� ZdS )�AbstractFilePatha-
Abstract implementation of an L{IFilePath}; must be completed by a
subclass.
This class primarily exists to provide common implementations of certain
methods in L{IFilePath}. It is *not* a required parent class for
L{IFilePath} implementations, just a useful starting point.
c
C s( | � � �}|�� W 5 Q R � S Q R X dS )z�
Retrieve the contents of the file at this path.
@return: the contents of the file
@rtype: L{bytes}
N)r9 �read)rS �fpr- r- r0 �
getContent s
zAbstractFilePath.getContentc c s, | }|� � }||kr(|V |}|� � }qdS )z�
Retrieve an iterator of all the ancestors of this path.
@return: an iterator of all the ancestors of this path, from the most
recent (its immediate parent) to the root of its filesystem.
N)rE )rS r/ rE r- r- r0 �parents* s zAbstractFilePath.parentsc
s� z� � � }W n� tk
rV } z,t|d|j�}|ttttfkr>� t|��W 5 d}~X Y n> t k
r� } z |jtj
tjfkrz� t|��W 5 d}~X Y nX � fdd�|D �S )a�
List the children of this path object.
@raise OSError: If an error occurs while listing the directory. If the
error is 'serious', meaning that the operation failed due to an access
violation, exhaustion of some kind of resource (file descriptors or
memory), OSError or a platform-specific variant will be raised.
@raise UnlistableError: If the inability to list the directory is due
to this path not existing or not being a directory, the more specific
OSError subclass L{UnlistableError} is raised instead.
@return: an iterable of all currently-existing children of this object.
�winerrorNc s g | ]}� � |��qS r- �r6 )�.0r5 �rS r- r0 �
<listcomp>{ s z-AbstractFilePath.children.<locals>.<listcomp>)
r r+ �getattr�errnor'