* autoxml, xmlfile: implement uri support for downloading remote files
* disable minidom
This commit is contained in:
@@ -74,9 +74,10 @@ Legend:
|
|||||||
|
|
||||||
3. Beta
|
3. Beta
|
||||||
|
|
||||||
- improve url support, it's a little dumb at the moment
|
/ improve url support, it's a little dumb at the moment
|
||||||
- devise a File class that works with URLs
|
+ devise a File class that works with URLs
|
||||||
- consider adding "other" protocols
|
+ add URL support to autoxml
|
||||||
|
? consider adding "other" protocols
|
||||||
- removable media: media://
|
- removable media: media://
|
||||||
|
|
||||||
+ info cmd: reverse dependencies of a package
|
+ info cmd: reverse dependencies of a package
|
||||||
|
|||||||
@@ -397,9 +397,9 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
cls.__ne__ = notequal
|
cls.__ne__ = notequal
|
||||||
|
|
||||||
if xmlfile_support:
|
if xmlfile_support:
|
||||||
def read(self, filename, keepDoc = False):
|
def read(self, uri, keepDoc = False, tmpDir = '/tmp'):
|
||||||
"read XML file and decode it into a python object"
|
"read XML file and decode it into a python object"
|
||||||
self.readxml(filename)
|
self.readxml(uri, tmpDir)
|
||||||
errs = []
|
errs = []
|
||||||
self.decode(self.rootNode(), errs)
|
self.decode(self.rootNode(), errs)
|
||||||
if hasattr(self, 'read_hook'):
|
if hasattr(self, 'read_hook'):
|
||||||
@@ -416,7 +416,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
errs.append(_("autoxml.read: File '%s' has errors") % filename)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
|
|
||||||
def write(self, filename, keepDoc = False):
|
def write(self, uri, keepDoc = False, tmpDir = '/tmp'):
|
||||||
"encode the contents of the python object into an XML file"
|
"encode the contents of the python object into an XML file"
|
||||||
errs = self.errors()
|
errs = self.errors()
|
||||||
if errs:
|
if errs:
|
||||||
@@ -430,7 +430,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
if errs:
|
if errs:
|
||||||
errs.append(_("autoxml.write: File encoding '%s' has errors") % filename)
|
errs.append(_("autoxml.write: File encoding '%s' has errors") % filename)
|
||||||
raise Error(*errs)
|
raise Error(*errs)
|
||||||
self.writexml(filename)
|
self.writexml(uri, tmpDir)
|
||||||
if not keepDoc:
|
if not keepDoc:
|
||||||
self.unlink() # get rid of the tree
|
self.unlink() # get rid of the tree
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ except:
|
|||||||
try:
|
try:
|
||||||
from xmlextcdom import *
|
from xmlextcdom import *
|
||||||
except:
|
except:
|
||||||
|
raise Error('cannot find 4suite implementation')
|
||||||
print 'xmlext: cDomlette/piksemel implementation cannot be loaded, falling back to minidom'
|
print 'xmlext: cDomlette/piksemel implementation cannot be loaded, falling back to minidom'
|
||||||
from xmlextmdom import *
|
from xmlextmdom import *
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ except:
|
|||||||
try:
|
try:
|
||||||
from xmlfilecdom import *
|
from xmlfilecdom import *
|
||||||
except:
|
except:
|
||||||
|
raise Error('cannot find 4suite implementation')
|
||||||
print 'xmlext: cDomlette/piksemel implementation cannot be loaded, falling back to minidom'
|
print 'xmlext: cDomlette/piksemel implementation cannot be loaded, falling back to minidom'
|
||||||
from xmlfilemdom import *
|
from xmlfilemdom import *
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ XML_NS = unicode(XML_NAMESPACE)
|
|||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
from pisi.pxml.xmlextcdom import *
|
from pisi.pxml.xmlextcdom import *
|
||||||
|
from pisi.file import File
|
||||||
|
from pisi.util import join_path as join
|
||||||
|
|
||||||
class Error(pisi.Error):
|
class Error(pisi.Error):
|
||||||
pass
|
pass
|
||||||
@@ -66,16 +68,18 @@ class XmlFile(object):
|
|||||||
"""returns root document element"""
|
"""returns root document element"""
|
||||||
return self.doc.documentElement
|
return self.doc.documentElement
|
||||||
|
|
||||||
def readxml(self, path):
|
def readxml(self, uri, tmpDir = '/tmp'):
|
||||||
|
uri = File.make_uri(uri)
|
||||||
|
localpath = File.download(uri, tmpDir)
|
||||||
try:
|
try:
|
||||||
self.doc = ParsePath(path)
|
self.doc = ParsePath(localpath)
|
||||||
return self.doc.documentElement
|
return self.doc.documentElement
|
||||||
except Ft.FtException, e:
|
except Ft.FtException, e:
|
||||||
raise Error(_("File '%s' has invalid XML: %s") % (path, str(e)) )
|
raise Error(_("File '%s' has invalid XML: %s") % (path, str(e)) )
|
||||||
except exceptions.ValueError, e:
|
except exceptions.ValueError, e:
|
||||||
raise Error(_("File '%s' not found") % path )
|
raise Error(_("File '%s' not found") % path )
|
||||||
|
|
||||||
def writexml(self, path):
|
def writexml(self, uri, tmpDir = '/tmp'):
|
||||||
f = file(path, 'w')
|
f = file(path, 'w')
|
||||||
PrettyPrint(self.rootNode(), stream = f)
|
PrettyPrint(self.rootNode(), stream = f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user