E4XML/XMLEntityResolver.py

changeset 0
de9c2efb9d02
child 13
1af94a91f439
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2004 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a specialized entity resolver to find our DTDs.
8 """
9
10 import os.path
11 from xml.sax.handler import EntityResolver
12
13 import Utilities
14
15 from eric4config import getConfig
16
17 class XMLEntityResolver(EntityResolver):
18 """
19 Class implementing a specialized entity resolver to find our DTDs.
20 """
21 def resolveEntity(self, publicId, systemId):
22 """
23 Public method to resolve the system identifier of an entity and
24 return either the system identifier to read from as a string.
25
26 @param publicId publicId of an entity (string)
27 @param systemId systemId of an entity to reslove (string)
28 @return resolved systemId (string)
29 """
30 if systemId.startswith('http://'):
31 sId = systemId
32
33 elif os.path.exists(systemId):
34 sId = systemId
35
36 else:
37 dtdDir = getConfig('ericDTDDir')
38 if not os.path.isabs(dtdDir):
39 dtdDir = os.path.abspath(dtdDir)
40 sId = os.path.join(dtdDir, systemId)
41 if not os.path.exists(sId):
42 ind = sId.rfind('-')
43 if ind != -1:
44 sId = "%s.dtd" % sId[:ind]
45 if not os.path.exists(sId):
46 sId = ""
47
48 return sId

eric ide

mercurial