473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

WSGI/wsgiref: modifying output on windows ?

Hi,

I am currently trying to port my web software AFoC <http://afoc.k.vu>
to Windows and have hit a strange problem: it seams that binary files
(PNG images in this case) get distorted by wsgiref. (I have tried both
the CGIHandler with both Xitami and Apache2 and WSGIServer). My
application is returning a list of one item (the image as a string).
The image is intact at that point. (tested by writing it to disk and
comparing); The client gets a version with a few added \r characters
and something missing at the end, but of the same overall length. Here
are specific examples:
>>f1 = file('afoc_bak', 'rb')
f2 = file('box_top.png', 'rb')
s1 = f1.read()
s2 = f2.read()
s1 == s2
False
>>s1
"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR
\x00\x00\x00\x96\x00\x00\x00\x14\x08\x06\x00
\x00\x00oy\xc41\x00\x00\x00\x04sBIT\x08\x08\x08\x0 8|\x08d
\x88\x00\x00\x00\x19tEX
tSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00\x00 \x01\x95IDATh\x81\xed
\xd9?K#A\
x18\xc7\xf1\xef\xecnv\xb3FQA\x8b\xf3@\xc1?\xe0)*\x da\xd9(v\xd7+r
\xb6\x82\xef\xc3
\xce\x17\xe1\xab\xb0\x15k\x0b\x1b\x1b\xe1@\x8eK\xa 1\x85\x044F
\x8d1\x9a8\x16\x93\
x80\xc4F]u\x89\xfc>\xcd\xb0\x0fS<\xc5\x8fyfw\x8d\xb5\x16\x9 1\x8f
\xe6\xa5\xdd\x80
|O\n\x96|\n\x05K>\x85\x01\x06\xd2nB\xda\xc6\xe3\xb 3\xb5\x06<\x00Uk\xed}
\xeb\xc6\
x00\xf8\xf1\x85\x8dI{\xab7\xd6f\xb0\xee\x81\xaa1\x a6\x02\x94\xad
\xb5\x95\xe6\xc6
\x00\x9dX\xf2zU\xc0\xc7\x05\xac\xd6x\xbe\x03n\x81\ xd8\x18s\x03\\Yk\xeb:
\xb1\xe4-
n\x80\x08\x17\xac\x07\\\xb0n\x812\x90\x05B\xc07\xc 6\x94\x82\xf9\xa5\xad
\xb5\xd4\
xda\x94\xb6\xe0y\xbe\x0fP*\xfe?>\xc9\xef\x15J\xc5\ x7f\x97\xb81x
\x87\x0bUL#T\xb8{
\xbb5\xab\xeb\x07\xfaB*oR)\x17\xce\x8f\x0e\xb7w\xf 3\xc7;\x7f\x81k
\xe0\n(\x01\x97
@\x11\xb8\xf0'g76S\xecQ\xdaP&\xccu\xfc\x1c\\\x98\n \xa3n\xef\xect\xbf
\xd0([\xdc\x
a5\xbe\x0e\xd4\xf4\x1dK\xdem\xf4\xd7\xca\xc2\xc8\x f8\xf24\xd0\x05t
\x02\x1d\xb8\x
b1\x18+X\xf2n\xc6xfbf}\x11\x17\xa8,\xeeb\x1f\x01\x a1\x82%
\x89\xc4\xb9\xfe\x9e\xb
1\xc9?\x11\xee2_\xc7\x8dC\xab`IbC\xc3\xbf\xe7p\xa3 \xb0\xf9f\xa8\x7f
\x85\x92\\\x9
4\xed\xedk\xad)X\x92X&\xcc\xf5\xb6\xd6\x14,I,\x08\ xe2\x9e\xd6\x9a\x82%
\x89y~&\xf
b\xa2\x96F#\xf2\xfd=\x01\x19c^\xe3KN&\x89\x00\x00\ x00\x00IEND\xaeB`
\x82"
>>s2
"\x89PNG\r\r\n\x1a\r\n\x00\x00\x00\rIHDR
\x00\x00\x00\x96\x00\x00\x00\x14\x08\x06
\x00\x00\x00oy\xc41\x00\x00\x00\x04sBIT\x08\x08\x0 8\x08|\x08d
\x88\x00\x00\x00\x1
9tEXtSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00 \x00\x01\x95IDATh
\x81\xed\xd9?
K#A\x18\xc7\xf1\xef\xecnv\xb3FQA\x8b\xf3@\xc1?\xe0 )*\xda\xd9(v\xd7+r
\xb6\x82\xef
\xc3\xce\x17\xe1\xab\xb0\x15k\x0b\x1b\x1b\xe1@\x8e K\xa1\x85\x044F
\x8d1\x9a8\x16\
x93\x80\xc4F]u\x89\xfc>\xcd\xb0\x0fS<\xc5\x8fyfw\x8d\xb5\x16\x9 1\x8f
\xe6\xa5\xdd
\x80|O\r\n\x96|\r\n\x05K>\x85\x01\x06\xd2nB\xda\xc 6\xe3\xb3\xb5\x06<
\x00Uk\xed}\
xeb\xc6\x00\xf8\xf1\x85\x8dI{\xab7\xd6f\xb0\xee
\x81\xaa1\xa6\x02\x94\xad\xb5\x95
\xe6\xc6\x00\x9dX\xf2zU\xc0\xc7\x05\xac\xd6x\xbe\x 03n\x81\xd8\x18s\x03\
\Yk\xeb:\
xb1\xe4-n\x80\x08\x17\xac\x07\\\xb0n\x812\x90\x05B
\xc07\xc6\x94\x82\xf9\xa5\xad\
xb5\xd4\xda\x94\xb6\xe0y\xbe\x0fP*\xfe?>\xc9\xef\x 15J\xc5\x7f\x97\xb81x
\x87\x0bU
L#T\xb8{\xbb5\xab\xeb\x07\xfaB*oR)\x17\xce\x8f\x0e \xb7w\xf3\xc7;\x7f
\x81k\xe0\r\
n(\x01\x97@\x11\xb8\xf0'g76S\xecQ\xdaP&\xccu\xfc\x 1c\\\x98\r\n\xa3n\xef
\xect\xbf
\xd0([\xdc\xa5\xbe\x0e\xd4\xf4\x1dK\xdem\xf4\xd7\xca
\xc2\xc8\xf8\xf24\xd0\x05t\x
02\x1d\xb8\xb1\x18+X\xf2n\xc6xfbf}\x11\x17\xa8,\xe eb\x1f\x01\xa1\x82%
\x89\xc4\xb
9\xfe\x9e\xb1\xc9?\x11\xee2_\xc7\x8dC\xab`IbC\xc3\ xbf\xe7p\xa3\xb0\xf9f
\xa8\x7f\
x85\x92\\\x94\xed\xedk\xad)X\x92X&\xcc\xf5\xb6\xd6 \x14,I,\x08\xe2\x9e
\xd6\x9a\x8
2%\x89y~&\xfb\xa2\x96F#\xf2\xfd=\x01\x19c^\xe3KN&
\x89\x00\x00\x00\x00IE"
>>>
a thought that springs to mind is that this may be related to the
barmy DOS relic of binary/ASCII file destinction; however, this should
not be a problem if I understand PEP 333 correctly:

"""The server or gateway should treat the yielded strings as binary
byte sequences: in particular, it should ensure that line endings are
not altered."""

Might this be a bug in wsgiref ? I will hopefully be able to do some
more testing, e.g. with the FLUP FastCGI back-end, in the next few
days.

Kind regards,

Thomas Jollans

Jun 3 '07 #1
2 1504
On Jun 3, 10:11 pm, "tjoll...@g-NOSPAM-mail.com"
<tjoll...@googlemail.comwrote:
Hi,

I am currently trying to port my web software AFoC <http://afoc.k.vu>
to Windows and have hit a strange problem: it seams that binary files
(PNG images in this case) get distorted by wsgiref. (I have tried both
the CGIHandler with both Xitami and Apache2 and WSGIServer).
I have just realised that the WSGIServer works after all, I do not
know why I thought it didn't.

Jun 4 '07 #2
On Jun 3, 10:11 pm, "tjoll...@g-NOSPAM-mail.com"
<tjoll...@googlemail.comwrote:
Might this be a bug in wsgiref ? I will hopefully be able to do some
more testing, ...
The following simple CGI script should, AFAIK, on any platform, output
exactly the file specified in code. It does not on Apache 2 on
Windows; I believe this to be a bug in wsgiref.handlers.CGIHandler.
Can someone test this in a similar environment (Windows+a web server?)
to confirm this ? (The first two lines need to be edited depending on
the site)

#!c:\python25\python.exe
fname, type = r'c:\hdr.png', 'image/png'

from wsgiref.handlers import CGIHandler

def wsgiapp(env, start_response):
f = file(fname, 'rb')
start_response('200 OK', [('Content-Type', type)])
return [f.read()]
CGIHandler().run(wsgiapp)

Jun 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thomas W | last post by:
Will there be a WSGI-server like BaseHTTPServer etc in the standard distro? I think that would increase the adoptation of the WSGI-standard. A new web-framework for python pops up every other week...
2
by: Ben Finney | last post by:
Howdy all, I'm trying to implement some new functionality for an existing PHP web application. Rather than writing a whole lot of stuff in PHP, and looking toward a future when more of the...
11
by: Gregory Piñero | last post by:
So I keep hearing more and more about this WSGI stuff, and honestly I still don't understand what it is exactly and how it differs from CGI in the fundamentals (Trying to research this on the web...
0
by: richmoore44 | last post by:
Hi, I've just written a python WSGI middleware class to mitigate XSS flaws, it's released under the python license. I've attached the docs below. Cheers Rich.
2
by: Adam Atlas | last post by:
I'm trying to figure out if there's any defined behaviour in PEP 333 for instances where an application returns an iterable as usual without error, but that iterable's next() method eventually...
8
by: Ron Garret | last post by:
The wsgiref module in Python 2.5 seems to be empty: $ python Python 2.5 (r25:51908, Mar 1 2007, 10:09:05) on darwin Type "help", "copyright", "credits" or "license" for more information. ...
9
by: Tool69 | last post by:
Hi, Until now, I was running my own static site with Python, but I'm in need of dynamism. After reading some cgi tutorials, I saw Joe Gregorio's old article "Why so many Python web...
0
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
In a recent experiment I've done this: from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from wsgiref.simple_server import make_server, demo_app from SocketServer import...
0
by: Gabriel Genellina | last post by:
En Tue, 26 Aug 2008 03:20:53 -0300, Gerhard Häring <gh@ghaering.de> escribi�: I'm not sure I understand completely the question - does the code below work for you? class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.