# -*- encoding: utf-8 -*-

def _pickle_method(method):
	"""Workaround function for pickling object methods"""
	func_name = method.im_func.__name__
	obj = method.im_self
	cls = method.im_class
	return _unpickle_method, (func_name, obj, cls)

def _unpickle_method(func_name, obj, cls):
	"""Workaround function for unpickling object methods"""
	for cls in cls.mro():
		try:
			func = cls.__dict__[func_name]
		except KeyError:
			pass
		else:
			break
	return func.__get__(obj, cls)

"""Registering pickling/unpickling for methods"""
import copy_reg
import types
copy_reg.pickle(types.MethodType, _pickle_method, _unpickle_method)
