
    3~h                     X    d dl Z d dlmZmZ ddlmZmZ  G d de      Z G d de      Zy)	    N)ContentFileFile   )extension_to_mimetypeformat_to_mimetypec                       e Zd ZdZd Zd Zd Zd Zd Z e	eee      Z
d Z e	e      Zd Z e	e      Zd	 Z e	e      Zdd
Zd Z e	e      Zd Zy)
BaseIKFilez
    This class contains all of the methods we need from
    django.db.models.fields.files.FieldFile, but with the model stuff ripped
    out. It's only extended by one class, but we keep it separate for
    organizational reasons.

    c                     || _         y N)storage)selfr   s     W/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/imagekit/files.py__init__zBaseIKFile.__init__   s	        c                     | s
t               y r   )
ValueErrorr   s    r   _require_filezBaseIKFile._require_file   s    , r   c                     | j                          t        | d      r| j                  +| j                  j	                  | j
                  d      | _        | j                  S )N_filerb)r   hasattrr   r   opennamer   s    r   	_get_filezBaseIKFile._get_file   sG    tW%);**499d;DJzzr   c                     || _         y r   r   r   files     r   	_set_filezBaseIKFile._set_file   s	    
r   c                     | ` y r   r   r   s    r   	_del_filezBaseIKFile._del_file!   s    Jr   c                 l    | j                          | j                  j                  | j                        S r   )r   r   pathr   r   s    r   	_get_pathzBaseIKFile._get_path&   s'    ||  ++r   c                 l    | j                          | j                  j                  | j                        S r   )r   r   urlr   r   s    r   _get_urlzBaseIKFile._get_url+   s'    ||		**r   c                     | j                          t        | dd      s| j                  j                  S | j                  j                  | j
                        S )N
_committedF)r   getattrr   sizer   r   r   s    r   	_get_sizezBaseIKFile._get_size0   sA    t\5199>>!||  ++r   c                     | j                          	 | j                  j                  |       y # t        $ r7 | j                  j                  r| `| j                  j                  |      cY S  w xY wr   )r   r   r   r   closed)r   modes     r   r   zBaseIKFile.open7   s^    	IINN4  		 yyI yy~~d++		s   . <A.,A.c                 @    t        | dd       }|d u xs |j                  S Nr   )r+   r/   r   s     r   _get_closedzBaseIKFile._get_closedF   s#    tWd+t|*t{{*r   c                 D    t        | dd       }||j                          y y r2   )r+   closer   s     r   r5   zBaseIKFile.closeK   s$    tWd+JJL r   N)r   )__name__
__module____qualname____doc__r   r   r   r    r"   propertyr   r%   r$   r(   r'   r-   r,   r   r3   r/   r5    r   r   r	   r	      s~     Iy)4D, ID+ 8
C,
 ID+ k"Fr   r	   c                   .    e Zd ZdZddZed        Zd Zy)IKContentFilez
    Wraps a ContentFile in a file-like object with a filename and a
    content_type. A PIL image format can be optionally be provided as a content
    type hint.

    Nc                    t        |      | _        || j                  _        t        | j                  dd       }|r|st	        |      }|s1t
        j                  j                  |xs d      d   }t        |      }|| j                  _	        y )Ncontent_type r   )
r   r   r   r+   r   osr$   splitextr   r?   )r   filenamecontentformatmimetypeexts         r   r   zIKContentFile.__init__X   sp    (	!		499nd;()&1H''""8>r215C,S1H!)		r   c                 .    | j                   j                  S r   )r   r   r   s    r   r   zIKContentFile.namec   s    yy~~r   c                 H    t        | j                  j                  xs d      S )Nr@   )strr   r   r   s    r   __str__zIKContentFile.__str__g   s    499>>'R((r   r   )r6   r7   r8   r9   r   r:   r   rK   r;   r   r   r=   r=   Q   s%    	*  )r   r=   )	rA   django.core.files.baser   r   utilsr   r   r	   r=   r;   r   r   <module>rN      s)    	 4 <F FR)K )r   