PNG  IHDR  8] PLTE S =tRNS   PNG  IHDR  8] PLTE S =tRNS   REDROOM
PHP 7.4.33
Preview: register.py Size: 11.56 KB
/opt/alt/python27/lib64/python2.7/distutils/command/register.py

"""distutils.command.register

Implements the Distutils 'register' command (register with the repository).
"""

# created 2002/10/21, Richard Jones

__revision__ = "$Id$"

import urllib2
import getpass
import urlparse
from warnings import warn

from distutils.core import PyPIRCCommand
from distutils import log

class register(PyPIRCCommand):

    description = ("register the distribution with the Python package index")
    user_options = PyPIRCCommand.user_options + [
        ('list-classifiers', None,
         'list the valid Trove classifiers'),
        ('strict', None ,
         'Will stop the registering if the meta-data are not fully compliant')
        ]
    boolean_options = PyPIRCCommand.boolean_options + [
        'verify', 'list-classifiers', 'strict']

    sub_commands = [('check', lambda self: True)]

    def initialize_options(self):
        PyPIRCCommand.initialize_options(self)
        self.list_classifiers = 0
        self.strict = 0

    def finalize_options(self):
        PyPIRCCommand.finalize_options(self)
        # setting options for the `check` subcommand
        check_options = {'strict': ('register', self.strict),
                         'restructuredtext': ('register', 1)}
        self.distribution.command_options['check'] = check_options

    def run(self):
        self.finalize_options()
        self._set_config()

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

        if self.dry_run:
            self.verify_metadata()
        elif self.list_classifiers:
            self.classifiers()
        else:
            self.send_metadata()

    def check_metadata(self):
        """Deprecated API."""
        warn("distutils.command.register.check_metadata is deprecated, \
              use the check command instead", PendingDeprecationWarning)
        check = self.distribution.get_command_obj('check')
        check.ensure_finalized()
        check.strict = self.strict
        check.restructuredtext = 1
        check.run()

    def _set_config(self):
        ''' Reads the configuration file and set attributes.
        '''
        config = self._read_pypirc()
        if config != {}:
            self.username = config['username']
            self.password = config['password']
            self.repository = config['repository']
            self.realm = config['realm']
            self.has_config = True
        else:
            if self.repository not in ('pypi', self.DEFAULT_REPOSITORY):
                raise ValueError('%s not found in .pypirc' % self.repository)
            if self.repository == 'pypi':
                self.repository = self.DEFAULT_REPOSITORY
            self.has_config = False

    def classifiers(self):
        ''' Fetch the list of classifiers from the server.
        '''
        response = urllib2.urlopen(self.repository+'?:action=list_classifiers')
        log.info(response.read())

    def verify_metadata(self):
        ''' Send the metadata to the package index server to be checked.
        '''
        # send the info to the server and report the result
        (code, result) = self.post_to_server(self.build_post_data('verify'))
        log.info('Server response (%s): %s' % (code, result))


    def send_metadata(self):
        ''' Send the metadata to the package index server.

            Well, do the following:
            1. figure who the user is, and then
            2. send the data as a Basic auth'ed POST.

            First we try to read the username/password from $HOME/.pypirc,
            which is a ConfigParser-formatted file with a section
            [distutils] containing username and password entries (both
            in clear text). Eg:

                [distutils]
                index-servers =
                    pypi

                [pypi]
                username: fred
                password: sekrit

            Otherwise, to figure who the user is, we offer the user three
            choices:

             1. use existing login,
             2. register as a new user, or
             3. set the password to a random string and email the user.

        '''
        # see if we can short-cut and get the username/password from the
        # config
        if self.has_config:
            choice = '1'
            username = self.username
            password = self.password
        else:
            choice = 'x'
            username = password = ''

        # get the user's login info
        choices = '1 2 3 4'.split()
        while choice not in choices:
            self.announce('''\
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]: ''', log.INFO)

            choice = raw_input()
            if not choice:
                choice = '1'
            elif choice not in choices:
                print 'Please choose one of the four options!'

        if choice == '1':
            # get the username and password
            while not username:
                username = raw_input('Username: ')
            while not password:
                password = getpass.getpass('Password: ')

            # set up the authentication
            auth = urllib2.HTTPPasswordMgr()
            host = urlparse.urlparse(self.repository)[1]
            auth.add_password(self.realm, host, username, password)
            # send the info to the server and report the result
            code, result = self.post_to_server(self.build_post_data('submit'),
                auth)
            self.announce('Server response (%s): %s' % (code, result),
                          log.INFO)

            # possibly save the login
            if code == 200:
                if self.has_config:
                    # sharing the password in the distribution instance
                    # so the upload command can reuse it
                    self.distribution.password = password
                else:
                    self.announce(('I can store your PyPI login so future '
                                   'submissions will be faster.'), log.INFO)
                    self.announce('(the login will be stored in %s)' % \
                                  self._get_rc_file(), log.INFO)
                    choice = 'X'
                    while choice.lower() not in 'yn':
                        choice = raw_input('Save your login (y/N)?')
                        if not choice:
                            choice = 'n'
                    if choice.lower() == 'y':
                        self._store_pypirc(username, password)

        elif choice == '2':
            data = {':action': 'user'}
            data['name'] = data['password'] = data['email'] = ''
            data['confirm'] = None
            while not data['name']:
                data['name'] = raw_input('Username: ')
            while data['password'] != data['confirm']:
                while not data['password']:
                    data['password'] = getpass.getpass('Password: ')
                while not data['confirm']:
                    data['confirm'] = getpass.getpass(' Confirm: ')
                if data['password'] != data['confirm']:
                    data['password'] = ''
                    data['confirm'] = None
                    print "Password and confirm don't match!"
            while not data['email']:
                data['email'] = raw_input('   EMail: ')
            code, result = self.post_to_server(data)
            if code != 200:
                log.info('Server response (%s): %s' % (code, result))
            else:
                log.info('You will receive an email shortly.')
                log.info(('Follow the instructions in it to '
                          'complete registration.'))
        elif choice == '3':
            data = {':action': 'password_reset'}
            data['email'] = ''
            while not data['email']:
                data['email'] = raw_input('Your email address: ')
            code, result = self.post_to_server(data)
            log.info('Server response (%s): %s' % (code, result))

    def build_post_data(self, action):
        # figure the data to send - the metadata plus some additional
        # information used by the package server
        meta = self.distribution.metadata
        data = {
            ':action': action,
            'metadata_version' : '1.0',
            'name': meta.get_name(),
            'version': meta.get_version(),
            'summary': meta.get_description(),
            'home_page': meta.get_url(),
            'author': meta.get_contact(),
            'author_email': meta.get_contact_email(),
            'license': meta.get_licence(),
            'description': meta.get_long_description(),
            'keywords': meta.get_keywords(),
            'platform': meta.get_platforms(),
            'classifiers': meta.get_classifiers(),
            'download_url': meta.get_download_url(),
            # PEP 314
            'provides': meta.get_provides(),
            'requires': meta.get_requires(),
            'obsoletes': meta.get_obsoletes(),
        }
        if data['provides'] or data['requires'] or data['obsoletes']:
            data['metadata_version'] = '1.1'
        return data

    def post_to_server(self, data, auth=None):
        ''' Post a query to the server, and return a string response.
        '''
        if 'name' in data:
            self.announce('Registering %s to %s' % (data['name'],
                                                   self.repository),
                                                   log.INFO)
        # Build up the MIME payload for the urllib2 POST data
        boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
        sep_boundary = '\n--' + boundary
        end_boundary = sep_boundary + '--'
        chunks = []
        for key, value in data.items():
            # handle multiple entries for the same name
            if type(value) not in (type([]), type( () )):
                value = [value]
            for value in value:
                chunks.append(sep_boundary)
                chunks.append('\nContent-Disposition: form-data; name="%s"'%key)
                chunks.append("\n\n")
                chunks.append(value)
                if value and value[-1] == '\r':
                    chunks.append('\n')  # write an extra newline (lurve Macs)
        chunks.append(end_boundary)
        chunks.append("\n")

        # chunks may be bytes (str) or unicode objects that we need to encode
        body = []
        for chunk in chunks:
            if isinstance(chunk, unicode):
                body.append(chunk.encode('utf-8'))
            else:
                body.append(chunk)

        body = ''.join(body)

        # build the Request
        headers = {
            'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary,
            'Content-length': str(len(body))
        }
        req = urllib2.Request(self.repository, body, headers)

        # handle HTTP and include the Basic Auth handler
        opener = urllib2.build_opener(
            urllib2.HTTPBasicAuthHandler(password_mgr=auth)
        )
        data = ''
        try:
            result = opener.open(req)
        except urllib2.HTTPError, e:
            if self.show_response:
                data = e.fp.read()
            result = e.code, e.msg
        except urllib2.URLError, e:
            result = 500, str(e)
        else:
            if self.show_response:
                data = result.read()
            result = 200, 'OK'
        if self.show_response:
            dashes = '-' * 75
            self.announce('%s%s%s' % (dashes, data, dashes))

        return result

