XInclude HREFs can now be relative.

Still trying to minimize namespaces declarations.
This commit is contained in:
eraviart 2004-06-26 11:44:15 +00:00
parent 622ba4da36
commit 9d0d9a7144
8 changed files with 34 additions and 22 deletions

View File

@ -101,8 +101,7 @@ class Election(things.Thing):
spipText = voteSubjects[votePageNode]
htmlText = "<spip>%s</spip>" % parsers.makeHtmlFromSpip(spipText)
doc = libxml2.readDoc(
htmlText, None, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
htmlText, None, None, libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
node = doc.getRootElement().children
while node is not None:
subjectDiv.append(node)

View File

@ -230,6 +230,7 @@ class DataHolder(stations.AbstractStation):
fileSystemConfigPath = os.path.join(fileSystemPath, "_config.xml")
else:
fileSystemConfigPath = fileSystemPath + ".config.xml"
absoluteConfigPath = fileSystem.getAbsolutePath(fileSystemConfigPath)
try:
configFile = fileSystem.open(fileSystemConfigPath, "rb")
except IOError, error:
@ -249,12 +250,12 @@ class DataHolder(stations.AbstractStation):
# FIXME: What to use for URL instead of None (second argument)?
if hasattr(configFile, "fileno"):
configDoc = libxml2.readFd(
configFile.fileno(), None, None,
configFile.fileno(), absoluteConfigPath, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
else:
# For zip files, ...
configDoc = libxml2.readDoc(
configFile.read(), None, None,
configFile.read(), absoluteConfigPath, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
except libxml2.parserError:
logs.info('Error while parsing XML file at "%s".' % fileSystemConfigPath)
@ -364,6 +365,7 @@ class DataHolder(stations.AbstractStation):
fileSystemMetadataPath = fileSystemPath + ".meta.xml"
metadataHolderPathFragment = self.pathFragment + ".meta.xml"
metadataHolderParent = self.getParent()
absoluteMetadataPath = fileSystem.getAbsolutePath(fileSystemMetadataPath)
try:
metadataFile = fileSystem.open(fileSystemMetadataPath, "rb")
except IOError, error:
@ -383,12 +385,12 @@ class DataHolder(stations.AbstractStation):
# FIXME: What to use for URL instead of None (second argument)?
if hasattr(metadataFile, "fileno"):
metadataDoc = libxml2.readFd(
metadataFile.fileno(), None, None,
metadataFile.fileno(), absoluteMetadataPath, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
else:
# For zip files, ...
metadataDoc = libxml2.readDoc(
metadataFile.read(), None, None,
metadataFile.read(), absoluteMetadataPath, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
except libxml2.parserError:
logs.info('Error while parsing XML file at "%s".' % fileSystemMetadataPath)
@ -805,12 +807,12 @@ class XmlHolder(DataHolder, documents.AbstractDocument):
# and a warning is logged when one is required.
if hasattr(dataFile, "fileno"):
doc = libxml2.readFd(
dataFile.fileno(), self.getUri(), None,
dataFile.fileno(), self.getAbsolutePath(), None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
else:
# For zip files, ...
doc = libxml2.readDoc(
dataFile.read(), self.getUri(), None,
dataFile.read(), self.getAbsolutePath(), None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
except libxml2.parserError:
logs.info('Error while parsing XML file at "%s".' % self.getAbsolutePath())

View File

@ -134,7 +134,8 @@ class Element(stations.AbstractStation, nodes.NodeWrapper):
if isinstance(item, libxml2.xmlCore):
self.node.addChild(item)
if self.node.doc is not None:
self.node.reconciliateNs(self.node.doc)
# self.node.reconciliateNs(self.node.doc)
self.node.doc.getRootElement().reconciliateNs(self.node.doc)
elif isinstance(item, unicode):
self.node.addContent(item.encode("UTF-8"))
elif isinstance(item, str):

View File

@ -42,6 +42,9 @@ class AbstractFileSystem(object):
def exists(self, filePath):
raise NotImplementedError
def getAbsolutePath(self, path):
raise NotImplementedError
def getModificationTime(self, filePath):
raise NotImplementedError
@ -85,15 +88,18 @@ class InheritedFileSystem(AbstractFileSystem):
def execute(self, filePath, globalVariables = None, localVariables = None):
if self.implementation.exists(filePath):
return self.implementation.execute(
filePath, globalVariables, localVariables)
return self.implementation.execute(filePath, globalVariables, localVariables)
else:
return self.prototype.execute(
filePath, globalVariables, localVariables)
return self.prototype.execute(filePath, globalVariables, localVariables)
def exists(self, filePath):
return self.implementation.exists(filePath) \
or self.prototype.exists(filePath)
return self.implementation.exists(filePath) or self.prototype.exists(filePath)
def getAbsolutePath(self, path):
if self.implementation.exists(path):
return self.implementation.getAbsolutePath(path)
else:
return self.prototype.getAbsolutePath(path)
def getModificationTime(self, filePath):
if self.implementation.exists(filePath):
@ -165,6 +171,9 @@ class PartialFileSystem(AbstractFileSystem):
fullFilePath = os.path.normpath(os.path.join(self.path, filePath))
return os.path.exists(fullFilePath)
def getAbsolutePath(self, path):
return os.path.normpath(os.path.join(self.path, path))
def getModificationTime(self, filePath):
fullFilePath = os.path.normpath(os.path.join(self.path, filePath))
return time.gmtime(os.stat(fullFilePath)[-2])
@ -231,6 +240,9 @@ class ZipFileSystem(AbstractFileSystem):
else:
return self.isdir(filePath)
def getAbsolutePath(self, path):
return os.path.normpath(os.path.join(self.archive.filename, path))
def getModificationTime(self, filePath):
info = self.archive.getinfo(filePath)
return time.gmtime(time.mktime(info.date_time + (0, 0, -1)))

View File

@ -142,7 +142,7 @@ class DbXmlContainerHolder(dataholders.DataHolder):
childNode = libxml2.newNode("node")
doc = libxml2.readDoc(
value.asString(),
self.getUri(),
self.getAbsolutePath(),
None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
childNode.addChild(doc.getRootElement())
@ -260,7 +260,7 @@ class DbXmlDocumentStation(stations.AbstractStation, documents.AbstractDocument)
self.dbxmlDocument = document
try:
node = libxml2.readDoc(
self.dbxmlDocument.getContentAsString(), self.getUri(), None,
self.dbxmlDocument.getContentAsString(), self.getAbsolutePath(), None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
self.publicName = self.localId
except libxml2.parserError:

View File

@ -999,8 +999,7 @@ class SpipType(xmlschemas.Type):
htmlText = "<spip>%s</spip>" % makeHtmlFromSpip(
valueNode.content)
doc = libxml2.readDoc(
htmlText, None, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
htmlText, None, None, libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
node = doc.getRootElement().children
result = []
while node is not None:

View File

@ -574,8 +574,7 @@ class Spip(xforms.TextArea):
if content:
htmlText = "<spip>%s</spip>" % spip.makeHtmlFromSpip(content)
doc = libxml2.readDoc(
htmlText, None, None,
libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
htmlText, None, None, libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
node = doc.getRootElement().children
while node is not None:
layout.append(node)

View File

@ -102,7 +102,7 @@ class ZipHolder(directories.DirectoryHolder):
## if self.node is None:
## try:
## self.node = libxml2.readDoc(
## data, self.getUri(), None,
## data, self.getAbsolutePath(), None,
## libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET)
## except libxml2.parserError:
## logs.info('Error while parsing XML file at "%s".' % self.getAbsolutePath())