Re: [Tutor] Web browser

2005-06-13 Thread Kent Johnson
Liam Clarke wrote:
> Can Beautiful Soup execute scripts? I was trying to scrape using 
> urllib2, and the Javascripts messed my navigation up something chronic.

No, Beautiful Soup won't run scripts. AFAIK the only way to access the web from 
Python and execute JavaScripts is to automate a browser and use the browser's 
JavaScript engine. (e.g. Pamie, COM, Selenium 
http://confluence.public.thoughtworks.org/display/SEL/Home)

If Java/Jython is an option you could try HttpUnit which includes a JS 
interpreter.
http://httpunit.sourceforge.net/

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Strange IndexError

2005-06-13 Thread Willi Richert
Hi,

I used the same Pyro code, but this time with the release versions of player 
and stage. This time python crashed with a segfault:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1273599056 (LWP 27633)]
tupleiter_next (it=0xb6393cec) at Objects/tupleobject.c:797
797 Py_INCREF(item);
(gdb) bt
#0  tupleiter_next (it=0xb6393cec) at Objects/tupleobject.c:797
#1  0x00ada39f in PyIter_Next (iter=0x9) at Objects/abstract.c:2225
#2  0x00b2d6f0 in eval_frame (f=0x815840c) at Python/ceval.c:2091
#3  0x00b3197b in eval_frame (f=0x814dcdc) at Python/ceval.c:3518
#4  0x00b3197b in eval_frame (f=0x815665c) at Python/ceval.c:3518
#5  0x00b3197b in eval_frame (f=0x81561e4) at Python/ceval.c:3518
#6  0x00b3209e in PyEval_EvalCodeEx (co=0xb7c0a4a0, globals=0x9, locals=0x0, 
args=0xb637e218, argcount=1, kws=0x0, kwcount=0, defs=0x0, defcount=0, 
closure=0x0)
at Python/ceval.c:2663
#7  0x00aede2e in function_call (func=0xb7c03d84, arg=0xb637e20c, kw=0x0) at 
Objects/funcobject.c:504
#8  0x00ada607 in PyObject_Call (func=0xb0b4f1, arg=0x0, kw=0x0) at 
Objects/abstract.c:1755
#9  0x00ae1d98 in instancemethod_call (func=0xb7c03d84, arg=0xb637e20c, 
kw=0x0) at Objects/classobject.c:2433
#10 0x00ada607 in PyObject_Call (func=0xb0b4f1, arg=0x0, kw=0x0) at 
Objects/abstract.c:1755
#11 0x00b2fb7f in eval_frame (f=0x811bbc4) at Python/ceval.c:3644
#12 0x00b3197b in eval_frame (f=0x8079b34) at Python/ceval.c:3518
#13 0x00b3197b in eval_frame (f=0x80fda8c) at Python/ceval.c:3518
#14 0x00b3209e in PyEval_EvalCodeEx (co=0xb7cdf220, globals=0x9, locals=0x0, 
args=0xb7bffb98, argcount=1, kws=0x0, kwcount=0, defs=0x0, defcount=0, 
closure=0x0)
at Python/ceval.c:2663
#15 0x00aede2e in function_call (func=0xb7ceca3c, arg=0xb7bffb8c, kw=0x0) at 
Objects/funcobject.c:504
#16 0x00ada607 in PyObject_Call (func=0xb0b4f1, arg=0x0, kw=0x0) at 
Objects/abstract.c:1755
#17 0x00ae1d98 in instancemethod_call (func=0xb7ceca3c, arg=0xb7bffb8c, 
kw=0x0) at Objects/classobject.c:2433
#18 0x00ada607 in PyObject_Call (func=0xb0b4f1, arg=0x0, kw=0x0) at 
Objects/abstract.c:1755
#19 0x00b2c1b0 in PyEval_CallObjectWithKeywords (func=0x0, arg=0xb7fa202c, 
kw=0x0) at Python/ceval.c:3346
#20 0x00b54072 in t_bootstrap (boot_raw=0x8119840) 
at ./Modules/threadmodule.c:180
#21 0x00baa341 in start_thread () from /lib/tls/libpthread.so.0
#22 0x00a29fee in clone () from /lib/tls/libc.so.6


Is this Python-related or some other application's problem?

wr
Am Donnerstag, 2. Juni 2005 21:00 schrieb Danny Yoo:
> On Thu, 2 Jun 2005, Willi Richert wrote:
> > my app is a Pyrobot (http://emergent.brynmawr.edu/~dblank/pyro/)
> > simulation which connects to PlayerStage (playerstage.sf.net)  to
> > simulate three Pioneer robots. These are controlled using NeedBrain.py.
> > In parallel to the three NeedBrains there is one MonitorBrain running
> > for some management tasks, so I have
> >  four parallel running classes.
>
> Hi Willi,
>
> I think you may want to bring this up on comp.lang.python: I have a strong
> feeling I'm in over my head.  *grin* The experts on comp.lang.python
> should be able to better pinpoint the exact problem.
>
>
> The code that prints that peculiar error message is at the very core of
> Python's object implementation in doing object equality checking:
>
> /*** Objects/object.c, about line 441 in Python 2.4 source ***/
> /* Helper to warn about deprecated tp_compare return values.  Return:
>-2 for an exception;
>-1 if v <  w;
> 0 if v == w;
> 1 if v  > w.
>(This function cannot return 2.)
> */
> static int
> adjust_tp_compare(int c)
> {
>   if (PyErr_Occurred()) {
>   if (c != -1 && c != -2) {
>   PyObject *t, *v, *tb;
>   PyErr_Fetch(&t, &v, &tb);
>   if (PyErr_Warn(PyExc_RuntimeWarning,
>  "tp_compare didn't return -1 or -2 "
>  "for exception") < 0) {
>   Py_XDECREF(t);
>   Py_XDECREF(v);
>   Py_XDECREF(tb);
>   }
>   else
>   PyErr_Restore(t, v, tb);
> /**/
>
>
> We can reason that PyErr_Occurred() somehow returned true, and that the
> error information is being captured in C code throught the 't', 'v' and
> 'tb' variables.  Those three variables are ultimately responsible for
> what's printing out:
>
> IndexError: tuple assignment index out of range
>
> and the output that talks about 'tp_compare' shows up because of the
> PyErr_Warn call.  That explains why we see both error messages.
>
>
>
> I'm staring at the code a little more; there's a bit of code around line
> 229 that bothers me a bit:
>
> ##
> try:
> self._markerObject = self.get("robot/fiducial/id")(self.marker)
> finally:
> if not self._markerObject:
> s

Re: [Tutor] Strange IndexError

2005-06-13 Thread Danny Yoo


On Mon, 13 Jun 2005, Willi Richert wrote:

> I used the same Pyro code, but this time with the release versions of
> player and stage. This time python crashed with a segfault:


Hi Willi,

If you see a segfault like this, it's almost definitely a bug in a
third-party module.  It is possible that the bug is in Python itself, but
since the Python core has been so well-tested, this is unlikely.


Bring this up to the Pyro folks so they can trace what looks like an
incorrect refcount problem somewhere in their C code or SWIG bindings.  I
don't think there's much else that you can do at this point, unless you
have written your code to use some substitute to Pyro.

If I had time, I'd be willing to look at the Pyro code and see what's
going on.  But the Pyro folks are probably the people to pester about
this, since this looks like a problem in their extension code.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Passing command line argument in function

2005-06-13 Thread Gary Taylor
I'm trying to pass the name of a file as the first argument
to the ftp.storbinary function(?) below.  The only thing I
can get to work is the real file name hard coded as the
argument.  I've tried parenthesis, single quotes, double
quotes, and many combinations of the previous. I've tried
passing sys.argv[1] directly as well, although with fewer
experiments.
 
I invoke this as below and the output is what I would
expect, but the file name on the ftp server is never
correct.


What is the correct way to do this? 


$ ./garyftp.py align.ps
align.ps



---
Python 2.3.4 on Linux.


---
#!/usr/bin/python
import sys
from ftplib import FTP

file_to_transfer = sys.argv[1]

ftp = FTP()
ftp.connect("myserver")
ftp.login("myusername", "mypasswd")


ftp.storbinary(stor file_to_transfer, open(file_to_transfer,"r"))

print file_to_transfer
ftp.quit()
--

Thanks,
Gary

[EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Passing command line argument in function

2005-06-13 Thread Liam Clarke
What path is the file? On 6/14/05, Gary Taylor <[EMAIL PROTECTED]> wrote:
I'm trying to pass the name of a file as the first argumentto the ftp.storbinary function(?) below.  The only thing Ican get to work is the real file name hard coded as theargument.  I've tried parenthesis, single quotes, double
quotes, and many combinations of the previous. I've triedpassing sys.argv[1] directly as well, although with fewerexperiments.I invoke this as below and the output is what I wouldexpect, but the file name on the ftp server is never
correct.What is the correct way to do this?$ ./garyftp.py align.psalign.ps---Python 2.3.4 on Linux.
---#!/usr/bin/pythonimport sysfrom ftplib import FTPfile_to_transfer = sys.argv[1]ftp = FTP()ftp.connect("myserver")ftp.login("myusername", "mypasswd")
ftp.storbinary(stor file_to_transfer, open(file_to_transfer,"r"))print file_to_transferftp.quit()--Thanks,Gary[EMAIL PROTECTED]
___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
-- 'There is only one basic human right, and that is to do as you damn well please.And with it comes the only basic human duty, to take the consequences.'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor