1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from chandlerdb.schema.c import Redirector
17 from chandlerdb.util.c import Nil
18 from repository.item.Item import Item as Base, ItemClass as BaseClass
19 from repository.item.Collection import CollectionClass as BaseCollectionClass
20 from repository.schema.Kind import CDescriptor, Kind
21 from repository.schema.Attribute import Attribute
22 from repository.schema import Types
23 from repository.schema.Cloud import Cloud as _Cloud
24 from repository.schema.Cloud import Endpoint as _Endpoint
25 from zope.interface.advice import getFrameInfo, addClassAdvisor
26 import __main__, repository, os, sys
27
28 __all__ = [
29 'ActiveDescriptor', 'Activator', 'Descriptor', 'itemFor', 'kindInfo',
30 'One', 'Many', 'Sequence', 'Mapping', 'Item', 'ItemClass', 'initialValues',
31 'importString', 'parcel_for_module', 'TypeReference',
32 'Enumeration', 'Cloud', 'Endpoint', 'addClouds', 'Struct',
33 'assertResolved', 'Annotation', 'AnnotationItem',
34 'observer',
35 ]
36
37 all_aspects = Attribute.valueAspects + Attribute.refAspects + ('description',)
38
39 policy_values = (
40 'byRef', 'byValue', 'byCloud', 'byRef', 'none', 'byMethod', 'literal'
41 )
42
43 default_schema = {
44 Kind: ('description', 'notify'),
45 Base: ('description',)
46 }
47
48
49
50
51
52
53
55 fsi = getattr(ob,'_find_schema_item',None)
56 if fsi:
57 return fsi.im_self is not None
58 return ob is Base or ob is Kind
59
61 if ob is Base or ob is Kind:
62 return ob
63 else:
64 return ob.targetType()
65
66
68 """Reference a core schema type (e.g. Integer) by its repository path"""
69
74
76 return "TypeReference(%r)" % self.path
77
83
86
87 core_types = """
88 Boolean Symbol Importable Bytes Text Integer Long Float Decimal
89 Tuple List Set Class Dictionary Anything
90 Date Time DateTime DateTimeTZ TimeDelta TimeZone
91 Lob URL Complex UUID Path ItemRef NilValue
92 """.split()
93
94 for name in core_types:
95 globals()[name] = TypeReference("//Schema/Core/"+name)
96
97 __all__.extend(core_types)
98
100 """Abstract base for descriptors needing activation by their classes"""
101
103 """Redefine in subclasses to do useful things with `cls` & `name`"""
104 raise NotImplementedError
105
106
108 """Metaclass that activates contained ``ActiveDescriptor`` instances"""
109
115
117 """By default, backreferences to arbitrary classes go nowhere"""
118 return None
119
120