diff --git a/src/mio/filecache.py b/src/mio/filecache.py index a1817dc29e0f824a210244d9926e07b449fed8a2..a47cf3106587c668af332316015bd392e16dfb2d 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 0000000000000000000000000000000000000000..b7ba67f23b3419d5e28137216c3f98062fc37fe4 --- /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