diff --git a/siphon/ncss.py b/siphon/ncss.py index f29caab59..2cc27654c 100644 --- a/siphon/ncss.py +++ b/siphon/ncss.py @@ -1,5 +1,8 @@ import xml.etree.ElementTree as ET +import atexit from io import BytesIO +from os import remove +import platform import numpy as np @@ -341,16 +344,35 @@ def parse_xml_dataset(elem, handle_units): @response_handlers.register('application/x-netcdf') @response_handlers.register('application/x-netcdf4') def read_netcdf(data, handle_units): # pylint:disable=unused-argument - with NamedTemporaryFile() as tmp_file: - tmp_file.write(data) - tmp_file.flush() - return Dataset(tmp_file.name, 'r') + ostype = platform.architecture() + if ostype[1].lower() == 'windowspe': + with NamedTemporaryFile(delete=False) as tmp_file: + tmp_file.write(data) + tmp_file.flush() + atexit.register(deletetempfile, tmp_file.name) + return Dataset(tmp_file.name, 'r') + else: + with NamedTemporaryFile() as tmp_file: + tmp_file.write(data) + tmp_file.flush() + return Dataset(tmp_file.name, 'r') + except ImportError: import warnings warnings.warn('netCDF4 module not installed. ' 'Will be unable to handle NetCDF returns from NCSS.') +def deletetempfile(fname): + try: + remove(fname) + except OSError: + import warnings + warnings.warn('temporary netcdf dataset file not deleted. ' + 'to delete temporary dataset file in the future ' + 'be sure to use dataset.close() when finished.') + + # Parsing of CSV data returned from NCSS @response_handlers.register('text/plain') def parse_csv_response(data, unit_handler):