Message2452
This is a partial solution to the current inability to
instantiate
a PyFile using a stream and directly using a java PyFile
constructor. It is entirely encapsulated within PyFile
and
does not require any new keyword semantics.
Before patch:
Jython 2.2a2 on java1.4.2_08 (JIT: null)
Type "copyright", "credits" or "license" for more
information.
>>> from java.io import FileInputStream as FIS
>>> from org.python.core import PyFile
>>> PyFile(FIS(r"c:\temp\junk.txt"))
Traceback (innermost last):
File "<console>", line 1, in ?
TypeError: argument 1: expected string, 'javainstance'
object found
After patch:
Jython 2.2a2 on java1.4.2_08 (JIT: null)
Type "copyright", "credits" or "license" for more
information.
>>> from java.io import FileInputStream as FIS
>>> from org.python.core import PyFile
>>> PyFile(FIS(r"c:\temp\junk.txt"))
<file <???>, mode r 1>
Patch addes logic in PyFile's PyNewWrapper.new_impl
that detects if first arg is PyString or String
assuming this cases is
the typical "jython" (name, mode, buffersize) call, and
otherwise assumes it is a java constructor call.
This is only a partial solution because open() still
doesn't work:
>>> file(FIS(r"c:\temp\junk.txt"),"dummy")
<file dummy, mode r 2>
>>> open(FIS(r"c:\temp\junk.txt"),"dummy")
Traceback (innermost last):
File "<console>", line 1, in ?
TypeError: open(): 1st arg can't be coerced to String
even though it's just supposed to be an alias for file().
open() calls PyFile.file_init(). I'm not sure why, so
I figured I'd
post what I had. |
|
Date |
User |
Action |
Args |
2008-02-20 17:18:29 | admin | link | issue1218893 messages |
2008-02-20 17:18:29 | admin | create | |
|