To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 819bd6eb authored by mattip's avatar mattip
Browse files

merge default into branch

parents c6b8f4c4 f2e31b8f
Metadata-Version: 1.0
Name: greenlet
Version: 0.4.0
Version: 0.4.5
Summary: Lightweight in-process concurrent programming
Home-page: https://github.com/python-greenlet/greenlet
Author: Ralf Schmitt (for CPython), PyPy team
......
import sys
import _continuation
__version__ = "0.4.0"
__version__ = "0.4.5"
# ____________________________________________________________
# Exceptions
......
......@@ -75,22 +75,32 @@ def _array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False):
if order != 'C': # or order != 'F':
raise oefmt(space.w_ValueError, "Unknown order: %s", order)
# arrays with correct dtype
if isinstance(w_object, W_NDimArray) and \
(space.is_none(w_dtype) or w_object.get_dtype() is dtype):
if copy and (subok or type(w_object) is W_NDimArray):
return w_object.descr_copy(space, w_order)
elif not copy and (subok or type(w_object) is W_NDimArray):
return w_object
if isinstance(w_object, W_NDimArray) and copy and not subok:
# TODO do the loop.assign without copying elems_w
shape = w_object.get_shape()
_elems_w = w_object.reshape(space, space.wrap(-1))
elems_w = [None] * w_object.get_size()
for i in range(len(elems_w)):
elems_w[i] = _elems_w.descr_getitem(space, space.wrap(i))
if space.is_none(w_dtype):
if isinstance(w_object, W_NDimArray):
if (dtype is None or w_object.get_dtype() is dtype):
if copy and (subok or type(w_object) is W_NDimArray):
return w_object.descr_copy(space, w_order)
elif not copy and (subok or type(w_object) is W_NDimArray):
return w_object
# we have a ndarray, but need to copy or change dtype or create W_NDimArray
if dtype is None:
dtype = w_object.get_dtype()
if dtype != w_object.get_dtype():
# silently reject the copy value
copy = True
if copy:
shape = w_object.get_shape()
_elems_w = w_object.reshape(space, space.wrap(-1))
elems_w = [None] * w_object.get_size()
for i in range(len(elems_w)):
elems_w[i] = _elems_w.descr_getitem(space, space.wrap(i))
elif subok:
raise oefmt(space.w_NotImplementedError,
"array(...copy=False, subok=True) not implemented yet")
else:
sz = support.product(w_object.get_shape()) * dtype.elsize
return W_NDimArray.from_shape_and_storage(space,
w_object.get_shape(),w_object.implementation.storage,
dtype, storage_bytes=sz, w_base=w_object)
else:
# not an array
shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype)
......
......@@ -268,7 +268,7 @@ class AppTestSupport(BaseNumpyAppTest):
c = array(a, float)
assert c.dtype is dtype(float)
def test__getitem_modifies_shape(self):
def test_array_of_subtype(self):
import numpy as N
# numpy's matrix class caused an infinite loop
class matrix(N.ndarray):
......@@ -309,8 +309,14 @@ class AppTestSupport(BaseNumpyAppTest):
a = matrix([[1., 2.], [3., 4.]])
b = N.array([a])
assert (b == a).all()
b = N.array(a)
assert len(b.shape) == 2
assert (b == a).all()
b = N.array(a, copy=False)
assert len(b.shape) == 2
assert (b == a).all()
def test_setstate_no_version(self):
# Some subclasses of ndarray, like MaskedArray, do not use
......
......@@ -220,6 +220,9 @@ class AppTestUfuncs(BaseNumpyAppTest):
af = arange(10, dtype=float)
af2 = ufunc(af)
assert all(af2 == af * 2)
ac = arange(10, dtype=complex)
skip('casting not implemented yet')
ac1 = ufunc(ac)
def test_frompyfunc_2d_sig(self):
def times_2(in_array, out_array):
......
......@@ -774,8 +774,13 @@ class W_UfuncGeneric(W_Ufunc):
break
else:
if len(self.funcs) > 1:
dtypesstr = ','.join(['%s%s%s' % (d.byteorder, d.kind, d.elsize) \
for d in dtypes])
dtypesstr = ''
for d in dtypes:
if d is None:
dtypesstr += 'None,'
else:
dtypesstr += '%s%s%s,' % (d.byteorder, d.kind, d.elsize)
_dtypesstr = ','.join(['%s%s%s' % (d.byteorder, d.kind, d.elsize) \
for d in _dtypes])
raise oefmt(space.w_TypeError,
......
......@@ -535,3 +535,9 @@ class RFile(object):
def isatty(self):
self._check_closed()
return os.isatty(c_fileno(self._ll_file))
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
......@@ -26,6 +26,7 @@ class TestFile(BaseRtypingTest):
f()
assert open(fname, "r").read() == "dupa"
os.unlink(fname)
self.interpret(f, [])
assert open(fname, "r").read() == "dupa"
......@@ -102,6 +103,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
os.unlink(fname)
self.interpret(f, [])
@py.test.mark.skipif("sys.platform == 'win32'")
......@@ -121,6 +123,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_open_buffering_full(self):
......@@ -138,6 +141,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_fdopen_buffering_full(self):
......@@ -157,6 +161,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_read_write(self):
......@@ -203,6 +208,7 @@ class TestFile(BaseRtypingTest):
f2.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_read_sequentially(self):
......@@ -277,6 +283,7 @@ class TestFile(BaseRtypingTest):
f.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_tempfile(self):
......@@ -309,6 +316,7 @@ class TestFile(BaseRtypingTest):
f()
assert open(fname).read() == "xxx"
os.unlink(fname)
self.interpret(f, [])
assert open(fname).read() == "xxx"
......@@ -325,6 +333,7 @@ class TestFile(BaseRtypingTest):
res = f()
assert res > 2
os.unlink(fname)
res = self.interpret(f, [])
assert res > 2
......@@ -341,6 +350,7 @@ class TestFile(BaseRtypingTest):
res = f()
assert res == 3
os.unlink(fname)
res = self.interpret(f, [])
assert res == 3
......@@ -357,6 +367,7 @@ class TestFile(BaseRtypingTest):
f.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_truncate(self):
......@@ -381,8 +392,28 @@ class TestFile(BaseRtypingTest):
f.close()
f()
os.unlink(fname)
self.interpret(f, [])
def test_with_statement(self):
fname = str(self.tmpdir.join('file_6'))
def f():
with open(fname, "w") as f:
f.write("dupa")
try:
f.write("dupb")
except ValueError:
pass
else:
assert False
f()
assert open(fname, "r").read() == "dupa"
os.unlink(fname)
self.interpret(f, [])
assert open(fname, "r").read() == "dupa"
class TestDirect:
def setup_class(cls):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment