Fix build error with scons-4.4.0 version which is based on python3
[platform/upstream/iotivity.git] / tools / scons / URLDownload.py
index f824140..56b026d 100644 (file)
@@ -66,7 +66,7 @@
 # default setting replaces the target name with the URL filename)
 
 
-import urllib2, urlparse
+import urllib.request, urllib.error, urllib.parse, urllib.parse
 import SCons.Builder, SCons.Node, SCons.Errors
 
 
@@ -84,8 +84,8 @@ class URLNode(SCons.Node.Python.Value) :
             pass 
         
         try :
-            response = urllib2.urlopen( str(self.value) ).info()
-        except Exception, e :
+            response = urllib.request.urlopen( str(self.value) ).info()
+        except Exception as e :
             raise SCons.Errors.StopError( "%s [%s]" % (e, self.value) )
             
         contents = ""
@@ -106,7 +106,7 @@ class URLNode(SCons.Node.Python.Value) :
 # @param source source name
 # @param env environment object
 def __message( s, target, source, env ) : 
-    print "downloading [%s] to [%s] ..." % (source[0], target[0])
+    print("downloading [%s] to [%s] ..." % (source[0], target[0]))
 
 
 # the download function, which reads the data from the URL
@@ -116,12 +116,12 @@ def __message( s, target, source, env ) :
 # @@param env environment object
 def __action( target, source, env ) :
     try :
-        stream = urllib2.urlopen( str(source[0]) )
+        stream = urllib.request.urlopen( str(source[0]) )
         file   = open( str(target[0]), "wb" )
         file.write(stream.read())
         file.close()
         stream.close()
-    except Exception, e :
+    except Exception as e :
         raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) )
 
 
@@ -138,8 +138,8 @@ def __emitter( target, source, env ) :
         return target, source
 
     try :
-        url = urlparse.urlparse( urllib2.urlopen( str(source[0]) ).geturl() )
-    except Exception, e :
+        url = urllib.parse.urlparse( urllib.request.urlopen( str(source[0]) ).geturl() )
+    except Exception as e :
         raise SCons.Errors.StopError( "%s [%s]" % (e, source[0]) )
 
     return url.path.split("/")[-1], source