have instead coded the path splitter logic like this to avoid some split callsdef splitpath(origpath)basename os path split(origpath)[ if basename =origpathif '\\in origpathbasename origpath split('\\')[- elif '/in origpathbasename origpath split('/')[- return basename get name at end try server paths didn' change ittry dos clients try unix clients but this alternative version may fail for some path formats ( dos paths with drive but no backslashesas isboth options waste time if the filename is already base name ( has no directory paths on the left)but we need to allow for the more complex cases generically this upload script works as plannedbut few caveats are worth pointing out before we close the book on this examplefirstlyputfile doesn' do anything about cross-platform incompatibilities in filenames themselves for instancespaces in filename shipped from dos client are not translated to nonspace charactersthey will wind up as spaces in the serverside file' namewhich may be legal but are difficult to process in some scenarios secondlyreading line by line means that this cgi script is biased toward uploading text filesnot binary datafiles it uses wb output open mode to retain the binary content of the uploaded filebut it assumes the data is text in other placesincluding the reply page see for more about binary file modes this is all largely moot point in python thoughas binary file uploads do not work at all (see "cgi file upload limitations in ")in future releasethoughthis would need to be addressed if you run into any of these limitationsyou will have crossed over into the domain of suggested exercises cgi file upload limitations in regrettablyi need to document the fact that python' standard library support for cgi file uploads is partially broken in python the version used for this edition in shortthe cgi module' internal parsing step fails today with an exception if any binary file data or incompatible text file data is uploaded this exception occurs before the script has chance to intervenemaking simple workarounds nonviable cgi uploads worked in python because strings handled bytesbut fail in today this regression stems in part from the fact that the cgi module uses the email package' parser to extract incoming multipart data for filesand is thus crippled by some of the very same email package issues we explored in detail in --its email parser requires str for the full text of message to be parsedbut this is invalid for some cgi upload data as mentioned in the data transmitted for cgi file uploads might have mixed text and binary data--including raw binary data that is not transferring files to clients and servers