some fixes to support Jython better

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-09-07 14:59:26 +02:00
parent 3c3002ccd5
commit 29d437489d
3 changed files with 15 additions and 11 deletions

View File

@ -32,7 +32,7 @@ class Code(object):
for name in kwargs:
if name not in names:
raise TypeError("unknown code attribute: %r" %(name, ))
if rec:
if rec and hasattr(self.raw, 'co_consts'): # jython
newconstlist = []
co = self.raw
cotype = type(co)
@ -47,22 +47,24 @@ class Code(object):
arglist = [
kwargs['co_argcount'],
kwargs['co_nlocals'],
kwargs['co_stacksize'],
kwargs['co_flags'],
kwargs['co_code'],
kwargs['co_consts'],
kwargs['co_names'],
kwargs.get('co_stacksize', 0), # jython
kwargs.get('co_flags', 0), # jython
kwargs.get('co_code', ''), # jython
kwargs.get('co_consts', ()), # jython
kwargs.get('co_names', []), #
kwargs['co_varnames'],
kwargs['co_filename'],
kwargs['co_name'],
kwargs['co_firstlineno'],
kwargs['co_lnotab'],
kwargs['co_freevars'],
kwargs['co_cellvars'],
kwargs.get('co_lnotab', ''), #jython
kwargs.get('co_freevars', None), #jython
kwargs.get('co_cellvars', None), # jython
]
if sys.version_info >= (3,0):
arglist.insert(1, kwargs['co_kwonlyargcount'])
return self.raw.__class__(*arglist)
return self.raw.__class__(*arglist)
else:
return py.std.new.code(*arglist)
def path(self):
""" return a py.path.local object pointing to the source code """

View File

@ -327,6 +327,8 @@ def stdouterrin_setnull():
# blocks there, while it works (sending to stderr if possible else
# ignoring) on *nix
import sys, os
if not hasattr(os, 'dup'): # jython
return
try:
devnull = os.devnull
except AttributeError:

View File

@ -53,7 +53,7 @@ def test_newcode_with_filename():
filename = MyStr("hello")
filename.__source__ = py.code.Source(source)
newco = code.new(rec=True, co_filename=filename)
assert newco.co_filename is filename
assert newco.co_filename.__source__ == filename.__source__
s = py.code.Source(newco)
assert str(s) == source