OLD | NEW |
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 Loading... |
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 Loading... |
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() |
OLD | NEW |