Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-20 Thread Tim Roberts
On Wed, 19 Oct 2005 09:51:32 +1000, Kinsley Turner 
[EMAIL PROTECTED] wrote:

Hey-ho,

I'm having a problem with some binary data read into a string.

Basically I open an icon file rb, read() it into a string, then
spit it back down on a web request for /favicon.ico.

It works fine under unix, but under Win32 Python 2.4.2 (#67, Sep 28 2005 
...
It comes back corrupted.

Similiarly I have a string with the IBM-extended-ASCII degrees symbol 
(ascii 0xb0) 
that is read in from a network-connected field device.  Somehow this ends 
up with 
an extended 'A' (with a single dot over it.) prepended before it.

Is there some sort of new 2.4 string encoding option I've missed ?
Never seen anything like this before.

I have the # -*- coding: iso-8859-1 -*- atop my files.



Are you writing this as a CGI process in Apache/Win32?  Have you 
redefined your stdout to be binary?  By default, Python opens its stdout 
as binary, so when you write this out to the socket, the file system 
will helpfully translate 0A to 0D/0A.  You need something like this:

import msvcrt
msvcrt.setmode( 0, os.O_BINARY )
msvcrt.setmode( 1, os.O_BINARY )

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Kinsley Turner


Hey-ho,

I'm having a problem with some binary data read into a string.

Basically I open an icon file rb, read() it into a string, then
spit it back down on a web request for /favicon.ico.

It works fine under unix, but under Win32 Python 2.4.2 (#67, Sep 28 2005 
...
It comes back corrupted.

Similiarly I have a string with the IBM-extended-ASCII degrees symbol 
(ascii 0xb0) 
that is read in from a network-connected field device.  Somehow this ends 
up with 
an extended 'A' (with a single dot over it.) prepended before it.

Is there some sort of new 2.4 string encoding option I've missed ?
Never seen anything like this before.

I have the # -*- coding: iso-8859-1 -*- atop my files.


-kt



Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in 
error, please delete and inform us by return email. Because emails and 
attachments may be interfered with, may contain computer viruses or other 
defects and may not be successfully replicated on other systems, you must be 
cautious. Westpac cannot guarantee that what you receive is what we sent. If 
you have any doubts about the authenticity of an email by Westpac, please 
contact us immediately.

It is also important to check for viruses and defects before opening or using 
attachments. Westpac's liability is limited to resupplying any affected 
attachments.


This email and its attachments are not intended to constitute any form of 
financial advice or recommendation of, or an offer to buy or offer to sell, any 
security or other financial product. We recommend that you seek your own 
independent legal or financial advice before proceeding with any investment 
decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a 
company registered in New South Wales in Australia under the Corporations Act 
2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the 
Financial Services Authority and is registered at Cardiff in the United Kingdom 
as Branch No. BR 106. Westpac operates in the United States of America as a 
federally chartered branch, regulated by the Office of the Comptroller of the 
Currency.

Westpac Banking Corporation ABN 33 007 457 141.
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Justin Ezequiel
 Date: Thu, 20 Oct 2005 10:04:24 +1000
 From: Kinsley Turner [EMAIL PROTECTED]

 I checked the icon, it seemed to be ok.  I'm unfamiliar with win32
 tools, but it seemed that the data being delivered from the socket
 rendered differently from a python print() compared to a terminal
 'type icon.ico'.  I cut the code out and tested it in isolation - this
 showed it to be flawless.  Despite appearing correct in other software
 the binary identical icon appears broken in IE 6.something.

for what its worth, had a similar problem serving up images from a
Python CGI script running on Apache on WinXP.

what worked for me was adding the -u switch to the shebang
#!E:\Python23\python.exe -u

-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
 see man page for details on internal buffering relating to '-u'

hope this helps
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] String weirdness on python 2.4 / windows

2005-10-19 Thread Gabriel Genellina
At Wednesday 19/10/2005 21:04, you wrote:

I think you might be correct with the headers suggestion, that was
going to be my next point of investigation.  I don't think the
MIME type of image/bmp is acceptable to IE.

Should be image/vnd.microsoft.icon or image/x-icon, but NOT image/bmp
(icon files having different format than bmp files)


Gabriel Genellina
Softlab SRL 

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32