| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 # TODO: In the new layout, this should move to the ./services or |
| 6 # ./services/waterfall_app directories, since it is only used by Waterfall. |
| 7 |
| 8 # TODO: we ought to abstract over the HTTP_CLIENT member (which is only |
| 9 # used by the Post method) by passing it to the constructor. That way |
| 10 # things are more losely coupled, improving modularity and reducing |
| 11 # fragility. In addition, for easier mocking, we may want to just have |
| 12 # the thing passed for HTTP_CLIENT to be ``callable``, rather than giving |
| 13 # a name to the method we use on that object. |
| 14 |
| 5 import logging | 15 import logging |
| 6 import re | 16 import re |
| 7 import urlparse | 17 import urlparse |
| 8 | 18 |
| 9 from common.codereview import CodeReview | |
| 10 from common.http_client_appengine import HttpClientAppengine | 19 from common.http_client_appengine import HttpClientAppengine |
| 11 | 20 |
| 12 | 21 |
| 13 _RIETVELD_ISSUE_NUMBER_RE = re.compile('^/(\d+)/?.*') | 22 _RIETVELD_ISSUE_NUMBER_RE = re.compile('^/(\d+)/?.*') |
| 14 | 23 |
| 15 | 24 |
| 16 class Rietveld(CodeReview): | 25 class Rietveld(object): |
| 17 """The implementation of CodeReview interface for Rietveld.""" | 26 """The implementation of CodeReview interface for Rietveld.""" |
| 18 HTTP_CLIENT = HttpClientAppengine(follow_redirects=False) | 27 HTTP_CLIENT = HttpClientAppengine(follow_redirects=False) |
| 19 | 28 |
| 20 def _GetXsrfToken(self, rietveld_url): | 29 def _GetXsrfToken(self, rietveld_url): |
| 21 """Returns the xsrf token for follow-up requests.""" | 30 """Returns the xsrf token for follow-up requests.""" |
| 22 headers = { | 31 headers = { |
| 23 'X-Requesting-XSRF-Token': '1', | 32 'X-Requesting-XSRF-Token': '1', |
| 24 'Accept': 'text/plain', | 33 'Accept': 'text/plain', |
| 25 } | 34 } |
| 26 url = '%s/xsrf_token' % rietveld_url | 35 url = '%s/xsrf_token' % rietveld_url |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 'no_redirect': 'True', | 86 'no_redirect': 'True', |
| 78 } | 87 } |
| 79 content_type, body = self._EncodeMultipartFormData(form_fields) | 88 content_type, body = self._EncodeMultipartFormData(form_fields) |
| 80 headers = { | 89 headers = { |
| 81 'Content-Type': content_type, | 90 'Content-Type': content_type, |
| 82 'Accept': 'text/plain', | 91 'Accept': 'text/plain', |
| 83 } | 92 } |
| 84 status_code, content = self.HTTP_CLIENT.Post( | 93 status_code, content = self.HTTP_CLIENT.Post( |
| 85 url, data=body, headers=headers) | 94 url, data=body, headers=headers) |
| 86 return status_code == 200 and content == 'OK' | 95 return status_code == 200 and content == 'OK' |
| OLD | NEW |