SubmitDatasetUtils.HTTP_ERROR,
            e.code, e.reason)
        SubmitDatasetUtils.printStackTrace()
        
    except:
        SubmitDatasetUtils.printHTMLHeaders()
        print "<h2>Server error while processing dataset submission</h2>"
        print "<p>Diagnostic stack trace follows</p>"
        SubmitDatasetUtils.printStackTrace()
        raise
    
    finally:
        print "</body>"
        print "</html>"
        Logger.debug("zipFilePath = "+zipFilePath)
        SubmitDatasetUtils.deleteLocalFile(zipFilePath)# Delete the local zip file after submission
        sys.stdout = save_stdout
        ###print "---- manifestFilePath "+manifestFilePath
        ###print "---- ElementValueList "+repr(ElementValueList)
    return

def validateFields(datasetDirectoryName, datasetName):
    datIDPattern = re.compile("^[a-zA-Z0-9._:-]+$")
    matchedString = datIDPattern.match(datasetName)
    
    if matchedString==None:
        raise SubmitDatasetUtils.SubmitDatasetError(
            SubmitDatasetUtils.INPUT_ERROR,
            None,
            "Not a valid Dataset ID: '"+datasetName+"' supplied")