From 6a73c2866380e9c48c32b546910c6dad23e90aba Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Tue, 6 May 2014 18:07:04 +0100
Subject: [PATCH] Version 2014-05-06 19:07

---
 src/mio/filecache.py         | 11 ++++++--
 src/mio/urlgrabber_compat.py | 53 ++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100755 src/mio/urlgrabber_compat.py

diff --git a/src/mio/filecache.py b/src/mio/filecache.py
index a1817dc..a47cf31 100755
--- a/src/mio/filecache.py
+++ b/src/mio/filecache.py
@@ -6,13 +6,18 @@ import re
 import sys
 import tempfile
 import time
-import urlgrabber
-import urlgrabber.mirror
 import urlparse
 import urllib
 import mio.exception
 import socket
-import pycurl
+try:
+    import urlgrabber
+    import urlgrabber.mirror
+    import pycurl
+except ImportError:
+    import mio.urlgrabber_compat as urlgrabber
+    import mio.urlgrabber_compat as pycurl
+    pass
         
 temp = []
 cache = {}
diff --git a/src/mio/urlgrabber_compat.py b/src/mio/urlgrabber_compat.py
new file mode 100755
index 0000000..b7ba67f
--- /dev/null
+++ b/src/mio/urlgrabber_compat.py
@@ -0,0 +1,53 @@
+#
+# Hackish compat library when urlgrabber is missing (MacOS)
+#
+import urllib2
+import calendar
+import time
+
+INFO_FILETIME = object()
+
+class CurlWrapper:
+
+    def __init__(self, url):
+        self.url = url
+        self.curl_obj = self
+        self.scheme = self.url.geturl().split(':', 1)[0]
+
+    def getinfo(self, what):
+        if what == INFO_FILETIME:
+            modified = self.url.info()["Last-Modified"]
+            mtime = calendar.timegm(time.strptime(modified, 
+                                                  "%a, %d %b %Y %H:%M:%S %Z"))
+            return mtime
+        raise Exception('Unknown getifo %s', what)
+    
+    def __getattr__(self, what):
+        return getattr(self.url, what)
+    pass
+
+class Compat: 
+    URLGrabError = Exception()
+
+    def URLGrabber(self):
+        pass
+
+    class MirrorGroup:
+        
+        def __init__(self, grabber, urls):
+            self.urls = urls
+            
+        def urlopen(self, path):
+            for u in self.urls:
+                url = "%s/%s" % (u, path)
+                try:
+                    return CurlWrapper(urllib2.urlopen(url))
+                except IOError, e:
+                    pass
+            raise IOError("Failed to get '%s' (%s)" % (path, e))
+            
+    pass
+
+compat = Compat()
+grabber = compat
+mirror = grabber
-- 
GitLab