Mailing list archives: September 2008

Site index · List index
Message listThread · Author · Date
foundation.org riptor object %r cannot be modified after use&quot; % self </span><span class="cx"> ) self._setattr(attr, value) </span><span class="lines">@@ -261,7 +261,7 @@ </span><span class="cx"> def __repr__(self): if self.name and self.owner: </span><span class="rem">- return &quot;&lt;Role %s of %s&gt;&quot; % (self.name,self.owner) </span><span class="add">+ return &quot;&lt;Descriptor %s of %s&gt;&quot; % (self.name,self.owner) </span><span class="cx"> return object.__repr__(self) def __setDoc(self,val): </span><span class="lines">@@ -357,19 +357,19 @@ </span><span class="cx"> itemFor(self.inverse, view) </span><span class="rem">-class One(Role): </span><span class="add">+class One(Descriptor): </span><span class="cx"> cardinality = 'single' </span><span class="rem">-class Many(Role): </span><span class="add">+class Many(Descriptor): </span><span class="cx"> cardinality = 'set' </span><span class="rem">-class Sequence(Role): </span><span class="add">+class Sequence(Descriptor): </span><span class="cx"> cardinality = 'list' </span><span class="rem">-class Mapping(Role): </span><span class="add">+class Mapping(Descriptor): </span><span class="cx"> cardinality = 'dict' </span><span class="lines">@@ -411,7 +411,7 @@ </span><span class="cx"> class AttributeAsEndpoint(Endpoint): </span><span class="rem">- &quot;&quot;&quot;Adapt a Role or attribute name to use as an Endpoint factory&quot;&quot;&quot; </span><span class="add">+ &quot;&quot;&quot;Adapt a Descriptor or attribute name to use as an Endpoint factory&quot;&quot;&quot; </span><span class="cx"> def __new__(cls, attr, policy): if isinstance(attr, Endpoint): </span><span class="lines">@@ -423,7 +423,7 @@ </span><span class="cx"> def __init__(self, attr, policy): if isinstance(attr,str): super(AttributeAsEndpoint,self).__init__(attr,(attr,), policy) </span><span class="rem">- elif isinstance(attr,Role): </span><span class="add">+ elif isinstance(attr,Descriptor): </span><span class="cx"> self.attr = attr super(AttributeAsEndpoint,self).__init__(None,(),policy) else: </span><span class="lines">@@ -525,7 +525,7 @@ </span><span class="cx"> kind.classes = {'python': cls } kind.attributes = [] for name,attr in cls.__dict__.items(): </span><span class="rem">- if isinstance(attr,Role): </span><span class="add">+ if isinstance(attr,Descriptor): </span><span class="cx"> ai = itemFor(attr, view) if ai not in kind.attributes: kind.attributes.append(ai,name) </span><span class="lines">@@ -689,7 +689,7 @@ </span><span class="cx"> def __init__(cls,name,bases,cdict): for name,ob in cdict.items(): </span><span class="rem">- if isinstance(ob,Role): </span><span class="add">+ if isinstance(ob,Descriptor): </span><span class="cx"> basename = &quot;%s.%s.&quot; % (parcel_name(cls.__module__), cls.__name__) ob.annotates = _target_type(cls), ob.activateInClass(cls,basename+name) </span><span class="lines">@@ -1182,7 +1182,7 @@ </span><span class="cx"> def _create_schema_item(self,view): # Create a temporary item without a kind, so as not to </span><span class="rem">- # incur unintended </span><span class="add">+ # incur unintended circularities. </span><span class="cx"> return Base(&quot;tmp_parcel_for-&quot;+self.moduleName, view, None) def _init_schema_item(self,item,view): </span></pre></div> <a id="trunkchandlerapplicationschema_apitxt"></a> <div class="modfile"><h4>Modified: trunk/chandler/application/schema_api.txt (8756 => 8757)</h4> <pre class="diff"> <span class="info">--- trunk/chandler/application/schema_api.txt 2005-12-19 18:28:47 UTC (rev 8756) +++ trunk/chandler/application/schema_api.txt 2005-12-19 18:59:29 UTC (rev 8757) </span><span class="lines">@@ -8,36 +8,15 @@ </span><span class="cx"> &gt;&gt;&gt; from repository.persistence.RepositoryView import NullRepositoryView </span><span class="rem">------------- -Introduction ------------- </span><span class="add">+------------------ +Descriptor Objects +------------------ </span><span class="cx"> </span><span class="rem">-TODO </span><span class="add">+The ``Descriptor`` Base Type +============================= </span><span class="cx"> </span><span class="rem">------------- -Role Objects ------------- - -The ``One``, ``Many``, ``Sequence``, and ``Mapping`` classes are all used to -define roles. They are all essentially identical except for their -``cardinality`` attribute, which controls how the repository will store the -attribute's value:: - - &gt;&gt;&gt; schema.One.cardinality - 'single' - &gt;&gt;&gt; schema.Many.cardinality - 'set' - &gt;&gt;&gt; schema.Sequence.cardinality - 'list' - &gt;&gt;&gt; schema.Mapping.cardinality - 'dict' - - -The ``Role`` Base Type -====================== - -The base class for roles is ``schema.Role``. It provides most of the -default behavior of roles, so rather than duplicate examples for each </span><span class="add">+The base class for roles is ``schema.Descriptor``. It provides most of the +default behavior of descriptors, so rather than duplicate examples for each </span><span class="cx"> individual role type, we'll examine the default behaviors here. All role objects have at least the following attributes and methods: </span><span class="lines">@@ -47,39 +26,40 @@ </span><span class="cx"> relationship, or ``None`` if the role has not been registered with a class yet:: </span><span class="rem">- &gt;&gt;&gt; role = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role.name None &gt;&gt;&gt; class anEntity(schema.Item): </span><span class="rem">- ... aRole = role </span><span class="add">+ ... aDescriptor = role </span><span class="cx"> &gt;&gt;&gt; role.name </span><span class="rem">- 'aRole' </span><span class="add">+ 'aDescriptor' </span><span class="cx"> ``owner`` (read-only) The entity or relationship class in which the role was defined, or ``None`` if the role has not been registered with a class yet:: </span><span class="rem">- &gt;&gt;&gt; role = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role.owner None &gt;&gt;&gt; class anEntity(schema.Item): </span><span class="rem">- ... aRole = role </span><span class="add">+ ... aDescriptor = role </span><span class="cx"> &gt;&gt;&gt; role.owner &lt;class '...anEntity'&gt; </span><span class="rem">- If a role's owner is an ``Item`` class, then setting ``aRole.inverse`` will - invoke ``aRole.inverse.addType(aRole.owner)``, so that the inverse role - will accept instances of the first role's owning type. This allows you </span><span class="add">+ If a role's owner is an ``Item`` class, then setting + ``aDescriptor.inverse`` will invoke + ``aDescriptor.inverse.addType(aDescriptor.owner)``, so that the inverse + role will accept instances of the first role's owning type. This allows you </span><span class="cx"> to easily define bidirectional links without &quot;forward references&quot;; just leave off the `type` argument in both role definitions, and specify an `inverse` argument for the second:: &gt;&gt;&gt; class anotherEntity(schema.Item): </span><span class="rem">- ... otherRole = schema.Role(inverse=anEntity.aRole) - &gt;&gt;&gt; anotherEntity.otherRole.type </span><span class="add">+ ... otherDescriptor=schema.Descriptor(inverse=anEntity.aDescriptor) + &gt;&gt;&gt; anotherEntity.otherDescriptor.type </span><span class="cx"> &lt;class '...anEntity'&gt; </span><span class="rem">- &gt;&gt;&gt; anEntity.aRole.type </span><span class="add">+ &gt;&gt;&gt; anEntity.aDescriptor.type </span><span class="cx"> &lt;class '...anotherEntity'&gt; As you can see, this ensures that both roles can accept the owning type of </span><span class="lines">@@ -115,17 +95,17 @@ </span><span class="cx"> | ... | Data and other attributes defined here: | </span><span class="rem">- | name = &lt;Role name of &lt;class '...Kind'&gt;&gt; </span><span class="add">+ | name = &lt;Descriptor name of &lt;class '...Kind'&gt;&gt; </span><span class="cx"> | Kind Name -- One(Text) | | This kind's name | </span><span class="rem">- | subkinds = &lt;Role subkinds of &lt;class '...Kind'&gt;&gt; </span><span class="add">+ | subkinds = &lt;Descriptor subkinds of &lt;class '...Kind'&gt;&gt; </span><span class="cx"> | Many(Kind) | | Sub-kinds of this kind | </span><span class="rem">- | superkinds = &lt;Role superkinds of &lt;class '...Kind'&gt;&gt; </span><span class="add">+ | superkinds = &lt;Descriptor superkinds of &lt;class '...Kind... </span><span class="cx"> | Many(Kind) | | Super-kinds of this kind </span><span class="lines">@@ -139,7 +119,7 @@ </span><span class="cx"> The ``doc`` and ``description`` are always strings, even if empty:: </span><span class="rem">- &gt;&gt;&gt; schema.Role().description </span><span class="add">+ &gt;&gt;&gt; schema.Descriptor().description </span><span class="cx"> '' ``inverse`` </span><span class="lines">@@ -152,10 +132,10 @@ </span><span class="cx"> ``inverse`` can be set via keyword argument to the role class' constructor:: </span><span class="rem">- &gt;&gt;&gt; role1 = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role1 = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role1.inverse None </span><span class="rem">- &gt;&gt;&gt; role2 = schema.Role(inverse=role1) </span><span class="add">+ &gt;&gt;&gt; role2 = schema.Descriptor(inverse=role1) </span><span class="cx"> &gt;&gt;&gt; role2.inverse is role1 True &gt;&gt;&gt; role1.inverse is role2 </span><span class="lines">@@ -163,8 +143,8 @@ </span><span class="cx"> Or by setting the ``inverse`` attribute after construction:: </span><span class="rem">- &gt;&gt;&gt; role1 = schema.Role() - &gt;&gt;&gt; role2 = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role1 = schema.Descriptor() + &gt;&gt;&gt; role2 = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; role2.inverse = role1 &gt;&gt;&gt; role2.inverse is role1 True </span><span class="lines">@@ -173,23 +153,23 @@ </span><span class="cx"> Once set, it cannot be changed, unless it is to the same role:: </span><span class="rem">- &gt;&gt;&gt; role2.inverse = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role2.inverse = schema.Descriptor() </span><span class="cx"> Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role objects are immutable; can't change 'inverse' ... once set </span><span class="add">+ TypeError: Descriptor objects are immutable; can't change 'inverse' ... </span><span class="cx"> &gt;&gt;&gt; role2.inverse is role1 # no change took place True And trying to insert a new role into an existing pair also fails:: </span><span class="rem">- &gt;&gt;&gt; role3 = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role3 = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role3.inverse None &gt;&gt;&gt; role3.inverse = role2 Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role objects are immutable; can't change 'inverse' ... once set </span><span class="add">+ TypeError: Descriptor objects are immutable; can't change 'inverse' ... </span><span class="cx"> &gt;&gt;&gt; print role3.inverse # no change took place None </span><span class="lines">@@ -210,7 +190,7 @@ </span><span class="cx"> &lt;class '...Folder'&gt; &gt;&gt;&gt; File.folder.inverse </span><span class="rem">- &lt;Role contents of &lt;class '...Folder'&gt;&gt; </span><span class="add">+ &lt;Descriptor contents of &lt;class '...Folder'&gt;&gt; </span><span class="cx"> ``type`` The ``type`` of a role can be either a ``schema.Item`` subclass, a </span><span class="lines">@@ -224,17 +204,17 @@ </span><span class="cx"> &gt;&gt;&gt; myType = schema.TypeReference('//Schema/Core/DateTime') </span><span class="rem">- &gt;&gt;&gt; print schema.Role(myType).__doc__ - Role(DateTime) </span><span class="add">+ &gt;&gt;&gt; print schema.Descriptor(myType).__doc__ + Descriptor(DateTime) </span><span class="cx"> Note that you cannot use arbitrary Python types or classes; you must either supply a ``schema.TypeReference``, a subclass of ``schema.Item``, or a string representing a forward reference:: </span><span class="rem">- &gt;&gt;&gt; schema.Role(str) </span><span class="add">+ &gt;&gt;&gt; schema.Descriptor(str) </span><span class="cx"> Traceback (most recent call last): ... </span><span class="rem">- TypeError: ('Attribute type must be Item/Enumeration class or TypeReference', ...) </span><span class="add">+ TypeError: ('...must be Item/Enumeration class or TypeReference',...) </span><span class="cx"> And type references must be to types defined by the repository's core schema:: </span><span class="lines">@@ -247,46 +227,47 @@ </span><span class="cx"> Types expressed as a string are automatically converted to ``ForwardReference`` objects:: </span><span class="rem">- &gt;&gt;&gt; testRole = schema.Role(&quot;application.schema.Item&quot;) - &gt;&gt;&gt; testRole.type - ForwardReference('application.schema.Item',&lt;...Role object...&gt;) </span><span class="add">+ &gt;&gt;&gt; testDescriptor = schema.Descriptor(&quot;application.schema.Item&quot;) + &gt;&gt;&gt; testDescriptor.type + ForwardReference('application.schema.Item',&lt;...Descriptor object...&gt;) </span><span class="cx"> Forward references compare equal to the type they reference:: </span><span class="rem">- &gt;&gt;&gt; testRole.type == schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type == schema.Item </span><span class="cx"> True </span><span class="rem">- &gt;&gt;&gt; testRole.type != schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type != schema.Item </span><span class="cx"> False Aspect Attributes </span><span class="rem">- Role objects support setting all of the aspects of a repository </span><span class="add">+ Descriptor objects support setting all of the aspects of a repository </span><span class="cx"> ``Attribute``, including ``required``, ``persisted``, ``indexed``, ``cardinality``, ``defaultValue``, ``initialValue``, ``inheritFrom``, ``redirectTo``, ``otherName``, ``companion``, ``deletePolicy``, ``copyPolicy``, ``countPolicy``, ``type``, ``superAttribute``, ``displayName``, and ``description``. You can supply any of these as </span><span class="rem">- keyword arguments to a Role constructor (such as ``schema.One``, </span><span class="add">+ keyword arguments to a Descriptor constructor (such as ``schema.One``, </span><span class="cx"> ``schema.Many``, etc.), in order to set the corresponding value for the attribute. Unspecified aspects will take on their normal default values, except for ``otherName``, which is set to ``inverse.name`` by default, if the attribute has an inverse. </span><span class="rem">-To avoid silent definition errors, ``Role`` classes will not allow setting -attributes that are not defined by their class:: </span><span class="add">+To avoid silent definition errors, ``Descriptor`` classes will not allow +setting attributes that are not defined by their class:: </span><span class="cx"> </span><span class="rem">- &gt;&gt;&gt; r = schema.Role(foo=&quot;bar&quot;) </span><span class="add">+ &gt;&gt;&gt; r = schema.Descriptor(foo=&quot;bar&quot;) </span><span class="cx"> Traceback (most recent call last): ... </span><span class="rem">- TypeError: 'foo' is not a public attribute of 'Role' objects </span><span class="add">+ TypeError: 'foo' is not a public attribute of 'Descriptor' objects </span><span class="cx"> </span><span class="rem">-And, to avoid unintentional alterations, Role attributes can be set only once:: </span><span class="add">+And, to avoid unintentional alterations, Descriptor attributes can be set only +once:: </span><span class="cx"> </span><span class="rem">- &gt;&gt;&gt; r = schema.Role(doc=&quot;x&quot;) </span><span class="add">+ &gt;&gt;&gt; r = schema.Descriptor(doc=&quot;x&quot;) </span><span class="cx"> &gt;&gt;&gt; r.doc = &quot;testing&quot; Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role objects are immutable; can't change 'doc' ... once set </span><span class="add">+ TypeError: Descriptor objects are immutable; can't change 'doc'... once set </span><span class="cx"> --------------- </span><span class="lines">@@ -305,7 +286,7 @@ </span><span class="cx"> ... children = schema.Sequence(inverse=parents) ... ... schema.addClouds( </span><span class="rem">- ... # endpoints can be defined using Role objects or strings </span><span class="add">+ ... # endpoints can be defined using Descriptor objects or strings </span><span class="cx"> ... sharing = schema.Cloud(byCloud=[parents,children]), ... export = schema.Cloud(byRef=[&quot;children&quot;]), ... ) </span><span class="lines">@@ -665,7 +646,7 @@ </span><span class="cx"> &gt;&gt;&gt; imp.description 'Description goes here' </span><span class="rem">- &gt;&gt;&gt; test_role = schema.Role(Importance) </span><span class="add">+ &gt;&gt;&gt; test_role = schema.Descriptor(Importance) </span><span class="cx"> &gt;&gt;&gt; imp.values ['high', 'medium', 'low'] </span><span class="lines">@@ -1055,7 +1036,7 @@ </span><span class="cx"> True </span><span class="rem">- Meanwhile, ``schema.itemFor(aRole)`` returns a repository ``Attribute`` </span><span class="add">+ Meanwhile, ``schema.itemFor(aDescriptor)`` returns a repository ``Attribute`` </span><span class="cx"> object representing that attribute in the null view:: &gt;&gt;&gt; schema.itemFor(Kind.subkinds, rv) </span><span class="lines">@@ -1079,7 +1060,7 @@ </span><span class="cx"> &gt;&gt;&gt; schema.itemFor(Kind.subkinds, rv).description is Kind.subkinds.doc True </span><span class="rem">- Roles must be activated in a class, however, in order to generate their </span><span class="add">+ Descriptors must be activated in a class, however, in order to generate their </span><span class="cx"> ``Attribute``:: &gt;&gt;&gt; schema.itemFor(schema.One(), rv) </span><span class="lines">@@ -1093,7 +1074,7 @@ </span><span class="cx"> &gt;&gt;&gt; Kind.subkinds.redirectTo = &quot;xyz&quot; Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role object &lt;Role subkinds of &lt;class '...Kind'&gt;&gt; cannot be modified after use </span><span class="add">+ TypeError: Descriptor object &lt;Descriptor subkinds of &lt;class '...Kind'&gt;&gt; cannot be modified after use </span><span class="cx"> ``initRepository(repoView)`` Ensure that the given repository view has been initialized with the core </span><span class="lines">@@ -1230,8 +1211,8 @@ </span><span class="cx"> &gt;&gt;&gt; class Test1(object): ... __metaclass__ = schema.Activator </span><span class="rem">- ... aRole = MockAttr() - activated 'aRole' in &lt;class 'Test1'&gt; </span><span class="add">+ ... aDescriptor = MockAttr() + activated 'aDescriptor' in &lt;class 'Test1'&gt; </span><span class="cx"> &gt;&gt;&gt; class Test2(Test1): ... test = MockAttr() </span></pre></div> <a id="trunkchandlerapplicationtestsTestSchemaAPIpy"></a> <div class="modfile"><h4>Modified: trunk/chandler/application/tests/TestSchemaAPI.py (8756 => 8757)</h4> <pre class="diff"> <span class="info">--- trunk/chandler/application/tests/TestSchemaAPI.py 2005-12-19 18:28:47 UTC (rev 8756) +++ trunk/chandler/application/tests/TestSchemaAPI.py 2005-12-19 18:59:29 UTC (rev 8757) </span><span class="lines">@@ -74,7 +74,7 @@ </span><span class="cx"> self.rv.findPath('//Schema/Core/Text')) self.assertEqual(schema.itemFor(Other.thing, self.rv).getAspect('type'), schema.itemFor(Dummy, self.rv)) </span><span class="rem">- self.assertRaises(TypeError, schema.Role, str) </span><span class="add">+ self.assertRaises(TypeError, schema.Descriptor, str) </span><span class="cx"> def testImportAll(self): schema.initRepository(self.rv) </span></pre></div> <a id="trunkchandlerparcelsfeedschannelspy"></a> <div class="modfile"><h4>Modified: trunk/chandler/parcels/feeds/channels.py (8756 => 8757)</h4> <pre class="diff"> <span class="info">--- trunk/chandler/parcels/feeds/channels.py 2005-12-19 18:28:47 UTC (rev 8756) +++ trunk/chandler/parcels/feeds/channels.py 2005-12-19 18:59:29 UTC (rev 8757) </span><span class="lines">@@ -118,8 +118,8 @@ </span><span class="cx"> sharing = schema.Cloud(author, copyright, link, url) ) </span><span class="rem">- who = schema.Role(redirectTo=&quot;author&quot;) - about = schema.Role(redirectTo=&quot;about&quot;) </span><span class="add">+ who = schema.Descriptor(redirectTo=&quot;author&quot;) + about = schema.Descriptor(redirectTo=&quot;about&quot;) </span><span class="cx"> def Update(self, data=None): #getattr returns a unicode object which needs to be converted to bytes for </span><span class="lines">@@ -292,9 +292,9 @@ </span><span class="cx"> displayName=u&quot;Content&quot; ) </span><span class="rem">- about = schema.Role(redirectTo=&quot;displayName&quot;) - who = schema.Role(redirectTo=&quot;author&quot;) - body = schema.Role(redirectTo=&quot;content&quot;) </span><span class="add">+ about = schema.Descriptor(redirectTo=&quot;displayName&quot;) + who = schema.Descriptorence:: </span><span class="rem">- &gt;&gt;&gt; testRole.type == schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type == schema.Item </span><span class="cx"> True </span><span class="rem">- &gt;&gt;&gt; testRole.type != schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type != schema.Item </span><span class="cx"> False Aspect Attributes </span><span class="rem">- Role objects support setting all of the aspects of a repository </span><span class="add">+ Descriptor objects support setting all of the aspects of a repository </span><span class="cx"> ``Attribute``, including ``required``, ``persisted``, ``indexed``, ``cardinality``, ``defaultValue``, ``initialValue``, ``inheritFrom``, ``redirectTo``, ``otherName``, ``companion``, ``deletePolicy``, ``copyPolicy``, ``countPolicy``, ``type``, ``superAttribute``, ``displayName``, and ``description``. You can supply any of these as </span><span class="rem">- keyword arguments to a Role constructor (such as ``schema.One``, </span><span class="add">+ keyword arguments to a Descriptor constructor (such as ``schema.One``, </span><span class="cx"> ``schema.Many``, etc.), in order to set the corresponding value for the attribute. Unspecified aspects will take on their normal default values, except for ``otherName``, which is set to ``inverse.name`` by default, if the attribute has an inverse. </span><span class="rem">-To avoid silent definition errors, ``Role`` cl=> Fri, 10 Nov, 20:57
foundation.org riptor object %r cannot be modified after use&quot; % self </span><span class="cx"> ) self._setattr(attr, value) </span><span class="lines">@@ -261,7 +261,7 @@ </span><span class="cx"> def __repr__(self): if self.name and self.owner: </span><span class="rem">- return &quot;&lt;Role %s of %s&gt;&quot; % (self.name,self.owner) </span><span class="add">+ return &quot;&lt;Descriptor %s of %s&gt;&quot; % (self.name,self.owner) </span><span class="cx"> return object.__repr__(self) def __setDoc(self,val): </span><span class="lines">@@ -357,19 +357,19 @@ </span><span class="cx"> itemFor(self.inverse, view) </span><span class="rem">-class One(Role): </span><span class="add">+class One(Descriptor): </span><span class="cx"> cardinality = 'single' </span><span class="rem">-class Many(Role): </span><span class="add">+class Many(Descriptor): </span><span class="cx"> cardinality = 'set' </span><span class="rem">-class Sequence(Role): </span><span class="add">+class Sequence(Descriptor): </span><span class="cx"> cardinality = 'list' </span><span class="rem">-class Mapping(Role): </span><span class="add">+class Mapping(Descriptor): </span><span class="cx"> cardinality = 'dict' </span><span class="lines">@@ -411,7 +411,7 @@ </span><span class="cx"> class AttributeAsEndpoint(Endpoint): </span><span class="rem">- &quot;&quot;&quot;Adapt a Role or attribute name to use as an Endpoint factory&quot;&quot;&quot; </span><span class="add">+ &quot;&quot;&quot;Adapt a Descriptor or attribute name to use as an Endpoint factory&quot;&quot;&quot; </span><span class="cx"> def __new__(cls, attr, policy): if isinstance(attr, Endpoint): </span><span class="lines">@@ -423,7 +423,7 @@ </span><span class="cx"> def __init__(self, attr, policy): if isinstance(attr,str): super(AttributeAsEndpoint,self).__init__(attr,(attr,), policy) </span><span class="rem">- elif isinstance(attr,Role): </span><span class="add">+ elif isinstance(attr,Descriptor): </span><span class="cx"> self.attr = attr super(AttributeAsEndpoint,self).__init__(None,(),policy) else: </span><span class="lines">@@ -525,7 +525,7 @@ </span><span class="cx"> kind.classes = {'python': cls } kind.attributes = [] for name,attr in cls.__dict__.items(): </span><span class="rem">- if isinstance(attr,Role): </span><span class="add">+ if isinstance(attr,Descriptor): </span><span class="cx"> ai = itemFor(attr, view) if ai not in kind.attributes: kind.attributes.append(ai,name) </span><span class="lines">@@ -689,7 +689,7 @@ </span><span class="cx"> def __init__(cls,name,bases,cdict): for name,ob in cdict.items(): </span><span class="rem">- if isinstance(ob,Role): </span><span class="add">+ if isinstance(ob,Descriptor): </span><span class="cx"> basename = &quot;%s.%s.&quot; % (parcel_name(cls.__module__), cls.__name__) ob.annotates = _target_type(cls), ob.activateInClass(cls,basename+name) </span><span class="lines">@@ -1182,7 +1182,7 @@ </span><span class="cx"> def _create_schema_item(self,view): # Create a temporary item without a kind, so as not to </span><span class="rem">- # incur unintended </span><span class="add">+ # incur unintended circularities. </span><span class="cx"> return Base(&quot;tmp_parcel_for-&quot;+self.moduleName, view, None) def _init_schema_item(self,item,view): </span></pre></div> <a id="trunkchandlerapplicationschema_apitxt"></a> <div class="modfile"><h4>Modified: trunk/chandler/application/schema_api.txt (8756 => 8757)</h4> <pre class="diff"> <span class="info">--- trunk/chandler/application/schema_api.txt 2005-12-19 18:28:47 UTC (rev 8756) +++ trunk/chandler/application/schema_api.txt 2005-12-19 18:59:29 UTC (rev 8757) </span><span class="lines">@@ -8,36 +8,15 @@ </span><span class="cx"> &gt;&gt;&gt; from repository.persistence.RepositoryView import NullRepositoryView </span><span class="rem">------------- -Introduction ------------- </span><span class="add">+------------------ +Descriptor Objects +------------------ </span><span class="cx"> </span><span class="rem">-TODO </span><span class="add">+The ``Descriptor`` Base Type +============================= </span><span class="cx"> </span><span class="rem">------------- -Role Objects ------------- - -The ``One``, ``Many``, ``Sequence``, and ``Mapping`` classes are all used to -define roles. They are all essentially identical except for their -``cardinality`` attribute, which controls how the repository will store the -attribute's value:: - - &gt;&gt;&gt; schema.One.cardinality - 'single' - &gt;&gt;&gt; schema.Many.cardinality - 'set' - &gt;&gt;&gt; schema.Sequence.cardinality - 'list' - &gt;&gt;&gt; schema.Mapping.cardinality - 'dict' - - -The ``Role`` Base Type -====================== - -The base class for roles is ``schema.Role``. It provides most of the -default behavior of roles, so rather than duplicate examples for each </span><span class="add">+The base class for roles is ``schema.Descriptor``. It provides most of the +default behavior of descriptors, so rather than duplicate examples for each </span><span class="cx"> individual role type, we'll examine the default behaviors here. All role objects have at least the following attributes and methods: </span><span class="lines">@@ -47,39 +26,40 @@ </span><span class="cx"> relationship, or ``None`` if the role has not been registered with a class yet:: </span><span class="rem">- &gt;&gt;&gt; role = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role.name None &gt;&gt;&gt; class anEntity(schema.Item): </span><span class="rem">- ... aRole = role </span><span class="add">+ ... aDescriptor = role </span><span class="cx"> &gt;&gt;&gt; role.name </span><span class="rem">- 'aRole' </span><span class="add">+ 'aDescriptor' </span><span class="cx"> ``owner`` (read-only) The entity or relationship class in which the role was defined, or ``None`` if the role has not been registered with a class yet:: </span><span class="rem">- &gt;&gt;&gt; role = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role.owner None &gt;&gt;&gt; class anEntity(schema.Item): </span><span class="rem">- ... aRole = role </span><span class="add">+ ... aDescriptor = role </span><span class="cx"> &gt;&gt;&gt; role.owner &lt;class '...anEntity'&gt; </span><span class="rem">- If a role's owner is an ``Item`` class, then setting ``aRole.inverse`` will - invoke ``aRole.inverse.addType(aRole.owner)``, so that the inverse role - will accept instances of the first role's owning type. This allows you </span><span class="add">+ If a role's owner is an ``Item`` class, then setting + ``aDescriptor.inverse`` will invoke + ``aDescriptor.inverse.addType(aDescriptor.owner)``, so that the inverse + role will accept instances of the first role's owning type. This allows you </span><span class="cx"> to easily define bidirectional links without &quot;forward references&quot;; just leave off the `type` argument in both role definitions, and specify an `inverse` argument for the second:: &gt;&gt;&gt; class anotherEntity(schema.Item): </span><span class="rem">- ... otherRole = schema.Role(inverse=anEntity.aRole) - &gt;&gt;&gt; anotherEntity.otherRole.type </span><span class="add">+ ... otherDescriptor=schema.Descriptor(inverse=anEntity.aDescriptor) + &gt;&gt;&gt; anotherEntity.otherDescriptor.type </span><span class="cx"> &lt;class '...anEntity'&gt; </span><span class="rem">- &gt;&gt;&gt; anEntity.aRole.type </span><span class="add">+ &gt;&gt;&gt; anEntity.aDescriptor.type </span><span class="cx"> &lt;class '...anotherEntity'&gt; As you can see, this ensures that both roles can accept the owning type of </span><span class="lines">@@ -115,17 +95,17 @@ </span><span class="cx"> | ... | Data and other attributes defined here: | </span><span class="rem">- | name = &lt;Role name of &lt;class '...Kind'&gt;&gt; </span><span class="add">+ | name = &lt;Descriptor name of &lt;class '...Kind'&gt;&gt; </span><span class="cx"> | Kind Name -- One(Text) | | This kind's name | </span><span class="rem">- | subkinds = &lt;Role subkinds of &lt;class '...Kind'&gt;&gt; </span><span class="add">+ | subkinds = &lt;Descriptor subkinds of &lt;class '...Kind'&gt;&gt; </span><span class="cx"> | Many(Kind) | | Sub-kinds of this kind | </span><span class="rem">- | superkinds = &lt;Role superkinds of &lt;class '...Kind'&gt;&gt; </span><span class="add">+ | superkinds = &lt;Descriptor superkinds of &lt;class '...Kind... </span><span class="cx"> | Many(Kind) | | Super-kinds of this kind </span><span class="lines">@@ -139,7 +119,7 @@ </span><span class="cx"> The ``doc`` and ``description`` are always strings, even if empty:: </span><span class="rem">- &gt;&gt;&gt; schema.Role().description </span><span class="add">+ &gt;&gt;&gt; schema.Descriptor().description </span><span class="cx"> '' ``inverse`` </span><span class="lines">@@ -152,10 +132,10 @@ </span><span class="cx"> ``inverse`` can be set via keyword argument to the role class' constructor:: </span><span class="rem">- &gt;&gt;&gt; role1 = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role1 = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role1.inverse None </span><span class="rem">- &gt;&gt;&gt; role2 = schema.Role(inverse=role1) </span><span class="add">+ &gt;&gt;&gt; role2 = schema.Descriptor(inverse=role1) </span><span class="cx"> &gt;&gt;&gt; role2.inverse is role1 True &gt;&gt;&gt; role1.inverse is role2 </span><span class="lines">@@ -163,8 +143,8 @@ </span><span class="cx"> Or by setting the ``inverse`` attribute after construction:: </span><span class="rem">- &gt;&gt;&gt; role1 = schema.Role() - &gt;&gt;&gt; role2 = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role1 = schema.Descriptor() + &gt;&gt;&gt; role2 = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; role2.inverse = role1 &gt;&gt;&gt; role2.inverse is role1 True </span><span class="lines">@@ -173,23 +153,23 @@ </span><span class="cx"> Once set, it cannot be changed, unless it is to the same role:: </span><span class="rem">- &gt;&gt;&gt; role2.inverse = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role2.inverse = schema.Descriptor() </span><span class="cx"> Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role objects are immutable; can't change 'inverse' ... once set </span><span class="add">+ TypeError: Descriptor objects are immutable; can't change 'inverse' ... </span><span class="cx"> &gt;&gt;&gt; role2.inverse is role1 # no change took place True And trying to insert a new role into an existing pair also fails:: </span><span class="rem">- &gt;&gt;&gt; role3 = schema.Role() </span><span class="add">+ &gt;&gt;&gt; role3 = schema.Descriptor() </span><span class="cx"> &gt;&gt;&gt; print role3.inverse None &gt;&gt;&gt; role3.inverse = role2 Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role objects are immutable; can't change 'inverse' ... once set </span><span class="add">+ TypeError: Descriptor objects are immutable; can't change 'inverse' ... </span><span class="cx"> &gt;&gt;&gt; print role3.inverse # no change took place None </span><span class="lines">@@ -210,7 +190,7 @@ </span><span class="cx"> &lt;class '...Folder'&gt; &gt;&gt;&gt; File.folder.inverse </span><span class="rem">- &lt;Role contents of &lt;class '...Folder'&gt;&gt; </span><span class="add">+ &lt;Descriptor contents of &lt;class '...Folder'&gt;&gt; </span><span class="cx"> ``type`` The ``type`` of a role can be either a ``schema.Item`` subclass, a </span><span class="lines">@@ -224,17 +204,17 @@ </span><span class="cx"> &gt;&gt;&gt; myType = schema.TypeReference('//Schema/Core/DateTime') </span><span class="rem">- &gt;&gt;&gt; print schema.Role(myType).__doc__ - Role(DateTime) </span><span class="add">+ &gt;&gt;&gt; print schema.Descriptor(myType).__doc__ + Descriptor(DateTime) </span><span class="cx"> Note that you cannot use arbitrary Python types or classes; you must either supply a ``schema.TypeReference``, a subclass of ``schema.Item``, or a string representing a forward reference:: </span><span class="rem">- &gt;&gt;&gt; schema.Role(str) </span><span class="add">+ &gt;&gt;&gt; schema.Descriptor(str) </span><span class="cx"> Traceback (most recent call last): ... </span><span class="rem">- TypeError: ('Attribute type must be Item/Enumeration class or TypeReference', ...) </span><span class="add">+ TypeError: ('...must be Item/Enumeration class or TypeReference',...) </span><span class="cx"> And type references must be to types defined by the repository's core schema:: </span><span class="lines">@@ -247,46 +227,47 @@ </span><span class="cx"> Types expressed as a string are automatically converted to ``ForwardReference`` objects:: </span><span class="rem">- &gt;&gt;&gt; testRole = schema.Role(&quot;application.schema.Item&quot;) - &gt;&gt;&gt; testRole.type - ForwardReference('application.schema.Item',&lt;...Role object...&gt;) </span><span class="add">+ &gt;&gt;&gt; testDescriptor = schema.Descriptor(&quot;application.schema.Item&quot;) + &gt;&gt;&gt; testDescriptor.type + ForwardReference('application.schema.Item',&lt;...Descriptor object...&gt;) </span><span class="cx"> Forward references compare equal to the type they reference:: </span><span class="rem">- &gt;&gt;&gt; testRole.type == schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type == schema.Item </span><span class="cx"> True </span><span class="rem">- &gt;&gt;&gt; testRole.type != schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type != schema.Item </span><span class="cx"> False Aspect Attributes </span><span class="rem">- Role objects support setting all of the aspects of a repository </span><span class="add">+ Descriptor objects support setting all of the aspects of a repository </span><span class="cx"> ``Attribute``, including ``required``, ``persisted``, ``indexed``, ``cardinality``, ``defaultValue``, ``initialValue``, ``inheritFrom``, ``redirectTo``, ``otherName``, ``companion``, ``deletePolicy``, ``copyPolicy``, ``countPolicy``, ``type``, ``superAttribute``, ``displayName``, and ``description``. You can supply any of these as </span><span class="rem">- keyword arguments to a Role constructor (such as ``schema.One``, </span><span class="add">+ keyword arguments to a Descriptor constructor (such as ``schema.One``, </span><span class="cx"> ``schema.Many``, etc.), in order to set the corresponding value for the attribute. Unspecified aspects will take on their normal default values, except for ``otherName``, which is set to ``inverse.name`` by default, if the attribute has an inverse. </span><span class="rem">-To avoid silent definition errors, ``Role`` classes will not allow setting -attributes that are not defined by their class:: </span><span class="add">+To avoid silent definition errors, ``Descriptor`` classes will not allow +setting attributes that are not defined by their class:: </span><span class="cx"> </span><span class="rem">- &gt;&gt;&gt; r = schema.Role(foo=&quot;bar&quot;) </span><span class="add">+ &gt;&gt;&gt; r = schema.Descriptor(foo=&quot;bar&quot;) </span><span class="cx"> Traceback (most recent call last): ... </span><span class="rem">- TypeError: 'foo' is not a public attribute of 'Role' objects </span><span class="add">+ TypeError: 'foo' is not a public attribute of 'Descriptor' objects </span><span class="cx"> </span><span class="rem">-And, to avoid unintentional alterations, Role attributes can be set only once:: </span><span class="add">+And, to avoid unintentional alterations, Descriptor attributes can be set only +once:: </span><span class="cx"> </span><span class="rem">- &gt;&gt;&gt; r = schema.Role(doc=&quot;x&quot;) </span><span class="add">+ &gt;&gt;&gt; r = schema.Descriptor(doc=&quot;x&quot;) </span><span class="cx"> &gt;&gt;&gt; r.doc = &quot;testing&quot; Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role objects are immutable; can't change 'doc' ... once set </span><span class="add">+ TypeError: Descriptor objects are immutable; can't change 'doc'... once set </span><span class="cx"> --------------- </span><span class="lines">@@ -305,7 +286,7 @@ </span><span class="cx"> ... children = schema.Sequence(inverse=parents) ... ... schema.addClouds( </span><span class="rem">- ... # endpoints can be defined using Role objects or strings </span><span class="add">+ ... # endpoints can be defined using Descriptor objects or strings </span><span class="cx"> ... sharing = schema.Cloud(byCloud=[parents,children]), ... export = schema.Cloud(byRef=[&quot;children&quot;]), ... ) </span><span class="lines">@@ -665,7 +646,7 @@ </span><span class="cx"> &gt;&gt;&gt; imp.description 'Description goes here' </span><span class="rem">- &gt;&gt;&gt; test_role = schema.Role(Importance) </span><span class="add">+ &gt;&gt;&gt; test_role = schema.Descriptor(Importance) </span><span class="cx"> &gt;&gt;&gt; imp.values ['high', 'medium', 'low'] </span><span class="lines">@@ -1055,7 +1036,7 @@ </span><span class="cx"> True </span><span class="rem">- Meanwhile, ``schema.itemFor(aRole)`` returns a repository ``Attribute`` </span><span class="add">+ Meanwhile, ``schema.itemFor(aDescriptor)`` returns a repository ``Attribute`` </span><span class="cx"> object representing that attribute in the null view:: &gt;&gt;&gt; schema.itemFor(Kind.subkinds, rv) </span><span class="lines">@@ -1079,7 +1060,7 @@ </span><span class="cx"> &gt;&gt;&gt; schema.itemFor(Kind.subkinds, rv).description is Kind.subkinds.doc True </span><span class="rem">- Roles must be activated in a class, however, in order to generate their </span><span class="add">+ Descriptors must be activated in a class, however, in order to generate their </span><span class="cx"> ``Attribute``:: &gt;&gt;&gt; schema.itemFor(schema.One(), rv) </span><span class="lines">@@ -1093,7 +1074,7 @@ </span><span class="cx"> &gt;&gt;&gt; Kind.subkinds.redirectTo = &quot;xyz&quot; Traceback (most recent call last): ... </span><span class="rem">- TypeError: Role object &lt;Role subkinds of &lt;class '...Kind'&gt;&gt; cannot be modified after use </span><span class="add">+ TypeError: Descriptor object &lt;Descriptor subkinds of &lt;class '...Kind'&gt;&gt; cannot be modified after use </span><span class="cx"> ``initRepository(repoView)`` Ensure that the given repository view has been initialized with the core </span><span class="lines">@@ -1230,8 +1211,8 @@ </span><span class="cx"> &gt;&gt;&gt; class Test1(object): ... __metaclass__ = schema.Activator </span><span class="rem">- ... aRole = MockAttr() - activated 'aRole' in &lt;class 'Test1'&gt; </span><span class="add">+ ... aDescriptor = MockAttr() + activated 'aDescriptor' in &lt;class 'Test1'&gt; </span><span class="cx"> &gt;&gt;&gt; class Test2(Test1): ... test = MockAttr() </span></pre></div> <a id="trunkchandlerapplicationtestsTestSchemaAPIpy"></a> <div class="modfile"><h4>Modified: trunk/chandler/application/tests/TestSchemaAPI.py (8756 => 8757)</h4> <pre class="diff"> <span class="info">--- trunk/chandler/application/tests/TestSchemaAPI.py 2005-12-19 18:28:47 UTC (rev 8756) +++ trunk/chandler/application/tests/TestSchemaAPI.py 2005-12-19 18:59:29 UTC (rev 8757) </span><span class="lines">@@ -74,7 +74,7 @@ </span><span class="cx"> self.rv.findPath('//Schema/Core/Text')) self.assertEqual(schema.itemFor(Other.thing, self.rv).getAspect('type'), schema.itemFor(Dummy, self.rv)) </span><span class="rem">- self.assertRaises(TypeError, schema.Role, str) </span><span class="add">+ self.assertRaises(TypeError, schema.Descriptor, str) </span><span class="cx"> def testImportAll(self): schema.initRepository(self.rv) </span></pre></div> <a id="trunkchandlerparcelsfeedschannelspy"></a> <div class="modfile"><h4>Modified: trunk/chandler/parcels/feeds/channels.py (8756 => 8757)</h4> <pre class="diff"> <span class="info">--- trunk/chandler/parcels/feeds/channels.py 2005-12-19 18:28:47 UTC (rev 8756) +++ trunk/chandler/parcels/feeds/channels.py 2005-12-19 18:59:29 UTC (rev 8757) </span><span class="lines">@@ -118,8 +118,8 @@ </span><span class="cx"> sharing = schema.Cloud(author, copyright, link, url) ) </span><span class="rem">- who = schema.Role(redirectTo=&quot;author&quot;) - about = schema.Role(redirectTo=&quot;about&quot;) </span><span class="add">+ who = schema.Descriptor(redirectTo=&quot;author&quot;) + about = schema.Descriptor(redirectTo=&quot;about&quot;) </span><span class="cx"> def Update(self, data=None): #getattr returns a unicode object which needs to be converted to bytes for </span><span class="lines">@@ -292,9 +292,9 @@ </span><span class="cx"> displayName=u&quot;Content&quot; ) </span><span class="rem">- about = schema.Role(redirectTo=&quot;displayName&quot;) - who = schema.Role(redirectTo=&quot;author&quot;) - body = schema.Role(redirectTo=&quot;content&quot;) </span><span class="add">+ about = schema.Descriptor(redirectTo=&quot;displayName&quot;) + who = schema.Descriptorence:: </span><span class="rem">- &gt;&gt;&gt; testRole.type == schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type == schema.Item </span><span class="cx"> True </span><span class="rem">- &gt;&gt;&gt; testRole.type != schema.Item </span><span class="add">+ &gt;&gt;&gt; testDescriptor.type != schema.Item </span><span class="cx"> False Aspect Attributes </span><span class="rem">- Role objects support setting all of the aspects of a repository </span><span class="add">+ Descriptor objects support setting all of the aspects of a repository </span><span class="cx"> ``Attribute``, including ``required``, ``persisted``, ``indexed``, ``cardinality``, ``defaultValue``, ``initialValue``, ``inheritFrom``, ``redirectTo``, ``otherName``, ``companion``, ``deletePolicy``, ``copyPolicy``, ``countPolicy``, ``type``, ``superAttribute``, ``displayName``, and ``description``. You can supply any of these as </span><span class="rem">- keyword arguments to a Role constructor (such as ``schema.One``, </span><span class="add">+ keyword arguments to a Descriptor constructor (such as ``schema.One``, </span><span class="cx"> ``schema.Many``, etc.), in order to set the corresponding value for the attribute. Unspecified aspects will take on their normal default values, except for ``otherName``, which is set to ``inverse.name`` by default, if the attribute has an inverse. </span><span class="rem">-To avoid silent definition errors, ``Role`` cl=> Fri, 10 Nov, 20:57
Message listThread · Author · Date
Box list
Jul 20091
Apr 20091
Oct 20081
Sep 20082
Aug 20082
Jul 20081
Jun 20082
May 20081
Mar 20082
Feb 20083
Jan 20082
Dec 20073
Nov 20074
Oct 20076
Sep 20076
Aug 20072
Jul 20071
Jun 20071
May 20071
Feb 20072
Nov 20063
Oct 20061
Sep 20062
May 20062
Mar 20066
Feb 20066
Jan 20063
Dec 20052
Nov 20052
Oct 20051
Sep 20058
Aug 20053
Jul 20054
Jun 20052
May 20052
Apr 20053
Mar 20057
Feb 20051
Jan 20053
Nov 20041
Oct 20043
Sep 20041
Aug 20041
Jul 20043
Jun 20043
May 20041
Apr 20041
Mar 20044
Feb 20042
Jan 20043
Dec 20036
Nov 20033
Oct 20036
Sep 20036
Apr 20033
Mar 20031
Feb 20032
Jan 20031
Nov 20021