Question about wsgi.input

I

inhahe

I'm sorry if this is off-topic, i couldn't find a mailing list OR forum for
WSGI (and #wsgi wasn't very helpful).

i played around with StringIO, and apparently if you write to a stringio the
position gets set to the end of the write, so if you read from it again,
without using seek, you won't read what comes next, you'll skip to the end
of the write. and if you write without seeking to the end first, you'll
overwrite part of the string if the reading hasn't caught up.

WSGI says that wsgi.input should block if there's more data to be read from
the socket, until that data is available. so when the server writes to the
file object, what happens to the file position? if i were writing a WSGI
app, i would just seek() to the last place my read ended at just to make
sure. but i'm making a server, so i need to know whether i should leave the
position at the end of the write, when it blocks (or for that matter, if i'm
writing while it's still reading), or at the end of the previous read?

thanks for any help.
 
D

Diez B. Roggisch

inhahe said:
I'm sorry if this is off-topic, i couldn't find a mailing list OR forum for
WSGI (and #wsgi wasn't very helpful).

i played around with StringIO, and apparently if you write to a stringio the
position gets set to the end of the write, so if you read from it again,
without using seek, you won't read what comes next, you'll skip to the end
of the write. and if you write without seeking to the end first, you'll
overwrite part of the string if the reading hasn't caught up.

WSGI says that wsgi.input should block if there's more data to be read from
the socket, until that data is available. so when the server writes to the
file object, what happens to the file position? if i were writing a WSGI
app, i would just seek() to the last place my read ended at just to make
sure. but i'm making a server, so i need to know whether i should leave the
position at the end of the write, when it blocks (or for that matter, if i'm
writing while it's still reading), or at the end of the previous read?

I'm not sure exactly about what you are talking here - but generally,
wsgi.input should be considerd being a pipe. One (the server) simply
writes into it. The WSGI-app just reads. No seek.

Diez
 
B

Brian Smith

at the end of the previous read?

At the end of the previous read.

Web-SIG is the mailing list for WSGI and related stuff.

- Brian
 
I

inhahe

That's what I would have thought, just seems strange since it seems to imply
that if I use StringIO or cStringIO, then whenever i write to it i have to
save the position, seek to the end, write, and then seek to the position i
saved. Are there any other classes that are more suitable for pipes, but
qualify as 'file-like objects'?
 
D

Diez B. Roggisch

inhahe said:
That's what I would have thought, just seems strange since it seems to imply
that if I use StringIO or cStringIO, then whenever i write to it i have to
save the position, seek to the end, write, and then seek to the position i
saved. Are there any other classes that are more suitable for pipes, but
qualify as 'file-like objects'?

Who uses StringIO for what? if you have two processes (server and
application), you can of course use a pipe of some sort. If you write a
WSGI-server that is supposed to pass the wsgi.input to an application,
just use StringIO with the completely initialized data - there is no
writing in-between.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top