Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Acquisition
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Acquisition
Commits
cdfad147
Commit
cdfad147
authored
Oct 29, 2014
by
Tres Seaver
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make module-level 'aq_acquire' respect 'default'.
Fixes LP #1387363.
parent
7b5c5fd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
5 deletions
+30
-5
CHANGES.txt
CHANGES.txt
+3
-0
src/Acquisition/_Acquisition.c
src/Acquisition/_Acquisition.c
+24
-5
src/Acquisition/tests.py
src/Acquisition/tests.py
+3
-0
No files found.
CHANGES.txt
View file @
cdfad147
...
...
@@ -4,6 +4,9 @@ Changelog
4.0.1 (unreleased)
------------------
- Make module-level ``aq_acquire`` API respect the ``default`` parameter.
LP #1387363.
- Don't raise an attribute error for ``__iter__`` if the fallback to
``__getitem__`` succeeds. LP #1155760.
...
...
src/Acquisition/_Acquisition.c
View file @
cdfad147
...
...
@@ -1499,12 +1499,14 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter,
if
(
filter
==
Py_None
)
filter
=
0
;
/* We got a wrapped object, so business as usual */
if
(
isWrapper
(
self
))
re
turn
Wrapper_findattr
(
if
(
isWrapper
(
self
))
{
re
sult
=
Wrapper_findattr
(
WRAPPER
(
self
),
name
,
filter
,
extra
,
OBJECT
(
self
),
1
,
explicit
||
WRAPPER
(
self
)
->
ob_type
==
(
PyTypeObject
*
)
&
Wrappertype
,
explicit
,
containment
);
goto
check_default
;
}
/* Not wrapped; check if we have a __parent__ pointer. If that's
the case, create a wrapper and pretend it's business as usual. */
else
if
((
result
=
PyObject_GetAttr
(
self
,
py__parent__
)))
...
...
@@ -1515,7 +1517,7 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter,
OBJECT
(
self
),
1
,
1
,
explicit
,
containment
);
/* Get rid of temporary wrapper */
Py_DECREF
(
self
);
return
res
ult
;
goto
check_defa
ult
;
}
/* No wrapper and no __parent__, so just getattr. */
else
...
...
@@ -1530,7 +1532,10 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter,
}
Py_XDECREF
(
result
);
Py_XDECREF
(
v
);
Py_XDECREF
(
tb
);
if
(
!
filter
)
return
PyObject_GetAttr
(
self
,
name
);
if
(
!
filter
)
{
result
=
PyObject_GetAttr
(
self
,
name
);
goto
check_default
;
}
/* Crap, we've got to construct a wrapper so we can use
Wrapper_findattr */
...
...
@@ -1542,8 +1547,22 @@ capi_aq_acquire(PyObject *self, PyObject *name, PyObject *filter,
/* Get rid of temporary wrapper */
Py_DECREF
(
self
);
return
res
ult
;
goto
check_defa
ult
;
}
check_default:
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
;
}
static
PyObject
*
...
...
src/Acquisition/tests.py
View file @
cdfad147
...
...
@@ -2527,6 +2527,9 @@ class TestAcquire(unittest.TestCase):
def
test_explicit_wrapper_false
(
self
):
self
.
assertEqual
(
self
.
a
.
b
.
c
.
aq_acquire
(
'z'
,
explicit
=
False
),
3
)
def
test_falls_back_to_default
(
self
):
self
.
assertEqual
(
self
.
acquire
(
object
(),
'nonesuch'
,
default
=
4
),
4
)
class
TestUnicode
(
unittest
.
TestCase
):
...
...
Kirill Smelkov
@kirr
mentioned in commit
6fb96530
·
Sep 19, 2016
mentioned in commit
6fb96530
mentioned in commit 6fb96530cb23074f21f6a38302aee4d4bd28fd80
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment