Issue1218893

classification
Title: PyFile new_impl workaround
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: bzimmer Nosy List: bzimmer, cupdike
Priority: normal Keywords: patch

Created on 2005-06-11.19:56:14 by cupdike, last changed 2005-06-11.19:56:14 by cupdike.

Files
File name Uploaded Description Edit Remove
PyFile_patch.txt cupdike, 2005-06-11.19:56:14 Change to PyFile's PyNewWrapper.new_impl
Messages
msg2452 (view) Author: Clark Updike (cupdike) Date: 2005-06-11.19:56:14
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.  
History
Date User Action Args
2005-06-11 19:56:14cupdikecreate