[pypy-commit] pypy stdlib-2.7.8: sys.exit() should produce a SystemExit with code is None

2014-08-22 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: stdlib-2.7.8
Changeset: r72963:8ab4bb347653
Date: 2014-08-12 21:34 +0200
http://bitbucket.org/pypy/pypy/changeset/8ab4bb347653/

Log:sys.exit() should produce a SystemExit with code is None (grafted
from 4558aef78acc9cca815eb6309c90adecdafc793f)

diff --git a/pypy/module/exceptions/test/test_exc.py 
b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -147,6 +147,28 @@
 assert SystemExit(x).code == x
 assert SystemExit(1, 2).code == (1, 2)
 
+def test_sys_exit(self):
+import sys
+
+exc = raises(SystemExit, sys.exit)
+assert exc.value.code is None
+
+exc = raises(SystemExit, sys.exit, 0)
+assert exc.value.code == 0
+
+exc = raises(SystemExit, sys.exit, 1)
+assert exc.value.code == 1
+
+exc = raises(SystemExit, sys.exit, 2)
+assert exc.value.code == 2
+
+exc = raises(SystemExit, sys.exit, (1, 2, 3))
+assert exc.value.code == (1, 2, 3)
+
+def test_str_unicode(self):
+e = ValueError('#224;#232;#236;')
+assert str(e) == '#224;#232;#236;'
+
 def test_unicode_decode_error(self):
 from exceptions import UnicodeDecodeError
 ud = UnicodeDecodeError(x, y, 1, 5, bah)
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -49,7 +49,7 @@
 except:
 return False# got an exception again... ignore, report the original
 
-def exit(exitcode=0):
+def exit(exitcode=None):
 Exit the interpreter by raising SystemExit(exitcode).
 If the exitcode is omitted or None, it defaults to zero (i.e., success).
 If the exitcode is numeric, it will be used as the system exit status.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.8: add custom __repr__ to Cell

2014-08-22 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: stdlib-2.7.8
Changeset: r72981:43b8e678a5e5
Date: 2014-07-27 11:45 +0200
http://bitbucket.org/pypy/pypy/changeset/43b8e678a5e5/

Log:add custom __repr__ to Cell (grafted from
c799b96b7ec531b447afdfeeaf574146af1eb3d3)

diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py
--- a/pypy/interpreter/nestedscope.py
+++ b/pypy/interpreter/nestedscope.py
@@ -65,6 +65,14 @@
 return %s(%s) at 0x%x % (self.__class__.__name__,
  content, uid(self))
 
+def descr__repr__(self, space):
+if self.w_value is None:
+content = empty
+else:
+content = %s object at 0x%x % (space.type(self.w_value).name, 
uid(self.w_value))
+s = cell at 0x%x: %s % (uid(self), content)
+return space.wrap(s.decode('utf-8'))
+
 def descr__cell_contents(self, space):
 try:
 return self.get()
diff --git a/pypy/interpreter/test/test_nestedscope.py 
b/pypy/interpreter/test/test_nestedscope.py
--- a/pypy/interpreter/test/test_nestedscope.py
+++ b/pypy/interpreter/test/test_nestedscope.py
@@ -60,6 +60,28 @@
 def test_lambda_in_genexpr(self):
 assert eval('map(apply, (lambda: t for t in range(10)))') == range(10)
 
+def test_cell_repr(self):
+import re
+from reprlib import repr as r # Don't shadow builtin repr
+
+def get_cell():
+x = 42
+def inner():
+return x
+return inner
+x = get_cell().__closure__[0]
+assert re.match(r'cell at 0x[0-9A-Fa-f]+: int object at 
0x[0-9A-Fa-f]+', repr(x))
+assert re.match(r'cell at 0x.*\.\.\..*', r(x))
+
+def get_cell():
+if False:
+x = 42
+def inner():
+return x
+return inner
+x = get_cell().__closure__[0]
+assert re.match(r'cell at 0x[0-9A-Fa-f]+: empty', repr(x))
+
 def test_cell_contents(self):
 def f(x):
 def f(y):
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -926,6 +926,7 @@
 __cmp__  = interp2app(Cell.descr__cmp__),
 __hash__ = None,
 __reduce__   = interp2app(Cell.descr__reduce__),
+__repr__ = interp2app(Cell.descr__repr__),
 __setstate__ = interp2app(Cell.descr__setstate__),
 cell_contents= GetSetProperty(Cell.descr__cell_contents, cls=Cell),
 )
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix typo

2014-08-21 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: 
Changeset: r72952:54408dd5e0f8
Date: 2014-08-21 22:00 +0200
http://bitbucket.org/pypy/pypy/changeset/54408dd5e0f8/

Log:fix typo

diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -354,6 +354,6 @@
 See the License for the specific language governing permissions and
 limitations under the License.
 
-Detailled license information is contained in the NOTICE file in the
+Detailed license information is contained in the NOTICE file in the
 directory.
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: implement os.truncate

2014-08-20 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72937:1a0bf771caeb
Date: 2014-08-20 18:44 +0200
http://bitbucket.org/pypy/pypy/changeset/1a0bf771caeb/

Log:implement os.truncate

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -86,6 +86,7 @@
 interpleveldefs['fchmod'] = 'interp_posix.fchmod'
 if hasattr(os, 'ftruncate'):
 interpleveldefs['ftruncate'] = 'interp_posix.ftruncate'
+interpleveldefs['truncate'] = 'interp_posix.truncate'
 if hasattr(os, 'fsync'):
 interpleveldefs['fsync'] = 'interp_posix.fsync'
 if hasattr(os, 'fdatasync'):
diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -159,7 +159,7 @@
 
 @unwrap_spec(fd=c_int, length=r_longlong)
 def ftruncate(space, fd, length):
-Truncate a file to a specified length.
+Truncate a file (by file descriptor) to a specified length.
 try:
 os.ftruncate(fd, length)
 except IOError, e:
@@ -173,6 +173,25 @@
 except OSError, e:
 raise wrap_oserror(space, e)
 
+def truncate(space, w_path, w_length):
+Truncate a file to a specified length.
+allocated_fd = False
+fd = -1
+try:
+if space.isinstance_w(w_path, space.w_int):
+w_fd = w_path
+else:
+w_fd = open(space, w_path, os.O_RDWR | os.O_CREAT)
+allocated_fd = True
+
+fd = space.c_filedescriptor_w(w_fd)
+length = space.int_w(w_length)
+return ftruncate(space, fd, length)
+
+finally:
+if allocated_fd and fd != -1:
+close(space, fd)
+
 def fsync(space, w_fd):
 Force write of file with filedescriptor to disk.
 fd = space.c_filedescriptor_w(w_fd)
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -976,6 +976,33 @@
 data = f.read()
 assert data == who cares?
 
+if hasattr(os, 'ftruncate'):
+def test_truncate(self):
+posix = self.posix
+dest = self.path
+
+def mkfile(dest, size=4):
+with open(dest, 'wb') as f:
+f.write(b'd' * size)
+
+# Check invalid inputs
+mkfile(dest)
+raises(OSError, posix.truncate, dest, -1)
+raises(OSError, posix.truncate, 1, 1)
+raises(TypeError, posix.truncate, dest, None)
+raises(TypeError, posix.truncate, None, None)
+
+# Truncate via file descriptor
+mkfile(dest)
+with open(dest, 'wb') as f:
+posix.truncate(f.fileno(), 1)
+assert 1 == posix.stat(dest).st_size
+
+# Truncate via filename
+mkfile(dest)
+posix.truncate(dest, 1)
+assert 1 == posix.stat(dest).st_size
+
 try:
 os.getlogin()
 except (AttributeError, OSError):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: add missing lzma.LZMAError

2014-08-20 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72938:5f4688671d8e
Date: 2014-08-20 22:08 +0200
http://bitbucket.org/pypy/pypy/changeset/5f4688671d8e/

Log:add missing lzma.LZMAError

diff --git a/pypy/module/_lzma/__init__.py b/pypy/module/_lzma/__init__.py
--- a/pypy/module/_lzma/__init__.py
+++ b/pypy/module/_lzma/__init__.py
@@ -8,6 +8,7 @@
 interpleveldefs = {
 'LZMACompressor': 'interp_lzma.W_LZMACompressor',
 'LZMADecompressor': 'interp_lzma.W_LZMADecompressor',
+'LZMAError': 'interp_lzma.W_LZMAError',
 '_encode_filter_properties': 'interp_lzma.encode_filter_properties',
 '_decode_filter_properties': 'interp_lzma.decode_filter_properties',
 'FORMAT_AUTO': 'space.wrap(interp_lzma.FORMAT_AUTO)',
diff --git a/pypy/module/_lzma/interp_lzma.py b/pypy/module/_lzma/interp_lzma.py
--- a/pypy/module/_lzma/interp_lzma.py
+++ b/pypy/module/_lzma/interp_lzma.py
@@ -3,6 +3,7 @@
 TypeDef, interp_attrproperty_bytes, interp_attrproperty)
 from pypy.interpreter.error import oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
+from pypy.module.exceptions.interp_exceptions import _new_exception, 
W_Exception
 from pypy.module.thread.os_lock import Lock
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import LONGLONG_MASK, r_ulonglong
@@ -346,6 +347,9 @@
 )
 
 
+W_LZMAError = _new_exception('LZMAError', W_Exception, 'Call to liblzma 
failed.')
+
+
 def encode_filter_properties(space, w_filter):
 Return a bytes object encoding the options (properties) of the filter
specified by *filter* (a dict).
diff --git a/pypy/module/_lzma/test/test_lzma.py 
b/pypy/module/_lzma/test/test_lzma.py
--- a/pypy/module/_lzma/test/test_lzma.py
+++ b/pypy/module/_lzma/test/test_lzma.py
@@ -15,3 +15,16 @@
   b't\x9e\xdfI]\xff\xf4\x9d\x80\x00')
 decompressed = lzma.decompress(compressed)
 assert decompressed == b'Insert Data Here'
+
+def test_exceptions(self):
+import _lzma
+import lzma
+
+assert hasattr(_lzma, 'LZMAError')
+assert hasattr(lzma, 'LZMAError')
+
+assert _lzma.LZMAError is lzma.LZMAError
+assert _lzma.LZMAError.__doc__ == 'Call to liblzma failed.'
+
+exc = raises(_lzma.LZMAError, 'raise _lzma.LZMAError')
+exc = raises(_lzma.LZMAError, 'raise _lzma.LZMAError(bad thing)')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Merged in numerodix/pypy/py3.3-fixes2 (pull request #271)

2014-08-19 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72917:6fcd3a9ba6e2
Date: 2014-08-19 22:13 +0200
http://bitbucket.org/pypy/pypy/changeset/6fcd3a9ba6e2/

Log:Merged in numerodix/pypy/py3.3-fixes2 (pull request #271)

remove time.accept2dyear (removed in python 3.3)

diff --git a/pypy/module/rctime/__init__.py b/pypy/module/rctime/__init__.py
--- a/pypy/module/rctime/__init__.py
+++ b/pypy/module/rctime/__init__.py
@@ -39,5 +39,3 @@
 from pypy.module.rctime import interp_time
 
 interp_time._init_timezone(space)
-interp_time._init_accept2dyear(space)
-
diff --git a/pypy/module/rctime/interp_time.py 
b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -198,13 +198,6 @@
 c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, 
TM_P],
   rffi.SIZE_T)
 
-def _init_accept2dyear(space):
-if os.environ.get(PYTHONY2K):
-accept2dyear = 0
-else:
-accept2dyear = 1
-_set_module_object(space, accept2dyear, space.wrap(accept2dyear))
-
 def _init_timezone(space):
 timezone = daylight = altzone = 0
 tzname = [, ]
@@ -435,21 +428,6 @@
 glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
 rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
 
