Re: [Tutor] Tail -f problem

2005-08-31 Thread Alberto Troiano
Hey Nick

About the mysql upgrade (by the way thanks for the reply) I have downloaded 
the rpm fron mysql.com along with the installation manual..I will give it a 
try

The code you sent in the hyperlink looks neat...I will try it out since the 
page hasn't much documentation about this example in particular

Thanks a lot

Alberto

>From: "Nick Lunt" <[EMAIL PROTECTED]>
>To: "Alberto Troiano" <[EMAIL PROTECTED]>, 
>Subject: Re: [Tutor] Tail -f problem
>Date: Wed, 31 Aug 2005 22:38:42 +0100
>
>Hi Alberto,
>
>
> > -Original Message-
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] Behalf Of
> > Alberto Troiano
> > Sent: 31 August 2005 22:01
> > To: tutor@python.org
> > Subject: [Tutor] Tail -f problem
> >
> >
> > Hey
> >
>I thought about tail-f
> > /var/log/radacct/max/detail but this thing opens a console and I
> > won't end
> > but how can I get the output of the command to python..
>
>Have a look here for a possible solution to your tail -f problem
>http://twistedmatrix.com/projects/core/documentation/examples/filewatch.py
>
>
> > I know the second option has nothing to do with this forum but if anyone
> > knows of any manual to upgrade MySQL over Linux Red HAt I would 
>appreciate
>
>If your using a recent Redhat then try this as root (im on a windows box at
>the moment so this is untested)
>
>$ yum upgrade mysql mysql-server
>
>Naturally this will only work if your current mysql install is an RPM.
>
>Cheers
>Nick .
>
>
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


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


Re: [Tutor] Tail -f problem

2005-08-31 Thread Nick Lunt
Hi Alberto,


> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> Alberto Troiano
> Sent: 31 August 2005 22:01
> To: tutor@python.org
> Subject: [Tutor] Tail -f problem
>
>
> Hey
>
I thought about tail-f
> /var/log/radacct/max/detail but this thing opens a console and I
> won't end
> but how can I get the output of the command to python..

Have a look here for a possible solution to your tail -f problem
http://twistedmatrix.com/projects/core/documentation/examples/filewatch.py


> I know the second option has nothing to do with this forum but if anyone
> knows of any manual to upgrade MySQL over Linux Red HAt I would appreciate

If your using a recent Redhat then try this as root (im on a windows box at
the moment so this is untested)

$ yum upgrade mysql mysql-server

Naturally this will only work if your current mysql install is an RPM.

Cheers
Nick .


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


[Tutor] Tail -f problem

2005-08-31 Thread Alberto Troiano
Hey

I'm still working with this RADIUS system over Red Hat 9.0, mysql 3.23 and 
python 2.2.2

I ran to another problem.I have a file that is written by the RADIUS 
server (for those who don't know RADIUS is an authentication Service). The 
file contains the detail of the RADIUS, the server writes the STOP and START 
signals to this filebelow is the detail of the file.
What I need to do is a program that check when the file gets an input and 
analyze only the text that has entered...I thought about tail-f 
/var/log/radacct/max/detail but this thing opens a console and I won't end 
but how can I get the output of the command to python..
This is one of two solutionsthe other would be Upgrade the MySQL Server 
to version 4.1.11 which I don't have idea how to

file desc
---
Date
  User-Name
  NAS-IP-ADDRESS
  and a long list of variables

---
end of file desc

I know the second option has nothing to do with this forum but if anyone 
knows of any manual to upgrade MySQL over Linux Red HAt I would appreciate

Thanks in advanced

Alberto


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


Re: [Tutor] Popen and Prompting

2005-08-31 Thread Faulconer, Steven M.
Danny,

Thanks for the response. We looked at using pexpect (I'm a UNIX guy at
heart), but we have variable command prompts, that may or may not show up,
with this program, so expect/pexpect would be difficult. John's suggestion
was to add some sort of unique ID as a good idea, but won't work in this
situation. I guess in the end, doing something with pexpect would be the way
to go if I needed to. This issue has been resolved in another way (per my
last message to the list).

Thanks again for the response,
Steven

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 31, 2005 3:06 PM
To: Faulconer, Steven M.
Cc: tutor@python.org
Subject: Re: [Tutor] Popen and Prompting



On Tue, 30 Aug 2005, Faulconer, Steven M. wrote:

> Been digging through the web and the archives for the tutor list and
> can't seem to locate an answer to my question. It is probably out there,
> but my searching skills are failing me. I recently wrote a GUI for
> several command line programs using Tkinter. Everything is working quite
> well, until I ran into one program that actually prompts for some input.

Hi Steven,

This is a common problem.  The Unix folks have traditionally used a
program called "Expect" to automate talking with interactive external
processes. There's a Python equivalent to Expect: take a look at the
'pexpect' module.  Here you go:

http://pexpect.sourceforge.net/

The documentation on that page has a few examples that should help you get
started.  Best of wishes to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing to XML file with minidom

2005-08-31 Thread Travis Spencer
On 8/31/05, Danny Yoo <[EMAIL PROTECTED]> wrote:
> Hi Travis,

Hey Danny,

> Putting pure binary bytes in an XML file has a flaw: the issue is that the
> binary bytes themselves might contain characters that could be interpreted
> as XML!  Even if we wrap the content in CDATA, there's nothing that really
> stops the bytes from containing the characters "]]>" to prematurely close
> off the CDATA tag.

Oh, sure.  I didn't think that through, and if I had, I wouldn't have
know how to work around it.

> To get around this, we can use a technique called "ascii-armor" to wrap
> protection around the troublesome binary text.
> 
> http://en.wikipedia.org/wiki/ASCII_armor

Brilliant.  I won't forget the term "ascii-armor" if I ever find
myself in Johan's shoes and I've forgotten the details.

> (Hey, look, an Elf!  *grin*)

HA!

> Hope this helps!

Tremendously.  Thanks, Danny!

-- 

Regards,

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


Re: [Tutor] Closing SimpleXMLRPCServer properly

2005-08-31 Thread Danny Yoo
> class StoppableXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
> def serve_forever(self):
> """to stop this server: register a function in the class
> that uses it which sets server.stop to True."""
> self.stop = False
> while not self.stop:
> self.handle_request()
>
> Here's the code where I start the server...
>
> try:
> self.server.serve_forever()
> finally:
> self.server.server_close()
> self.log('server closed')
>
> >From another thread, I set the server's stop attribute to False, so the
> server stops running. It exits the try block, runs server_close(), then I
> get the message 'server closed'...
>
> ...but when I try to use the port that the server's bound to again, it
> takes a very long time (while i try to use the port, catch the
> exception, sleep, try again) until it becomes free. Is there something
> else I need to call to ensure that the port is released cleanly? Is this
> an OS-specific thing out of my control? (I'm running Debian Linux.)


Hi Lawrence,

It's TCP specific.  When the server shuts down, the port is in a TIME_WAIT
state that causes the port to wait until things are cleanly shut down.

For more information on TIME_WAIT, see:

http://www.developerweb.net/sock-faq/detail.php?id=13


Anyway, you can force the issue, get the server to "reuse" the address, by
setting the "allow_reuse_address" attribute on your server.

##
class StoppableXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
"""Override of TIME_WAIT"""
allow_reuse_address = True

def serve_forever(self):
self.stop = False
while not self.stop:
self.handle_request()
##

See:

http://www.python.org/doc/lib/module-SocketServer.html

for a brief mention of allow_reuse_address.


One of these days, I have to read Richard Stevens's book on TCP to better
understand what exactly is going on.  I have to admit that I don't
understand the TCP model quite well yet.


Best of wishes to you!

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


Re: [Tutor] Popen and Prompting

2005-08-31 Thread Danny Yoo


On Tue, 30 Aug 2005, Faulconer, Steven M. wrote:

> Been digging through the web and the archives for the tutor list and
> can't seem to locate an answer to my question. It is probably out there,
> but my searching skills are failing me. I recently wrote a GUI for
> several command line programs using Tkinter. Everything is working quite
> well, until I ran into one program that actually prompts for some input.

Hi Steven,

This is a common problem.  The Unix folks have traditionally used a
program called "Expect" to automate talking with interactive external
processes. There's a Python equivalent to Expect: take a look at the
'pexpect' module.  Here you go:

http://pexpect.sourceforge.net/

The documentation on that page has a few examples that should help you get
started.  Best of wishes to you!

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


Re: [Tutor] PYTHON????

2005-08-31 Thread Danny Yoo


On Mon, 29 Aug 2005 [EMAIL PROTECTED] wrote:

>  How does a calculator multiply? I want to create a computer software
> that can multiply. How do I program the computer to multiply?

Hello,

Have you had a chance to look at:

http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

There are a few tutorial there that should help you get started.  Almost
every one of them talks about how to get the computer to do basic
arithmetic.

If you have questions about the tutorials, please feel free to ask here.

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


Re: [Tutor] Writing to XML file with minidom

2005-08-31 Thread Danny Yoo

> > One snag that I found is that the des encryption that I used for the
> > data that is written back, it is not parsed correctly when the file is
> > read again with the new data in it. There is non-printable characters
> > or non-ascii chars in that gives errors from expat when the contents
> > is parsed. I had to use a different encryption algorithm. I am going
> > to do some tests on it now.
>
> Put the cyphertext in a CDATA section, so the parser knows to ignore
> its contents:
>
> 
> 
> 
> 
> 


Hi Travis,


Putting pure binary bytes in an XML file has a flaw: the issue is that the
binary bytes themselves might contain characters that could be interpreted
as XML!  Even if we wrap the content in CDATA, there's nothing that really
stops the bytes from containing the characters "]]>" to prematurely close
off the CDATA tag.

To get around this, we can use a technique called "ascii-armor" to wrap
protection around the troublesome binary text.

http://en.wikipedia.org/wiki/ASCII_armor

Python comes with a common ascii-armoring algorithm called "base64", and
it's actually very easy to use it.  Let's do a quick example.


Let's say we have some binary unprintable bytes, like this:

##
>>> someBytes = open('/usr/bin/ls').read(8)
>>> someBytes
'\x7fELF\x01\x01\x01\x00'
##

(Hey, look, an Elf!  *grin*)

Anyway, this ELF will probably pass through email poorly, because the
bytes surrounding it are pretty weird.  But we can apply base64 encoding
on those bytes:

##
>>> encodedBytes = someBytes.encode('base64')
>>> encodedBytes
'f0VMRgEBAQA=\n'
##

And now it's in a form that should pass cleanly through.  Decoding it is
also a fairly easy task:

##
>>> encodedBytes.decode('base64')
'\x7fELF\x01\x01\x01\x00'
##

And now we've got our ELF back.


Hope this helps!

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


[Tutor] Closing SimpleXMLRPCServer properly

2005-08-31 Thread lawrence wang
I have a SimpleXMLRPCServer, which I've tweaked thusly: 

class StoppableXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
    def serve_forever(self):
        """to stop this server: register a function in the class
        that uses it which sets server.stop to True."""
        self.stop = False
        while not self.stop:
            self.handle_request()

Here's the code where I start the server...

        try:
            self.server.serve_forever()
        finally:
            self.server.server_close()
            self.log('server closed')

>From another thread, I set the server's stop attribute to False, so the
server stops running. It exits the try block, runs server_close(), then
I get the message 'server closed'...

...but when I try to use the port that the server's bound to again, it
takes a very long time (while i try to use the port, catch the
exception, sleep, try again) until it becomes free. Is there something
else I need to call to ensure that the port is released cleanly? Is
this an OS-specific thing out of my control? (I'm running Debian Linux.)

Thanks in advance
Lawrence
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHON????

2005-08-31 Thread luckygoodluck



Dear Python,
 How does a calculator multiply? I want to 
create a computer software that can multiply. How do I program the computer to 
multiply? 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Popen and Prompting

2005-08-31 Thread Faulconer, Steven M.
John,

I thought about that, but it would potentially cause other conflicts. I
think our final plan is to edit the code to die on error cases instead of
prompting. However, if anyone knows of a way of handling this, I'd love to
know for future use. Thanks for the response.

Steven

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of John Fouhy
Sent: Tuesday, August 30, 2005 7:03 PM
To: tutor@python.org
Subject: Re: [Tutor] Popen and Prompting

On 31/08/05, Faulconer, Steven M. <[EMAIL PROTECTED]> wrote:
> My question for all of you python people; how can I handle programs that
MAY
> need input from the command line. I thought about using something like
> pexpect, but the input requests are fairly variable, and may not show up
at
> all. Also, I need to tie this in with the Tkinter GUI as well. The
binaries
> we are running are written in C, and we have no way of changing that (it's
> in-house software, but the API we have to use does not talk to Python). 

Could you kludge it?

eg, change the C programs so that, every time they ask for user input,
they include in the prompt a certain unusual string.  Then, any time
your GUI detects this string in the program output, it can pop up a
dialog box asking for user input.

(just a suggestion ... I don't know the best way of dealing with this)

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


Re: [Tutor] Writing to XML file with minidom

2005-08-31 Thread Travis Spencer
On 8/30/05, Johan Geldenhuys <[EMAIL PROTECTED]> wrote:
> One snag that I found is that the des encryption that I used for the data 
> that is 
> written back, it is not parsed correctly when the file is read again with the 
> new 
> data in it. There is non-printable characters or non-ascii chars in that 
> gives errors
> from expat when the contents is parsed.
> I had to use a different encryption algorithm. I am going to do some tests on 
> it 
> now.

Put the cyphertext in a CDATA section, so the parser knows to ignore
its contents:







-- 

Regards,

Travis Spencer 

P.S. Please don't send HTML e-mails.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Listbox help

2005-08-31 Thread Kent Johnson
David Holland wrote:
> I can work out how to use most Tkinter widgets.  Eg 
> buttons like :-
>def create_widgets(self):
> #create GUI
>Button(self, text = "x", command =
> self.y).grid(row = 3, column = 3, columnspan = 3)
> 
> However I am not sure how to use Listboxes.  What
> would be the similar syntax to create a listbox.

This page has a complete example of using a listbox:
http://effbot.org/zone/tkinter-scrollbar-patterns.htm

And this page has some useful snippets:
http://www.pythonware.com/library/tkinter/introduction/x5453-patterns.htm

Kent

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


[Tutor] Listbox help

2005-08-31 Thread David Holland
I can work out how to use most Tkinter widgets.  Eg 
buttons like :-
   def create_widgets(self):
#create GUI
   Button(self, text = "x", command =
self.y).grid(row = 3, column = 3, columnspan = 3)

However I am not sure how to use Listboxes.  What
would be the similar syntax to create a listbox.

Thanks in advance.

David



___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor