Re: [Zope] windows python differences
garry saddington wrote: This code on linux works without a problem ispell = os.popen(echo + word + | /opt/scholarpack/ancillary/ispell/bin/ispell -a) ispell.readline sentence = ispell.readline() What if the word is like `rm -rf /` for example? Doing something like that above is completely creazy :( There are actually 3 different popen() variants - 2 of them give you stdin too so you better use this to write the word to ispells stdin. Don't use echo or something like this! ... however on windows it throws a string index out of range at the sentence[0] constructs. the popen command on windows is: ispell=os.popen(echo +word+ \scholarpack\ancillary\ispell\bin\ispell -a) Anyone know what the difference is on the two platforms? As Andreas already said (and you can easily see by comparing the strings, can you? ;) Python has os.path.join() to construct paths for the actual platform. (And since this is a 3rd party tool anyway, you might want to make it configurable - of course not via ZMI) Regards Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] windows python differences
On Fri, 2006-05-19 at 06:06 +0200, Andreas Jung wrote: --On 18. Mai 2006 23:21:50 +0100 garry saddington [EMAIL PROTECTED] wrote: hrows a string index out of range at the sentence[0] constructs. the popen command on windows is: ispell=os.popen(echo +word+ \scholarpack\ancillary\ispell\bin\ispell -a) Anyone know what the difference is on the two platforms? Is this a serious question? Window and Unix use completely different path names (\ vs /). I know this as you can see. It is the returned value from readline that seems to be different. regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] windows python differences
On Fri, 2006-05-19 at 09:01 +0200, Tino Wildenhain wrote: garry saddington wrote: This code on linux works without a problem ispell = os.popen(echo + word + | /opt/scholarpack/ancillary/ispell/bin/ispell -a) ispell.readline sentence = ispell.readline() What if the word is like `rm -rf /` It is impossible for this to happen because of other controls in place. for example? Doing something like that above is completely creazy :( There are actually 3 different popen() variants - 2 of them give you stdin too so you better use this to write the word to ispells stdin. Don't use echo or something like this! ... however on windows it throws a string index out of range at the sentence[0] constructs. the popen command on windows is: ispell=os.popen(echo +word+ \scholarpack\ancillary\ispell\bin\ispell -a) Anyone know what the difference is on the two platforms? As Andreas already said (and you can easily see by comparing the strings, can you? ;) Python has os.path.join() to construct paths for the actual platform. (And since this is a 3rd party tool anyway, you might want to make it configurable - of course not via ZMI) I am not bothered about the paths, that is not the question. Both commands work in their respective environments. It is the sequence[0] that throws the error so I am looking at differences in the way the results are returned from ispell.readline() regards Garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] windows python differences
At Thursday 18/5/2006 19:21, garry saddington wrote: This code on linux works without a problem ispell = os.popen(echo + word + | /opt/scholarpack/ancillary/ispell/bin/ispell -a) ispell.readline sentence = ispell.readline() if (sentence[0] == ''): however on windows it throws a string index out of range at the sentence[0] constructs. Well, if 0 is out of range, the string is empty; readline() returns an empty string when it gets the EOF before any other thing. (You learn this by reading the Python documentation). So, your popen() call gave you an empty file... the popen command on windows is: ispell=os.popen(echo +word+ \scholarpack\ancillary\ispell\bin\ispell -a) ...which is not a surprise, given that command. You must duplicate back quotes inside a string, they are used as escape characters. Again, read the Python manuals... Maybe you should investigate the several popen variants, using echo to construct the command is a bit crazy... Anyone know what the difference is on the two platforms? Surely! But this is not the problem here. Gabriel Genellina Softlab SRL __ Yahoo! Autos. Más de 3.000 vehículos vendidos por mes. ¿Qué esperás para vender el tuyo? Hacelo ahora y ganate un premio de Yahoo! http://autos.yahoo.com.ar/vender/ ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] windows python differences
garry saddington wrote: On Fri, 2006-05-19 at 09:01 +0200, Tino Wildenhain wrote: garry saddington wrote: This code on linux works without a problem ispell = os.popen(echo + word + | /opt/scholarpack/ancillary/ispell/bin/ispell -a) ispell.readline sentence = ispell.readline() What if the word is like `rm -rf /` It is impossible for this to happen because of other controls in place. Well Zope isnt PHP. You dont need to create potential security problems if the fix is much more easier then your bunch of (untested) code you believe prevents it from happen. for example? Doing something like that above is completely creazy :( There are actually 3 different popen() variants - 2 of them give you stdin too so you better use this to write the word to ispells stdin. Don't use echo or something like this! ... however on windows it throws a string index out of range at the sentence[0] constructs. ... I am not bothered about the paths, that is not the question. Both commands work in their respective environments. It is the sequence[0] that throws the error so I am looking at differences in the way the results are returned from ispell.readline() regards Garry Well, what if you try it out in the interactive interpreter? if sequence is an empty list, accessing [0] index will give you that error you see. So your code above does not work as expected. See also the comment regarding echo, Fred made. Regards Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] windows python differences
garry saddington wrote: What if the word is like `rm -rf /` It is impossible for this to happen because of other controls in place. Gary, Just to echo what others have said: this is all insane. There are much better ways of communicating with other processes and spawning them off. In Zope 2.9, you have Python 2.4's subprocess module which will let you set up nice pipes to communicate without opening unnecessary gaping security holes. Even so, there are other examples of using spell checkers which will help you a little in the don't-blow-my-foot-off department... cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] windows python differences
This code on linux works without a problem ispell = os.popen(echo + word + | /opt/scholarpack/ancillary/ispell/bin/ispell -a) ispell.readline sentence = ispell.readline() if (sentence[0] == ''): parts = string.split(sentence, : ) gluedwords = parts[1] words = string.split(gluedwords,, ) length = len(words) words[length-1] = words[length-1][0:len(words[length-1]) - 1] return [word] + words elif (sentence[0] == '#') or (sentence[0] == '?'): return [word] else: return [] however on windows it throws a string index out of range at the sentence[0] constructs. the popen command on windows is: ispell=os.popen(echo +word+ \scholarpack\ancillary\ispell\bin\ispell -a) Anyone know what the difference is on the two platforms? regards garry ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )