fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance
(fields, files)
| 105 | |
| 106 | |
| 107 | def EncodeMultipartFormdata(fields, files): |
| 108 | """ |
| 109 | fields is a sequence of (name, value) elements for regular form fields. |
| 110 | files is a sequence of (name, filename, value) elements for data to be uploaded as files |
| 111 | Return (content_type, body) ready for httplib.HTTP instance |
| 112 | """ |
| 113 | print "EncodeMultipartFormdata BEGIN" |
| 114 | boundary = '----------ThIs_Is_tHe_bouNdaRY_$' |
| 115 | crlf = '\r\n' |
| 116 | lines = [] |
| 117 | print "FIELDS" |
| 118 | for (key, value) in fields: |
| 119 | print "FIELD", key, value |
| 120 | lines.append('--' + boundary) |
| 121 | lines.append('Content-Disposition: form-data; name="%s"' % key) |
| 122 | lines.append('') |
| 123 | lines.append(value) |
| 124 | print "FILES" |
| 125 | for (key, filename, value) in files: |
| 126 | print "FILE", key, filename, len(value) |
| 127 | lines.append('--' + boundary) |
| 128 | lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) |
| 129 | lines.append('Content-Type: %s' % GetContentType(filename)) |
| 130 | lines.append('') |
| 131 | lines.append(value) |
| 132 | lines.append('--' + boundary + '--') |
| 133 | lines.append('') |
| 134 | print "JOINING" |
| 135 | body = crlf.join(lines) |
| 136 | print "BODY", len(body) |
| 137 | #print body |
| 138 | contentType = 'multipart/form-data; boundary=%s' % boundary |
| 139 | return contentType, body |
| 140 | |
| 141 | |
| 142 | def FacebookAPI(path, params=None, method=u'GET', domain=u'graph', access_token=None, fileNames=None): |
no test coverage detected