statichttprepo: make the opener a subclass of abstractopener
authorDan Villiom Podlaski Christiansen <danchr@gmail.com>
Sat, 30 Apr 2011 19:41:25 +0200
changeset 14091 0aa60e4e0b76
parent 14090 e24b5e3c2f27
child 14092 222c8ec7a274
statichttprepo: make the opener a subclass of abstractopener
mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py	Sat Apr 30 19:37:13 2011 +0200
+++ b/mercurial/statichttprepo.py	Sat Apr 30 19:41:25 2011 +0200
@@ -9,7 +9,7 @@
 
 from i18n import _
 import changelog, byterange, url, error
-import localrepo, manifest, util, store
+import localrepo, manifest, util, scmutil, store
 import urllib, urllib2, errno
 
 class httprangereader(object):
@@ -67,17 +67,17 @@
     urlopener = url.opener(ui, authinfo)
     urlopener.add_handler(byterange.HTTPRangeHandler())
 
-    def opener(base):
-        """return a function that opens files over http"""
-        p = base
-        def o(path, mode="r", atomictemp=None):
+    class statichttpopener(scmutil.abstractopener):
+        def __init__(self, base):
+            self.base = base
+
+        def __call__(self, path, mode="r", atomictemp=None):
             if mode not in ('r', 'rb'):
                 raise IOError('Permission denied')
-            f = "/".join((p, urllib.quote(path)))
+            f = "/".join((self.base, urllib.quote(path)))
             return httprangereader(f, urlopener)
-        return o
 
-    return opener
+    return statichttpopener
 
 class statichttprepository(localrepo.localrepository):
     def __init__(self, ui, path):