
^Q\H
                 @   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 Z d  d l	 m
 Z
 d d   Z d d d  Z Gd	 d
   d
  Z d  d l m Z e Z e j r e Z n  d S)    )unicode_literals)BytesION)settingsc             C   s   t  j d k  rU d d l m } m } y | |   } | SWq | k
 rQ d SYq Xnf d d l m } d d l m } y' |   |  } t j	 |  j
 } | SWn | t f k
 r d SYn Xd S)	zkLoad a templatetag library on multiple Django versions.

    Returns None if the library isn't loaded.
       	   r   )get_libraryInvalidTemplateLibraryN)get_installed_libraries)r   )r   r   )djangoVERSIONZdjango.template.baser   r   Zdjango.template.backends.djangor	   Zdjango.template.library	importlibimport_moduleregisterKeyError)libnamer   r   libr	    r   I/var/www/dbchiro/venv/build/django-extensions/django_extensions/compat.pyload_tag_library   s    r   c             C   sj   t  t d d  } | d k	 r: |  | d k r: | d |  S|  d k rf d |  } t  t | |  } | S| S)z0 Read template settings pre and post django 1.8 Z	TEMPLATESNr   ZDIRSzTEMPLATES_%s)getattrr   )Ztemplate_keydefaultZtemplates_varZpre18_template_keyvaluer   r   r   get_template_setting)   s    
r   c               @   sC   e  Z d  Z d Z e j d d d  Z d d   Z d d   Z d	 S)
UnicodeWriterz
    A 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
    zutf-8c             K   sL   t    |  _ t j |  j d | | |  _ | |  _ t j |    |  _ d  S)Ndialect)r   queuecsvwriterstreamcodecsgetincrementalencoderencoder)selffr   encodingkwdsr   r   r   __init__;   s    	zUnicodeWriter.__init__c             C   sq   |  j  j d d   | D  |  j j   } | j d  } |  j j |  } |  j j |  |  j j	 d  d  S)Nc             S   s   g  |  ] } | j  d    q S)zutf-8)encode).0sr   r   r   
<listcomp>B   s   	 z*UnicodeWriter.writerow.<locals>.<listcomp>zutf-8r   )
r   writerowr   getvaluedecoder!   r'   r   writetruncate)r"   rowdatar   r   r   r+   A   s    zUnicodeWriter.writerowc             C   s"   x | D] } |  j  |  q Wd  S)N)r+   )r"   rowsr0   r   r   r   	writerowsM   s    zUnicodeWriter.writerowsN)	__name__
__module____qualname____doc__r   excelr&   r+   r3   r   r   r   r   r   5   s   r   )r   )
__future__r   ior   r   sixr   r   r
   Zdjango.confr   r   r   r   r   Z
csv_writerPY2r   r   r   r   <module>   s   	