OLD | NEW |
1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 11 matching lines...) Expand all Loading... |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
29 import mimetypes | 29 import mimetypes |
30 import urllib2 | 30 import urllib2 |
31 | 31 |
32 from webkitpy.common.net.networktransaction import NetworkTransaction | 32 from webkitpy.common.net.network_transaction import NetworkTransaction |
33 | 33 |
34 | 34 |
35 def get_mime_type(filename): | 35 def get_mime_type(filename): |
36 return mimetypes.guess_type(filename)[0] or 'application/octet-stream' | 36 return mimetypes.guess_type(filename)[0] or 'application/octet-stream' |
37 | 37 |
38 | 38 |
39 # FIXME: Rather than taking tuples, this function should take more structured da
ta. | 39 # FIXME: Rather than taking tuples, this function should take more structured da
ta. |
40 def _encode_multipart_form_data(fields, files): | 40 def _encode_multipart_form_data(fields, files): |
41 """Encode form fields for multipart/form-data. | 41 """Encode form fields for multipart/form-data. |
42 | 42 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 def _upload_data(self, content_type, data): | 99 def _upload_data(self, content_type, data): |
100 def callback(): | 100 def callback(): |
101 # FIXME: Setting a timeout, either globally using socket.setdefaultt
imeout() | 101 # FIXME: Setting a timeout, either globally using socket.setdefaultt
imeout() |
102 # or in urlopen(), doesn't appear to work on Mac 10.5 with Python 2.
7. | 102 # or in urlopen(), doesn't appear to work on Mac 10.5 with Python 2.
7. |
103 # For now we will ignore the timeout value and hope for the best. | 103 # For now we will ignore the timeout value and hope for the best. |
104 request = urllib2.Request(self._url, data, {"Content-Type": content_
type}) | 104 request = urllib2.Request(self._url, data, {"Content-Type": content_
type}) |
105 return urllib2.urlopen(request) | 105 return urllib2.urlopen(request) |
106 | 106 |
107 return NetworkTransaction(timeout_seconds=self._timeout_seconds).run(cal
lback) | 107 return NetworkTransaction(timeout_seconds=self._timeout_seconds).run(cal
lback) |
OLD | NEW |