<s> """<STR_LIT>""" <EOL> from datetime import datetime <EOL> import os <EOL> import re <EOL> import json <EOL> from django . conf import settings <EOL> from django . core . cache import cache <EOL> from django . http import HttpResponse <EOL> from django . template import RequestContext <EOL> from django . template . loader import render_to_string <EOL> from django . utils . text import compress_string <EOL> from django . utils . cache import patch_vary_headers , patch_response_headers <EOL> from django . utils . encoding import smart_text <EOL> import tinymce . settings <EOL> safe_filename_re = re . compile ( '<STR_LIT>' ) <EOL> def get_file_contents ( filename ) : <EOL> if '<STR_LIT>' in settings . INSTALLED_APPS or '<STR_LIT>' in settings . INSTALLED_APPS : <EOL> from django . contrib . staticfiles import finders <EOL> file_path = finders . find ( os . path . join ( '<STR_LIT>' , filename ) ) <EOL> else : <EOL> file_path = os . path . join ( tinymce . settings . JS_ROOT , filename ) <EOL> try : <EOL> f = open ( file_path ) <EOL> try : <EOL> return f . read ( ) <EOL> finally : <EOL> f . close ( ) <EOL> except ( IOError , TypeError ) : <EOL> return '<STR_LIT>' <EOL> def split_commas ( str ) : <EOL> if str == '<STR_LIT>' : <EOL> return [ ] <EOL> return str . split ( '<STR_LIT:U+002C>' ) <EOL> def gzip_compressor ( request ) : <EOL> plugins = split_commas ( request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> languages = split_commas ( request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> themes = split_commas ( request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> isJS = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT:true>' <EOL> compress = request . GET . get ( '<STR_LIT>' , '<STR_LIT:true>' ) == '<STR_LIT:true>' <EOL> suffix = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT>' and '<STR_LIT>' or '<STR_LIT>' <EOL> content = [ ] <EOL> response = HttpResponse ( ) <EOL> response [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> if not isJS : <EOL> response . write ( render_to_string ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : tinymce . settings . JS_BASE_URL , <EOL> } , context_instance = RequestContext ( request ) ) ) <EOL> return response <EOL> patch_vary_headers ( response , [ '<STR_LIT>' ] ) <EOL> now = datetime . utcnow ( ) <EOL> response [ '<STR_LIT>' ] = now . strftime ( '<STR_LIT>' ) <EOL> cacheKey = '<STR_LIT:|>' . join ( plugins + languages + themes ) <EOL> cacheData = cache . get ( cacheKey ) <EOL> if cacheData is not None : <EOL> if '<STR_LIT>' in cacheData : <EOL> if_none_match = request . META . get ( '<STR_LIT>' ) <EOL> if if_none_match == cacheData [ '<STR_LIT>' ] : <EOL> response . status_code = <NUM_LIT> <EOL> response . content = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = '<STR_LIT:0>' <EOL> return response <EOL> if '<STR_LIT>' in cacheData : <EOL> if_modified_since = request . META . get ( '<STR_LIT>' ) <EOL> if if_modified_since == cacheData [ '<STR_LIT>' ] : <EOL> response . status_code = <NUM_LIT> <EOL> response . content = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = '<STR_LIT:0>' <EOL> return response <EOL> tinyMCEPreInit = { <EOL> '<STR_LIT>' : tinymce . settings . JS_BASE_URL , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> content . append ( '<STR_LIT>' . format ( <EOL> json . dumps ( tinyMCEPreInit ) <EOL> ) ) <EOL> files = [ '<STR_LIT>' ] <EOL> for lang in languages : <EOL> files . append ( '<STR_LIT>' . format ( lang ) ) <EOL> for plugin in plugins : <EOL> files . append ( '<STR_LIT>' . format ( plugin , suffix ) ) <EOL> for lang in languages : <EOL> files . append ( '<STR_LIT>' . format ( plugin , lang ) ) <EOL> for theme in themes : <EOL> files . append ( '<STR_LIT>' . format ( theme , suffix ) ) <EOL> for lang in languages : <EOL> files . append ( '<STR_LIT>' . format ( theme , lang ) ) <EOL> for f in files : <EOL> if not safe_filename_re . match ( f ) : <EOL> continue <EOL> content . append ( get_file_contents ( '<STR_LIT>' . format ( f ) ) ) <EOL> content . append ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( '<STR_LIT:U+002C>' . join ( files ) ) ) <EOL> unicode_content = [ ] <EOL> for i , c in enumerate ( content ) : <EOL> try : <EOL> unicode_content . append ( c . decode ( '<STR_LIT>' ) ) <EOL> except AttributeError : <EOL> unicode_content . append ( smart_text ( c ) ) <EOL> except UnicodeDecodeError : <EOL> try : <EOL> unicode_content . append ( c . decode ( '<STR_LIT:utf-8>' ) ) <EOL> except : <EOL> print ( '<STR_LIT>' . format ( files [ i ] ) ) <EOL> raise <EOL> if compress : <EOL> content = compress_string ( b'<STR_LIT>' . join ( [ c . encode ( '<STR_LIT:utf-8>' ) <EOL> for c in unicode_content ] ) ) <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = str ( len ( content ) ) <EOL> response . write ( content ) <EOL> timeout = <NUM_LIT> * <NUM_LIT> * <NUM_LIT:10> <EOL> patch_response_headers ( response , timeout ) <EOL> cache . set ( cacheKey , { <EOL> '<STR_LIT>' : response [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : response . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } ) <EOL> return response </s>
