Psyduck - 可達鴨 之 鴨力山大2


Server : LiteSpeed
System : Linux premium217.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User : alloknri ( 880)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /lib/python2.7/site-packages/setuptools/command/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python2.7/site-packages/setuptools/command/upload_docs.py
# -*- coding: utf-8 -*-
"""upload_docs

Implements a Distutils 'upload_docs' subcommand (upload documentation to
PyPI's pythonhosted.org).
"""

from base64 import standard_b64encode
from distutils import log
from distutils.errors import DistutilsOptionError
import os
import socket
import zipfile
import tempfile
import shutil
import itertools
import functools

from setuptools.extern import six
from setuptools.extern.six.moves import http_client, urllib

from pkg_resources import iter_entry_points
from .upload import upload


def _encode(s):
    errors = 'surrogateescape' if six.PY3 else 'strict'
    return s.encode('utf-8', errors)


class upload_docs(upload):
    # override the default repository as upload_docs isn't
    # supported by Warehouse (and won't be).
    DEFAULT_REPOSITORY = 'https://pypi.python.org/pypi/'

    description = 'Upload documentation to PyPI'

    user_options = [
        ('repository=', 'r',
         "url of repository [default: %s]" % upload.DEFAULT_REPOSITORY),
        ('show-response', None,
         'display full response text from server'),
        ('upload-dir=', None, 'directory to upload'),
    ]
    boolean_options = upload.boolean_options

    def has_sphinx(self):
        if self.upload_dir is None:
            for ep in iter_entry_points('distutils.commands', 'build_sphinx'):
                return True

    sub_commands = [('build_sphinx', has_sphinx)]

    def initialize_options(self):
        upload.initialize_options(self)
        self.upload_dir = None
        self.target_dir = None

    def finalize_options(self):
        upload.finalize_options(self)
        if self.upload_dir is None:
            if self.has_sphinx():
                build_sphinx = self.get_finalized_command('build_sphinx')
                self.target_dir = build_sphinx.builder_target_dir
            else:
                build = self.get_finalized_command('build')
                self.target_dir = os.path.join(build.build_base, 'docs')
        else:
            self.ensure_dirname('upload_dir')
            self.target_dir = self.upload_dir
        if 'pypi.python.org' in self.repository:
            log.warn("Upload_docs command is deprecated. Use RTD instead.")
        self.announce('Using upload directory %s' % self.target_dir)

    def create_zipfile(self, filename):
        zip_file = zipfile.ZipFile(filename, "w")
        try:
            self.mkpath(self.target_dir)  # just in case
            for root, dirs, files in os.walk(self.target_dir):
                if root == self.target_dir and not files:
                    tmpl = "no files found in upload directory '%s'"
                    raise DistutilsOptionError(tmpl % self.target_dir)
                for name in files:
                    full = os.path.join(root, name)
                    relative = root[len(self.target_dir):].lstrip(os.path.sep)
                    dest = os.path.join(relative, name)
                    zip_file.write(full, dest)
        finally:
            zip_file.close()

    def run(self):
        # Run sub commands
        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)

        tmp_dir = tempfile.mkdtemp()
        name = self.distribution.metadata.get_name()
        zip_file = os.path.join(tmp_dir, "%s.zip" % name)
        try:
            self.create_zipfile(zip_file)
            self.upload_file(zip_file)
        finally:
            shutil.rmtree(tmp_dir)

    @staticmethod
    def _build_part(item, sep_boundary):
        key, values = item
        title = '\nContent-Disposition: form-data; name="%s"' % key
        # handle multiple entries for the same name
        if not isinstance(values, list):
            values = [values]
        for value in values:
            if isinstance(value, tuple):
                title += '; filename="%s"' % value[0]
                value = value[1]
            else:
                value = _encode(value)
            yield sep_boundary
            yield _encode(title)
            yield b"\n\n"
            yield value
            if value and value[-1:] == b'\r':
                yield b'\n'  # write an extra newline (lurve Macs)

    @classmethod
    def _build_multipart(cls, data):
        """
        Build up the MIME payload for the POST data
        """
        boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
        sep_boundary = b'\n--' + boundary
        end_boundary = sep_boundary + b'--'
        end_items = end_boundary, b"\n",
        builder = functools.partial(
            cls._build_part,
            sep_boundary=sep_boundary,
        )
        part_groups = map(builder, data.items())
        parts = itertools.chain.from_iterable(part_groups)
        body_items = itertools.chain(parts, end_items)
        content_type = 'multipart/form-data; boundary=%s' % boundary.decode('ascii')
        return b''.join(body_items), content_type

    def upload_file(self, filename):
        with open(filename, 'rb') as f:
            content = f.read()
        meta = self.distribution.metadata
        data = {
            ':action': 'doc_upload',
            'name': meta.get_name(),
            'content': (os.path.basename(filename), content),
        }
        # set up the authentication
        credentials = _encode(self.username + ':' + self.password)
        credentials = standard_b64encode(credentials)
        if six.PY3:
            credentials = credentials.decode('ascii')
        auth = "Basic " + credentials

        body, ct = self._build_multipart(data)

        msg = "Submitting documentation to %s" % (self.repository)
        self.announce(msg, log.INFO)

        # build the Request
        # We can't use urllib2 since we need to send the Basic
        # auth right with the first request
        schema, netloc, url, params, query, fragments = \
            urllib.parse.urlparse(self.repository)
        assert not params and not query and not fragments
        if schema == 'http':
            conn = http_client.HTTPConnection(netloc)
        elif schema == 'https':
            conn = http_client.HTTPSConnection(netloc)
        else:
            raise AssertionError("unsupported schema " + schema)

        data = ''
        try:
            conn.connect()
            conn.putrequest("POST", url)
            content_type = ct
            conn.putheader('Content-type', content_type)
            conn.putheader('Content-length', str(len(body)))
            conn.putheader('Authorization', auth)
            conn.endheaders()
            conn.send(body)
        except socket.error as e:
            self.announce(str(e), log.ERROR)
            return

        r = conn.getresponse()
        if r.status == 200:
            msg = 'Server response (%s): %s' % (r.status, r.reason)
            self.announce(msg, log.INFO)
        elif r.status == 301:
            location = r.getheader('Location')
            if location is None:
                location = 'https://pythonhosted.org/%s/' % meta.get_name()
            msg = 'Upload successful. Visit %s' % location
            self.announce(msg, log.INFO)
        else:
            msg = 'Upload failed (%s): %s' % (r.status, r.reason)
            self.announce(msg, log.ERROR)
        if self.show_response:
            print('-' * 75, r.read(), '-' * 75)
