the browser (dumpstatepage)and that wrap calls to functions that print status messages so that their output isn' added to the html stream (runsilenta version addition also attempts to work around the fact that built-in print calls can fail in python for some types of unicode text ( non-ascii character sets in internationalized headers)by forcing binary mode and bytes for the output stream (printi'll leave the discovery of any remaining magic in the code in example - up to youthe reader you are hereby admonished to go forth and readreferand reuse example - pp \internet\web\pymailcgi\cgi-bin\commonhtml py #!/usr/bin/python ""#################################################################################generate standard page headerlistand footer htmlisolates html generation related details in this filetext printed here goes over socket to the clientto create parts of new web page in the web browseruses one print per lineinstead of string blocksuses urllib to escape params in url links auto from dictbut cgi escape to put them in html hidden fieldssome tools here may be useful outside pymailcgicould also return the html generated here instead of printing itso it could be included in other pagescould also structure as single cgi script that gets and tests next action name as hidden form fieldcaveatthis system worksbut was largely written during two-hour layover at the chicago 'hare airportthere is much room for improvement and optimization#################################################################################""import cgiurllib parsesysos python has issues printing some decoded str as text to stdout import builtins bstdout open(sys stdout fileno()'wb'def print(*argsend='\ ')trybuiltins print(*argsend=endsys stdout flush(exceptfor arg in argsbstdout write(str(argencode('utf- ')if endbstdout write(end encode('utf- ')bstdout flush(sys stderr sys stdout from externs import mailconfig from externs import mailtools parser mailtools mailparser(show error messages in browser from package somewhere on server need parser for header decoding one per process in this module my cgi address root #urlroot '#urlroot 'urlroot 'use minimalrelative paths utility modules