Example #1
0
class CachingEntityResolver(EntityResolver):
    def __init__(self, parser, dir):
        self.parser = parser
        if not os.path.isdir(dir):
            raise Exception("CachingEntityResolver: no such directory: %s" %
                            dir)
        self.cache = URLCache(dir)

    def resolveEntity(self, pubid, sysid):
        parser_sysid = self.parser.getSystemId()
        src = None
        if sysid.startswith("http:"):
            src = self.resolveURL(sysid)
        elif isinstance(parser_sysid,
                        StringTypes) and parser_sysid.startswith("http:"):
            src = self.resolveURL(sysid, parser_sysid)
        if not src:
            src = EntityResolver.resolveEntity(self, p, s)
        return src

    def resolveURL(self, sysid, base=""):
        url = urllib.parse.urljoin(base, sysid)
        source = xml.sax.xmlreader.InputSource(url)
        f = self.cache.get(url)
        source.setByteStream(f)
        return source
Example #2
0
class CachingEntityResolver (EntityResolver):
	def __init__ (self, parser, dir):
		self.parser = parser
		if not os.path.isdir (dir):
			raise Exception ("CachingEntityResolver: no such directory: %s" % dir)
		self.cache = URLCache (dir)

	def resolveEntity (self, pubid, sysid):
		parser_sysid = self.parser.getSystemId ()
		src = None
		if sysid.startswith ("http:"):
			src = self.resolveURL (sysid)
		elif isinstance (parser_sysid, StringTypes) and parser_sysid.startswith ("http:"):
			src = self.resolveURL (sysid, parser_sysid)
		if not src:
			src = EntityResolver.resolveEntity (self, p, s)
		return src

	def resolveURL (self, sysid, base = ""):
		url = urlparse.urljoin (base, sysid)
		source = xml.sax.xmlreader.InputSource (url)
		f = self.cache.get (url)
		source.setByteStream (f)
		return source
Example #3
0
	def __init__ (self, parser, dir):
		self.parser = parser
		if not os.path.isdir (dir):
			raise Exception ("CachingEntityResolver: no such directory: %s" % dir)
		self.cache = URLCache (dir)
Example #4
0
 def __init__(self, parser, dir):
     self.parser = parser
     if not os.path.isdir(dir):
         raise Exception("CachingEntityResolver: no such directory: %s" %
                         dir)
     self.cache = URLCache(dir)