summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorphillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771>2013-05-15 21:59:07 +0000
committerphillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771>2013-05-15 21:59:07 +0000
commit3fcd24b6bec780a56664ea5bb74a4e8eaadf3014 (patch)
treea28aadfd78dd33a2bbba5e19d9ad07745b4867e1 /setuptools
parentc06e88c3e042b0747d8626bc86db8919f94d7bfd (diff)
downloadpython-setuptools-3fcd24b6bec780a56664ea5bb74a4e8eaadf3014.tar.gz
Snapshot pre-merger changes, mostly SSL support and a few bugfixes
git-svn-id: http://svn.python.org/projects/sandbox/trunk/setuptools@88994 6015fed2-1504-0410-9fe1-9d1591cc4771
Diffstat (limited to 'setuptools')
-rwxr-xr-xsetuptools/command/easy_install.py2
-rw-r--r--setuptools/dist.py8
-rwxr-xr-xsetuptools/package_index.py30
-rwxr-xr-xsetuptools/sandbox.py2
-rwxr-xr-xsetuptools/tests/api_tests.txt91
-rw-r--r--setuptools/tests/test_resources.py8
6 files changed, 116 insertions, 25 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index b5db0e8..920af02 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -156,7 +156,7 @@ class easy_install(Command):
else:
self.all_site_dirs.append(normalize_path(d))
if not self.editable: self.check_site_dir()
- self.index_url = self.index_url or "http://pypi.python.org/simple"
+ self.index_url = self.index_url or "https://pypi.python.org/simple"
self.shadow_path = self.all_site_dirs[:]
for path_item in self.install_dir, normalize_path(self.script_dir):
if path_item not in self.shadow_path:
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 482c6bf..e7f5454 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -47,7 +47,6 @@ def assert_string_list(dist, attr, value):
raise DistutilsSetupError(
"%r must be a list of strings (got %r)" % (attr,value)
)
-
def check_nsp(dist, attr, value):
"""Verify that namespace packages are valid"""
assert_string_list(dist,attr,value)
@@ -69,6 +68,10 @@ def check_extras(dist, attr, value):
"""Verify that extras_require mapping is valid"""
try:
for k,v in value.items():
+ if ':' in k:
+ k,m = k.split(':',1)
+ if pkg_resources.invalid_marker(m):
+ raise DistutilsSetupError("Invalid environment marker: "+m)
list(pkg_resources.parse_requirements(v))
except (TypeError,ValueError,AttributeError):
raise DistutilsSetupError(
@@ -77,9 +80,6 @@ def check_extras(dist, attr, value):
"requirement specifiers."
)
-
-
-
def assert_bool(dist, attr, value):
"""Verify that value is True, False, 0, or 1"""
if bool(value) != value:
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 9a9c5d6..aab2bb2 100755
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -1,6 +1,6 @@
"""PyPI and direct package downloading"""
import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO
-import httplib, urllib
+import httplib, urllib; from setuptools import ssl_support
from pkg_resources import *
from distutils import log
from distutils.errors import DistutilsError
@@ -145,12 +145,11 @@ user_agent = "Python-urllib/%s setuptools/%s" % (
urllib2.__version__, require('setuptools')[0].version
)
-
class PackageIndex(Environment):
"""A distribution index that scans web pages for download URLs"""
- def __init__(self, index_url="http://pypi.python.org/simple", hosts=('*',),
- *args, **kw
+ def __init__(self, index_url="https://pypi.python.org/simple", hosts=('*',),
+ ca_bundle=None, verify_ssl=True, *args, **kw
):
Environment.__init__(self,*args,**kw)
self.index_url = index_url + "/"[:not index_url.endswith('/')]
@@ -159,8 +158,9 @@ class PackageIndex(Environment):
self.package_pages = {}
self.allows = re.compile('|'.join(map(translate,hosts))).match
self.to_scan = []
-
-
+ if verify_ssl and ssl_support.is_available and (ca_bundle or ssl_support.find_ca_bundle()):
+ self.opener = ssl_support.opener_for(ca_bundle)
+ else: self.opener = urllib2.urlopen
def process_url(self, url, retrieve=False):
"""Evaluate a URL as a possible download, and maybe retrieve it"""
@@ -575,12 +575,13 @@ class PackageIndex(Environment):
def open_url(self, url, warning=None):
if url.startswith('file:'): return local_open(url)
try:
- return open_with_auth(url)
- except urllib2.HTTPError, v:
- return v
- except urllib2.URLError, v:
- reason = v.reason
- except httplib.HTTPException, v:
+ return open_with_auth(url, self.opener)
+ except urllib2.HTTPError:
+ return sys.exc_info()[1]
+ except urllib2.URLError:
+ reason = sys.exc_info()[1].reason
+ except httplib.HTTPException:
+ v = sys.exc_info()[1]
reason = "%s: %s" % (v.__doc__ or v.__class__.__name__, v)
if warning:
self.warn(warning, reason)
@@ -612,7 +613,6 @@ class PackageIndex(Environment):
self.url_ok(url, True) # raises error if not allowed
return self._attempt_download(url, filename)
-
def scan_url(self, url):
self.process_url(url, True)
@@ -736,7 +736,7 @@ def htmldecode(text):
-def open_with_auth(url):
+def open_with_auth(url, opener=urllib2.urlopen):
"""Open a urllib2 request, handling HTTP authentication"""
scheme, netloc, path, params, query, frag = urlparse.urlparse(url)
@@ -755,7 +755,7 @@ def open_with_auth(url):
request = urllib2.Request(url)
request.add_header('User-Agent', user_agent)
- fp = urllib2.urlopen(request)
+ fp = opener(request)
if auth:
# Put authentication info back into request URL if same host,
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py
index 4c5e712..8b889a7 100755
--- a/setuptools/sandbox.py
+++ b/setuptools/sandbox.py
@@ -206,7 +206,7 @@ class DirectorySandbox(AbstractSandbox):
def tmpnam(self): self._violation("tmpnam")
def _ok(self,path):
- if hasattr(_os,'devnull') and path==_os.devnull: return True
+ if hasattr(os,'devnull') and path==os.devnull: return True
active = self._active
try:
self._active = False
diff --git a/setuptools/tests/api_tests.txt b/setuptools/tests/api_tests.txt
index 823d815..e35dad1 100755
--- a/setuptools/tests/api_tests.txt
+++ b/setuptools/tests/api_tests.txt
@@ -328,3 +328,94 @@ setuptools is provided as well::
>>> cp("darwin-8.2.0-Power_Macintosh", "macosx-10.3-ppc")
False
+
+Environment Markers
+-------------------
+
+ >>> from pkg_resources import invalid_marker as im, evaluate_marker as em
+ >>> import os
+
+ >>> print(im("sys_platform"))
+ Comparison or logical expression expected
+
+ >>> print(im("sys_platform=="))
+ unexpected EOF while parsing (line 1)
+
+ >>> print(im("sys_platform=='win32'"))
+ False
+
+ >>> print(im("sys=='x'"))
+ Unknown name 'sys'
+
+ >>> print(im("(extra)"))
+ Comparison or logical expression expected
+
+ >>> print(im("(extra"))
+ unexpected EOF while parsing (line 1)
+
+ >>> print(im("os.open('foo')=='y'"))
+ Language feature not supported in environment markers
+
+ >>> print(im("'x'=='y' and os.open('foo')=='y'")) # no short-circuit!
+ Language feature not supported in environment markers
+
+ >>> print(im("'x'=='x' or os.open('foo')=='y'")) # no short-circuit!
+ Language feature not supported in environment markers
+
+ >>> print(im("'x' < 'y'"))
+ '<' operator not allowed in environment markers
+
+ >>> print(im("'x' < 'y' < 'z'"))
+ Chained comparison not allowed in environment markers
+
+ >>> print(im("r'x'=='x'"))
+ Only plain strings allowed in environment markers
+
+ >>> print(im("'''x'''=='x'"))
+ Only plain strings allowed in environment markers
+
+ >>> print(im('"""x"""=="x"'))
+ Only plain strings allowed in environment markers
+
+ >>> print(im(r"'x\n'=='x'"))
+ Only plain strings allowed in environment markers
+
+ >>> print(im("os.open=='y'"))
+ Language feature not supported in environment markers
+
+ >>> em('"x"=="x"')
+ True
+
+ >>> em('"x"=="y"')
+ False
+
+ >>> em('"x"=="y" and "x"=="x"')
+ False
+
+ >>> em('"x"=="y" or "x"=="x"')
+ True
+
+ >>> em('"x"=="y" and "x"=="q" or "z"=="z"')
+ True
+
+ >>> em('"x"=="y" and ("x"=="q" or "z"=="z")')
+ False
+
+ >>> em('"x"=="y" and "z"=="z" or "x"=="q"')
+ False
+
+ >>> em('"x"=="x" and "z"=="z" or "x"=="q"')
+ True
+
+ >>> em("sys_platform=='win32'") == (sys.platform=='win32')
+ True
+
+ >>> em("'x' in 'yx'")
+ True
+
+ >>> em("'yx' in 'x'")
+ False
+
+
+
+
diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py
index 1c010e7..ad2d02f 100644
--- a/setuptools/tests/test_resources.py
+++ b/setuptools/tests/test_resources.py
@@ -507,7 +507,7 @@ class ScriptHeaderTests(TestCase):
def test_get_script_header_jython_workaround(self):
platform = sys.platform
sys.platform = 'java1.5.0_13'
- stdout = sys.stdout
+ stdout, stderr = sys.stdout, sys.stderr
try:
# A mock sys.executable that uses a shebang line (this file)
exe = os.path.normpath(os.path.splitext(__file__)[0] + '.py')
@@ -517,17 +517,17 @@ class ScriptHeaderTests(TestCase):
# Ensure we generate what is basically a broken shebang line
# when there's options, with a warning emitted
- sys.stdout = StringIO.StringIO()
+ sys.stdout = sys.stderr = StringIO.StringIO()
self.assertEqual(get_script_header('#!/usr/bin/python -x',
executable=exe),
'#!%s -x\n' % exe)
self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
- sys.stdout = StringIO.StringIO()
+ sys.stdout = sys.stderr = StringIO.StringIO()
self.assertEqual(get_script_header('#!/usr/bin/python',
executable=self.non_ascii_exe),
'#!%s -x\n' % self.non_ascii_exe)
self.assert_('Unable to adapt shebang line' in sys.stdout.getvalue())
finally:
sys.platform = platform
- sys.stdout = stdout
+ sys.stdout, sys.stderr = stdout, stderr