File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -382,6 +382,19 @@ ImagingError_ModeError(void) {
382382 return NULL ;
383383}
384384
385+ // Derives from both NotImplementedError and ValueError
386+ // (as the functions above raise ValueErrors).
387+ static PyObject * ImagingNotSupportedError = NULL ;
388+
389+ void *
390+ ImagingError_NotSupportedError (const char * message ) {
391+ PyErr_SetString (
392+ ImagingNotSupportedError ? ImagingNotSupportedError : PyExc_NotImplementedError ,
393+ (message ) ? (char * )message : "operation not supported"
394+ );
395+ return NULL ;
396+ }
397+
385398void *
386399ImagingError_ValueError (const char * message ) {
387400 PyErr_SetString (
@@ -4326,6 +4339,24 @@ setup_module(PyObject *m) {
43264339 return -1 ;
43274340 }
43284341
4342+ if (ImagingNotSupportedError == NULL ) {
4343+ // NotSupportedError derives from both NotImplementedError and ValueError,
4344+ // for compatibility with `except ValueError`.
4345+ PyObject * bases = PyTuple_Pack (2 , PyExc_NotImplementedError , PyExc_ValueError );
4346+ if (bases == NULL ) {
4347+ return -1 ;
4348+ }
4349+ ImagingNotSupportedError =
4350+ PyErr_NewException ("PIL._imaging.NotSupportedError" , bases , NULL );
4351+ Py_DECREF (bases );
4352+ if (ImagingNotSupportedError == NULL ) {
4353+ return -1 ;
4354+ }
4355+ }
4356+ if (PyModule_AddObjectRef (m , "NotSupportedError" , ImagingNotSupportedError ) < 0 ) {
4357+ return -1 ;
4358+ }
4359+
43294360#ifdef HAVE_LIBJPEG
43304361 {
43314362 extern const char * ImagingJpegVersion (void );
Original file line number Diff line number Diff line change @@ -273,6 +273,10 @@ extern void *
273273ImagingError_Mismatch (void ); /* maps to ValueError by default */
274274extern void *
275275ImagingError_ValueError (const char * message );
276+ extern void *
277+ ImagingError_NotSupportedError (
278+ const char * message
279+ ); /* derives from NotImplementedError and ValueError */
276280
277281/* Transform callbacks */
278282/* ------------------- */
You can’t perform that action at this time.
0 commit comments