Re: [Zope3-dev] Your best Zope (3) tricks

2006-04-10 Thread ksmith99

full text indexing - http://opensource.zopyx.biz/OpenSource/TextIndexNG3
--
View this message in context: 
http://www.nabble.com/Your-best-Zope-%283%29-tricks-t1419460.html#a3851124
Sent from the Zope3 - dev forum at Nabble.com.

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] zope.i18n.translate ignores keyword arguments: desired/expected?

2006-04-10 Thread Gary Poster
Hi all.  in zope/i18n/__init__.py, the _translate method used by  
translate, if the msgid is a MessageID or a Message then the domain,  
default, and mapping are all used in preference to keyword arguments,  
even if, for instance, the keyword is non-None and the attribute is  
None.


Because of the immutability of Message, it would be nice if,  
minimally, the mapping keyword were honored.


My strawman is that all non-None `translate` keyword arguments should  
win over msgid values.


A valid counter-argument for domain, at least, is that this is really  
an attribute of the msgid, and overriding it effectively changes the  
msgid into an entirely different token.  But I'm tempted to go with  
simple logic and just say 'keywords override msgids'.


This seems to be in direct opposition with the current code, so I'm  
guessing someone put some thought behind the current behavior.  Would  
anyone care to champion it?


Gary
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: SVN: Zope3/trunk/src/zope/app/file/browser/ fixed the way absolute_url is retrieved in ImageData.tag()

2006-04-10 Thread Tarek Ziadé
Philipp von Weitershausen wrote:

>Tarek Ziadé wrote:
>  
>
>>Modified: Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py
>>===
>>--- Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py 
>>2006-04-09 21:31:11 UTC (rev 66754)
>>+++ Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py 
>>2006-04-10 01:09:35 UTC (rev 66755)
>>@@ -20,6 +20,9 @@
>> from zope.app.file.image import Image
>> from zope.app.file.browser.image import ImageData
>> 
>>+class FakeRequest(object):
>>+pass
>>+
>>
>>
>...
>  
>
>>+# faking absolute_url getter .
>>+def absolute_url(context, request):
>> return '/img'
>>
>>
>...
>  
>
>>+from zope.app import zapi
>>+old_absoluteURL = zapi.absoluteURL
>>+try:
>>+zapi.absoluteURL = absolute_url
>>+self.assertEqual(fe.tag(),
>>+'>/>')
>>+self.assertEqual(fe.tag(alt="Test Image"),
>>+'>+'height="-1" width="-1" border="0" />')
>>+self.assertEqual(fe.tag(height=100, width=100),
>>+('>+ 'width="100" border="0" />'))
>>+self.assertEqual(fe.tag(border=1),
>>+'>/>')
>>+self.assertEqual(fe.tag(css_class="Image"),
>>+'>+'height="-1" width="-1" border="0" class="Image" />')
>>+self.assertEqual(fe.tag(height=100, width="100",
>>+border=1, css_class="Image"),
>>+'>+'height="100" width="100" class="Image" border="1" />')
>>+finally:
>>+zapi.absoluteURL = old_absoluteURL
>>
>>
>
>Perhaps I may suggest an alternative solution for the test that won't
>require a) a monkey patch to zapi.absoluteURL nor b) a try/finally
>clause (which is pointless in a test since you really wouldn't want
>errors to be eaten away).
>  
>
b) errors are not eaten away with a finally clause, and still pops,
it is just here to make sure zapi.absoluteURL leaves the test in its
formal shape
no matters what happens.

>zapi.absoluteURL does nothing else than return a multiadapter from
>(object, request) to IAbsoluteURL. I would therefore recommend
>registering a stub IAbsoluteURL adapter instead of monkey patching a
>stub zapi.absoluteURL. This adapter would be very simple:
>
>class StubAbsoluteURL(object):
>adapts(ImageData, FakeRequest)
>implements(IAbsoluteURL)
>
>def __str__(self):
>return '/img'
>
>__call__ = __str__
>
>Then you only need to register it in the test:
>zope.component.provideAdapter(StubAbsoluteURL). Clean up will be handled
>if you call zope.component.testing.cleanUp() or make the test inherit
>from zope.component.testing.PlacelessSetup (zope.app.testing's
>PlacelessSetup would be overkill).
>
>  
>
Great, way better, i'll change to use your solution,
thanks

Regards,

Tarek

>Philipp
>
>  
>

___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com