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

Side by Side Diff: chrome/common/extensions/docs/server2/servlet.py

Issue 575613003: Docserver: Gitiles auth and cron refactoring. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 5
6 class RequestHeaders(object): 6 class RequestHeaders(object):
7 '''A custom dictionary impementation for headers which ignores the case 7 '''A custom dictionary impementation for headers which ignores the case
8 of requests, since different HTTP libraries seem to mangle them. 8 of requests, since different HTTP libraries seem to mangle them.
9 ''' 9 '''
10 def __init__(self, dict_): 10 def __init__(self, dict_):
11 if isinstance(dict_, RequestHeaders): 11 if isinstance(dict_, RequestHeaders):
12 self._dict = dict_ 12 self._dict = dict_
13 else: 13 else:
14 self._dict = dict((k.lower(), v) for k, v in dict_.iteritems()) 14 self._dict = dict((k.lower(), v) for k, v in dict_.iteritems())
15 15
16 def get(self, key, default=None): 16 def get(self, key, default=None):
17 return self._dict.get(key.lower(), default) 17 return self._dict.get(key.lower(), default)
18 18
19 def __repr__(self): 19 def __repr__(self):
20 return repr(self._dict) 20 return repr(self._dict)
21 21
22 def __str__(self): 22 def __str__(self):
23 return repr(self._dict) 23 return repr(self._dict)
24 24
25 25
26 class Request(object): 26 class Request(object):
27 '''Request data. 27 '''Request data.
28 ''' 28 '''
29 def __init__(self, path, host, headers): 29 def __init__(self, path, host, headers, arguments={}):
30 self.path = path.lstrip('/') 30 self.path = path.lstrip('/')
31 self.host = host.rstrip('/') 31 self.host = host.rstrip('/')
32 self.headers = RequestHeaders(headers) 32 self.headers = RequestHeaders(headers)
33 self.arguments = arguments
33 34
34 @staticmethod 35 @staticmethod
35 def ForTest(path, host=None, headers=None): 36 def ForTest(path, host=None, headers=None):
36 return Request(path, host or 'http://developer.chrome.com', headers or {}) 37 return Request(path, host or 'http://developer.chrome.com', headers or {})
37 38
38 def __repr__(self): 39 def __repr__(self):
39 return 'Request(path=%s, host=%s, headers=%s)' % ( 40 return 'Request(path=%s, host=%s, headers=%s)' % (
40 self.path, self.host, self.headers) 41 self.path, self.host, self.headers)
41 42
42 def __str__(self): 43 def __str__(self):
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 @staticmethod 101 @staticmethod
101 def NotModified(content, headers=None): 102 def NotModified(content, headers=None):
102 return Response(content=content, headers=headers, status=304) 103 return Response(content=content, headers=headers, status=304)
103 104
104 @staticmethod 105 @staticmethod
105 def InternalError(content, headers=None): 106 def InternalError(content, headers=None):
106 '''Returns an internal error (500) response. 107 '''Returns an internal error (500) response.
107 ''' 108 '''
108 return Response(content=content, headers=headers, status=500) 109 return Response(content=content, headers=headers, status=500)
109 110
111 @staticmethod
112 def ThrottledError(content, headers=None):
113 '''Returns an HTTP throttle error (429) response.
114 '''
115 return Response(content=content, headers=headers, status=429)
116
110 def Append(self, content): 117 def Append(self, content):
111 '''Appends |content| to the response content. 118 '''Appends |content| to the response content.
112 ''' 119 '''
113 self.content.append(content) 120 self.content.append(content)
114 121
115 def AddHeader(self, key, value): 122 def AddHeader(self, key, value):
116 '''Adds a header to the response. 123 '''Adds a header to the response.
117 ''' 124 '''
118 self.headers[key] = value 125 self.headers[key] = value
119 126
(...skipping 30 matching lines...) Expand all
150 return repr(self) 157 return repr(self)
151 158
152 class Servlet(object): 159 class Servlet(object):
153 def __init__(self, request): 160 def __init__(self, request):
154 self._request = request 161 self._request = request
155 162
156 def Get(self): 163 def Get(self):
157 '''Returns a Response. 164 '''Returns a Response.
158 ''' 165 '''
159 raise NotImplemented() 166 raise NotImplemented()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/samples_model.py ('k') | chrome/common/extensions/docs/server2/sidenav_data_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698