<commit_before># Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import distutils.spawn
import hashlib
import logging
import os.path

import pkginfo
import pkg_resources
import requests

from twine.exceptions import CommandError
from twine.wheel import Wheel
from twine.utils import get_distutils_config


logger = logging.getLogger(__name__)


class Upload(object):

    DIST_TYPES = {
        "bdist_wheel": Wheel,
        "bdist_egg": pkginfo.BDist,
        "sdist": pkginfo.SDist,
    }

    DIST_EXTENSIONS = {
        ".whl": "bdist_wheel",
        ".egg": "bdist_egg",
        ".tar.bz2": "sdist",
        ".tar.gz": "sdist",
        ".zip": "sdist",
    }

    def __call__(self, dists, repository, sign, identity, username, password,
            comment):
        # Check that a nonsensical option wasn't given
        if not sign and identity:
            raise CommandError("--sign must be given along with --identity")

        # Get our config from ~/.pypirc
        config = get_distutils_config(repository)

        logger.info("Uploading distributions to %s", config["repository"])

        session = requests.session()

        for filename in dists:
            # Sign the dist if requested
            if sign:
                logger.info("Signing %s", os.path.basename(filename))
                gpg_args = ["gpg", "--detach-sign", "-a", filename]
                if identity:
                    gpg_args[2:2] = ["--local-user", identity]
                distutils.spawn.spawn(gpg_args)

            # Extract the metadata from the package
            for ext, dtype in self.DIST_EXTENSIONS.items():
                if filename.endswith(ext):
                    meta = self.DIST_TYPES[dtype](filename)
                    break
            else:
                raise ValueError(
                    "Unknown distribution format: '%s'" %
                    os.path.basename(filename)
                )

            if dtype == "bdist_egg":
                pkgd = pkg_resources.Distribution.from_filename(filename)<commit_msg>Force PyPI to use HTTPS<commit_after># Copyright 2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function

import distutils.spawn
import hashlib
import logging
import os.path

import pkginfo
import pkg_resources
import requests

from six.moves import urllib_parse

from twine.exceptions import CommandError
from twine.wheel import Wheel
from twine.utils import get_distutils_config


logger = logging.getLogger(__name__)


class Upload(object):

    DIST_TYPES = {
        "bdist_wheel": Wheel,
        "bdist_egg": pkginfo.BDist,
        "sdist": pkginfo.SDist,
    }

    DIST_EXTENSIONS = {
        ".whl": "bdist_wheel",
        ".egg": "bdist_egg",
        ".tar.bz2": "sdist",
        ".tar.gz": "sdist",
        ".zip": "sdist",
    }

    def __call__(self, dists, repository, sign, identity, username, password,
            comment):
        # Check that a nonsensical option wasn't given
        if not sign and identity:
            raise CommandError("--sign must be given along with --identity")

        # Get our config from ~/.pypirc
        config = get_distutils_config(repository)

        parsed = urllib_parse.urlparse(config["repository"])
        if parsed.netloc == "pypi.python.org" and parsed.scheme == "http":
            config["repository"] = urllib_parse.urlunparse(
                ("https",) + parsed[1:]
            )

        logger.info("Uploading distributions to %s", config["repository"])

        session = requests.session()

        for filename in dists:
            # Sign the dist if requested
            if sign:
                logger.info("Signing %s", os.path.basename(filename))
                gpg_args = ["gpg", "--detach-sign", "-a", filename]
                if identity:
                    gpg_args[2:2] = ["--local-user", identity]
                distutils.spawn.spawn(gpg_args)

            # Extract the metadata from the package
            for ext, dtype in self.DIST_EXTENSIONS.items():
                if filename.endswith(ext):
                    meta = self.DIST_TYPES[dtype](filename)
                    break
            else:
                raise ValueError(
                    "Unknown distribution format: '%s'" %
                    os.path.basename(filename)
                )

            if dtype == "bdist_egg":
                pkgd = pkg_resources.Distribution.from_filename(filename)
{'fraction_non_alphanumeric': 0.09483534281086918, 'fraction_numerical': 0.004138923879791255, 'mean_word_length': 2.288757396449704, 'pattern_counts': {'":': 19, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6241224', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1477, 'n_words': 485}