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