Tom Price | 1 Apr 02:21
Favicon

Loading JAR files with large packages

Hi,

I'm trying to access some classes from Jython that are in a .jar file,
which works the first time the application is started, but I
consistently get the following error on the second and subsequent
executions:

ImportError: No module named settings

I looked in the .pkc file for this .jar, and indeed the "settings"
package is not listed there, but it *is* present in the .jar.  I then
did some experimentation and found that the problem is when
CachedJarsPackageManager.java attempts to write the .pkc file (in
writeCacheFile), it gets an IOException as follows:

java.io.UTFDataFormatException: encoded string too long: 67064 bytes
        at java.io.DataOutputStream.writeUTF(Unknown Source)
        at java.io.DataOutputStream.writeUTF(Unknown Source)
        at Test.writeCacheFile(Test.java:397)

(where Test.java is a copy of CachedJarsPackageManager.java modified to
experiment with this problem).

This is triggered by the fact that one of the packages in my .jar file
is very large (thousands of classes), so the string listing all the
classes in this package is too long for DataOutputStream to write in one
go.  Has anyone come across this before, and is there any way to work
around it?

Thanks in advance for any suggestions.
(Continue reading)

marvin greenberg | 1 Apr 03:03
Picon

Re: Use of interned strings in various jython methods

David Huebel wrote:
> String literals in Java source code get interned.
>   
ok.  personally I still prefer defining some constants since it avoids 
typographical errors that would not be checked by the compiler.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
Moore, Greg | 1 Apr 03:10
Picon
Favicon

SSL socket failure.

Hi,

I'm having to get some ssl code to work. Since I've never done any SSL
programming I started with the page that Alan Kennedy started/wrote on
the wiki at http://wiki.python.org/jython/NewSocketModule and read some
old ML message with nabble like
http://www.nabble.com/Re%3A-SSL-support-p8995253.html 

So using jython 2.2 I tried the code that was said to work at
http://docs.python.org/lib/socket-example.html however I was less then
successful.

with a 1.4.2 JVM this is what I got:

Jython Completion Shell

Jython 2.2 on java1.4.2_07

>>> import socket

>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

>>> s.connect(('localhost', 443))

>>> ssl_sock = socket.ssl(s)

Traceback (most recent call last):

  File "<input>", line 1, in ?

(Continue reading)

David Huebel | 1 Apr 04:59
Picon

Re: Use of interned strings in various jython methods

On Mon, Mar 31, 2008 at 8:03 PM, marvin greenberg
<public.marvin <at> gmail.com> wrote:
> David Huebel wrote:
>  > String literals in Java source code get interned.
>  >
>  ok.  personally I still prefer defining some constants since it avoids
>  typographical errors that would not be checked by the compiler.
>

It's tempting to say something snide like, "Why are you interested in
Python, then?" ;-) but I tend to agree with you.  Supposedly (I'm not
a developer) a lot of internals have been cleaned up for 2.5; you
should have a look at the latest code and then maybe bring the issue
up on jython-dev.

-David

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
David Huebel | 1 Apr 05:35
Picon

Re: SSL socket failure.

On Mon, Mar 31, 2008 at 8:10 PM, Moore, Greg <Greg_W_Moore <at> adp.com> wrote:
>
> javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLHandshakeException:
> sun.security.validator.ValidatorException: PKIX path building failed:
> sun.security.provider.certpath.SunCertPathBuilderException: unable to find
> valid certification path to requested target
>
>
>
> For the purposes of what I'm doing I don't really want (or even need) to
> deal with certificates.

The Java SSL implementation checks certificates by default.  See the
second message in this thread for a way to disable checking:

http://forum.java.sun.com/thread.jspa?threadID=660461&tstart=0

If you want to check certificates, you need to find the cert used to
sign the server's cert and make it available to your application.  You
have two options for making it available to the application:

1) put the cert into the JRE's default trust store (which is
impractical when deploying to multiple machines), or
2) point your application to a special trust store containing the cert

For both of those, see "Customizing the Default Key and Trust Stores"
in this guide:

http://java.sun.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html

(Continue reading)

NISHIO Hirokazu | 1 Apr 09:05
Picon

Problem on formatting of unicode string

Hi, all
I'm using Jython2.2.1 and WindowsXP.
I found some strange behavior on formatting unicode string.
It seems to be dropping the higher byte. (hex(ord("B")) is '0x42')
I replaced a Japanese character in following script with asterisk.

=====
# -*- coding: utf8 -*-

s = "*%s"
print repr(s) # '\xE3\x81\x82%s'
u = unicode(s, "utf8")
print repr(u) # u'\u3042%s'
print repr(u % u) # u'BB%s'
=====

