On Sep 16, 2009, at 6:50 PM, Steve Lewis wrote:
> Hey all,
> I'm new to Jython, and I've started working on the bz2 module
> implementation. I've looked at the PortingPythonModulesToJython
> wiki, and I was following that, but I can't seem to get my bz2
> module to be recognized:
> Traceback (most recent call last):
> File "test_bz2.py", line 11, in <module>
> import bz2
> ImportError: No module named bz2
> It appears that there is more than one way to register a module, if
> the "JythonModulesInJava" is still valid:
> "My new approach is borrowed slightly from CPython where it's very
> common to write a C library, a straight wrapper and then a Pythonic
> So, is there a way I can use the new approach? It looks like
> (reading the CPythonLib/csv.py) that if I create a "bz2.py" file in
> the CPythonLib directory, then jython might see it? Or is there a
> piece of ant that copies the ... oh there it is.
> CPythonLib.includes. There it is. Thanks for the help!
It just needs an entry in org.python.modules.Setup.
I tried making the bz2 module a couple years ago using the Apache bz2
lib. The big problem I ran into was the Apache decompressor doesn't
support streaming (allow passing in pieces of an archive piecemeal)
like Python's bz2.BZ2Decompressor does. Without a bunch of work on
this decompressor code we either can't support BZ2Decompressor at all
or can't support it efficiently (unless you can think of another way)
I actually revistied this code again recently and updated a little.
Here's what I currently have except for my older failed
BZ2Decompressor experiment -- it's now using the Apache Commons
Compress bz2 lib, which is the same Apache's under a different name.
BZ2Compressor seems to work, BZ2File needs cleanup and to support
writing and universal newlines during read. For that it can probably
use either java.io.LineNumberReader or
org.python.core.io.TextIOInputStream combined with
io.UniversalIOWrapper like core.ParserFacade does.