marcel liker | 1 Dec 20:57
Picon
Favicon

jython's convenience java methods

Hi there,
I ran into an issue with Jython's "convenience" java methods. Consider this example:

[mliker <at> jbox1 ~]$ ./rlwrap jython/jython
Jython 2.2.1 on java1.4.2_08
Type "copyright", "credits" or "license" for more information.

>>> from weblogic.jndi import Environment
>>> server, user, password = 'server', 'user', 'password'
>>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user,
securityCredentials = password)
>>> env.getInitialContext().lookup("javax.jms.QueueConnectionFactory")
weblogic.jms.client.JMSXAConnectionFactory <at> 1d226a7

however:

[mliker <at> box1 ~]$ ./rlwrap jython/jython

Jython 2.2.1 on java1.4.2_08

Type "copyright", "credits" or "license" for more information.

>>> from weblogic.jndi import Environment
>>> server, user, password = 'server', 'user', 'password'

>>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user,
securityCredentials = password)
>>> env.initialContext.lookup("javax.jms.QueueConnectionFactory") 
Traceback (innermost last):
  File "<console>", line 1, in ?
(Continue reading)

Charlie Groves | 1 Dec 22:06
Picon
Gravatar

Re: jython's convenience java methods

On Dec 1, 2007 11:57 AM, marcel liker <m_liker <at> yahoo.com> wrote:
> Hi there,
> I ran into an issue with Jython's "convenience" java methods. Consider this example:
>
> [mliker <at> jbox1 ~]$ ./rlwrap jython/jython
> Jython 2.2.1 on java1.4.2_08
> Type "copyright", "credits" or "license" for more information.
>
> >>> from weblogic.jndi import Environment
> >>> server, user, password = 'server', 'user', 'password'
> >>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user,
securityCredentials = password)
> >>> env.getInitialContext().lookup("javax.jms.QueueConnectionFactory")
> weblogic.jms.client.JMSXAConnectionFactory <at> 1d226a7
>
> however:
>
> [mliker <at> box1 ~]$ ./rlwrap jython/jython
>
> Jython 2.2.1 on java1.4.2_08
>
> Type "copyright", "credits" or "license" for more information.
>
> >>> from weblogic.jndi import Environment
> >>> server, user, password = 'server', 'user', 'password'
>
> >>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user,
securityCredentials = password)
> >>> env.initialContext.lookup("javax.jms.QueueConnectionFactory")
> Traceback (innermost last):
(Continue reading)

marcel liker | 1 Dec 22:37
Picon
Favicon

Re: jython's convenience java methods

----- Original Message ----
From: Charlie Groves <charlie.groves <at> gmail.com>
To: marcel liker <m_liker <at> yahoo.com>
Cc: jython-users <at> lists.sourceforge.net
Sent: Saturday, December 1, 2007 4:06:44 PM
Subject: Re: [Jython-users] jython's convenience java methods

On Dec 1, 2007 11:57 AM, marcel liker <m_liker <at> yahoo.com> wrote:
> Hi there,
> I ran into an issue with Jython's "convenience" java methods.
 Consider this example:
>
> [mliker <at> jbox1 ~]$ ./rlwrap jython/jython
> Jython 2.2.1 on java1.4.2_08
> Type "copyright", "credits" or "license" for more information.
>
> >>> from weblogic.jndi import Environment
> >>> server, user, password = 'server', 'user', 'password'
> >>> env = Environment(providerUrl = 't3://' + server + ':80',
 securityPrincipal = user, securityCredentials = password)
> >>>
 env.getInitialContext().lookup("javax.jms.QueueConnectionFactory")
> weblogic.jms.client.JMSXAConnectionFactory <at> 1d226a7
>
> however:
>
> [mliker <at> box1 ~]$ ./rlwrap jython/jython
>
> Jython 2.2.1 on java1.4.2_08
>
(Continue reading)

Joseph Montanez | 2 Dec 05:47
Gravatar

Exec Cache-able?

I  am using Jython's Embeded method to pass an extended PyObject to jython scripts for them to modify. But I was wonder if there is a way to cache .exex() calls as I have jython scripts that never change and constantly calling exec on them is a bit of an overkill.
Jython Example (150~ fps):
co = GameLogic.getCurrentController()
own = co.getOwner()
rot = own.getRotation()
rot[1] += 0.5
own.setRotation(rot)

Java example (400 ~ fps):
BasicObject co = GameLogic.getCurrentController ();
BasicObject own = co.getOwner();
float[] rot = own.getRotation();
rot[1] += 0.5f;
own.setRotation(rot);

Java is 2.66x (266%) faster then Jython, which really is darn good as I was expection slower 5x-10x.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Charlie Groves | 2 Dec 20:41
Picon
Gravatar

Re: Exec Cache-able?

On Dec 1, 2007 8:47 PM, Joseph Montanez <jmontanez <at> gorilla3d.com> wrote:
> I  am using Jython's Embeded method to pass an extended PyObject to jython
> scripts for them to modify. But I was wonder if there is a way to cache
> .exex() calls as I have jython scripts that never change and constantly
> calling exec on them is a bit of an overkill.

You can compile source to a code object, and then pass that to exec to
be run.  This is what PythonInterpreter.exec does except that it
compiles it every time.  Just call Py.compile_flags(yourCodeString,
"<string>", "exec", null).  The final null variable is a CompilerFlags
object.  If allows you to control the features from __future__ you can
use.  If you're just running vanilla Jython code, it can be null.  If
you want to use generators or future division, you'll have to
instantiate a CompilerFlags and set it up.  Pass the PyObject from
compile_flags to PythonInterpreter.exec and it'll run it in that
interpreter's namespace.

Charlie

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
rachmat | 3 Dec 09:53
Picon

jython jsp

i do learn my skill about jython and jsp, can u give me example about
jython jsp ?
 thanks for attention

rachmat

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
Simon Brunning | 3 Dec 15:05
Gravatar

Re: jython jsp

On Dec 3, 2007 8:53 AM,  <rachmat <at> cs.its.ac.id> wrote:
> i do learn my skill about jython and jsp, can u give me example about
> jython jsp ?

http://www.google.com/search?q=jython+jsp

--

-- 
Cheers,
Simon B.
simon <at> brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
Austin Mount | 3 Dec 19:26
Picon

registry/cachdir PythonInterpreter

I have a jython class that I am trying to implement via the java interface/org.python.util.PythonInterpreter method.  The interface class and the class that I use to load the py script are encapsulated in a jar file. The py file is located outside the jar file in the /jre/lib/ext directory.   When I attempt to create the object I recieve two errors... the first that it can't create the cachdir and it attempts to created it in the ext/**jarfile**/cachedir/packages.  The second error is that the module UserString does not exist and and I think it would be due to the first error.  I know the first error is because there is no permission to write to that directory.  I have created a directory /usr/share/jython/cachedir and given full permissions to all user on that dir.  I also changed the registry file to use that for the cache dir.  When I run jython from the terminal it seems to be using that cachedir and I am able to import the module UserString without issue.  So I believe my problem is that when I load the class with PythonInterpreter it is not using the settings in the registry file.  Assuming that is correct, how does jython find that file and what do I need to do to ensure the PythonInterpreter finds that file and uses it?

Version Information that may be pertainent....

java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)

Jython 2.2.1 on java1.6.0_03

Any help would be much appreciated!!!

Austin

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Oti | 3 Dec 21:41
Picon
Gravatar

Re: registry/cachdir PythonInterpreter

Austin,

you can either use -Dpython.cachedir=/your/dir when starting java, or
pass a java.util.Properties containing a python.cachedir property
(with value /your/dir) into the constructor of PythonInterpreter.

The other approach is to set python.home pointing to your registry
file, and indicating python.cachedir (and other options) inside the
registry file.

Hope this helps,
Oti.

On Dec 3, 2007 7:26 PM, Austin Mount <adrenlinerush <at> gmail.com> wrote:
> I have a jython class that I am trying to implement via the java
> interface/org.python.util.PythonInterpreter method.  The interface class and
> the class that I use to load the py script are encapsulated in a jar file.
> The py file is located outside the jar file in the /jre/lib/ext directory.
> When I attempt to create the object I recieve two errors... the first that
> it can't create the cachdir and it attempts to created it in the
> ext/**jarfile**/cachedir/packages.  The second error is that the module
> UserString does not exist and and I think it would be due to the first
> error.  I know the first error is because there is no permission to write to
> that directory.  I have created a directory /usr/share/jython/cachedir and
> given full permissions to all user on that dir.  I also changed the registry
> file to use that for the cache dir.  When I run jython from the terminal it
> seems to be using that cachedir and I am able to import the module
> UserString without issue.  So I believe my problem is that when I load the
> class with PythonInterpreter it is not using the settings in the registry
> file.  Assuming that is correct, how does jython find that file and what do
> I need to do to ensure the PythonInterpreter finds that file and uses it?
>
> Version Information that may be pertainent....
>
> java version "1.6.0_03"
> Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
> Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)
>
> Jython 2.2.1 on java1.6.0_03
>
> Any help would be much appreciated!!!
>
> Austin
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by: The Future of Linux Business White Paper
> from Novell.  From the desktop to the data center, Linux is going
> mainstream.  Let it simplify your IT future.
> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
>

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
Oti | 3 Dec 22:03
Picon
Gravatar

Re: jython's convenience java methods

Marcel,

could you please provide a
  dir(env)

I suspect that initialContext is not a setter/getter pair, but
something else, like in my example below.

Consider the following Java class with an unbalanced initialContext:
package st.extreme.jython;
public class Environment {
	public Environment() {
	}
	public String initialContext;
	public String getInitialContext() {
		return "getInitialContext";
	}
}

and then, after calling jython interpreter:

>>> from st.extreme.jython import Environment
>>> env = Environment()
>>> dir(env)
['__init__', 'class', 'equals', 'getClass', 'getInitialContext',
'hashCode', 'initialContext', 'notify', 'notifyAll', 'toString',
'wait']
>>> print env.getInitialContext()
getInitialContext
>>> print env.initialContext
None
>>> env.initialContext.someMethod()
>>> Traceback (innermost last):
  File "<console>", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'someMethod'

best wishes,
Oti.

On Dec 1, 2007 10:37 PM, marcel liker <m_liker <at> yahoo.com> wrote:
>
> ----- Original Message ----
> From: Charlie Groves <charlie.groves <at> gmail.com>
> To: marcel liker <m_liker <at> yahoo.com>
> Cc: jython-users <at> lists.sourceforge.net
> Sent: Saturday, December 1, 2007 4:06:44 PM
> Subject: Re: [Jython-users] jython's convenience java methods
>
> On Dec 1, 2007 11:57 AM, marcel liker <m_liker <at> yahoo.com> wrote:
> > Hi there,
> > I ran into an issue with Jython's "convenience" java methods.
>  Consider this example:
> >
> > [mliker <at> jbox1 ~]$ ./rlwrap jython/jython
> > Jython 2.2.1 on java1.4.2_08
> > Type "copyright", "credits" or "license" for more information.
> >
> > >>> from weblogic.jndi import Environment
> > >>> server, user, password = 'server', 'user', 'password'
> > >>> env = Environment(providerUrl = 't3://' + server + ':80',
>  securityPrincipal = user, securityCredentials = password)
> > >>>
>  env.getInitialContext().lookup("javax.jms.QueueConnectionFactory")
> > weblogic.jms.client.JMSXAConnectionFactory <at> 1d226a7
> >
> > however:
> >
> > [mliker <at> box1 ~]$ ./rlwrap jython/jython
> >
> > Jython 2.2.1 on java1.4.2_08
> >
> > Type "copyright", "credits" or "license" for more information.
> >
> > >>> from weblogic.jndi import Environment
> > >>> server, user, password = 'server', 'user', 'password'
> >
> > >>> env = Environment(providerUrl = 't3://' + server + ':80',
>  securityPrincipal = user, securityCredentials = password)
> > >>> env.initialContext.lookup("javax.jms.QueueConnectionFactory")
> > Traceback (innermost last):
> >   File "<console>", line 1, in ?
> > AttributeError: 'NoneType' object has no attribute 'lookup'
>
> It strikes me as odd that this is complaining about NoneType not
> having lookup on it.  If the bean accessors weren't being created,
> you'd get an AttributeError about the lack of initialContext on env.
> Is there anything that could be going on here to cause
> getInitialContext to return null just in this instance?
>
> [Marcel]
>
> [mliker <at> box1 ~]$ ./rlwrap jython/jython
> >>> from weblogic.jndi import Environment
> >>> server, user, password = 'server', 'user', 'password'
> >>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user,
securityCredentials = password)
> >>> ctx = env.initialContext
> >>> type(ctx)
> <type 'NoneType'>
> >>> ctx = env.getInitialContext()
> >>> dir(ctx)
> ['APPLET', 'AUTHORITATIVE', 'BATCHSIZE', 'CREATE_INTERMEDIATE_CONTEXTS',
'DELEGATE_ENVIRONMENT', 'DNS_URL', 'ENABLE_CALL_BY_REFERENCE', 'ENABLE_SERVER_AFFINITY',
'INITIAL_CONTEXT_FACTORY', 'LANGUAGE', 'OBJECT_FACTORIES', 'PIN_TO_PRIMARY_SERVER',
'PROVIDER_RJVM', 'PROVIDER_URL', 'REFERRAL', 'REPLICATE_BINDINGS', 'SECURITY_AUTHENTICATION',
'SECURITY_CREDENTIALS', 'SECURITY_PRINCIPAL', 'SECURITY_PROTOCOL', 'SSL_CLIENT_CERTIFICATE',
'SSL_CLIENT_KEY_PASSWORD', 'SSL_ROOT_CA_FINGERPRINTS', 'SSL_SERVER_NAME', 'STATE_FACTORIES',
'URL_PKG_PREFIXES', 'addToEnvironment', 'bind', 'class', 'clone', 'close', 'composeName',
'createSubcontext', 'destroySubcontext', 'enableLogoutOnClose', 'env', 'environment',
'equals', 'finalize', 'getClass', 'getEnvironment', 'getNameInNamespace', 'getNameParser', 'getN
 ode', 'getRemoteDelegate', 'hashCode', 'kernelId', 'list', 'listBindings', 'log', 'loginThread',
'lookup', 'lookupLink', 'nameInNamespace', 'node', 'notify', 'notifyAll',
>  'readExternal', 'rebind', 'registerNatives', 'remoteDelegate', 'removeFromEnvironment',
'rename', 'serialVersionUID', 'toString', 'translateException', 'unbind', 'wait', 'writeExternal']
> >>> type(ctx)
> <type 'javainstance'>
>
>
>
> Your console
> output makes it seem like that's impossible, but it's the first thing
> I want to be sure of.  Would it be hard for me to set this up locally
> or have you seen this anywhere else?
>
> [Marcel]
>
> I do not remember that I saw this before. If you would like to reproduce it you would need:
> - Weblogic Server 8.1 sp5 installed and running
> - for jython put the $BEA_HOME/weblogic81/server/lib/weblogic.jar on your classpath
> - use the same java version as the one used to run Weblogic Server
>
> > If somebody could also shed some light on how does jython provide
>  these "convenience" methods as I have come across instances where not all
>  java methods would have a jython "convenience" method
>
> It's based off of JavaBean properties:
> http://jython.org/Project/userguide.html#javabean-properties
> Essentially, if an object x has a getBlah method that returns a
> String, it can be accessed as  x.blah and if it has a setBlah(String)
> method, it can be set with x.blah = 'whatever'.  If the get method
> takes an argument, or if the setter returns something, they won't be
> exposed as a field since they're not JavaBeans.
>
> [Marcel]
>
> Thanks for the info Charlie
>
> Charlie
>
>
>
>
>
>       Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. 
Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by: The Future of Linux Business White Paper
> from Novell.  From the desktop to the data center, Linux is going
> mainstream.  Let it simplify your IT future.
> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

Gmane