a
    Cg1                     @   sh   d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ dd Zdd Zdd
dZdddZd	S )    )URLResolverincludepathre_pathregister_converter)get_converters)RoutePattern)api_settingsc                    sL   | r2t | dkr| d }ndd|  }d|  nd G  fddd}|S )	N   r   z(?:%s)|z\.%s/?z\.[a-z0-9]+/?c                       s    e Zd Z Zdd Zdd ZdS )z9_get_format_path_converter.<locals>.FormatSuffixConverterc                 S   s
   | dS )Nz./)stripselfvalue r   Y/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/rest_framework/urlpatterns.py	to_python   s    zC_get_format_path_converter.<locals>.FormatSuffixConverter.to_pythonc                 S   s   d| d S )N./r   r   r   r   r   to_url   s    z@_get_format_path_converter.<locals>.FormatSuffixConverter.to_urlN)__name__
__module____qualname__regexr   r   r   suffix_patternr   r   FormatSuffixConverter   s   r   )lenjoin)allowedallowed_patternr   r   r   r   _get_format_path_converter   s    

	r!   c                 C   s   d}| r|dd |  7 }|S )NZdrf_format_suffix_)r   )r   converter_namer   r   r   _generate_converter_name   s    r$   Nc                 C   sJ  g }| D ]:}t |tr|jjj}|j}|j}|j}	t|j|||}
t |jt	r~t
d us\J t|j}t
|t|
|f||	}nt|t|
|f||	}|| q|jjjdd| }|j}|j}	|j}|s|| t |jt	r,t
d usJ |d usJ t|jdd| }t
|||	|}nt|||	|}|| q|S )N$r   )
isinstancer   patternr   	namespaceapp_nameZdefault_kwargsapply_suffix_patternsZurl_patternsr   r   strr   r   appendrstripcallbackZdefault_argsname)urlpatternsr   suffix_requiredsuffix_routeretZ
urlpatternr   r(   r)   kwargspatternsZrouteZnew_patternviewr/   r   r   r   r*   %   s@    




r*   Fc           	      C   s   t j}|r<t|dkr |d }ndd| }d||f }nd| }t|}|t vrht|}t|| d||f }t| |||S )a  
    Supplement existing urlpatterns with corresponding patterns that also
    include a '.format' suffix.  Retains urlpattern ordering.

    urlpatterns:
        A list of URL patterns.

    suffix_required:
        If `True`, only suffixed URLs will be generated, and non-suffixed
        URLs will not be used.  Defaults to `False`.

    allowed:
        An optional tuple/list of allowed suffixes.  eg ['json', 'api']
        Defaults to `None`, which allows any suffix.
    r
   r   z(%s)r   z\.(?P<%s>%s)/?$z\.(?P<%s>[a-z0-9]+)/?$z<%s:%s>)	r	   ZFORMAT_SUFFIX_KWARGr   r   r$   r   r!   r   r*   )	r0   r1   r   Zsuffix_kwargr    r   r#   Zsuffix_converterr2   r   r   r   format_suffix_patternsU   s    


r7   )N)FN)Zdjango.urlsr   r   r   r   r   Zdjango.urls.convertersr   Zdjango.urls.resolversr   Zrest_framework.settingsr	   r!   r$   r*   r7   r   r   r   r   <module>   s   
0