Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: reviewbot/third_party/google-api-python-client/apiclient/errors.py

Issue 20515002: Add google-api-python-client in third_party/ (Closed) Base URL: https://src.chromium.org/chrome/trunk/tools/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 #
3 # Copyright (C) 2010 Google Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """Errors for the library.
18
19 All exceptions defined by the library
20 should be defined in this file.
21 """
22
23 __author__ = 'jcgregorio@google.com (Joe Gregorio)'
24
25
26 from oauth2client import util
27 from oauth2client.anyjson import simplejson
28
29
30 class Error(Exception):
31 """Base error for this module."""
32 pass
33
34
35 class HttpError(Error):
36 """HTTP data was invalid or unexpected."""
37
38 @util.positional(3)
39 def __init__(self, resp, content, uri=None):
40 self.resp = resp
41 self.content = content
42 self.uri = uri
43
44 def _get_reason(self):
45 """Calculate the reason for the error from the response content."""
46 reason = self.resp.reason
47 try:
48 data = simplejson.loads(self.content)
49 reason = data['error']['message']
50 except (ValueError, KeyError):
51 pass
52 if reason is None:
53 reason = ''
54 return reason
55
56 def __repr__(self):
57 if self.uri:
58 return '<HttpError %s when requesting %s returned "%s">' % (
59 self.resp.status, self.uri, self._get_reason().strip())
60 else:
61 return '<HttpError %s "%s">' % (self.resp.status, self._get_reason())
62
63 __str__ = __repr__
64
65
66 class InvalidJsonError(Error):
67 """The JSON returned could not be parsed."""
68 pass
69
70
71 class UnknownFileType(Error):
72 """File type unknown or unexpected."""
73 pass
74
75
76 class UnknownLinkType(Error):
77 """Link type unknown or unexpected."""
78 pass
79
80
81 class UnknownApiNameOrVersion(Error):
82 """No API with that name and version exists."""
83 pass
84
85
86 class UnacceptableMimeTypeError(Error):
87 """That is an unacceptable mimetype for this operation."""
88 pass
89
90
91 class MediaUploadSizeError(Error):
92 """Media is larger than the method can accept."""
93 pass
94
95
96 class ResumableUploadError(HttpError):
97 """Error occured during resumable upload."""
98 pass
99
100
101 class InvalidChunkSizeError(Error):
102 """The given chunksize is not valid."""
103 pass
104
105
106 class BatchError(HttpError):
107 """Error occured during batch operations."""
108
109 @util.positional(2)
110 def __init__(self, reason, resp=None, content=None):
111 self.resp = resp
112 self.content = content
113 self.reason = reason
114
115 def __repr__(self):
116 return '<BatchError %s "%s">' % (self.resp.status, self.reason)
117
118 __str__ = __repr__
119
120
121 class UnexpectedMethodError(Error):
122 """Exception raised by RequestMockBuilder on unexpected calls."""
123
124 @util.positional(1)
125 def __init__(self, methodId=None):
126 """Constructor for an UnexpectedMethodError."""
127 super(UnexpectedMethodError, self).__init__(
128 'Received unexpected call %s' % methodId)
129
130
131 class UnexpectedBodyError(Error):
132 """Exception raised by RequestMockBuilder on unexpected bodies."""
133
134 def __init__(self, expected, provided):
135 """Constructor for an UnexpectedMethodError."""
136 super(UnexpectedBodyError, self).__init__(
137 'Expected: [%s] - Provided: [%s]' % (expected, provided))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698