<div dir="ltr">Hi Christopher,<div class="gmail_extra"><br><div class="gmail_quote">On 9 June 2014 16:29, Christopher Lozinski <span dir="ltr"><<a href="mailto:lozinski@freerecruiting.com" target="_blank">lozinski@freerecruiting.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Here is an extract from the principalannotation configure.zcml file.<br>


<br>
   <adapter factory=".utility.annotations" /><br>
<br>
  <adapter<br>
      for="zope.security.interfaces.<u></u>IPrincipal *"<br>
      factory=".utility.annotations"<br>
      /><br>
<br>
Clearly something is wrong.  Two copies, and no "provides" line.</blockquote><div><br></div><div>The <adapter /> element only needs the `for` and `provides` attributes if you want to give different values than the ones already declared on the factory, or if the factory doesn't have them. In the case of `.utility.annotations` those are, respectively:</div>

<div><br></div><div> * zope.security.interfaces.IPrincipal</div><div> * zope.annotation.interfaces.IAnnotations</div><div><br></div><div>As can be seen here:</div><div><br></div><div><a href="https://github.com/zopefoundation/zope.principalannotation/blob/master/src/zope/principalannotation/utility.py#L122-L126">https://github.com/zopefoundation/zope.principalannotation/blob/master/src/zope/principalannotation/utility.py#L122-L126</a><br>

</div><div><br></div><div>The second <adapter /> element creates a multi-adapter from (IPrincipal, Interface) to IAnnotations.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


So I tried fixing it.<br>
<br>
  <adapter<br>
      factory=".utility.annotations"<br>
      provides="zope.annotation.<u></u>interfaces.IAnnotations"<br>
      for="zope.principalregistry.<u></u>principalregistry.Principal"<br>
      /><br>
<br>
No luck.  I still get the following error report.  Cannot adapt.<br>
<br>
  File "/root/.buildout/eggs/zope.<u></u>app.container-3.9.2-py2.7.egg/<u></u>zope/app/container/browser/<u></u>contents.py", line 462, in getPrincipalClipboard<br>
    annotations = IAnnotations(user)<br>
TypeError: ('Could not adapt', <zope.principalregistry.<u></u>principalregistry.Principal object at 0x80bae03d0>, <InterfaceClass zope.annotation.interfaces.<u></u>IAnnotations>)<br>
<br>
I am running the most recent release of grok, to which I added<br>
<br>
zope.principalannotation.<br>
<br>
<br>
I am trying to adapt the user object.<br>
(Pdb) user<br>
<zope.principalregistry.<u></u>principalregistry.Principal object at 0x80bae03d0><br>
<br>
<br>
Here is what I have tried so far.<br>
<br>
Maybe I am not installing it correctly. So I inserted a typo in the principalannotation configuration file, and sure enough I got an error report<br>
<br>
<br>
So let me see if the adapter is loaded.<br>
<br>
<br>
(Pdb) from zope.component import getGlobalSiteManager<br>
(Pdb) gsm = getGlobalSiteManager()<br>
(Pdb) gsm.adapters._adapters<br>
<br>
A long list is returned, but searching on<br>
zope.annotation.interfaces.<u></u>IAnnotations<br>
gives me<br>
<br>
<implementedBy zope.principalregistry.<u></u>principalregistry.Principal>: {<InterfaceClass zope.annotation.interfaces.<u></u>IAnnotations\<br>
>: {u'': <function annotations at 0x80b983230>}},<br>
<br>
Okay, so it is in the list of adapters, but getAdapter seems to have a problem.<br>
<br>
<br>
(Pdb)  from zope.component import getAdapter<br>
(Pdb) from zope.annotation.interfaces  import IAnnotations<br>
<br>
(Pdb) getAdapter(user,IAnnotations)<br>
*** ComponentLookupError: (<zope.principalregistry.<u></u>principalregistry.Principal object at 0x80bae03d0>, <InterfaceClass zope.annotation.interfaces.<u></u>IAnnotations>, u'')<br>
<br></blockquote><div><br></div><div><div>In the code I linked above, the adapter factory tries to look up a `IPrincipalAnnotationUtility` (while ignoring the context parameter, which is bad form, but likely not the cause of your troubles).</div>

<div><br></div><div>Maybe you're getting the adaptation error because you don't have an `IPrincipalAnnotationUtilty` utility?</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
For those interested in the context, I am trying to put up a Zope 2 style ZMI on top of grok. For the cut copy paste interface, it needs to store the objects somewhere, presumably on the principal, but since principals are transient objects, the principal annotation package  stores the data persistently.<br>


<br>
I am not sure what to try next.  Any advice would be most appreciated.<br></blockquote><div><br></div><div>For this immediate problem, perhaps you need to register an `IPrincipalAnnotationUtility`. The file I linked above contains a persistent implementation, suitable registration on a local site manager. "persistent" means it won't be there by default until you actually register it.</div>

<div><br></div><div>For the more generic problem of a Zope2 like management interface on top of ZODB storage containing a copy+paste implementation, done on modern libraries (including a zca registry), you could try SubstanceD:</div>

<div><br></div><div><a href="http://substanced.readthedocs.org/">http://substanced.readthedocs.org/</a><br></div><div><br></div><div>Cheers,</div><div><br></div><div>Leo</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
Christopher Lozinski<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Zope-Dev maillist  -  <a href="mailto:Zope-Dev@zope.org" target="_blank">Zope-Dev@zope.org</a><br>
<a href="https://mail.zope.org/mailman/listinfo/zope-dev" target="_blank">https://mail.zope.org/mailman/<u></u>listinfo/zope-dev</a><br>
**  No cross posts or HTML encoding!  **<br>
(Related lists -<br>
<a href="https://mail.zope.org/mailman/listinfo/zope-announce" target="_blank">https://mail.zope.org/mailman/<u></u>listinfo/zope-announce</a><br>
<a href="https://mail.zope.org/mailman/listinfo/zope" target="_blank">https://mail.zope.org/mailman/<u></u>listinfo/zope</a> )<br>
</blockquote></div><br></div></div>