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

Side by Side Diff: appengine/chromium_rietveld/upload.py

Issue 624513002: Make MIME boundary harder to accidentally match. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Using this code to upload this patch 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 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 Args: 966 Args:
967 fields: A sequence of (name, value) elements for regular form fields. 967 fields: A sequence of (name, value) elements for regular form fields.
968 files: A sequence of (name, filename, value) elements for data to be 968 files: A sequence of (name, filename, value) elements for data to be
969 uploaded as files. 969 uploaded as files.
970 Returns: 970 Returns:
971 (content_type, body) ready for httplib.HTTP instance. 971 (content_type, body) ready for httplib.HTTP instance.
972 972
973 Source: 973 Source:
974 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306 974 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
975 """ 975 """
976 BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-' 976 BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-%s-' % sum(hash(f) for f in files)
iannucci 2014/10/13 18:19:16 oh... I was meaning a real crypographic hash over
977 CRLF = '\r\n' 977 CRLF = '\r\n'
978 lines = [] 978 lines = []
979 for (key, value) in fields: 979 for (key, value) in fields:
980 lines.append('--' + BOUNDARY) 980 lines.append('--' + BOUNDARY)
981 lines.append('Content-Disposition: form-data; name="%s"' % key) 981 lines.append('Content-Disposition: form-data; name="%s"' % key)
982 lines.append('') 982 lines.append('')
983 if isinstance(value, unicode): 983 if isinstance(value, unicode):
984 value = value.encode('utf-8') 984 value = value.encode('utf-8')
985 lines.append(value) 985 lines.append(value)
986 for (key, filename, value) in files: 986 for (key, filename, value) in files:
(...skipping 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 os.environ['LC_ALL'] = 'C' 2706 os.environ['LC_ALL'] = 'C'
2707 RealMain(sys.argv) 2707 RealMain(sys.argv)
2708 except KeyboardInterrupt: 2708 except KeyboardInterrupt:
2709 print 2709 print
2710 StatusUpdate("Interrupted.") 2710 StatusUpdate("Interrupted.")
2711 sys.exit(1) 2711 sys.exit(1)
2712 2712
2713 2713
2714 if __name__ == "__main__": 2714 if __name__ == "__main__":
2715 main() 2715 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