From 29d437489d09ebbcc18450e8be35cb290297eca9 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 7 Sep 2009 14:59:26 +0200 Subject: [PATCH] some fixes to support Jython better --HG-- branch : trunk --- py/code/code.py | 22 ++++++++++++---------- py/execnet/gateway.py | 2 ++ testing/code/test_code.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/py/code/code.py b/py/code/code.py index df84621a4..64962a436 100644 --- a/py/code/code.py +++ b/py/code/code.py @@ -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 """ diff --git a/py/execnet/gateway.py b/py/execnet/gateway.py index 3b016df70..ad0c655cc 100644 --- a/py/execnet/gateway.py +++ b/py/execnet/gateway.py @@ -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: diff --git a/testing/code/test_code.py b/testing/code/test_code.py index 0f0e74616..8788862fb 100644 --- a/testing/code/test_code.py +++ b/testing/code/test_code.py @@ -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