473,382 Members | 1,332 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,382 software developers and data experts.

Alternative to python -u for binary upload to cgi on windows?

Hi all,

Using a python cgi script such as the one below to handle uploaded
binary files will end up with a truncated file (truncates when it hits
^Z) on Windows systems. On linux systems the code works and the file is
not truncated.

One solution for Windows is to use the -u flag, i.e.
#!C:\Python\python.exe -u

Is there another fix that doesn't require python to be run in unbuffered
mode? What performance hits would I expect for running in unbuffered mode?

Best regards,

Cameron.
Example code:

import cgi, os.path as path
form = cgi.FieldStorage()
new_file = form.getvalue("new_file",None)
if new_file is not null:
fname = path.split(form["new_file"].filename)[-1]
fle = open(fname,"wb")
fle.write(new_file)
fle.close()
Dec 14 '07 #1
1 1830
On Dec 14, 6:58 pm, Cameron Walsh <cameron.wa...@gmail.comwrote:
Hi all,

Using a pythoncgiscript such as the one below to handle uploaded
binary files will end up with atruncatedfile (truncates when it hits
^Z) on Windows systems. On linux systems the code works and the file is
nottruncated.

One solution for Windows is to use the -u flag, i.e.
#!C:\Python\python.exe -u

Is there another fix that doesn't require python to be run in unbuffered
mode? What performance hits would I expect for running in unbuffered mode?
Answer to the first part:

import msvcrt, sys, os
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)

# other problems may also be fixed with:
# msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

Cameron.
Dec 23 '07 #2

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

Similar topics

46
by: Robin Becker | last post by:
It seems that the rotor module is being deprecated in 2.3, but there doesn't seem to be an obvious alternative. I'm using it just for obfuscation. It seems we have ssl available in 2.3 for sockets,...
3
by: C | last post by:
Re: Microsoft Knowledge Base Article - 870669 How to disable the ADODB.Stream object from Internet Explorer You may recently have heard of the vulnarability exposed by Internet Explorer as...
3
by: Steve Holden | last post by:
I know there are quite a few hosting companies now who represent themselves as Python-friendly. Rather than trawl through the Wiki pages, however, and email each one separately I am sending this...
7
by: Anton Mellit | last post by:
Hi, I am working on a Pari-Python module (see about GP/PARI at http://pari.math.u-bordeaux.fr/). Similar project was started by Stefane Fermigier 12 years ago (you can find a post about it on...
15
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer...
25
by: Brian | last post by:
Had a unsettling conversation with a CS instructor that teaches at local high schools and the community college. This person is a long-term Linux/C/Python programmer, but he claims that the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.