|
From: Brad C. <bk...@mu...> - 2001-01-10 15:47:37
|
For some reason the @sig line in the code below doesn't work. The
resulting .java file doesn't have a public Put() method..
I added java.lang to the String type to see if that would fix it.. no go (the
web docs say that all types *except* those in java.lang need to be fully
specified, yet the example on the web page does have java.lang.String
spelled out).
Does anyone have any ideas?
-- Python Code --
# FTPClient
from ftplib import FTP
class FTPClient:
def __init__(self):
pass
def Put(self,host,user,passwd,fileName,filePath):
"@sig public void Put(java.lang.String host, java.lang.String user,
java.lang.String passwd, java.lang.String fileName, java.lang.String
filePath)"
ftp = FTP(host,user,passwd)
file = open(filePath,"rb");
ftp.storbinary("stor "+fileName,file,512)
ftp.quit()
--- Resulting Java Class
package tinitools;
import org.python.core.*;
public class FTPClient extends java.lang.Object {
static String[] jpy$properties = new String[] {"python.modules.builtin", "exceptions:org.python.core.exceptions", "python.options.showJavaExceptions", "true"};
static String[] jpy$packages = new String[] {"org.python.core", null, "java.lang", null, "java.io", null, "java.net", null};
public static class _PyInner extends PyFunctionTable implements PyRunnable {
private static PyObject s$0;
private static PyObject s$1;
private static PyObject s$2;
private static PyObject s$3;
private static PyObject i$4;
private static PyFunctionTable funcTable;
private static PyCode c$0___init__;
private static PyCode c$1_Put;
private static PyCode c$2_FTPClient;
private static PyCode c$3_main;
private static void initConstants() {
s$0 = Py.newString("E:\\prj\\src\\jbuilder\\tini\\python\\FTPClient.py");
s$1 = Py.newString("@sig public void Put(java.lang.String host, java.lang.String user, java.lang.String passwd, java.lang.String fileName, java.lang.String filePath)");
s$2 = Py.newString("rb");
s$3 = Py.newString("stor ");
i$4 = Py.newInteger(512);
funcTable = new _PyInner();
c$0___init__ = Py.newCode(1, new String[] {"self"}, "E:\\prj\\src\\jbuilder\\tini\\python\\FTPClient.py", "__init__", false, false, funcTable, 0);
c$1_Put = Py.newCode(6, new String[] {"self", "host", "user", "passwd", "fileName", "filePath", "ftp", "file"}, "E:\\prj\\src\\jbuilder\\tini\\python\\FTPClient.py", "Put", false, false, funcTable, 1);
c$2_FTPClient = Py.newCode(0, new String[] {"__init__", "Put"}, "E:\\prj\\src\\jbuilder\\tini\\python\\FTPClient.py", "FTPClient", false, false, funcTable, 2);
c$3_main = Py.newCode(0, new String[] {}, "E:\\prj\\src\\jbuilder\\tini\\python\\FTPClient.py", "main", false, false, funcTable, 3);
}
public PyCode getMain() {
if (c$3_main == null) _PyInner.initConstants();
return c$3_main;
}
public PyObject call_function(int index, PyFrame frame) {
switch (index){
case 0:
return _PyInner.__init__$1(frame);
case 1:
return _PyInner.Put$2(frame);
case 2:
return _PyInner.FTPClient$3(frame);
case 3:
return _PyInner.main$4(frame);
default:
return null;
}
}
private static PyObject __init__$1(PyFrame frame) {
// pass
return Py.None;
}
private static PyObject Put$2(PyFrame frame) {
/* @sig public void Put(java.lang.String host, java.lang.String user, java.lang.String passwd, java.lang.String fileName, java.lang.String filePath) */
frame.setlocal(6, frame.getglobal("FTP").__call__(frame.getlocal(1), frame.getlocal(2), frame.getlocal(3)));
frame.setlocal(7, frame.getglobal("open").__call__(frame.getlocal(5), s$2));
frame.getlocal(6).invoke("storbinary", new PyObject[] {s$3._add(frame.getlocal(4)), frame.getlocal(7), i$4});
frame.getlocal(6).invoke("quit");
return Py.None;
}
private static PyObject FTPClient$3(PyFrame frame) {
frame.setlocal("__init__", new PyFunction(frame.f_globals, new PyObject[] {}, c$0___init__));
frame.setlocal("Put", new PyFunction(frame.f_globals, new PyObject[] {}, c$1_Put));
return frame.getf_locals();
}
private static PyObject main$4(PyFrame frame) {
frame.setglobal("__file__", s$0);
org.python.core.imp.importFromAs("ftplib", new String[] {"FTP"}, new String[] {"FTP"}, frame);
frame.setglobal("FTPClient", Py.makeClass("FTPClient", new PyObject[] {}, c$2_FTPClient, null));
return Py.None;
}
}
public static void moduleDictInit(PyObject dict) {
dict.__setitem__("__name__", new PyString("FTPClient"));
Py.runCode(new _PyInner().getMain(), dict, dict);
}
public static void main(String[] args) {
String[] newargs = new String[args.length+1];
newargs[0] = "FTPClient";
System.arraycopy(args, 0, newargs, 1, args.length);
Py.runMain("tinitools.FTPClient$_PyInner", newargs, jpy$packages, jpy$properties, "tinitools", new String[] {"FTPClient", "sre_compile", "javapath", "sre_constants", "sre_parse", "string", "copy_reg", "ftplib", "javaos", "socket", "re", "sre"});
}
}
Brad Clements, bk...@mu... (315)268-1000
http://www.murkworks.com (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
|
|
From: <bc...@wo...> - 2001-01-10 16:26:05
|
[Brad Clements] >For some reason the @sig line in the code below doesn't work. The >resulting .java file doesn't have a public Put() method.. The class *must* inherit from a java class. F.ex from ftplib import FTP import java class FTPClient(java.lang.Object): ... Also, the @sig must be placed on one single line. It was probably just your (or my) mailer that did the line folding. regards, finn |
|
From: Brad C. <bk...@mu...> - 2001-01-10 16:40:54
|
On 10 Jan 2001, at 16:25, Finn Bock wrote: > >For some reason the @sig line in the code below doesn't work. The > >resulting .java file doesn't have a public Put() method.. > > The class *must* inherit from a java class. F.ex > > from ftplib import FTP > import java > > class FTPClient(java.lang.Object): Thanks for the suggestion, but it still doesn't work. Somehow I thought that inheritance from Object was implied for all classes in Jython.. Since all objects are a subclass of Object in Java In any case, changing it to: class FTPClient(java.lang.Object): Still doesn't produce a public Put method. > Also, the @sig must be placed on one single line. It was probably just > your (or my) mailer that did the line folding. Mailer wrapped it, it is all on one line in the .py file. This is very strange because I have another .py module where it does work. Brad Clements, bk...@mu... (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements |
|
From: <bc...@wo...> - 2001-01-10 18:19:45
|
[Finn]
> The class *must* inherit from a java class. F.ex
>
> from ftplib import FTP
> import java
>
> class FTPClient(java.lang.Object):
[Brad]
>Thanks for the suggestion, but it still doesn't work.
>
>Somehow I thought that inheritance from Object was implied for all
>classes in Jython.. Since all objects are a subclass of Object in Java
Using a java base class (like Object) tells the jython compiler to
generate a proxy class. It is this proxy class which should contain your
Put() method. Without a java base class, the python class is only
compiled into series of PyCode objects. These code objects are callable
and usefull from jython, but does not have any representation in java.
>In any case, changing it to:
>
>class FTPClient(java.lang.Object):
>
>Still doesn't produce a public Put method.
I assume you also added a "import java" somewhere above. Take a look at
the output from jythonc. If the proxy generation is succesfull, the
output must include:
Creating .java files:
FTPClient extends java.lang.Object
regards,
finn
|
|
From: Brad C. <bk...@mu...> - 2001-01-10 18:45:27
|
Adding Import Java to the .py code fixed it.. duh Thanks --- Brad Clements, bk...@mu... (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements |