Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard
erp5
Commits
6317f21f
Commit
6317f21f
authored
May 07, 2014
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SFTPConnection.readBinaryFile now returns binary str, instead of StringIO object.
also readAsciiFile normilises CRLF/CR/LF.
parent
4a5fa825
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
12 deletions
+10
-12
product/ERP5Type/ConnectionPlugin/SFTPConnection.py
product/ERP5Type/ConnectionPlugin/SFTPConnection.py
+10
-12
No files found.
product/ERP5Type/ConnectionPlugin/SFTPConnection.py
View file @
6317f21f
...
...
@@ -94,28 +94,26 @@ class SFTPConnection:
except
error
,
msg
:
raise
SFTPError
(
str
(
msg
)
+
' while writing file %s on %s'
%
(
filepath
,
path
,
self
.
url
))
def
_getFile
(
self
,
filepath
,
binary
=
True
):
def
_getFile
(
self
,
filepath
):
"""Retrieve the file"""
try
:
if
binary
:
tmp_file
=
self
.
conn
.
file
(
filepath
,
'rb'
)
else
:
tmp_file
=
self
.
conn
.
file
(
filepath
,
'r
'
)
# always open with binary mode, otherwise paramiko will raise
# UnicodeDecodeError for non-utf8 data. also SFTP has no ASCII
# mode like FTP that normalises CRLF/CR/LF.
tmp_file
=
self
.
conn
.
file
(
filepath
,
'rb
'
)
tmp_file
.
seek
(
0
)
return
Binary
(
tmp_file
.
read
()
)
return
tmp_file
.
read
(
)
except
error
,
msg
:
raise
SFTPError
(
str
(
msg
)
+
' while retrieving file %s from %s'
%
(
filepath
,
self
.
url
))
def
readBinaryFile
(
self
,
filepath
):
"""Retrieve the file in binary mode"""
return
StringIO
(
str
(
self
.
_getFile
(
filepath
,
binary
=
True
))
)
return
self
.
_getFile
(
filepath
)
def
readAsciiFile
(
self
,
filepath
):
"""Retrieve the file in ASCII mode"""
binary
=
self
.
_getFile
(
filepath
,
binary
=
False
)
if
binary
:
return
binary
.
data
return
None
# normalise CRLF/CR/LF like FTP's ASCII mode transfer.
return
os
.
linesep
.
join
(
self
.
_getFile
(
filepath
).
splitlines
())
def
getDirectoryContent
(
self
,
path
):
"""retrieve all entries in a givan path as a list"""
...
...
@@ -133,7 +131,7 @@ class SFTPConnection:
try
:
self
.
conn
.
unlink
(
filepath
)
except
error
,
msg
:
raise
SFTPError
(
str
(
msg
)
+
'while trying to delete %s on %s'
%
(
file
name
,
self
.
url
))
raise
SFTPError
(
str
(
msg
)
+
'while trying to delete %s on %s'
%
(
file
path
,
self
.
url
))
def
renameFile
(
self
,
old_path
,
new_path
):
"""Rename a file"""
...
...
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