diff --git a/py/__init__.py b/py/__init__.py index 05d33f0b0..afd45843f 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -152,12 +152,10 @@ initpkg(__name__, 'builtin._isbytes' : ('./builtin/builtin31.py', '_isbytes'), 'builtin._istext' : ('./builtin/builtin31.py', '_istext'), 'builtin._getimself' : ('./builtin/builtin31.py', '_getimself'), - 'builtin._getcode' : ('./builtin/builtin31.py', '_getcode'), 'builtin._getfuncdict' : ('./builtin/builtin31.py', '_getfuncdict'), 'builtin.builtins' : ('./builtin/builtin31.py', 'builtins'), 'builtin.execfile' : ('./builtin/builtin31.py', 'execfile'), 'builtin.callable' : ('./builtin/builtin31.py', 'callable'), - 'builtin.pickle' : ('./builtin/builtin31.py', 'pickle'), # gateways into remote contexts 'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'), diff --git a/py/builtin/builtin31.py b/py/builtin/builtin31.py index 68af8323a..66ce47d4b 100644 --- a/py/builtin/builtin31.py +++ b/py/builtin/builtin31.py @@ -1,9 +1,9 @@ + import sys if sys.version_info >= (3, 0): exec ("print_ = print ; exec_=exec") import builtins - import pickle # some backward compatibility helpers _basestring = str @@ -22,9 +22,6 @@ if sys.version_info >= (3, 0): def _getimself(function): return getattr(function, '__self__', None) - def _getcode(function): - return function.__code__ - def _getfuncdict(function): return getattr(function, "__dict__", None) @@ -48,10 +45,7 @@ if sys.version_info >= (3, 0): return hasattr(obj, "__call__") else: - try: - import cPickle as pickle - except ImportError: - import pickle + import __builtin__ as builtins _totext = unicode _basestring = basestring execfile = execfile @@ -64,13 +58,9 @@ else: def _getimself(function): return getattr(function, 'im_self', None) - def _getcode(function): - return function.func_code - def _getfuncdict(function): return getattr(function, "__dict__", None) - import __builtin__ as builtins def print_(*args, **kwargs): """ minimal backport of py3k print statement. """ sep = ' ' diff --git a/py/builtin/testing/test_builtin.py b/py/builtin/testing/test_builtin.py index 41152a1b0..ec5cc84cd 100644 --- a/py/builtin/testing/test_builtin.py +++ b/py/builtin/testing/test_builtin.py @@ -45,8 +45,8 @@ def test_frozenset(): assert len(s) == 1 def test_sorted(): - if sys.version_info >= (2,5): - py.test.skip("python 2.5 needs no sorted tests") + if sorted == py.builtin.sorted: + return # don't test a real builtin for s in [py.builtin.sorted]: def test(): assert s([3, 2, 1]) == [1, 2, 3] @@ -98,7 +98,7 @@ def test_execfile(tmpdir): ns = {"y" : 42} py.builtin.execfile(str(test_file), ns) assert ns["x"] == 42 - assert py.builtin._getcode(ns["f"]).co_filename == str(test_file) + assert py.code.getrawcode(ns["f"]).co_filename == str(test_file) class A: y = 3 x = 4 diff --git a/py/path/common.py b/py/path/common.py index 32602e390..d8963f963 100644 --- a/py/path/common.py +++ b/py/path/common.py @@ -136,14 +136,15 @@ newline will be removed from the end of each line. """ """ (deprecated) return object unpickled from self.read() """ f = self.open('rb') try: - return py.error.checked_call(py.builtin.pickle.load, f) + return py.error.checked_call(py.std.pickle.load, f) finally: f.close() def move(self, target): """ move this path to target. """ if target.relto(self): - raise py.error.EINVAL(target, "cannot move path into a subdirectory of itself") + raise py.error.EINVAL(target, + "cannot move path into a subdirectory of itself") try: self.rename(target) except py.error.EXDEV: # invalid cross-device link diff --git a/py/path/local.py b/py/path/local.py index 10def4b9f..5726a66ac 100644 --- a/py/path/local.py +++ b/py/path/local.py @@ -355,7 +355,7 @@ class LocalPath(FSBase): """ pickle object into path location""" f = self.open('wb') try: - py.error.checked_call(py.builtin.pickle.dump, obj, f, bin) + py.error.checked_call(py.std.pickle.dump, obj, f, bin) finally: f.close() diff --git a/py/path/testing/test_local.py b/py/path/testing/test_local.py index a36c8de56..a338a48d3 100644 --- a/py/path/testing/test_local.py +++ b/py/path/testing/test_local.py @@ -98,7 +98,7 @@ class TestLocalPath(common.CommonFSTests): d = {'answer' : 42} path.dump(d, bin=bin) f = path.open('rb+') - dnew = py.builtin.pickle.load(f) + dnew = py.std.pickle.load(f) assert d == dnew finally: f.close() diff --git a/py/test/pycollect.py b/py/test/pycollect.py index a5f8d6498..0da86e374 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -345,8 +345,7 @@ class Function(FunctionMixin, py.test.collect.Item): def readkeywords(self): d = super(Function, self).readkeywords() - d.update(getattr(self.obj, '__dict__', - getattr(self.obj, 'func_dict', {}))) + d.update(py.builtin._getfuncdict(self.obj)) return d def runtest(self):