Commit ed96b7bf authored by Benjamin Peterson's avatar Benjamin Peterson

merge from trunk

parent dd9e0fc1
......@@ -152,3 +152,26 @@ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR P
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License for 'pypy/module/unicodedata/'
======================================
The following files are from the website of The Unicode Consortium
at http://www.unicode.org/. For the terms of use of these files, see
http://www.unicode.org/terms_of_use.html
CompositionExclusions-3.2.0.txt
CompositionExclusions-4.1.0.txt
CompositionExclusions-5.0.0.txt
EastAsianWidth-3.2.0.txt
EastAsianWidth-4.1.0.txt
EastAsianWidth-5.0.0.txt
UnicodeData-3.2.0.txt
UnicodeData-4.1.0.txt
UnicodeData-5.0.0.txt
The following files are derived from files from the above website. The same
terms of use apply.
UnihanNumeric-3.2.0.txt
UnihanNumeric-4.1.0.txt
UnihanNumeric-5.0.0.txt
......@@ -21,7 +21,7 @@ def ssh_graph_server(sshargs):
remoteport = random.randrange(10000, 20000)
# ^^^ and just hope there is no conflict
args = ['ssh', '-C', '-R%d:127.0.0.1:%d' % (remoteport, localport)]
args = ['ssh', '-S', 'none', '-C', '-R%d:127.0.0.1:%d' % (remoteport, localport)]
args = args + sshargs + ['python -u -c "exec input()"']
print ' '.join(args[:-1])
p = subprocess.Popen(args, bufsize=0,
......
This directory contains all the include files needed to build cpython
extensions with PyPy. Note that these are just copies of the original headers
that are in pypy/module/cpyext/include: they are automatically copied from
there during translation.
Moreover, pypy_decl.h and pypy_macros.h are automatically generated, also
during translation.
......@@ -17,9 +17,9 @@ from distutils import log
def _easy_install_get_site_dirs():
# return a list of 'site' dirs for easy_install
from pkg_resources import normalize_path
from distutils.sysconfig import get_python_lib
sitedirs = filter(None,os.environ.get('PYTHONPATH','').split(os.pathsep))
pypylib = 'pypy%d.%d' % sys.pypy_version_info[:2]
sitedirs.append(os.path.join(sys.prefix, 'lib', pypylib, 'site-packages'))
sitedirs.append(get_python_lib(standard_lib=False))
sitedirs = map(normalize_path, sitedirs)
return sitedirs
......
......@@ -167,7 +167,7 @@ class build_ext (Command):
# for Release and Debug builds.
# also Python's library directory must be appended to library_dirs
if os.name == 'nt':
self.library_dirs.append(os.path.join(sys.prefix, 'pypy', '_interfaces'))
self.library_dirs.append(os.path.join(sys.prefix, 'include'))
if self.debug:
self.build_temp = os.path.join(self.build_temp, "Debug")
else:
......
......@@ -67,8 +67,8 @@ INSTALL_SCHEMES = {
'data' : '$base',
},
'pypy': {
'purelib': '$base/lib/pypy$pypy_version_short/site-packages',
'platlib': '$base/lib/pypy$pypy_version_short/site-packages',
'purelib': '$base/site-packages',
'platlib': '$base/site-packages',
'headers': '$base/include',
'scripts': '$base/bin',
'data' : '$base',
......
......@@ -13,12 +13,7 @@ python_build = False
def get_python_inc(plat_specific=0, prefix=None):
from os.path import join as j
cand = j(sys.pypy_prefix, 'include')
if os.path.exists(cand):
return cand
if plat_specific:
return j(sys.prefix, "pypy", "_interfaces")
return j(sys.prefix, 'pypy', 'module', 'cpyext', 'include')
return j(sys.prefix, 'include')
def get_python_version():
"""Return a string containing the major and minor Python version,
......@@ -47,8 +42,7 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
"calls to get_python_lib(standard_lib=1) cannot succeed")
if prefix is None:
prefix = PREFIX
pypylib = 'pypy%d.%d' % sys.pypy_version_info[:2]
return os.path.join(prefix, 'lib', pypylib, 'site-packages')
return os.path.join(prefix, 'site-packages')
_config_vars = None
......
......@@ -176,8 +176,8 @@ def addsitedir(sitedir, known_paths=None):
def addsitepackages(known_paths):
"""Add site-packages to sys.path, in a PyPy-specific way."""
if hasattr(sys, 'pypy_version_info'):
pypylib = 'pypy%d.%d' % sys.pypy_version_info[:2]
sitedir = os.path.join(sys.prefix, 'lib', pypylib, 'site-packages')
from distutils.sysconfig import get_python_lib
sitedir = get_python_lib(standard_lib=False)
if os.path.isdir(sitedir):
addsitedir(sitedir, known_paths)
return None
......
from __future__ import absolute_import
from .. import binascii
def test_uu():
assert binascii.b2a_uu('1234567') == "',3(S-#4V-P \n"
assert binascii.b2a_uu('123456789012345678901234567890123456789012345') == 'M,3(S-#4V-S@Y,#$R,S0U-C<X.3 Q,C,T-38W.#DP,3(S-#4V-S@Y,#$R,S0U\n'
try:
assert binascii.b2a_uu('1234567890123456789012345678901234567890123456')
except binascii.Error:
pass
else:
assert False, "Expected binascii.Error on oversize input."
assert binascii.b2a_uu('1234567') == "',3(S-#4V-P \n"
assert binascii.b2a_uu('123456789012345678901234567890123456789012345') == 'M,3(S-#4V-S@Y,#$R,S0U-C<X.3 Q,C,T-38W.#DP,3(S-#4V-S@Y,#$R,S0U\n'
def test_base64():
assert binascii.b2a_base64('xxxx') == 'eHh4eA==\n'
"""
Disabled for now. This should run at app-level, too.
"""
import pickle
class Picklable(object):
def __init__(self, a=555):
self.a = a
def __eq__(self, other):
return self.a == other.a
def __str__(self):
return '%s(%r)' % (self.__class__.__name__, self.a)
__repr__ = __str__
class PicklableSpecial2(Picklable):
def __reduce__(self):
return self.__class__, (self.a,)
class PicklableSpecial3(Picklable):
def __reduce__(self):
return self.__class__, (), self.a
def __setstate__(self, a):
self.a = a
class PicklableSpecial4(Picklable):
def __reduce_ex__(self, proto):
return self.__class__, (), self.a
def __setstate__(self, a):
self.a = a
def _pickle_some(x):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
s = pickle.dumps(x, proto)
y = pickle.loads(s)
assert x == y
_pickle_some(Picklable(5))
_pickle_some(PicklableSpecial2(66))
_pickle_some(PicklableSpecial3(7))
_pickle_some(PicklableSpecial4(17))
from __future__ import absolute_import
import py
from .. import binascii
# Create binary test data
data = "The quick brown fox jumps over the lazy dog.\r\n"
# Be slow so we don't depend on other modules
data += "".join(map(chr, xrange(256)))
data += "\r\nHello world.\n"
def test_exceptions():
# Check module exceptions
assert issubclass(binascii.Error, Exception)
assert issubclass(binascii.Incomplete, Exception)
def test_functions():
# Check presence of all functions
funcs = []
for suffix in "base64", "hqx", "uu", "hex":
prefixes = ["a2b_", "b2a_"]
if suffix == "hqx":
prefixes.extend(["crc_", "rlecode_", "rledecode_"])
for prefix in prefixes:
name = prefix + suffix
assert callable(getattr(binascii, name))
py.test.raises(TypeError, getattr(binascii, name))
for name in ("hexlify", "unhexlify"):
assert callable(getattr(binascii, name))
py.test.raises(TypeError, getattr(binascii, name))
def test_base64valid():
# Test base64 with valid data
MAX_BASE64 = 57
lines = []
for i in range(0, len(data), MAX_BASE64):
b = data[i:i+MAX_BASE64]
a = binascii.b2a_base64(b)
lines.append(a)
res = ""
for line in lines:
b = binascii.a2b_base64(line)
res = res + b
assert res == data
def test_base64invalid():
# Test base64 with random invalid characters sprinkled throughout
# (This requires a new version of binascii.)
MAX_BASE64 = 57
lines = []
for i in range(0, len(data), MAX_BASE64):
b = data[i:i+MAX_BASE64]
a = binascii.b2a_base64(b)
lines.append(a)
fillers = ""
valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/"
for i in xrange(256):
c = chr(i)
if c not in valid:
fillers += c
def addnoise(line):
noise = fillers
ratio = len(line) // len(noise)
res = ""
while line and noise:
if len(line) // len(noise) > ratio:
c, line = line[0], line[1:]
else:
c, noise = noise[0], noise[1:]
res += c
return res + noise + line
res = ""
for line in map(addnoise, lines):
b = binascii.a2b_base64(line)
res += b
assert res == data
# Test base64 with just invalid characters, which should return
# empty strings. TBD: shouldn't it raise an exception instead ?
assert binascii.a2b_base64(fillers) == ''
def test_uu():
MAX_UU = 45
lines = []
for i in range(0, len(data), MAX_UU):
b = data[i:i+MAX_UU]
a = binascii.b2a_uu(b)
lines.append(a)
res = ""
for line in lines:
b = binascii.a2b_uu(line)
res += b
assert res == data
assert binascii.a2b_uu("\x7f") == "\x00"*31
assert binascii.a2b_uu("\x80") == "\x00"*32
assert binascii.a2b_uu("\xff") == "\x00"*31
py.test.raises(binascii.Error, binascii.a2b_uu, "\xff\x00")
py.test.raises(binascii.Error, binascii.a2b_uu, "!!!!")
py.test.raises(binascii.Error, binascii.b2a_uu, 46*"!")
def test_crc32():
crc = binascii.crc32("Test the CRC-32 of")
crc = binascii.crc32(" this string.", crc)
assert crc == 1571220330
crc = binascii.crc32('frotz\n', 0)
assert crc == -372923920
py.test.raises(TypeError, binascii.crc32)
def test_hex():
# test hexlification
s = '{s\005\000\000\000worldi\002\000\000\000s\005\000\000\000helloi\001\000\000\0000'
t = binascii.b2a_hex(s)
u = binascii.a2b_hex(t)
assert s == u
py.test.raises(TypeError, binascii.a2b_hex, t[:-1])
py.test.raises(TypeError, binascii.a2b_hex, t[:-1] + 'q')
# Verify the treatment of Unicode strings
assert binascii.hexlify(unicode('a', 'ascii')) == '61'
def test_qp():
# A test for SF bug 534347 (segfaults without the proper fix)
try:
binascii.a2b_qp("", **{1:1})
except TypeError:
pass
else:
fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError")
assert binascii.a2b_qp("= ") == "= "
assert binascii.a2b_qp("==") == "="
assert binascii.a2b_qp("=AX") == "=AX"
py.test.raises(TypeError, binascii.b2a_qp, foo="bar")
assert binascii.a2b_qp("=00\r\n=00") == "\x00\r\n\x00"
assert binascii.b2a_qp("\xff\r\n\xff\n\xff") == "=FF\r\n=FF\r\n=FF"
target = "0"*75+"=\r\n=FF\r\n=FF\r\n=FF"
assert binascii.b2a_qp("0"*75+"\xff\r\n\xff\r\n\xff") == target
def test_empty_string():
# A test for SF bug #1022953. Make sure SystemError is not raised.
for n in ['b2a_qp', 'a2b_hex', 'b2a_base64', 'a2b_uu', 'a2b_qp',
'b2a_hex', 'unhexlify', 'hexlify', 'crc32', 'b2a_hqx',
'a2b_hqx', 'a2b_base64', 'rlecode_hqx', 'b2a_uu',
'rledecode_hqx']:
f = getattr(binascii, n)
f('')
binascii.crc_hqx('', 0)
def test_qp_bug_case():
assert binascii.b2a_qp('y'*77, False, False) == 'y'*75 + '=\nyy'
assert binascii.b2a_qp(' '*77, False, False) == ' '*75 + '=\n =20'
assert binascii.b2a_qp('y'*76, False, False) == 'y'*76
assert binascii.b2a_qp(' '*76, False, False) == ' '*75 + '=\n=20'
def test_wrong_padding():
s = 'CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ'
py.test.raises(binascii.Error, binascii.a2b_base64, s)
def test_crap_after_padding():
s = 'xxx=axxxx'
assert binascii.a2b_base64(s) == '\xc7\x1c'
def test_wrong_args():
# this should grow as a way longer list
py.test.raises(TypeError, binascii.a2b_base64, 42)
from __future__ import absolute_import
from .. import collections
import py
def test_deque_remove_empty():
d = collections.deque([])
py.test.raises(ValueError, d.remove, 1)
def test_deque_remove_mutating():
class MutatingCmp(object):
def __eq__(self, other):
d.clear()
return True
d = collections.deque([MutatingCmp()])
py.test.raises(IndexError, d.remove, 1)
class SubclassWithKwargs(collections.deque):
def __init__(self, newarg=1):
collections.deque.__init__(self)
def test_subclass_with_kwargs():
# SF bug #1486663 -- this used to erroneously raise a TypeError
SubclassWithKwargs(newarg=1)
from __future__ import absolute_import
from py.test import skip, raises
try:
from ..stackless import coroutine
except ImportError, e:
skip('cannot import stackless: %s' % (e,))
class Test_Coroutine:
def test_is_zombie(self):
co = coroutine()
def f():
print 'in coro'
assert not co.is_zombie
co.bind(f)
assert not co.is_zombie
co.switch()
assert not co.is_zombie
def test_is_zombie_del_without_frame(self):
try:
import _stackless # are we on pypy with a stackless build?
except ImportError:
skip("only works on pypy-c-stackless")
import gc
res = []
class MyCoroutine(coroutine):
def __del__(self):
res.append(self.is_zombie)
def f():
print 'in coro'
co = MyCoroutine()
co.bind(f)
co.switch()
del co
for i in range(10):
gc.collect()
if res:
break
co = coroutine()
co.bind(f)
co.switch()
assert res[0], "is_zombie was False in __del__"
def test_is_zombie_del_with_frame(self):
try:
import _stackless # are we on pypy with a stackless build?
except ImportError:
skip("only works on pypy-c-stackless")
import gc
res = []
class MyCoroutine(coroutine):
def __del__(self):
res.append(self.is_zombie)
main = coroutine.getcurrent()
def f():
print 'in coro'
main.switch()
co = MyCoroutine()
co.bind(f)
co.switch()
del co
for i in range(10):
gc.collect()
if res:
break
co = coroutine()
co.bind(f)
co.switch()
assert res[0], "is_zombie was False in __del__"
def test_raise_propagate(self):
co = coroutine()
def f():
return 1/0
co.bind(f)
try:
co.switch()
except ZeroDivisionError:
pass
else:
raise AssertionError("exception not propagated")
def test_strange_test(self):
def f():
return 42
def create():
b = coroutine()
b.bind(f)
b.switch()
return b
a = coroutine()
a.bind(create)
b = a.switch()
def nothing():
pass
a.bind(nothing)
def kill():
a.kill()
b.bind(kill)
b.switch()
def test_kill(self):
co = coroutine()
def f():
pass
assert not co.is_alive
co.bind(f)
assert co.is_alive
co.kill()
assert not co.is_alive
def test_catch_coroutineexit(self):
coroutineexit = []
co_a = coroutine()
co_test = coroutine.getcurrent()
def a():
try:
co_test.switch()
except CoroutineExit:
coroutineexit.append(True)
raise
co_a.bind(a)
co_a.switch()
assert co_a.is_alive
co_a.kill()
assert coroutineexit == [True]
assert not co_a.is_alive
def test_throw(self):
exceptions = []
co = coroutine()
def f(main):
try:
main.switch()
except RuntimeError:
exceptions.append(True)
co.bind(f, coroutine.getcurrent())
co.switch()
co.throw(RuntimeError)
assert exceptions == [True]
def test_propagation(self):
exceptions = []
co = coroutine()
co2 = coroutine()
def f(main):
main.switch()
co.bind(f, coroutine.getcurrent())
co.switch()
try:
co.throw(RuntimeError)
except RuntimeError:
exceptions.append(1)
def f2():
raise RuntimeError
co2.bind(f2)
try:
co2.switch()
except RuntimeError:
exceptions.append(2)
assert exceptions == [1,2]
def test_bogus_bind(self):
co = coroutine()
def f():
pass
co.bind(f)
raises(ValueError, co.bind, f)
def test_simple_task(self):
maintask = coroutine.getcurrent()
def f():pass
co = coroutine()
co.bind(f)
co.switch()
assert not co.is_alive
assert maintask is coroutine.getcurrent()
def test_backto_main(self):
maintask = coroutine.getcurrent()
def f(task):
task.switch()
co = coroutine()
co.bind(f,maintask)
co.switch()
def test_wrapped_main(self):
class mwrap(object):
def __init__(self, coro):
self._coro = coro
def __getattr__(self, attr):
return getattr(self._coro, attr)
maintask = mwrap(coroutine.getcurrent())
def f(task):
task.switch()
co = coroutine()
co.bind(f,maintask)
co.switch()
from __future__ import absolute_import
import py
from ctypes import *
try:
from ctypes_support import standard_c_lib, get_errno, set_errno
except ImportError: # on top of cpython
from ..ctypes_support import standard_c_lib, get_errno, set_errno
def test_stdlib_and_errno():
py.test.skip("this is expected on top of pypy, we need to fix ctypes in a way that is now in 2.6 in order to make this reliable")
write = standard_c_lib.write
write.argtypes = [c_int, c_char_p, c_size_t]
write.restype = c_size_t
# clear errno first
set_errno(0)
assert get_errno() == 0
write(-345, "abc", 3)
assert get_errno() != 0
set_errno(0)
assert get_errno() == 0
from __future__ import absolute_import
from .. import datetime
def test_repr():
print datetime
expected = "datetime.datetime(1, 2, 3, 0, 0)"
assert repr(datetime.datetime(1,2,3)) == expected
def test_strptime():
import time
string = '2004-12-01 13:02:47'
format = '%Y-%m-%d %H:%M:%S'
expected = datetime.datetime(*(time.strptime(string, format)[0:6]))
got = datetime.datetime.strptime(string, format)
assert expected == got
from __future__ import absolute_import
import py
from pypy.tool.udir import udir
try:
from .. import dbm
except ImportError, e:
py.test.skip(e)
def test_get():
path = str(udir.join('test_dbm_extra.test_get'))
d = dbm.open(path, 'c')
x = d.get("42")
assert x is None
d.close()