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
b856b9ea
Commit
b856b9ea
authored
Nov 29, 2001
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*string module free zone*
replaced all calls with string methods
parent
a0063c70
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
lib/python/webdav/client.py
lib/python/webdav/client.py
+27
-27
No files found.
lib/python/webdav/client.py
View file @
b856b9ea
"""HTTP 1.1 / WebDAV client library."""
"""HTTP 1.1 / WebDAV client library."""
__version__
=
'$Revision: 1.1
7
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
8
$'
[
11
:
-
2
]
import
sys
,
os
,
string
,
time
,
types
,
re
import
sys
,
os
,
time
,
types
,
re
import
socket
,
httplib
,
mimetools
import
socket
,
httplib
,
mimetools
from
types
import
FileType
from
types
import
FileType
from
mimetypes
import
guess_type
from
mimetypes
import
guess_type
...
@@ -30,22 +30,22 @@ class HTTP(httplib.HTTP):
...
@@ -30,22 +30,22 @@ class HTTP(httplib.HTTP):
def
getreply
(
self
):
def
getreply
(
self
):
file
=
self
.
sock
.
makefile
(
'rb'
)
file
=
self
.
sock
.
makefile
(
'rb'
)
data
=
string
.
join
(
file
.
readlines
(),
''
)
data
=
''
.
join
(
file
.
readlines
()
)
file
.
close
()
file
.
close
()
self
.
file
=
StringIO
(
data
)
self
.
file
=
StringIO
(
data
)
line
=
self
.
file
.
readline
()
line
=
self
.
file
.
readline
()
try
:
try
:
[
ver
,
code
,
msg
]
=
string
.
split
(
line
,
None
,
2
)
[
ver
,
code
,
msg
]
=
line
.
split
(
None
,
2
)
except
ValueError
:
except
ValueError
:
try
:
try
:
[
ver
,
code
]
=
string
.
split
(
line
,
None
,
1
)
[
ver
,
code
]
=
line
.
split
(
None
,
1
)
msg
=
""
msg
=
""
except
ValueError
:
except
ValueError
:
return
-
1
,
line
,
None
return
-
1
,
line
,
None
if
ver
[:
5
]
!=
'HTTP/'
:
if
ver
[:
5
]
!=
'HTTP/'
:
return
-
1
,
line
,
None
return
-
1
,
line
,
None
code
=
string
.
atoi
(
code
)
code
=
int
(
code
)
msg
=
string
.
strip
(
msg
)
msg
=
msg
.
strip
(
)
headers
=
mimetools
.
Message
(
self
.
file
,
0
)
headers
=
mimetools
.
Message
(
self
.
file
,
0
)
return
ver
,
code
,
msg
,
headers
return
ver
,
code
,
msg
,
headers
...
@@ -62,7 +62,7 @@ class Resource:
...
@@ -62,7 +62,7 @@ class Resource:
if
mo
:
if
mo
:
host
,
port
,
uri
=
mo
.
group
(
1
,
2
,
3
)
host
,
port
,
uri
=
mo
.
group
(
1
,
2
,
3
)
self
.
host
=
host
self
.
host
=
host
self
.
port
=
port
and
string
.
atoi
(
port
[
1
:])
or
80
self
.
port
=
port
and
int
(
port
[
1
:])
or
80
self
.
uri
=
uri
or
'/'
self
.
uri
=
uri
or
'/'
else
:
raise
ValueError
,
url
else
:
raise
ValueError
,
url
...
@@ -91,7 +91,7 @@ class Resource:
...
@@ -91,7 +91,7 @@ class Resource:
return
headers
return
headers
if
atype
==
'Basic'
:
if
atype
==
'Basic'
:
headers
[
'Authorization'
]
=
(
headers
[
'Authorization'
]
=
(
"Basic %s"
%
string
.
replace
(
encodestring
(
'%s:%s'
%
(
self
.
username
,
self
.
password
)),
"Basic %s"
%
(
encodestring
(
'%s:%s'
%
(
self
.
username
,
self
.
password
))).
replace
(
'
\
012
'
,
''
))
'
\
012
'
,
''
))
return
headers
return
headers
raise
ValueError
,
'Unknown authentication scheme: %s'
%
atype
raise
ValueError
,
'Unknown authentication scheme: %s'
%
atype
...
@@ -99,14 +99,14 @@ class Resource:
...
@@ -99,14 +99,14 @@ class Resource:
def
__enc_formdata
(
self
,
args
=
{}):
def
__enc_formdata
(
self
,
args
=
{}):
formdata
=
[]
formdata
=
[]
for
key
,
val
in
args
.
items
():
for
key
,
val
in
args
.
items
():
n
=
string
.
rfind
(
key
,
'__'
)
n
=
key
.
rfind
(
'__'
)
if
n
>
0
:
if
n
>
0
:
tag
=
key
[
n
+
2
:]
tag
=
key
[
n
+
2
:]
key
=
key
[:
n
]
key
=
key
[:
n
]
else
:
tag
=
'string'
else
:
tag
=
'string'
func
=
varfuncs
.
get
(
tag
,
marshal_string
)
func
=
varfuncs
.
get
(
tag
,
marshal_string
)
formdata
.
append
(
func
(
key
,
val
))
formdata
.
append
(
func
(
key
,
val
))
return
string
.
join
(
formdata
,
'&'
)
return
'&'
.
join
(
formdata
)
def
__enc_multipart
(
self
,
args
=
{}):
def
__enc_multipart
(
self
,
args
=
{}):
return
MultiPart
(
args
).
render
()
return
MultiPart
(
args
).
render
()
...
@@ -280,7 +280,7 @@ class Resource:
...
@@ -280,7 +280,7 @@ class Resource:
def
getprops
(
self
,
*
names
):
def
getprops
(
self
,
*
names
):
if
not
names
:
return
self
.
propfind
()
if
not
names
:
return
self
.
propfind
()
tags
=
string
.
join
(
names
,
'/>
\
n
<'
)
tags
=
'/>
\
n
<'
.
join
(
names
)
body
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
\
body
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
\
'<d:propfind xmlns:d="DAV:">
\
n
'
\
'<d:propfind xmlns:d="DAV:">
\
n
'
\
' <d:prop>
\
n
'
\
' <d:prop>
\
n
'
\
...
@@ -295,7 +295,7 @@ class Resource:
...
@@ -295,7 +295,7 @@ class Resource:
tags
=
[]
tags
=
[]
for
key
,
val
in
props
.
items
():
for
key
,
val
in
props
.
items
():
tags
.
append
(
' <%s>%s</%s>'
%
(
key
,
val
,
key
))
tags
.
append
(
' <%s>%s</%s>'
%
(
key
,
val
,
key
))
tags
=
string
.
join
(
tags
,
'
\
n
'
)
tags
=
'
\
n
'
.
join
(
tags
)
body
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
\
body
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
\
'<d:propertyupdate xmlns:d="DAV:">
\
n
'
\
'<d:propertyupdate xmlns:d="DAV:">
\
n
'
\
'<d:set>
\
n
'
\
'<d:set>
\
n
'
\
...
@@ -309,7 +309,7 @@ class Resource:
...
@@ -309,7 +309,7 @@ class Resource:
def
delprops
(
self
,
*
names
):
def
delprops
(
self
,
*
names
):
if
not
names
:
if
not
names
:
raise
ValueError
,
'No property names specified.'
raise
ValueError
,
'No property names specified.'
tags
=
string
.
join
(
names
,
'/>
\
n
<'
)
tags
=
'/>
\
n
<'
.
join
(
names
)
body
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
\
body
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
\
'<d:propertyupdate xmlns:d="DAV:">
\
n
'
\
'<d:propertyupdate xmlns:d="DAV:">
\
n
'
\
'<d:remove>
\
n
'
\
'<d:remove>
\
n
'
\
...
@@ -344,7 +344,7 @@ class http_response:
...
@@ -344,7 +344,7 @@ class http_response:
return
'%s %s'
%
(
self
.
code
,
self
.
msg
)
return
'%s %s'
%
(
self
.
code
,
self
.
msg
)
def
get_header
(
self
,
name
,
val
=
None
):
def
get_header
(
self
,
name
,
val
=
None
):
return
self
.
headers
.
dict
.
get
(
string
.
lower
(
name
),
val
)
return
self
.
headers
.
dict
.
get
(
name
.
lower
(
),
val
)
def
get_headers
(
self
):
def
get_headers
(
self
):
return
self
.
headers
.
dict
return
self
.
headers
.
dict
...
@@ -358,7 +358,7 @@ class http_response:
...
@@ -358,7 +358,7 @@ class http_response:
map
(
data
.
append
,
self
.
headers
.
headers
)
map
(
data
.
append
,
self
.
headers
.
headers
)
data
.
append
(
'
\
r
\
n
'
)
data
.
append
(
'
\
r
\
n
'
)
data
.
append
(
self
.
body
)
data
.
append
(
self
.
body
)
return
string
.
join
(
data
,
''
)
return
''
.
join
(
data
)
set_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
set_xml
=
"""<?xml version="1.0" encoding="utf-8"?>
...
@@ -450,7 +450,7 @@ def marshal_list(name, seq, tname='list', lt=type([]), tt=type(())):
...
@@ -450,7 +450,7 @@ def marshal_list(name, seq, tname='list', lt=type([]), tt=type(())):
if
tp
in
(
lt
,
tt
):
if
tp
in
(
lt
,
tt
):
raise
TypeError
,
'Invalid recursion in data to be marshaled.'
raise
TypeError
,
'Invalid recursion in data to be marshaled.'
result
.
append
(
marshal_var
(
"%s:%s"
%
(
name
,
tname
),
v
))
result
.
append
(
marshal_var
(
"%s:%s"
%
(
name
,
tname
),
v
))
return
string
.
join
(
result
,
'&'
)
return
'&'
.
join
(
result
)
def
marshal_tuple
(
name
,
seq
):
def
marshal_tuple
(
name
,
seq
):
return
marshal_list
(
name
,
seq
,
'tuple'
)
return
marshal_list
(
name
,
seq
,
'tuple'
)
...
@@ -502,8 +502,8 @@ class MultiPart:
...
@@ -502,8 +502,8 @@ class MultiPart:
if
hasattr
(
val
,
'name'
):
if
hasattr
(
val
,
'name'
):
ct
,
enc
=
guess_type
(
val
.
name
)
ct
,
enc
=
guess_type
(
val
.
name
)
if
not
ct
:
ct
=
'application/octet-stream'
if
not
ct
:
ct
=
'application/octet-stream'
fn
=
string
.
replace
(
val
.
name
,
'
\
\
'
,
'/'
)
fn
=
val
.
name
.
replace
(
'
\
\
'
,
'/'
)
fn
=
fn
[(
string
.
rfind
(
fn
,
'/'
)
+
1
):]
fn
=
fn
[(
fn
.
rfind
(
'/'
)
+
1
):]
else
:
else
:
ct
=
'application/octet-stream'
ct
=
'application/octet-stream'
enc
=
''
enc
=
''
...
@@ -522,7 +522,7 @@ class MultiPart:
...
@@ -522,7 +522,7 @@ class MultiPart:
d
.
append
(
l
)
d
.
append
(
l
)
l
=
val
.
read
(
8192
)
l
=
val
.
read
(
8192
)
else
:
else
:
n
=
string
.
rfind
(
name
,
'__'
)
n
=
name
.
rfind
(
'__'
)
if
n
>
0
:
name
=
'%s:%s'
%
(
name
[:
n
],
name
[
n
+
2
:])
if
n
>
0
:
name
=
'%s:%s'
%
(
name
[:
n
],
name
[
n
+
2
:])
h
[
'Content-Disposition'
][
'_v'
]
=
'form-data'
h
[
'Content-Disposition'
][
'_v'
]
=
'form-data'
h
[
'Content-Disposition'
][
'name'
]
=
'"%s"'
%
name
h
[
'Content-Disposition'
][
'name'
]
=
'"%s"'
%
name
...
@@ -538,7 +538,7 @@ class MultiPart:
...
@@ -538,7 +538,7 @@ class MultiPart:
return
'%s_%s_%s'
%
(
int
(
time
.
time
()),
os
.
getpid
(),
random
())
return
'%s_%s_%s'
%
(
int
(
time
.
time
()),
os
.
getpid
(),
random
())
def
render
(
self
):
def
render
(
self
):
join
=
string
.
join
h
=
self
.
_headers
h
=
self
.
_headers
s
=
[]
s
=
[]
...
@@ -555,12 +555,12 @@ class MultiPart:
...
@@ -555,12 +555,12 @@ class MultiPart:
for
d
in
self
.
_data
:
for
d
in
self
.
_data
:
p
.
append
(
d
.
render
())
p
.
append
(
d
.
render
())
t
.
append
(
'--%s
\
n
'
%
b
)
t
.
append
(
'--%s
\
n
'
%
b
)
t
.
append
(
join
(
p
,
'
\
n
--%s
\
n
'
%
b
))
t
.
append
(
(
'
\
n
--%s
\
n
'
%
b
).
join
(
p
))
t
.
append
(
'
\
n
--%s--
\
n
'
%
b
)
t
.
append
(
'
\
n
--%s--
\
n
'
%
b
)
t
=
join
(
t
,
''
)
t
=
''
.
join
(
t
)
s
.
append
(
'Content-Length: %s
\
n
\
n
'
%
len
(
t
))
s
.
append
(
'Content-Length: %s
\
n
\
n
'
%
len
(
t
))
s
.
append
(
t
)
s
.
append
(
t
)
return
join
(
s
,
''
)
return
''
.
join
(
s
)
else
:
else
:
for
n
,
v
in
h
.
items
():
for
n
,
v
in
h
.
items
():
...
@@ -577,11 +577,11 @@ class MultiPart:
...
@@ -577,11 +577,11 @@ class MultiPart:
for
d
in
self
.
_data
:
for
d
in
self
.
_data
:
p
.
append
(
d
.
render
())
p
.
append
(
d
.
render
())
s
.
append
(
'--%s
\
n
'
%
b
)
s
.
append
(
'--%s
\
n
'
%
b
)
s
.
append
(
join
(
p
,
'
\
n
--%s
\
n
'
%
b
))
s
.
append
(
(
'
\
n
--%s
\
n
'
%
b
).
join
(
p
))
s
.
append
(
'
\
n
--%s--
\
n
'
%
b
)
s
.
append
(
'
\
n
--%s--
\
n
'
%
b
)
return
join
(
s
,
''
)
return
''
.
join
(
s
)
else
:
else
:
return
join
(
s
+
self
.
_data
,
''
)
return
''
.
join
(
s
+
self
.
_data
)
_extmap
=
{
''
:
'text/plain'
,
_extmap
=
{
''
:
'text/plain'
,
...
...
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