From 1a308962b0e74fd22d2ae0e91f39f931f5b9ba57 Mon Sep 17 00:00:00 2001 From: Marco Selig <mselig@ncg-02.MPA-Garching.MPG.DE> Date: Wed, 21 Jan 2015 13:36:49 +0100 Subject: [PATCH] demo_mod operational; pickling moved. --- __init__.py | 35 ++---------------------------- demos/__init__.py | 2 +- nifty_core.py | 4 +++- pickling.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 pickling.py diff --git a/__init__.py b/__init__.py index 4121b411a..4a281acad 100644 --- a/__init__.py +++ b/__init__.py @@ -25,38 +25,7 @@ from nifty_cmaps import * from nifty_power import * from nifty_tools import * from nifty_explicit import * - #from nifty_power_conversion import * +from demos import * +from pickling import * - -##----------------------------------------------------------------------------- - -import copy_reg as cr -from types import MethodType as mt - - -def _pickle_method(method): - fct_name = method.im_func.__name__ - obj = method.im_self - cl = method.im_class - ## handle mangled function name - if(fct_name.startswith("__"))and(not fct_name.endswith("__")): - cl_name = cl.__name__.lstrip("_") - fct_name = "_" + cl_name + fct_name - return _unpickle_method, (fct_name, obj, cl) - - -def _unpickle_method(fct_name, obj, cl): - for oo in cl.__mro__: - try: - fct = oo.__dict__[fct_name] - except(KeyError): - pass - else: - break - return fct.__get__(obj, cl) - -## enable instance methods pickling -cr.pickle(mt, _pickle_method, _unpickle_method) - -##----------------------------------------------------------------------------- \ No newline at end of file diff --git a/demos/__init__.py b/demos/__init__.py index e9456ac3f..7e38285b3 100644 --- a/demos/__init__.py +++ b/demos/__init__.py @@ -19,5 +19,5 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see <http://www.gnu.org/licenses/>. -pass +from demos_core import * diff --git a/nifty_core.py b/nifty_core.py index ec0186af8..9593b7a92 100644 --- a/nifty_core.py +++ b/nifty_core.py @@ -163,6 +163,8 @@ import powerspectrum as gp pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 +__version__ = "0.9.5" + ##----------------------------------------------------------------------------- @@ -514,7 +516,7 @@ class _about(object): ## nifty support class for global settings """ ## version - self._version = "0.9.3" + self._version = str(__version__) ## switches and notifications self._errors = notification(default=True,ccode=notification._code) diff --git a/pickling.py b/pickling.py new file mode 100644 index 000000000..d8974660a --- /dev/null +++ b/pickling.py @@ -0,0 +1,54 @@ +## NIFTY (Numerical Information Field Theory) has been developed at the +## Max-Planck-Institute for Astrophysics. +## +## Copyright (C) 2013 Max-Planck-Society +## +## Author: Marco Selig +## Project homepage: <http://www.mpa-garching.mpg.de/ift/nifty/> +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +## See the GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see <http://www.gnu.org/licenses/>. + +import copy_reg as cr +from types import MethodType as mt + + +##----------------------------------------------------------------------------- + +def _pickle_method(method): + fct_name = method.im_func.__name__ + obj = method.im_self + cl = method.im_class + ## handle mangled function name + if(fct_name.startswith("__"))and(not fct_name.endswith("__")): + cl_name = cl.__name__.lstrip("_") + fct_name = "_" + cl_name + fct_name + return _unpickle_method, (fct_name, obj, cl) + +##----------------------------------------------------------------------------- + +def _unpickle_method(fct_name, obj, cl): + for oo in cl.__mro__: + try: + fct = oo.__dict__[fct_name] + except(KeyError): + pass + else: + break + return fct.__get__(obj, cl) + +##----------------------------------------------------------------------------- + +## enable instance methods pickling +cr.pickle(mt, _pickle_method, _unpickle_method) + -- GitLab