OLD | NEW |
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 class Request(object): | 5 class Request(object): |
6 '''Request data. | 6 '''Request data. |
7 ''' | 7 ''' |
8 def __init__(self, path, host, headers): | 8 def __init__(self, path, host, headers): |
9 self.path = path.lstrip('/') | 9 self.path = path.lstrip('/') |
10 self.host = host.rstrip('/') | 10 self.host = host.rstrip('/') |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 self.headers.update(headers) | 98 self.headers.update(headers) |
99 | 99 |
100 def SetStatus(self, status): | 100 def SetStatus(self, status): |
101 self.status = status | 101 self.status = status |
102 | 102 |
103 def GetRedirect(self): | 103 def GetRedirect(self): |
104 if self.headers.get('Location') is None: | 104 if self.headers.get('Location') is None: |
105 return (None, None) | 105 return (None, None) |
106 return (self.headers.get('Location'), self.status == 301) | 106 return (self.headers.get('Location'), self.status == 301) |
107 | 107 |
| 108 def IsNotFound(self): |
| 109 return self.status == 404 |
| 110 |
108 def __eq__(self, other): | 111 def __eq__(self, other): |
109 return (isinstance(other, self.__class__) and | 112 return (isinstance(other, self.__class__) and |
110 str(other.content) == str(self.content) and | 113 str(other.content) == str(self.content) and |
111 other.headers == self.headers and | 114 other.headers == self.headers and |
112 other.status == self.status) | 115 other.status == self.status) |
113 | 116 |
114 def __ne__(self, other): | 117 def __ne__(self, other): |
115 return not (self == other) | 118 return not (self == other) |
116 | 119 |
117 def __repr__(self): | 120 def __repr__(self): |
118 return 'Response(content=%s bytes, status=%s, headers=%s)' % ( | 121 return 'Response(content=%s bytes, status=%s, headers=%s)' % ( |
119 len(self.content), self.status, self.headers) | 122 len(self.content), self.status, self.headers) |
120 | 123 |
121 def __str__(self): | 124 def __str__(self): |
122 return repr(self) | 125 return repr(self) |
123 | 126 |
124 class Servlet(object): | 127 class Servlet(object): |
125 def __init__(self, request): | 128 def __init__(self, request): |
126 self._request = request | 129 self._request = request |
127 | 130 |
128 def Get(self): | 131 def Get(self): |
129 '''Returns a Response. | 132 '''Returns a Response. |
130 ''' | 133 ''' |
131 raise NotImplemented() | 134 raise NotImplemented() |
OLD | NEW |