def upload_file(self, metadata, filename, signer=None, sign_password=None,<EOL>filetype='<STR_LIT>', pyversion='<STR_LIT:source>', keystore=None):
self.check_credentials()<EOL>if not os.path.exists(filename):<EOL><INDENT>raise DistlibException('<STR_LIT>' % filename)<EOL><DEDENT>metadata.validate()<EOL>d = metadata.todict()<EOL>sig_file = None<EOL>if signer:<EOL><INDENT>if not self.gpg:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>sig_file = self.sign_file(filename, signer, sign_password,<EOL>keystore)<EOL><DEDENT><DEDENT>with open(filename, '<STR_LIT:rb>') as f:<EOL><INDENT>file_data = f.read()<EOL><DEDENT>md5_digest = hashlib.md5(file_data).hexdigest()<EOL>sha256_digest = hashlib.sha256(file_data).hexdigest()<EOL>d.update({<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:1>',<EOL>'<STR_LIT>': filetype,<EOL>'<STR_LIT>': pyversion,<EOL>'<STR_LIT>': md5_digest,<EOL>'<STR_LIT>': sha256_digest,<EOL>})<EOL>files = [('<STR_LIT:content>', os.path.basename(filename), file_data)]<EOL>if sig_file:<EOL><INDENT>with open(sig_file, '<STR_LIT:rb>') as f:<EOL><INDENT>sig_data = f.read()<EOL><DEDENT>files.append(('<STR_LIT>', os.path.basename(sig_file),<EOL>sig_data))<EOL>shutil.rmtree(os.path.dirname(sig_file))<EOL><DEDENT>request = self.encode_request(d.items(), files)<EOL>return self.send_request(request)<EOL>
Upload a release file to the index.

:param metadata: A :class:`Metadata` instance defining at least a name
                 and version number for the file to be uploaded.
:param filename: The pathname of the file to be uploaded.
:param signer: The identifier of the signer of the file.
:param sign_password: The passphrase for the signer's
                      private key used for signing.
:param filetype: The type of the file being uploaded. This is the
                distutils command which produced that file, e.g.
                ``sdist`` or ``bdist_wheel``.
:param pyversion: The version of Python which the release relates
                  to. For code compatible with any Python, this would
                  be ``source``, otherwise it would be e.g. ``3.2``.
:param keystore: The path to a directory which contains the keys
                 used in signing. If not specified, the instance's
                 ``gpg_home`` attribute is used instead.
:return: The HTTP response received from PyPI upon submission of the
        request.