ó
O'^c           @  s  d  d l  m Z 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 d
 e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   i˙˙˙˙(   t   unicode_literalsN(   t   ugettext_lazy(   t
   exceptions(   t   unicode_http_header(   t   _reverse(   t   api_settings(   t   replace_query_param(   t
   _MediaTypet   BaseVersioningc           B  sJ   e  Z e j Z e j Z e j Z d    Z	 d d d d d  Z d   Z RS(   c         O  s(   d } t  | j d |  j j    d  S(   Nu.   {cls}.determine_version() must be implemented.t   cls(   t   NotImplementedErrort   formatt	   __class__t   __name__(   t   selft   requestt   argst   kwargst   msg(    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyt   determine_version   s    c         K  s   t  | | | | | |  S(   N(   R   (   R   t   viewnameR   R   R   R   t   extra(    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyt   reverse   s    c         C  s5   |  j  s t S| d  k	 r( | |  j k p4 | |  j  k S(   N(   t   allowed_versionst   Truet   Nonet   default_version(   R   t   version(    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyt   is_allowed_version   s    	N(   R   t
   __module__R   t   DEFAULT_VERSIONR   t   ALLOWED_VERSIONSR   t   VERSION_PARAMt   version_paramR   R   R   R   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR      s   				t   AcceptHeaderVersioningc           B  s#   e  Z d  Z e d  Z d   Z RS(   ub   
    GET /something/ HTTP/1.1
    Host: example.com
    Accept: application/json; version=1.0
    u#   Invalid version in "Accept" header.c         O  s^   t  | j  } | j j |  j |  j  } t |  } |  j |  sZ t j	 |  j
   n  | S(   N(   R   t   accepted_media_typet   paramst   getR!   R   R   R   R   t   NotAcceptablet   invalid_version_message(   R   R   R   R   t
   media_typeR   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR   -   s    (   R   R   t   __doc__t   _R'   R   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR"   %   s   t   URLPathVersioningc           B  s8   e  Z d  Z e d  Z d   Z d d d d d  Z RS(   u0  
    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 = [
        url(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
        url(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
    u   Invalid version in URL path.c         O  s@   | j  |  j |  j  } |  j |  s< t j |  j   n  | S(   N(   R%   R!   R   R   R   t   NotFoundR'   (   R   R   R   R   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR   L   s    c         K  s_   | j  d  k	 r: | d  k r! i  n | } | j  | |  j <n  t t |   j | | | | | |  S(   N(   R   R   R!   t   superR+   R   (   R   R   R   R   R   R   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR   R   s
    N(   R   R   R)   R*   R'   R   R   R   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR+   9   s   	t   NamespaceVersioningc           B  sA   e  Z d  Z e d  Z d   Z d d d d d  Z d   Z RS(   uŻ  
    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 = [
        url(r'^/users/$', users_list, name='users-list'),
        url(r'^/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
    ]

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

    GET /1.0/something/ HTTP/1.1
    Host: example.com
    Accept: application/json
    uB   Invalid version in URL path. Does not match any version namespace.c         O  s{   t  | d d   } | d  k s( | j r/ |  j S| j j d  } x! | D] } |  j |  rH | SqH Wt j |  j   d  S(   Nu   resolver_matchu   :(	   t   getattrR   t	   namespaceR   t   splitR   R   R,   R'   (   R   R   R   R   t   resolver_matcht   possible_versionsR   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR   v   s    c         K  sI   | j  d  k	 r$ |  j | |  } n  t t |   j | | | | | |  S(   N(   R   R   t   get_versioned_viewnameR-   R.   R   (   R   R   R   R   R   R   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR      s    c         C  s   | j  d | S(   Nu   :(   R   (   R   R   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR4      s    N(	   R   R   R)   R*   R'   R   R   R   R4   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR.   \   s
   	t   HostNameVersioningc           B  s2   e  Z d  Z e j d  Z e d  Z d   Z RS(   uX   
    GET /something/ HTTP/1.1
    Host: v1.example.com
    Accept: application/json
    u,   ^([a-zA-Z0-9]+)\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+$u   Invalid version in hostname.c   	      O  st   | j    j d  \ } } } |  j j |  } | s= |  j S| j d  } |  j |  sp t j |  j	   n  | S(   Nu   :i   (
   t   get_hostt	   partitiont   hostname_regext   matchR   t   groupR   R   R,   R'   (	   R   R   R   R   t   hostnamet	   separatort   portR9   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR      s    (	   R   R   R)   t   ret   compileR8   R*   R'   R   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR5      s   t   QueryParameterVersioningc           B  s8   e  Z d  Z e d  Z d   Z d d d d d  Z RS(   ua   
    GET /something/?version=0.1 HTTP/1.1
    Host: example.com
    Accept: application/json
    u#   Invalid version in query parameter.c         O  sC   | j  j |  j |  j  } |  j |  s? t j |  j   n  | S(   N(   t   query_paramsR%   R!   R   R   R   R,   R'   (   R   R   R   R   R   (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR   Ĵ   s    c         K  sP   t  t |   j | | | | | |  } | j d  k	 rL t | |  j | j  S| S(   N(   R-   R@   R   R   R   R   R!   (   R   R   R   R   R   R   R   t   url(    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR   ²   s
    N(   R   R   R)   R*   R'   R   R   R   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyR@   ¤   s   	(   t
   __future__R    R>   t   django.utils.translationR   R*   t   rest_frameworkR   t   rest_framework.compatR   t   rest_framework.reverseR   t   rest_framework.settingsR   t*   rest_framework.templatetags.rest_frameworkR   t   rest_framework.utils.mediatypesR   t   objectR   R"   R+   R.   R5   R@   (    (    (    s;   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/versioning.pyt   <module>   s   #1