CGI POST binary file upload?

Ilariu Raducan lale at fotonation.com
Wed Dec 6 11:34:56 EST 2000


Hmm..
It's true mode='rb' should be the default parameter in the function call
only when the OS is windows.
I think the module should be modified to work on every OS.. but not by
myself
But I tried the SocketServer with the folowing code and it's working:

import SocketServer, sys,traceback,re

class ReqHandler (SocketServer.StreamRequestHandler):
    def handle(self):
        print 'Starting .. . ..............'
        f = open ('log.log','wb')
        try:
            yf = self.request.makefile()
            line = yf.readline()
            while(line):
                print line
                for xx in line:
                    print ord(xx),
                if line == '\r\n':
                    print "break"
                    break
                if line[:15]=='Content-Length:':
                    lentemp = re.split('\s+',line)
                    length = int(lentemp[1])-1
                    print length
                line = yf.readline()

            line = yf.read(length)

        except:
            traceback.print_exc()

        print line
        print "**"
        f.write(line)
        f.close()
        yf.flush()
        print "**"
        yf.write("HTTP/1.0 200 OK Message\r\n\r\n")
        yf.flush()
        print 'End  .. . . .. . . .. . .. . .. .'

x=SocketServer.TCPServer(('',9080),ReqHandler)

try:
    x.serve_forever()
except KeyboardInterrupt:
    sys.exit()
except:
    pass

 Are you sure is broking the the SocketServer module?

Regards,
Lale


"Fredrik Lundh" <fredrik at effbot.org> wrote in message
news:zodX5.1943$O%.340817 at newsc.telia.net...
> Ilariu Raducan wrote:
> > In class _sockobject in the file socket.py change the 'r' mode with 'rb'
> >
> >   def makefile(self, mode='r', bufsize=-1):
> >         #MODIFIED   return _fileobject(self._sock, 'rb', bufsize)
> >         return _fileobject(self._sock, 'rb', bufsize)
>
> please.  what's wrong with changing the *call* to the
> function, instead of the function itself?
>
> btw, your "fix" breaks SocketServer.py, and god knows
> how many other programs...
>
> </F>
>
>





More information about the Python-list mailing list