예제 #1
0
def score_def(x, y, c_x, c_y):
	x = bytes(x, encoding='utf8')
	y = bytes(y, encoding='utf8')

	cat_xy = x + y
	c_xy = len(deflate.gzip_compress(cat_xy))
	cat_yx = y + x
	c_yx = len(deflate.gzip_compress(cat_yx))

	return (min(c_xy, c_yx) - min(c_x, c_y))/max(c_x, c_y)
예제 #2
0
def gzip_compress(content, compresslevel=None):
  if compresslevel is None:
    compresslevel = 9

  if deflate:
    return deflate.gzip_compress(content, compresslevel)

  stringio = BytesIO()
  gzip_obj = gzip.GzipFile(mode='wb', fileobj=stringio, compresslevel=compresslevel)
  gzip_obj.write(content)
  gzip_obj.close()
  return stringio.getvalue()  
예제 #3
0
def gzip_compress(content, compresslevel=None):
    if compresslevel is None:
        compresslevel = 9

    return deflate.gzip_compress(content, compresslevel)
예제 #4
0
__all__ = [
    'deflate',
    'zlib',
    'no_compress',
    'CompressionAlgorithm'
]


class CompressionAlgorithm:
    def __init__(self, compress, decompress, label):
        self.compress = compress
        self.decompress = decompress
        self.label = label

    def __str__(self):
        return self.label


deflate = CompressionAlgorithm(lambda data_bytes: de.gzip_compress(data_bytes, 12),
                               de.gzip_decompress,
                               'deflate')

zlib = CompressionAlgorithm(lambda data_bytes: zl.compress(data_bytes, 9),
                            zl.decompress,
                            'zlib')

no_compress = CompressionAlgorithm(lambda data_bytes: data_bytes,
                                   lambda data_bytes: data_bytes,
                                   'no compression')