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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/wpt_github.py

Issue 2691953003: [WPT Export] Remove all newlines in GitHub auth header (Closed)
Patch Set: Change base64.encodestring to base64.b64encode to fix newline problem Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import base64 5 import base64
6 import json 6 import json
7 import logging 7 import logging
8 import urllib2 8 import urllib2
9 9
10 10
11 _log = logging.getLogger(__name__) 11 _log = logging.getLogger(__name__)
12 API_BASE = 'https://api.github.com' 12 API_BASE = 'https://api.github.com'
13 EXPORT_LABEL = 'chromium-export' 13 EXPORT_LABEL = 'chromium-export'
14 14
15 15
16 class WPTGitHub(object): 16 class WPTGitHub(object):
17 17
18 def __init__(self, host, user, token): 18 def __init__(self, host, user, token):
19 self.host = host 19 self.host = host
20 self.user = user 20 self.user = user
21 self.token = token 21 self.token = token
22 assert self.user and self.token 22 assert self.user and self.token
23 23
24 def auth_token(self): 24 def auth_token(self):
25 return base64.encodestring('{}:{}'.format(self.user, self.token)).strip( ) 25 return base64.b64encode('{}:{}'.format(self.user, self.token))
26 26
27 def request(self, path, method, body=None): 27 def request(self, path, method, body=None):
28 assert path.startswith('/') 28 assert path.startswith('/')
29 if body: 29 if body:
30 body = json.dumps(body) 30 body = json.dumps(body)
31 opener = urllib2.build_opener(urllib2.HTTPHandler) 31 opener = urllib2.build_opener(urllib2.HTTPHandler)
32 request = urllib2.Request(url=API_BASE + path, data=body) 32 request = urllib2.Request(url=API_BASE + path, data=body)
33 request.add_header('Accept', 'application/vnd.github.v3+json') 33 request.add_header('Accept', 'application/vnd.github.v3+json')
34 request.add_header('Authorization', 'Basic {}'.format(self.auth_token()) ) 34 request.add_header('Authorization', 'Basic {}'.format(self.auth_token()) )
35 request.get_method = lambda: method 35 request.get_method = lambda: method
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 def delete_remote_branch(self, remote_branch_name): 96 def delete_remote_branch(self, remote_branch_name):
97 # TODO(jeffcarp): Unit test this method 97 # TODO(jeffcarp): Unit test this method
98 path = '/repos/w3c/web-platform-tests/git/refs/heads/%s' % remote_branch _name 98 path = '/repos/w3c/web-platform-tests/git/refs/heads/%s' % remote_branch _name
99 data, status_code = self.request(path, method='DELETE') 99 data, status_code = self.request(path, method='DELETE')
100 100
101 if status_code != 204: 101 if status_code != 204:
102 # TODO(jeffcarp): Raise more specific exception (create MergeError c lass?) 102 # TODO(jeffcarp): Raise more specific exception (create MergeError c lass?)
103 raise Exception('Received non-204 status code attempting to delete r emote branch: {}'.format(status_code)) 103 raise Exception('Received non-204 status code attempting to delete r emote branch: {}'.format(status_code))
104 104
105 return data 105 return data
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698