o
    ^"<f                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZ e
r/d dlmZ nzd dlmZ W n eyD   d dlZY nw dd Zdd Zdadd	d
ZdddZde_dd ZdS )    Nimport_string)CONVERT_FILENAMENORMALIZE_FILENAME
STRICT_PILVERSION_PROCESSORS)Imagec                 C   s   t r=| tj}g }|D ] }tdt|dd	d}t
dd| }|| qt|dkr9d|} n|d } trG| d	d
 } | S )z
    Convert Filename.
    NFKDasciiignorez[^\w\s-]    .r    _)r   splitosextsepunicodedata	normalizesix	text_typeencodedecoderesubstripappendlenjoinr   replacelower)valuechunks
normalizedv r&   H/var/www/html/kck/venv/lib/python3.10/site-packages/filebrowser/utils.pyconvert_filename   s    r(   c                 C   sB   | r|s| S t j| } t j|}| |r| t|d  S | S N)r   pathnormcase
startswithr   )r*   rootr&   r&   r'   
path_strip/   s   
r.   c                 C   sD   |du rt du rdd tD a t }| }|D ]
}||fi |}q|S )zy
    Process a source PIL image through a series of image processors, returning
    the (potentially) altered image.
    Nc                 S      g | ]}t |qS r&   r   ).0namer&   r&   r'   
<listcomp>D       z!process_image.<locals>.<listcomp>)_default_processorsr   )sourceprocessor_options
processorsimage	processorr&   r&   r'   process_image<   s   r:   r   c                 K   s  dd | j D \}}t|pd}t|pd}||f||fkr | S d|vr2||k s*|s2||k s0|s2| S |r9t|}nt|| | }|rHt|}nt|| | }d|v r^t|| || }	n	t|| || }	|	dk ss|	dkrd|v r| jtt||	 tt||	 ftj	d} d|v rdd | j D \}}|t|| d	 |t|| d	 }
}|
s|r| 
t|
t|t|
| t|| f} | S )
z
    Scale and Crop.
    c                 S   r/   r&   floatr0   r%   r&   r&   r'   r2   P   r3   z"scale_and_crop.<locals>.<listcomp>r   upscalecropg      ?)resamplec                 S   r/   r&   r;   r=   r&   r&   r'   r2   m   r3      )sizer<   maxminresizeintmathceilr   	ANTIALIASr?   )imwidthheightoptskwargsxyxryrrexeyr&   r&   r'   scale_and_cropL   s2   

0&*rV   )r?   r>   c                 C   s   t | dr
| |S | |S )Nget_modified_time)hasattrrW   modified_time)storager*   r&   r&   r'   rW   v   s   


rW   r)   )NNr   )rG   r   r   r   r   django.utils.module_loadingr   filebrowser.settingsr   r   r   r   PILr   ImportErrorr(   r.   r4   r:   rV   valid_optionsrW   r&   r&   r&   r'   <module>   s*   


'