From 767a681c4b8fe9102a2e4e8d990bfd74299035ae Mon Sep 17 00:00:00 2001 From: alex_nanou Date: Sun, 29 Aug 2004 10:41:52 +0000 Subject: [PATCH] *** empty log message *** --- CHANGES | 6 ++- PKG-INFO | 2 +- pli/interface.py | 53 +++++++++++++------ pli/logictypes.py | 121 ++++++------------------------------------- pli/pattern/mixin/mapping.py | 2 +- 5 files changed, 61 insertions(+), 123 deletions(-) diff --git a/CHANGES b/CHANGES index 464bb21..fae03c5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ -# this file was generated on [200408291357] +# this file was generated on [200408291440] pli changes: +version 0.0.79 (200408291438): +- updated pli.logictypes.DictUnion to use the pli.pattern.mixin.mapping module... +- rewriting the pli.interface using pli.logictypes.DictUnion. + version 0.0.78 (200408290203): - done a redesign and a full rewrite of the pli.interface... (currently in the testing phase...). diff --git a/PKG-INFO b/PKG-INFO index deb9025..99effb8 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: pli -Version: 0.0.78 +Version: 0.0.79 Summary: PLI: a utility library for the Python language. Home-page: http://pli.sourceforge.net/ Author: Alex A. Naanou diff --git a/pli/interface.py b/pli/interface.py index 70c99b6..96dfa97 100755 --- a/pli/interface.py +++ b/pli/interface.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.2.01''' -__sub_version__ = '''20040829135749''' +__sub_version__ = '''20040829143248''' __copyright__ = '''(c) Alex A. Naanou 2003''' @@ -16,6 +16,7 @@ classes. #----------------------------------------------------------------------- import pli.pattern.mixin.mapping as mapping +import pli.logictypes as logictypes #----------------------------------------------------------------------- @@ -463,16 +464,15 @@ def checkessentials(obj, interface=None): ''' ''' if interface != None: - format = (interface,) + format = interface else: - format = getinterfaces(obj) + format = logictypes.DictUnion(*getinterfaces(obj)[::-1]) res = {} - for i in format: - for n in i: - if n not in res: - v = i.getattrproperty(n, 'essential') - if v not in (None, False): - res[n] = v + for n in format: + if n not in res: + v = format[n].get('essential', False) + if v not in (None, False): + res[n] = v for n in res: if not hasattr(obj, n): raise InterfaceError, 'essential attribute "%s" missing from %s' % (n, obj) @@ -484,7 +484,26 @@ def checkessentials(obj, interface=None): def checkobject(obj, interface=None): ''' ''' - ##!!! + if interface != None: + format = interface + else: + format = logictypes.DictUnion(*getinterfaces(obj)[::-1]) + o_attrs = vars(obj).copy() + for n in format: + # Q: which one of the folowing is faster?? + if n not in o_attrs: +## if isessential(obj, n): + if format[n].get('essential', False): + raise InterfaceError, 'essential attribute "%s" missing from %s' % (n, obj) + else: + chackattr(obj, n) + del o_attrs[n] + if len(o_attrs) > 0: + if '*' not in format: + raise InterfaceError, 'excess attributes %s in object %s.' % (o_attrs.keys(), obj) + for n in o_attrs: + chackattr(obj, n) + return True @@ -498,14 +517,13 @@ def getdoc(obj, name=None, interface=None): if name is not present this will return all the docs for each attr defined... ''' if interface != None: - format = (interface,) + format = interface else: - format = getinterfaces(obj) + format = logictypes.DictUnion(*getinterfaces(obj)[::-1]) # if name is present... if name != None: - for i in format: - if name in i: - return {name: i.getattrproperty(name, 'doc')} + if name in format: + return {name: format[n].get('essential', None)} raise InterfaceError, 'attribute "%s" is not defined in the interface for %s.' % (name, obj) # if name is not present... res = {} @@ -616,6 +634,7 @@ if __name__ == '__main__': class ITest(Interface): __format__ = {\ 'aaa': {}, + 'ess': {'essential': True}, 'xxx': {'doc':'ITest'}, } @@ -657,11 +676,15 @@ if __name__ == '__main__': a = A() + a.ess = '' + print checkattr(a, 'ccc') print checkvalue(a, 'ccc', 0) print getdoc(a, 'ccc') + print checkessentials(a) + #======================================================================= # vim:set ts=4 sw=4 nowrap : diff --git a/pli/logictypes.py b/pli/logictypes.py index 3db48fc..47e7b5f 100755 --- a/pli/logictypes.py +++ b/pli/logictypes.py @@ -1,7 +1,7 @@ #======================================================================= -__version__ = '''0.0.04''' -__sub_version__ = '''20040724012609''' +__version__ = '''0.1.00''' +__sub_version__ = '''20040829143825''' __copyright__ = '''(c) Alex A. Naanou 2003''' __doc__ = '''\ @@ -11,6 +11,7 @@ usage of standard python types. #----------------------------------------------------------------------- +import pli.pattren.mixin.mapping as mapping #----------------------------------------------------------------------- @@ -64,7 +65,8 @@ def dictcopyunite(*members): #-----------------------------------------------------------DictUnion--- -class DictUnion(object): +# TODO use pli.pattern.mixin.mapping +class DictUnion(mapping.MappingWithMethods): ''' this is a dict like object, that acts as a union of its members but without modifieng its members in any way. @@ -95,16 +97,16 @@ class DictUnion(object): if name in m: return m[name] raise KeyError, 'key "%s" is not present in any of the members.' % name -## def __setitem__(self, name, value): -## ''' -## ''' -## # find source... -## # set -## raise TypeError, 'can\'t add values to a dict union object.' -## def __delitem__(self, name): -## ''' -## ''' -## raise TypeError, 'can\'t delete values from a dict union object.' + def __setitem__(self, name, value): + ''' + ''' + # find source... + # set + raise TypeError, 'can\'t add values to a dict union object.' + def __delitem__(self, name): + ''' + ''' + raise TypeError, 'can\'t delete values from a dict union object.' def __contains__(self, name): ''' ''' @@ -121,97 +123,6 @@ class DictUnion(object): if n not in seen: seen += [n] yield n -## def __len__(self): -## ''' -## ''' -## pass -## def __cmp__(self): -## ''' -## ''' -## pass -## def __eq__(self): -## ''' -## ''' -## pass -## def __ge__(self): -## ''' -## ''' -## pass -## def __gt__(self): -## ''' -## ''' -## pass -## def __le__(self): -## ''' -## ''' -## pass -## def __lt__(self): -## ''' -## ''' -## pass -## def __ne__(self): -## ''' -## ''' -## pass -## def __repr__(self): -## ''' -## ''' -## pass -## def __str__(self): -## ''' -## ''' -## pass -## def __reduce__(self): -## ''' -## ''' -## pass -## def __reduce_ex__(self): -## ''' -## ''' -## pass - def keys(self): - ''' - ''' - return list(self) - def values(self): - ''' - ''' - return list(self.itervalues()) - def items(self): - ''' - ''' - return list(self.iteritems()) - def iterkeys(self): - ''' - ''' - return self.__iter__() - def itervalues(self): - ''' - ''' - for k in self: - yield self[k] - def iteritems(self): - ''' - ''' - for k in self: - yield k, self[k] - def get(self, name, dfl=None): - ''' - ''' - try: - return self[name] - except KeyError: - if dfl == None: - raise - return dfl - def has_key(self, name): - ''' - ''' - return name in self -## def setdefault(self): -## ''' -## ''' -## pass # the dict union specific interface... ##!!! revise... def unite(self, *others): @@ -270,7 +181,7 @@ class DictUnion(object): ''' this will return a dict copy of the DictUnion object. ''' - return dict(*self.items()) + return dict(self.items()) #-------------------------------------------------------DictTypeUnion--- diff --git a/pli/pattern/mixin/mapping.py b/pli/pattern/mixin/mapping.py index 6845b69..2daf373 100644 --- a/pli/pattern/mixin/mapping.py +++ b/pli/pattern/mixin/mapping.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.1.01''' -__sub_version__ = '''20040820043927''' +__sub_version__ = '''20040829143830''' __copyright__ = '''(c) Alex A. Naanou 2003''' -- 2.11.4.GIT