Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine van Gelder <antoine@g7.org.za>2007-10-28 14:01:59 (GMT)
committer Antoine van Gelder <antoine@g7.org.za>2007-10-28 14:01:59 (GMT)
commit05d7e0283b978bb4836a1ddf8833b039ae55f130 (patch)
tree16e4c65b1dadff81d5b847f28694758c2252f466
parent366ab3f599b1d68b80d3432f787deb184c868323 (diff)
File cleanup
-rw-r--r--util/persistence.py.args81
-rw-r--r--util/persistence.py.noargs75
2 files changed, 0 insertions, 156 deletions
diff --git a/util/persistence.py.args b/util/persistence.py.args
deleted file mode 100644
index 1aa235f..0000000
--- a/util/persistence.py.args
+++ /dev/null
@@ -1,81 +0,0 @@
-# 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 2 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, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-
-import sys
-
-from util.decorators import DecoratorWithArgs
-
-
-class Persistent(type):
- '''Metaclass providing object persistence'''
- def __init__(cls, name, bases, dct):
- super(Persistent, cls).__init__(name, bases, dct)
-
- setattr(cls, '__dirty__', False)
- setattr(cls, '__properties__', filter(_is_persistent, dct.iteritems()))
-
- from util.journalpickler import dumps, loads
- setattr(cls, 'dumps', dumps)
- setattr(cls, 'loads', loads)
-
-
-@DecoratorWithArgs
-def PersistentProperty(function, default = None):
- '''Decorator to set persistent properties'''
- keys = 'fset', 'fdel'
- func_locals = {'doc':function.__doc__}
-
- def fgetter(obj, name, getter, default_value):
- attr_name = '_' + obj.__class__.__name__ + '__' + name
- if not hasattr(obj, attr_name):
- setattr(obj, attr_name, default_value(obj))
- return getter(obj)
-
- def fsetter(obj, name, setter, value):
- setattr(obj, '__dirty__', True)
- return setter(obj, value)
-
- def introspect(frame, event, arg):
- if event == 'return':
- locals = frame.f_locals
- func_locals.update(dict((k,locals.get(k)) for k in keys))
- if locals.has_key('fset'):
- func_locals['fset'] = \
- lambda obj, value : fsetter(obj, function.__name__, locals['fset'], value)
- if default != None:
- get_function = \
- lambda obj : fgetter(obj, function.__name__, locals['fget'], lambda x : default)
- else:
- get_function = \
- lambda obj : fgetter(obj, function.__name__, locals['fget'], lambda x : None)
- get_function.decorator = PersistentProperty # tag the getter so we can id
- # the decorator. Yeah, it's ugly.
- func_locals['fget'] = get_function
- sys.settrace(None)
- return introspect
-
- sys.settrace(introspect)
- function()
- return property(**func_locals)
-
-
-# a wee bit ugly
-def _is_persistent(item):
- '''check if property is decorated with PersistentProperty decorator'''
- prop = item[1]
- return type(prop) is property and \
- hasattr(prop.fget, 'decorator') and \
- prop.fget.decorator is PersistentProperty
diff --git a/util/persistence.py.noargs b/util/persistence.py.noargs
deleted file mode 100644
index bf982af..0000000
--- a/util/persistence.py.noargs
+++ /dev/null
@@ -1,75 +0,0 @@
-# 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 2 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, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-
-import sys
-
-
-def is_persistent(item):
- prop = item[1]
- return type(prop) is property and \
- hasattr(prop.fget, 'decorator') and \
- prop.fget.decorator is PersistentProperty
-
-
-class Persistent(type):
- def __init__(cls, name, bases, dct):
- # is_dirty
- setattr(cls, '__dirty__', False)
-
- # properties
- setattr(cls, '__properties__', filter(is_persistent, dct.iteritems()))
-
- super(Persistent, cls).__init__(name, bases, dct)
-
-
-def PersistentProperty(function):
- function.decorator = PersistentProperty
-
- keys = 'fset', 'fdel'
- func_locals = {'doc':function.__doc__}
-
- def fgetter(obj, name, getter, fdef):
- attr_name = '_' + obj.__class__.__name__ + '__' + name
- if not hasattr(obj, attr_name):
- setattr(obj, attr_name, fdef(obj))
- return getter(obj)
-
- def fsetter(obj, name, setter, value):
- setattr(obj, '__dirty__', True)
- return setter(obj, value)
-
- def probe_function(frame, event, arg):
- if event == 'return':
- locals = frame.f_locals
- func_locals.update(dict((k,locals.get(k)) for k in keys))
-
- if locals.has_key('fset'):
- func_locals['fset'] = lambda obj, value : fsetter(obj, function.__name__, locals['fset'], value)
-
- if locals.has_key('fdef'):
- f = lambda obj : fgetter(obj, function.__name__, locals['fget'], locals['fdef'])
- else:
- f = lambda obj : fgetter(obj, function.__name__, locals['fget'], lambda x : None)
- f.decorator = PersistentProperty # tag the getter
- func_locals['fget'] = f
-
- sys.settrace(None)
- return probe_function
- sys.settrace(probe_function)
- function()
- return property(**func_locals)
-
-