
    ^f                        d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ  G d	 d
          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    N)gettext_lazy)
exceptions)unicode_http_header_reverse)api_settings)replace_query_param)
_MediaTypec                   L    e Zd Zej        Zej        Zej        Z	d Z
ddZd ZdS )BaseVersioningc                 `    d}t          |                    | j        j                            )Nz.{cls}.determine_version() must be implemented.)cls)NotImplementedErrorformat	__class____name__)selfrequestargskwargsmsgs        K/var/www/html/env/lib/python3.11/site-packages/rest_framework/versioning.pydetermine_versionz BaseVersioning.determine_version   s6    >!#**' #- #
 #
   	    Nc                 $    t          |||||fi |S Nr   )r   viewnamer   r   r   r   extras          r   reversezBaseVersioning.reverse   s     $II5IIIr   c                 D    | j         sdS |d ur|| j        k    p|| j         v S )NT)allowed_versionsdefault_version)r   versions     r   is_allowed_versionz!BaseVersioning.is_allowed_version   s<    $ 	4$HD4H)H 3D11	4r   NNNN)r   
__module____qualname__r   DEFAULT_VERSIONr"   ALLOWED_VERSIONSr!   VERSION_PARAMversion_paramr   r   r$    r   r   r   r      sc        "2O#4 .M  J J J J4 4 4 4 4r   r   c                   .    e Zd ZdZ ed          Zd ZdS )AcceptHeaderVersioningzb
    GET /something/ HTTP/1.1
    Host: example.com
    Accept: application/json; version=1.0
    z#Invalid version in "Accept" header.c                     t          |j                  }|j                            | j        | j                  }t          |          }|                     |          st          j	        | j
                  |S r   )r
   accepted_media_typeparamsgetr+   r"   r   r$   r   NotAcceptableinvalid_version_message)r   r   r   r   
media_typer#   s         r   r   z(AcceptHeaderVersioning.determine_version*   sm     ;<<
#''(:D<PQQ%g..&&w// 	I*4+GHHHr   N)r   r&   r'   __doc___r4   r   r,   r   r   r.   r.   "   s@         
  a EFF    r   r.   c                   @     e Zd ZdZ ed          Zd Zd fd	Z xZS )URLPathVersioninga8  
    To the client this is the same style as `NamespaceVersioning`.
    The difference is in the backend - this implementation uses
    Django's URL keyword arguments to determine the version.

    An example URL conf for two views that accept two different versions.

    urlpatterns = [
        re_path(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
        re_path(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
    ]

    GET /1.0/something/ HTTP/1.1
    Host: example.com
    Accept: application/json
    zInvalid version in URL path.c                     |                     | j        | j                  }|| j        }|                     |          st	          j        | j                  |S r   )r2   r+   r"   r$   r   NotFoundr4   r   r   r   r   r#   s        r   r   z#URLPathVersioning.determine_versionI   sX    **T/1EFF?*G&&w// 	D%d&BCCCr   Nc                 x    |j         |i n|}|j         || j        <    t                      j        |||||fi |S r   )r#   r+   superr   r   r   r   r   r   r   r   r   s          r   r   zURLPathVersioning.reverseR   sY    ?&"NRRF)0F4%&uwwdFGV
 
7<
 
 	
r   r%   	r   r&   r'   r6   r7   r4   r   r   __classcell__r   s   @r   r9   r9   6   si            a >??  
 
 
 
 
 
 
 
 
 
r   r9   c                   F     e Zd ZdZ ed          Zd Zd fd	Zd Z xZ	S )NamespaceVersioninga  
    To the client this is the same style as `URLPathVersioning`.
    The difference is in the backend - this implementation uses
    Django's URL namespaces to determine the version.

    An example URL conf that is namespaced into two separate versions

    # users/urls.py
    urlpatterns = [
        path('/users/', users_list, name='users-list'),
        path('/users/<int:pk>/', users_detail, name='users-detail')
    ]

    # urls.py
    urlpatterns = [
        path('v1/', include('users.urls', namespace='v1')),
        path('v2/', include('users.urls', namespace='v2'))
    ]

    GET /1.0/something/ HTTP/1.1
    Host: example.com
    Accept: application/json
    zBInvalid version in URL path. Does not match any version namespace.c                     t          |dd           }||j        s| j        S |j                            d          }|D ]}|                     |          r|c S t          j        | j                  )Nresolver_match:)getattr	namespacer"   splitr$   r   r;   r4   )r   r   r   r   rF   possible_versionsr#   s          r   r   z%NamespaceVersioning.determine_versionv   s     *:DAA!)A!'' +4::3??( 	 	G&&w// !$">???r   Nc                 z    |j         |                     ||          } t                      j        |||||fi |S r   )r#   get_versioned_viewnamer>   r   r?   s          r   r   zNamespaceVersioning.reverse   sR    ?&228WEEHuwwdFGV
 
7<
 
 	
r   c                     |j         dz   |z   S )NrG   )r#   )r   r   r   s      r   rM   z*NamespaceVersioning.get_versioned_viewname   s    $x//r   r%   )
r   r&   r'   r6   r7   r4   r   r   rM   rA   rB   s   @r   rD   rD   \   s{         .  a dee
@ 
@ 
@
 
 
 
 
 
0 0 0 0 0 0 0r   rD   c                   N    e Zd ZdZ ej        d          Z ed          Zd Z	dS )HostNameVersioningzX
    GET /something/ HTTP/1.1
    Host: v1.example.com
    Accept: application/json
    z,^([a-zA-Z0-9]+)\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+$zInvalid version in hostname.c                 (   |                                                     d          \  }}}| j                            |          }|s| j        S |                    d          }|                     |          st          j        | j	                  |S )NrG      )
get_host	partitionhostname_regexmatchr"   groupr$   r   r;   r4   )	r   r   r   r   hostname	separatorportrV   r#   s	            r   r   z$HostNameVersioning.determine_version   s    $+$4$4$6$6$@$@$E$E!)T#))(33 	(''++a..&&w// 	D%d&BCCCr   N)
r   r&   r'   r6   recompilerU   r7   r4   r   r,   r   r   rP   rP      sR         
  RZ OPPNa >??    r   rP   c                   @     e Zd ZdZ ed          Zd Zd fd	Z xZS )QueryParameterVersioningza
    GET /something/?version=0.1 HTTP/1.1
    Host: example.com
    Accept: application/json
    z#Invalid version in query parameter.c                     |j                             | j        | j                  }|                     |          st          j        | j                  |S r   )query_paramsr2   r+   r"   r$   r   r;   r4   r<   s        r   r   z*QueryParameterVersioning.determine_version   sP    &**4+=t?STT&&w// 	D%d&BCCCr   Nc                      t                      j        |||||fi |}|j        t          || j        |j                  S |S r   )r>   r   r#   r	   r+   )	r   r   r   r   r   r   r   urlr   s	           r   r   z QueryParameterVersioning.reverse   sX    eggodFGV
 
7<
 
 ?&&sD,>PPP
r   r%   r@   rB   s   @r   r^   r^      si         
  a EFF           r   r^   )r[   django.utils.translationr   r7   rest_frameworkr   rest_framework.compatr   rest_framework.reverser   rest_framework.settingsr   *rest_framework.templatetags.rest_frameworkr	   rest_framework.utils.mediatypesr
   r   r.   r9   rD   rP   r^   r,   r   r   <module>rj      s   				 6 6 6 6 6 6 % % % % % % 5 5 5 5 5 5 + + + + + + 0 0 0 0 0 0 J J J J J J 6 6 6 6 6 64 4 4 4 4 4 4 4*    ^   (#
 #
 #
 #
 #
 #
 #
 #
L.0 .0 .0 .0 .0. .0 .0 .0b       .    ~     r   