some fixes to support Jython better
--HG-- branch : trunk
This commit is contained in:
parent
3c3002ccd5
commit
29d437489d
|
@ -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 """
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue