Re: [Zope-dev] Re: SVN: Zope/branches/Zope-2_8-branch/ - Collector #1879: applied patch by Dieter Maurer to fix a bug in

2005-09-27 Thread Dieter Maurer
Florent Guillaume wrote at 2005-9-26 18:31 +0200:
This is the kind of thing that would *really* benefit from having unit
tests...

from Acquisition import Explicit
class A(Explicit): x = 1

...
def test_aq_acquire(self):
  ac = A()
  a = A().__of__(ac)
  self.assertEqual(a.aq_acquire('x'), 1)
  self.assertRaises(AttributeError, a.aq_acquire, 'y')
  self.assertEqual(a.aq_acquire('y', default=None), None)


Note, that aq_acquire has a lot more arguments -- not checked
by the above test (which checks just the fixed handling of the
argument default).


-- 
Dieter
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: SVN: Zope/branches/Zope-2_8-branch/ - Collector #1879: applied patch by Dieter Maurer to fix a bug in

2005-09-26 Thread Andreas Jung
You could convince Dieter to write unittests for his patches :-) On the 
other side his patches are in 99% of the cases trustworthy. Otherwise this 
bug would remain open.


-aj


--On 26. September 2005 18:31:27 +0200 Florent Guillaume [EMAIL PROTECTED] 
wrote:



This is the kind of thing that would *really* benefit from having unit
tests...

Florent


Andreas Jung  [EMAIL PROTECTED] wrote:

Log message for revision 38586:
- Collector #1879: applied patch by Dieter Maurer to fix a bug
in  ac_aquire() ignoring the default argument


Changed:
  U   Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
  U   Zope/branches/Zope-2_8-branch/lib/python/Acquisition/_Acquisition.c

-=-
Modified: Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
===
--- Zope/branches/Zope-2_8-branch/doc/CHANGES.txt   2005-09-24 12:01:37 UTC
(rev 38585)
+++ Zope/branches/Zope-2_8-branch/doc/CHANGES.txt   2005-09-24 12:10:07 UTC
(rev 38586)
@@ -31,6 +31,9 @@

 Bugs Fixed

+  - Collector #1879: applied patch by Dieter Maurer to fix a bug in
+ac_aquire() ignoring the default argument
+
   - Collector #1864, #1906: fixed header normalization in
   appendHeader()

   - Collector #1899: fixed migration issue when using export/import
   for

Modified:
Zope/branches/Zope-2_8-branch/lib/python/Acquisition/_Acquisition.c
=== ---
Zope/branches/Zope-2_8-branch/lib/python/Acquisition/_Acquisition.c
2005-09-24 12:01:37 UTC (rev 38585)
+++ Zope/branches/Zope-2_8-branch/lib/python/Acquisition/_Acquisition.c
2005-09-24 12:10:07 UTC (rev 38586)
@@ -1059,6 +1059,7 @@
   PyObject *expl=0, *defalt=0;
   int explicit=1;
   int containment=0;
+  PyObject *result; /* DM 2005-08-25: argument default ignored */

   UNLESS (PyArg_ParseTupleAndKeywords(
 args, kw, O|i, acquire_args+1,
@@ -1070,12 +1071,34 @@

   if (filter==Py_None) filter=0;

+  /* DM 2005-08-25: argument default ignored -- fix it! */
+# if 0
   return Wrapper_findattr(self,name,filter,extra,OBJECT(self),1,
  explicit ||
  self-ob_type==(PyTypeObject*)Wrappertype,
  explicit, containment);
+# else
+  result = Wrapper_findattr(self,name,filter,extra,OBJECT(self),1,
+ explicit ||
+ self-ob_type==(PyTypeObject*)Wrappertype,
+ explicit, containment);
+  if (result == NULL  defalt != NULL) {
+/* as Python/bltinmodule.c:builtin_getattr turn
+   only 'AttributeError' into a default value, such
+   that e.g. ConflictError and errors raised by the filter
+   are not mapped to the default value.
+*/
+if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+  PyErr_Clear();
+  Py_INCREF(defalt);
+  result = defalt;
+}
+  }
+  return result;
+# endif
 }

+
 static PyObject *
 Wrapper_inContextOf(Wrapper *self, PyObject *args)
 {



--
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of RD
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )






pgpdZrH2tR5rm.pgp
Description: PGP signature
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )