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

Side by Side Diff: appengine/findit/common/rietveld.py

Issue 2344443005: [Findit] Factoring the gitiles (etc) stuff out into its own directory (Closed)
Patch Set: rebase-update Created 4 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 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(wrengr): this file is only used by waterfall. We should either
6 # move it to that directory, or else factor out the dependency on
7 # HttpClientAppengine by abstracting over the HTTP_CLIENT member. The
8 # only thing we use/need HTTP_CLIENT for is to call the Post method,
9 # which could just as well be rewritten to use the __call__ method
10 # instead; hence, we could just pass an appropriate callable object to
11 # the constructor (incidentally allowing multiple Rietveld objects to
12 # share the same HTTP_CLIENT, if desired) rather than allocating our own
13 # one automatically. Does rietveld itself actually require appengine?
14 # Or is that just an incidental circumstance about our particular use
15 # of it?
stgao 2016/09/21 23:03:25 This should go to waterfall/infra/ as in the new c
5 import logging 16 import logging
6 import re 17 import re
7 import urlparse 18 import urlparse
8 19
9 from common.codereview import CodeReview
10 from common.http_client_appengine import HttpClientAppengine 20 from common.http_client_appengine import HttpClientAppengine
11 21
12 22
13 _RIETVELD_ISSUE_NUMBER_RE = re.compile('^/(\d+)/?.*') 23 _RIETVELD_ISSUE_NUMBER_RE = re.compile('^/(\d+)/?.*')
14 24
15 25
16 class Rietveld(CodeReview): 26 class Rietveld(object):
17 """The implementation of CodeReview interface for Rietveld.""" 27 """The implementation of CodeReview interface for Rietveld."""
18 HTTP_CLIENT = HttpClientAppengine(follow_redirects=False) 28 HTTP_CLIENT = HttpClientAppengine(follow_redirects=False)
19 29
20 def _GetXsrfToken(self, rietveld_url): 30 def _GetXsrfToken(self, rietveld_url):
21 """Returns the xsrf token for follow-up requests.""" 31 """Returns the xsrf token for follow-up requests."""
22 headers = { 32 headers = {
23 'X-Requesting-XSRF-Token': '1', 33 'X-Requesting-XSRF-Token': '1',
24 'Accept': 'text/plain', 34 'Accept': 'text/plain',
25 } 35 }
26 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
77 'no_redirect': 'True', 87 'no_redirect': 'True',
78 } 88 }
79 content_type, body = self._EncodeMultipartFormData(form_fields) 89 content_type, body = self._EncodeMultipartFormData(form_fields)
80 headers = { 90 headers = {
81 'Content-Type': content_type, 91 'Content-Type': content_type,
82 'Accept': 'text/plain', 92 'Accept': 'text/plain',
83 } 93 }
84 status_code, content = self.HTTP_CLIENT.Post( 94 status_code, content = self.HTTP_CLIENT.Post(
85 url, data=body, headers=headers) 95 url, data=body, headers=headers)
86 return status_code == 200 and content == 'OK' 96 return status_code == 200 and content == 'OK'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698