What about creating two simple scripts instead of dealing with all this cases:
1) from nrml to csv + mdata
2) from csv + mdata to nrml

This would make the converter work also with StringIO (moreover, you will not need to care about file extensions...)