Directory Contents

Dirs: 0 × Files: 76

Name Size Perms Modified Actions
5.46 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.12 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
5.12 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.07 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.93 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.93 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
34.37 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
23.62 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
23.51 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
20.56 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
17.31 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
17.23 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
14.65 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
10.60 KB lrw-r--r-- 2025-12-02 12:55:38
Edit Download
10.52 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.33 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.15 KB lrw-r--r-- 2025-12-02 12:55:12
Edit Download
5.15 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
7.94 KB lrw-r--r-- 2025-01-08 10:54:00
Edit Download
6.33 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.33 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
31.74 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
31.51 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
19.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
19.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
15.96 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
11.49 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
11.42 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.49 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
4.46 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
4.46 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
5.54 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.27 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.27 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.75 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.06 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.06 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
719 B lrw-r--r-- 2025-01-08 10:54:01
Edit Download
12.82 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
12.64 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
12.64 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
25.65 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
16.73 KB lrw-r--r-- 2025-12-02 12:55:12
Edit Download
16.73 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.78 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.13 KB lrw-r--r-- 2025-12-02 12:55:38
Edit Download
3.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.53 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.77 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
3.77 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
1.31 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.29 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.29 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
8.14 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.68 KB lrw-r--r-- 2025-12-02 12:55:38
Edit Download
6.68 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.02 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
2.95 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
2.95 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
11.56 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
10.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
10.13 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
18.12 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
16.53 KB lrw-r--r-- 2025-12-02 12:55:37
Edit Download
16.53 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.84 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.24 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
6.24 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
60.00 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
64.00 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
60.00 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
218.50 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
191.50 KB lrw-r--r-- 2025-01-08 10:54:01
Edit Download
822 B lrw-r--r-- 2025-01-08 10:54:01
Edit Download
678 B lrw-r--r-- 2025-12-02 12:55:12
Edit Download
678 B lrw-r--r-- 2025-01-08 10:54:01
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
 !"#$%&'(()*+,-./00123456789 t\ wIDATx ]ys  47Y ƒ -  "  Rv  < f{Ɛ $k l L > L  ~h^ 1  [  r G t& h  l F z3O Y ! p A(_g̷ E8 )S 8 c  Kb"z ~ 5 J xAL WU <  *  5 m;W a pB h ~P J 2 3 6 ҙ .Ƹ P i  4g F R L P ΪK/D  M v (a3 k J Œ4N5* SH ` SdJ z  O J Xՠ V>u ߱ BE&L b2 ?2` tX+  c CB A$ i b C ĀMB E : /  # Dx &l =q Ty  0 \p I ( L Ǎ { e 4k ;`u^ヲ eP!( d {  )T A 8 O;Ě n >;s6 !  :Nx `[S D HU ~ q›J F} a g*D 49 / pn k h (t 8NxƐF _!r չ7 ZR R׷ q/5") Ӎ NY 0 x sZ!   o  fu  ,  K"$ ? pg  㕣=  1» {h " fh7    y  } € +7  $ y " X —ą - G P u 4 m >J 5 L =V ' ^@I p ?MS xЌ XV P ! h "C NS9B8̢ ]!K  e   zA , ӏkbY  !< XQ ٿyS| *" f { w  4@[S <  # 0 ! js [m  =,~ o "ݎ DHf Wo $ g ! Vԅ t mB /y Wf V4񺍸 c+@x?  B ~u " xUN e 0 BĂ) ~J pz! 7y6]l Ԥ@ P a< O /DHC `≻  N m"$  0ObB }{ x AO FCG D R ^ "B  { WDH  UR l@ T #  +"d T ; 0 i  D}. 7 ` ' ] w rE &S i ƕiTD EL P _ u h $ Ա FG wVD G L R Zf ' .!] J /ZR oGЍs Mr Ĥ ʬ 3 Q [3 cL ` ^ p + ( F;# B 5 '  2Y f [  ϶R0e }  E 7 6M aۮ H <& n % L] E}Up x紉, Uw' Q  Ǯշo k ވۙ 0N94 VX5 xEDE l D #֤ } C o )W :  ^ s 9  bRf iX5u ཱི 4 :[  T 1. | [E 2ؽ Iy\ : o x K G 5 ylP ' uK E ftb/i[3 .g _  [3M n G, #NwQ5~  ؚ) | n =Ц"x qg gB ` 듘 ~ x w ? ? R~  _ u. &VQ K˻   H C ( TN˄+ `C dA nB׭ D 3"Z G ê ^k H_ /- ~ " R_  .8 Z_ 6@ o  xg  uP ? 3լ @7AM!  E7^ - =V L  x  g-D0  CtmW 7  O  G _ WD0 g C  w1 r d w : a | \  *" f nֳ ^ H# f L ` Z ۽hV  }S F r0Ù Bć5r] @! NL iQ]{s^=4 d  WD  "  "   M; t" 8 5 e dL| "-*st" ) SWD ?R[S e ooF  20.D ? bo =) A i o d ģ ZҰaO @E =) i D a &ܟa CϞ y6 ,<%{^x%{f8? `iw^ ?/ M * IEND B`