view env/lib/python3.7/site-packages/galaxy/util/aliaspickler.py @ 3:758bc20232e8 draft

"planemo upload commit 2a0fe2cc28b09e101d37293e53e82f61762262ec"
author shellac
date Thu, 14 May 2020 16:20:52 -0400
parents 26e78fe6e8c4
children
line wrap: on
line source

import pickle

from six.moves import cStringIO as StringIO


class AliasUnpickler(pickle.Unpickler):
    def __init__(self, aliases, *args, **kw):
        pickle.Unpickler.__init__(self, *args, **kw)
        self.aliases = aliases

    def find_class(self, module, name):
        module, name = self.aliases.get((module, name), (module, name))
        return pickle.Unpickler.find_class(self, module, name)


class AliasPickleModule(object):
    def __init__(self, aliases):
        self.aliases = aliases

    def dump(self, obj, fileobj, protocol=0):
        return pickle.dump(obj, fileobj, protocol)

    def dumps(self, obj, protocol=0):
        return pickle.dumps(obj, protocol)

    def load(self, fileobj):
        return AliasUnpickler(self.aliases, fileobj).load()

    def loads(self, string):
        fileobj = StringIO(string)
        return AliasUnpickler(self.aliases, fileobj).load()