How to use the hickle.hickle_legacy function in hickle

To help you get started, we’ve selected a few hickle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github telegraphic / hickle / hickle / hickle.py View on Github external
from . import hickle_legacy2
                    return hickle_legacy2.load(fileobj, path=path, safe=safe)
                else:
                    raise RuntimeError("Cannot open file. This file was likely"
                                       " created with Python 2 and an old hickle version.")
            elif VER_MAJOR >= 3:
                py_container = PyContainer()
                py_container.container_type = 'hickle'
                py_container = _load(py_container, h_root_group)
                return py_container[0][0]

        except AssertionError:
            if PY2:
                warnings.warn("Hickle file is not versioned, attempting legacy loading...")
                from . import hickle_legacy
                return hickle_legacy.load(fileobj, safe)
            else:
                raise RuntimeError("Cannot open file. This file was likely"
                                   " created with Python 2 and an old hickle version.")
    finally:
        # Close the file if requested.
        # Closing a file twice will not cause any problems
        if close_flag:
            h5f.close()
github telegraphic / hickle / hickle / hickle.py View on Github external
try:
        h5f, close_flag = file_opener(fileobj)
        h_root_group = h5f.get(path)
        try:
            assert 'CLASS' in h5f.attrs.keys()
            assert 'VERSION' in h5f.attrs.keys()
            VER = h5f.attrs['VERSION']
            try:
                VER_MAJOR = int(VER)
            except ValueError:
                VER_MAJOR = int(VER[0])
            if VER_MAJOR == 1:
                if PY2:
                    warnings.warn("Hickle file versioned as V1, attempting legacy loading...")
                    from . import hickle_legacy
                    return hickle_legacy.load(fileobj, safe)
                else:
                    raise RuntimeError("Cannot open file. This file was likely"
                                       " created with Python 2 and an old hickle version.")
            elif VER_MAJOR == 2:
                if PY2:
                    warnings.warn("Hickle file appears to be old version (v2), attempting "
                                  "legacy loading...")
                    from . import hickle_legacy2
                    return hickle_legacy2.load(fileobj, path=path, safe=safe)
                else:
                    raise RuntimeError("Cannot open file. This file was likely"
                                       " created with Python 2 and an old hickle version.")
            # There is an unfortunate period of time where hickle 2.1.0 claims VERSION = int(3)
            # For backward compatibility we really need to catch this.
            # Actual hickle v3 files are versioned as A.B.C (e.g. 3.1.0)
            elif VER_MAJOR == 3 and VER == VER_MAJOR: