Attempting to parse free-form ANSI text.

Michael B. Trausch mike$#at^&nospam!%trauschus
Mon Oct 23 18:17:00 EDT 2006


Frederic Rentsch wrote:
> Michael B. Trausch wrote:
>> Alright... I am attempting to find a way to parse ANSI text from a
>> telnet application.  However, I am experiencing a bit of trouble.
>>
[snip]
>
> *I have no experience with reading from TCP/IP. But looking at your
> program with a candid mind I'd say that it is written to process a chunk
> of data in memory.
>

That would be correct... that's the only way that I can think of to do
it, since the chunks come in from the network to a variable.

>
> If, as you say, the chunks you get from TCP/IP may
> start and end anywhere and, presumably you pass each chunk through
> AppendText, then you have a synchronization problem, as each call resets
> your escape flag, even if the new chunk starts in the middle of an
> escape sequence. Perhaps you should cut off incomplete escapes at the
> end and prepend them to the next chunk.
>

The question would be -- how does one determine if it is incomplete or
not?  The answer might lie in the previous response to this, where there
is another ANSI python module that works with the text.  Actually, it's
possible that my entire approach is faulty -- I am, after all, a rather
newbie programmer -- and this is my first go at an application that does
something other than "Hello, world!"

> 
> And:
> 
> if(len(buffer) > 0):                         
> wx.TextCtrl.AppendText(self, buffer)      <<< Are you sure text goes
> into the same place as the controls?
>

What do you mean?  This function is in AnsiTextCtrl (so, it is
AnsiTextCtrl.AppendText).  I have derived AnsiTextCtrl from wx.TextCtrl,
so I think that if I need to call the parent's function, I would do so
directly, with 'self' being the current object, and buffer being the
text to add from the network.

When I call AppendText from an instance of a text control, (e.g.,
AnsiTextCtrl.AppendText(buffer)), I don't need to provide the object
that needs to be worked on.  It seems to work okay; but I know that just
because something works okay, that doesn't mean it is right.  So, am I
doing it wrong?

>                                           if(len(AnsiBuffer) >
> 0):                       wx.TextCtrl.AppendText(self, AnsiBuffer)  <<<
> You say you want to strip the control sequences
> 

Yes, in the end I do.  Right now, I had to see what was going on.  I
figure that once I do figure out how to get it working, I can see the
color changes when the ANSI code shows up in the buffer, and they should
match up with the little chart that I have of the codes here.
Hopefully.  And then I can stop printing the extra crud on here.

	-- Mike



More information about the Python-list mailing list