This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathexceptions.py
More file actions
75 lines (62 loc) · 2.79 KB
/
exceptions.py
File metadata and controls
75 lines (62 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Exceptions raised by the library."""
# These exceptions were originally part of the google-resumable-media library
# but were integrated into python-storage in version 3.0. For backwards
# compatibility with applications which use except blocks with
# google-resumable-media exceptions, if the library google-resumable-media is
# installed, make all exceptions subclasses of the exceptions from that library.
# Note that either way, the classes will subclass Exception, either directly or
# indirectly.
#
# This backwards compatibility feature may be removed in a future major version
# update. Please update application code to use the new exception classes in
# this module.
try:
from google.resumable_media import InvalidResponse as InvalidResponseDynamicParent
from google.resumable_media import DataCorruption as DataCorruptionDynamicParent
except ImportError:
InvalidResponseDynamicParent = Exception
DataCorruptionDynamicParent = Exception
class InvalidPathError(Exception):
"""Raised when the provided path string is malformed."""
pass
class InvalidResponse(InvalidResponseDynamicParent):
"""Error class for responses which are not in the correct state.
Args:
response (object): The HTTP response which caused the failure.
args (tuple): The positional arguments typically passed to an
exception class.
"""
def __init__(self, response, *args):
if InvalidResponseDynamicParent is Exception:
super().__init__(*args)
self.response = response
"""object: The HTTP response object that caused the failure."""
else:
super().__init__(response, *args)
class DataCorruption(DataCorruptionDynamicParent):
"""Error class for corrupt media transfers.
Args:
response (object): The HTTP response which caused the failure.
args (tuple): The positional arguments typically passed to an
exception class.
"""
def __init__(self, response, *args):
if DataCorruptionDynamicParent is Exception:
super().__init__(*args)
self.response = response
"""object: The HTTP response object that caused the failure."""
else:
super().__init__(response, *args)