1. remove PY3 check; 2. replace the home-made local-file-way with tempfile module from the python std library; 3. NOTE: the suffix parameter in the tempfile.NamedTemporaryFile() function is a must, since Part.read need the suffix parameter......

This commit is contained in:
Simon Huskier 2015-12-02 11:37:28 +08:00
parent 51a8d35645
commit f94f9fe115

View File

@ -26,15 +26,9 @@ import FreeCAD
import Part
import sys
import os
import platform
if sys.version > '3':
PY3 = True
import urllib.request as urlreader
else:
PY3 = False
import urllib as urlreader
import urllib as urlreader
import tempfile
class ImportTypes:
STEP = "STEP"
@ -80,20 +74,12 @@ def importStepFromURL(url):
#Now read and return the shape
try:
webFile = urlreader.urlopen(url)
if platform.system() == 'Windows':
localFileName = os.environ['TEMP']+'/'+url.split('/')[-1]
else:
localFileName = "/tmp/"+url.split('/')[-1]
localFile = open(localFileName, 'w')
if PY3:
localFile.write(webFile.read().decode('utf-8'))
else:
localFile.write(webFile.read())
tempFile = tempfile.NamedTemporaryFile(suffix='.step', delete=False)
tempFile.write(webFile.read())
webFile.close()
localFile.close()
fileName = localFileName
rshape = Part.read(fileName)
tempFile.close()
rshape = Part.read(tempFile.name)
#Make sure that we extract all the solids
solids = []