Hi<br>Sorry about that. Here is the full question:<br>I wonder if you can help me. I am using pexpect with python to access remote machines and run commands on them. I pass commands into code like so:<br><br>def cmd(self, cmd):
<br> pp=[ "|", "]", "[", "(", ")", "$", "?", "*", ".", ":"]<br> expcmd=cmd<br> for element in pp:<br>
expcmd=expcmd.replace(element, "\\%s" % element)<br> self.spawn.setecho(False)<br> self.spawn.sendline(cmd)<br> self.spawn.expect(expcmd)<br> self.spawn.expect(self.prompt
)<br> return self.spawn.before<br><br>The above code is supposed to match the command, then match the prompt and then return what is in between. Since pexpect uses regular expressions to match what it sees, the command needs to have certain characters backslashed. The problem is that on some remote shells hidden characters are introduced that causes the expect statement (
self.spawn.expect(expcmd)) to timeout without matching. In perl there is a way to translate any character with an ascii value of less than 32 to "" so that all hidden characters are removed. Can this be done in python? Can this be applied to the regular expression used by pexpect?
<br><br>Bewildered<br><br><div><span class="gmail_quote">On 02/10/06, <b class="gmail_sendername"><a href="mailto:python-list-request@python.org">python-list-request@python.org</a></b> <<a href="mailto:python-list-request@python.org">
python-list-request@python.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="direction: ltr;">Send Python-list mailing list submissions to
<br> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:python-list@python.org">python-list@python.org</a><br><br>To subscribe or unsubscribe via the World Wide Web, visit<br> <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">
http://mail.python.org/mailman/listinfo/python-list</a><br>or, via email, send a message with subject or body 'help' to<br> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:python-list-request@python.org">
python-list-request@python.org</a><br><br>You can reach the person managing the list at<br> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:python-list-owner@python.org">python-list-owner@python.org
</a><br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Python-list digest..."<br><br></div><br>Today's Topics:<br><br> 1. Re: Problems wth os.stat().st_mtime on Mac (Michael Glassford)
<br> 2. Re: Help with ConfigParser (TonyHa)<br> 3. regular expressions in the pexpect module for python (Mark Devine)<br> 4. commands.getstatusoutput result is not command line exit<br> value!!! (Hari Sekhon)<br>
5. PyCon proposals (was Re: PATCH: Speed up direct string<br> concatenation by 20+%!) (Aahz)<br> 6. Re: Python/UNO/OpenOffice? (John Machin)<br> 7. Re: Help with ConfigParser (Enrico)<br> 8. How to coerce a list of vars into a new type? (Matthew Wilson)
<br> 9. Making posts to an <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://ASP.NET" target="_blank">ASP.NET</a> webform. (Bernard)<br> 10. How can I make a class that can be converted into an int?
<br> (Matthew Wilson)<br> 11. Sort by domain name? (js )<br><br><br><br>---------- Forwarded message ----------<br>From: Michael Glassford <<a href="mailto:glassfordm@hotmail.com">glassfordm@hotmail.com</a>><br>
To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Mon, 02 Oct 2006 10:15:26 -0400<br>Subject: Re: Problems wth os.stat().st_mtime on Mac<br>Martin v. Löwis wrote:<br>> Michael Glassford schrieb:
<br>>> Although not mentioned in the Python 2.5 News, apparently there was a<br>>> similar change on Mac that I'm having some problems with. On the Mac,<br>>> just as on Windows, os.stat().st_mtime now returns a float instead of an
<br>>> integer.<br>><br>> It's isn't really new; os.stat_float_times was introduced in Python 2.3.<br>> What changed in 2.5 is that it is now true. See<br>><br>> <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://docs.python.org/whatsnew/modules.html" target="_blank">
http://docs.python.org/whatsnew/modules.html</a><br><br>Thanks, I wasn't aware of os.stat_float_times. This helps me a lot,<br>since I can turn off the floating point times in places until<br>incompatible code can be fixed.
<br><br>><br>>> a) Why the difference between machines?<br>><br>> You really have to delve into OSX to answer this question. Several<br>> reasons are possible:<br>> - there is a change in the operating system implementations
<br><br>Possible, I guess, although I don't know how to find out and there's<br>likely nothing I could do about it even if I did.<br><br>> - you are using different Python versions<br><br>Python 2.5 on both.<br><br>> - you are using different file systems
<br><br>This is the first thing I thought of, but all of the drives are<br>formatted using "Mac OS Extended (Journalled)", which I assumed meant<br>they are using the same file system.<br><br>><br>>> b) Why do most files on this machine have ".0", while some (generally
<br>>> those I created myself using Python 2.5, I think) don't?<br>><br>> Hard to tell. Maybe the software that created those files explicitly<br>> set a time stamp on them, and failed to use the API that supports
<br>> subsecond resolution in setting those time stamps.<br>><br>>> I understand how the results can be different: the os.stat() function<br>>> returns a posix.stat_result object, which gives back an integer value
<br>>> for the mtime if you call __str__ or __repr__, or if you iterate on it;<br>>> and a float if you get the st_mtime attribute. But I would consider it a<br>>> bug that the results are different: a float should be returned in either
<br>>> case.<br>><br>> That's for backwards compatibility: You shouldn't use the tuple<br>> interface anymore, but use st_mtime for new code. This will always<br>> be a float. OTOH, the tuple interface will continue to return
<br>> integers forever<br><br><snip><br><br>OK, thanks for the explanation.<br><br>Mike<br><br><br><br><br><br>---------- Forwarded message ----------<br>From: "TonyHa" <<a href="mailto:tony_ha2002@yahoo.co.uk">
tony_ha2002@yahoo.co.uk</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: 2 Oct 2006 07:29:49 -0700<br>Subject: Re: Help with ConfigParser<br>Hello Peter,<br><br>Thanks for your help, and it works now!
<br><br>Tony.<br><br>Peter Otten wrote:<br>> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:tony.ha@philips.com">tony.ha@philips.com</a> wrote:<br>><br>> > Question: How can I pervent ConfigParse to convert Upper case yo lower
<br>> > case??, thanks.<br>><br>> <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://docs.python.org/dev/lib/RawConfigParser-objects.html" target="_blank">http://docs.python.org/dev/lib/RawConfigParser-objects.html
</a><br>><br>> """<br>> optionxform(option)<br>><br>> Transforms the option name option as found in an input file or as passed in<br>> by client code to the form that should be used in the internal structures.
<br>> The default implementation returns a lower-case version of option;<br>> subclasses may override this or client code can set an attribute of this<br>> name on instances to affect this behavior. Setting this to str(), for
<br>> example, would make option names case sensitive.<br>> """"<br>><br>> If you don't pass defaults:<br>><br>> config = ConfigParser()<br>> config.optionxform = str<br>> # ...
<br>><br>> Or, to be on the safe side:<br>><br>> class MyCasePreservingConfigParser(ConfigParser):<br>> optionxform = str<br>><br>> config = MyCasePreservingConfigParser()<br>> # ...<br>><br>
> Peter<br><br><br><br><br><br>---------- Forwarded message ----------<br>From: "Mark Devine" <<a href="mailto:mfmdevine@gmail.com">mfmdevine@gmail.com</a>><br>To: <a href="mailto:python-list@python.org">
python-list@python.org</a><br>Date: Mon, 2 Oct 2006 15:43:35 +0100<br>Subject: regular expressions in the pexpect module for python<br>Hi<br>I wonder if you can help me. I am using pexpect with python to access remote machines and run commands on them. I pass commands into code like so:
<br><br>def cmd(self, cmd):<br> pp=[ "|", "]", "[", "(", ")", "$", "?", "*", ".", ":"]
<br> expcmd=cmd<br> for element in pp:<br> expcmd=expcmd.replace(element, "\\%s" % element)<br> self.spawn.setecho(False)<br> self.spawn.sendline(cmd)<br> self.spawn.expect
(expcmd)<br> self.spawn.expect(self.prompt)<br> return self.spawn.before<br><br>The above code is supposed to match the command, then match the prompt and then return what is in between. Since pexpect uses regular expressions to match what it sees
<br>
<br><br>---------- Forwarded message ----------<br>From: Hari Sekhon <<a href="mailto:hpsekhon@googlemail.com">hpsekhon@googlemail.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>
Date: Mon, 02 Oct 2006 15:45:12 +0100<br>Subject: commands.getstatusoutput result is not command line exit value!!!<br>I'm running a command like<br><br>import commands<br>result = commands.getstatusoutput('somecommand')<br>
print result[0]<br>3072<br><br><br>However, this exit code made no sense so I ran it manually from the<br>command line in bash on my linux server and it gives the exit code as<br>12, not this weird 3072 number.<br><br>So I tried
os.system('somecommand') in the interactive python shell and<br>it too returned the same result for the exit code as the unix shell, 12,<br>but re-running the commands.getstatusoutput() with the exact same<br>command still gave 3072.
<br><br><br>Is commands.getstatusoutput() broken or something?<br><br><br>-h<br><br>--<br>Hari Sekhon<br><br><br><br><br><br>---------- Forwarded message ----------<br>From: <a href="mailto:aahz@pythoncraft.com">aahz@pythoncraft.com
</a> (Aahz)<br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: 2 Oct 2006 07:43:09 -0700<br>Subject: PyCon proposals (was Re: PATCH: Speed up direct string concatenation by 20+%!)<br>In article <
<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:1159762765.943691.139690@b28g2000cwb.googlegroups.com">1159762765.943691.139690@b28g2000cwb.googlegroups.com</a>>,<br>Larry Hastings <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:larry@hastings.org">
larry@hastings.org</a>> wrote:<br>>Steve Holden wrote:<br>>><br>>> I think your project might make a very<br>>> interesting PyCon paper for people who were thinking about joining the<br>>> development effort but hadn't yet started.
<br>><br>>Perhaps; I've never been to PyCon, but it might be fun to give a<br>>presentation there. That said, it would be way more relevant if the<br>>patch got accepted, don'tcha think?<br><br>Not really. The principles involved are timeless, and I guarantee you a
<br>large audience regardless of whether the patch gets accepted (provided<br>you specify an appropriate presentation title and summary).<br>--<br>Aahz (<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:aahz@pythoncraft.com">
aahz@pythoncraft.com</a>) <*> <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.pythoncraft.com/" target="_blank">http://www.pythoncraft.com/</a><br><br>"LL YR VWL R BLNG T S" --
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.nancybuttons.com" target="_blank">www.nancybuttons.com</a><br><br><br><br><br>---------- Forwarded message ----------<br>From: "John Machin" <
<a href="mailto:sjmachin@lexicon.net">sjmachin@lexicon.net</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: 2 Oct 2006 07:46:53 -0700<br>Subject: Re: Python/UNO/OpenOffice?<br><br>
olive wrote:<br>> ... and you have to start your py file with:<br>><br>> import uno, sys, socket<br>> from com.sun.star.beans import PropertyValue<br>><br>> ... and your start_oo_server.bat file with:<br>
><br>> @SET PYTHONPATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program<br>> Files\OpenOffice.org 2.0\program\python-core-2.3.4\lib<br>> @SET PATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program<br>
> Files\OpenOffice.org 2.0\program\python-core-2.3.4\bin<br><br>Many thanks for all that, olive; I made the minimal hacks to make it<br>open an XLS ffile, and it worked!<br>I'll try to see why that worked and my previous experiment crashed
<br>inside a DLL.<br>Cheers,<br>John<br><br><br><br><br><br>---------- Forwarded message ----------<br>From: "Enrico" <<a href="mailto:lux@perpetua.org">lux@perpetua.org</a>><br>To: <a href="mailto:python-list@python.org">
python-list@python.org</a><br>Date: Mon, 2 Oct 2006 16:53:04 +0200<br>Subject: Re: Help with ConfigParser<br>Hi,<br>from the documentation:<br><br>optionxform(option)<br><br>Transforms the option name option as found in an input file or as passed in
<br>by client code to the form that should be used in the internal structures.<br>The default implementation returns a lower-case version of option;<br>subclasses may override this or client code can set an attribute of this
<br>name on instances to affect this behavior. Setting this to str(), for<br>example, would make option names case sensitive.<br><br>Bye,<br>Enrico<br><br><br><br><br><br><br>---------- Forwarded message ----------<br>From: Matthew Wilson <
<a href="mailto:matt@tplus1.com">matt@tplus1.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Mon, 02 Oct 2006 14:53:10 GMT<br>Subject: How to coerce a list of vars into a new type?
<br><br>I want to verify that three parameters can all be converted into<br>integers, but I don't want to modify the parameters themselves.<br><br>This seems to work:<br><br> def f(a, b, c):<br><br> a, b, c = [int(x) for x in (a, b, c)]
<br><br>Originally, I had a bunch of assert isinstance(a, int) statements at the<br>top of my code, but I decided that I would rather just check if the<br>parameters can be converted into integers.<br><br>The new a, b, and c are all different objects, with different id values.
<br>Anyhow, this all seems like black magic to me. Can anyone explain what<br>is going on?<br><br>Is it as simple as call-by-value?<br><br><br><br><br>--<br>A better way of running series of SAS programs:<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles" target="_blank">
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles</a><br><br><br><br><br>---------- Forwarded message ----------<br>From: "Bernard" <<a href="mailto:bernard.chhun@gmail.com">bernard.chhun@gmail.com</a>
><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: 2 Oct 2006 07:55:23 -0700<br>Subject: Making posts to an <a href="http://ASP.NET">ASP.NET</a> webform.<br>hiya everyone,<br><br>I've made this little webcrawler using BeautifulSoup, urllib and
<br>urllib2. I've been encountering <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://ASP.NET" target="_blank">ASP.NET</a> Forms recently and I can't seem<br>to make a proper post to some of them. My post function has been doing
<br>great until this particular website.<br>Here's some explanations first so that you guys understands my<br>problem...<br><br>Usually there are 8 hidden inputs spread all over the web page:<br>__EVENTTARGET --> that is the id of the control that is assigned by the
<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://ASP.NET" target="_blank">ASP.NET</a> engine. It is usually in this particular form<br>"dg_Result$_ctl2$linkbtn1" The javascript function DoPostback usually
<br>replaces the '$' for a ':' before doing the real post. Some other<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://ASP.NET" target="_blank">ASP.NET</a> page doesn't.<br>__EVENTARGUMENT --> nothing's here usually.
<br>__ScrollTop --> its value is often 0<br>__ScrollLeft --> same as __ScrollTop<br>__ValidationSummary --> usually empty<br>__VIEWSTATEENCRYPTED --> an encrypted string. I don't know what it<br>means nor what it does.
<br>__EVENTVALIDATION --> an encrypted string. I don't know what it means<br>nor what it does.<br>__VIEWSTATE --> the encrypted state of the current control. the state<br>of a datagrid for example.<br><br>I extract all those values using regexes on the web page, build a
<br>dictionnary out of all those values and encrypt the whole thing using<br>urllib.urlencode(). Afterwards I extract the form action and post the<br>whole thing with cookies enabled. This procedure works like a charm.<br>
<br>The website I've just encounted has only 3 of the 8 hidden inputs.<br>(EVENTTARGET, EVENTARGUMENT & VIEWSTATE ).<br>I tried posting the whole thing using only these 3 values & nada.<br>I then tried posting the whole thing using all empty values for the 5
<br>remaining values...still nothing.<br><br>Has anyone tried what I'm doing? and if you tried how have you<br>succeeded getting the data back after the post action?<br><br>thanks for any tips!<br><br>cP<br><br><br><br><br>
<br>---------- Forwarded message ----------<br>From: Matthew Wilson <<a href="mailto:matt@tplus1.com">matt@tplus1.com</a>><br>To: <a href="mailto:python-list@python.org">python-list@python.org</a><br>Date: Mon, 02 Oct 2006 14:59:05 GMT
<br>Subject: How can I make a class that can be converted into an int?<br>What are the internal methods that I need to define on any class so that<br>this code can work?<br><br>c = C("three")<br><br>i = int(c) # i is 3
<br><br>I can handle the part of mapping "three" to 3, but I don't know what<br>internal method is called when int(c) happens.<br><br>For string conversion, I just define the __str__ method. What's the<br>equivalent for int? For float, too, while I'm at it?
<br><br>TIA<br><br>Matt<br><br>--<br>A better way of running series of SAS programs:<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles" target="_blank">
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles</a><br><br><br><br><br>---------- Forwarded message ----------<br>From: "js " <<a href="mailto:ebgssth@gmail.com">ebgssth@gmail.com</a>><br>To: <a href="mailto:python-list@python.org">
python-list@python.org</a><br>Date: Tue, 3 Oct 2006 00:08:06 +0900<br>Subject: Sort by domain name?<br>Hi list,<br><br>I have a list of URL and I want to sort that list by the domain name.<br><br>Here, domain name doesn't contain subdomain,
<br>or should I say, domain's part of 'www', mail, news and en should be excluded.<br><br>For example, if the list was the following<br>------------------------------------------------------------<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.google.com" target="_blank">
http://mail.google.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://reader.google.com" target="_blank">http://reader.google.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.yahoo.co.uk" target="_blank">
http://mail.yahoo.co.uk</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://google.com" target="_blank">http://google.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.yahoo.com" target="_blank">
http://mail.yahoo.com</a><br>------------------------------------------------------------<br><br>the sort's output would be<br>------------------------------------------------------------<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://google.com" target="_blank">
http://google.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.google.com" target="_blank">http://mail.google.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://reader.google.com" target="_blank">
http://reader.google.com</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.yahoo.co.uk" target="_blank">http://mail.yahoo.co.uk</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.yahoo.com" target="_blank">
http://mail.yahoo.com</a><br>------------------------------------------------------------<br><br>As you can see above, I don't want to<br><br><br>Thanks in advance.<br><br><br><br>--<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">
http://mail.python.org/mailman/listinfo/python-list</a><br><br></blockquote></div><br>