Anthony Tarlano | 1 Nov 16:14
Picon

Re: XML in Jython: ElementTree?

F.Y.I..

There has been support for Jython in the ElementTree subversion repository since 2005 in the form of a  file named JavaXMLTreeBuilder.py .

Below is a  sample of its explicit use as a parameter with the version 1.2.7 of ElementTree, by passing a TreeBuilder instance to the ElementTree.parse as the default parser. Of course you can set it as the default parser in ElementTree.py by modifying the DefaultParserAPI line to be:

parser_api = default_parser_api = DefaultParserAPI(parser=JavaXMLTreeBuilder())

Regards,

Anthony

----------------------------

89> jython
Jython 2.2.1 on java1.6.0_03
Type "copyright", "credits" or "license" for more information.
>>> from elementtree.ElementTree import ElementTree
>>> from elementtree.JavaXMLTreeBuilder import TreeBuilder
>>> tree = ElementTree()
>>> tree
<elementtree.ElementTree.ElementTree instance 1>
>>> root = tree.parse('nsexample.xml', TreeBuilder())
>>> for each in root:
...  each
...
<Element {http://purl.org/dc/elements/1.1/}Description at 2>
<Element { http://purl.org/dc/elements/1.1/}Title at 3>
<Element {http://fourthought.com/timelog}MinIncrement at 4>
<Element { http://fourthought.com/timelog}InvoiceNumber at 5>
>>>
>>>
>>> from elementtree.ElementTree import dump
>>> dump(tree)
<ns0:ClientInfo xmlns:ns0=" http://fourthought.com/timelog">
  <ns1:Description xmlns:ns1="http://purl.org/dc/elements/1.1/">
    Fourthought, Inc
  </ns1:Description>
  <ns1:Title xmlns:ns1="http://purl.org/dc/elements/1.1/">
    Management Subcontracting
  </ns1:Title>
  <ns0:MinIncrement>0.25</ns0:MinIncrement>
  <ns0:InvoiceNumber>7777</ns0:InvoiceNumber>
</ns0:ClientInfo>
>>>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Pratyush R Giri | 1 Nov 22:59
Picon
Favicon

Jython Leaking memopry in byte[] ?

All,

I have this test code

public class TestMemory
{
    public static void main(String[] args)
    {
        byte[] myByte = new byte[1024 * 1024 * 200];

        myByte = null;
        System.gc();
        while(true) {

        }
   }
}

When I am trying to run this from a java code then as
expected the heap size increases to 200 MB and then
comes back. However, when running this from a jython
intepreter, the memory seems not to be released at
all.

Anyone has faced the same issues and if there is a
solution to this?

Rgds,
Pratyush

Thanks
Pratyush

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Balaji Srinivasan | 2 Nov 09:53
Picon

Re: Wierd issue with string buffer

Thanks a lot Oti. That really worked. I updated to 2.2.1 and removed  
the hack below and it seems to work now.
Thanks
Balaji

On Oct 30, 2007, at 1:22 PM, Oti wrote:

> Balaji,
>
> I assume you are using Jython 2.1 with Java 1.5.
> The fix you mentioned is really a workaround, and I suspect there are
> other unresolved problems when using the above combination.
> I'd suggest to upgrade to Jython 2.2., or even 2.2.1
>
> Best wishes,
> Oti.
>
> On 10/30/07, Balaji Srinivasan <balajione <at> gmail.com> wrote:
>> Hi There
>> We are using Jython in a JBoss appserver. When we ported over to Java
>> 1.5 we started getting errors liek:
>>> Traceback (innermost last):
>>>   File "<console>", line 1, in ?
>>> java.lang.IllegalAccessException: Class
>>> org.python.core.PyReflectedFunction can not access a member of class
>>> java.lang.AbstractStringBuilder with modifiers "public"
>>
>> The following URL
>> http://aspn.activestate.com/ASPN/Mail/Message/Jython-users/2191110
>> gave the following fix:
>>
>> import java
>> import org.python.core
>>
>> import java.lang.StringBuffer as SB
>>
>> for n,f in java.lang.AbstractStringBuilder.__dict__.items():
>>    x = org.python.core.PyReflectedFunction(n)
>>    for a in f.argslist:
>>      if a is None: continue
>>      m = SB.getMethod(n,a.args)
>>      x.addMethod(m)
>>    SB.__dict__[n] = x
>>
>>
>> Now I evaluate this code every time I create a new interpreter.
>> Unfortunately now occassionally I am getting errors like:
>>
>> java.lang.NoSuchMethodException:  
>> java.lang.StringBuffer.deleteCharAt(int, int)
>>        at java.lang.Class.getMethod(Class.java:1581)
>>        at sun.reflect.GeneratedMethodAccessor345.invoke(Unknown  
>> Source)
>>        at
>> sun 
>> .reflect 
>> .DelegatingMethodAccessorImpl 
>> .invoke(DelegatingMethodAccessorImpl.java:25)
>>        at java.lang.reflect.Method.invoke(Method.java:585)
>>        at
>> org 
>> .python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
>>        at org.python.core.PyMethod.__call__(PyMethod.java)
>>        at org.python.core.PyObject.__call__(PyObject.java)
>>
>> This happens on the getMethod line in the script fragment above.
>> Surprisingly it doesnt happen every time. Just very infrequently.
>> Any ideas why this might be happening? Please let me know if you need
>> more details.
>> Any help would be appreciated.
>> Balaji
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc.
>> Still grepping through log files to find problems?  Stop.
>> Now Search log events and configuration files using AJAX and a  
>> browser.
>> Download your FREE copy of Splunk now >> http://get.splunk.com/
>> _______________________________________________
>> Jython-users mailing list
>> Jython-users <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Paul D. Fernhout | 3 Nov 13:55
Favicon
Gravatar

ImportError: no module named ihooks

I'm trying to have Jython import modules directly from a fine-grained
versioned repository of source code and content, similar in some ways to
IBM/OTI's ENVY/Developer for Smalltalk and Java (but more generalized). A
sample screenshot of an (unreleased yet) Jython version of the code I'm
working on is here:
  http://sourceforge.net/project/screenshots.php?group_id=6010

For some reason I thought Jython 2.2 supported import hooks.
  http://fwierzbicki.blogspot.com/2007/08/jython-22-released-woohoo.html
  "PEP 302 implementation"
  http://www.python.org/dev/peps/pep-0302/
  "New Import Hooks"

But when I try this:
  import sys
  print sys.version
  import ihooks

I get:

  2.2
  Exception in thread "AWT-EventQueue-0" Traceback (innermost last):
    File "/home/pdf/workspace/pointrel20071003/browser.py", line 120, in
       runPressed
    File "<string>", line 3, in ?
  ImportError: no module named ihooks

I tried copying over a CPython2.4 ihooks.py file, but it has CPython
specific stuff and does not load. When I removed some of the CPython
specific stuff, it loaded, but when I ran it with this example:
   http://mail.python.org/pipermail/python-list/2001-May/086186.html
the code installed OK,, but on doing a new import, I then got CPython
functions missing (weirdly prefixed os.path references).

  Exception in thread "AWT-EventQueue-0" Traceback (innermost last):
  File "/home/pdf/workspace/pointrel20071003/browser.py", line 120, in
      runPressed
  File "<string>", line 2, in ?
  File "/home/pdf/workspace/pointrel20071003/ihooks_from_cpython.py", line
     408, in import_module
  File "/home/pdf/workspace/pointrel20071003/ihooks_from_cpython.py", line
     461, in load_tail
  ImportError: No module named org.python.modules.os.path

But when I do:
  import os
  print os.path

I get:
  <module 'javapath' from
'/home/pdf/workspace/PROJECT/jython2.2/Lib/javapath.py'>

Rather than go further, I decided to stop and ask.  I don't know much about
import hooks, so perhaps I'm just missing something obvious before I
reinvent the wheel.

The only direct reference I found in recent jython-dev emails is ihooks in
the "List of missing modules" from a post on 2007-01-18.

On the jython-users list on 2007-08-30, "Separated .class and .py
directories", dperez links to an import hook, but it was written in Java.
"""
The patch is here (fully documented):
http://sourceforge.net/tracker/index.php?func=detail&aid=1784696&group_id=12867&atid=312867

"""

The file ihooks.py did not seem to be on SourceForge in the libraries,
  http://jython.svn.sourceforge.net/viewvc/jython/trunk/jython/Lib/
so I was not sure if I should copy a CPython version over. (I still feel it
would be nice if all the supported lib modules were there and not copied
from CPython during builds, to avoid such uncertainty.)

Anyway, does Jython2.2 just support import hooks in general but not the
ihooks module?

Can I do an import hook written in Jython somehow just not using the ihooks
module? Or do I need to make a Java class like dperez did?

If I want to use the ihooks module, would I need to continue hacking away
until I make a module that works?

In general Jython2.2 is a great advance and I appreciate all the hard work
that went into it. Just wondering how to proceed.

--Paul Fernhout

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Oti | 3 Nov 14:02
Picon
Gravatar

Re: Wierd issue with string buffer

Cool - thanks for the feedback!

Oti.

On 11/2/07, Balaji Srinivasan <balajione <at> gmail.com> wrote:
> Thanks a lot Oti. That really worked. I updated to 2.2.1 and removed
> the hack below and it seems to work now.
> Thanks
> Balaji
>
> On Oct 30, 2007, at 1:22 PM, Oti wrote:
>
> > Balaji,
> >
> > I assume you are using Jython 2.1 with Java 1.5.
> > The fix you mentioned is really a workaround, and I suspect there are
> > other unresolved problems when using the above combination.
> > I'd suggest to upgrade to Jython 2.2., or even 2.2.1
> >
> > Best wishes,
> > Oti.
> >
> > On 10/30/07, Balaji Srinivasan <balajione <at> gmail.com> wrote:
> >> Hi There
> >> We are using Jython in a JBoss appserver. When we ported over to Java
> >> 1.5 we started getting errors liek:
> >>> Traceback (innermost last):
> >>>   File "<console>", line 1, in ?
> >>> java.lang.IllegalAccessException: Class
> >>> org.python.core.PyReflectedFunction can not access a member of class
> >>> java.lang.AbstractStringBuilder with modifiers "public"
> >>
> >> The following URL
> >> http://aspn.activestate.com/ASPN/Mail/Message/Jython-users/2191110
> >> gave the following fix:
> >>
> >> import java
> >> import org.python.core
> >>
> >> import java.lang.StringBuffer as SB
> >>
> >> for n,f in java.lang.AbstractStringBuilder.__dict__.items():
> >>    x = org.python.core.PyReflectedFunction(n)
> >>    for a in f.argslist:
> >>      if a is None: continue
> >>      m = SB.getMethod(n,a.args)
> >>      x.addMethod(m)
> >>    SB.__dict__[n] = x
> >>
> >>
> >> Now I evaluate this code every time I create a new interpreter.
> >> Unfortunately now occassionally I am getting errors like:
> >>
> >> java.lang.NoSuchMethodException:
> >> java.lang.StringBuffer.deleteCharAt(int, int)
> >>        at java.lang.Class.getMethod(Class.java:1581)
> >>        at sun.reflect.GeneratedMethodAccessor345.invoke(Unknown
> >> Source)
> >>        at
> >> sun
> >> .reflect
> >> .DelegatingMethodAccessorImpl
> >> .invoke(DelegatingMethodAccessorImpl.java:25)
> >>        at java.lang.reflect.Method.invoke(Method.java:585)
> >>        at
> >> org
> >> .python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
> >>        at org.python.core.PyMethod.__call__(PyMethod.java)
> >>        at org.python.core.PyObject.__call__(PyObject.java)
> >>
> >> This happens on the getMethod line in the script fragment above.
> >> Surprisingly it doesnt happen every time. Just very infrequently.
> >> Any ideas why this might be happening? Please let me know if you need
> >> more details.
> >> Any help would be appreciated.
> >> Balaji
> >>
> >> -------------------------------------------------------------------------
> >> This SF.net email is sponsored by: Splunk Inc.
> >> Still grepping through log files to find problems?  Stop.
> >> Now Search log events and configuration files using AJAX and a
> >> browser.
> >> Download your FREE copy of Splunk now >> http://get.splunk.com/
> >> _______________________________________________
> >> Jython-users mailing list
> >> Jython-users <at> lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/jython-users
> >>
>
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Paul D. Fernhout | 5 Nov 00:51
Favicon
Gravatar

Re: ImportError: no module named ihooks

To answer my own question, under Jython2.2 the following code works to set
an import hook, so all you really need is the "imp" module and the
"__builtin__" module, not "ihooks":

"""
import imp

# resources:
# http://wiki.python.org/moin/ImpModule
# http://docs.python.org/lib/module-imp.html
#http://groups.google.com/group/comp.lang.python/browse_thread/thread/fdafee093d2e1d09/3efc3ceb5849adf7?hl=en&lnk=st&q=python+%22imp+module%22#3efc3ceb5849adf7

import __builtin__

oldimport = __builtin__.__import__
def mycode(name, globals=None, locals=None, fromlist=None):
  print "MY IMPORT!", name
  return oldimport(name, globals, locals, fromlist)

__builtin__.__import__ = mycode

import java
print "done"
"""

Output:
""""
run pressed
=== run code ===
MY IMPORT! java
done
=== done ===
run pressed
=== run code ===
MY IMPORT! imp
MY IMPORT! __builtin__
MY IMPORT! java
MY IMPORT! java
done
=== done ===
run pressed
=== run code ===
MY IMPORT! imp
MY IMPORT! imp
MY IMPORT! __builtin__
MY IMPORT! __builtin__
MY IMPORT! java
MY IMPORT! java
MY IMPORT! java
done
=== done ===
run pressed
=== run code ===
MY IMPORT! imp
MY IMPORT! imp
MY IMPORT! imp
MY IMPORT! __builtin__
MY IMPORT! __builtin__
MY IMPORT! __builtin__
MY IMPORT! java
MY IMPORT! java
MY IMPORT! java
MY IMPORT! java
done
=== done ===
"""

Every time it is run (from within a host GUI) it adds the same new "mycode"
importer to the chain, which ends up calling itself recursively -- something
I need to fix (probably by just doing it once!). And I don't quite
understand the increasing numbers of imports of imp and __builtin__ each
time I eval the code -- once I can understand, but why more, I don't know
yet. Might have something to do with the rest of my evaluation environment?
Well, unimportant for now, but a curiosity. :-)

I don't actually use the "imp" module yet, but presume I will have to at
some point to manage compiled code and really make my new import hook do
stuff properly?

So it looks like the general functionality for overriding what __import__
does is supported in Jython2.2 (maybe even earlier?) but the ihooks module
itself is still missing?

In my case, fortunately the general "__builtin__" functionality and "imp"
functionality is hopefully really all I need for now (I think). If I
understand it correctly now, ihooks just lets multiple modifiers of the
import mechanism coordinate their hooks in a cooperative fashion, or as the
comment there says: "Consistent use of this [ihooks] module will make it
possible to change the different mechanisms involved in loading modules
independently."

Hope this might help someone else understand the basics if they want to do
something similar. The comp.lang.python thread referenced above was what
pointed me in this direction.

--Paul Fernhout

Paul D. Fernhout wrote:
> Anyway, does Jython2.2 just support import hooks in general but not the
> ihooks module?
> 
> Can I do an import hook written in Jython somehow just not using the ihooks
> module? Or do I need to make a Java class like dperez did?
> 
> If I want to use the ihooks module, would I need to continue hacking away
> until I make a module that works?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Paul D. Fernhout | 5 Nov 01:21
Favicon
Gravatar

Re: ImportError: no module named ihooks

Silly me, the mycode hook is recursively calling down the chain for the
imports before the latest hook is set too. So it does import them just once,
but reports on it for every previous time the routine was eval'd. So that is
why they are reported one less time than the number of java imports (which
is done after the latest hook is added to the chain).

--Paul Fernhout

Paul D. Fernhout wrote:
> Every time it is run (from within a host GUI) it adds the same new "mycode"
> importer to the chain, which ends up calling itself recursively -- something
> I need to fix (probably by just doing it once!). And I don't quite
> understand the increasing numbers of imports of imp and __builtin__ each
> time I eval the code -- once I can understand, but why more, I don't know
> yet. Might have something to do with the rest of my evaluation environment?
> Well, unimportant for now, but a curiosity. :-)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Fabio Zadrozny | 5 Nov 20:53
Picon

Pydev 1.3.10 Released

Hi All,

Pydev and Pydev Extensions 1.3.10 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-----------------------------------------------------------------

* Code-analysis: Doesn't report 'statement without effect' within list comprehension.
* Context insensitive code completion: Shows contents of zips/eggs/jars
* Go to definition: Working with zips/eggs/jars.


Release Highlights in Pydev:
----------------------------------------------

* Symlinks supported in the system pythonpath configuration.
* Egg/zip files are now supported.
* The creation of a project in a non-default location is now allowed within the workspace
* JDT used to get completions from jars (but referencing other java projects is still not supported).
* Configuration of pythonpath allows multiple selection for removal.
* Configuration of pythonpath allows multiple jars/zips to be added at once.
* When configuring the pythonpath, the paths are sorted for selection.
* The file extensions that pydev recognizes for python can now be customized.
* Patch by Carl Robinson: Code-folding for elements such as for, try, while, etc.
* Removed the go to next/previous problem annotation (Eclipse 3.3 already provides a default implementation for it).


What is PyDev?
---------------------------

PyDev is a plugin that enables users to use Eclipse for Python and Jython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others.


Cheers,

--
Fabio Zadrozny
------------------------------------------------------
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
pydev-code mailing list
pydev-code <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pydev-code
Byron | 5 Nov 22:17

Re: Pydev 1.3.10 Released

Awsome Work, Thank you!

Fabio Zadrozny wrote:
> Hi All,
> 
> Pydev and Pydev Extensions 1.3.10 have been released
> 
> Details on Pydev Extensions: http://www.fabioz.com/pydev
> Details on Pydev: http://pydev.sf.net
> Details on its development: http://pydev.blogspot.com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Somchai Rukthai | 6 Nov 02:00
Picon

java.lang.ClassCastException: org.python.core.PySingleton


Hello,

My situation is that I experiment on the "accessing Jython from Java without using Jythonc" example in the
FAQ section from the following link,
http://wiki.python.org/jython/JythonMonthly/Articles/September2006/1.

Everything is ok. 

Then, in the Employee.py, I replace the "from employee import EmployeeType" statement with "import
java", and
change the Employee class definition,

from
class Employee(EmployeeType):
to
class Employee(java.lang.Object):

I get the following error:
Exception in thread "main" java.lang.ClassCastException: org.python.core.PySingleton cannot be
cast to employee.EmployeeType

What should I do if I have to use the "class Employee(java.lang.Object):" instead of "class
Employee(EmployeeType):" for the class definition?

The reason for this is that I am using an open source Python package and it uses java.lang.Object in its class definition.

Thank you very much.

_________________________________________________________________
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

Gmane