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

Side by Side Diff: third_party/upload.py

Issue 639503002: Make MIME boundary harder to accidentally match. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 2 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 # 3 #
4 # Copyright 2007 Google Inc. 4 # Copyright 2007 Google Inc.
5 # 5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License. 7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at 8 # You may obtain a copy of the License at
9 # 9 #
10 # http://www.apache.org/licenses/LICENSE-2.0 10 # http://www.apache.org/licenses/LICENSE-2.0
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 Args: 965 Args:
966 fields: A sequence of (name, value) elements for regular form fields. 966 fields: A sequence of (name, value) elements for regular form fields.
967 files: A sequence of (name, filename, value) elements for data to be 967 files: A sequence of (name, filename, value) elements for data to be
968 uploaded as files. 968 uploaded as files.
969 Returns: 969 Returns:
970 (content_type, body) ready for httplib.HTTP instance. 970 (content_type, body) ready for httplib.HTTP instance.
971 971
972 Source: 972 Source:
973 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 973 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
974 """ 974 """
975 BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-' 975 BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-%s-' % sum(hash(f) for f in files)
976 CRLF = '\r\n' 976 CRLF = '\r\n'
977 lines = [] 977 lines = []
978 for (key, value) in fields: 978 for (key, value) in fields:
979 lines.append('--' + BOUNDARY) 979 lines.append('--' + BOUNDARY)
980 lines.append('Content-Disposition: form-data; name="%s"' % key) 980 lines.append('Content-Disposition: form-data; name="%s"' % key)
981 lines.append('') 981 lines.append('')
982 if isinstance(value, unicode): 982 if isinstance(value, unicode):
983 value = value.encode('utf-8') 983 value = value.encode('utf-8')
984 lines.append(value) 984 lines.append(value)
985 for (key, filename, value) in files: 985 for (key, filename, value) in files:
(...skipping 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 os.environ['LC_ALL'] = 'C' 2705 os.environ['LC_ALL'] = 'C'
2706 RealMain(sys.argv) 2706 RealMain(sys.argv)
2707 except KeyboardInterrupt: 2707 except KeyboardInterrupt:
2708 print 2708 print
2709 StatusUpdate("Interrupted.") 2709 StatusUpdate("Interrupted.")
2710 sys.exit(1) 2710 sys.exit(1)
2711 2711
2712 2712
2713 if __name__ == "__main__": 2713 if __name__ == "__main__":
2714 main() 2714 main()
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