Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
6f6cd52f
Commit
6f6cd52f
authored
Dec 22, 2013
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Fix TypeError on "setup.py upload --show-response".
parents
91bb029d
a9d12941
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
6 deletions
+26
-6
command/register.py
command/register.py
+1
-4
command/upload.py
command/upload.py
+2
-1
config.py
config.py
+7
-0
tests/test_upload.py
tests/test_upload.py
+16
-1
No files found.
command/register.py
View file @
6f6cd52f
...
@@ -5,7 +5,6 @@ Implements the Distutils 'register' command (register with the repository).
...
@@ -5,7 +5,6 @@ Implements the Distutils 'register' command (register with the repository).
# created 2002/10/21, Richard Jones
# created 2002/10/21, Richard Jones
import
cgi
import
os
,
string
,
getpass
import
os
,
string
,
getpass
import
io
import
io
import
urllib.parse
,
urllib
.
request
import
urllib.parse
,
urllib
.
request
...
@@ -88,9 +87,7 @@ class register(PyPIRCCommand):
...
@@ -88,9 +87,7 @@ class register(PyPIRCCommand):
'''
'''
url
=
self
.
repository
+
'?:action=list_classifiers'
url
=
self
.
repository
+
'?:action=list_classifiers'
response
=
urllib
.
request
.
urlopen
(
url
)
response
=
urllib
.
request
.
urlopen
(
url
)
content_type
=
response
.
getheader
(
'content-type'
,
'text/plain'
)
log
.
info
(
self
.
_read_pypi_response
(
response
))
encoding
=
cgi
.
parse_header
(
content_type
)[
1
].
get
(
'charset'
,
'ascii'
)
log
.
info
(
response
.
read
().
decode
(
encoding
))
def
verify_metadata
(
self
):
def
verify_metadata
(
self
):
''' Send the metadata to the package index server to be checked.
''' Send the metadata to the package index server to be checked.
...
...
command/upload.py
View file @
6f6cd52f
...
@@ -196,5 +196,6 @@ class upload(PyPIRCCommand):
...
@@ -196,5 +196,6 @@ class upload(PyPIRCCommand):
self
.
announce
(
'Upload failed (%s): %s'
%
(
status
,
reason
),
self
.
announce
(
'Upload failed (%s): %s'
%
(
status
,
reason
),
log
.
ERROR
)
log
.
ERROR
)
if
self
.
show_response
:
if
self
.
show_response
:
msg
=
'
\
n
'
.
join
((
'-'
*
75
,
result
.
read
(),
'-'
*
75
))
text
=
self
.
_read_pypi_response
(
result
)
msg
=
'
\
n
'
.
join
((
'-'
*
75
,
text
,
'-'
*
75
))
self
.
announce
(
msg
,
log
.
INFO
)
self
.
announce
(
msg
,
log
.
INFO
)
config.py
View file @
6f6cd52f
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
Provides the PyPIRCCommand class, the base class for the command classes
Provides the PyPIRCCommand class, the base class for the command classes
that uses .pypirc in the distutils.command package.
that uses .pypirc in the distutils.command package.
"""
"""
import
cgi
import
os
import
os
from
configparser
import
ConfigParser
from
configparser
import
ConfigParser
...
@@ -110,6 +111,12 @@ class PyPIRCCommand(Command):
...
@@ -110,6 +111,12 @@ class PyPIRCCommand(Command):
return
{}
return
{}
def
_read_pypi_response
(
self
,
response
):
"""Read and decode a PyPI HTTP response."""
content_type
=
response
.
getheader
(
'content-type'
,
'text/plain'
)
encoding
=
cgi
.
parse_header
(
content_type
)[
1
].
get
(
'charset'
,
'ascii'
)
return
response
.
read
().
decode
(
encoding
)
def
initialize_options
(
self
):
def
initialize_options
(
self
):
"""Initialize options."""
"""Initialize options."""
self
.
repository
=
None
self
.
repository
=
None
...
...
tests/test_upload.py
View file @
6f6cd52f
...
@@ -6,6 +6,7 @@ from test.support import run_unittest
...
@@ -6,6 +6,7 @@ from test.support import run_unittest
from
distutils.command
import
upload
as
upload_mod
from
distutils.command
import
upload
as
upload_mod
from
distutils.command.upload
import
upload
from
distutils.command.upload
import
upload
from
distutils.core
import
Distribution
from
distutils.core
import
Distribution
from
distutils.log
import
INFO
from
distutils.tests.test_config
import
PYPIRC
,
PyPIRCCommandTestCase
from
distutils.tests.test_config
import
PYPIRC
,
PyPIRCCommandTestCase
...
@@ -48,6 +49,14 @@ class FakeOpen(object):
...
@@ -48,6 +49,14 @@ class FakeOpen(object):
self
.
req
=
None
self
.
req
=
None
self
.
msg
=
'OK'
self
.
msg
=
'OK'
def
getheader
(
self
,
name
,
default
=
None
):
return
{
'content-type'
:
'text/plain; charset=utf-8'
,
}.
get
(
name
.
lower
(),
default
)
def
read
(
self
):
return
b'xyzzy'
def
getcode
(
self
):
def
getcode
(
self
):
return
200
return
200
...
@@ -108,10 +117,11 @@ class uploadTestCase(PyPIRCCommandTestCase):
...
@@ -108,10 +117,11 @@ class uploadTestCase(PyPIRCCommandTestCase):
# lets run it
# lets run it
pkg_dir
,
dist
=
self
.
create_dist
(
dist_files
=
dist_files
)
pkg_dir
,
dist
=
self
.
create_dist
(
dist_files
=
dist_files
)
cmd
=
upload
(
dist
)
cmd
=
upload
(
dist
)
cmd
.
show_response
=
1
cmd
.
ensure_finalized
()
cmd
.
ensure_finalized
()
cmd
.
run
()
cmd
.
run
()
# what did we send ?
# what did we send ?
headers
=
dict
(
self
.
last_open
.
req
.
headers
)
headers
=
dict
(
self
.
last_open
.
req
.
headers
)
self
.
assertEqual
(
headers
[
'Content-length'
],
'2087'
)
self
.
assertEqual
(
headers
[
'Content-length'
],
'2087'
)
content_type
=
headers
[
'Content-type'
]
content_type
=
headers
[
'Content-type'
]
...
@@ -121,6 +131,11 @@ class uploadTestCase(PyPIRCCommandTestCase):
...
@@ -121,6 +131,11 @@ class uploadTestCase(PyPIRCCommandTestCase):
self
.
assertEqual
(
self
.
last_open
.
req
.
get_full_url
(),
expected_url
)
self
.
assertEqual
(
self
.
last_open
.
req
.
get_full_url
(),
expected_url
)
self
.
assertTrue
(
b'xxx'
in
self
.
last_open
.
req
.
data
)
self
.
assertTrue
(
b'xxx'
in
self
.
last_open
.
req
.
data
)
# The PyPI response body was echoed
results
=
self
.
get_logs
(
INFO
)
self
.
assertIn
(
'xyzzy
\
n
'
,
results
[
-
1
])
def
test_suite
():
def
test_suite
():
return
unittest
.
makeSuite
(
uploadTestCase
)
return
unittest
.
makeSuite
(
uploadTestCase
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment