ó
¸9^c           @  s´   d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 d   Z
 d d  Z d d
 d     YZ d  d	 l m Z e Z e j r° e Z n  d S(   i˙˙˙˙(   t   unicode_literals(   t   BytesION(   t   settingsc         C  sf   d d l  m } d d l m } y' |   |  } t j |  j } | SWn | t f k
 ra d SXd S(   up   
    Load a templatetag library on multiple Django versions.

    Returns None if the library isn't loaded.
    i˙˙˙˙(   t   get_installed_libraries(   t   InvalidTemplateLibraryN(	   t   django.template.backends.djangoR   t   django.template.libraryR   t	   importlibt   import_modulet   registert   KeyErrort   None(   t   libnameR   R   t   lib(    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyt   load_tag_library   s    c         C  sD   t  t d d  } | r@ x% | D] } |  | k r | |  Sq Wn  | S(   u    Read template settings u	   TEMPLATESN(   t   getattrR   R   (   t   template_keyt   defaultt   templates_vart   tdict(    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyt   get_template_setting!   s    t   UnicodeWriterc           B  s2   e  Z d  Z e j d d  Z d   Z d   Z RS(   uŞ   
    CSV writer which will write rows to CSV file "f",
    which is encoded in the given encoding.
    We are using this custom UnicodeWriter for python versions 2.x
    u   utf-8c         K  sL   t    |  _ t j |  j d | | |  _ | |  _ t j |    |  _ d  S(   Nt   dialect(   R   t   queuet   csvt   writert   streamt   codecst   getincrementalencodert   encoder(   t   selft   fR   t   encodingt   kwds(    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyt   __init__2   s    	c         C  s   |  j  j g  | D] } | j d  ^ q  |  j j   } | j d  } |  j j |  } |  j j |  |  j j	 d  d  S(   Nu   utf-8i    (
   R   t   writerowt   encodeR   t   getvaluet   decodeR   R   t   writet   truncate(   R   t   rowt   st   data(    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyR#   8   s    ,c         C  s"   x | D] } |  j  |  q Wd  S(   N(   R#   (   R   t   rowsR)   (    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyt	   writerowsD   s    (   t   __name__t
   __module__t   __doc__R   t   excelR"   R#   R-   (    (    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyR   +   s   	(   R   (    (   t
   __future__R    t   ioR   R   t   sixR   R   t   django.confR   R   R   R   R   R   t
   csv_writert   PY2(    (    (    s:   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/compat.pyt   <module>   s   	
	