def _put_or_post_multipart(self, method, url, data):
fields = []<EOL>files = []<EOL>for key, value in list(data.items()):<EOL><INDENT>if type(value) == file:<EOL><INDENT>files.append((key, value.name, value.read()))<EOL><DEDENT>else:<EOL><INDENT>fields.append((key, value))<EOL><DEDENT><DEDENT>content_type, body = _encode_multipart_formdata(fields, files)<EOL>if self.parsed_endpoint.scheme == '<STR_LIT>':<EOL><INDENT>h = http.client.HTTPS(self.parsed_endpoint.netloc)<EOL><DEDENT>else:<EOL><INDENT>h = http.client.HTTP(self.parsed_endpoint.netloc)<EOL><DEDENT>h.putrequest(method, url)<EOL>h.putheader('<STR_LIT:Content-Type>', content_type)<EOL>h.putheader('<STR_LIT>', str(len(body)))<EOL>h.putheader('<STR_LIT>', '<STR_LIT:application/json>')<EOL>h.putheader('<STR_LIT>', USER_AGENT)<EOL>h.putheader(API_TOKEN_HEADER_NAME, self.api_token)<EOL>if self.api_version in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>h.putheader(API_VERSION_HEADER_NAME, self.api_version)<EOL><DEDENT>h.endheaders()<EOL>h.send(body)<EOL>errcode, errmsg, headers = h.getreply()<EOL>if errcode not in [<NUM_LIT:200>, <NUM_LIT>]:<EOL><INDENT>raise IOError('<STR_LIT>' % (method, url, errcode, h.file.read()))<EOL><DEDENT>return json.loads(h.file.read())<EOL>
encodes the data as a multipart form and PUTs or POSTs to the url
the response is parsed as JSON and the returns the resulting data structure