trolly/card.py
def encode_multipart_formdata(self, fields, filename, file_values):
        '''
        Encodes data to updload a file to Trello.
        Fields is a dictionary of api_key and token. Filename is the name of
        the file and file_values is the open(file).read() string.
        '''
        boundary = '----------Trello_Boundary_$'
        crlf = '\r\n'

        data = []

        for key in fields:
            data.append('--' + boundary)
            data.append('Content-Disposition: form-data; name="%s"' % key)
            data.append('')
            data.append(fields[key])

        data.append('--' + boundary)
        data.append(
            'Content-Disposition: form-data; name="file"; filename="%s"' %
            filename)
        data.append('Content-Type: %s' % self.get_content_type(filename))
        data.append('')
        data.append(file_values)

        data.append('--' + boundary + '--')
        data.append('')

        # Try and avoid the damn unicode errors
        data = [str(segment) for segment in data]

        body = crlf.join(data)
        content_type = 'multipart/form-data; boundary=%s' % boundary

        return content_type, body
def encode_multipart_formdata(self, fields, filename, file_values):
        '''
        Encodes data to updload a file to Trello.
        Fields is a dictionary of api_key and token. Filename is the name of
        the file and file_values is the open(file).read() string.
        '''
        boundary = '----------Trello_Boundary_$'
        crlf = '\r\n'

        data = []

        for key in fields:
            data.append('--' + boundary)
            data.append('Content-Disposition: form-data; name="%s"' % key)
            data.append('')
            data.append(fields[key])

        data.append('--' + boundary)
        data.append(
            'Content-Disposition: form-data; name="file"; filename="%s"' %
            filename)
        data.append('Content-Type: %s' % self.get_content_type(filename))
        data.append('')
        data.append(file_values)

        data.append('--' + boundary + '--')
        data.append('')

        # Try and avoid the damn unicode errors
        data = [str(segment) for segment in data]

        body = crlf.join(data)
        content_type = 'multipart/form-data; boundary=%s' % boundary

        return content_type, body
Encodes data to updload a file to Trello.
        Fields is a dictionary of api_key and token. Filename is the name of
        the file and file_values is the open(file).read() string.