Would anyone tell me why it does?

Thanks,

Nishio Hirokazu
Attachment (unicodetest.py): text/x-python, 153 bytes
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
(Continue reading)

Moore, Greg | 1 Apr 20:09
Picon
Favicon

Re: SSL socket failure.


Thanks David. that link helps. So I need to setup a trust manager even
though I'm trying to use a more pythonic solution? 

Is that because this is running on a JVM? And if that's that case
wouldn't it make the discussions (on the dev mailing list) about if
jython SSL support should work like CPyhton a moot point. e.g. it never
can because of the JVM?!?!??

Greg.

-----Original Message-----
From: David Huebel [mailto:davidhuebel <at> gmail.com] 
Sent: Monday, March 31, 2008 8:36 PM
To: Moore, Greg
Cc: jython-users <at> lists.sourceforge.net
Subject: Re: [Jython-users] SSL socket failure.

On Mon, Mar 31, 2008 at 8:10 PM, Moore, Greg <Greg_W_Moore <at> adp.com>
wrote:
>
> javax.net.ssl.SSLHandshakeException:
javax.net.ssl.SSLHandshakeException:
> sun.security.validator.ValidatorException: PKIX path building failed:
> sun.security.provider.certpath.SunCertPathBuilderException: unable to
find
> valid certification path to requested target
>
>
>
(Continue reading)

David Huebel | 1 Apr 22:22
Picon

Re: SSL socket failure.

On Tue, Apr 1, 2008 at 1:09 PM, Moore, Greg <Greg_W_Moore <at> adp.com> wrote:
>
>  Thanks David. that link helps. So I need to setup a trust manager even
>  though I'm trying to use a more pythonic solution?
>
>  Is that because this is running on a JVM? And if that's that case
>  wouldn't it make the discussions (on the dev mailing list) about if
>  jython SSL support should work like CPyhton a moot point. e.g. it never
>  can because of the JVM?!?!??
>
>  Greg.
>

Mostly I answered the way I did because I had that information at my
fingertips.  From the stack trace it looks like the Jython
implementation of the library you're using uses the Java SSL
implementation under the covers.  Most likely it uses the default
settings, which means you can probably configure it by changing the
Java default configuration.

That said, I'm sure the Python library has its own way of configuring
trust, which probably works just as well.  Might as well check on
python.org....

> ssl(  	sock[, keyfile, certfile])
>    Initiate a SSL connection over the socket sock. keyfile is the name of a
>    PEM formatted file that > contains your private key. certfile is a PEM
>    formatted certificate chain file. On success, a new SSLObject is returned.
>
>    Warning: This does not do any certificate verification!
(Continue reading)

Moore, Greg | 2 Apr 00:17
Picon
Favicon

Re: SSL socket failure.


> 
> Mostly I answered the way I did because I had that information at my
> fingertips.  From the stack trace it looks like the Jython
> implementation of the library you're using uses the Java SSL
> implementation under the covers.  

Well, I guess its possible but I was just using the example was from the
python site, the socket example 17.2.3 near the bottom of the page. all
it does is import socket. http://docs.python.org/lib/socket-example.html

> 
> That said, I'm sure the Python library has its own way of configuring
> trust, which probably works just as well.  Might as well check on
> python.org....

Been there DONE that :) 

> 
> > ssl(  	sock[, keyfile, certfile])
> >    Initiate a SSL connection over the socket sock. keyfile is the
name
> > of a PEM formatted file that > contains your private key. certfile
is a
> >PEM formatted certificate chain file. On success, a new SSLObject is
> returned.
> >
> >    Warning: This does not do any certificate verification!
> 
> That's odd.  It takes a certfile argument but says it doesn't do any
(Continue reading)

David Huebel | 2 Apr 00:40
Picon

Re: SSL socket failure.

On Tue, Apr 1, 2008 at 5:17 PM, Moore, Greg <Greg_W_Moore <at> adp.com> wrote:
>  Since this is my first attempt at SSL programming I really just wanted
>  to make sure I wasn't doing something really stupid. or if I've stumbled
>  on a "feature" (as in its not a bug...)

It's probably just a result of implementation priorities... get the
features working first, and leave bug-for-bug compatibility for later
:-)

>  Yea, I guess I muddle through trying to get it to work with Jakarta
>  httpclient.

If the Jython version of socket.ssl uses the default Java SSL
configuration (as I suspect it does -- it's the most likely
explanation for the "bug"), then the directions for disabling cert
checking (see the first link in my first message) will allow you to
use socket.ssl without worrying about certs.

-David

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

Gmane