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
2f34efa7
Commit
2f34efa7
authored
Jun 17, 2009
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make convert_os_errors() decorate rewrite the resource path if self as an attribute "root_path"
parent
72b8884b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
+21
-14
fs/errors.py
+16
-9
fs/sftpfs.py
+5
-5
No files found.
fs/errors.py
View file @
2f34efa7
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
import
sys
import
sys
import
errno
import
errno
from
fs.path
import
*
try
:
try
:
from
functools
import
wraps
from
functools
import
wraps
except
ImportError
:
except
ImportError
:
...
@@ -153,26 +155,31 @@ def convert_os_errors(func):
...
@@ -153,26 +155,31 @@ def convert_os_errors(func):
"""Function wrapper to convert OSError/IOError instances into FSErrors."""
"""Function wrapper to convert OSError/IOError instances into FSErrors."""
opname
=
func
.
__name__
opname
=
func
.
__name__
@wraps
(
func
)
@wraps
(
func
)
def
wrapper
(
*
args
,
**
kwds
):
def
wrapper
(
self
,
*
args
,
**
kwds
):
try
:
try
:
return
func
(
*
args
,
**
kwds
)
return
func
(
self
,
*
args
,
**
kwds
)
except
(
OSError
,
IOError
),
e
:
except
(
OSError
,
IOError
),
e
:
path
=
getattr
(
e
,
"filename"
,
None
)
if
path
and
path
[
0
]
==
"/"
and
hasattr
(
self
,
"root_path"
):
path
=
normpath
(
path
)
if
isprefix
(
self
.
root_path
,
path
):
path
=
path
[
len
(
self
.
root_path
):]
if
not
hasattr
(
e
,
"errno"
)
or
not
e
.
errno
:
if
not
hasattr
(
e
,
"errno"
)
or
not
e
.
errno
:
raise
OperationFailedError
(
opname
,
details
=
e
)
raise
OperationFailedError
(
opname
,
details
=
e
)
if
e
.
errno
==
errno
.
ENOENT
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
ResourceNotFoundError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
ResourceNotFoundError
(
path
,
opname
=
opname
,
details
=
e
)
if
e
.
errno
==
errno
.
ENOTEMPTY
:
if
e
.
errno
==
errno
.
ENOTEMPTY
:
raise
DirectoryNotEmptyError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
DirectoryNotEmptyError
(
path
,
opname
=
opname
,
details
=
e
)
if
e
.
errno
==
errno
.
EEXIST
:
if
e
.
errno
==
errno
.
EEXIST
:
raise
DestinationExistsError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
DestinationExistsError
(
path
,
opname
=
opname
,
details
=
e
)
if
e
.
errno
==
183
:
# some sort of win32 equivalent to EEXIST
if
e
.
errno
==
183
:
# some sort of win32 equivalent to EEXIST
raise
DestinationExistsError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
DestinationExistsError
(
path
,
opname
=
opname
,
details
=
e
)
if
e
.
errno
==
errno
.
ENOTDIR
:
if
e
.
errno
==
errno
.
ENOTDIR
:
raise
ResourceInvalidError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
ResourceInvalidError
(
path
,
opname
=
opname
,
details
=
e
)
if
e
.
errno
==
errno
.
EISDIR
:
if
e
.
errno
==
errno
.
EISDIR
:
raise
ResourceInvalidError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
ResourceInvalidError
(
path
,
opname
=
opname
,
details
=
e
)
if
e
.
errno
==
errno
.
EINVAL
:
if
e
.
errno
==
errno
.
EINVAL
:
raise
ResourceInvalidError
(
e
.
filename
,
opname
=
opname
,
details
=
e
)
raise
ResourceInvalidError
(
path
,
opname
=
opname
,
details
=
e
)
raise
OperationFailedError
(
opname
,
details
=
e
)
raise
OperationFailedError
(
opname
,
details
=
e
)
return
wrapper
return
wrapper
...
...
fs/sftpfs.py
View file @
2f34efa7
...
@@ -40,7 +40,7 @@ class SFTPFS(FS):
...
@@ -40,7 +40,7 @@ class SFTPFS(FS):
class in the paramiko module.
class in the paramiko module.
"""
"""
def
__init__
(
self
,
connection
,
root
=
"/"
,
**
credentials
):
def
__init__
(
self
,
connection
,
root
_path
=
"/"
,
**
credentials
):
"""SFTPFS constructor.
"""SFTPFS constructor.
The only required argument is 'connection', which must be something
The only required argument is 'connection', which must be something
...
@@ -52,7 +52,7 @@ class SFTPFS(FS):
...
@@ -52,7 +52,7 @@ class SFTPFS(FS):
* a paramiko.Transport instance
* a paramiko.Transport instance
* a paramiko.Channel instance in "sftp" mode
* a paramiko.Channel instance in "sftp" mode
The kwd argument 'root' specifies the root directory on the remote
The kwd argument 'root
_path
' specifies the root directory on the remote
machine - access to files outsite this root wil be prevented. Any
machine - access to files outsite this root wil be prevented. Any
other keyword arguments are assumed to be credentials to be used when
other keyword arguments are assumed to be credentials to be used when
connecting the transport.
connecting the transport.
...
@@ -71,7 +71,7 @@ class SFTPFS(FS):
...
@@ -71,7 +71,7 @@ class SFTPFS(FS):
if
not
connection
.
is_authenticated
():
if
not
connection
.
is_authenticated
():
connection
.
connect
(
**
credentials
)
connection
.
connect
(
**
credentials
)
self
.
_transport
=
connection
self
.
_transport
=
connection
self
.
root
=
abspath
(
normpath
(
root
))
self
.
root
_path
=
abspath
(
normpath
(
root_path
))
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
...
@@ -111,8 +111,8 @@ class SFTPFS(FS):
...
@@ -111,8 +111,8 @@ class SFTPFS(FS):
self
.
_transport
.
close
()
self
.
_transport
.
close
()
def
_normpath
(
self
,
path
):
def
_normpath
(
self
,
path
):
npath
=
pathjoin
(
self
.
root
,
relpath
(
normpath
(
path
)))
npath
=
pathjoin
(
self
.
root
_path
,
relpath
(
normpath
(
path
)))
if
not
isprefix
(
self
.
root
,
npath
):
if
not
isprefix
(
self
.
root
_path
,
npath
):
raise
PathError
(
path
,
msg
=
"Path is outside root:
%(path)
s"
)
raise
PathError
(
path
,
msg
=
"Path is outside root:
%(path)
s"
)
return
npath
return
npath
...
...
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