statements in control structures (Re: Conditional Expressions don't solve the problem)

Markus Schaber use-net at schabi.de
Fri Oct 19 03:00:08 EDT 2001


Hi,

On Fri, 19 Oct 2001 03:28:59 +0000 (UTC), huaiyu at gauss.almadan.ibm.com
(Huaiyu Zhu) wrote:

> The original code is quite enigmatic to me.  I don't know the ftp
> protocol, but from Andrew's example data I think the code is intended
> to be
> 
>     def getmultiline(self):
>         code = None
>         lines = []
>         while line = self.getline(); \
>             lines.append(line); \
>             line[3:4] == '-' or code != line[:3]:
>                 code = line[:3]
>         return '\n'.join(lines)
> 
> I'm not sure if this is correc, either, except it works on Andrew's
> data.(What should happen if code changes when line[3:4]=='-', etc?)

I think you have to break after adding the first line with no - after the code, because otherwise you would be blocked in a read.

AFAIR (didn't look into the RFC) the protocol (which IIRC is also used in SMTP) says that the last line of a message is three digits code (the machine readable information), then a blank, and then a human readable text (saying esentially the same than the three digits code). When more then one line of texts is needed, then this last line can be preceeded by lines using three digits of code, then a -, and then the human readable code.

I don't remember whether changing the code is allowed, but the original code clearly hangs when the code is changed (because it terminates only when the line containing the space has the same code than the first line).

I'd write this like (not tested):

    def getmultiline(self):
        lines = []      
        while 1:
            line = self.getline()
            lines.append(line)
            if line[3:4]==" ":
                break
    return "\n".join(lines)
        
markus
-- 
You don't have to be Microsoft to suck... but it helps.
(Tim Hammerquist in comp.lang.python)



More information about the Python-list mailing list