Add a file to be uploaded. file_object: file-like object (with read method) from which to read data to upload content_type: MIME content type of data to upload filename: filename to pass to server If filename is None, no filename is sent to the server.
(self, file_object, content_type=None, filename=None,
name=None, id=None, nr=None, label=None)
| 3065 | # Form-filling method applying only to FileControls. |
| 3066 | |
| 3067 | def add_file(self, file_object, content_type=None, filename=None, |
| 3068 | name=None, id=None, nr=None, label=None): |
| 3069 | """Add a file to be uploaded. |
| 3070 | |
| 3071 | file_object: file-like object (with read method) from which to read |
| 3072 | data to upload |
| 3073 | content_type: MIME content type of data to upload |
| 3074 | filename: filename to pass to server |
| 3075 | |
| 3076 | If filename is None, no filename is sent to the server. |
| 3077 | |
| 3078 | If content_type is None, the content type is guessed based on the |
| 3079 | filename and the data from read from the file object. |
| 3080 | |
| 3081 | XXX |
| 3082 | At the moment, guessed content type is always application/octet-stream. |
| 3083 | Use sndhdr, imghdr modules. Should also try to guess HTML, XML, and |
| 3084 | plain text. |
| 3085 | |
| 3086 | Note the following useful HTML attributes of file upload controls (see |
| 3087 | HTML 4.01 spec, section 17): |
| 3088 | |
| 3089 | accept: comma-separated list of content types that the server will |
| 3090 | handle correctly; you can use this to filter out non-conforming files |
| 3091 | size: XXX IIRC, this is indicative of whether form wants multiple or |
| 3092 | single files |
| 3093 | maxlength: XXX hint of max content length in bytes? |
| 3094 | |
| 3095 | """ |
| 3096 | self.find_control(name, "file", id=id, label=label, nr=nr).add_file( |
| 3097 | file_object, content_type, filename) |
| 3098 | |
| 3099 | #--------------------------------------------------- |
| 3100 | # Form submission methods, applying only to clickable controls. |
nothing calls this directly
no test coverage detected