Mayne, Peter | 1 Jul 09:49
Picon
Favicon

socket.getaddrinfo() breaks ftplib FTP client

Consider the following call taken not quite verbatim from ftplib.makeport(). (The difference is that socket.AF_INET) is actually self.af, which can be either socket.AF_INET or socket.AF_INET6.) Assume “import socket”.
 
socket.getaddrinfo(None, 0, socket.AF_INET, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
 
CPython 2.5 returns
 
[(2, 1, 0, '', ('0.0.0.0', 0))]
 
Jython 2.5 returns
 
[(2, 2, 0, 'localhost', ('127.0.0.1', 0))]
 
The second element in the tuple is socktype: the difference reflects the different values of socket.SOCK_STREAM in the two implementations, and is of no concern. However, the canonname and particularly the sockaddr (fourth and fifth elements) in Jython are a problem.
 
When an FTP client (using set_pasv(False)) binds a socket to sockaddr to accept the incoming data connection from the FTP server, CPython binds to sockaddr (‘0.0.0.0’, 0), which allows the FTP server to connect, and the FTP session continues.
 
However, Jython binds to sockaddr (‘127.0.0.1’, 0). Since the socket is bound to localhost, external connection attempts from the FTP server fail: the FTP client hangs waiting for a connection to 127.0.0.1, and the FTP server fails because it can’t connect to the address/port that it was told to connect to.
 
A workaround is to make a local copy of ftplib.py and explicitly set “sa = (‘0.0.0.0’, 0)” before the bind(), but that probably isn’t a proper fix.
 
I’ve tried this on two different Windows systems and a non-Windows system. Is it possible that my systems are misconfigured?
 
Thanks.
 
PJDM
--
Peter Mayne
Hewlett-Packard
Canberra, ACT, Australia
 
 
------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Alan Kennedy | 1 Jul 16:33
Favicon
Gravatar

Re: socket.getaddrinfo() breaks ftplib FTP client

[Peter]
> Consider the following call taken not quite verbatim from ftplib.makeport().
> (The difference is that socket.AF_INET) is actually self.af, which can be
> either socket.AF_INET or socket.AF_INET6.) Assume “import socket”.

Hi Peter,

I'm currently attending Europython at the moment.

I promise I'll look at this in detail soon, either during the sprints
at the end of the week, or when I return home at the weekend.

Meantime, it would be good if you record a bug for this in the bug database.

http://bugs.jython.org

Regards,

Alan.

------------------------------------------------------------------------------
Mayne, Peter | 2 Jul 05:40
Picon
Favicon

Re: socket.getaddrinfo() breaks ftplib FTP client

Done: issue 1391. (There's no 2.5.0 in the "Versions" list.)

PJDM
-- 
Peter Mayne
Hewlett-Packard
Canberra, ACT, Australia 

-----Original Message-----
From: alan.kennedy.name <at> gmail.com [mailto:alan.kennedy.name <at> gmail.com] On Behalf Of Alan Kennedy
Sent: Thursday, 2 July 2009 12:34 AM
To: Mayne, Peter
Cc: jython-users <at> lists.sourceforge.net
Subject: Re: [Jython-users] socket.getaddrinfo() breaks ftplib FTP client

[Peter]
> Consider the following call taken not quite verbatim from ftplib.makeport().
> (The difference is that socket.AF_INET) is actually self.af, which can be
> either socket.AF_INET or socket.AF_INET6.) Assume "import socket".

Hi Peter,

I'm currently attending Europython at the moment.

I promise I'll look at this in detail soon, either during the sprints
at the end of the week, or when I return home at the weekend.

Meantime, it would be good if you record a bug for this in the bug database.

http://bugs.jython.org

Regards,

Alan.

------------------------------------------------------------------------------
Carl | 7 Jul 16:39

Jython Class.forName()

I am trying to use the jtds driver to connect to a MSSQL database, and can’t get past the Class.forName line in the code. I have done exhausting google searches and found others with the same problem, but no definitive solution or workaround. I’m guessing there must be something wrong with my Jython setup or installation.

 

I am testing with NetBeans 6.7, and have tried this with Jython versions 2.2, 2.5b0+, and 2.5rc3. Within NetBeans, under services, I set up the jtds driver, and was able to define a URL and connect to my database, so I assume the rest of my code will work if I get past the Class.forName problem.

 

The code is pretty basic:

 

from java.sql import DriverManager

from java.lang import Class

 

Class.forName("net.sourceforge.jtds.jdbc.Driver")

 

Error: “java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver”

 

I found one note that mentioned adding “–verify” to the command arguments, but other notes saying that it wasn’t necessary with version 2.5.

 

Any ideas?

 

Thanks.

 

Carl

 

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have 
the opportunity to enter the BlackBerry Developer Challenge. See full prize 
details at: http://p.sf.net/sfu/blackberry
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Frank Wierzbicki | 7 Jul 18:55
Picon
Gravatar

Re: Jython Class.forName()

On Tue, Jul 7, 2009 at 10:39 AM, Carl<s7plc <at> ttlc.net> wrote:
> I am trying to use the jtds driver to connect to a MSSQL database, and can’t
> get past the Class.forName line in the code. I have done exhausting google
> searches and found others with the same problem, but no definitive solution
> or workaround. I’m guessing there must be something wrong with my Jython
> setup or installation.
>
>
>
> I am testing with NetBeans 6.7, and have tried this with Jython versions
> 2.2, 2.5b0+, and 2.5rc3. Within NetBeans, under services, I set up the jtds
> driver, and was able to define a URL and connect to my database, so I assume
> the rest of my code will work if I get past the Class.forName problem.
>
>
>
> The code is pretty basic:
>
>
>
> from java.sql import DriverManager
>
> from java.lang import Class
>
>
>
> Class.forName("net.sourceforge.jtds.jdbc.Driver")
>
>
>
> Error: “java.lang.ClassNotFoundException: java.lang.ClassNotFoundException:
> net.sourceforge.jtds.jdbc.Driver”
>
>
>
> I found one note that mentioned adding “–verify” to the command arguments,
> but other notes saying that it wasn’t necessary with version 2.5.
--verify is gone in 2.5.0.  The one thing to make sure of is that you
are not calling jython with the --boot option (the behavior of
--verify is now the default, --boot puts jython on the boot classpath,
which would cause this problem).

This almost certainly means that you don't have
"net.sourceforge.jtds.jdbc.Driver" on your classpath.  You could test
this another way by trying the following jython code:

from net.sourceforge.jtds.jdbc import Driver

Have you tried the equivalent Java code in your environment?  That's
another good troubleshooting step.

-Frank

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have 
the opportunity to enter the BlackBerry Developer Challenge. See full prize 
details at: http://p.sf.net/sfu/blackberry
Ted Larson Freeman | 8 Jul 22:32

Jython concurrency in the PythonInterpreter class

I am investigating the use of Jython to replace a simple home-grown
scripting language for a Java application. I'm instantiating a
PythonInterpreter and executing an entire jython file at once, like
this:

PythonInterpreter interp = new PythonInterpreter();
interp.execfile("test.py");

It works beautifully for sequential execution of Java method calls,
but I'm uncertain as to the best way to implement concurrent
execution. In my first attempt, using threads, "test.py" included code
like this:

from threading import Thread
Thread(JavaClassA.methodA()).start()
Thread(JavaClassB.methodB()).start()

This is a simple case with no shared data between methodA and methodB.
Both methods write to a log4j log file. The entries in the log file
appear sequentially, labeled as running on thread "MainThread". That
is, the results are the same as if I just do this:

JavaClassA.methodA()
JavaClassB.methodB()

Is the PythonInterpreter class capable of creating new threads? Is
there a better technique for concurrency that I should use instead?

Any comments are greatly appreciated.

Thanks.

Ted

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
Fabio Zadrozny | 9 Jul 01:01
Picon

Pydev 1.4.7 Released

Hi All,

Pydev and Pydev Extensions 1.4.7 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:
-----------------------------------------------------------------

* The interactive console can be used on the remote debugger
* Remote debugger properly redirects contents from the server on multiple runs.
* Providing context-independent completions when other completions are
not available (until now, it only gave those completions for method
parameters)
* The number of chars required to show the context-insensitive
completion can now be customized.
* Fixed problem with Eclipse 3.5: "Invalid Thread Access" when trying
to rename a class

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

* Iron Python support
* Fixed issue when configuring interpreter on Eclipse 3.3 and 3.2 (was
using API only available in 3.4)
* Google App Engine
      o Popup menus for google app engine are now working with eclipse 3.2
      o Fixed issues when google app engine project has spaces in path
* Launching
      o Ctrl+F9 can be used to run as unit-test and select which tests
will be run
      o F9 will now run the current editor based on the project type
      o Changed run icons
      o Run configurations can be created for the project
      o Run as unit-test can have --filter and --tests as a parameter
set in the run configuration
* Shift left can now shift even when there are less chars than the
required indent string
* Top-level modules on .egg files are now properly recognized
* Auto-config fixed
* Fixed problem when .pydevproject was not a parseable xml file (the
pydev package explorer wouldn't work because of that)
* When a new interpreter is created, it's properly selected in the tree
* Code-completion better heuristic when analyzing function return
that's called on self.
* Code-completion in the interactive console now handles import
sections correctly
* Code formatter: Spaces after square and curly braces are no longer
changed when an unary operator is found afterwards
* Fixed problem when recognizing encodings (regexp was not correct)

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

PyDev is a plugin that enables users to use Eclipse for Python, Jython
and Iron Python 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,

Charlie Groves | 9 Jul 03:46
Picon
Gravatar

Re: Jython concurrency in the PythonInterpreter class

Hi Ted,

On Wed, Jul 8, 2009 at 1:32 PM, Ted Larson
Freeman<freeman <at> alumni.stanford.org> wrote:
> In my first attempt, using threads, "test.py" included code
> like this:
>
> from threading import Thread
> Thread(JavaClassA.methodA()).start()
> Thread(JavaClassB.methodB()).start()

Check out the docs for the Thread object:
http://docs.python.org/library/threading.html#thread-objects  The
first argument is the thread group, so you're setting the thread group
for your threads with the results of methodA and methodB.  Since
you're calling methodA and methodB to create arguments for Thread,
they're run in the main thread.

What you want to do is set the target of the Thread to the function or
method you want invoked on the new thread, and then call start.  For
example, the code below calls add on an ArrayList on a separate
thread:

Jython 2.5.0+ (trunk:6503:6505M, Jul 8 2009, 18:36:14)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_13
Type "help", "copyright", "credits" or "license" for more information.
>>> from threading import Thread
>>> from java.util import ArrayList
>>> l = ArrayList()
>>> Thread(target=l.add, args=(5,)).start()
>>> l
[5]

The args keyword arg is a tuple of positional arguments to pass to the
target method.

With your examples, you'd want to do
Thread(target=JavaClassA.methodA).start() and
Thread(target=JavaClassB.methodB).start().

Hope this helps,
Charlie

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
Ted Larson Freeman | 9 Jul 07:36

Re: Jython concurrency in the PythonInterpreter class

Thanks for the clear and amazingly prompt reply, Charlie!

That got me going. At first I was troubled by seeing all of my new
threads labeled "Thread" in the log4j output (is this a bug?). I found
that by assigning my own names to the threads I could see each thread
executing as expected. I ended up with this:

t1 = Thread(target=JavaClassA.methodA, name='t1')
t2 = Thread(target=JavaClassB.methadB, name='t2')
t1.start()
t2.start()
t1.join()
t2.join()

Thanks again,

Ted

On Wed, Jul 8, 2009 at 6:46 PM, Charlie Groves<charlie.groves <at> gmail.com> wrote:
> Hi Ted,
>
> On Wed, Jul 8, 2009 at 1:32 PM, Ted Larson
> Freeman<freeman <at> alumni.stanford.org> wrote:
>> In my first attempt, using threads, "test.py" included code
>> like this:
>>
>> from threading import Thread
>> Thread(JavaClassA.methodA()).start()
>> Thread(JavaClassB.methodB()).start()
>
> Check out the docs for the Thread object:
> http://docs.python.org/library/threading.html#thread-objects  The
> first argument is the thread group, so you're setting the thread group
> for your threads with the results of methodA and methodB.  Since
> you're calling methodA and methodB to create arguments for Thread,
> they're run in the main thread.
>
> What you want to do is set the target of the Thread to the function or
> method you want invoked on the new thread, and then call start.  For
> example, the code below calls add on an ArrayList on a separate
> thread:
>
> Jython 2.5.0+ (trunk:6503:6505M, Jul 8 2009, 18:36:14)
> [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_13
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from threading import Thread
>>>> from java.util import ArrayList
>>>> l = ArrayList()
>>>> Thread(target=l.add, args=(5,)).start()
>>>> l
> [5]
>
> The args keyword arg is a tuple of positional arguments to pass to the
> target method.
>
> With your examples, you'd want to do
> Thread(target=JavaClassA.methodA).start() and
> Thread(target=JavaClassB.methodB).start().
>
> Hope this helps,
> Charlie
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
>
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
Carl | 11 Jul 20:24

Jython Sockets and Strings

I’ve written a Jython socket program that grabs incoming messages and writes them to a database. It works great with my test data.

 

But now, I want to send a message that contains mixed data types. During testing, I had the luxury of encoding and decoding on both ends, but in this case I can’t do that. For instance, I might have this list of data:

 

[‘Test’1,’Test2,100,7,18,’21’]

 

What I want to do is concatenate each item in the list into a string for the socket.send. Note that this needs to be a raw stream of bytes, so converting 100 to a string isn’t possible. Obviously I can’t just use a ‘’.join due to the non-string variables, so I looked at the java libraries and it looks like some combination of jarray, java.lang.string, and outputstream should work. Can someone point me in the right direction?

 

Thanks.

 

Carl

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

Gmane