Name
Size
Permissions
Options
__init__.py
0.58 KB
-rw-r--r--
__init__.pyc
0.861 KB
-rw-r--r--
__init__.pyo
0.861 KB
-rw-r--r--
alias.py
2.369 KB
-rw-r--r--
alias.pyc
3.025 KB
-rw-r--r--
alias.pyo
3.025 KB
-rw-r--r--
bdist_egg.py
17.759 KB
-rw-r--r--
bdist_egg.pyc
17.957 KB
-rw-r--r--
bdist_egg.pyo
17.957 KB
-rw-r--r--
bdist_rpm.py
1.473 KB
-rw-r--r--
bdist_rpm.pyc
1.869 KB
-rw-r--r--
bdist_rpm.pyo
1.869 KB
-rw-r--r--
bdist_wininst.py
0.622 KB
-rw-r--r--
bdist_wininst.pyc
1.163 KB
-rw-r--r--
bdist_wininst.pyo
1.163 KB
-rw-r--r--
build_clib.py
4.379 KB
-rw-r--r--
build_clib.pyc
2.777 KB
-rw-r--r--
build_clib.pyo
2.777 KB
-rw-r--r--
build_ext.py
12.864 KB
-rw-r--r--
build_ext.pyc
12.276 KB
-rw-r--r--
build_ext.pyo
12.233 KB
-rw-r--r--
build_py.py
9.371 KB
-rw-r--r--
build_py.pyc
10.417 KB
-rw-r--r--
build_py.pyo
10.417 KB
-rw-r--r--
develop.py
7.857 KB
-rw-r--r--
develop.pyc
7.715 KB
-rw-r--r--
develop.pyo
7.715 KB
-rw-r--r--
dist_info.py
0.938 KB
-rw-r--r--
dist_info.pyc
1.757 KB
-rw-r--r--
dist_info.pyo
1.757 KB
-rw-r--r--
easy_install.py
84.992 KB
-rw-r--r--
easy_install.pyc
78.498 KB
-rw-r--r--
easy_install.pyo
78.442 KB
-rw-r--r--
egg_info.py
24.219 KB
-rw-r--r--
egg_info.pyc
25.289 KB
-rw-r--r--
egg_info.pyo
25.289 KB
-rw-r--r--
install.py
4.573 KB
-rw-r--r--
install.pyc
4.837 KB
-rw-r--r--
install.pyo
4.837 KB
-rw-r--r--
install_egg_info.py
2.151 KB
-rw-r--r--
install_egg_info.pyc
3.11 KB
-rw-r--r--
install_egg_info.pyo
3.11 KB
-rw-r--r--
install_lib.py
3.75 KB
-rw-r--r--
install_lib.pyc
4.756 KB
-rw-r--r--
install_lib.pyo
4.711 KB
-rw-r--r--
install_scripts.py
2.382 KB
-rw-r--r--
install_scripts.pyc
2.823 KB
-rw-r--r--
install_scripts.pyo
2.823 KB
-rw-r--r--
launcher manifest.xml
0.613 KB
-rw-r--r--
py36compat.py
4.869 KB
-rw-r--r--
py36compat.pyc
5.42 KB
-rw-r--r--
py36compat.pyo
5.42 KB
-rw-r--r--
register.py
0.264 KB
-rw-r--r--
register.pyc
0.693 KB
-rw-r--r--
register.pyo
0.693 KB
-rw-r--r--
rotate.py
2.113 KB
-rw-r--r--
rotate.pyc
2.965 KB
-rw-r--r--
rotate.pyo
2.965 KB
-rw-r--r--
saveopts.py
0.643 KB
-rw-r--r--
saveopts.pyc
1.103 KB
-rw-r--r--
saveopts.pyo
1.103 KB
-rw-r--r--
sdist.py
6.554 KB
-rw-r--r--
sdist.pyc
7.64 KB
-rw-r--r--
sdist.pyo
7.64 KB
-rw-r--r--
setopt.py
4.966 KB
-rw-r--r--
setopt.pyc
5.908 KB
-rw-r--r--
setopt.pyo
5.908 KB
-rw-r--r--
test.py
8.998 KB
-rw-r--r--
test.pyc
10.223 KB
-rw-r--r--
test.pyo
10.223 KB
-rw-r--r--
upload.py
1.145 KB
-rw-r--r--
upload.pyc
1.598 KB
-rw-r--r--
upload.pyo
1.598 KB
-rw-r--r--
upload_docs.py
7.14 KB
-rw-r--r--
upload_docs.pyc
7.658 KB
-rw-r--r--
upload_docs.pyo
7.63 KB
-rw-r--r--