Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
78c7dd80
Commit
78c7dd80
authored
Oct 19, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DAVFS: more accurate size determination when setting Content-Length in uploads
parent
30995c07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
+20
-3
fs/contrib/davfs/__init__.py
+4
-1
fs/contrib/davfs/util.py
+16
-2
No files found.
fs/contrib/davfs/__init__.py
View file @
78c7dd80
...
@@ -17,6 +17,7 @@ Requires the dexml module:
...
@@ -17,6 +17,7 @@ Requires the dexml module:
# All rights reserved; available under the terms of the MIT License.
# All rights reserved; available under the terms of the MIT License.
import
os
import
os
import
sys
import
httplib
import
httplib
import
socket
import
socket
from
urlparse
import
urlparse
from
urlparse
import
urlparse
...
@@ -267,7 +268,6 @@ class DAVFS(FS):
...
@@ -267,7 +268,6 @@ class DAVFS(FS):
if
resp
.
status
==
409
:
if
resp
.
status
==
409
:
raise
ParentDirectoryMissingError
(
path
)
raise
ParentDirectoryMissingError
(
path
)
if
resp
.
status
not
in
(
200
,
201
,
204
):
if
resp
.
status
not
in
(
200
,
201
,
204
):
print
resp
.
status
raise_generic_error
(
resp
,
"setcontents"
,
path
)
raise_generic_error
(
resp
,
"setcontents"
,
path
)
def
open
(
self
,
path
,
mode
=
"r"
):
def
open
(
self
,
path
,
mode
=
"r"
):
...
@@ -302,6 +302,9 @@ class DAVFS(FS):
...
@@ -302,6 +302,9 @@ class DAVFS(FS):
contents
.
size
=
int
(
contents
.
size
)
contents
.
size
=
int
(
contents
.
size
)
except
ValueError
:
except
ValueError
:
contents
.
size
=
None
contents
.
size
=
None
if
not
hasattr
(
contents
,
"__exit__"
):
contents
.
__enter__
=
lambda
*
a
:
contents
contents
.
__exit__
=
lambda
*
a
:
contents
.
close
()
return
contents
return
contents
# For everything else, use a RemoteFileBuffer.
# For everything else, use a RemoteFileBuffer.
# This will take care of closing the socket when it's done.
# This will take care of closing the socket when it's done.
...
...
fs/contrib/davfs/util.py
View file @
78c7dd80
...
@@ -27,8 +27,22 @@ def get_fileno(file):
...
@@ -27,8 +27,22 @@ def get_fileno(file):
else
:
else
:
raise
AttributeError
raise
AttributeError
return
file
.
fileno
()
return
file
.
fileno
()
def
get_filesize
(
file
):
"""Get the "size" attribute of a file-like object."""
while
not
hasattr
(
file
,
"size"
):
if
hasattr
(
file
,
"file"
):
file
=
file
.
file
elif
hasattr
(
file
,
"_file"
):
file
=
file
.
_file
elif
hasattr
(
file
,
"_fileobj"
):
file
=
file
.
_fileobj
else
:
raise
AttributeError
return
file
.
size
def
file_chunks
(
f
,
chunk_size
=
1024
*
64
):
def
file_chunks
(
f
,
chunk_size
=
1024
*
64
):
"""Generator yielding chunks of a file.
"""Generator yielding chunks of a file.
...
@@ -54,7 +68,7 @@ def normalize_req_body(body,chunk_size=1024*64):
...
@@ -54,7 +68,7 @@ def normalize_req_body(body,chunk_size=1024*64):
return
(
len
(
value
),[
value
])
return
(
len
(
value
),[
value
])
elif
hasattr
(
body
,
"read"
):
elif
hasattr
(
body
,
"read"
):
try
:
try
:
size
=
int
(
body
.
size
)
size
=
int
(
get_filesize
(
body
)
)
except
(
AttributeError
,
TypeError
):
except
(
AttributeError
,
TypeError
):
try
:
try
:
size
=
os
.
fstat
(
get_fileno
(
body
))
.
st_size
size
=
os
.
fstat
(
get_fileno
(
body
))
.
st_size
...
...
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