Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
726d61b2
Commit
726d61b2
authored
Nov 29, 2001
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced string module calls by string methods
parent
093b1ad8
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
53 deletions
+64
-53
lib/python/webdav/Collection.py
lib/python/webdav/Collection.py
+4
-4
lib/python/webdav/LockItem.py
lib/python/webdav/LockItem.py
+8
-8
lib/python/webdav/Resource.py
lib/python/webdav/Resource.py
+11
-11
lib/python/webdav/common.py
lib/python/webdav/common.py
+14
-3
lib/python/webdav/davcmds.py
lib/python/webdav/davcmds.py
+8
-8
lib/python/webdav/xmltools.py
lib/python/webdav/xmltools.py
+19
-19
No files found.
lib/python/webdav/Collection.py
View file @
726d61b2
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
"""WebDAV support - collection objects."""
"""WebDAV support - collection objects."""
__version__
=
'$Revision: 1.2
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
3
$'
[
11
:
-
2
]
import
sys
,
os
,
string
,
Globals
,
davcmds
,
Lockable
,
re
import
sys
,
os
,
Globals
,
davcmds
,
Lockable
,
re
from
common
import
urlfix
,
rfc1123_date
from
common
import
urlfix
,
rfc1123_date
from
Resource
import
Resource
from
Resource
import
Resource
from
AccessControl
import
getSecurityManager
from
AccessControl
import
getSecurityManager
...
@@ -77,7 +77,7 @@ class Collection(Resource):
...
@@ -77,7 +77,7 @@ class Collection(Resource):
self
.
dav__init
(
REQUEST
,
RESPONSE
)
self
.
dav__init
(
REQUEST
,
RESPONSE
)
ifhdr
=
REQUEST
.
get_header
(
'If'
,
''
)
ifhdr
=
REQUEST
.
get_header
(
'If'
,
''
)
url
=
urlfix
(
REQUEST
[
'URL'
],
'DELETE'
)
url
=
urlfix
(
REQUEST
[
'URL'
],
'DELETE'
)
name
=
unquote
(
filter
(
None
,
string
.
split
(
url
,
'/'
))[
-
1
])
name
=
unquote
(
filter
(
None
,
url
.
split
(
'/'
))[
-
1
])
parent
=
self
.
aq_parent
parent
=
self
.
aq_parent
user
=
getSecurityManager
().
getUser
()
user
=
getSecurityManager
().
getUser
()
token
=
None
token
=
None
...
@@ -106,7 +106,7 @@ class Collection(Resource):
...
@@ -106,7 +106,7 @@ class Collection(Resource):
for
tok
in
tokens
:
for
tok
in
tokens
:
# We already know that the simple if handler succeeded,
# We already know that the simple if handler succeeded,
# we just want to get the right token out of the header now
# we just want to get the right token out of the header now
if
string
.
find
(
ifhdr
,
tok
)
>
-
1
:
if
ifhdr
.
find
(
tok
)
>
-
1
:
token
=
tok
token
=
tok
cmd
=
davcmds
.
DeleteCollection
()
cmd
=
davcmds
.
DeleteCollection
()
result
=
cmd
.
apply
(
self
,
token
,
user
,
REQUEST
[
'URL'
])
result
=
cmd
.
apply
(
self
,
token
,
user
,
REQUEST
[
'URL'
])
...
...
lib/python/webdav/LockItem.py
View file @
726d61b2
...
@@ -11,9 +11,9 @@
...
@@ -11,9 +11,9 @@
#
#
##############################################################################
##############################################################################
__version__
=
"$Revision: 1.4 $"
[
11
:
-
2
]
__version__
=
"$Revision: 1.5 $"
[
11
:
-
2
]
from
string
import
lower
,
split
,
join
from
Globals
import
Persistent
from
Globals
import
Persistent
from
WriteLockInterface
import
LockItemInterface
from
WriteLockInterface
import
LockItemInterface
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
...
@@ -28,8 +28,8 @@ def validateTimeout(timeout):
...
@@ -28,8 +28,8 @@ def validateTimeout(timeout):
# Timeout *should* be in the form "Seconds-XXX" or "Infinite"
# Timeout *should* be in the form "Seconds-XXX" or "Infinite"
errors
=
[]
errors
=
[]
try
:
try
:
t
=
split
(
str
(
timeout
),
'-'
)[
-
1
]
t
=
str
(
timeout
).
split
(
'-'
)[
-
1
]
if
lower
(
t
)
==
'infinite'
:
if
t
.
lower
(
)
==
'infinite'
:
timeout
=
DEFAULTTIMEOUT
# Default to 1800 secods for infinite
timeout
=
DEFAULTTIMEOUT
# Default to 1800 secods for infinite
else
:
# requests
else
:
# requests
timeout
=
long
(
t
)
timeout
=
long
(
t
)
...
@@ -60,11 +60,11 @@ class LockItem(Persistent):
...
@@ -60,11 +60,11 @@ class LockItem(Persistent):
# First check the values and raise value errors if outside of contract
# First check the values and raise value errors if outside of contract
if
not
getattr
(
creator
,
'getUserName'
,
None
):
if
not
getattr
(
creator
,
'getUserName'
,
None
):
errors
.
append
(
"Creator not a user object"
)
errors
.
append
(
"Creator not a user object"
)
if
lower
(
str
(
depth
)
)
not
in
(
'0'
,
'infinity'
):
if
str
(
depth
).
lower
(
)
not
in
(
'0'
,
'infinity'
):
errors
.
append
(
"Depth must be 0 or infinity"
)
errors
.
append
(
"Depth must be 0 or infinity"
)
if
lo
wer
(
locktype
)
!=
'write'
:
if
lo
cktype
.
lower
(
)
!=
'write'
:
errors
.
append
(
"Lock type '%s' not supported"
%
locktype
)
errors
.
append
(
"Lock type '%s' not supported"
%
locktype
)
if
lo
wer
(
lockscope
)
!=
'exclusive'
:
if
lo
ckscope
.
lower
(
)
!=
'exclusive'
:
errors
.
append
(
"Lock scope '%s' not supported"
%
lockscope
)
errors
.
append
(
"Lock scope '%s' not supported"
%
lockscope
)
timeout
,
e
=
validateTimeout
(
timeout
)
timeout
,
e
=
validateTimeout
(
timeout
)
...
@@ -95,7 +95,7 @@ class LockItem(Persistent):
...
@@ -95,7 +95,7 @@ class LockItem(Persistent):
def
getCreatorPath
(
self
):
def
getCreatorPath
(
self
):
db
,
name
=
self
.
_creator
db
,
name
=
self
.
_creator
path
=
join
(
db
,
'/'
)
path
=
'/'
.
join
(
db
)
return
"/%s/%s"
%
(
path
,
name
)
return
"/%s/%s"
%
(
path
,
name
)
def
getOwner
(
self
):
def
getOwner
(
self
):
...
...
lib/python/webdav/Resource.py
View file @
726d61b2
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
"""WebDAV support - resource objects."""
"""WebDAV support - resource objects."""
__version__
=
'$Revision: 1.
49
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
50
$'
[
11
:
-
2
]
import
sys
,
os
,
string
,
mimetypes
,
davcmds
,
ExtensionClass
,
Lockable
import
sys
,
os
,
mimetypes
,
davcmds
,
ExtensionClass
,
Lockable
from
common
import
absattr
,
aq_base
,
urlfix
,
rfc1123_date
,
tokenFinder
,
urlbase
from
common
import
absattr
,
aq_base
,
urlfix
,
rfc1123_date
,
tokenFinder
,
urlbase
from
common
import
IfParser
from
common
import
IfParser
from
urllib
import
quote
,
unquote
from
urllib
import
quote
,
unquote
...
@@ -104,7 +104,7 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
...
@@ -104,7 +104,7 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
# if 'col' is passed in, an operation is happening on a submember
# if 'col' is passed in, an operation is happening on a submember
# of a collection, while the Lock may be on the parent. Lob off
# of a collection, while the Lock may be on the parent. Lob off
# the final part of the URL (ie '/a/b/foo.html' becomes '/a/b/')
# the final part of the URL (ie '/a/b/foo.html' becomes '/a/b/')
if
col
:
url
=
url
[:
string
.
rfind
(
url
,
'/'
)
+
1
]
if
col
:
url
=
url
[:
url
.
rfind
(
'/'
)
+
1
]
havetag
=
lambda
x
,
self
=
self
:
self
.
wl_hasLock
(
x
)
havetag
=
lambda
x
,
self
=
self
:
self
.
wl_hasLock
(
x
)
found
=
0
;
resourcetagged
=
0
found
=
0
;
resourcetagged
=
0
...
@@ -151,14 +151,14 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
...
@@ -151,14 +151,14 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
content_type
=
absattr
(
self
.
content_type
)
content_type
=
absattr
(
self
.
content_type
)
if
content_type
is
None
:
if
content_type
is
None
:
url
=
urlfix
(
REQUEST
[
'URL'
],
'HEAD'
)
url
=
urlfix
(
REQUEST
[
'URL'
],
'HEAD'
)
name
=
unquote
(
filter
(
None
,
string
.
split
(
url
,
'/'
))[
-
1
]
)
name
=
unquote
(
filter
(
None
,
url
.
split
(
'/'
)[
-
1
])
)
content_type
,
encoding
=
mimetypes
.
guess_type
(
name
)
content_type
,
encoding
=
mimetypes
.
guess_type
(
name
)
if
content_type
is
None
:
if
content_type
is
None
:
if
hasattr
(
self
,
'default_content_type'
):
if
hasattr
(
self
,
'default_content_type'
):
content_type
=
absattr
(
self
.
default_content_type
)
content_type
=
absattr
(
self
.
default_content_type
)
if
content_type
is
None
:
if
content_type
is
None
:
content_type
=
'application/octet-stream'
content_type
=
'application/octet-stream'
RESPONSE
.
setHeader
(
'Content-Type'
,
string
.
lower
(
content_type
))
RESPONSE
.
setHeader
(
'Content-Type'
,
content_type
.
lower
(
))
if
hasattr
(
aq_base
(
self
),
'get_size'
):
if
hasattr
(
aq_base
(
self
),
'get_size'
):
RESPONSE
.
setHeader
(
'Content-Length'
,
absattr
(
self
.
get_size
))
RESPONSE
.
setHeader
(
'Content-Length'
,
absattr
(
self
.
get_size
))
...
@@ -183,7 +183,7 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
...
@@ -183,7 +183,7 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
def
OPTIONS
(
self
,
REQUEST
,
RESPONSE
):
def
OPTIONS
(
self
,
REQUEST
,
RESPONSE
):
"""Retrieve communication options."""
"""Retrieve communication options."""
self
.
dav__init
(
REQUEST
,
RESPONSE
)
self
.
dav__init
(
REQUEST
,
RESPONSE
)
RESPONSE
.
setHeader
(
'Allow'
,
string
.
join
(
self
.
__http_methods__
,
', '
))
RESPONSE
.
setHeader
(
'Allow'
,
', '
.
join
(
self
.
__http_methods__
))
RESPONSE
.
setHeader
(
'Content-Length'
,
0
)
RESPONSE
.
setHeader
(
'Content-Length'
,
0
)
RESPONSE
.
setHeader
(
'DAV'
,
'1,2'
,
1
)
RESPONSE
.
setHeader
(
'DAV'
,
'1,2'
,
1
)
RESPONSE
.
setStatus
(
200
)
RESPONSE
.
setStatus
(
200
)
...
@@ -206,7 +206,7 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
...
@@ -206,7 +206,7 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
self
.
dav__init
(
REQUEST
,
RESPONSE
)
self
.
dav__init
(
REQUEST
,
RESPONSE
)
ifhdr
=
REQUEST
.
get_header
(
'If'
,
''
)
ifhdr
=
REQUEST
.
get_header
(
'If'
,
''
)
url
=
urlfix
(
REQUEST
[
'URL'
],
'DELETE'
)
url
=
urlfix
(
REQUEST
[
'URL'
],
'DELETE'
)
name
=
unquote
(
filter
(
None
,
string
.
split
(
url
,
'/'
))[
-
1
]
)
name
=
unquote
(
filter
(
None
,
url
.
split
(
'/'
)[
-
1
])
)
parent
=
self
.
aq_parent
parent
=
self
.
aq_parent
# Lock checking
# Lock checking
if
Lockable
.
wl_isLocked
(
self
):
if
Lockable
.
wl_isLocked
(
self
):
...
@@ -301,9 +301,9 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
...
@@ -301,9 +301,9 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
raise
'Bad Request'
,
'Invalid Destination header'
raise
'Bad Request'
,
'Invalid Destination header'
name
=
path
.
pop
()
name
=
path
.
pop
()
parent_path
=
string
.
join
(
path
,
'/'
)
parent_path
=
'/'
.
join
(
path
)
oflag
=
string
.
upper
(
REQUEST
.
get_header
(
'Overwrite'
,
'F'
)
)
oflag
=
REQUEST
.
get_header
(
'Overwrite'
,
'F'
).
upper
(
)
if
not
oflag
in
(
'T'
,
'F'
):
if
not
oflag
in
(
'T'
,
'F'
):
raise
'Bad Request'
,
'Invalid Overwrite header.'
raise
'Bad Request'
,
'Invalid Overwrite header.'
...
@@ -390,10 +390,10 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
...
@@ -390,10 +390,10 @@ class Resource(ExtensionClass.Base, Lockable.LockableItem):
raise
'Bad Request'
,
'No destination given'
raise
'Bad Request'
,
'No destination given'
flag
=
REQUEST
.
get_header
(
'Overwrite'
,
'F'
)
flag
=
REQUEST
.
get_header
(
'Overwrite'
,
'F'
)
flag
=
string
.
upper
(
flag
)
flag
=
flag
.
upper
(
)
name
=
path
.
pop
()
name
=
path
.
pop
()
parent_path
=
string
.
join
(
path
,
'/'
)
parent_path
=
'/'
.
join
(
path
)
try
:
parent
=
self
.
restrictedTraverse
(
path
)
try
:
parent
=
self
.
restrictedTraverse
(
path
)
except
ValueError
:
except
ValueError
:
...
...
lib/python/webdav/common.py
View file @
726d61b2
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
"""Commonly used functions for WebDAV support modules."""
"""Commonly used functions for WebDAV support modules."""
__version__
=
'$Revision: 1.1
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
4
$'
[
11
:
-
2
]
import
string
,
time
,
urllib
,
re
import
time
,
urllib
,
re
from
App.Common
import
iso8601_date
,
rfc850_date
,
rfc1123_date
from
App.Common
import
iso8601_date
,
rfc850_date
,
rfc1123_date
from
App.Common
import
aq_base
from
App.Common
import
aq_base
...
@@ -31,6 +31,17 @@ def urlfix(url, s):
...
@@ -31,6 +31,17 @@ def urlfix(url, s):
url
=
url
[:
-
1
]
url
=
url
[:
-
1
]
return
url
return
url
def
is_acquired
(
ob
):
# Return true if this object is not a direct
# subobject of its aq_parent object.
if
not
hasattr
(
ob
,
'aq_parent'
):
return
0
if
hasattr
(
aq_base
(
ob
.
aq_parent
),
absattr
(
ob
.
id
)):
return
0
if
hasattr
(
aq_base
(
ob
),
'isTopLevelPrincipiaApplicationObject'
)
and
\
ob
.
isTopLevelPrincipiaApplicationObject
:
return
0
return
1
def
urlbase
(
url
,
ftype
=
urllib
.
splittype
,
fhost
=
urllib
.
splithost
):
def
urlbase
(
url
,
ftype
=
urllib
.
splittype
,
fhost
=
urllib
.
splithost
):
# Return a '/' based url such as '/foo/bar', removing
# Return a '/' based url such as '/foo/bar', removing
...
@@ -53,7 +64,7 @@ def tokenFinder(token):
...
@@ -53,7 +64,7 @@ def tokenFinder(token):
if
not
token
:
return
None
# An empty string was passed in
if
not
token
:
return
None
# An empty string was passed in
if
token
[
0
]
==
'['
:
return
None
# An Etag was passed in
if
token
[
0
]
==
'['
:
return
None
# An Etag was passed in
if
token
[
0
]
==
'<'
:
token
=
token
[
1
:
-
1
]
if
token
[
0
]
==
'<'
:
token
=
token
[
1
:
-
1
]
return
token
[
string
.
find
(
token
,
':'
)
+
1
:]
return
token
[
token
.
find
(
':'
)
+
1
:]
### If: header handling support. IfParser returns a sequence of
### If: header handling support. IfParser returns a sequence of
...
...
lib/python/webdav/davcmds.py
View file @
726d61b2
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
"""WebDAV xml request objects."""
"""WebDAV xml request objects."""
__version__
=
'$Revision: 1.1
5
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
6
$'
[
11
:
-
2
]
import
sys
,
os
,
string
import
sys
,
os
from
common
import
absattr
,
aq_base
,
urlfix
,
urlbase
from
common
import
absattr
,
aq_base
,
urlfix
,
urlbase
from
OFS.PropertySheets
import
DAVProperties
from
OFS.PropertySheets
import
DAVProperties
from
LockItem
import
LockItem
from
LockItem
import
LockItem
...
@@ -26,8 +26,8 @@ from cStringIO import StringIO
...
@@ -26,8 +26,8 @@ from cStringIO import StringIO
from
urllib
import
quote
from
urllib
import
quote
from
AccessControl
import
getSecurityManager
from
AccessControl
import
getSecurityManager
def
safe_quote
(
url
,
mark
=
r'%'
,
find
=
string
.
find
):
def
safe_quote
(
url
,
mark
=
r'%'
):
if
find
(
url
,
mark
)
>
-
1
:
if
url
.
find
(
mark
)
>
-
1
:
return
url
return
url
return
quote
(
url
)
return
quote
(
url
)
...
@@ -105,14 +105,14 @@ class PropFind:
...
@@ -105,14 +105,14 @@ class PropFind:
for
ps
in
propsets
:
for
ps
in
propsets
:
if
hasattr
(
aq_base
(
ps
),
'dav__allprop'
):
if
hasattr
(
aq_base
(
ps
),
'dav__allprop'
):
stats
.
append
(
ps
.
dav__allprop
())
stats
.
append
(
ps
.
dav__allprop
())
stats
=
string
.
join
(
stats
,
''
)
or
'<d:status>200 OK</d:status>
\
n
'
stats
=
''
.
join
(
stats
)
or
'<d:status>200 OK</d:status>
\
n
'
result
.
write
(
stats
)
result
.
write
(
stats
)
elif
self
.
propname
:
elif
self
.
propname
:
stats
=
[]
stats
=
[]
for
ps
in
propsets
:
for
ps
in
propsets
:
if
hasattr
(
aq_base
(
ps
),
'dav__propnames'
):
if
hasattr
(
aq_base
(
ps
),
'dav__propnames'
):
stats
.
append
(
ps
.
dav__propnames
())
stats
.
append
(
ps
.
dav__propnames
())
stats
=
string
.
join
(
stats
,
''
)
or
'<d:status>200 OK</d:status>
\
n
'
stats
=
''
.
join
(
stats
)
or
'<d:status>200 OK</d:status>
\
n
'
result
.
write
(
stats
)
result
.
write
(
stats
)
elif
self
.
propnames
:
elif
self
.
propnames
:
rdict
=
{}
rdict
=
{}
...
@@ -266,7 +266,7 @@ class PropPatch:
...
@@ -266,7 +266,7 @@ class PropPatch:
# This is lame, but I cant find a way to keep ZPublisher
# This is lame, but I cant find a way to keep ZPublisher
# from sticking a traceback into my xml response :(
# from sticking a traceback into my xml response :(
get_transaction
().
abort
()
get_transaction
().
abort
()
result
=
string
.
replace
(
result
,
'200 OK'
,
'424 Failed Dependency'
)
result
=
result
.
replace
(
'200 OK'
,
'424 Failed Dependency'
)
return
result
return
result
...
@@ -282,7 +282,7 @@ class Lock:
...
@@ -282,7 +282,7 @@ class Lock:
self
.
type
=
'write'
self
.
type
=
'write'
self
.
owner
=
''
self
.
owner
=
''
timeout
=
request
.
get_header
(
'Timeout'
,
'infinite'
)
timeout
=
request
.
get_header
(
'Timeout'
,
'infinite'
)
self
.
timeout
=
string
.
strip
(
string
.
split
(
timeout
,
','
)[
-
1
]
)
self
.
timeout
=
timeout
.
split
(
','
)[
-
1
].
strip
(
)
self
.
parse
(
data
)
self
.
parse
(
data
)
def
parse
(
self
,
data
,
dav
=
'DAV:'
):
def
parse
(
self
,
data
,
dav
=
'DAV:'
):
...
...
lib/python/webdav/xmltools.py
View file @
726d61b2
...
@@ -17,9 +17,9 @@
...
@@ -17,9 +17,9 @@
in favor of a standard xml package once some issues are
in favor of a standard xml package once some issues are
worked out."""
worked out."""
__version__
=
'$Revision: 1.1
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
import
sys
,
os
,
string
import
sys
,
os
import
Shared.DC.xml.xmllib
import
Shared.DC.xml.xmllib
from
Acquisition
import
Implicit
from
Acquisition
import
Implicit
...
@@ -63,12 +63,12 @@ class Node(Implicit):
...
@@ -63,12 +63,12 @@ class Node(Implicit):
return
''
return
''
self
=
self
.
aq_parent
self
=
self
.
aq_parent
def
elements
(
self
,
name
=
None
,
ns
=
None
,
lower
=
string
.
lower
):
def
elements
(
self
,
name
=
None
,
ns
=
None
):
nodes
=
[]
nodes
=
[]
name
=
name
and
lower
(
name
)
name
=
name
and
name
.
lower
(
)
for
node
in
self
.
__nodes__
:
for
node
in
self
.
__nodes__
:
if
node
.
__type__
==
type_element
and
\
if
node
.
__type__
==
type_element
and
\
((
name
is
None
)
or
(
lower
(
node
.
__name__
)
==
name
))
and
\
((
name
is
None
)
or
(
(
node
.
__name__
.
lower
()
)
==
name
))
and
\
((
ns
is
None
)
or
(
node
.
namespace
()
==
ns
)):
((
ns
is
None
)
or
(
node
.
namespace
()
==
ns
)):
nodes
.
append
(
node
)
nodes
.
append
(
node
)
return
nodes
return
nodes
...
@@ -100,7 +100,7 @@ class Document(Node):
...
@@ -100,7 +100,7 @@ class Document(Node):
result
=
[
'<?xml version="1.0" encoding="%s"?>'
%
self
.
encoding
]
result
=
[
'<?xml version="1.0" encoding="%s"?>'
%
self
.
encoding
]
for
node
in
self
.
__nodes__
:
for
node
in
self
.
__nodes__
:
result
.
append
(
node
.
toxml
())
result
.
append
(
node
.
toxml
())
return
string
.
join
(
result
,
''
)
return
''
.
join
(
result
)
#def __del__(self):
#def __del__(self):
# self.document=None
# self.document=None
...
@@ -119,16 +119,16 @@ class Element(Node):
...
@@ -119,16 +119,16 @@ class Element(Node):
attr
=
Attribute
(
name
,
val
)
attr
=
Attribute
(
name
,
val
)
self
.
__attrs__
.
append
(
attr
)
self
.
__attrs__
.
append
(
attr
)
self
.
ns_parse
()
self
.
ns_parse
()
parts
=
s
tring
.
split
(
self
.
__name__
,
':'
)
parts
=
s
elf
.
__name__
.
split
(
':'
)
if
len
(
parts
)
>
1
:
if
len
(
parts
)
>
1
:
self
.
__nskey__
=
parts
[
0
]
self
.
__nskey__
=
parts
[
0
]
self
.
__name__
=
string
.
join
(
parts
[
1
:],
':'
)
self
.
__name__
=
':'
.
join
(
parts
[
1
:]
)
def
ns_parse
(
self
):
def
ns_parse
(
self
):
nsdef
=
self
.
__nsdef__
=
{}
nsdef
=
self
.
__nsdef__
=
{}
for
attr
in
self
.
attrs
():
for
attr
in
self
.
attrs
():
name
,
val
=
attr
.
name
(),
attr
.
value
()
name
,
val
=
attr
.
name
(),
attr
.
value
()
key
=
string
.
lower
(
name
)
key
=
name
.
lower
(
)
if
key
[:
6
]
==
'xmlns:'
:
if
key
[:
6
]
==
'xmlns:'
:
nsdef
[
name
[
6
:]]
=
val
nsdef
[
name
[
6
:]]
=
val
elif
key
==
'xmlns'
:
elif
key
==
'xmlns'
:
...
@@ -198,13 +198,13 @@ class Element(Node):
...
@@ -198,13 +198,13 @@ class Element(Node):
for
node
in
self
.
__nodes__
:
for
node
in
self
.
__nodes__
:
result
.
append
(
node
.
toxml
())
result
.
append
(
node
.
toxml
())
result
.
append
(
'</%s>'
%
qname
)
result
.
append
(
'</%s>'
%
qname
)
return
string
.
join
(
result
,
''
)
return
''
.
join
(
result
)
def
strval
(
self
,
top
=
1
):
def
strval
(
self
,
top
=
1
):
if
not
self
.
__value__
and
not
self
.
__nodes__
:
if
not
self
.
__value__
and
not
self
.
__nodes__
:
return
''
return
''
result
=
map
(
lambda
n
:
n
.
toxml
(),
self
.
__nodes__
)
result
=
map
(
lambda
n
:
n
.
toxml
(),
self
.
__nodes__
)
return
string
.
join
(
result
,
''
)
return
''
.
join
(
result
)
class
Attribute
(
Node
):
class
Attribute
(
Node
):
__type__
=
type_attribute
__type__
=
type_attribute
...
@@ -212,12 +212,12 @@ class Attribute(Node):
...
@@ -212,12 +212,12 @@ class Attribute(Node):
self
.
__name__
=
name
self
.
__name__
=
name
self
.
__value__
=
val
self
.
__value__
=
val
self
.
__nskey__
=
''
self
.
__nskey__
=
''
parts
=
string
.
split
(
name
,
':'
)
parts
=
name
.
split
(
':'
)
if
len
(
parts
)
>
1
:
if
len
(
parts
)
>
1
:
pre
=
string
.
lower
(
parts
[
0
]
)
pre
=
parts
[
0
].
lower
(
)
if
not
(
pre
in
(
'xml'
,
'xmlns'
)):
if
not
(
pre
in
(
'xml'
,
'xmlns'
)):
self
.
__nskey__
=
parts
[
0
]
self
.
__nskey__
=
parts
[
0
]
self
.
__name__
=
string
.
join
(
parts
[
1
:],
':'
)
self
.
__name__
=
':'
.
join
(
parts
[
1
:]
)
def
remap
(
self
,
dict
,
n
=
0
,
top
=
1
):
def
remap
(
self
,
dict
,
n
=
0
,
top
=
1
):
nsval
=
self
.
namespace
()
nsval
=
self
.
namespace
()
...
@@ -344,12 +344,12 @@ class XmlParser(Shared.DC.xml.xmllib.XMLParser):
...
@@ -344,12 +344,12 @@ class XmlParser(Shared.DC.xml.xmllib.XMLParser):
def
escape
(
data
,
rmap
=
{}
,
replace
=
string
.
replace
):
def
escape
(
data
,
rmap
=
{}):
data
=
replace
(
data
,
"&"
,
"&"
)
data
=
data
.
replace
(
"&"
,
"&"
)
data
=
replace
(
data
,
"<"
,
"<"
)
data
=
data
.
replace
(
"<"
,
"<"
)
data
=
replace
(
data
,
">"
,
">"
)
data
=
data
.
replace
(
">"
,
">"
)
for
key
,
val
in
rmap
.
items
():
for
key
,
val
in
rmap
.
items
():
data
=
replace
(
data
,
key
,
val
)
data
=
data
.
replace
(
key
,
val
)
return
data
return
data
def
remap
(
data
,
dict
=
{
'DAV:'
:
'd'
}):
def
remap
(
data
,
dict
=
{
'DAV:'
:
'd'
}):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment