Ejemplo n.º 1
0
 def __init__(self):
     self._default_public_ids = {
         "HTML": "-//W3C//DTD HTML 5//EN",
     }
     self._default_namespace_ids = {}
     self.defaultHandler = EmptyDatasetHandler()
     self.resolver = CatalogResolver()
Ejemplo n.º 2
0
class DatasetHandlerService:
    handlers = {}  # empty dataset handlers
    resolver = None

    def __init__(self):
        self.defaultHandler = EmptyDatasetHandler()
        self.resolver = CatalogResolver()

    def setCatalogs(self, catalogs):
        self.resolver.resetCatalogs(catalogs)
        DatasetHandlerService.handlers = {}

    def getDefaultPublicId(self, lang, env):
        if lang == "HTML":
            return "-//W3C//DTD HTML 4.01//EN"
        return None

    def getDefaultNamespace(self, lang, env):
        return None

    def createDatasetHandler(self, publicId, systemId, namespace):
        dataset = self.resolver.getDataset(publicId, systemId, namespace)
        if not dataset:
            handler = EmptyDatasetHandler()
        else:
            handler = DataSetHandler(namespace, dataset)
        if namespace:
            self.handlers[namespace] = handler
        if publicId or systemId:
            self.handlers[(publicId, systemId)] = handler

        return handler

    def getDocumentHandler(self, publicId=None, systemId=None, namespace=None):
        if namespace:
            if namespace not in self.handlers:
                handler = self.createDatasetHandler(publicId, systemId,
                                                    namespace)
            else:
                handler = self.handlers.get(namespace)
            if handler:
                return handler
        if publicId or systemId:
            key = (publicId, systemId)
            if key not in self.handlers:
                handler = self.createDatasetHandler(publicId, systemId,
                                                    namespace)
            else:
                handler = self.handlers.get(key)
            if handler:
                return handler
        return EmptyDatasetHandler()
Ejemplo n.º 3
0
class DatasetHandlerService:
    handlers = {}  # empty dataset handlers
    resolver = None

    def __init__(self):
        self.defaultHandler = EmptyDatasetHandler()
        self.resolver = CatalogResolver()

    def setCatalogs(self, catalogs):
        self.resolver.resetCatalogs(catalogs)
        DatasetHandlerService.handlers = {}

    def getDefaultPublicId(self, lang, env):
        if lang == "HTML":
            return "-//W3C//DTD HTML 4.01//EN"
        return None

    def getDefaultNamespace(self, lang, env):
        return None

    def createDatasetHandler(self, publicId, systemId, namespace):
        dataset = self.resolver.getDataset(publicId, systemId, namespace)
        if not dataset:
            handler = EmptyDatasetHandler()
        else:
            handler = DataSetHandler(namespace, dataset)
        if namespace:
            self.handlers[namespace] = handler
        if publicId or systemId:
            self.handlers[(publicId, systemId)] = handler

        return handler

    def getDocumentHandler(self, publicId=None, systemId=None, namespace=None):
        if namespace:
            if namespace not in self.handlers:
                handler = self.createDatasetHandler(
                    publicId, systemId, namespace)
            else:
                handler = self.handlers.get(namespace)
            if handler:
                return handler
        if publicId or systemId:
            key = (publicId, systemId)
            if key not in self.handlers:
                handler = self.createDatasetHandler(
                    publicId, systemId, namespace)
            else:
                handler = self.handlers.get(key)
            if handler:
                return handler
        return EmptyDatasetHandler()
 def __init__(self):
     self._default_public_ids = {
         "HTML": "-//W3C//DTD HTML 5//EN",
     }
     self._default_namespace_ids = {}
     self.defaultHandler = EmptyDatasetHandler()
     self.resolver = CatalogResolver()
Ejemplo n.º 5
0
 def __init__(self):
     self.defaultHandler = EmptyDatasetHandler()
     self.resolver = CatalogResolver()
