ó
Ñs/Uc           @   s°   d  Z  d Z e e d d „  ƒ d ƒ Z d Z d Z d Z d d	 g Z d
 d l Z e	 e	 d „ Z
 e
 ƒ  Z d „  Z e d k r¬ d
 d l Z e j j e e j j ƒ  ƒ ƒ n  d S(   sÁ  
=====================
 Javascript Minifier
=====================

Javascript Minifier based on `jsmin.c by Douglas Crockford`_\.

This module is a re-implementation based on the semantics of jsmin.c. Usually
it produces the same results. It differs in the following ways:

- there is no error detection: unterminated string, regex and comment
  literals are treated as regular javascript code and minified as such.
- Control characters inside string and regex literals are left untouched; they
  are not converted to spaces (nor to \n)
- Newline characters are not allowed inside string and regex literals, except
  for line continuations in string literals (ECMA-5).
- "return /regex/" is recognized correctly.
- rjsmin does not handle streams, but only complete strings. (However, the
  module provides a "streamy" interface).

Besides the list above it differs from direct python ports of jsmin.c in
speed. Since most parts of the logic are handled by the regex engine it's way
faster than the original python port by Baruch Even. The speed factor varies
between about 6 and 55 depending on input and python version (it gets faster
the more compressed the input already is). Compared to the speed-refactored
python port by Dave St.Germain the performance gain is less dramatic but still
between 1.2 and 7. See the docs/BENCHMARKS file for details.

rjsmin.c is a reimplementation of rjsmin.py in C and speeds it up even more.

Both python 2 and python 3 are supported.

.. _jsmin.c by Douglas Crockford:
   http://www.crockford.com/javascript/jsmin.c

Original author of Python version: Andr\xe9 Malo
Home page: http://opensource.perlig.de/rjsmin/
Modified by Ross Peoples <ross.peoples@gmail.com> for inclusion into web2py.
s
   André Malot   decodec         C   s   t  S(   N(   t
   __author__(   t   x(    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   <lambda>:   s    s   latin-1s   restructuredtext ens   Apache License, Version 2.0s   1.0.2t   jsmint   jsmin_for_posersiÿÿÿÿNc            s?  | s4 y d d l  } Wn t k
 r) q4 X| j Sn  y ˆ
 Wn t k
 rU t ‰
 n Xd } d } d } d } d } d | | f } d	 }	 d
 }
 |  r¬ d |
 |	 |
 f } n d } | |	 |
 |	 |
 f } d | | f } d | } d „  ‰  ‡  ‡
 f d †  ‰ ‡  ‡ ‡
 f d †  } | d ƒ } d } d t ƒ  } |  r’ˆ d ƒ } ˆ d ƒ } ˆ d ƒ } t j d t ƒ  ƒ j ‰ d „  ‰ ‡ ‡ f d †  } n© d t ƒ  } | d ƒ } | d ƒ } t j d t ƒ  ƒ j ‰ d „  ‰ t j d t ƒ  ƒ j ‰ d „  ‰ t j d t ƒ  ƒ j ‰ d „  ‰	 ‡ ‡ ‡ ‡ ‡ ‡	 f d  †  } | S(!   s²  
    Generate JS minifier based on `jsmin.c by Douglas Crockford`_

    .. _jsmin.c by Douglas Crockford:
       http://www.crockford.com/javascript/jsmin.c

    :Parameters:
      `extended` : ``bool``
        Extended Regexps? (using lookahead and lookbehind). This is faster,
        because it can be optimized way more. The regexps used with `extended`
        being false are only left here to allow easier porting to platforms
        without extended regex features (and for my own reference...)

      `python_only` : ``bool``
        Use only the python variant. If true, the c extension is not even
        tried to be loaded.

    :Return: Minifier
    :Rtype: ``callable``
    iÿÿÿÿNs   [\000-\011\013\014\016-\040]s   (?://[^\r\n]*)s"   (?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)sC   (?:\047[^\047\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^\047\\\r\n]*)*\047)s7   (?:"[^"\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^"\\\r\n]*)*")s	   (?:%s|%s)s.   (?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\])s   [^/\\\[\r\n]s-   (?:/(?![\r\n/*])%s*(?:(?:\\[^\r\n]|%s)%s*)*/)s?   (?:/(?:[^*/\\\r\n\[]|%s|\\[^\r\n])%s*(?:(?:\\[^\r\n]|%s)%s*)*/)s   (?:%s?[\r\n])c         S   sƒ   |  j  d ƒ } | d k r: d |  |  |  | d f }  n  d „  } t j d d „  | |  ƒ j d d	 ƒ j d
 d ƒ j d d ƒ ƒ S(   s6    Fixup string of chars to fit into a regex char class s   -i    s   %s%s-i   c         S   s  d d g  } } } xf t t |  ƒ D]U } | d k rC | } } q$ | d | k r\ | } q$ | j | | f ƒ | } } q$ W| d k	 rŸ | j | | f ƒ n  d j g  | D]S \ } } d t | ƒ | | d k rÚ d pÝ d | | k rõ t | ƒ pø d f ^ q¬ ƒ S(   sf   
            Notate consecutive characters as sequence

            (1-4 instead of 1234)
            i   t    s   %s%s%ss   -N(   t   Nonet   mapt   ordt   appendt   joint   chr(   t   stringt   firstt   lastt   resultt   char(    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt
   sequentizeƒ   s    		s   ([\000-\040\047])c         S   s   d t  |  j d ƒ ƒ S(   Ns   \%03oi   (   R	   t   group(   t   m(    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyR   ›   s    s   \s   \\s   [s   \[s   ]s   \](   t   findt   _ret   subt   replace(   R   t   posR   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   fix_charclass}   s    		c            s`   t  j |  ƒ j } d j g  ˆ d ƒ D]$ } | t | ƒ ƒ s% t | ƒ ^ q% ƒ } d ˆ  | ƒ S(   s!    Make id_literal like char class R   i   s   [^%s](   R   t   compilet   matchR   R   (   t   whatR   t   cR   (   R   t   xrange(    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   id_literal_¢   s    :c            sf   t  j ˆ |  ƒ ƒ j } d j g  ˆ d ƒ D]$ } | t | ƒ ƒ s+ t | ƒ ^ q+ ƒ } d ˆ  | ƒ S(   s)    Make negated id_literal like char class R   i   s   [%s](   R   R   R   R   R   (   t   keepR   R   R   (   R   R    R   (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   not_id_literal_ª   s    :s   [a-zA-Z0-9_$]s   [(,=:\[!&|?{};\r\n]s   %(not_id_literal)sreturns   [a-zA-Z0-9_${\[(+-]s   [a-zA-Z0-9_$}\])"\047+-]sc  ([^\047"/\000-\040]+)|(%(strings)s[^\047"/\000-\040]*)|(?:(?<=%(preregex1)s)%(space)s*(%(regex)s[^\047"/\000-\040]*))|(?:(?<=%(preregex2)s)%(space)s*(%(regex)s[^\047"/\000-\040]*))|(?<=%(id_literal_close)s)%(space)s*(?:(%(newline)s)%(space)s*)+(?=%(id_literal_open)s)|(?<=%(id_literal)s)(%(space)s)+(?=%(id_literal)s)|%(space)s+|(?:%(newline)s%(space)s*)+c         S   sx   |  j  ƒ  } | d r | d S| d r0 | d S| d rB | d S| d rT | d S| d rb d S| d rp d Sd	 Sd
 S(   s    Substitution callback i    i   i   i   i   s   
i   s    R   N(   t   groups(   R   R#   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   space_subberÈ   s    





c            s   ˆ  ˆ d |  ƒ j  ƒ  S(   s  
            Minify javascript based on `jsmin.c by Douglas Crockford`_\.

            Instead of parsing the stream char by char, it uses a regular
            expression approach which minifies the whole script with one big
            substitution regex.

            .. _jsmin.c by Douglas Crockford:
               http://www.crockford.com/javascript/jsmin.c

            :Parameters:
              `script` : ``str``
                Script to minify

            :Return: Minified script
            :Rtype: ``str``
            s   
%s
(   t   strip(   t   script(   t	   space_subR$   (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyR   Û   s    s   (?:%(preregex1)s|%(preregex2)s)s`   (%(strings)s)|(?:(%(pre_regex)s)%(space)s*(%(regex)s))|(%(space)s)+|(?:(%(newline)s)%(space)s*)+c         S   sd   |  j  ƒ  } | d r | d S| d rD | d j d d ƒ | d S| d rR d S| d r` d Sd	 S(
   s    Substitution callback i    i   s   s   
i   i   s    i   N(   R#   R   (   R   R#   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   space_norm_subberû   s    



sb   [\040\n]?(%(strings)s|%(pre_regex)s%(regex)s)|\040(%(not_id_literal)s)|\n(%(not_id_literal_open)s)c         S   s(   |  j  ƒ  } | d p' | d p' | d S(   s    Substitution callback i    i   i   (   R#   (   R   R#   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   space_subber1  s    sj   (%(strings)s)\040?|(%(pre_regex)s%(regex)s)[\040\n]?|(%(not_id_literal)s)\040|(%(not_id_literal_close)s)\nc         S   s2   |  j  ƒ  } | d p1 | d p1 | d p1 | d S(   s    Substitution callback i    i   i   i   (   R#   (   R   R#   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   space_subber2  s    c            s)   ˆ ˆ ˆ ˆ ˆ  ˆ d |  ƒ ƒ ƒ j  ƒ  S(   s;  
            Minify javascript based on `jsmin.c by Douglas Crockford`_\.

            Instead of parsing the stream char by char, it uses a regular
            expression approach. The script is minified with three passes:

            normalization
                Control character are mapped to spaces, spaces and newlines
                are squeezed and comments are stripped.
            space removal 1
                Spaces before certain tokens are removed
            space removal 2
                Spaces after certain tokens are remove

            .. _jsmin.c by Douglas Crockford:
               http://www.crockford.com/javascript/jsmin.c

            :Parameters:
              `script` : ``str``
                Script to minify

            :Return: Minified script
            :Rtype: ``str``
            s   
%s
(   R%   (   R&   (   t   space_norm_subR(   t
   space_sub1t
   space_sub2R)   R*   (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyR     s    (	   t   _rjsmint   ImportErrorR   t	   NameErrort   ranget   localsR   R   R   (   t   extendedt   python_onlyR.   t   space_charst   line_commentt   space_commentt   string1t   string2t   stringst	   charclasst	   nospecialt   regext   spacet   newlineR"   t   not_id_literalt	   preregex1t	   preregex2t
   id_literalt   id_literal_opent   id_literal_closeR   t	   pre_regext   not_id_literal_opent   not_id_literal_close(    (   R   R    R+   R(   R'   R,   R-   R$   R)   R*   R   sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   _make_jsminC   sr    


	%
				c         C   s&   d „  } t  j d | d |  ƒ j ƒ  S(   sŽ  
    Minify javascript based on `jsmin.c by Douglas Crockford`_\.

    Instead of parsing the stream char by char, it uses a regular
    expression approach which minifies the whole script with one big
    substitution regex.

    .. _jsmin.c by Douglas Crockford:
       http://www.crockford.com/javascript/jsmin.c

    :Warning: This function is the digest of a _make_jsmin() call. It just
              utilizes the resulting regex. It's just for fun here and may
              vanish any time. Use the `jsmin` function instead.

    :Parameters:
      `script` : ``str``
        Script to minify

    :Return: Minified script
    :Rtype: ``str``
    c      	   S   sX   |  j  ƒ  } | d pW | d pW | d pW | d pW | d rD d pW | d rT d pW d	 S(
   s    Substitution callback i    i   i   i   i   s   
i   s    R   (   R#   (   R   R#   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   subbera  s    



s–  ([^\047"/\000-\040]+)|((?:(?:\047[^\047\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^\047\\\r\n]*)*\047)|(?:"[^"\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^"\\\r\n]*)*"))[^\047"/\000-\040]*)|(?:(?<=[(,=:\[!&|?{};\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*((?:/(?![\r\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/)[^\047"/\000-\040]*))|(?:(?<=[\000-#%-,./:-@\[-^`{-~-]return)(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*((?:/(?![\r\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/)[^\047"/\000-\040]*))|(?<=[^\000-!#%&(*,./:-@\[\\^`{|~])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:((?:(?://[^\r\n]*)?[\r\n]))(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000-#%-\047)*,./:-@\\-^`|-~])|(?<=[^\000-#%-,./:-@\[-^`{-~-])((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=[^\000-#%-,./:-@\[-^`{-~-])|(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))+|(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+s   
%s
(   R   R   R%   (   R&   RJ   (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyR   K  s    	t   __main__(   t   __doc__R   t   getattrt   __docformat__t   __license__t   __version__t   __all__t   reR   t   TrueRI   R   R   t   __name__t   syst   _syst   stdoutt   writet   stdint   read(    (    (    sD   /var/www/c4bv.valis/web2py-ge-R-2.10.3/gluon/contrib/minify/jsmin.pyt   <module>8   s   ý		: