annotate Lib/distutils/command/register.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 8d837bd8148a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1 """distutils.command.register
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
3 Implements the Distutils 'register' command (register with the repository).
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
4 """
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
5
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
6 # created 2002/10/21, Richard Jones
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
7
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
8 __revision__ = "$Id$"
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
9
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54110
diff changeset
10 import urllib2
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54110
diff changeset
11 import getpass
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 54110
diff changeset
12 import urlparse
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
13 from warnings import warn
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
14
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
15 from distutils.core import PyPIRCCommand
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
16 from distutils import log
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
17
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
18 class register(PyPIRCCommand):
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
19
28151
bda490fc2691 Improve description
Andrew M. Kuchling <amk@amk.ca>
parents: 27976
diff changeset
20 description = ("register the distribution with the Python package index")
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
21 user_options = PyPIRCCommand.user_options + [
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
22 ('list-classifiers', None,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
23 'list the valid Trove classifiers'),
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
24 ('strict', None ,
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
25 'Will stop the registering if the meta-data are not fully compliant')
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
26 ]
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
27 boolean_options = PyPIRCCommand.boolean_options + [
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
28 'verify', 'list-classifiers', 'strict']
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
29
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
30 sub_commands = [('check', lambda self: True)]
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
31
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
32 def initialize_options(self):
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
33 PyPIRCCommand.initialize_options(self)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
34 self.list_classifiers = 0
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
35 self.strict = 0
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
36
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
37 def finalize_options(self):
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
38 PyPIRCCommand.finalize_options(self)
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
39 # setting options for the `check` subcommand
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
40 check_options = {'strict': ('register', self.strict),
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
41 'restructuredtext': ('register', 1)}
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
42 self.distribution.command_options['check'] = check_options
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
43
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
44 def run(self):
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
45 self.finalize_options()
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
46 self._set_config()
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
47
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
48 # Run sub commands
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
49 for cmd_name in self.get_sub_commands():
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
50 self.run_command(cmd_name)
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
51
28544
ee8853cc8ca1 Remove the --verify option in favor of the standard -n/--dry-run option
Andrew M. Kuchling <amk@amk.ca>
parents: 28151
diff changeset
52 if self.dry_run:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
53 self.verify_metadata()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
54 elif self.list_classifiers:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
55 self.classifiers()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
56 else:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
57 self.send_metadata()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
58
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
59 def check_metadata(self):
54110
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
60 """Deprecated API."""
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
61 warn("distutils.command.register.check_metadata is deprecated, \
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
62 use the check command instead", PendingDeprecationWarning)
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
63 check = self.distribution.get_command_obj('check')
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
64 check.ensure_finalized()
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
65 check.strict = self.strict
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
66 check.restructuredtext = 1
d514a8b7ae78 #6041: sdist and register now use the check command. No more duplicate code for metadata checking
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 52584
diff changeset
67 check.run()
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
68
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
69 def _set_config(self):
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
70 ''' Reads the configuration file and set attributes.
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
71 '''
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
72 config = self._read_pypirc()
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
73 if config != {}:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
74 self.username = config['username']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
75 self.password = config['password']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
76 self.repository = config['repository']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
77 self.realm = config['realm']
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
78 self.has_config = True
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
79 else:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
80 if self.repository not in ('pypi', self.DEFAULT_REPOSITORY):
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
81 raise ValueError('%s not found in .pypirc' % self.repository)
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
82 if self.repository == 'pypi':
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
83 self.repository = self.DEFAULT_REPOSITORY
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
84 self.has_config = False
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
85
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
86 def classifiers(self):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
87 ''' Fetch the list of classifiers from the server.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
88 '''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
89 response = urllib2.urlopen(self.repository+'?:action=list_classifiers')
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
90 log.info(response.read())
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
91
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
92 def verify_metadata(self):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
93 ''' Send the metadata to the package index server to be checked.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
94 '''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
95 # send the info to the server and report the result
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
96 (code, result) = self.post_to_server(self.build_post_data('verify'))
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
97 log.info('Server response (%s): %s' % (code, result))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
98
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
99
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
100 def send_metadata(self):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
101 ''' Send the metadata to the package index server.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
102
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
103 Well, do the following:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
104 1. figure who the user is, and then
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
105 2. send the data as a Basic auth'ed POST.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
106
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
107 First we try to read the username/password from $HOME/.pypirc,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
108 which is a ConfigParser-formatted file with a section
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
109 [distutils] containing username and password entries (both
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
110 in clear text). Eg:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
111
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
112 [distutils]
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
113 index-servers =
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
114 pypi
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
115
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
116 [pypi]
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
117 username: fred
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
118 password: sekrit
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
119
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
120 Otherwise, to figure who the user is, we offer the user three
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
121 choices:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
122
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
123 1. use existing login,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
124 2. register as a new user, or
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
125 3. set the password to a random string and email the user.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
126
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
127 '''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
128 # see if we can short-cut and get the username/password from the
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
129 # config
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
130 if self.has_config:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
131 choice = '1'
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
132 username = self.username
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
133 password = self.password
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
134 else:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
135 choice = 'x'
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
136 username = password = ''
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
137
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
138 # get the user's login info
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
139 choices = '1 2 3 4'.split()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
140 while choice not in choices:
50298
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
141 self.announce('''\
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
142 We need to know who you are, so please choose either:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
143 1. use your existing login,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
144 2. register as a new user,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
145 3. have the server generate a new password for you (and email it to you), or
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
146 4. quit
50298
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
147 Your selection [default 1]: ''', log.INFO)
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
148
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
149 choice = raw_input()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
150 if not choice:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
151 choice = '1'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
152 elif choice not in choices:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
153 print 'Please choose one of the four options!'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
154
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
155 if choice == '1':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
156 # get the username and password
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
157 while not username:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
158 username = raw_input('Username: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
159 while not password:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
160 password = getpass.getpass('Password: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
161
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
162 # set up the authentication
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
163 auth = urllib2.HTTPPasswordMgr()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
164 host = urlparse.urlparse(self.repository)[1]
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
165 auth.add_password(self.realm, host, username, password)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
166 # send the info to the server and report the result
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
167 code, result = self.post_to_server(self.build_post_data('submit'),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
168 auth)
50298
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
169 self.announce('Server response (%s): %s' % (code, result),
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
170 log.INFO)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
171
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
172 # possibly save the login
50637
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
173 if code == 200:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
174 if self.has_config:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
175 # sharing the password in the distribution instance
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
176 # so the upload command can reuse it
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
177 self.distribution.password = password
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
178 else:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
179 self.announce(('I can store your PyPI login so future '
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
180 'submissions will be faster.'), log.INFO)
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
181 self.announce('(the login will be stored in %s)' % \
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
182 self._get_rc_file(), log.INFO)
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
183 choice = 'X'
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
184 while choice.lower() not in 'yn':
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
185 choice = raw_input('Save your login (y/N)?')
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
186 if not choice:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
187 choice = 'n'
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
188 if choice.lower() == 'y':
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
189 self._store_pypirc(username, password)
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
190
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
191 elif choice == '2':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
192 data = {':action': 'user'}
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
193 data['name'] = data['password'] = data['email'] = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
194 data['confirm'] = None
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
195 while not data['name']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
196 data['name'] = raw_input('Username: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
197 while data['password'] != data['confirm']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
198 while not data['password']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
199 data['password'] = getpass.getpass('Password: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
200 while not data['confirm']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
201 data['confirm'] = getpass.getpass(' Confirm: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
202 if data['password'] != data['confirm']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
203 data['password'] = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
204 data['confirm'] = None
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
205 print "Password and confirm don't match!"
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
206 while not data['email']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
207 data['email'] = raw_input(' EMail: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
208 code, result = self.post_to_server(data)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
209 if code != 200:
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
210 log.info('Server response (%s): %s' % (code, result))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
211 else:
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
212 log.info('You will receive an email shortly.')
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
213 log.info(('Follow the instructions in it to '
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
214 'complete registration.'))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
215 elif choice == '3':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
216 data = {':action': 'password_reset'}
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
217 data['email'] = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
218 while not data['email']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
219 data['email'] = raw_input('Your email address: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
220 code, result = self.post_to_server(data)
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
221 log.info('Server response (%s): %s' % (code, result))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
222
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
223 def build_post_data(self, action):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
224 # figure the data to send - the metadata plus some additional
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
225 # information used by the package server
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
226 meta = self.distribution.metadata
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
227 data = {
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
228 ':action': action,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
229 'metadata_version' : '1.0',
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
230 'name': meta.get_name(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
231 'version': meta.get_version(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
232 'summary': meta.get_description(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
233 'home_page': meta.get_url(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
234 'author': meta.get_contact(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
235 'author_email': meta.get_contact_email(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
236 'license': meta.get_licence(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
237 'description': meta.get_long_description(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
238 'keywords': meta.get_keywords(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
239 'platform': meta.get_platforms(),
27974
d0d29df2b639 [Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents: 27945
diff changeset
240 'classifiers': meta.get_classifiers(),
27976
d5ea2b67b5f4 Include download_url in the data POSTed to the catalog server
Andrew M. Kuchling <amk@amk.ca>
parents: 27974
diff changeset
241 'download_url': meta.get_download_url(),
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
242 # PEP 314
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
243 'provides': meta.get_provides(),
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
244 'requires': meta.get_requires(),
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
245 'obsoletes': meta.get_obsoletes(),
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
246 }
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
247 if data['provides'] or data['requires'] or data['obsoletes']:
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
248 data['metadata_version'] = '1.1'
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
249 return data
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
250
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
251 def post_to_server(self, data, auth=None):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
252 ''' Post a query to the server, and return a string response.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
253 '''
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
254 if 'name' in data:
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
255 self.announce('Registering %s to %s' % (data['name'],
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
256 self.repository),
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
257 log.INFO)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
258 # Build up the MIME payload for the urllib2 POST data
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
259 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
260 sep_boundary = '\n--' + boundary
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
261 end_boundary = sep_boundary + '--'
72834
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
262 chunks = []
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
263 for key, value in data.items():
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
264 # handle multiple entries for the same name
40034
0e9fdb164d20 [Bug #1545341] Allow 'classifier' parameter to be a tuple as well as a list. Will backport.
Andrew M. Kuchling <amk@amk.ca>
parents: 34852
diff changeset
265 if type(value) not in (type([]), type( () )):
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
266 value = [value]
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
267 for value in value:
72834
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
268 chunks.append(sep_boundary)
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
269 chunks.append('\nContent-Disposition: form-data; name="%s"'%key)
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
270 chunks.append("\n\n")
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
271 chunks.append(value)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
272 if value and value[-1] == '\r':
72834
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
273 chunks.append('\n') # write an extra newline (lurve Macs)
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
274 chunks.append(end_boundary)
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
275 chunks.append("\n")
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
276
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
277 # chunks may be bytes (str) or unicode objects that we need to encode
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
278 body = []
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
279 for chunk in chunks:
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
280 if isinstance(chunk, unicode):
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
281 body.append(chunk.encode('utf-8'))
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
282 else:
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
283 body.append(chunk)
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
284
8d837bd8148a Fix distutils’ check and register Unicode handling (#13114).
Éric Araujo <merwok@netwok.org>
parents: 68256
diff changeset
285 body = ''.join(body)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
286
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
287 # build the Request
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
288 headers = {
34852
63c5d6ce0763 Since PyPI only accepts UTF-8 encoded data now, make sure that the data is
Walter Dörwald <walter@livinglogic.de>
parents: 34785
diff changeset
289 'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary,
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
290 'Content-length': str(len(body))
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
291 }
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
292 req = urllib2.Request(self.repository, body, headers)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
293
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
294 # handle HTTP and include the Basic Auth handler
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
295 opener = urllib2.build_opener(
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
296 urllib2.HTTPBasicAuthHandler(password_mgr=auth)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
297 )
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
298 data = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
299 try:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
300 result = opener.open(req)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
301 except urllib2.HTTPError, e:
27974
d0d29df2b639 [Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents: 27945
diff changeset
302 if self.show_response:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
303 data = e.fp.read()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
304 result = e.code, e.msg
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
305 except urllib2.URLError, e:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
306 result = 500, str(e)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
307 else:
27974
d0d29df2b639 [Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents: 27945
diff changeset
308 if self.show_response:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
309 data = result.read()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
310 result = 200, 'OK'
27974
d0d29df2b639 [Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents: 27945
diff changeset
311 if self.show_response:
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
312 dashes = '-' * 75
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
313 self.announce('%s%s%s' % (dashes, data, dashes))
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
314
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
315 return result