ó
O'—^c           @  sœ  d  Z  d d l m Z d d l 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 m Z m Z d d l m Z m Z m Z d d	 l m Z d d
 l m Z y d d l Z Wn! e k
 ré d d l m Z n XyD d d l m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" WnQ e k
 rd d l# m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" n Xy d d l$ Z$ Wn  e k
 r´d d l% j& Z$ n Xd „  Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ d „  Z0 d „  Z1 d „  Z2 y d d l3 m4 Z5 Wn e k
 rNd Z5 n Xy d d l7 m8 Z8 Wn e k
 r|d Z8 n Xy d d l9 Z9 d d l: Z: Wn# e e; f k
 r¾d Z9 d Z: n Xy d d l< Z< Wn e k
 rèd Z< n Xy d d l= Z= Wn e k
 rd Z= n Xy d d l> Z> Wn e k
 r<d Z> n Xd Z? y" d e j@ k rdd d l? Z? n  Wn e k
 rxn Xd e jA k rže jA d g e _A n  ya d d lB ZB eB jC d k rËd ZD d ZE n* eB jC d  k  réd! ZD d ZE n d" ZD d# ZE d$ „  ZF Wn e k
 rd ZF n Xe jG r7d1 ZH d2 ZI d3 ZJ n d4 ZH d5 ZI d6 ZJ y d d- lK mL ZL Wn e k
 rvd ZL n Xd. „  ZM d d d/ „ ZN d0 „  ZO d S(7   u   
The `compat` module provides support for backwards compatibility with older
versions of Django/Python, and compatibility wrappers around optional packages.
iÿÿÿÿ(   t   unicode_literalsN(   t   apps(   t   settings(   t   ImproperlyConfigured(   t
   connectiont   modelst   transaction(   t   Contextt   RequestContextt   Template(   t   six(   t   View(   t	   importlib(	   t   NoReverseMatcht   RegexURLPatternt   RegexURLResolvert   ResolverMatcht   Resolver404t   get_script_prefixt   reverset   reverse_lazyt   resolvec         C  s&   t  j r t |  ƒ j d ƒ St |  ƒ S(   Nu   utf-8(   R
   t   PY2t   reprt   decode(   t   instance(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   unicode_repr*   s    	c         C  s   t  j r |  j d ƒ S|  S(   Nu   utf-8(   R
   R   t   encode(   t   value(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   unicode_to_repr2   s    	c         C  s#   t  |  t j ƒ r |  j d ƒ S|  S(   Nu
   iso-8859-1(   t
   isinstanceR
   t   binary_typeR   (   R   (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   unicode_http_header;   s    c         C  s@   t  |  d ƒ r |  j ƒ  S|  j d t |  j ƒ |  j d Sd  S(   Nu   total_secondsg     õ@g    €„.A(   t   hasattrt   total_secondst   dayst   floatt   secondst   microseconds(   t	   timedelta(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyR"   B   s    
c         C  sI   t  j |  j d d k r? | j d t |  j d d t ƒƒ ƒ S|  j ƒ  S(   Nu   ENGINEu   django.db.backends.oraclet   pk__inu   pkt   flat(   R   t	   DATABASESt   dbt   filtert   sett   values_listt   Truet   distinct(   t   querysett   base(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyR0   J   s    %c         C  sa   t  j d k r2 g  |  j D] } | j | f ^ q Sg  |  j |  j D] } | d | d f ^ qC S(   Ni   i
   i   (   i   i
   (   t   djangot   VERSIONt   managerst   namet   concrete_managerst   abstract_managers(   t   optionst   managert   manager_info(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   get_names_and_managersR   s
     c         K  s`   d | k rC t  j d k  r/ t |  d | d ƒ St |  d | d ƒ St  j d k  rY |  j S|  j S(   Nu   defaulti   i	   u   relu   remote_field(   i   i	   (   i   i	   (   R3   R4   t   getattrt   relt   remote_field(   t   fieldt   kwargs(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   get_remote_fieldd   s    c         C  sÃ   t  |  t j ƒ r… t |  j d ƒ ƒ d k r… |  j d ƒ \ } } t j | | ƒ } | d k r d } t | j	 | | ƒ ƒ ‚ n  | St
 j |  ƒ rª t |  t j ƒ rª |  St d j	 |  ƒ ƒ ‚ d S(   u~  
    Resolve supplied `obj` to a Django model class.

    `obj` must be a Django model class itself, or a string
    representation of one.  Useful in situations like GH #1225 where
    Django may not have resolved a string-based reference to a model in
    another model's foreign key definition.

    String representations should have the format:
        'appname.ModelName'
    u   .i   u)   Django did not return a model for {0}.{1}u   {0} is not a Django modelN(   R   R
   t   string_typest   lent   splitR   t	   get_modelt   NoneR   t   formatt   inspectt   isclasst
   issubclassR   t   Modelt
   ValueError(   t   objt   app_namet
   model_namet   resolved_modelt   msg(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   _resolve_modelo   s    -!c         C  s    t  j d k  r |  j ƒ  S|  j S(   Ni   i
   (   i   i
   (   R3   R4   t   is_authenticated(   t   user(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyRT   ‡   s    
c         C  s    t  j d k  r |  j ƒ  S|  j S(   Ni   i
   (   i   i
   (   R3   R4   t   is_anonymous(   RU   (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyRV      s    
c         C  s)   t  j d k  r t |  j j ƒ S|  j j S(   Ni   i	   (   i   i	   (   R3   R4   RS   R>   t   toR?   t   model(   R@   (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   get_related_model“   s    c         C  s)   t  j d k  r |  j | ƒ S|  j | ƒ S(   Ni   i	   (   i   i	   (   R3   R4   t   _get_val_from_objt   value_from_object(   R@   RN   (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyR[   ™   s    (   t   fields(   t	   JSONFieldu   guardianu   patchu   2.2u   headeridu   levelu   2.6u   markdown.extensions.headeridu   markdown.extensions.tocu	   baselevelc         C  sB   t  g } i i d t 6t  6} t j d | d | ƒ } | j |  ƒ S(   u}   
        Simple wrapper around :func:`markdown.markdown` to set the base level
        of '#' style headers to <h2>.
        u   2t
   extensionst   extension_configs(   t   HEADERID_EXT_PATHt   LEVEL_PARAMt   markdownt   Markdownt   convert(   t   textR^   R_   t   md(    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   apply_markdowné   s    		u   ,u   :u   , u   : t   ,t   :s   , s   : (   t   DecimalValidatorc           C  sy   t  t d ƒ rC t j j d t ƒ ru t j r@ t j t ƒ q@ qu n2 t j	 ƒ  ru t j
 ƒ  rh t j ƒ  n  t j ƒ  n  d  S(   Nu   set_rollbacku   ATOMIC_REQUESTS(   R!   R   R   t   settings_dictt   gett   Falset   in_atomic_blockt   set_rollbackR/   t
   is_managedt   is_dirtyt   rollbackt   leave_transaction_management(    (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyRo     s    	c         C  sW   t  |  t ƒ r@ | r' t | | ƒ } n t | ƒ } |  j | ƒ S|  j | d | ƒSd S(   u  
    Passing Context or RequestContext to Template.render is deprecated in 1.9+,
    see https://github.com/django/django/pull/3883 and
    https://github.com/django/django/blob/1.9/django/template/backends/django.py#L82-L84

    :param template: Template instance
    :param context: dict
    :param request: Request instance
    :return: rendered template as SafeText instance
    t   requestN(   R   R	   R   R   t   render(   t   templatet   contextRt   (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   template_render  s    c         C  sB   t  j d k  r" t |  | | ƒ n t |  | ƒ } | j | ƒ d  S(   Ni   i
   (   i   i
   (   R3   R4   t   setattrR=   R-   (   R   R@   R   (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   set_many5  s    (   u   ,u   :(   u   , u   : (   u   ,u   : (   Rh   Ri   (   s   , s   : (   Rh   s   : (P   t   __doc__t
   __future__R    RI   R3   t   django.appsR   t   django.confR   t   django.core.exceptionsR   t	   django.dbR   R   R   t   django.templateR   R   R	   t   django.utilsR
   t   django.views.genericR   R   t   ImportErrort   django.urlsR   R   R   R   R   R   R   R   R   t   django.core.urlresolverst   urlparset   urllib.parset   parseR   R   R    R"   R0   R<   RB   RS   RT   RV   RY   R[   t   django.contrib.postgresR\   t   postgres_fieldsRG   t   django.contrib.postgres.fieldsR]   t   coreapit   uritemplatet   SyntaxErrort   django_filterst   crispy_formst   requestst   guardiant   INSTALLED_APPSt   http_method_namesRb   t   versionR`   Ra   Rg   t   PY3t   SHORT_SEPARATORSt   LONG_SEPARATORSt   INDENT_SEPARATORSt   django.core.validatorsRj   Ro   Rx   Rz   (    (    (    s7   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/compat.pyt   <module>   s¾   DD													





		
		
	