javascript to python

lkcl luke.leighton at googlemail.com
Thu Oct 2 20:07:19 CEST 2008


On Oct 2, 5:54 pm, Joe Hrbek <joe.hr... at gmail.com> wrote:
> Could someone help me translate to something that would close to it in
> python?  The anonymous functions are giving me problems.


class dataListener:
    def __init__(self):
        data = ""
    def onStartRequest(self, request, context):
        pass
    def onStopRequest(self, request, context, status):

        # TODO: pass these three in to dataListener as
        # params to the constructor, so it's
        # def __init__(self, instream, outstream, listener)
        # and do self.instream = instream

        global instream
        global outstream
        global listener

        instream.close()
        outstream.close()
        listener.finished(self.data)

    def onDataAvailable(self, request, context, inputStream,
                        offset, count):

        global instream

        self.data += instream.read(count)


question.

why are request and context being ignored?
why is there an inputStream argument to onDataAvailable, yet
there's a global variable (in the javascript) called
instream?  is it the same?

all this, and more, thanks to the awfulness that is javascript :)

for fits and giggles, compile the above python using
pyjs.py, the python-to-javascript compiler
(see http://pyjamas.sf.net) and compare the
resultant javascript to your original code-fragment.

l.



More information about the Python-list mailing list