community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1727530 - /comdev/projects.apache.org/scripts/cronjobs/urlutils.py
Date Fri, 29 Jan 2016 11:08:54 GMT
Author: sebb
Date: Fri Jan 29 11:08:54 2016
New Revision: 1727530

URL: http://svn.apache.org/viewvc?rev=1727530&view=rev
Log:
FileNotFoundError not supported in Python2

Modified:
    comdev/projects.apache.org/scripts/cronjobs/urlutils.py

Modified: comdev/projects.apache.org/scripts/cronjobs/urlutils.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/urlutils.py?rev=1727530&r1=1727529&r2=1727530&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/urlutils.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/urlutils.py Fri Jan 29 11:08:54 2016
@@ -7,6 +7,8 @@ import os
 from os.path import dirname, abspath, join, getmtime, basename
 import shutil
 import io
+import errno
+
 # Allow for Python2/3 differences
 try:
     from urllib.request import urlopen, Request
@@ -71,7 +73,7 @@ def getIfNewer(url, sinceTime, encoding=
         req = Request(url, headers=headers)
         resp = urlopen(req)
         # Debug - detect why json sometimes returned as HTML but no error code
-        print("STATUS ",resp.status)
+        print("STATUS %s" % resp.getcode()) # Works for Py2/3
         print(resp.headers)
         try:
             lastMod = resp.headers['Last-Modified']
@@ -115,7 +117,9 @@ class UrlCache(object):
     def __file_mtime(self, filename):
         try:
             t = getmtime(filename)
-        except FileNotFoundError:
+        except OSError as e:
+            if not e.errno == errno.ENOENT:
+                raise e
             t = -1 # so cannot be confused with a valid mtime
         return t
 
@@ -141,13 +145,15 @@ class UrlCache(object):
         path = self.__getname(name)
         try:
             os.remove(path)
-        except FileNotFoundError:
-            pass
+        except OSError as e:
+            if not e.errno == errno.ENOENT:
+                raise e
         dotpath = self.__getname('.'+name)
         try:
             os.remove(dotpath)
-        except FileNotFoundError:
-            pass
+        except OSError as e:
+            if not e.errno == errno.ENOENT:
+                raise e
 
     def get(self, url, name, encoding=None, errors=None, useFileModTime=False):
         """
@@ -246,13 +252,14 @@ if __name__ == '__main__':
         fc = UrlCache(cachedir='x')
         raise Error("Expected OSError")
     except OSError as e:
-        print('Expected: ', e)
+        print('Expected: %s' % e)
     fc = UrlCache(interval=0)
     name = "_wao.html"
+    fc._deleteCacheFile(name)
     icla_info = fc.get("http://www.apache.org/", name, encoding='utf-8')
     print(icla_info.readline().rstrip())
     print(icla_info.readline().rstrip())
     print(icla_info.readline().rstrip())
     print(icla_info.readline().rstrip())
+    icla_info = fc.get("http://www.apache.org/", name, encoding='utf-8')
     fc._deleteCacheFile(name)
-    fc._deleteCacheFile(name)
\ No newline at end of file



Mime
View raw message