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

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

22 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 InvalidResponse(InvalidResponseDynamicParent): 

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

38 

39 Args: 

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

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

42 exception class. 

43 """ 

44 

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

46 if InvalidResponseDynamicParent is Exception: 

47 super().__init__(*args) 

48 self.response = response 

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

50 else: 

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

52 

53 

54class DataCorruption(DataCorruptionDynamicParent): 

55 """Error class for corrupt media transfers. 

56 

57 Args: 

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

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

60 exception class. 

61 """ 

62 

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

64 if DataCorruptionDynamicParent is Exception: 

65 super().__init__(*args) 

66 self.response = response 

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

68 else: 

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