Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
persistent
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
persistent
Commits
31d240ae
Commit
31d240ae
authored
Aug 02, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C implementation, and add tests that BaseException isn't caught.
parent
1e9f7c42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
1 deletion
+82
-1
persistent/cPersistence.c
persistent/cPersistence.c
+61
-1
persistent/tests/test_persistence.py
persistent/tests/test_persistence.py
+21
-0
No files found.
persistent/cPersistence.c
View file @
31d240ae
...
...
@@ -1372,6 +1372,66 @@ Per_set_sticky(cPersistentObject *self, PyObject* value)
return
0
;
}
static
PyObject
*
repr_helper
(
PyObject
*
o
,
char
*
format
)
{
/* Returns a new reference, or NULL on error */
PyObject
*
exc_t
;
PyObject
*
exc_v
;
PyObject
*
exc_tb
;
PyObject
*
result
;
if
(
o
)
{
result
=
PyUnicode_FromFormat
(
format
,
o
);
if
(
!
result
&&
PyErr_Occurred
()
&&
PyErr_ExceptionMatches
(
PyExc_Exception
))
{
PyErr_Fetch
(
&
exc_t
,
&
exc_v
,
&
exc_tb
);
PyErr_NormalizeException
(
&
exc_t
,
&
exc_v
,
&
exc_tb
);
PyErr_Clear
();
result
=
PyUnicode_FromFormat
(
format
,
exc_v
);
Py_DECREF
(
exc_t
);
Py_DECREF
(
exc_v
);
Py_DECREF
(
exc_tb
);
}
}
else
{
result
=
PyUnicode_FromString
(
""
);
}
return
result
;
}
static
PyObject
*
Per_repr
(
cPersistentObject
*
self
)
{
PyObject
*
oid_str
=
NULL
;
PyObject
*
jar_str
=
NULL
;
PyObject
*
result
=
NULL
;
oid_str
=
repr_helper
(
self
->
oid
,
" oid %R"
);
if
(
!
oid_str
)
goto
cleanup
;
jar_str
=
repr_helper
(
self
->
jar
,
" in %R"
);
if
(
!
jar_str
)
goto
cleanup
;
result
=
PyUnicode_FromFormat
(
"<%s object at %p%S%S>"
,
Py_TYPE
(
self
)
->
tp_name
,
self
,
oid_str
,
jar_str
);
cleanup:
Py_XDECREF
(
oid_str
);
Py_XDECREF
(
jar_str
);
return
result
;
}
static
PyGetSetDef
Per_getsets
[]
=
{
{
"_p_changed"
,
(
getter
)
Per_get_changed
,
(
setter
)
Per_set_changed
},
{
"_p_jar"
,
(
getter
)
Per_get_jar
,
(
setter
)
Per_set_jar
},
...
...
@@ -1454,7 +1514,7 @@ static PyTypeObject Pertype = {
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_repr */
(
reprfunc
)
Per_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
...
...
persistent/tests/test_persistence.py
View file @
31d240ae
...
...
@@ -1789,6 +1789,27 @@ class _Persistent_Base(object):
"<persistent.Persistent object at 0xdeadbeef oid Exception('oid repr failed')"
" in Exception('jar repr failed')>"
)
def
test_repr_no_oid_repr_jar_raises_baseexception
(
self
):
p
=
self
.
_makeOne
()
class
Jar
(
object
):
def
__repr__
(
self
):
raise
BaseException
(
'jar repr failed'
)
p
.
_p_jar
=
Jar
()
with
self
.
assertRaisesRegex
(
BaseException
,
'jar repr failed'
):
repr
(
p
)
def
test_repr_oid_raises_baseexception_no_jar
(
self
):
p
=
self
.
_makeOne
()
class
BadOID
(
bytes
):
def
__repr__
(
self
):
raise
BaseException
(
"oid repr failed"
)
p
.
_p_oid
=
BadOID
(
b'12345678'
)
with
self
.
assertRaisesRegex
(
BaseException
,
'oid repr failed'
):
repr
(
p
)
def
test_repr_oid_and_jar
(
self
):
p
=
self
.
_makeOne
()
...
...
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