def gzip_decompress(content):
    import gzip
    from cStringIO import StringIO
    zbuf = StringIO(content)
    zfile = gzip.GzipFile(mode='rb', fileobj=zbuf, compresslevel=9)
    uncontent = zfile.read()
    zfile.close()
    zbuf.close()
    return uncontent

def gzip_compress(content):
    import gzip
    from cStringIO import StringIO
    zbuf = StringIO()
    zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9)
    zfile.write(content)
    zfile.close()
    output=zbuf.getvalue()
    zbuf.close()
    return output

def calcCheckSum(str):
    import hashlib
    m = hashlib.md5()
    m.update(str)
    str = m.digest()
    return ''.join(["%02X" % ord(str[ix]) for ix in xrange(len(str))])

def getSplitSize(objectSize, operationSize):
    m = objectSize % operationSize
    splitsize = (objectSize / operationSize)
    if m > 0:
        splitsize = splitsize+1

    return splitsize


def __compress__(content):
    import zlib
    if type(content) in (str, unicode):
        return zlib.compress(content)

def __decompress__(compressed):
    import zlib
    import logging
    try:
        return zlib.decompress(compressed)
    except zlib.error, e:
        logging.warn('Invalid compression. %s'%(e))
        return compressed