| OLD | NEW |
| 1 # Copyright 2014 Google Inc. All rights reserved. | 1 # Copyright 2014 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with 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 | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 13 # limitations under the License. |
| 14 | 14 |
| 15 """A fake implementation of test-results.appspot.com.""" | 15 """A fake implementation of test-results.appspot.com.""" |
| 16 | 16 |
| 17 import io | 17 import io |
| 18 import sys | 18 import sys |
| 19 import threading | 19 import threading |
| 20 | 20 |
| 21 | 21 |
| 22 if sys.version_info.major == 2: # pragma: python2 | 22 if sys.version_info.major == 2: # pragma: python2 |
| 23 from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler | 23 from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler |
| 24 from SocketServer import TCPServer | 24 from SocketServer import TCPServer |
| 25 else: # pragma: python3 | 25 else: # pragma: python3 |
| 26 assert sys.version_info.major == 3 | 26 assert sys.version_info.major == 3 |
| 27 # pylint: disable=redefined-builtin | 27 # pylint: disable=invalid-name, redefined-builtin |
| 28 unicode = str | 28 unicode = str |
| 29 from http.server import BaseHTTPRequestHandler # pylint: disable=F0401 | 29 from http.server import BaseHTTPRequestHandler # pylint: disable=F0401 |
| 30 HTTPRequestHandler = BaseHTTPRequestHandler | 30 HTTPRequestHandler = BaseHTTPRequestHandler |
| 31 from socketserver import TCPServer # pylint: disable=F0401 | 31 from socketserver import TCPServer # pylint: disable=F0401 |
| 32 | 32 |
| 33 | 33 |
| 34 def start(code=200): | 34 def start(code=200): |
| 35 server = _Server(code=code) | 35 server = _Server(code=code) |
| 36 thread = threading.Thread(target=_run, args=(server,)) | 36 thread = threading.Thread(target=_run, args=(server,)) |
| 37 server.main_thread = thread | 37 server.main_thread = thread |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 path = self.path | 70 path = self.path |
| 71 length = int(self.headers['content-length']) | 71 length = int(self.headers['content-length']) |
| 72 payload = self.rfile.read(length) | 72 payload = self.rfile.read(length) |
| 73 self.server.requests.append(('post', path, payload)) | 73 self.server.requests.append(('post', path, payload)) |
| 74 self.send_response(self.server.code) | 74 self.send_response(self.server.code) |
| 75 self.end_headers() | 75 self.end_headers() |
| 76 | 76 |
| 77 # 'Redefining built-in' pylint: disable=W0622 | 77 # 'Redefining built-in' pylint: disable=W0622 |
| 78 def log_message(self, format, *args): | 78 def log_message(self, format, *args): |
| 79 self.server.log.write(unicode('%s\n' % (format % args))) | 79 self.server.log.write(unicode('%s\n' % (format % args))) |
| OLD | NEW |