File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -381,6 +381,19 @@ ImagingError_ModeError(void) {
381381 return NULL ;
382382}
383383
384+ // Derives from both NotImplementedError and ValueError
385+ // (as the functions above raise ValueErrors).
386+ static PyObject * ImagingNotSupportedError = NULL ;
387+
388+ void *
389+ ImagingError_NotSupportedError (const char * message ) {
390+ PyErr_SetString (
391+ ImagingNotSupportedError ? ImagingNotSupportedError : PyExc_NotImplementedError ,
392+ (message ) ? (char * )message : "operation not supported"
393+ );
394+ return NULL ;
395+ }
396+
384397void *
385398ImagingError_ValueError (const char * message ) {
386399 PyErr_SetString (
@@ -4328,6 +4341,24 @@ setup_module(PyObject *m) {
43284341 return -1 ;
43294342 }
43304343
4344+ if (ImagingNotSupportedError == NULL ) {
4345+ // NotSupportedError derives from both NotImplementedError and ValueError,
4346+ // for compatibility with `except ValueError`.
4347+ PyObject * bases = PyTuple_Pack (2 , PyExc_NotImplementedError , PyExc_ValueError );
4348+ if (bases == NULL ) {
4349+ return -1 ;
4350+ }
4351+ ImagingNotSupportedError =
4352+ PyErr_NewException ("PIL._imaging.NotSupportedError" , bases , NULL );
4353+ Py_DECREF (bases );
4354+ if (ImagingNotSupportedError == NULL ) {
4355+ return -1 ;
4356+ }
4357+ }
4358+ if (PyModule_AddObjectRef (m , "NotSupportedError" , ImagingNotSupportedError ) < 0 ) {
4359+ return -1 ;
4360+ }
4361+
43314362#ifdef HAVE_LIBJPEG
43324363 {
43334364 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