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
da422dd9
Commit
da422dd9
authored
Apr 21, 2012
by
btimby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY
parent
1e8f893b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
25 deletions
+30
-25
fs/expose/ftp.py
+30
-25
No files found.
fs/expose/ftp.py
View file @
da422dd9
...
...
@@ -18,6 +18,7 @@ loopback address.
import
os
import
stat
import
time
from
functools
import
wraps
from
pyftpdlib
import
ftpserver
...
...
@@ -30,6 +31,23 @@ UID = os.getuid()
GID
=
os
.
getgid
()
def
decode_args
(
f
):
"""
Decodes string arguments using the decoding defined on the method's class.
This decorator is for use on methods (functions which take a class or instance
as the first parameter).
"""
@wraps
(
f
)
def
wrapper
(
self
,
*
args
):
encoded
=
[]
for
arg
in
args
:
if
isinstance
(
arg
,
str
):
arg
=
arg
.
decode
(
self
.
encoding
)
encoded
.
append
(
arg
)
return
f
(
self
,
*
encoded
)
return
wrapper
class
FakeStat
(
object
):
"""
Pyftpdlib uses stat inside the library. This class emulates the standard
...
...
@@ -67,53 +85,44 @@ class FTPFS(ftpserver.AbstractedFS):
return
False
@convert_fs_errors
@decode_args
def
open
(
self
,
path
,
mode
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
return
self
.
fs
.
open
(
path
,
mode
)
def
chdir
(
self
,
path
):
self
.
_cwd
=
self
.
ftp2fs
(
path
)
@convert_fs_errors
@decode_args
def
mkdir
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
self
.
fs
.
makedir
(
path
)
@convert_fs_errors
@decode_args
def
listdir
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
return
map
(
lambda
x
:
x
.
encode
(
self
.
encoding
),
self
.
fs
.
listdir
(
path
))
@convert_fs_errors
@decode_args
def
rmdir
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
self
.
fs
.
removedir
(
path
)
@convert_fs_errors
@decode_args
def
remove
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
self
.
fs
.
remove
(
path
)
@convert_fs_errors
@decode_args
def
rename
(
self
,
src
,
dst
):
if
not
isinstance
(
src
,
unicode
):
src
=
src
.
decode
(
self
.
encoding
)
if
not
isinstance
(
dst
,
unicode
):
dst
=
dst
.
decode
(
self
.
encoding
)
self
.
fs
.
rename
(
src
,
dst
)
def
chmod
(
self
,
path
,
mode
):
r
aise
NotImplementedError
()
r
eturn
@convert_fs_errors
@decode_args
def
stat
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
info
=
self
.
fs
.
getinfo
(
path
)
kwargs
=
{
'st_size'
:
info
.
get
(
'size'
),
...
...
@@ -147,27 +156,23 @@ class FTPFS(ftpserver.AbstractedFS):
lstat
=
stat
@convert_fs_errors
@decode_args
def
isfile
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
return
self
.
fs
.
isfile
(
path
)
@convert_fs_errors
@decode_args
def
isdir
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
return
self
.
fs
.
isdir
(
path
)
@convert_fs_errors
@decode_args
def
getsize
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
return
self
.
fs
.
getsize
(
path
)
@convert_fs_errors
@decode_args
def
getmtime
(
self
,
path
):
if
not
isinstance
(
path
,
unicode
):
path
=
path
.
decode
(
self
.
encoding
)
return
self
.
fs
.
getinfo
(
path
)
.
time
def
realpath
(
self
,
path
):
...
...
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