By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

Question about wsgi.input

P: n/a
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.

Jun 27 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
inhahe schrieb:
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
Jun 27 '08 #2

P: n/a
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

Jun 27 '08 #3

P: n/a
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'?

"Diez B. Roggisch" <de***@nospam.web.dewrote in message
news:6a*************@mid.uni-berlin.de...
inhahe schrieb:
>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

Jun 27 '08 #4

P: n/a
inhahe schrieb:
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
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.