# Path: turbulenz_local/tools.py
# def compress_file(file_path, compress_path):
#     seven_zip = get_7zip_path()
#     if seven_zip:
#         process = Popen([seven_zip,
#                          'a', '-tgzip',
#                          #'-mx=9', '-mfb=257', '-mpass=15',
#                          compress_path, file_path],
#                         stdout=PIPE, stderr=PIPE)
#         output, _ = process.communicate()
#         retcode = process.poll()
#         if retcode:
#             LOG.error('Failed to compress file "%s" as "%s": %s', file_path, compress_path, str(output))
#             return False
#         else:
#             return True
#     else:
#         cache_dir = dirname(compress_path)
#         if not isdir(cache_dir):
#             os.makedirs(cache_dir)
#         try:
#             with GzipFile(compress_path, mode='wb', compresslevel=9) as gzipfile:
#                 with open(file_path, 'rb') as f:
#                     gzipfile.write(f.read())
#         except IOError as e:
#             LOG.error(str(e))
#             return False
#         LOG.warning('Using Python for GZip compression, install 7zip for optimal performance')
#         return True


import io
import gzip
import logging
import mimetypes
import os
from os.path import join, normpath
from paste.deploy.converters import asint, aslist
from turbulenz_local.tools import compress_file
def _get_file_stats(file_name):
    try:
        file_stat = os.stat(file_name)
        return file_stat.st_mtime, file_stat.st_size
    except OSError:
        return -1, 0


class GzipFileIter(object):
    __slots__ = ('file')

    def __init__(self, f):
        self.file = f

    def __iter__(self):
        return self

    def next(self):
        data = self.file.read(65536)
        if not data:
            raise StopIteration
        return data

    def close(self):
        self.file.close()


def _compress_response(response, response_buffer, compression_level):
    compressed_buffer = io.BytesIO()
    gzip_file = gzip.GzipFile(

# Path: turbulenz_local/tools.py
# def compress_file(file_path, compress_path):
#     seven_zip = get_7zip_path()
#     if seven_zip:
#         process = Popen([seven_zip,
#                          'a', '-tgzip',
#                          #'-mx=9', '-mfb=257', '-mpass=15',
#                          compress_path, file_path],
#                         stdout=PIPE, stderr=PIPE)
#         output, _ = process.communicate()
#         retcode = process.poll()
#         if retcode:
#             LOG.error('Failed to compress file "%s" as "%s": %s', file_path, compress_path, str(output))
#             return False
#         else:
#             return True
#     else:
#         cache_dir = dirname(compress_path)
#         if not isdir(cache_dir):
#             os.makedirs(cache_dir)
#         try:
#             with GzipFile(compress_path, mode='wb', compresslevel=9) as gzipfile:
#                 with open(file_path, 'rb') as f:
#                     gzipfile.write(f.read())
#         except IOError as e:
#             LOG.error(str(e))
#             return False
#         LOG.warning('Using Python for GZip compression, install 7zip for optimal performance')
#         return True


# Path: turbulenz_local/middleware/gzipcompress.py
import io
import gzip
import logging
import mimetypes
import os
from os.path import join, normpath
from paste.deploy.converters import asint, aslist
from turbulenz_local.tools import compress_file

def _get_file_stats(file_name):
    try:
        file_stat = os.stat(file_name)
        return file_stat.st_mtime, file_stat.st_size
    except OSError:
        return -1, 0


class GzipFileIter(object):
    __slots__ = ('file')

    def __init__(self, f):
        self.file = f

    def __iter__(self):
        return self

    def next(self):
        data = self.file.read(65536)
        if not data:
            raise StopIteration
        return data

    def close(self):
        self.file.close()


def _compress_response(response, response_buffer, compression_level):
    compressed_buffer = io.BytesIO()
    gzip_file = gzip.GzipFile(

        mode='wb',