Ejemplo n.º 6
0
class DatasetHandlerService:
    handlers = {}  # empty dataset handlers
    resolver = None

    def __init__(self):
        self._default_public_ids = {
            "HTML": "-//W3C//DTD HTML 5//EN",
        }
        self._default_namespace_ids = {}
        self.defaultHandler = EmptyDatasetHandler()
        self.resolver = CatalogResolver()

    def setCatalogs(self, catalogs):
        self.resolver.resetCatalogs(catalogs)
        DatasetHandlerService.handlers = {}

    def getDefaultPublicId(self, lang, env):
        decl = self._default_public_ids.get(lang, None)
        if env:
            decl = env.get_pref("default%sDecl" % (lang, ), decl)
        return decl

    def setDefaultPublicId(self, lang, public_id):
        self._default_public_ids[lang] = public_id

    def getDefaultNamespace(self, lang, env):
        namespace = self._default_namespace_ids.get(lang, None)
        if env:
            namespace = env.get_pref("default%sNamespace" % (lang, ),
                                     namespace)
        return namespace

    def setDefaultNamespace(self, lang, namespace):
        self._default_namespace_ids[lang] = namespace

    def createDatasetHandler(self, publicId, systemId, namespace):
        dataset = self.resolver.getDataset(publicId, systemId, namespace)
        if not dataset:
            handler = EmptyDatasetHandler()
        else:
            handler = DataSetHandler(namespace, dataset)
        if namespace:
            self.handlers[namespace] = handler
        if publicId or systemId:
            self.handlers[(publicId, systemId)] = handler

        return handler

    def getDocumentHandler(self, publicId=None, systemId=None, namespace=None):
        if namespace:
            if namespace not in self.handlers:
                handler = self.createDatasetHandler(publicId, systemId,
                                                    namespace)
            else:
                handler = self.handlers.get(namespace)
            if handler:
                return handler
        if publicId or systemId:
            key = (publicId, systemId)
            if key not in self.handlers:
                handler = self.createDatasetHandler(publicId, systemId,
                                                    namespace)
            else:
                handler = self.handlers.get(key)
            if handler:
                return handler
        return EmptyDatasetHandler()
Ejemplo n.º 7
0
 def __init__(self):
     self.defaultHandler = EmptyDatasetHandler()
     self.resolver = CatalogResolver()
Ejemplo n.º 8
0
class DatasetHandlerService:
    handlers = {}  # empty dataset handlers
    resolver = None

    def __init__(self):
        self._default_public_ids = {
            "HTML": "-//W3C//DTD HTML 5//EN",
        }
        self._default_namespace_ids = {}
        self.defaultHandler = EmptyDatasetHandler()
        self.resolver = CatalogResolver()

    def setCatalogs(self, catalogs):
        self.resolver.resetCatalogs(catalogs)
        DatasetHandlerService.handlers = {}

    def getDefaultPublicId(self, lang, env):
        decl = self._default_public_ids.get(lang, None)
        if env:
            decl = env.get_pref("default%sDecl" % (lang, ), decl)
        return decl

    def setDefaultPublicId(self, lang, public_id):
        self._default_public_ids[lang] = public_id

    def getDefaultNamespace(self, lang, env):
        namespace = self._default_namespace_ids.get(lang, None)
        if env:
            namespace = env.get_pref("default%sNamespace" % (lang, ),
                                     namespace)
        return namespace

    def setDefaultNamespace(self, lang, namespace):
        self._default_namespace_ids[lang] = namespace

    def getDocumentHandler(self, publicId=None, systemId=None, namespace=None):
        try:
            if namespace:
                if publicId or systemId:
                    log.debug("getDocumentHandler: using all three, %s %s %s",
                              publicId, systemId, namespace)
                    return self.handlers[(publicId, systemId, namespace)]
                else:
                    log.debug("getDocumentHandler: namespace only, %s",
                              namespace)
                    return self.handlers[namespace]
            else:
                log.debug("getDocumentHandler: ids only, %s, %s", publicId,
                          systemId)
                return self.handlers[(publicId, systemId)]
        except KeyError:
            log.debug(
                "getDocumentHandler: Failed, retrying with %s, %s, %s...",
                publicId, systemId, namespace)
            dataset = self.resolver.getDataset(publicId, systemId, namespace)
            if not dataset:
                handler = EmptyDatasetHandler()
            else:
                handler = DataSetHandler(namespace, dataset)
                if namespace:
                    self.handlers[namespace] = handler
                    if publicId or systemId:
                        self.handlers[(publicId, systemId,
                                       namespace)] = handler
                if publicId or systemId:
                    self.handlers[(publicId, systemId)] = handler
            return handler
class DatasetHandlerService:
    handlers = {}  # empty dataset handlers
    resolver = None

    def __init__(self):
        self._default_public_ids = {
            "HTML": "-//W3C//DTD HTML 5//EN",
        }
        self._default_namespace_ids = {}
        self.defaultHandler = EmptyDatasetHandler()
        self.resolver = CatalogResolver()

    def setCatalogs(self, catalogs):
        self.resolver.resetCatalogs(catalogs)
        DatasetHandlerService.handlers = {}

    def getDefaultPublicId(self, lang, env):
        decl = self._default_public_ids.get(lang, None)
        if env:
            decl = env.get_pref("default%sDecl" % (lang,), decl)
        return decl

    def setDefaultPublicId(self, lang, public_id):
        self._default_public_ids[lang] = public_id

    def getDefaultNamespace(self, lang, env):
        namespace = self._default_namespace_ids.get(lang, None)
        if env:
            namespace = env.get_pref("default%sNamespace" % (lang,), namespace)
        return namespace

    def setDefaultNamespace(self, lang, namespace):
        self._default_namespace_ids[lang] = namespace

    def createDatasetHandler(self, publicId, systemId, namespace):
        dataset = self.resolver.getDataset(publicId, systemId, namespace)
        if not dataset:
            handler = EmptyDatasetHandler()
        else:
            handler = DataSetHandler(namespace, dataset)
        if namespace:
            self.handlers[namespace] = handler
        if publicId or systemId:
            self.handlers[(publicId, systemId)] = handler

        return handler

    def getDocumentHandler(self, publicId=None, systemId=None, namespace=None):
        if namespace:
            if namespace not in self.handlers:
                handler = self.createDatasetHandler(
                    publicId, systemId, namespace)
            else:
                handler = self.handlers.get(namespace)
            if handler:
                return handler
        if publicId or systemId:
            key = (publicId, systemId)
            if key not in self.handlers:
                handler = self.createDatasetHandler(
                    publicId, systemId, namespace)
            else:
                handler = self.handlers.get(key)
            if handler:
                return handler
        return EmptyDatasetHandler()
Ejemplo n.º 10
0
class DatasetHandlerService:
    handlers = {} # empty dataset handlers
    resolver = None
    def __init__(self):
        self._default_public_ids = {
            "HTML": "-//W3C//DTD HTML 5//EN",
            "AngularJS": "-//ANGULARJS//DTD HTML 5 NG//EN",
        }
        self._default_namespace_ids = {}
        self.defaultHandler = EmptyDatasetHandler()
        self.resolver = CatalogResolver()

    def setCatalogs(self, catalogs):
        self.resolver.resetCatalogs(catalogs)
        DatasetHandlerService.handlers = {}

    def getDefaultPublicId(self, lang, env):
        decl = self._default_public_ids.get(lang, None)
        if env:
            decl = env.get_pref("default%sDecl" % (lang,), decl)
        return decl

    def setDefaultPublicId(self, lang, public_id):
        self._default_public_ids[lang] = public_id

    def getDefaultNamespace(self, lang, env):
        namespace = self._default_namespace_ids.get(lang, None)
        if env:
            namespace = env.get_pref("default%sNamespace" % (lang,), namespace)
        return namespace

    def setDefaultNamespace(self, lang, namespace):
        self._default_namespace_ids[lang] = namespace

    def getDocumentHandler(self, publicId=None, systemId=None, namespace=None):
        try:
            if namespace:
                if publicId or systemId:
                    log.debug("getDocumentHandler: using all three, %s %s %s",
                              publicId, systemId, namespace)
                    return self.handlers[(publicId, systemId, namespace)]
                else:
                    log.debug("getDocumentHandler: namespace only, %s",
                              namespace)
                    return self.handlers[namespace]
            else:
                log.debug("getDocumentHandler: ids only, %s, %s",
                          publicId, systemId)
                return self.handlers[(publicId, systemId)]
        except KeyError:
            log.debug("getDocumentHandler: Failed, retrying with %s, %s, %s...",
                      publicId, systemId, namespace)
            dataset = self.resolver.getDataset(publicId, systemId, namespace)
            if not dataset:
                handler = EmptyDatasetHandler()
            else:
                handler = DataSetHandler(namespace, dataset)
                if namespace:
                    self.handlers[namespace] = handler
                    if publicId or systemId:
                        self.handlers[(publicId, systemId, namespace)] = handler
                if publicId or systemId:
                    self.handlers[(publicId, systemId)] = handler
            return handler