U
    mÇfc
  ã                   @   s8   d dl Z d dlZd dlmZ ddd„ZG dd„ dƒZdS )	é    N)ÚSuspiciousFileOperationFc                 C   sj   t j | ¡dkrtd|  ƒ‚|rJt | ¡}| ¡ s<d|jkrftd|  ƒ‚n| t j | ¡krftd|  ƒ‚| S )N>   Ú Ú.ú..z$Could not derive file name from '%s'r   z'Detected path traversal attempt in '%s'z%File name '%s' includes path elements)ÚosÚpathÚbasenamer   ÚpathlibÚPurePosixPathÚis_absoluteÚparts)ÚnameZallow_relative_pathr   © r   ú;/tmp/pip-unpacked-wheel-siwebuq3/django/core/files/utils.pyÚvalidate_file_name   s    
ÿr   c                   @   sä   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZ	edd„ ƒZ
ed	d„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚFileProxyMixinzü
    A mixin class used to forward file methods to an underlaying file
    object.  The internal file object has to be called "file"::

        class FileProxy(FileProxyMixin):
            def __init__(self, file):
                self.file = file
    c                 C   s   | j jS ©N)ÚfileÚencoding©Úselfr   r   r   Ú<lambda>%   ó    zFileProxyMixin.<lambda>c                 C   s   | j jS r   )r   Úfilenor   r   r   r   r   &   r   c                 C   s   | j jS r   )r   Úflushr   r   r   r   r   '   r   c                 C   s   | j jS r   )r   Úisattyr   r   r   r   r   (   r   c                 C   s   | j jS r   )r   Únewlinesr   r   r   r   r   )   r   c                 C   s   | j jS r   )r   Úreadr   r   r   r   r   *   r   c                 C   s   | j jS r   )r   Úreadintor   r   r   r   r   +   r   c                 C   s   | j jS r   )r   Úreadliner   r   r   r   r   ,   r   c                 C   s   | j jS r   )r   Ú	readlinesr   r   r   r   r   -   r   c                 C   s   | j jS r   )r   Úseekr   r   r   r   r   .   r   c                 C   s   | j jS r   )r   Útellr   r   r   r   r   /   r   c                 C   s   | j jS r   )r   Útruncater   r   r   r   r   0   r   c                 C   s   | j jS r   )r   Úwriter   r   r   r   r   1   r   c                 C   s   | j jS r   )r   Ú
writelinesr   r   r   r   r   2   r   c                 C   s   | j  p| j jS r   )r   Úclosedr   r   r   r   r&   4   s    zFileProxyMixin.closedc                 C   s$   | j r
dS t| jdƒr | j ¡ S dS )NFÚreadableT)r&   Úhasattrr   r'   r   r   r   r   r'   8   s
    
zFileProxyMixin.readablec                 C   s2   | j r
dS t| jdƒr | j ¡ S dt| jddƒkS )NFÚwritableÚwÚmoder   )r&   r(   r   r)   Úgetattrr   r   r   r   r)   ?   s
    
zFileProxyMixin.writablec                 C   s$   | j r
dS t| jdƒr | j ¡ S dS )NFÚseekableT)r&   r(   r   r-   r   r   r   r   r-   F   s
    
zFileProxyMixin.seekablec                 C   s
   t | jƒS r   )Úiterr   r   r   r   r   Ú__iter__M   s    zFileProxyMixin.__iter__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r)   r-   r/   r   r   r   r   r      s*   	
r   )F)r   r	   Zdjango.core.exceptionsr   r   r   r   r   r   r   Ú<module>   s   
