[xiph-commits] r15262 - websites/validator.xspf.org

sping at svn.xiph.org sping at svn.xiph.org
Fri Sep 5 16:29:20 PDT 2008


Author: sping
Date: 2008-09-05 16:29:19 -0700 (Fri, 05 Sep 2008)
New Revision: 15262

Modified:
   websites/validator.xspf.org/check.py
Log:
Close file handles, bring back HTTPS support

Modified: websites/validator.xspf.org/check.py
===================================================================
--- websites/validator.xspf.org/check.py	2008-09-04 20:23:41 UTC (rev 15261)
+++ websites/validator.xspf.org/check.py	2008-09-05 23:29:19 UTC (rev 15262)
@@ -30,6 +30,12 @@
 # -----------------------------------------------------------------------
 # HISTORY
 # -----------------------------------------------------------------------
+# 2008-09-06 -- Sebastian Pipping <webmaster at hartwork.org>
+#
+#   * Fixed: Now closing files properly
+#   * Added: Bring back "https" scheme support unintentionally
+#       removed two days ago
+#
 # 2008-09-04 -- Sebastian Pipping <webmaster at hartwork.org>
 #
 #   * Fixed: [SECURITY] Accessing local files was possible
@@ -144,7 +150,11 @@
 
 def isSafeDownloadTarget(candidate):
     schemeOrNone = Uri.GetScheme(candidate)
-    return (schemeOrNone != None) and (schemeOrNone.lower() == "http")
+    if schemeOrNone == None:
+        return False
+    scheme = schemeOrNone.lower()
+    allowedSchemes = set(["http", "https"])
+    return scheme in allowedSchemes
 
 
 print """
@@ -277,6 +287,7 @@
             input = f.read()
         finally:
             f.close()
+
     except IOError:
         pass
 
@@ -293,7 +304,12 @@
     elif form.has_key("uploaded") and form.has_key("submitUploaded"):
         uploaded = form["uploaded"]
         if uploaded.file:
-            input = uploaded.file.read()
+            try:
+                input = uploaded.file.read()
+            except IOError:
+                pass
+            finally:
+                uploaded.file.close()
 
         if input != "":
             intro = "Validating uploaded file<br><b><i>" + cgi.escape(uploaded.filename) + "</i></b><br><br>"
@@ -306,11 +322,15 @@
         else:
             try:
                 file = urllib2.urlopen(url)
-                input = file.read()
+                try:
+                    input = file.read()
+                finally:
+                    file.close()
+                
             except ValueError:
                 intro = """<b style="color:red;">Invalid URL.</b><br><br>"""
 
-            except urllib2.URLError:
+            except Exception: ### urllib2.URLError:
                 # One of 404, non-existent host, IPv6 (not supported), ...
                 intro = """<b style="color:red">Could not download from URL.</b><br><br>"""
 



More information about the commits mailing list