remove so-far superflous _getcode and pickle from builtins, some streamlining

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-09-04 16:32:49 +02:00
parent 99af33b26d
commit 45b98d4915
7 changed files with 11 additions and 23 deletions

View File

@ -152,12 +152,10 @@ initpkg(__name__,
'builtin._isbytes' : ('./builtin/builtin31.py', '_isbytes'), 'builtin._isbytes' : ('./builtin/builtin31.py', '_isbytes'),
'builtin._istext' : ('./builtin/builtin31.py', '_istext'), 'builtin._istext' : ('./builtin/builtin31.py', '_istext'),
'builtin._getimself' : ('./builtin/builtin31.py', '_getimself'), 'builtin._getimself' : ('./builtin/builtin31.py', '_getimself'),
'builtin._getcode' : ('./builtin/builtin31.py', '_getcode'),
'builtin._getfuncdict' : ('./builtin/builtin31.py', '_getfuncdict'), 'builtin._getfuncdict' : ('./builtin/builtin31.py', '_getfuncdict'),
'builtin.builtins' : ('./builtin/builtin31.py', 'builtins'), 'builtin.builtins' : ('./builtin/builtin31.py', 'builtins'),
'builtin.execfile' : ('./builtin/builtin31.py', 'execfile'), 'builtin.execfile' : ('./builtin/builtin31.py', 'execfile'),
'builtin.callable' : ('./builtin/builtin31.py', 'callable'), 'builtin.callable' : ('./builtin/builtin31.py', 'callable'),
'builtin.pickle' : ('./builtin/builtin31.py', 'pickle'),
# gateways into remote contexts # gateways into remote contexts
'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'), 'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'),

View File

@ -1,9 +1,9 @@
import sys import sys
if sys.version_info >= (3, 0): if sys.version_info >= (3, 0):
exec ("print_ = print ; exec_=exec") exec ("print_ = print ; exec_=exec")
import builtins import builtins
import pickle
# some backward compatibility helpers # some backward compatibility helpers
_basestring = str _basestring = str
@ -22,9 +22,6 @@ if sys.version_info >= (3, 0):
def _getimself(function): def _getimself(function):
return getattr(function, '__self__', None) return getattr(function, '__self__', None)
def _getcode(function):
return function.__code__
def _getfuncdict(function): def _getfuncdict(function):
return getattr(function, "__dict__", None) return getattr(function, "__dict__", None)
@ -48,10 +45,7 @@ if sys.version_info >= (3, 0):
return hasattr(obj, "__call__") return hasattr(obj, "__call__")
else: else:
try: import __builtin__ as builtins
import cPickle as pickle
except ImportError:
import pickle
_totext = unicode _totext = unicode
_basestring = basestring _basestring = basestring
execfile = execfile execfile = execfile
@ -64,13 +58,9 @@ else:
def _getimself(function): def _getimself(function):
return getattr(function, 'im_self', None) return getattr(function, 'im_self', None)
def _getcode(function):
return function.func_code
def _getfuncdict(function): def _getfuncdict(function):
return getattr(function, "__dict__", None) return getattr(function, "__dict__", None)
import __builtin__ as builtins
def print_(*args, **kwargs): def print_(*args, **kwargs):
""" minimal backport of py3k print statement. """ """ minimal backport of py3k print statement. """
sep = ' ' sep = ' '

View File

@ -45,8 +45,8 @@ def test_frozenset():
assert len(s) == 1 assert len(s) == 1
def test_sorted(): def test_sorted():
if sys.version_info >= (2,5): if sorted == py.builtin.sorted:
py.test.skip("python 2.5 needs no sorted tests") return # don't test a real builtin
for s in [py.builtin.sorted]: for s in [py.builtin.sorted]:
def test(): def test():
assert s([3, 2, 1]) == [1, 2, 3] assert s([3, 2, 1]) == [1, 2, 3]
@ -98,7 +98,7 @@ def test_execfile(tmpdir):
ns = {"y" : 42} ns = {"y" : 42}
py.builtin.execfile(str(test_file), ns) py.builtin.execfile(str(test_file), ns)
assert ns["x"] == 42 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: class A:
y = 3 y = 3
x = 4 x = 4

View File

@ -136,14 +136,15 @@ newline will be removed from the end of each line. """
""" (deprecated) return object unpickled from self.read() """ """ (deprecated) return object unpickled from self.read() """
f = self.open('rb') f = self.open('rb')
try: try:
return py.error.checked_call(py.builtin.pickle.load, f) return py.error.checked_call(py.std.pickle.load, f)
finally: finally:
f.close() f.close()
def move(self, target): def move(self, target):
""" move this path to target. """ """ move this path to target. """
if target.relto(self): 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: try:
self.rename(target) self.rename(target)
except py.error.EXDEV: # invalid cross-device link except py.error.EXDEV: # invalid cross-device link

View File

@ -355,7 +355,7 @@ class LocalPath(FSBase):
""" pickle object into path location""" """ pickle object into path location"""
f = self.open('wb') f = self.open('wb')
try: try:
py.error.checked_call(py.builtin.pickle.dump, obj, f, bin) py.error.checked_call(py.std.pickle.dump, obj, f, bin)
finally: finally:
f.close() f.close()

View File

@ -98,7 +98,7 @@ class TestLocalPath(common.CommonFSTests):
d = {'answer' : 42} d = {'answer' : 42}
path.dump(d, bin=bin) path.dump(d, bin=bin)
f = path.open('rb+') f = path.open('rb+')
dnew = py.builtin.pickle.load(f) dnew = py.std.pickle.load(f)
assert d == dnew assert d == dnew
finally: finally:
f.close() f.close()

View File

@ -345,8 +345,7 @@ class Function(FunctionMixin, py.test.collect.Item):
def readkeywords(self): def readkeywords(self):
d = super(Function, self).readkeywords() d = super(Function, self).readkeywords()
d.update(getattr(self.obj, '__dict__', d.update(py.builtin._getfuncdict(self.obj))
getattr(self.obj, 'func_dict', {})))
return d return d
def runtest(self): def runtest(self):