Commit fd552539 authored by 's avatar

Minor fixups

parent 4cce4261
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV support - null resource objects.""" """WebDAV support - null resource objects."""
__version__='$Revision: 1.12 $'[11:-2] __version__='$Revision: 1.13 $'[11:-2]
import sys, os, string, mimetypes import sys, os, string, mimetypes
import Acquisition, OFS.content_types import Acquisition, OFS.content_types
...@@ -99,7 +99,7 @@ class NullResource(Persistent, Acquisition.Implicit, Resource): ...@@ -99,7 +99,7 @@ class NullResource(Persistent, Acquisition.Implicit, Resource):
"""Null resources are used to handle HTTP method calls on """Null resources are used to handle HTTP method calls on
objects which do not yet exist in the url namespace.""" objects which do not yet exist in the url namespace."""
__dav_null__=1 __null_resource__=1
__ac_permissions__=( __ac_permissions__=(
('View', ('HEAD',)), ('View', ('HEAD',)),
...@@ -169,7 +169,7 @@ class NullResource(Persistent, Acquisition.Implicit, Resource): ...@@ -169,7 +169,7 @@ class NullResource(Persistent, Acquisition.Implicit, Resource):
if hasattr(aq_base(parent), name): if hasattr(aq_base(parent), name):
raise 'Method Not Allowed', 'The name %s is in use.' % name raise 'Method Not Allowed', 'The name %s is in use.' % name
if not hasattr(parent, '__dav_collection__'): if not hasattr(parent, '__dav_collection__'):
raise 'Forbidden', 'Unable to create collection resource.' raise 'Forbidden', 'Cannot create collection at this location.'
parent.manage_addFolder(name) parent.manage_addFolder(name)
RESPONSE.setStatus(201) RESPONSE.setStatus(201)
RESPONSE.setBody('') RESPONSE.setBody('')
......
...@@ -85,12 +85,24 @@ ...@@ -85,12 +85,24 @@
"""WebDAV support - resource objects.""" """WebDAV support - resource objects."""
__version__='$Revision: 1.15 $'[11:-2] __version__='$Revision: 1.16 $'[11:-2]
import sys, os, string, mimetypes, xmlcmds import sys, os, string, mimetypes, xmlcmds
from common import absattr, aq_base, urlfix, rfc1123_date from common import absattr, aq_base, urlfix, rfc1123_date
import exceptions
class error(exceptions.Exception):
def __init__(self, msg):
self.msg=msg
html='<html>\n<head>\n<title></title>\n</head>\n<body>\n' \
'%s\n</body></html>'
def __str__(self, fmt=html):
return fmt % self.msg
class Resource: class Resource:
"""The Resource mixin class provides basic WebDAV support for """The Resource mixin class provides basic WebDAV support for
non-collection objects. It provides default implementations non-collection objects. It provides default implementations
...@@ -240,7 +252,7 @@ class Resource: ...@@ -240,7 +252,7 @@ class Resource:
except 'Not Found': except 'Not Found':
raise 'Conflict', 'Object ancestors must already exist.' raise 'Conflict', 'Object ancestors must already exist.'
except: raise sys.exc_type, sys.exc_value except: raise sys.exc_type, sys.exc_value
if hasattr(parent, '__dav_null__'): if hasattr(parent, '__null_resource__'):
raise 'Conflict', 'Object ancestors must already exist.' raise 'Conflict', 'Object ancestors must already exist.'
existing=hasattr(aq_base(parent), name) existing=hasattr(aq_base(parent), name)
if existing and oflag=='F': if existing and oflag=='F':
...@@ -294,7 +306,7 @@ class Resource: ...@@ -294,7 +306,7 @@ class Resource:
except 'Not Found': except 'Not Found':
raise 'Conflict', 'The resource %s must exist.' % path raise 'Conflict', 'The resource %s must exist.' % path
except: raise sys.exc_type, sys.exc_value except: raise sys.exc_type, sys.exc_value
if hasattr(parent, '__dav_null__'): if hasattr(parent, '__null_resource__'):
raise 'Conflict', 'The resource %s must exist.' % path raise 'Conflict', 'The resource %s must exist.' % path
existing=hasattr(aq_base(parent), name) existing=hasattr(aq_base(parent), name)
if existing and flag=='F': if existing and flag=='F':
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV xml request objects.""" """WebDAV xml request objects."""
__version__='$Revision: 1.15 $'[11:-2] __version__='$Revision: 1.16 $'[11:-2]
import sys, os, string import sys, os, string
from common import absattr, aq_base, urlfix from common import absattr, aq_base, urlfix
...@@ -96,7 +96,9 @@ from cStringIO import StringIO ...@@ -96,7 +96,9 @@ from cStringIO import StringIO
class DAVProps(DAVProperties): class DAVProps(DAVProperties):
"""Emulate required DAV properties for objects which do """Emulate required DAV properties for objects which do
not themselves support properties.""" not themselves support properties. This is mainly so
that non-PropertyManagers can appear to support DAV
PROPFIND requests."""
def __init__(self, obj): def __init__(self, obj):
self.__obj__=obj self.__obj__=obj
def v_self(self): def v_self(self):
......
...@@ -83,9 +83,13 @@ ...@@ -83,9 +83,13 @@
# #
############################################################################## ##############################################################################
"""WebDAV XML parsing tools.""" """WebDAV XML parsing tools. Note that this module does just
enough for the purposes of DAV - it is not intended as a
general xml toolkit, and will probably eventually go away
in favor of a standard xml package once some issues are
worked out."""
__version__='$Revision: 1.4 $'[11:-2] __version__='$Revision: 1.5 $'[11:-2]
import sys, os, string, xmllib import sys, os, string, xmllib
from Acquisition import Implicit from Acquisition import Implicit
...@@ -311,7 +315,6 @@ class Text(Node): ...@@ -311,7 +315,6 @@ class Text(Node):
def toxml(self): def toxml(self):
return escape(self.__value__) return escape(self.__value__)
class CData(Node): class CData(Node):
__type__=type_cdata __type__=type_cdata
__name__='#cdata' __name__='#cdata'
...@@ -320,27 +323,19 @@ class CData(Node): ...@@ -320,27 +323,19 @@ class CData(Node):
def toxml(self): def toxml(self):
return '<![CDATA[%s]]>' % self.__value__ return '<![CDATA[%s]]>' % self.__value__
class EntityRef(Node): class EntityRef(Node):
__name__='#entityref' __name__='#entityref'
__type__=type_entityref __type__=type_entityref
def __init__(self, val): def __init__(self, val):
self.__value__=val self.__value__=val
def toxml(self): def toxml(self):
return '&%s;' % self.__value__ return '&%s;' % self.__value__
class Entity(Node): class Entity(Node):
__name__='#entity' __name__='#entity'
__type__=type_entity __type__=type_entity
def __init__(self, name, pubid, sysid, nname): def __init__(self, name, pubid, sysid, nname):
self.__value__=val self.__value__=val
def toxml(self): def toxml(self):
return '' return ''
...@@ -349,18 +344,14 @@ class ProcInst(Node): ...@@ -349,18 +344,14 @@ class ProcInst(Node):
def __init__(self, name, val): def __init__(self, name, val):
self.__name__=name self.__name__=name
self.__value__=val self.__value__=val
def toxml(self): def toxml(self):
return '<?%s %s?>' % (self.__name__, self.__value__) return '<?%s %s?>' % (self.__name__, self.__value__)
class Comment(Node): class Comment(Node):
__name__='#comment' __name__='#comment'
__type__=type_comment __type__=type_comment
def __init__(self, val): def __init__(self, val):
self.__value__=val self.__value__=val
def toxml(self): def toxml(self):
return '<!--%s-->' % self.__value__ return '<!--%s-->' % self.__value__
...@@ -425,26 +416,15 @@ class XmlParser(xmllib.XMLParser): ...@@ -425,26 +416,15 @@ class XmlParser(xmllib.XMLParser):
def escape(data, entities={}): def escape(data, rmap={}, replace=string.replace):
# snarfed from xml.util... data=replace(data, "&", "&amp;")
data = string.replace(data, "&", "&amp;") data=replace(data, "<", "&lt;")
data = string.replace(data, "<", "&lt;") data=replace(data, ">", "&gt;")
data = string.replace(data, ">", "&gt;") for key, val in rmap.items():
for chars, entity in entities.items(): data=replace(data, key, val)
data = string.replace(data, chars, entity)
return data return data
def remap(data): def remap(data, dict={'DAV:': 'd'}):
root=XmlParser().parse(data) root=XmlParser().parse(data)
dict={'DAV:':'d', 'http://www.zope.org/propsets/default':'z'}
root.elements()[0].remap(dict, 0) root.elements()[0].remap(dict, 0)
return root.toxml() return root.toxml()
def remap_test():
file=open('big.xml','r')
data=file.read()
file.close()
data=remap(data)
file=open('new.xml','w')
file.write(data)
file.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment