jython

exposing a Java Map<> in Jython so that its keys are available with Python “dot” operator (attribute access)

只愿长相守 提交于 2020-01-05 11:31:59
问题 We have some Map<String, Object> in Java that I would like to make available into a Jython function. I would like to access the contents via mymap.foo.bar rather than mymap['foo']['bar'] Is there a way to wrap the Map in an object so that it has this behavior in Jython? (e.g. like the __getattr__ method in Python, only implemented in Java) 回答1: I ended up implementing this: @Override public PyObject __findattr_ex__(String name) { if (this.containsKey(name)) { return Py.java2py(this.get(name))

exposing a Java Map<> in Jython so that its keys are available with Python “dot” operator (attribute access)

醉酒当歌 提交于 2020-01-05 11:31:28
问题 We have some Map<String, Object> in Java that I would like to make available into a Jython function. I would like to access the contents via mymap.foo.bar rather than mymap['foo']['bar'] Is there a way to wrap the Map in an object so that it has this behavior in Jython? (e.g. like the __getattr__ method in Python, only implemented in Java) 回答1: I ended up implementing this: @Override public PyObject __findattr_ex__(String name) { if (this.containsKey(name)) { return Py.java2py(this.get(name))

Jython: Open URL in browser (without importing Python libraries)

試著忘記壹切 提交于 2020-01-05 03:51:15
问题 Maximo 7.6.1.1: Using Jython, I want to open a URL in a browser (in Windows 10). I've found a Java example: import java.awt.Desktop; import java.net.URI; if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(new URI("http://www.example.com")); } And I've attempted to convert it to Jython: from java.awt import Desktop from java.net import URI desktop = Desktop.getDesktop() uri = URI("http://google.com/#q=wonum1%2Cwonum2

java.lang.NoClassDefFoundError: Could not initialize class sun.nio.ch.FileChannelImpl

こ雲淡風輕ζ 提交于 2020-01-03 17:03:02
问题 I am working on an application that executes a Jython 2.5.3 script from JAVA 1.6.027 . The script just open a file using codecs library and it looks like this: try: from codecs import open as codecs_open except ImportError: print 'ERROR', 'Could not import.' CODECS_LIST = ['latin-1', 'utf-8', 'utf-16', '1250', '1252'] def open_file(filename, mode): ''' DOC ''' for encoding in CODECS_LIST: try: f = codecs_open(filename, mode, encoding) f.read() f.close() print 'INFO', "File %s supports

Pydev: error initializing console

坚强是说给别人听的谎言 提交于 2020-01-02 08:44:14
问题 I can't get the Jython console to work in Eclipse Luna. The Python console works. The error message is: Error initializing console. Unexpected error connecting to console. Failed to recive suitable Hello response from ... The problem and a solution is described here:proposed solution The solution describes a fix in XP which i've tried to follow in Windows 7 though the steps are not exactly the same as described.. I had to check 'use a proxy server' and then add the 'localhost', ... to the

Pydev: error initializing console

馋奶兔 提交于 2020-01-02 08:44:06
问题 I can't get the Jython console to work in Eclipse Luna. The Python console works. The error message is: Error initializing console. Unexpected error connecting to console. Failed to recive suitable Hello response from ... The problem and a solution is described here:proposed solution The solution describes a fix in XP which i've tried to follow in Windows 7 though the steps are not exactly the same as described.. I had to check 'use a proxy server' and then add the 'localhost', ... to the

How do I determine if an email is Base64 encoded?

江枫思渺然 提交于 2020-01-02 05:15:10
问题 I am having difficulty determining if the body of a text email message is base64 encoded. if it is then use this line of code; making use of jython 2.2.1 dirty=base64.decodestring(dirty) else continue as normal. This is the code I have atm. What line of code will allow me to extract this from the email: "Content-Transfer-Encoding: base64" import email, email.Message import base64 def _get_email_body(self): try: parts=self._email.get_payload() check=parts[0].get_content_type() if check=="text

In Jython, can I make an inline anonymous class that implements a Java interface?

霸气de小男生 提交于 2020-01-01 11:58:09
问题 In Java, I can say Thread t = new Thread(){ public void run(){ // do stuff } } (or something much like that) to declare an anonymous class inline. This is most useful for making event handlers or other callback sorts of things, that in any sensible language wouldn't require an object to own them in the first place. I face the same problem in Jython -- I want to define an event handler, but I don't want to build a whole standalone class to do so. Ideally, I'd just be able to pass a lambda and

Jython saying “No visible constructors for class”

二次信任 提交于 2020-01-01 10:59:30
问题 I have a jython servlet as part of a large application running in tomcat5. I tested a few Spring Framework classes and create the objects in the Jython servlet. When I try to create objects of classes in the application I catch an Exception message "No visible constructors for class". These java classes do have a public constructor class, such as: public SchoolImpl() { } I create the object in python: from com.dc.sports.entity import SchoolImpl ... school = SchoolImpl() What am I doing wrong?