Coverage for sources/mimeogram/exceptions.py: 100%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-16 03:28 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

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#============================================================================# 

19 

20 

21''' Family of exceptions for package API. 

22 

23 * ``Omniexception``: Base for all package exceptions 

24 * ``Omnierror``: Base for all package errors 

25''' 

26 

27 

28from . import __ 

29 

30 

31class Omniexception( BaseException, metaclass = __.ImmutableClass ): 

32 ''' Base for all exceptions raised by package API. ''' 

33 # TODO: Class attribute concealment. 

34 # TODO: Instance attribute concealment and immutability. 

35 

36 _attribute_visibility_includes_: __.cabc.Collection[ str ] = ( 

37 frozenset( ( '__cause__', '__context__', ) ) ) 

38 

39 

40class Omnierror( Omniexception, Exception ): 

41 ''' Base for error exceptions raised by package API. ''' 

42 

43 

44class ContentAcquireFailure( Omnierror ): 

45 ''' Failure to acquire content from location. ''' 

46 

47 def __init__( self, location: str | __.Path ): 

48 super( ).__init__( f"Could not acquire content from '{location}'." ) 

49 

50 

51class ContentDecodeFailure( Omnierror ): 

52 ''' Failure to decode content as character set from location. ''' 

53 

54 def __init__( self, location: str | __.Path, charset: str ): 

55 super( ).__init__( 

56 f"Could not decode content at '{location}' " 

57 f"as character set '{charset}'." ) 

58 

59 

60class ContentUpdateFailure( Omnierror ): 

61 ''' Failure to update content at location. ''' 

62 

63 def __init__( self, location: str | __.Path ): 

64 super( ).__init__( f"Could not update content at '{location}'." ) 

65 

66 

67class DifferencesProcessFailure( Omnierror ): 

68 ''' Failure during diff processing. ''' 

69 

70 def __init__( self, reason: str ): 

71 super( ).__init__( f"Could not process changes. Reason: {reason}" ) 

72 

73 

74class EditorFailure( Omnierror ): 

75 ''' Failure while operating editor. ''' 

76 

77 def __init__( self, cause: str | Exception ): 

78 super( ).__init__( f"Could not edit content. Cause: {cause}" ) 

79 

80 

81class LocationInvalidity( Omnierror ): 

82 ''' Invalid location. ''' 

83 

84 def __init__( self, location: str | __.Path ): 

85 super( ).__init__( f"Invalid location '{location}'." ) 

86 

87 

88class MimeogramFormatEmpty( Omnierror ): 

89 ''' Attempt to format empty mimeogram. ''' 

90 

91 def __init__( self ): 

92 super( ).__init__( "Cannot format empty mimeogram." ) 

93 

94 

95class MimeogramParseFailure( Omnierror ): 

96 ''' Failure to parse mimeogram content. ''' 

97 

98 def __init__( self, reason: str ): 

99 super( ).__init__( f"Could not parse mimeogram. Reason: {reason}" ) 

100 

101 

102class PagerFailure( Omnierror ): 

103 ''' Failure while operating pager. ''' 

104 

105 def __init__( self, cause: str | Exception ): 

106 super( ).__init__( f"Could not display content. Cause: {cause}" ) 

107 

108 

109class ProgramAbsenceError( Omnierror ): 

110 ''' Could not discover valid editor. ''' 

111 

112 def __init__( self, species: str ): 

113 super( ).__init__( f"Could not discover valid {species}." ) 

114 

115 

116class TextualMimetypeInvalidity( Omnierror ): 

117 ''' Invalid textual MIME type for content at location. ''' 

118 

119 def __init__( self, location: str | __.Path, mimetype: str ): 

120 super( ).__init__( 

121 f"Invalid MIME type '{mimetype}' for content at '{location}'." ) 

122 

123 

124class UrlSchemeNoSupport( Omnierror ): 

125 ''' Unsupported URL scheme. ''' 

126 

127 def __init__( self, url: str ): 

128 super( ).__init__( f"Scheme of URL '{url}' is not supported." ) 

129 

130 

131class UserOperateCancellation( Omniexception ): 

132 ''' Operation cancelled by user. ''' 

133 

134 def __init__( self, cause: BaseException ): 

135 super( ).__init__( f"Operation cancelled by user. Cause: {cause}" )