From e82803e1c81f2f45b27c980b21dd576212bee149 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rg=20Lehmann?= Date: Sat, 17 Jan 2004 18:28:30 +0000 Subject: [PATCH] remove unused attribute code git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@1244 069f4177-920e-0410-937b-c2a4a81bcd90 --- pyx/helper.py | 104 ---------------------------------------------------------- 1 file changed, 104 deletions(-) diff --git a/pyx/helper.py b/pyx/helper.py index c5883a8e..7184735e 100644 --- a/pyx/helper.py +++ b/pyx/helper.py @@ -102,107 +102,3 @@ def getsequenceno(arg, n): except: return None else: return arg - - -class AttrError(base.PyXExcept): pass - - -def checkattr(attrs, allowonce=(), allowmulti=()): - """checks the sequence attrs for occurencies of instances - the classes provided as a tuple to allowonce are allowed only once - the classes provided as a tuple to allowonce are allowed multiple times""" - hadonce = [] - for attr in attrs: - for once in allowonce: - if isinstance(attr, once): - if once in hadonce: - raise AttrError("only a single instance of %r allowed" % once) - else: - hadonce += [once] - break - else: - for multi in allowmulti: - if isinstance(attr, multi): - break - else: - raise AttrError("%r not allowed" % attr) - - -def getattrs(attrs, get, default=nodefault): - """creates a list of instances of class get out of the sequence attrs - when no instances are found it returns default when set (whatever it is) - when no instances are found it raises AttrError when default is not set""" - first = 1 - for attr in attrs: - if isinstance(attr, get): - if first: - result = [attr] - first = 0 - else: - result.append(attr) - if first: - if default is nodefault: - raise AttrError - else: - return default - return result - - -def countattrs(attrs, check): - "count the occurancies of instances of class get out of the sequence attrs" - return len(getattrs(attrs, check, ())) - - -def getattr(attrs, get, default=nodefault): - """get the instance of class get out of the sequence attrs - when no instance is found it returns default when set (whatever it is) - when no instance is found it raises AttrError when default is not set - when no multiple instances are found it always raises AttrError""" - try: - result = getattrs(attrs, get) - except AttrError: - if default is nodefault: - raise AttrError - else: - return default - if len(result) > 1: - raise AttrError - return result[0] - - -def getfirstattr(attrs, get, default=nodefault): - """get the first instance of class get out of the sequence attrs - when no instances are found it returns default when set (whatever it is) - when no instances are found it raises AttrError when default is not set""" - try: - result = getattrs(attrs, get) - except AttrError: - if default is nodefault: - raise AttrError - else: - return default - return result[0] - - -def getlastattr(attrs, get, default=nodefault): - """get the last instance of class get out of the sequence attrs - when no instances are found it returns default when set (whatever it is) - when no instances are found it raises AttrError when default is not set""" - try: - result = getattrs(attrs, get) - except AttrError: - if default is nodefault: - raise AttrError - else: - return default - return result[-1] - - -def delattr(attrs, remove): - """create a new list of instances out of the sequence attrs - where all instances of class remove are removed""" - result = [] - for attr in attrs: - if not isinstance(attr, remove): - result.append(attr) - return result -- 2.11.4.GIT