Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/storage/exceptions.py: 42%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

24 statements  

1# Copyright 2024 Google LLC 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15"""Exceptions raised by the library.""" 

16 

17# These exceptions were originally part of the google-resumable-media library 

18# but were integrated into python-storage in version 3.0. For backwards 

19# compatibility with applications which use except blocks with 

20# google-resumable-media exceptions, if the library google-resumable-media is 

21# installed, make all exceptions subclasses of the exceptions from that library. 

22# Note that either way, the classes will subclass Exception, either directly or 

23# indirectly. 

24# 

25# This backwards compatibility feature may be removed in a future major version 

26# update. Please update application code to use the new exception classes in 

27# this module. 

28try: 

29 from google.resumable_media import InvalidResponse as InvalidResponseDynamicParent 

30 from google.resumable_media import DataCorruption as DataCorruptionDynamicParent 

31except ImportError: 

32 InvalidResponseDynamicParent = Exception 

33 DataCorruptionDynamicParent = Exception 

34 

35 

36class InvalidPathError(Exception): 

37 """Raised when the provided path string is malformed.""" 

38 

39 pass 

40 

41 

42class InvalidResponse(InvalidResponseDynamicParent): 

43 """Error class for responses which are not in the correct state. 

44 

45 Args: 

46 response (object): The HTTP response which caused the failure. 

47 args (tuple): The positional arguments typically passed to an 

48 exception class. 

49 """ 

50 

51 def __init__(self, response, *args): 

52 if InvalidResponseDynamicParent is Exception: 

53 super().__init__(*args) 

54 self.response = response 

55 """object: The HTTP response object that caused the failure.""" 

56 else: 

57 super().__init__(response, *args) 

58 

59 

60class DataCorruption(DataCorruptionDynamicParent): 

61 """Error class for corrupt media transfers. 

62 

63 Args: 

64 response (object): The HTTP response which caused the failure. 

65 args (tuple): The positional arguments typically passed to an 

66 exception class. 

67 """ 

68 

69 def __init__(self, response, *args): 

70 if DataCorruptionDynamicParent is Exception: 

71 super().__init__(*args) 

72 self.response = response 

73 """object: The HTTP response object that caused the failure.""" 

74 else: 

75 super().__init__(response, *args)