import os
import sys

import gzip
import lz4.block
import lzma
try:
    import snappy
    SNAPPY_SUPPORT = True
except ImportError:
    SNAPPY_SUPPORT = False

sys.path.append(
    os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from python_utils.base import BaseFormatter

__version__ = '0.0.1'
DESCRIPTION = 'Python native decompressing formatter with gzip, lzma, lz4 ' \
              'and snappy support'


def is_gzip(value):
    return len(value) >= 3 and value[:3] == b'\x1f\x8b\x08'


def is_lzma(value):
    return len(value) >= 26 and value[:26] == \
                                b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!' \
                                b'\x01\x16\x00\x00\x00t/\xe5\xa3\x01\x00'


def is_snappy(value):
    return snappy.isValidCompressed(value)


class DecompressingFormatter(BaseFormatter):
    description = DESCRIPTION
    version = __version__

    def format(self, value):
        try:
            if is_gzip(value):
                output = gzip.decompress(value)
            elif is_lzma(value):
                output = lzma.decompress(value)
            elif is_snappy(value):
                if SNAPPY_SUPPORT:
                    output = snappy.uncompress(value)
                else:
                    return self.process_error(
                        'Cannot decompress value: '
                        'Snappy is not available on this system.')
            else:
                output = lz4.block.decompress(value)
            return output
        except OSError as e:
            return self.process_error('Cannot decompress value: {}'.format(e))


if __name__ == "__main__":
    DecompressingFormatter().main()

9790d24e872b8c522bf64c2f29f0e178b0b85a1a
<mask token>


def is_gzip(value):
    return len(value) >= 3 and value[:3] == b'\x1f\x8b\x08'


def is_lzma(value):
    return (len(value) >= 26 and value[:26] ==
        b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3\x01\x00'
        )


<mask token>


class DecompressingFormatter(BaseFormatter):
    description = DESCRIPTION
    version = __version__

    def format(self, value):
        try:
            if is_gzip(value):
                output = gzip.decompress(value)
            elif is_lzma(value):
                output = lzma.decompress(value)
            elif is_snappy(value):
                if SNAPPY_SUPPORT:
                    output = snappy.uncompress(value)
                else:
                    return self.process_error(
                        'Cannot decompress value: Snappy is not available on this system.'
                        )
            else:
                output = lz4.block.decompress(value)
            return output
        except OSError as e:
            return self.process_error('Cannot decompress value: {}'.format(e))


<mask token>

<mask token>
try:
    import snappy
    SNAPPY_SUPPORT = True
except ImportError:
    SNAPPY_SUPPORT = False
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
<mask token>


def is_gzip(value):
    return len(value) >= 3 and value[:3] == b'\x1f\x8b\x08'


def is_lzma(value):
    return (len(value) >= 26 and value[:26] ==
        b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3\x01\x00'
        )


def is_snappy(value):
    return snappy.isValidCompressed(value)


class DecompressingFormatter(BaseFormatter):
    description = DESCRIPTION
    version = __version__

    def format(self, value):
        try:
            if is_gzip(value):
                output = gzip.decompress(value)
            elif is_lzma(value):
                output = lzma.decompress(value)
            elif is_snappy(value):
                if SNAPPY_SUPPORT:
                    output = snappy.uncompress(value)
                else:
                    return self.process_error(
                        'Cannot decompress value: Snappy is not available on this system.'
                        )
            else:
                output = lz4.block.decompress(value)
            return output
        except OSError as e:
            return self.process_error('Cannot decompress value: {}'.format(e))


if __name__ == '__main__':
    DecompressingFormatter().main()

<mask token>
try:
    import snappy
    SNAPPY_SUPPORT = True
except ImportError:
    SNAPPY_SUPPORT = False
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
<mask token>
__version__ = '0.0.1'
DESCRIPTION = (
    'Python native decompressing formatter with gzip, lzma, lz4 and snappy support'
    )


def is_gzip(value):
    return len(value) >= 3 and value[:3] == b'\x1f\x8b\x08'


def is_lzma(value):
    return (len(value) >= 26 and value[:26] ==
        b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3\x01\x00'
        )


def is_snappy(value):
    return snappy.isValidCompressed(value)


class DecompressingFormatter(BaseFormatter):
    description = DESCRIPTION
    version = __version__

    def format(self, value):
        try:
            if is_gzip(value):
                output = gzip.decompress(value)
            elif is_lzma(value):
                output = lzma.decompress(value)
            elif is_snappy(value):
                if SNAPPY_SUPPORT:
                    output = snappy.uncompress(value)
                else:
                    return self.process_error(
                        'Cannot decompress value: Snappy is not available on this system.'
                        )
            else:
                output = lz4.block.decompress(value)
            return output
        except OSError as e:
            return self.process_error('Cannot decompress value: {}'.format(e))


if __name__ == '__main__':
    DecompressingFormatter().main()

import os
import sys
import gzip
import lz4.block
import lzma
try:
    import snappy
    SNAPPY_SUPPORT = True
except ImportError:
    SNAPPY_SUPPORT = False
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from python_utils.base import BaseFormatter
__version__ = '0.0.1'
DESCRIPTION = (
    'Python native decompressing formatter with gzip, lzma, lz4 and snappy support'
    )


def is_gzip(value):
    return len(value) >= 3 and value[:3] == b'\x1f\x8b\x08'


def is_lzma(value):
    return (len(value) >= 26 and value[:26] ==
        b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3\x01\x00'
        )


def is_snappy(value):
    return snappy.isValidCompressed(value)


class DecompressingFormatter(BaseFormatter):
    description = DESCRIPTION
    version = __version__

    def format(self, value):
        try:
            if is_gzip(value):
                output = gzip.decompress(value)
            elif is_lzma(value):
                output = lzma.decompress(value)
            elif is_snappy(value):
                if SNAPPY_SUPPORT:
                    output = snappy.uncompress(value)
                else:
                    return self.process_error(
                        'Cannot decompress value: Snappy is not available on this system.'
                        )
            else:
                output = lz4.block.decompress(value)
            return output
        except OSError as e:
            return self.process_error('Cannot decompress value: {}'.format(e))


if __name__ == '__main__':
    DecompressingFormatter().main()

import os
import sys

import gzip
import lz4.block
import lzma
try:
    import snappy
    SNAPPY_SUPPORT = True
except ImportError:
    SNAPPY_SUPPORT = False

sys.path.append(
    os.path.dirname(os.path.dirname(os.path.realpath(__file__))))

from python_utils.base import BaseFormatter

__version__ = '0.0.1'
DESCRIPTION = 'Python native decompressing formatter with gzip, lzma, lz4 ' \
              'and snappy support'


def is_gzip(value):
    return len(value) >= 3 and value[:3] == b'\x1f\x8b\x08'


def is_lzma(value):
    return len(value) >= 26 and value[:26] == \
                                b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!' \
                                b'\x01\x16\x00\x00\x00t/\xe5\xa3\x01\x00'


def is_snappy(value):
    return snappy.isValidCompressed(value)


class DecompressingFormatter(BaseFormatter):
    description = DESCRIPTION
    version = __version__

    def format(self, value):
        try:
            if is_gzip(value):
                output = gzip.decompress(value)
            elif is_lzma(value):
                output = lzma.decompress(value)
            elif is_snappy(value):
                if SNAPPY_SUPPORT:
                    output = snappy.uncompress(value)
                else:
                    return self.process_error(
                        'Cannot decompress value: '
                        'Snappy is not available on this system.')
            else:
                output = lz4.block.decompress(value)
            return output
        except OSError as e:
            return self.process_error('Cannot decompress value: {}'.format(e))


if __name__ == "__main__":
    DecompressingFormatter().main()
