ó
pÁìVc           @@ s  d  d l  m Z m Z d  d l 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 d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z e j d ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i    (   t   absolute_importt   unicode_literalsN(   t   ImproperlyConfigured(   t   NamedTemporaryFile(   t   import_module(   t
   smart_text(   t   six(   t   settings(   t   FilterError(   t   get_mod_funcu   compressor.filterst
   FilterBasec           B@ s5   e  Z d  Z d d d d d „ Z d „  Z d „  Z RS(   uÎ   
    A base class for filters that does nothing.

    Subclasses should implement `input` and/or `output` methods which must
    return a string (unicode under python 2) or raise a NotImplementedError.
    i    c         C@ sC   | |  _  | |  _ | p t j |  _ t |  _ | |  _ | |  _ d  S(   N(   t   typet   contentR   t   COMPRESS_VERBOSEt   verboset   loggert   filenamet   charset(   t   selfR   t   filter_typeR   R   R   (    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyt   __init__   s    				c         K@ s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   t   kwargs(    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyt   input$   s    c         K@ s
   t  ‚ d  S(   N(   R   (   R   R   (    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyt   output'   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R   R   (    (    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR
      s
   		t   CallbackOutputFilterc           B@ s8   e  Z d  Z d Z g  Z i  Z g  Z d „  Z d „  Z	 RS(   u^  
    A filter which takes function path in `callback` attribute, imports it
    and uses that function to filter output string::

        class MyFilter(CallbackOutputFilter):
            callback = 'path.to.my.callback'

    Callback should be a function which takes a string as first argument and
    returns a string (unicode under python 2).
    c   	      O@ s5  t  t |  ƒ j | | Ž  |  j d  k rA t d |  j j ƒ ‚ n  y. t |  j ƒ \ } } t	 t
 | ƒ | ƒ } Wn¶ t k
 rÿ |  j rÝ t |  j ƒ d k r± d |  j d } qã d d j g  |  j D] } | ^ qÄ ƒ } n d } t d |  j | f ƒ ‚ n2 t k
 r'} t d	 |  | f ƒ ‚ n
 X| |  _ d  S(
   Nu:   The callback filter %s must define a 'callback' attribute.i   u   dependency (%s) isi    u   dependencies (%s) areu   , u    uK   The callback %s couldn't be imported. Make sure the %s correctly installed.u<   An error occurred while importing the callback filter %s: %s(   t   superR   R   t   callbackR   R   t	   __class__R   R	   t   getattrR   t   ImportErrort   dependenciest   lent   joint   AttributeErrort   _callback_func(	   R   t   argsR   t   mod_namet	   func_namet   funct   warningt   dept   e(    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR   ;   s,    	)c         K@ s:   |  j  |  j |  j |  j Ž } t | t j ƒ s6 t ‚ | S(   N(   R'   R   R(   R   t
   isinstanceR   t	   text_typet   AssertionError(   R   R   t   ret(    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR   V   s    N(
   R   R   R   R   R   R(   R   R#   R   R   (    (    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR   +   s   
	t   CompilerFilterc           B@ s8   e  Z d  Z d Z d Z e j Z d d „ Z	 d „  Z
 RS(   uU   
    A filter subclass that is able to filter content via
    external commands.
    c         O@ sô   t  t |  ƒ j | | | Ž d  |  _ | r7 | |  _ n  |  j d  k rU t d ƒ ‚ n  t |  j t	 ƒ r d } x! | j
 ƒ  D] } | | f 7} qz W| |  _ n  x& | j
 ƒ  D] } |  j | f 7_ qª Wt j |  _ |  _ |  _ d  |  _ |  _ d  S(   Nu&   Required attribute 'command' not given(    (   R   R3   R   R   t   cwdt   commandR   R/   t   optionst   dictt   itemst
   subprocesst   PIPEt   stdoutt   stdint   stderrt   infilet   outfile(   R   R   R5   R(   R   t   new_optionst   item(    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR   e   s    	c         K@ s  |  j  } t |  j ƒ } |  j d  k r¾ d |  j k r¾ |  j d  k r“ t d d ƒ |  _ |  j j |  j	 j
 | ƒ ƒ |  j j ƒ  |  j j | d <q¾ |  j } t |  j ƒ |  _ |  j | d <n  d |  j k r d | k r |  j rï d |  j pò d } t d d	 d
 | ƒ |  _ |  j j | d <n  z°y³ |  j j |   } t j | d t d |  j d |  j d |  j d |  j ƒ} |  j d  k r¤| j |  j	 j
 | ƒ ƒ \ } } n | j ƒ  \ } } | j | ƒ | j | ƒ } } Wn; t t f k
 r}	 t d |  j j |  j |	 f ƒ ‚ n¼ X| j  ƒ  d k rn| s_d |  j j |  j f } | r_| d | 7} q_n  t | ƒ ‚ n  |  j! rŠ|  j" j# | ƒ n  | j$ d ƒ }
 |
 rÏt% j |
 d d | ƒ } | j& ƒ  } Wd  QXn  Wd  |  j d  k	 rò|  j j' ƒ  n  |  j d  k	 r|  j j' ƒ  n  Xt( | ƒ S(   Nu   {infile}t   modeu   wbu   infileu	   {outfile}u   outfileu   .%su    u   r+t   suffixt   shellR4   R;   R<   R=   u   Unable to apply %s (%r): %si    u   Unable to apply %s (%s)u   
%su   rt   encoding()   t   default_encodingR7   R6   R>   R   R5   R   R   t   writeR   t   encodet   flusht   nameR   t   openR   R?   t   formatR9   t   Popent   TrueR4   R;   R<   R=   t   communicatet   decodet   IOErrort   OSErrorR   R    R   t   waitR   R   t   debugt   gett   iot   readt   closeR   (   R   R   RE   R6   t   extR5   t   proct   filteredt   errR.   t   outfile_patht   file(    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR   |   s^    		 # 	N(    (   R   R   R   R   R5   R6   R   t   FILE_CHARSETRF   R   R   (    (    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyR3   \   s   	(   t
   __future__R    R   RV   t   loggingR9   t   django.core.exceptionsR   t   django.core.files.tempR   t   django.utils.importlibR   t   django.utils.encodingR   t   django.utilsR   t   compressor.confR   t   compressor.exceptionsR   t   compressor.utilsR	   t	   getLoggerR   t   objectR
   R   R3   (    (    (    sm   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/django_compressor-1.4-py2.7.egg/compressor/filters/base.pyt   <module>   s   1