77from .utils import classproperty , describe_task , matching_source
88from .identification import to_mime_format_name
99from .converter import SubtypeVar
10- from .exceptions import FileFormatsError , FormatMismatchError , FormatRecognitionError
10+ from .exceptions import (
11+ FormatMismatchError ,
12+ FormatRecognitionError ,
13+ FormatDefinitionError ,
14+ )
1115
1216
1317logger = logging .getLogger ("fileformats" )
@@ -95,7 +99,7 @@ def version(self) -> ty.Union[str, ty.Tuple[str]]:
9599 )
96100 version = tuple (b .decode ("utf-8" ) for b in match .groups ())
97101 if not version :
98- raise FileFormatsError (
102+ raise FormatDefinitionError (
99103 f"No version patterns found in magic pattern of { type (self ).__name__ } "
100104 f"class, { self .magic_pattern } "
101105 )
@@ -278,7 +282,7 @@ def my_func(file: MyFormatWithClassifiers[Integer]):
278282
279283 def _validate_class (self ):
280284 if self .wildcard_classifiers ():
281- raise FileFormatsError (
285+ raise FormatDefinitionError (
282286 f"Can instantiate { type (self )} class as it has wildcard classifiers "
283287 "and therefore should only be used for converter specifications"
284288 )
@@ -317,7 +321,7 @@ def __class_getitem__(cls, classifiers):
317321 if not any (issubclass (q , t ) for t in cls .allowed_classifiers )
318322 ]
319323 if not_allowed :
320- raise FileFormatsError (
324+ raise FormatDefinitionError (
321325 f"Invalid content types provided to { cls } (must be subclasses of "
322326 f"{ cls .allowed_classifiers } ): { not_allowed } "
323327 )
@@ -339,7 +343,7 @@ def __class_getitem__(cls, classifiers):
339343 repetitions [exc_classifier ].append (classifier )
340344 repeated = [t for t in repetitions .items () if len (t [1 ]) > 1 ]
341345 if repeated :
342- raise FileFormatsError (
346+ raise FormatDefinitionError (
343347 "Cannot have more than one occurrence of a classifier "
344348 f"or subclasses for { cls } class when "
345349 f"{ cls .__name__ } .ordered_classifiers is false:\n "
@@ -351,8 +355,9 @@ def __class_getitem__(cls, classifiers):
351355 classifiers = frozenset (classifiers )
352356 else :
353357 if len (classifiers ) > 1 :
354- raise FileFormatsError (
355- f"Multiple classifiers not permitted for { cls } types, provided: ({ classifiers } )"
358+ raise FormatDefinitionError (
359+ f"Multiple classifiers not permitted for { cls } types, provided: "
360+ f"({ classifiers } )"
356361 )
357362 # Make sure that the "classified" dictionary is present in this class not super
358363 # classes
@@ -363,26 +368,26 @@ def __class_getitem__(cls, classifiers):
363368 classified = cls ._classified_subtypes [classifiers ]
364369 except KeyError :
365370 if not hasattr (cls , "classifiers_attr_name" ):
366- raise FileFormatsError (
371+ raise FormatDefinitionError (
367372 f"{ cls } needs to define the 'classifiers_attr_name' class attribute "
368373 "with the name of the (different) class attribute to hold the "
369374 "classified types"
370375 )
371376 if cls .classifiers_attr_name is None :
372- raise FileFormatsError (
377+ raise FormatDefinitionError (
373378 f"Inherited classifiers have been disabled in { cls } (by setting "
374379 f'"classifiers_attr_name)" to None)'
375380 )
376381 try :
377382 classifiers_attr = getattr (cls , cls .classifiers_attr_name )
378383 except AttributeError :
379- raise FileFormatsError (
384+ raise FormatDefinitionError (
380385 f"Default value for classifiers attribute "
381386 f"'{ cls .classifiers_attr_name } ' needs to be set in { cls } "
382387 )
383388 else :
384389 if classifiers_attr :
385- raise FileFormatsError (
390+ raise FormatDefinitionError (
386391 f"Default value for classifiers attribute "
387392 f"'{ cls .classifiers_attr_name } ' needs to be set in { cls } "
388393 )
@@ -571,18 +576,18 @@ def register_converter(
571576 if cls .wildcard_classifiers ():
572577 if issubclass (source_format , SubtypeVar ):
573578 if len (cls .wildcard_classifiers ()) > 1 :
574- raise FileFormatsError (
579+ raise FormatDefinitionError (
575580 "Can only have one wildcard qualifier when registering a converter "
576581 f"to { cls } from a generic type, found { cls .wildcard_classifiers ()} "
577582 )
578583 elif not source_format .is_classified :
579- raise FileFormatsError (
584+ raise FormatDefinitionError (
580585 "Can only use wildcard classifiers when registering a converter "
581586 f"from a generic type or similarly classified type, not { source_format } "
582587 )
583588 else :
584589 if cls .wildcard_classifiers () != source_format .wildcard_classifiers ():
585- raise FileFormatsError (
590+ raise FormatDefinitionError (
586591 f"Mismatching wildcards between source format, { source_format } "
587592 f"({ list (source_format .wildcard_classifiers ())} ), and target "
588593 f"{ cls } ({ cls .wildcard_classifiers ()} )"
@@ -612,7 +617,7 @@ def register_converter(
612617 describe_task (task ),
613618 )
614619 return # actually the same task but just imported twice for some reason
615- raise FileFormatsError (
620+ raise FormatDefinitionError (
616621 f"Cannot register converter from { prev .unclassified } "
617622 f"to { cls .unclassified } with non-wildcard classifiers "
618623 f"{ list (prev .non_wildcard_classifiers ())} , { describe_task (task )} , "
0 commit comments