Coverage for sources/detextive/exceptions.py: 100%
13 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-12 18:11 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-12 18:11 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
4#============================================================================#
5# #
6# Licensed under the Apache License, Version 2.0 (the "License"); #
7# you may not use this file except in compliance with the License. #
8# You may obtain a copy of the License at #
9# #
10# http://www.apache.org/licenses/LICENSE-2.0 #
11# #
12# Unless required by applicable law or agreed to in writing, software #
13# distributed under the License is distributed on an "AS IS" BASIS, #
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15# See the License for the specific language governing permissions and #
16# limitations under the License. #
17# #
18#============================================================================#
21''' Family of exceptions for package API. '''
24from . import __
27class Omniexception( BaseException ):
28 ''' Base for all exceptions raised by package API. '''
29 # TODO: Class and instance attribute concealment and immutability.
31 _attribute_visibility_includes_: __.cabc.Collection[ str ] = (
32 frozenset( ( '__cause__', '__context__', ) ) )
35class Omnierror( Omniexception, Exception ):
36 ''' Base for error exceptions raised by package API. '''
39class CharsetDetectFailure( Omnierror, RuntimeError ):
40 ''' Character encoding detection fails. '''
42 def __init__( self, location: str ) -> None:
43 super( ).__init__(
44 f"Character encoding detection failed for content at "
45 f"'{location}'." )
48class ContentDecodeFailure( Omnierror, UnicodeError ):
49 ''' Content cannot be decoded with detected charset. '''
51 def __init__( self, location: str, charset: str ) -> None:
52 super( ).__init__(
53 f"Content at '{location}' cannot be decoded using charset "
54 f"'{charset}'." )
57class TextualMimetypeInvalidity( Omnierror, ValueError ):
58 ''' MIME type is invalid for textual content processing. '''
60 def __init__( self, location: str, mimetype: str ) -> None:
61 super( ).__init__(
62 f"MIME type '{mimetype}' is not textual for content at "
63 f"'{location}'." )