Commit 67b6efc1 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make FTPConnector.getFile binary mode by default, because ascii mode only...

make FTPConnector.getFile binary mode by default, because ascii mode only works with utf-8 encoding.

also propagate binary mode to SFTPClient.file().
parent 2e7fbe79
master allmywork allow_login_change allow_login_change_differentiate_id_and_login allow_login_change_wip arnau arnau-kns arnau-kns-without-property-mapping auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog catalog_fulltext catalog_fulltext_old cedric cedriclen-eos cherries cherry-pick-4a8e045d clean_up_upgrader compact_title_no_reference datetimefield devel douglas_forum dream_distributor eos-dev erp5-component erp5-data-notebook erp5-forum erp5-preference erp5-release erp5-slapos-upgrade erp5-vifib erp5-vifib-cleanup erp5_free_subscription erp5_workflow feature/renderjs-form-error-handling feature/renderjs-formbox feature/renderjs-listbox-columnsort feature/renderjs-reports feature/rjs-listbox-stats fix/accounting_period_constraint_vs_acquired_node fix/change_state_priority fix/login_validate_check_consistency for_testrunner_1 for_testrunner_2 formbox gabriel-fix-rounding-in-accounting-generation gabriel-fix-rounding-in-accounting-generation2 gadget-json-value improve_default_caching_policy_manager isDeletable item_tracking_graph_editor jerome-test jerome_graph_editor_renderjs jerome_user_preference_time_zone jm/form-action-guard joblib-activity kato kns master_calendar_wip_patches master_calendar_wip_patches_extend_security master_no_guard_on_workflow_transition master_no_guard_on_workflow_transition_plus_calendar_wip_patchs nexedi-erp5-jp no_longer_simulated_state officejs officejs_clean portal_callables portal_solver_process_security_configuration reindex_calendar_after_change_calendar_exception renderjs/test romain-fulltext shop-box sms_more_than_140_characters strict_catalog test/rjs test/rjsacc test/rjsfull test/tmp test/ui testnode_software_link timezones tristan tristan-merge tristan-performance view-aggregated-amounts vivekpab_erp5webrenderjs_layoutconfig vivekpab_jabberclient vivekpab_renderjs_interfaces wenjie wenjie_branch xiaowu_newui test-ui test-rjsfull test-rjsacc test-rjs renderjs-test nexedi/master jio-reports-old feature-jio-reports erp5.util-0.4.49 erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40
No related merge requests found
...@@ -84,7 +84,7 @@ class FTPConnector(XMLObject): ...@@ -84,7 +84,7 @@ class FTPConnector(XMLObject):
finally: finally:
conn.logout() conn.logout()
def getFile(self, filepath, binary=False): def getFile(self, filepath, binary=True):
""" Try to get a file on the remote server """ """ Try to get a file on the remote server """
conn = self.getConnection() conn = self.getConnection()
try: try:
......
5 6
\ No newline at end of file \ No newline at end of file
...@@ -94,10 +94,13 @@ class SFTPConnection: ...@@ -94,10 +94,13 @@ class SFTPConnection:
except error, msg: except error, msg:
raise SFTPError(str(msg) + ' while writing file %s on %s' % (filepath, path, self.url)) raise SFTPError(str(msg) + ' while writing file %s on %s' % (filepath, path, self.url))
def _getFile(self, filepath): def _getFile(self, filepath, binary=True):
"""Retrieve the file""" """Retrieve the file"""
try: try:
tmp_file = self.conn.file(filepath) if binary:
tmp_file = self.conn.file(filepath, 'rb')
else:
tmp_file = self.conn.file(filepath, 'r')
tmp_file.seek(0) tmp_file.seek(0)
return Binary(tmp_file.read()) return Binary(tmp_file.read())
except error, msg: except error, msg:
...@@ -105,11 +108,11 @@ class SFTPConnection: ...@@ -105,11 +108,11 @@ class SFTPConnection:
def readBinaryFile(self, filepath): def readBinaryFile(self, filepath):
"""Retrieve the file in binary mode""" """Retrieve the file in binary mode"""
return StringIO(str(self._getFile(filepath))) return StringIO(str(self._getFile(filepath, binary=True)))
def readAsciiFile(self, filepath): def readAsciiFile(self, filepath):
"""Retrieve the file in ASCII mode""" """Retrieve the file in ASCII mode"""
binary = self._getFile(filepath) binary = self._getFile(filepath, binary=False)
if binary: if binary:
return binary.data return binary.data
return None return None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment