annotate Lib/distutils/command/register.py @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 807d83f57bc8
children b36cb4602e21
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
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
13 import StringIO
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
14 from warnings import warn
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
15
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
16 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
17 from distutils import log
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
18
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
19 class register(PyPIRCCommand):
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
20
28151
bda490fc2691 Improve description
Andrew M. Kuchling <amk@amk.ca>
parents: 27976
diff changeset
21 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
22 user_options = PyPIRCCommand.user_options + [
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
23 ('list-classifiers', None,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
24 '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
25 ('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
26 '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
27 ]
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
28 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
29 '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
30
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
31 sub_commands = [('check', lambda self: True)]
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
32
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
33 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
34 PyPIRCCommand.initialize_options(self)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
35 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
36 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
37
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 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
39 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
40 # 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
41 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
42 '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
43 self.distribution.command_options['check'] = check_options
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
44
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
45 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
46 self.finalize_options()
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
47 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
48
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 # 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
50 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
51 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
52
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
53 if self.dry_run:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
54 self.verify_metadata()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
55 elif self.list_classifiers:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
56 self.classifiers()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
57 else:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
58 self.send_metadata()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
59
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
60 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
61 """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
62 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
63 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
64 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
65 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
66 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
67 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
68 check.run()
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
69
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
70 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
71 ''' 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
72 '''
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
73 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
74 if config != {}:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
75 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
76 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
77 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
78 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
79 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
80 else:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
81 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
82 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
83 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
84 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
85 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
86
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
87 def classifiers(self):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
88 ''' Fetch the list of classifiers from the server.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
89 '''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
90 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
91 log.info(response.read())
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
92
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
93 def verify_metadata(self):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
94 ''' 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
95 '''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
96 # 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
97 (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
98 log.info('Server response (%s): %s' % (code, result))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
99
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
100
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
101 def send_metadata(self):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
102 ''' Send the metadata to the package index server.
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
103
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
104 Well, do the following:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
105 1. figure who the user is, and then
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
106 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
107
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
108 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
109 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
110 [distutils] containing username and password entries (both
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
111 in clear text). Eg:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
112
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
113 [distutils]
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
114 index-servers =
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
115 pypi
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
116
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
117 [pypi]
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
118 username: fred
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
119 password: sekrit
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
120
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
121 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
122 choices:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
123
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
124 1. use existing login,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
125 2. register as a new user, or
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
126 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
127
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
128 '''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
129 # 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
130 # config
46881
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
131 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
132 choice = '1'
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
133 username = self.username
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
134 password = self.password
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
135 else:
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
136 choice = 'x'
0df616193b98 #1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents: 46836
diff changeset
137 username = password = ''
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
138
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
139 # get the user's login info
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
140 choices = '1 2 3 4'.split()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
141 while choice not in choices:
50298
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
142 self.announce('''\
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
143 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
144 1. use your existing login,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
145 2. register as a new user,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
146 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
147 4. quit
50298
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
148 Your selection [default 1]: ''', log.INFO)
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
149
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
150 choice = raw_input()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
151 if not choice:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
152 choice = '1'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
153 elif choice not in choices:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
154 print 'Please choose one of the four options!'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
155
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
156 if choice == '1':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
157 # get the username and password
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
158 while not username:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
159 username = raw_input('Username: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
160 while not password:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
161 password = getpass.getpass('Password: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
162
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
163 # set up the authentication
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
164 auth = urllib2.HTTPPasswordMgr()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
165 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
166 auth.add_password(self.realm, host, username, password)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
167 # 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
168 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
169 auth)
50298
fb150fcf165d Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 46881
diff changeset
170 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
171 log.INFO)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
172
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
173 # 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
174 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
175 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
176 # 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
177 # 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
178 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
179 else:
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
180 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
181 '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
182 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
183 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
184 choice = 'X'
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
185 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
186 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
187 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
188 choice = 'n'
a3f329f23b23 fixed #4394 make the storage of the password optional in .pypirc
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50298
diff changeset
189 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
190 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
191
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
192 elif choice == '2':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
193 data = {':action': 'user'}
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
194 data['name'] = data['password'] = data['email'] = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
195 data['confirm'] = None
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
196 while not data['name']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
197 data['name'] = raw_input('Username: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
198 while data['password'] != data['confirm']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
199 while not data['password']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
200 data['password'] = getpass.getpass('Password: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
201 while not data['confirm']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
202 data['confirm'] = getpass.getpass(' Confirm: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
203 if data['password'] != data['confirm']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
204 data['password'] = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
205 data['confirm'] = None
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
206 print "Password and confirm don't match!"
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
207 while not data['email']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
208 data['email'] = raw_input(' EMail: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
209 code, result = self.post_to_server(data)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
210 if code != 200:
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
211 log.info('Server response (%s): %s' % (code, result))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
212 else:
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
213 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
214 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
215 'complete registration.'))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
216 elif choice == '3':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
217 data = {':action': 'password_reset'}
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
218 data['email'] = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
219 while not data['email']:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
220 data['email'] = raw_input('Your email address: ')
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
221 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
222 log.info('Server response (%s): %s' % (code, result))
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
223
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
224 def build_post_data(self, action):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
225 # 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
226 # information used by the package server
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
227 meta = self.distribution.metadata
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
228 data = {
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
229 ':action': action,
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
230 'metadata_version' : '1.0',
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
231 'name': meta.get_name(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
232 'version': meta.get_version(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
233 'summary': meta.get_description(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
234 'home_page': meta.get_url(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
235 'author': meta.get_contact(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
236 'author_email': meta.get_contact_email(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
237 'license': meta.get_licence(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
238 'description': meta.get_long_description(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
239 'keywords': meta.get_keywords(),
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
240 '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
241 '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
242 'download_url': meta.get_download_url(),
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
243 # PEP 314
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
244 'provides': meta.get_provides(),
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
245 'requires': meta.get_requires(),
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
246 'obsoletes': meta.get_obsoletes(),
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
247 }
34785
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
248 if data['provides'] or data['requires'] or data['obsoletes']:
dc6f315f1f7f PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents: 32736
diff changeset
249 data['metadata_version'] = '1.1'
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
250 return data
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
251
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
252 def post_to_server(self, data, auth=None):
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
253 ''' 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
254 '''
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
255 if 'name' in data:
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
256 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
257 self.repository),
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
258 log.INFO)
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
259 # 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
260 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
261 sep_boundary = '\n--' + boundary
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
262 end_boundary = sep_boundary + '--'
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
263 body = StringIO.StringIO()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
264 for key, value in data.items():
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
265 # 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
266 if type(value) not in (type([]), type( () )):
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
267 value = [value]
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
268 for value in value:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
269 body.write(sep_boundary)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
270 body.write('\nContent-Disposition: form-data; name="%s"'%key)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
271 body.write("\n\n")
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
272 body.write(value)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
273 if value and value[-1] == '\r':
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
274 body.write('\n') # write an extra newline (lurve Macs)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
275 body.write(end_boundary)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
276 body.write("\n")
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
277 body = body.getvalue()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
278
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
279 # build the Request
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
280 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
281 '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
282 'Content-length': str(len(body))
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
283 }
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
284 req = urllib2.Request(self.repository, body, headers)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
285
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
286 # handle HTTP and include the Basic Auth handler
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
287 opener = urllib2.build_opener(
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
288 urllib2.HTTPBasicAuthHandler(password_mgr=auth)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
289 )
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
290 data = ''
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
291 try:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
292 result = opener.open(req)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
293 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
294 if self.show_response:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
295 data = e.fp.read()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
296 result = e.code, e.msg
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
297 except urllib2.URLError, e:
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
298 result = 500, str(e)
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
299 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
300 if self.show_response:
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
301 data = result.read()
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
302 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
303 if self.show_response:
52584
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
304 dashes = '-' * 75
efaa67bb3f06 more tests for the register command
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 50637
diff changeset
305 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
306
27049
1cd9c8564875 [Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
307 return result