1
2
3 """
4 orm.py
5
6 Created by Philip Cooper on 2007-11-23.
7 Copyright (c) 2007 Openvest. All rights reserved.
8 """
9
10 from rdfalchemy.rdfSubject import rdfSubject
11 from rdfalchemy.descriptors import rdfAbstract
12
13 import logging
14 log=logging.getLogger(__name__)
15
17 "return all subclasses of the given class"
18 sub = set(cl.__subclasses__()) | beenthere
19 newsubs = set(cl.__subclasses__()) - beenthere
20 for onesub in newsubs:
21 sub |= allsub(onesub, sub)
22 return sub
23
24
26 """Map the classes given to allow descriptors with ranges to the proper Class of that type
27 default if no args is to map all subclasses(recursivly) of rdfSubject
28
29 preforms the mapping
30
31 returns a dict of {rdf_type: mapped_class} for further processing"""
32 if not classes:
33 classes = allsub(rdfSubject)
34 class_dict = dict([(str(cl.rdf_type), cl) for cl in classes])
35 for cl in classes:
36 for v in cl.__dict__.values():
37 if isinstance(v,rdfAbstract) and v.range_type:
38 try:
39 v._mappedClass = class_dict[str(v.range_type)]
40 except KeyError:
41 log.warn("No Class Found\nFailed to map %s range of %s"%(v,v.range_type))
42 return class_dict
43
44
45
46
47
48