-if y  1000:
-w_accept2dyear = _get_module_object(space, accept2dyear)
-accept2dyear = space.is_true(w_accept2dyear)
-
-if accept2dyear:
-if 69 = y = 99:
-y += 1900
-elif 0 = y = 68:
-y += 2000
-else:
-raise OperationError(space.w_ValueError,
- space.wrap(year out of range))
-space.warn(space.wrap(Century info guessed for a 2-digit year.),
-   space.w_DeprecationWarning)
-
 # tm_wday does not need checking of its upper-bound since taking %
 #  7 in _gettmarg() automatically restricts the range.
 if rffi.getintfield(glob_buf, 'c_tm_wday')  -1:
diff --git a/pypy/module/rctime/test/test_rctime.py 
b/pypy/module/rctime/test/test_rctime.py
--- a/pypy/module/rctime/test/test_rctime.py
+++ b/pypy/module/rctime/test/test_rctime.py
@@ -5,7 +5,6 @@
 
 def test_attributes(self):
 import time as rctime
-assert isinstance(rctime.accept2dyear, int)
 assert isinstance(rctime.altzone, int)
 assert isinstance(rctime.daylight, int)
 assert isinstance(rctime.timezone, int)
@@ -101,22 +100,16 @@
 res = rctime.mktime(rctime.localtime())
 assert isinstance(res, float)
 
+# year cannot be -1
 ltime = rctime.localtime()
-rctime.accept2dyear == 0
 ltime = list(ltime)
 ltime[0] = -1
-raises(ValueError, rctime.mktime, tuple(ltime))
-rctime.accept2dyear == 1
+raises(OverflowError, rctime.mktime, tuple(ltime))
 
-ltime = list(ltime)
-ltime[0] = 67
-ltime = tuple(ltime)
-if os.name != nt and sys.maxsize  132:   # time_t may be 64bit
-raises(OverflowError, rctime.mktime, ltime)
-
+# year cannot be 100
 ltime = list(ltime)
 ltime[0] = 100
-raises(ValueError, rctime.mktime, tuple(ltime))
+raises(OverflowError, rctime.mktime, tuple(ltime))
 
 t = rctime.time()
 assert int(rctime.mktime(rctime.localtime(t))) == int(t)
@@ -169,28 +162,6 @@
 assert asc[-len(str(bigyear)):] == str(bigyear)
 raises(OverflowError, rctime.asctime, (bigyear + 1,) + (0,)*8)
 
-def test_accept2dyear_access(self):
-import time as rctime
-
-accept2dyear = rctime.accept2dyear
-del rctime.accept2dyear
-try:
-# with year = 1900 this shouldn't need to access accept2dyear
-assert rctime.asctime((2000,) + (0,) * 8).split()[-1] == '2000'
-finally:
-rctime.accept2dyear = accept2dyear
-
-def test_accept2dyear_bad(self):
-import time as rctime
-class X:
-def __bool__(self):
-raise RuntimeError('boo')
-orig, rctime.accept2dyear = rctime.accept2dyear, X()
-try:
-raises(RuntimeError, rctime.asctime, (200,)  + (0,) * 8)
-finally:
-rctime.accept2dyear = orig
-
 def test_struct_time(self):
 import time as rctime
 raises(TypeError, rctime.struct_time)
@@ -281,7 +252,7 @@
 raises(TypeError, rctime.strftime, ())
 raises(TypeError, rctime.strftime, (1,))
 raises(TypeError, rctime.strftime, range(8))
-exp = '2000 01 01 00 00 00 1 001'
+exp = '0 01 01 00 00 00 1 001'
 assert rctime.strftime(%Y %m %d %H %M %S %w %j, (0,)*9) == exp
 
 # Guard against invalid/non-supported format string
@@ -296,6 +267,23 @@
 else:
 assert rctime.strftime('%f') == '%f'
 
+def

[pypy-commit] pypy py3.3-fixes2: remove time.accept2dyear (removed in pythong 3.3)

2014-08-19 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72916:df851de79c11
Date: 2014-08-19 20:20 +0200
http://bitbucket.org/pypy/pypy/changeset/df851de79c11/

Log:remove time.accept2dyear (removed in pythong 3.3)

diff --git a/pypy/module/rctime/__init__.py b/pypy/module/rctime/__init__.py
--- a/pypy/module/rctime/__init__.py
+++ b/pypy/module/rctime/__init__.py
@@ -39,5 +39,3 @@
 from pypy.module.rctime import interp_time
 
 interp_time._init_timezone(space)
-interp_time._init_accept2dyear(space)
-
diff --git a/pypy/module/rctime/interp_time.py 
b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -198,13 +198,6 @@
 c_strftime = external('strftime', [rffi.CCHARP, rffi.SIZE_T, rffi.CCHARP, 
TM_P],
   rffi.SIZE_T)
 
-def _init_accept2dyear(space):
-if os.environ.get(PYTHONY2K):
-accept2dyear = 0
-else:
-accept2dyear = 1
-_set_module_object(space, accept2dyear, space.wrap(accept2dyear))
-
 def _init_timezone(space):
 timezone = daylight = altzone = 0
 tzname = [, ]
@@ -435,21 +428,6 @@
 glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
 rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)
 
-if y  1000:
-w_accept2dyear = _get_module_object(space, accept2dyear)
-accept2dyear = space.is_true(w_accept2dyear)
-
-if accept2dyear:
-if 69 = y = 99:
-y += 1900
-elif 0 = y = 68:
-y += 2000
-else:
-raise OperationError(space.w_ValueError,
- space.wrap(year out of range))
-space.warn(space.wrap(Century info guessed for a 2-digit year.),
-   space.w_DeprecationWarning)
-
 # tm_wday does not need checking of its upper-bound since taking %
 #  7 in _gettmarg() automatically restricts the range.
 if rffi.getintfield(glob_buf, 'c_tm_wday')  -1:
diff --git a/pypy/module/rctime/test/test_rctime.py 
b/pypy/module/rctime/test/test_rctime.py
--- a/pypy/module/rctime/test/test_rctime.py
+++ b/pypy/module/rctime/test/test_rctime.py
@@ -5,7 +5,6 @@
 
 def test_attributes(self):
 import time as rctime
-assert isinstance(rctime.accept2dyear, int)
 assert isinstance(rctime.altzone, int)
 assert isinstance(rctime.daylight, int)
 assert isinstance(rctime.timezone, int)
@@ -101,22 +100,16 @@
 res = rctime.mktime(rctime.localtime())
 assert isinstance(res, float)
 
+# year cannot be -1
 ltime = rctime.localtime()
-rctime.accept2dyear == 0
 ltime = list(ltime)
 ltime[0] = -1
-raises(ValueError, rctime.mktime, tuple(ltime))
-rctime.accept2dyear == 1
+raises(OverflowError, rctime.mktime, tuple(ltime))
 
-ltime = list(ltime)
-ltime[0] = 67
-ltime = tuple(ltime)
-if os.name != nt and sys.maxsize  132:   # time_t may be 64bit
-raises(OverflowError, rctime.mktime, ltime)
-
+# year cannot be 100
 ltime = list(ltime)
 ltime[0] = 100
-raises(ValueError, rctime.mktime, tuple(ltime))
+raises(OverflowError, rctime.mktime, tuple(ltime))
 
 t = rctime.time()
 assert int(rctime.mktime(rctime.localtime(t))) == int(t)
@@ -169,28 +162,6 @@
 assert asc[-len(str(bigyear)):] == str(bigyear)
 raises(OverflowError, rctime.asctime, (bigyear + 1,) + (0,)*8)
 
-def test_accept2dyear_access(self):
-import time as rctime
-
-accept2dyear = rctime.accept2dyear
-del rctime.accept2dyear
-try:
-# with year = 1900 this shouldn't need to access accept2dyear
-assert rctime.asctime((2000,) + (0,) * 8).split()[-1] == '2000'
-finally:
-rctime.accept2dyear = accept2dyear
-
-def test_accept2dyear_bad(self):
-import time as rctime
-class X:
-def __bool__(self):
-raise RuntimeError('boo')
-orig, rctime.accept2dyear = rctime.accept2dyear, X()
-try:
-raises(RuntimeError, rctime.asctime, (200,)  + (0,) * 8)
-finally:
-rctime.accept2dyear = orig
-
 def test_struct_time(self):
 import time as rctime
 raises(TypeError, rctime.struct_time)
@@ -281,7 +252,7 @@
 raises(TypeError, rctime.strftime, ())
 raises(TypeError, rctime.strftime, (1,))
 raises(TypeError, rctime.strftime, range(8))
-exp = '2000 01 01 00 00 00 1 001'
+exp = '0 01 01 00 00 00 1 001'
 assert rctime.strftime(%Y %m %d %H %M %S %w %j, (0,)*9) == exp
 
 # Guard against invalid/non-supported format string
@@ -296,6 +267,23 @@
 else:
 assert rctime.strftime('%f') == '%f'
 
+def test_strftime_y2k(self):
+'''Port of cpython's 

[pypy-commit] pypy py3.3-fixes2: implement flush kwarg for print()

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72843:c92b637d6a83
Date: 2014-08-17 15:01 +0200
http://bitbucket.org/pypy/pypy/changeset/c92b637d6a83/

Log:implement flush kwarg for print()

diff --git a/pypy/module/__builtin__/app_io.py 
b/pypy/module/__builtin__/app_io.py
--- a/pypy/module/__builtin__/app_io.py
+++ b/pypy/module/__builtin__/app_io.py
@@ -57,13 +57,14 @@
 return line
 
 def print_(*args, **kwargs):
-rprint(value, ..., sep=' ', end='\n', file=sys.stdout)
+rprint(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
 
 Prints the values to a stream, or to sys.stdout by default.
 Optional keyword arguments:
-file: a file-like object (stream); defaults to the current sys.stdout.
-sep:  string inserted between values, default a space.
-end:  string appended after the last value, default a newline.
+file:  a file-like object (stream); defaults to the current sys.stdout.
+sep:   string inserted between values, default a space.
+end:   string appended after the last value, default a newline.
+flush: whether to forcibly flush the stream.
 
 fp = kwargs.pop(file, None)
 if fp is None:
@@ -80,6 +81,7 @@
 if end is not None:
 if not isinstance(end, str):
 raise TypeError(end must be None or a string)
+flush = kwargs.pop('flush', None)
 if kwargs:
 raise TypeError(invalid keyword arguments to print())
 if sep is None:
@@ -91,3 +93,5 @@
 write(sep)
 write(arg)
 write(end)
+if flush:
+fp.flush()
diff --git a/pypy/module/__builtin__/test/test_print.py 
b/pypy/module/__builtin__/test/test_print.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__builtin__/test/test_print.py
@@ -0,0 +1,29 @@
+class AppTestPrint:
+
+def test_print_flush(self):
+
+# operation of the flush flag
+class filelike():
+def __init__(self):
+self.written = ''
+self.flushed = 0
+def write(self, str):
+self.written += str
+def flush(self):
+self.flushed += 1
+
+f = filelike()
+print(1, file=f, end='', flush=True)
+print(2, file=f, end='', flush=True)
+print(3, file=f, flush=False)
+assert f.written == '123\\n'
+assert f.flushed == 2
+
+# ensure exceptions from flush are passed through
+class noflush():
+def write(self, str):
+pass
+def flush(self):
+raise RuntimeError
+raises(RuntimeError, print, 1, file=noflush(), flush=True)
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes2: merge py3.3

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72842:bb19e3e737b0
Date: 2014-08-17 15:00 +0200
http://bitbucket.org/pypy/pypy/changeset/bb19e3e737b0/

Log:merge py3.3

diff too long, truncating to 2000 out of 2 lines

diff --git a/_pytest/__init__.py b/_pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.2.4.dev2'
+__version__ = '2.5.2'
diff --git a/_pytest/_argcomplete.py b/_pytest/_argcomplete.py
new file mode 100644
--- /dev/null
+++ b/_pytest/_argcomplete.py
@@ -0,0 +1,104 @@
+
+allow bash-completion for argparse with argcomplete if installed
+needs argcomplete=0.5.6 for python 3.2/3.3 (older versions fail
+to find the magic string, so _ARGCOMPLETE env. var is never set, and
+this does not need special code.
+
+argcomplete does not support python 2.5 (although the changes for that
+are minor).
+
+Function try_argcomplete(parser) should be called directly before
+the call to ArgumentParser.parse_args().
+
+The filescompleter is what you normally would use on the positional
+arguments specification, in order to get dirname/ after dirnTAB
+instead of the default dirname :
+
+   optparser.add_argument(Config._file_or_dir, nargs='*'
+   ).completer=filescompleter
+
+Other, application specific, completers should go in the file
+doing the add_argument calls as they need to be specified as .completer
+attributes as well. (If argcomplete is not installed, the function the
+attribute points to will not be used).
+
+SPEEDUP
+===
+The generic argcomplete script for bash-completion
+(/etc/bash_completion.d/python-argcomplete.sh )
+uses a python program to determine startup script generated by pip.
+You can speed up completion somewhat by changing this script to include
+  # PYTHON_ARGCOMPLETE_OK
+so the the python-argcomplete-check-easy-install-script does not
+need to be called to find the entry point of the code and see if that is
+marked  with PYTHON_ARGCOMPLETE_OK
+
+INSTALL/DEBUGGING
+=
+To include this support in another application that has setup.py generated
+scripts:
+- add the line:
+# PYTHON_ARGCOMPLETE_OK
+  near the top of the main python entry point
+- include in the file calling parse_args():
+from _argcomplete import try_argcomplete, filescompleter
+   , call try_argcomplete just before parse_args(), and optionally add
+   filescompleter to the positional arguments' add_argument()
+If things do not work right away:
+- switch on argcomplete debugging with (also helpful when doing custom
+  completers):
+export _ARC_DEBUG=1
+- run:
+python-argcomplete-check-easy-install-script $(which appname)
+echo $?
+  will echo 0 if the magic line has been found, 1 if not
+- sometimes it helps to find early on errors using:
+_ARGCOMPLETE=1 _ARC_DEBUG=1 appname
+  which should throw a KeyError: 'COMPLINE' (which is properly set by the
+  global argcomplete script).
+
+
+import sys
+import os
+from glob import glob
+
+class FastFilesCompleter:
+'Fast file completer class'
+def __init__(self, directories=True):
+self.directories = directories
+
+def __call__(self, prefix, **kwargs):
+only called on non option completions
+if os.path.sep in prefix[1:]: #
+prefix_dir = len(os.path.dirname(prefix) + os.path.sep)
+else:
+prefix_dir = 0
+completion = []
+globbed = []
+if '*' not in prefix and '?' not in prefix:
+if prefix[-1] == os.path.sep:  # we are on unix, otherwise no bash
+globbed.extend(glob(prefix + '.*'))
+prefix += '*'
+globbed.extend(glob(prefix))
+for x in sorted(globbed):
+if os.path.isdir(x):
+x += '/'
+# append stripping the prefix (like bash, not like compgen)
+completion.append(x[prefix_dir:])
+return completion
+
+if os.environ.get('_ARGCOMPLETE'):
+# argcomplete 0.5.6 is not compatible with python 2.5.6: print/with/format
+if sys.version_info[:2]  (2, 6):
+sys.exit(1)
+try:
+import argcomplete.completers
+except ImportError:
+sys.exit(-1)
+filescompleter = FastFilesCompleter()
+
+def try_argcomplete(parser):
+argcomplete.autocomplete(parser)
+else:
+def try_argcomplete(parser): pass
+filescompleter = None
diff --git a/_pytest/assertion/__init__.py b/_pytest/assertion/__init__.py
--- a/_pytest/assertion/__init__.py
+++ b/_pytest/assertion/__init__.py
@@ -3,7 +3,6 @@
 
 import py
 import sys
-import pytest
 from _pytest.monkeypatch import monkeypatch
 from _pytest.assertion import util
 
@@ -19,8 +18,8 @@
 to provide assert expression information. )
 group.addoption('--no-assert', action=store_true, default=False,
 dest=noassert, help=DEPRECATED equivalent to --assert=plain)
-group.addoption('--nomagic', action=store_true, default=False,
-

[pypy-commit] pypy py3.3-fixes3: add missing name attribute for MD5Type

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes3
Changeset: r72858:18c94a38e38e
Date: 2014-08-17 16:56 +0200
http://bitbucket.org/pypy/pypy/changeset/18c94a38e38e/

Log:add missing name attribute for MD5Type

diff --git a/pypy/module/_md5/interp_md5.py b/pypy/module/_md5/interp_md5.py
--- a/pypy/module/_md5/interp_md5.py
+++ b/pypy/module/_md5/interp_md5.py
@@ -52,6 +52,7 @@
 copy  = interp2app(W_MD5.copy_w),
 digest_size = 16,
 block_size = 64,
+name  = 'md5',
 __doc__   = md5(arg) - return new md5 object.
 
 If arg is present, the method call update(arg) is made.)
diff --git a/pypy/module/_md5/test/test_md5.py 
b/pypy/module/_md5/test/test_md5.py
--- a/pypy/module/_md5/test/test_md5.py
+++ b/pypy/module/_md5/test/test_md5.py
@@ -19,6 +19,12 @@
 )
 
 
+def test_name(self):
+
+md5.name should be 'md5'.
+
+assert self.md5.md5().name == 'md5'
+
 def test_digest_size(self):
 
 md5.digest_size should be 16.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes3: fix unbound variable

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes3
Changeset: r72859:7bdae69fd02e
Date: 2014-08-17 18:03 +0200
http://bitbucket.org/pypy/pypy/changeset/7bdae69fd02e/

Log:fix unbound variable

diff --git a/lib-python/3/test/test_hashlib.py 
b/lib-python/3/test/test_hashlib.py
--- a/lib-python/3/test/test_hashlib.py
+++ b/lib-python/3/test/test_hashlib.py
@@ -142,7 +142,7 @@
 def test_hexdigest(self):
 for cons in self.hash_constructors:
 h = cons()
-assert isinstance(h.digest(), bytes), name
+assert isinstance(h.digest(), bytes), cons.__name__
 self.assertEqual(hexstr(h.digest()), h.hexdigest())
 
 def test_large_update(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes3: add .name attribute for all instances of shaXXX classes

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes3
Changeset: r72862:98b3c0bab1fe
Date: 2014-08-17 20:14 +0200
http://bitbucket.org/pypy/pypy/changeset/98b3c0bab1fe/

Log:add .name attribute for all instances of shaXXX classes

diff --git a/lib_pypy/_sha1.py b/lib_pypy/_sha1.py
--- a/lib_pypy/_sha1.py
+++ b/lib_pypy/_sha1.py
@@ -123,6 +123,8 @@
 def __init__(self):
 Initialisation.
 
+self.name = 'sha'
+
 # Initial message length in bits(!).
 self.length = 0
 self.count = [0, 0]
@@ -349,6 +351,7 @@
 
 
 crypto = sha()
+crypto.name = 'sha1'
 if arg:
 crypto.update(arg)
 
diff --git a/lib_pypy/_sha256.py b/lib_pypy/_sha256.py
--- a/lib_pypy/_sha256.py
+++ b/lib_pypy/_sha256.py
@@ -208,6 +208,7 @@
 block_size = SHA_BLOCKSIZE
 
 def __init__(self, s=None):
+self.name = 'sha256'
 self._sha = sha_init()
 if s:
 sha_update(self._sha, s)
@@ -230,6 +231,7 @@
 digest_size = digestsize = 28
 
 def __init__(self, s=None):
+self.name = 'sha224'
 self._sha = sha224_init()
 if s:
 sha_update(self._sha, s)
diff --git a/lib_pypy/_sha512.py b/lib_pypy/_sha512.py
--- a/lib_pypy/_sha512.py
+++ b/lib_pypy/_sha512.py
@@ -236,6 +236,7 @@
 block_size = SHA_BLOCKSIZE
 
 def __init__(self, s=None):
+self.name = 'sha512'
 self._sha = sha_init()
 if s:
 sha_update(self._sha, s)
@@ -258,6 +259,7 @@
 digest_size = digestsize = 48
 
 def __init__(self, s=None):
+self.name = 'sha384'
 self._sha = sha384_init()
 if s:
 sha_update(self._sha, s)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes3: port _sha512.py module test to py3

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes3
Changeset: r72861:9852a31d49d9
Date: 2014-08-17 19:50 +0200
http://bitbucket.org/pypy/pypy/changeset/9852a31d49d9/

Log:port _sha512.py module test to py3

diff --git a/lib_pypy/_sha512.py b/lib_pypy/_sha512.py
--- a/lib_pypy/_sha512.py
+++ b/lib_pypy/_sha512.py
@@ -270,7 +270,7 @@
 def test():
 import _sha512
 
-a_str = just a test string
+a_str = bjust a test string
 
 assert _sha512.sha512().hexdigest() == sha512().hexdigest()
 assert _sha512.sha512(a_str).hexdigest() == sha512(a_str).hexdigest()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes3: port _sha256.py to py3

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes3
Changeset: r72860:27a13b5357da
Date: 2014-08-17 19:49 +0200
http://bitbucket.org/pypy/pypy/changeset/27a13b5357da/

Log:port _sha256.py to py3

diff --git a/lib_pypy/_sha256.py b/lib_pypy/_sha256.py
--- a/lib_pypy/_sha256.py
+++ b/lib_pypy/_sha256.py
@@ -201,7 +201,7 @@
 dig = []
 for i in sha_info['digest']:
 dig.extend([ ((i24)  0xff), ((i16)  0xff), ((i8)  0xff), (i  
0xff) ])
-return ''.join([chr(i) for i in dig])
+return bytes(dig)
 
 class sha256(object):
 digest_size = digestsize = SHA_DIGESTSIZE
@@ -219,7 +219,7 @@
 return sha_final(self._sha.copy())[:self._sha['digestsize']]
 
 def hexdigest(self):
-return ''.join(['%.2x' % ord(i) for i in self.digest()])
+return ''.join(['%.2x' % i for i in self.digest()])
 
 def copy(self):
 new = sha256.__new__(sha256)
@@ -240,7 +240,7 @@
 return new
 
 def test():
-a_str = just a test string
+a_str = bjust a test string
 
 assert 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' 
== sha256().hexdigest()
 assert 'd7b553c6f09ac85d142415f857c5310f3bbbe7cdd787cce4b985acedd585266f' 
== sha256(a_str).hexdigest()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes3: add tests for .name attribute on sha objects

2014-08-17 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes3
Changeset: r72863:51ec894e3d52
Date: 2014-08-17 20:17 +0200
http://bitbucket.org/pypy/pypy/changeset/51ec894e3d52/

Log:add tests for .name attribute on sha objects

diff --git a/pypy/module/test_lib_pypy/test_sha_extra.py 
b/pypy/module/test_lib_pypy/test_sha_extra.py
--- a/pypy/module/test_lib_pypy/test_sha_extra.py
+++ b/pypy/module/test_lib_pypy/test_sha_extra.py
@@ -37,3 +37,30 @@
 assert _sha.sha1().digest_size == 20
 assert _sha.sha1().digestsize == 20
 assert _sha.sha1().block_size == 64
+
+assert _sha.sha().name == 'sha'
+assert _sha.sha1().name == 'sha1'
+
+
+class AppTestSHA256:
+spaceconfig = dict(usemodules=('struct',))
+
+def setup_class(cls):
+cls.w__sha256 = import_lib_pypy(cls.space, '_sha256')
+
+def test_attributes(self):
+_sha256 = self._sha256
+assert _sha256.sha224().name == 'sha224'
+assert _sha256.sha256().name == 'sha256'
+
+
+class AppTestSHA512:
+spaceconfig = dict(usemodules=('struct',))
+
+def setup_class(cls):
+cls.w__sha512 = import_lib_pypy(cls.space, '_sha512')
+
+def test_attributes(self):
+_sha512 = self._sha512
+assert _sha512.sha384().name == 'sha384'
+assert _sha512.sha512().name == 'sha512'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes2: bz2: disallow pickling for compressor/decompresson (cpython compat)

2014-08-16 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72831:a11bfe6cc0b1
Date: 2014-08-15 23:50 +0200
http://bitbucket.org/pypy/pypy/changeset/a11bfe6cc0b1/

Log:bz2: disallow pickling for compressor/decompresson (cpython compat)

diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -268,6 +268,10 @@
 BZ2_bzCompressEnd(self.bzs)
 lltype.free(self.bzs, flavor='raw')
 
+def __getstate__(self):
+raise OperationError(self.space.w_TypeError,
+self.space.wrap(cannot serialize '_bz2.BZ2Compressor' object))
+
 @unwrap_spec(data='bufferstr')
 def compress(self, data):
 compress(data) - string
@@ -333,6 +337,7 @@
 W_BZ2Compressor.typedef = TypeDef(_bz2.BZ2Compressor,
 __doc__ = W_BZ2Compressor.__doc__,
 __new__ = interp2app(descr_compressor__new__),
+__getstate__ = interp2app(W_BZ2Compressor.__getstate__),
 compress = interp2app(W_BZ2Compressor.compress),
 flush = interp2app(W_BZ2Compressor.flush),
 )
@@ -372,6 +377,10 @@
 BZ2_bzDecompressEnd(self.bzs)
 lltype.free(self.bzs, flavor='raw')
 
+def __getstate__(self):
+raise OperationError(self.space.w_TypeError,
+self.space.wrap(cannot serialize '_bz2.BZ2Decompressor' object))
+
 def eof_w(self, space):
 if self.running:
 return space.w_False
@@ -429,6 +438,7 @@
 W_BZ2Decompressor.typedef = TypeDef(_bz2.BZ2Decompressor,
 __doc__ = W_BZ2Decompressor.__doc__,
 __new__ = interp2app(descr_decompressor__new__),
+__getstate__ = interp2app(W_BZ2Decompressor.__getstate__),
 unused_data = interp_attrproperty_bytes(unused_data, W_BZ2Decompressor),
 eof = GetSetProperty(W_BZ2Decompressor.eof_w),
 decompress = interp2app(W_BZ2Decompressor.decompress),
diff --git a/pypy/module/bz2/test/test_bz2_compdecomp.py 
b/pypy/module/bz2/test/test_bz2_compdecomp.py
--- a/pypy/module/bz2/test/test_bz2_compdecomp.py
+++ b/pypy/module/bz2/test/test_bz2_compdecomp.py
@@ -108,6 +108,13 @@
 data += bz2c.flush()
 assert self.decompress(data) == self.TEXT
 
+def test_compressor_pickle_error(self):
+from bz2 import BZ2Compressor
+import pickle
+
+exc = raises(TypeError, pickle.dumps, BZ2Compressor())
+assert exc.value.args[0] == cannot serialize '_bz2.BZ2Compressor' 
object
+
 
 class AppTestBZ2Decompressor(CheckAllocation):
 spaceconfig = dict(usemodules=('bz2', 'rctime'))
@@ -186,6 +193,13 @@
 assert decompressed_data == b''
 raises(IOError, bz2d.decompress, self.BUGGY_DATA)
 
+def test_decompressor_pickle_error(self):
+from bz2 import BZ2Decompressor
+import pickle
+
+exc = raises(TypeError, pickle.dumps, BZ2Decompressor())
+assert exc.value.args[0] == cannot serialize '_bz2.BZ2Decompressor' 
object
+
 
 class AppTestBZ2ModuleFunctions(CheckAllocation):
 spaceconfig = dict(usemodules=('bz2', 'rctime'))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes2: prefer oefmt over OperationError

2014-08-16 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72832:50ea833f79dd
Date: 2014-08-16 06:57 +0200
http://bitbucket.org/pypy/pypy/changeset/50ea833f79dd/

Log:prefer oefmt over OperationError

diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -2,7 +2,7 @@
 from rpython.rtyper.tool import rffi_platform as platform
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rtyper.lltypesystem import lltype
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.typedef import TypeDef, interp_attrproperty_bytes
 from pypy.interpreter.typedef import GetSetProperty
@@ -269,8 +269,7 @@
 lltype.free(self.bzs, flavor='raw')
 
 def __getstate__(self):
-raise OperationError(self.space.w_TypeError,
-self.space.wrap(cannot serialize '_bz2.BZ2Compressor' object))
+raise oefmt(self.space.w_TypeError, cannot serialize '%T' object, 
self)
 
 @unwrap_spec(data='bufferstr')
 def compress(self, data):
@@ -378,8 +377,7 @@
 lltype.free(self.bzs, flavor='raw')
 
 def __getstate__(self):
-raise OperationError(self.space.w_TypeError,
-self.space.wrap(cannot serialize '_bz2.BZ2Decompressor' object))
+raise oefmt(self.space.w_TypeError, cannot serialize '%T' object, 
self)
 
 def eof_w(self, space):
 if self.running:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes2: make test_debugmallocstats cpython only

2014-08-12 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72768:ceebddacd8c1
Date: 2014-08-12 20:41 +0200
http://bitbucket.org/pypy/pypy/changeset/ceebddacd8c1/

Log:make test_debugmallocstats cpython only

diff --git a/lib-python/3/test/test_sys.py b/lib-python/3/test/test_sys.py
--- a/lib-python/3/test/test_sys.py
+++ b/lib-python/3/test/test_sys.py
@@ -588,6 +588,7 @@
 self.assertEqual(sys.implementation.name,
  sys.implementation.name.lower())
 
+@test.support.cpython_only
 def test_debugmallocstats(self):
 # Test sys._debugmallocstats()
 from test.script_helper import assert_python_ok
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes2: sys.exit() should produce a SystemExit with code is None

2014-08-12 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes2
Changeset: r72775:4558aef78acc
Date: 2014-08-12 21:34 +0200
http://bitbucket.org/pypy/pypy/changeset/4558aef78acc/

Log:sys.exit() should produce a SystemExit with code is None

diff --git a/pypy/module/exceptions/test/test_exc.py 
b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -127,6 +127,24 @@
 assert SystemExit(x).code == x
 assert SystemExit(1, 2).code == (1, 2)
 
+def test_sys_exit(self):
+import sys
+
+exc = raises(SystemExit, sys.exit)
+assert exc.value.code is None
+
+exc = raises(SystemExit, sys.exit, 0)
+assert exc.value.code == 0
+
+exc = raises(SystemExit, sys.exit, 1)
+assert exc.value.code == 1
+
+exc = raises(SystemExit, sys.exit, 2)
+assert exc.value.code == 2
+
+exc = raises(SystemExit, sys.exit, (1, 2, 3))
+assert exc.value.code == (1, 2, 3)
+
 def test_str_unicode(self):
 e = ValueError('#224;#232;#236;')
 assert str(e) == '#224;#232;#236;'
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -49,7 +49,7 @@
 except:
 return False# got an exception again... ignore, report the original
 
-def exit(exitcode=0):
+def exit(exitcode=None):
 Exit the interpreter by raising SystemExit(exitcode).
 If the exitcode is omitted or None, it defaults to zero (i.e., success).
 If the exitcode is numeric, it will be used as the system exit status.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: fix typo

2014-08-09 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72730:17a069157969
Date: 2014-08-03 18:19 +0200
http://bitbucket.org/pypy/pypy/changeset/17a069157969/

Log:fix typo

diff --git a/rpython/doc/windows.rst b/rpython/doc/windows.rst
--- a/rpython/doc/windows.rst
+++ b/rpython/doc/windows.rst
@@ -306,7 +306,7 @@
 it CPython64/64.
 
 It is probably not too much work if the goal is only to get a translated
-PyPy executable, and to run all tests before transaction.  But you need
+PyPy executable, and to run all tests before translation.  But you need
 to start somewhere, and you should start with some tests in
 rpython/translator/c/test/, like ``test_standalone.py`` and
 ``test_newgc.py``: try to have them pass on top of CPython64/64.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: fix typo

2014-08-09 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72731:c6f8542c472b
Date: 2014-08-03 18:21 +0200
http://bitbucket.org/pypy/pypy/changeset/c6f8542c472b/

Log:fix typo

diff --git a/rpython/doc/windows.rst b/rpython/doc/windows.rst
--- a/rpython/doc/windows.rst
+++ b/rpython/doc/windows.rst
@@ -314,7 +314,7 @@
 Keep in mind that this runs small translations, and some details may go
 wrong.  The most obvious one is to check that it produces C files that
 use the integer type ``Signed`` --- but what is ``Signed`` defined to?
-It should be equal to ``long`` on every other platforms, but on Win64 it
+It should be equal to ``long`` on every other platform, but on Win64 it
 should be something like ``long long``.
 
 What is more generally needed is to review all the C files in
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: use a different wording

2014-08-09 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72733:af71f724922c
Date: 2014-08-04 06:10 +0200
http://bitbucket.org/pypy/pypy/changeset/af71f724922c/

Log:use a different wording

diff --git a/rpython/doc/windows.rst b/rpython/doc/windows.rst
--- a/rpython/doc/windows.rst
+++ b/rpython/doc/windows.rst
@@ -339,9 +339,9 @@
 The major intermediate goal is to get a translation of PyPy with ``-O2``
 with a minimal set of modules, starting with ``--no-allworkingmodules``;
 you need to use CPython64/64 to run this translation too.  Check
-carefully the warnings of the C compiler at the end.  I think that MSVC
-is lenient in that by default a lot of mismatches of integer sizes are
-reported as warnings.
+carefully the warnings of the C compiler at the end. By default, MSVC
+reports a lot of mismatches of integer sizes as warnings instead of
+errors.
 
 Then you need to review ``pypy/module/*/`` for ``LONG-versus-Signed``
 issues.  At some time during this review, we get a working translated
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: fix some typos

2014-08-09 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72732:7f2b23211785
Date: 2014-08-03 18:26 +0200
http://bitbucket.org/pypy/pypy/changeset/7f2b23211785/

Log:fix some typos

diff --git a/rpython/doc/windows.rst b/rpython/doc/windows.rst
--- a/rpython/doc/windows.rst
+++ b/rpython/doc/windows.rst
@@ -325,11 +325,11 @@
 
 Then, these two C types have corresponding RPython types: ``rffi.LONG``
 and ``lltype.Signed`` respectively.  The first should really correspond
-to the C ``long``.  Add tests that check that integers casted to one
+to the C ``long``.  Add tests that check that integers cast to one
 type or the other really have 32 and 64 bits respectively, on Win64.
 
 Once these basic tests work, you need to review ``rpython/rlib/`` for
-usages of ``rffi.LONG`` versus ``lltype.Signed``.  The goal would be to
+uses of ``rffi.LONG`` versus ``lltype.Signed``.  The goal would be to
 fix some more ``LONG-versus-Signed`` issues, by fixing the tests --- as
 always run on top of CPython64/64.  Note that there was some early work
 done in ``rpython/rlib/rarithmetic`` with the goal of running all the
@@ -340,13 +340,13 @@
 with a minimal set of modules, starting with ``--no-allworkingmodules``;
 you need to use CPython64/64 to run this translation too.  Check
 carefully the warnings of the C compiler at the end.  I think that MSVC
-is nice in the sense that by default a lot of mismatches of integer
-sizes are reported as warnings.
+is lenient in that by default a lot of mismatches of integer sizes are
+reported as warnings.
 
 Then you need to review ``pypy/module/*/`` for ``LONG-versus-Signed``
 issues.  At some time during this review, we get a working translated
 PyPy on Windows 64 that includes all ``--translationmodules``, i.e.
-everything needed to run translations.  When we are there, the hacked
+everything needed to run translations.  Once we have that, the hacked
 CPython64/64 becomes much less important, because we can run future
 translations on top of this translated PyPy.  As soon as we get there,
 please *distribute* the translated PyPy.  It's an essential component
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: update link to bug tracker

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72662:6057597cf892
Date: 2014-08-03 12:17 +0200
http://bitbucket.org/pypy/pypy/changeset/6057597cf892/

Log:update link to bug tracker

diff --git a/pypy/doc/index.rst b/pypy/doc/index.rst
--- a/pypy/doc/index.rst
+++ b/pypy/doc/index.rst
@@ -110,7 +110,7 @@
 .. _here: http://www.tismer.com/pypy/irc-logs/pypy/
 .. _Development mailing list: http://mail.python.org/mailman/listinfo/pypy-dev
 .. _Commit mailing list: http://mail.python.org/mailman/listinfo/pypy-commit
-.. _Development bug/feature tracker: https://bugs.pypy.org/
+.. _Development bug/feature tracker: 
https://bitbucket.org/pypy/pypy/issues?status=newstatus=open
 
 
 Indices and tables
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: fix typos and awkward wording

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72661:b3db0567b334
Date: 2014-08-02 20:20 +0200
http://bitbucket.org/pypy/pypy/changeset/b3db0567b334/

Log:fix typos and awkward wording

diff --git a/pypy/doc/you-want-to-help.rst b/pypy/doc/you-want-to-help.rst
--- a/pypy/doc/you-want-to-help.rst
+++ b/pypy/doc/you-want-to-help.rst
@@ -14,14 +14,14 @@
 * Because of the above, we are very serious about Test Driven Development.
   It's not only what we believe in, but also that PyPy's architecture is
   working very well with TDD in mind and not so well without it. Often
-  the development means progressing in an unrelated corner, one unittest
+  development means progressing in an unrelated corner, one unittest
   at a time; and then flipping a giant switch, bringing it all together.
   (It generally works out of the box.  If it doesn't, then we didn't
-  write enough unit tests.)  It's worth repeating - PyPy
-  approach is great if you do TDD, not so great otherwise.
+  write enough unit tests.)  It's worth repeating - PyPy's
+  approach is great if you do TDD, and not so great otherwise.
 
 * PyPy uses an entirely different set of tools - most of them included
-  in the PyPy repository. There is no Makefile, nor autoconf. More below
+  in the PyPy repository. There is no Makefile, nor autoconf. More below.
 
 
 Architecture
@@ -32,13 +32,13 @@
 * :doc:`RPython rpython:rpython` is the language in which we write 
interpreters. Not the entire
   PyPy project is written in RPython, only the parts that are compiled in
   the translation process. The interesting point is that RPython has no parser,
-  it's compiled from the live python objects, which make it possible to do
+  it's compiled from the live python objects, which makes it possible to do
   all kinds of metaprogramming during import time. In short, Python is a meta
   programming language for RPython.
 
   The RPython standard library is to be found in the ``rlib`` subdirectory.
 
-* The translation toolchain - this is the part that takes care about 
translating
+* The translation toolchain - this is the part that takes care of translating
   RPython to flow graphs and then to C. There is more in the 
:doc:`architecture architecture`
   document written about it.
 
@@ -67,7 +67,7 @@
   that turns it into machine code.  Writing a new backend is a
   traditional way to get into the project.
 
-* Garbage Collectors (GC): as you can notice if you are used to CPython's
+* Garbage Collectors (GC): as you may notice if you are used to CPython's
   C code, there are no ``Py_INCREF/Py_DECREF`` equivalents in RPython code.
   :doc:`rpython:garbage-collection` is inserted
   during translation.  Moreover, this is not reference counting; it is a real
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: add lzma to build-time dependencies (required for py3.3)

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72660:cbb086cc9406
Date: 2014-08-02 19:52 +0200
http://bitbucket.org/pypy/pypy/changeset/cbb086cc9406/

Log:add lzma to build-time dependencies (required for py3.3)

diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -61,6 +61,9 @@
 bz2
 libbz2
 
+lzma
+liblzma
+
 sqlite3
 libsqlite3
 
@@ -79,12 +82,12 @@
 On Debian, this is the command to install all build-time dependencies::
 
 apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
-libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev
+liblzma-dev libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev
 
 On Fedora::
 
 yum install gcc make libffi-devel pkgconfig zlib-devel bzip2-devel \
-lib-sqlite3-devel ncurses-devel expat-devel openssl-devel
+xz-devel lib-sqlite3-devel ncurses-devel expat-devel openssl-devel
 
 On Mac OS X, most of these build-time dependencies are installed alongside
 the Developer Tools. However, note that in order for the installation to
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: use a more robust (hopefully) bug tracker url

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72666:ef9b286e5879
Date: 2014-08-03 17:59 +0200
http://bitbucket.org/pypy/pypy/changeset/ef9b286e5879/

Log:use a more robust (hopefully) bug tracker url

diff --git a/pypy/doc/index.rst b/pypy/doc/index.rst
--- a/pypy/doc/index.rst
+++ b/pypy/doc/index.rst
@@ -110,7 +110,7 @@
 .. _here: http://www.tismer.com/pypy/irc-logs/pypy/
 .. _Development mailing list: http://mail.python.org/mailman/listinfo/pypy-dev
 .. _Commit mailing list: http://mail.python.org/mailman/listinfo/pypy-commit
-.. _Development bug/feature tracker: 
https://bitbucket.org/pypy/pypy/issues?status=newstatus=open
+.. _Development bug/feature tracker: https://bitbucket.org/pypy/pypy/issues
 
 
 Indices and tables
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: remove obsolete paragraph about translation to Java/.NET

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72663:2e6e8dfca126
Date: 2014-08-03 12:18 +0200
http://bitbucket.org/pypy/pypy/changeset/2e6e8dfca126/

Log:remove obsolete paragraph about translation to Java/.NET

diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -75,9 +75,6 @@
 zipimport
 zlib
 
-  When translated to Java or .NET, the list is smaller; see
-  :source:`pypy/config/pypyoption.py` for details.
-
   When translated on Windows, a few Unix-only modules are skipped,
   and the following module is built instead:
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: move lzma instructions to dedicated Python 3.3 section

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72664:0c0a5730d7c7
Date: 2014-08-03 14:00 +0200
http://bitbucket.org/pypy/pypy/changeset/0c0a5730d7c7/

Log:move lzma instructions to dedicated Python 3.3 section

diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -61,9 +61,6 @@
 bz2
 libbz2
 
-lzma
-liblzma
-
 sqlite3
 libsqlite3
 
@@ -82,12 +79,12 @@
 On Debian, this is the command to install all build-time dependencies::
 
 apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
-liblzma-dev libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev
+libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev
 
 On Fedora::
 
 yum install gcc make libffi-devel pkgconfig zlib-devel bzip2-devel \
-xz-devel lib-sqlite3-devel ncurses-devel expat-devel openssl-devel
+lib-sqlite3-devel ncurses-devel expat-devel openssl-devel
 
 On Mac OS X, most of these build-time dependencies are installed alongside
 the Developer Tools. However, note that in order for the installation to
@@ -96,6 +93,26 @@
 xcode-select --install
 
 
+Python 3.3
+~~
+
+For versions of PyPy that implement Python 3.3 and later you will
+also need:
+
+lzma
+liblzma
+
+On Debian. install it using::
+
+apt-get install liblzma-dev
+
+On Fedora::
+
+yum install xz-devel
+
+TODO: Mac OS X
+
+
 Run the translation
 ---
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: restore lzma instructions to the common section

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72665:1c82abf52290
Date: 2014-08-03 16:56 +0200
http://bitbucket.org/pypy/pypy/changeset/1c82abf52290/

Log:restore lzma instructions to the common section

diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -61,6 +61,9 @@
 bz2
 libbz2
 
+lzma (required for Python 3.3 and later)
+liblzma
+
 sqlite3
 libsqlite3
 
@@ -81,11 +84,15 @@
 apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
 libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev
 
+For Python 3.3 you will also need ``liblzma-dev``.
+
 On Fedora::
 
 yum install gcc make libffi-devel pkgconfig zlib-devel bzip2-devel \
 lib-sqlite3-devel ncurses-devel expat-devel openssl-devel
 
+For Python 3.3 you will also need ``xz-devel``.
+
 On Mac OS X, most of these build-time dependencies are installed alongside
 the Developer Tools. However, note that in order for the installation to
 find them you may need to run::
@@ -93,26 +100,6 @@
 xcode-select --install
 
 
-Python 3.3
-~~
-
-For versions of PyPy that implement Python 3.3 and later you will
-also need:
-
-lzma
-liblzma
-
-On Debian. install it using::
-
-apt-get install liblzma-dev
-
-On Fedora::
-
-yum install xz-devel
-
-TODO: Mac OS X
-
-
 Run the translation
 ---
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: refer to PyPy3 rather than Python 3.3

2014-08-03 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72667:a8628eb1bb4f
Date: 2014-08-03 18:06 +0200
http://bitbucket.org/pypy/pypy/changeset/a8628eb1bb4f/

Log:refer to PyPy3 rather than Python 3.3

diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -61,7 +61,7 @@
 bz2
 libbz2
 
-lzma (required for Python 3.3 and later)
+lzma (required for PyPy3)
 liblzma
 
 sqlite3
@@ -84,14 +84,14 @@
 apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
 libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev
 
-For Python 3.3 you will also need ``liblzma-dev``.
+For PyPy3 you will also need ``liblzma-dev``.
 
 On Fedora::
 
 yum install gcc make libffi-devel pkgconfig zlib-devel bzip2-devel \
 lib-sqlite3-devel ncurses-devel expat-devel openssl-devel
 
-For Python 3.3 you will also need ``xz-devel``.
+For PyPy3 you will also need ``xz-devel``.
 
 On Mac OS X, most of these build-time dependencies are installed alongside
 the Developer Tools. However, note that in order for the installation to
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes: wrap LONGLONG_MASK (fixes #1836)

2014-08-02 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes
Changeset: r72654:744ada0a9c08
Date: 2014-08-02 23:36 +0200
http://bitbucket.org/pypy/pypy/changeset/744ada0a9c08/

Log:wrap LONGLONG_MASK (fixes #1836)

diff --git a/pypy/module/_lzma/interp_lzma.py b/pypy/module/_lzma/interp_lzma.py
--- a/pypy/module/_lzma/interp_lzma.py
+++ b/pypy/module/_lzma/interp_lzma.py
@@ -13,6 +13,7 @@
 
 
 FORMAT_AUTO, FORMAT_XZ, FORMAT_ALONE, FORMAT_RAW = range(4)
+R_LONGLONG_MASK = r_ulonglong(LONGLONG_MASK)
 
 
 eci = ExternalCompilationInfo(
@@ -282,7 +283,7 @@
 W_LZMADecompressor.__init__(self, space, format)
 
 if space.is_none(w_memlimit):
-memlimit = r_ulonglong(LONGLONG_MASK)
+memlimit = R_LONGLONG_MASK
 else:
 memlimit = space.r_ulonglong_w(w_memlimit)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: fix typos

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72631:91450a0f17bc
Date: 2014-07-31 20:58 +0200
http://bitbucket.org/pypy/pypy/changeset/91450a0f17bc/

Log:fix typos

diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst
--- a/pypy/doc/coding-guide.rst
+++ b/pypy/doc/coding-guide.rst
@@ -443,7 +443,7 @@
 
 Adding an entry under pypy/module (e.g. mymodule) entails automatic
 creation of a new config option (such as --withmod-mymodule and
---withoutmod-mymodule (the later being the default)) for py.py and
+--withoutmod-mymodule (the latter being the default)) for py.py and
 translate.py.
 
 
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -325,7 +325,7 @@
 * directly calling the internal magic methods of a few built-in types
   with invalid arguments may have a slightly different result.  For
   example, ``[].__add__(None)`` and ``(2).__add__(None)`` both return
-  ``NotImplemented`` on PyPy; on CPython, only the later does, and the
+  ``NotImplemented`` on PyPy; on CPython, only the latter does, and the
   former raises ``TypeError``.  (Of course, ``[]+None`` and ``2+None``
   both raise ``TypeError`` everywhere.)  This difference is an
   implementation detail that shows up because of internal C-level slots
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy improve-docs-fixes: fix typo

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: improve-docs-fixes
Changeset: r72632:98cb8999d9f7
Date: 2014-07-31 21:18 +0200
http://bitbucket.org/pypy/pypy/changeset/98cb8999d9f7/

Log:fix typo

diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst
--- a/pypy/doc/coding-guide.rst
+++ b/pypy/doc/coding-guide.rst
@@ -640,7 +640,7 @@
 assert self.result == 2 ** 6
 
 which executes the code string function with the given arguments at app level.
-Note the use of ``w_result`` in ``setup_class`` but self.result in the test 
+Note the use of ``w_result`` in ``setup_class`` but self.result in the test.
 Here is how to define an app level class  in ``setup_class`` that can be used
 in subsequent tests::
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: omit sorting the items in dir/type/module __dir__, like cpython does

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72646:743d934f01f7
Date: 2014-08-01 21:16 +0200
http://bitbucket.org/pypy/pypy/changeset/743d934f01f7/

Log:omit sorting the items in dir/type/module __dir__, like cpython does

diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -129,7 +129,6 @@
 w__dict__ = space.getattr(self, space.wrap('__dict__'))
 result = space.listview(w__dict__)
 w_result = space.wrap(result)
-space.call_method(w_result, 'sort')
 return w_result
 except OperationError as e:
 if e.match(space, space.w_AttributeError):
diff --git a/pypy/interpreter/test/test_module.py 
b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -71,8 +71,7 @@
 def test_dir(self):
 import sys
 items = sys.__dir__()
-assert items == sorted(items)
-assert items == dir(sys)
+assert sorted(items) == dir(sys)
 
 def test_package(self):
 import sys
diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py
--- a/pypy/objspace/std/objecttype.py
+++ b/pypy/objspace/std/objecttype.py
@@ -49,7 +49,6 @@
 except AttributeError:
 pass
 result = list(Dict.keys())
-result.sort()
 return result
 )
 return w_result
diff --git a/pypy/objspace/std/test/test_obj.py 
b/pypy/objspace/std/test/test_obj.py
--- a/pypy/objspace/std/test/test_obj.py
+++ b/pypy/objspace/std/test/test_obj.py
@@ -113,7 +113,7 @@
 obj = A()
 obj_items = dir(obj)
 assert obj_items == sorted(obj_items)
-assert obj_items == dir(obj)
+assert obj_items == sorted(object.__dir__(obj))
 
 
 def test_is_on_primitives(self):
diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -728,7 +728,6 @@
 pass
 
 C_items = dir(C)
-assert C_items == sorted(C_items)
 assert C_items != C.__dir__(C)  # as in cpython
 
 assert 'a_var' in C_items
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -750,7 +750,6 @@
 return Dict
 
 result = list(_classdir(obj).keys())
-result.sort()
 return result
 )
 return w_result
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: prefer use of __mro__ instead of recursing the inheritance hierarchy

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72642:239d45aea639
Date: 2014-07-29 20:58 +0200
http://bitbucket.org/pypy/pypy/changeset/239d45aea639/

Log:prefer use of __mro__ instead of recursing the inheritance hierarchy

diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py
--- a/pypy/objspace/std/objecttype.py
+++ b/pypy/objspace/std/objecttype.py
@@ -27,16 +27,14 @@
 Dict.update(klass.__dict__)
 except AttributeError: pass
 try:
-# XXX - Use of .__mro__ would be suggested, if the existance
-#   of that attribute could be guarranted.
-bases = klass.__bases__
+bases = klass.__mro__
 except AttributeError: pass
 else:
 try:
 #Note that since we are only interested in the keys,
 #  the order we merge classes is unimportant
 for base in bases:
-Dict.update(_classdir(base))
+Dict.update(base.__dict__)
 except TypeError: pass
 return Dict
 
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -738,16 +738,14 @@
 Dict.update(klass.__dict__)
 except AttributeError: pass
 try:
-# XXX - Use of .__mro__ would be suggested, if the existance
-#   of that attribute could be guarranted.
-bases = klass.__bases__
+bases = klass.__mro__
 except AttributeError: pass
 else:
 try:
 #Note that since we are only interested in the keys,
 #  the order we merge classes is unimportant
 for base in bases:
-Dict.update(_classdir(base))
+Dict.update(base.__dict__)
 except TypeError: pass
 return Dict
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Merged pypy/pypy/py3.3 into py3.3

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72643:61ea6233fd47
Date: 2014-07-30 21:05 +0200
http://bitbucket.org/pypy/pypy/changeset/61ea6233fd47/

Log:Merged pypy/pypy/py3.3 into py3.3

diff --git a/lib-python/3/test/test_builtin.py 
b/lib-python/3/test/test_builtin.py
--- a/lib-python/3/test/test_builtin.py
+++ b/lib-python/3/test/test_builtin.py
@@ -15,7 +15,8 @@
 import unittest
 import warnings
 from operator import neg
-from test.support import TESTFN, unlink,  run_unittest, check_warnings
+from test.support import (
+TESTFN, unlink,  run_unittest, check_warnings, check_impl_detail)
 try:
 import pty, signal
 except ImportError:
@@ -423,7 +424,9 @@
 try:
 raise IndexError
 except:
-self.assertEqual(len(dir(sys.exc_info()[2])), 4)
+methods = [meth for meth in dir(sys.exc_info()[2])
+   if not meth.startswith('_')]
+self.assertEqual(len(methods), 4)
 
 # test that object has a __dir__()
 self.assertEqual(sorted([].__dir__()), dir([]))
@@ -558,18 +561,21 @@
 self.assertEqual((g, l), ({'a': 1}, {'b': 2}))
 
 def test_exec_globals(self):
-code = compile(print('Hello World!'), , exec)
-# no builtin function
-self.assertRaisesRegex(NameError, name 'print' is not defined,
-   exec, code, {'__builtins__': {}})
-# __builtins__ must be a mapping type
-self.assertRaises(TypeError,
-  exec, code, {'__builtins__': 123})
+if check_impl_detail():
+# strict __builtins__ compliance (CPython)
+code = compile(print('Hello World!'), , exec)
+# no builtin function
+self.assertRaisesRegex(NameError, name 'print' is not defined,
+   exec, code, {'__builtins__': {}})
+# __builtins__ must be a mapping type
+self.assertRaises(TypeError,
+  exec, code, {'__builtins__': 123})
 
-# no __build_class__ function
-code = compile(class A: pass, , exec)
-self.assertRaisesRegex(NameError, __build_class__ not found,
-   exec, code, {'__builtins__': {}})
+# no __build_class__ function
+code = compile(class A: pass, , exec)
+if True:
+self.assertRaisesRegex(NameError, __build_class__ not found,
+   exec, code, {'__builtins__': {}})
 
 class frozendict_error(Exception):
 pass
@@ -579,7 +585,7 @@
 raise frozendict_error(frozendict is readonly)
 
 # read-only builtins
-frozen_builtins = frozendict(__builtins__)
+frozen_builtins = frozendict(builtins.__dict__)
 code = compile(__builtins__['superglobal']=2; print(superglobal), 
test, exec)
 self.assertRaises(frozendict_error,
   exec, code, {'__builtins__': frozen_builtins})
diff --git a/lib-python/3/test/test_concurrent_futures.py 
b/lib-python/3/test/test_concurrent_futures.py
--- a/lib-python/3/test/test_concurrent_futures.py
+++ b/lib-python/3/test/test_concurrent_futures.py
@@ -295,14 +295,19 @@
 event = threading.Event()
 def future_func():
 event.wait()
-oldswitchinterval = sys.getswitchinterval()
-sys.setswitchinterval(1e-6)
+newgil = hasattr(sys, 'getswitchinterval')
+if newgil:
+geti, seti = sys.getswitchinterval, sys.setswitchinterval
+else:
+geti, seti = sys.getcheckinterval, sys.setcheckinterval
+oldinterval = geti()
+seti(1e-6 if newgil else 1)
 try:
 fs = {self.executor.submit(future_func) for i in range(100)}
 event.set()
 futures.wait(fs, return_when=futures.ALL_COMPLETED)
 finally:
-sys.setswitchinterval(oldswitchinterval)
+seti(oldinterval)
 
 
 class ProcessPoolWaitTests(ProcessPoolMixin, WaitTests, unittest.TestCase):
diff --git a/lib-python/3/test/test_imp.py b/lib-python/3/test/test_imp.py
--- a/lib-python/3/test/test_imp.py
+++ b/lib-python/3/test/test_imp.py
@@ -317,7 +317,6 @@
 
 @unittest.skipUnless(sys.implementation.cache_tag is not None,
  'requires sys.implementation.cache_tag not be None')
-@support.impl_detail(PyPy ignores the optimize flag, pypy=False)
 def test_cache_from_source(self):
 # Given the path to a .py file, return the path to its PEP 3147
 # defined .pyc file (i.e. under __pycache__).
@@ -339,7 +338,6 @@
   'file{}.pyc'.format(self.tag))
 self.assertEqual(imp.cache_from_source(path, True), expect)
 
-@support.impl_detail(PyPy ignores the optimize flag, pypy=False)
 def test_cache_from_source_optimized(self):
 # Given the path to a .py file, return the path 

[pypy-commit] pypy py3.3: use space.call_method over w_result.sort

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72644:2c73a529647b
Date: 2014-07-31 18:35 +0200
http://bitbucket.org/pypy/pypy/changeset/2c73a529647b/

Log:use space.call_method over w_result.sort

diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -129,7 +129,7 @@
 w__dict__ = space.getattr(self, space.wrap('__dict__'))
 result = space.listview(w__dict__)
 w_result = space.wrap(result)
-w_result.sort(False)
+space.call_method(w_result, 'sort')
 return w_result
 except OperationError as e:
 if e.match(space, space.w_AttributeError):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: merging

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72645:7a470162ff0e
Date: 2014-07-31 19:13 +0200
http://bitbucket.org/pypy/pypy/changeset/7a470162ff0e/

Log:merging

diff --git a/pypy/interpreter/astcompiler/validate.py 
b/pypy/interpreter/astcompiler/validate.py
--- a/pypy/interpreter/astcompiler/validate.py
+++ b/pypy/interpreter/astcompiler/validate.py
@@ -11,7 +11,8 @@
 
 
 class ValidationError(Exception):
-Signals an invalid AST
+def __init__(self, message):
+self.message = message
 
 
 def expr_context_name(ctx):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: merging

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72647:80b1862342a0
Date: 2014-08-01 21:17 +0200
http://bitbucket.org/pypy/pypy/changeset/80b1862342a0/

Log:merging

diff --git a/pypy/interpreter/astcompiler/validate.py 
b/pypy/interpreter/astcompiler/validate.py
--- a/pypy/interpreter/astcompiler/validate.py
+++ b/pypy/interpreter/astcompiler/validate.py
@@ -11,7 +11,8 @@
 
 
 class ValidationError(Exception):
-Signals an invalid AST
+def __init__(self, message):
+self.message = message
 
 
 def expr_context_name(ctx):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: factor dir() built-in out into object, type and module methods

2014-08-01 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72641:2bdf0e894a85
Date: 2014-07-29 19:44 +0200
http://bitbucket.org/pypy/pypy/changeset/2bdf0e894a85/

Log:factor dir() built-in out into object, type and module methods

This happened in bugs.python.org/issue12166

diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -123,3 +123,15 @@
 except OperationError:
 __file__ = u'?'
 return space.wrap(umodule %s from %s % (name, __file__))
+
+def descr_module__dir__(self, space):
+try:
+w__dict__ = space.getattr(self, space.wrap('__dict__'))
+result = space.listview(w__dict__)
+w_result = space.wrap(result)
+w_result.sort(False)
+return w_result
+except OperationError as e:
+if e.match(space, space.w_AttributeError):
+return space.wrap([])
+raise
diff --git a/pypy/interpreter/test/test_module.py 
b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -68,6 +68,12 @@
 m = type(_pypy_interact).__new__(type(_pypy_interact))
 assert repr(m).startswith(module '?')
 
+def test_dir(self):
+import sys
+items = sys.__dir__()
+assert items == sorted(items)
+assert items == dir(sys)
+
 def test_package(self):
 import sys
 import os
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -779,6 +779,7 @@
 __new__ = interp2app(Module.descr_module__new__.im_func),
 __init__ = interp2app(Module.descr_module__init__),
 __repr__ = interp2app(Module.descr_module__repr__),
+__dir__ = interp2app(Module.descr_module__dir__),
 __reduce__ = interp2app(Module.descr__reduce__),
 __dict__ = GetSetProperty(descr_get_dict, cls=Module), # module 
dictionaries are readonly attributes
 __doc__ = 'module(name[, doc])\n\nCreate a module object.\nThe name must 
be a string; the optional doc argument can have any type.'
diff --git a/pypy/module/__builtin__/app_inspect.py 
b/pypy/module/__builtin__/app_inspect.py
--- a/pypy/module/__builtin__/app_inspect.py
+++ b/pypy/module/__builtin__/app_inspect.py
@@ -45,8 +45,6 @@
 local_names.sort()
 return local_names
 
-import types
-
 obj = args[0]
 
 dir_meth = lookup_special(obj, __dir__)
@@ -56,58 +54,5 @@
 result = list(result)  # Will throw TypeError if not iterable
 result.sort()
 return result
-elif isinstance(obj, types.ModuleType):
-try:
-result = list(obj.__dict__)
-result.sort()
-return result
-except AttributeError:
-return []
 
-elif isinstance(obj, type):
-#Don't look at __class__, as metaclass methods would be confusing.
-result = list(_classdir(obj).keys())
-result.sort()
-return result
-
-else: #(regular item)
-Dict = {}
-try:
-if isinstance(obj.__dict__, dict):
-Dict.update(obj.__dict__)
-except AttributeError:
-pass
-try:
-Dict.update(_classdir(obj.__class__))
-except AttributeError:
-pass
-result = list(Dict.keys())
-result.sort()
-return result
-
-def _classdir(klass):
-Return a dict of the accessible attributes of class/type klass.
-
-This includes all attributes of klass and all of the
-base classes recursively.
-
-The values of this dict have no meaning - only the keys have
-meaning.  
-
-Dict = {}
-try:
-Dict.update(klass.__dict__)
-except AttributeError: pass 
-try:
-# XXX - Use of .__mro__ would be suggested, if the existance
-#   of that attribute could be guarranted.
-bases = klass.__bases__
-except AttributeError: pass
-else:
-try:
-#Note that since we are only interested in the keys,
-#  the order we merge classes is unimportant
-for base in bases:
-Dict.update(_classdir(base))
-except TypeError: pass
-return Dict
+return []  # we should never reach here since object.__dir__ exists
diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py
--- a/pypy/objspace/std/objecttype.py
+++ b/pypy/objspace/std/objecttype.py
@@ -19,6 +19,43 @@
 classname = u'%s.%s' % (modulename, classname)
 return w_obj.getrepr(space, u'%s object' % (classname,))
 
+def descr__dir__(space, w_obj):
+w_result = space.appexec([w_obj], (obj):
+def _classdir(klass):
+Dict = {}
+try:
+Dict.update(klass.__dict__)
+except AttributeError: pass
+   

[pypy-commit] pypy default-trivial-fixes: fix typo

2014-07-31 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: default-trivial-fixes
Changeset: r72619:c83a966e0c06
Date: 2014-07-30 22:07 +0200
http://bitbucket.org/pypy/pypy/changeset/c83a966e0c06/

Log:fix typo

diff --git a/pypy/interpreter/pycompiler.py b/pypy/interpreter/pycompiler.py
--- a/pypy/interpreter/pycompiler.py
+++ b/pypy/interpreter/pycompiler.py
@@ -96,7 +96,7 @@
 
 XXX: This class should override the baseclass implementation of
  compile_command() in order to optimize it, especially in case
- of incomplete inputs (e.g. we shouldn't re-compile from sracth
+ of incomplete inputs (e.g. we shouldn't re-compile from scratch
  the whole source after having only added a new '\n')
 
 def __init__(self, space, override_version=None):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3-fixes: use helper function to locate the code object

2014-07-31 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3-fixes
Changeset: r72629:4f709511ed94
Date: 2014-07-31 21:40 +0200
http://bitbucket.org/pypy/pypy/changeset/4f709511ed94/

Log:use helper function to locate the code object

diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -718,15 +718,20 @@
 from pypy.interpreter.pycode import cpython_code_signature
 from pypy.interpreter.signature import Signature
 
+def find_func(code):
+for w_const in code.co_consts_w:
+if isinstance(w_const, PyCode):
+return w_const
+
 snippet = 'def f(a, b, m=1, n=2, **kwargs): pass'
 containing_co = self.compiler.compile(snippet, 'string', 'single', 0)
-co = containing_co.co_consts_w[2]
+co = find_func(containing_co)
 sig = cpython_code_signature(co)
 assert sig == Signature(['a', 'b', 'm', 'n'], None, 'kwargs', [])
 
 snippet = 'def f(a, b, *, m=1, n=2, **kwargs): pass'
 containing_co = self.compiler.compile(snippet, 'string', 'single', 0)
-co = containing_co.co_consts_w[4]
+co = find_func(containing_co)
 sig = cpython_code_signature(co)
 assert sig == Signature(['a', 'b'], None, 'kwargs', ['m', 'n'])
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: add _csv test_quotechar

2014-07-27 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72551:d43ba084a258
Date: 2014-07-27 10:20 +0200
http://bitbucket.org/pypy/pypy/changeset/d43ba084a258/

Log:add _csv test_quotechar

diff --git a/pypy/module/_csv/test/test_dialect.py 
b/pypy/module/_csv/test/test_dialect.py
--- a/pypy/module/_csv/test/test_dialect.py
+++ b/pypy/module/_csv/test/test_dialect.py
@@ -80,6 +80,12 @@
 _csv.register_dialect('foo1', strict=_csv)# :-/
 assert _csv.get_dialect('foo1').strict == True
 
+def test_quotechar(self):
+import _csv
+
+exc_info = raises(TypeError, _csv.register_dialect, 'foo1', 
quotechar=4)
+assert exc_info.value.args[0] == 'quotechar must be string, not int'
+
 def test_delimiter(self):
 import _csv
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: add _csv test_delimiter test and replicate cpython error handling

2014-07-27 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72550:44f52293da32
Date: 2014-07-27 10:15 +0200
http://bitbucket.org/pypy/pypy/changeset/44f52293da32/

Log:add _csv test_delimiter test and replicate cpython error handling

diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py
--- a/pypy/module/_csv/interp_csv.py
+++ b/pypy/module/_csv/interp_csv.py
@@ -49,6 +49,8 @@
 return default
 if space.is_w(w_src, space.w_None):
 return u'\0'
+if not space.isinstance_w(w_src, space.w_unicode):
+raise oefmt(space.w_TypeError, '%s must be string, not %T', name, 
w_src)
 src = space.unicode_w(w_src)
 if len(src) == 1:
 return src[0]
@@ -109,7 +111,7 @@
 
 if dialect.delimiter == u'\0':
 raise OperationError(space.w_TypeError,
- space.wrap('delimiter must be set'))
+ space.wrap('delimiter must be a 1-character 
string'))
 
 if space.is_w(w_quotechar, space.w_None) and w_quoting is None:
 tmp_quoting = QUOTE_NONE
diff --git a/pypy/module/_csv/test/test_dialect.py 
b/pypy/module/_csv/test/test_dialect.py
--- a/pypy/module/_csv/test/test_dialect.py
+++ b/pypy/module/_csv/test/test_dialect.py
@@ -80,6 +80,21 @@
 _csv.register_dialect('foo1', strict=_csv)# :-/
 assert _csv.get_dialect('foo1').strict == True
 
+def test_delimiter(self):
+import _csv
+
+exc_info = raises(TypeError, _csv.register_dialect, 'foo1', 
delimiter=:::)
+assert exc_info.value.args[0] == 'delimiter must be a 1-character 
string'
+
+exc_info = raises(TypeError, _csv.register_dialect, 'foo1', 
delimiter=)
+assert exc_info.value.args[0] == 'delimiter must be a 1-character 
string'
+
+exc_info = raises(TypeError, _csv.register_dialect, 'foo1', 
delimiter=b,)
+assert exc_info.value.args[0] == 'delimiter must be string, not 
bytes'
+
+exc_info = raises(TypeError, _csv.register_dialect, 'foo1', 
delimiter=4)
+assert exc_info.value.args[0] == 'delimiter must be string, not int'
+
 def test_line_terminator(self):
 # lineterminator can be the empty string
 import _csv
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: add custom __repr__ to Cell

2014-07-27 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72556:c799b96b7ec5
Date: 2014-07-27 11:45 +0200
http://bitbucket.org/pypy/pypy/changeset/c799b96b7ec5/

Log:add custom __repr__ to Cell

diff --git a/pypy/interpreter/nestedscope.py b/pypy/interpreter/nestedscope.py
--- a/pypy/interpreter/nestedscope.py
+++ b/pypy/interpreter/nestedscope.py
@@ -71,6 +71,14 @@
 return %s(%s) at 0x%x % (self.__class__.__name__,
  content, uid(self))
 
+def descr__repr__(self, space):
+if self.w_value is None:
+content = empty
+else:
+content = %s object at 0x%x % (space.type(self.w_value).name, 
uid(self.w_value))
+s = cell at 0x%x: %s % (uid(self), content)
+return space.wrap(s.decode('utf-8'))
+
 def descr__cell_contents(self, space):
 try:
 return self.get()
diff --git a/pypy/interpreter/test/test_nestedscope.py 
b/pypy/interpreter/test/test_nestedscope.py
--- a/pypy/interpreter/test/test_nestedscope.py
+++ b/pypy/interpreter/test/test_nestedscope.py
@@ -59,6 +59,28 @@
 def test_lambda_in_genexpr(self):
 assert [x() for x in (lambda: x for x in range(10))] == list(range(10))
 
+def test_cell_repr(self):
+import re
+from reprlib import repr as r # Don't shadow builtin repr
+
+def get_cell():
+x = 42
+def inner():
+return x
+return inner
+x = get_cell().__closure__[0]
+assert re.match(r'cell at 0x[0-9A-Fa-f]+: int object at 
0x[0-9A-Fa-f]+', repr(x))
+assert re.match(r'cell at 0x.*\.\.\..*', r(x))
+
+def get_cell():
+if False:
+x = 42
+def inner():
+return x
+return inner
+x = get_cell().__closure__[0]
+assert re.match(r'cell at 0x[0-9A-Fa-f]+: empty', repr(x))
+
 def test_cell_contents(self):
 def f(x):
 def f(y):
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -944,6 +944,7 @@
 __eq__   = interp2app(Cell.descr__eq__),
 __hash__ = None,
 __reduce__   = interp2app(Cell.descr__reduce__),
+__repr__ = interp2app(Cell.descr__repr__),
 __setstate__ = interp2app(Cell.descr__setstate__),
 cell_contents= GetSetProperty(Cell.descr__cell_contents, cls=Cell),
 )
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: fix repr test_descriptors to accept pypy repr for dict.items

2014-07-27 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72555:c0bb7244f113
Date: 2014-07-27 11:08 +0200
http://bitbucket.org/pypy/pypy/changeset/c0bb7244f113/

Log:fix repr test_descriptors to accept pypy repr for dict.items

diff --git a/lib-python/3/test/test_reprlib.py 
b/lib-python/3/test/test_reprlib.py
--- a/lib-python/3/test/test_reprlib.py
+++ b/lib-python/3/test/test_reprlib.py
@@ -182,9 +182,13 @@
 self.assertRegex(r(x), r'cell at 0x.*\.\.\..*')
 
 def test_descriptors(self):
-eq = self.assertEqual
 # method descriptors
-eq(repr(dict.items), method 'items' of 'dict' objects)
+self.assertTrue(any((
+# cpython
+repr(dict.items) == method 'items' of 'dict' objects,
+# pypy
+repr(dict.items).startswith(function items at 0x),
+)))
 # XXX member descriptors
 # XXX attribute descriptors
 # XXX slot descriptors
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: fix repr test_builtin_function to accept pypy repr for string split method

2014-07-27 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72554:f1c6ae47c0d4
Date: 2014-07-27 11:03 +0200
http://bitbucket.org/pypy/pypy/changeset/f1c6ae47c0d4/

Log:fix repr test_builtin_function to accept pypy repr for string split
method

diff --git a/lib-python/3/test/test_reprlib.py 
b/lib-python/3/test/test_reprlib.py
--- a/lib-python/3/test/test_reprlib.py
+++ b/lib-python/3/test/test_reprlib.py
@@ -140,8 +140,12 @@
 # Functions
 eq(repr(hash), 'built-in function hash')
 # Methods
-self.assertTrue(repr(''.split).startswith(
-'built-in method split of str object at 0x'))
+self.assertTrue(any((
+# cpython
+repr(''.split).startswith('built-in method split of str object at 
0x'),
+# pypy
+repr(''.split) == bound method str.split of '',
+)))
 
 def test_range(self):
 eq = self.assertEqual
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: fixing _csv lineterminator exception message

2014-07-26 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72494:cbfe89ead8c2
Date: 2014-07-26 12:12 +0200
http://bitbucket.org/pypy/pypy/changeset/cbfe89ead8c2/

Log:fixing _csv lineterminator exception message

diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py
--- a/pypy/module/_csv/interp_csv.py
+++ b/pypy/module/_csv/interp_csv.py
@@ -34,10 +34,15 @@
 return default
 return space.int_w(w_src)
 
-def _get_str(space, w_src, default):
+def _get_str(space, w_src, default, attrname):
 if w_src is None:
 return default
-return space.unicode_w(w_src)
+try:
+return space.unicode_w(w_src)
+except OperationError as e:
+if e.match(space, space.w_TypeError):
+raise oefmt(space.w_TypeError, '%s must be a string', attrname)
+raise
 
 def _get_char(space, w_src, default, name):
 if w_src is None:
@@ -91,7 +96,7 @@
 dialect.delimiter = _get_char(space, w_delimiter, u',', 'delimiter')
 dialect.doublequote = _get_bool(space, w_doublequote, True)
 dialect.escapechar = _get_char(space, w_escapechar, u'\0', 'escapechar')
-dialect.lineterminator = _get_str(space, w_lineterminator, u'\r\n')
+dialect.lineterminator = _get_str(space, w_lineterminator, u'\r\n', 
'lineterminator')
 dialect.quotechar = _get_char(space, w_quotechar, u'', 'quotechar')
 tmp_quoting = _get_int(space, w_quoting, QUOTE_MINIMAL)
 dialect.skipinitialspace = _get_bool(space, w_skipinitialspace, False)
diff --git a/pypy/module/_csv/test/test_dialect.py 
b/pypy/module/_csv/test/test_dialect.py
--- a/pypy/module/_csv/test/test_dialect.py
+++ b/pypy/module/_csv/test/test_dialect.py
@@ -67,6 +67,9 @@
 kwargs = {name: value}
 raises(TypeError, _csv.register_dialect, 'foo1', **kwargs)
 
+exc_info = raises(TypeError, _csv.register_dialect, 'foo1', 
lineterminator=4)
+assert exc_info.value.args[0] == 'lineterminator must be a string'
+
 def test_bool_arg(self):
 # boolean arguments take *any* object and use its truth-value
 import _csv
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Merged pypy/pypy/py3.3 into py3.3

2014-07-26 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72495:61fd7b56f3ed
Date: 2014-07-26 12:41 +0200
http://bitbucket.org/pypy/pypy/changeset/61fd7b56f3ed/

Log:Merged pypy/pypy/py3.3 into py3.3

diff --git a/pypy/module/__builtin__/app_inspect.py 
b/pypy/module/__builtin__/app_inspect.py
--- a/pypy/module/__builtin__/app_inspect.py
+++ b/pypy/module/__builtin__/app_inspect.py
@@ -53,8 +53,7 @@
 if dir_meth is not None:
 result = dir_meth()
 if not isinstance(result, list):
-raise TypeError(__dir__() must return a list, not %r % (
-type(result),))
+result = list(result)  # Will throw TypeError if not iterable
 result.sort()
 return result
 elif isinstance(obj, types.ModuleType):
diff --git a/pypy/module/__builtin__/functional.py 
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -482,7 +482,7 @@
 def descr_hash(self, space):
 if space.eq_w(self.w_length, space.wrap(0)):
 w_tup = space.newtuple([self.w_length, space.w_None, space.w_None])
-elif space.eq_w(self.w_length, space.wrap(0)):
+elif space.eq_w(self.w_length, space.wrap(1)):
 w_tup = space.newtuple([self.w_length, self.w_start, space.w_None])
 else:
 w_tup = space.newtuple([self.w_length, self.w_start, self.w_step])
diff --git a/pypy/module/__builtin__/test/test_construct_singletons.py 
b/pypy/module/__builtin__/test/test_construct_singletons.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__builtin__/test/test_construct_singletons.py
@@ -0,0 +1,7 @@
+class AppTestConstructSingletons:
+
+def test_construct_singletons(self):
+none_type = type(None)
+assert none_type() is None
+raises(TypeError, none_type, 1, 2)
+raises(TypeError, none_type, a=1, b=2)
diff --git a/pypy/module/__builtin__/test/test_dir.py 
b/pypy/module/__builtin__/test/test_dir.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__builtin__/test/test_dir.py
@@ -0,0 +1,26 @@
+class AppTestDir:
+
+def test_dir_obj__dir__tuple(self):
+If __dir__ method returns a tuple, cpython3 converts it to list.
+class Foo(object):
+def __dir__(self):
+return (b, c, a)
+res = dir(Foo())
+assert isinstance(res, list)
+assert res == [a, b, c]
+
+def test_dir_obj__dir__genexp(self):
+Generator expression is also converted to list by cpython3.
+class Foo(object):
+def __dir__(self):
+return (i for i in [b, c, a])
+res = dir(Foo())
+assert isinstance(res, list)
+assert res == [a, b, c]
+
+def test_dir_obj__dir__noniter(self):
+If result of __dir__ is not iterable, it's an error.
+class Foo(object):
+def __dir__(self):
+return 42
+raises(TypeError, dir, Foo())
diff --git a/pypy/module/__builtin__/test/test_functional.py 
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -484,7 +484,7 @@
 for a in test_ranges:
 for b in test_ranges:
 if a == b:
-assert (hash(a), hash(b))
+assert hash(a) == hash(b)
 
 # Ranges are unequal to other types (even sequence types)
 assert (range(0) == ()) is False
diff --git a/pypy/module/math/__init__.py b/pypy/module/math/__init__.py
--- a/pypy/module/math/__init__.py
+++ b/pypy/module/math/__init__.py
@@ -23,6 +23,7 @@
'frexp'  : 'interp_math.frexp',
'degrees': 'interp_math.degrees',
'log': 'interp_math.log',
+   'log2'   : 'interp_math.log2',
'log10'  : 'interp_math.log10',
'fmod'   : 'interp_math.fmod',
'atan'   : 'interp_math.atan',
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -228,6 +228,11 @@
 return math1(space, math.log, w_base)
 return _log_any(space, w_x, base)
 
+def log2(space, w_x):
+log2(x) - the base 2 logarithm of x.
+
+return _log_any(space, w_x, 2.0)
+
 def log10(space, w_x):
 log10(x) - the base 10 logarithm of x.
 
diff --git a/pypy/module/math/test/test_math.py 
b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -148,6 +148,19 @@
 raises(ValueError, math.log1p, -1)
 raises(ValueError, math.log1p, -100)
 
+def test_log2(self):
+import math
+self.ftest(math.log2(0.125), -3)
+self.ftest(math.log2(0.5), -1)
+self.ftest(math.log2(4), 2)
+
+def test_log10(self):
+import math
+

[pypy-commit] pypy py3.3: patching cpython3 csv test as the exception message has bad grammar

2014-07-26 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72493:c94a608f5616
Date: 2014-07-26 11:11 +0200
http://bitbucket.org/pypy/pypy/changeset/c94a608f5616/

Log:patching cpython3 csv test as the exception message has bad grammar

diff --git a/lib-python/3/test/test_csv.py b/lib-python/3/test/test_csv.py
--- a/lib-python/3/test/test_csv.py
+++ b/lib-python/3/test/test_csv.py
@@ -766,8 +766,9 @@
 mydialect.quotechar = ''
 with self.assertRaises(csv.Error) as cm:
 mydialect()
+# NOTE: Patched exception message since cpython uses bad grammar 
(cpython issue22076)
 self.assertEqual(str(cm.exception),
- 'quotechar must be an 1-character string')
+ 'quotechar must be a 1-character string')
 
 mydialect.quotechar = 4
 with self.assertRaises(csv.Error) as cm:
@@ -789,14 +790,16 @@
 mydialect.delimiter = :::
 with self.assertRaises(csv.Error) as cm:
 mydialect()
+# NOTE: Patched exception message since cpython uses bad grammar 
(cpython issue22076)
 self.assertEqual(str(cm.exception),
- 'delimiter must be an 1-character string')
+ 'delimiter must be a 1-character string')
 
 mydialect.delimiter = 
 with self.assertRaises(csv.Error) as cm:
 mydialect()
+# NOTE: Patched exception message since cpython uses bad grammar 
(cpython issue22076)
 self.assertEqual(str(cm.exception),
- 'delimiter must be an 1-character string')
+ 'delimiter must be a 1-character string')
 
 mydialect.delimiter = b,
 with self.assertRaises(csv.Error) as cm:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Removing sys.flags.division_warning (removed in 3.3)

2014-07-26 Thread numerodix
Author: Martin Matusiak numero...@gmail.com
Branch: py3.3
Changeset: r72506:d4642496139c
Date: 2014-07-26 15:02 +0200
http://bitbucket.org/pypy/pypy/changeset/d4642496139c/

Log:Removing sys.flags.division_warning (removed in 3.3)

diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -317,7 +317,6 @@
 # Order is significant!
 sys_flags = (
 debug,
-division_warning,
 inspect,
 interactive,
 optimize,
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -94,20 +94,19 @@
 name = sys.flags
 
 debug = structseqfield(0)
-division_warning = structseqfield(1)
-inspect = structseqfield(2)
-interactive = structseqfield(3)
-optimize = structseqfield(4)
-dont_write_bytecode = structseqfield(5)
-no_user_site = structseqfield(6)
-no_site = structseqfield(7)
-ignore_environment = structseqfield(8)
-verbose = structseqfield(9)
-bytes_warning = structseqfield(10)
-quiet = structseqfield(11)
-hash_randomization = structseqfield(12)
+inspect = structseqfield(1)
+interactive = structseqfield(2)
+optimize = structseqfield(3)
+dont_write_bytecode = structseqfield(4)
+no_user_site = structseqfield(5)
+no_site = structseqfield(6)
+ignore_environment = structseqfield(7)
+verbose = structseqfield(8)
+bytes_warning = structseqfield(9)
+quiet = structseqfield(10)
+hash_randomization = structseqfield(11)
 
-null_sysflags = sysflags((0,)*13)
+null_sysflags = sysflags((0,)*12)
 null__xoptions = {}
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit