Rev 4936: Support Unicode paths for ftp transport (encoded as utf8). in file:///home/vila/src/bzr/bugs/472161-ftp-utf8/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Jan 7 14:05:13 GMT 2010
At file:///home/vila/src/bzr/bugs/472161-ftp-utf8/
------------------------------------------------------------
revno: 4936
revision-id: v.ladeuil+lp at free.fr-20100107140512-nu5rgbw7fabvxphp
parent: pqm at pqm.ubuntu.com-20100106074025-ga21h28spm91o1h8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 472161-ftp-utf8
timestamp: Thu 2010-01-07 15:05:12 +0100
message:
Support Unicode paths for ftp transport (encoded as utf8).
* bzrlib/transport/ftp/__init__.py:
(FtpTransport._remote_path): Remove the work around, we send and
receive utf8 paths.
* bzrlib/tests/per_transport.py:
(TransportTests.test_unicode_paths): Check that the *server* can
support Unicode paths).
* bzrlib/tests/ftp_server/pyftpdlib_based.py:
(BzrConformingFS.ftp2fs): Added to decode utf8 received paths.
* bzrlib/tests/ftp_server/medusa_based.py:
(FTPTestServer): Declare that medusa can't support Unicode paths
in an had-hoc way.
* bzrlib/osutils.py:
(fancy_rename): Ensure all paths are unicode.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2010-01-05 16:55:12 +0000
+++ b/NEWS 2010-01-07 14:05:12 +0000
@@ -58,6 +58,9 @@
returns ``EINTR`` by calling ``PyErr_CheckSignals``. This affected the
optional ``_readdir_pyx`` extension. (Andrew Bennetts, #495023)
+* FTP transports support Unicode paths by encoding/decoding them as utf8.
+ (Vincent Ladeuil, #472161)
+
* Give a clearer message if the lockdir disappears after being apparently
successfully taken. (Martin Pool, #498378)
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2009-12-23 00:15:34 +0000
+++ b/bzrlib/osutils.py 2010-01-07 14:05:12 +0000
@@ -202,13 +202,15 @@
:param old: The old path, to rename from
:param new: The new path, to rename to
:param rename_func: The potentially non-atomic rename function
- :param unlink_func: A way to delete the target file if the full rename succeeds
+ :param unlink_func: A way to delete the target file if the full rename
+ succeeds
"""
-
+ new = safe_unicode(new)
# sftp rename doesn't allow overwriting, so play tricks:
base = os.path.basename(new)
dirname = os.path.dirname(new)
- tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(), os.getpid(), rand_chars(10))
+ tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(),
+ os.getpid(), rand_chars(10))
tmp_name = pathjoin(dirname, tmp_name)
# Rename the file out of the way, but keep track if it didn't exist
=== modified file 'bzrlib/tests/ftp_server/medusa_based.py'
--- a/bzrlib/tests/ftp_server/medusa_based.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/ftp_server/medusa_based.py 2010-01-07 14:05:12 +0000
@@ -213,6 +213,8 @@
class FTPTestServer(transport.Server):
"""Common code for FTP server facilities."""
+ _no_unicode_support = True
+
def __init__(self):
self._root = None
self._ftp_server = None
=== modified file 'bzrlib/tests/ftp_server/pyftpdlib_based.py'
--- a/bzrlib/tests/ftp_server/pyftpdlib_based.py 2009-10-06 08:24:14 +0000
+++ b/bzrlib/tests/ftp_server/pyftpdlib_based.py 2010-01-07 14:05:12 +0000
@@ -50,14 +50,15 @@
def listdir(self, path):
"""List the content of a directory."""
- # FIXME: need tests with unicode paths
return [osutils.safe_utf8(s) for s in os.listdir(path)]
def fs2ftp(self, fspath):
p = ftpserver.AbstractedFS.fs2ftp(self, fspath)
- # FIXME: need tests with unicode paths
return osutils.safe_utf8(p)
+ def ftp2fs(self, ftppath):
+ p = osutils.safe_unicode(ftppath)
+ return ftpserver.AbstractedFS.ftp2fs(self, p)
class BzrConformingFTPHandler(ftpserver.FTPHandler):
=== modified file 'bzrlib/tests/per_transport.py'
--- a/bzrlib/tests/per_transport.py 2009-10-05 12:50:34 +0000
+++ b/bzrlib/tests/per_transport.py 2010-01-07 14:05:12 +0000
@@ -1497,6 +1497,10 @@
u'\u65e5', # Kanji person
]
+ no_unicode_support = getattr(self._server, '_no_unicode_support', False)
+ if no_unicode_support:
+ raise TestSkipped("test server cannot handle unicode paths")
+
try:
self.build_tree(files, transport=t, line_endings='binary')
except UnicodeError:
=== modified file 'bzrlib/transport/ftp/__init__.py'
--- a/bzrlib/transport/ftp/__init__.py 2009-10-06 08:24:14 +0000
+++ b/bzrlib/transport/ftp/__init__.py 2010-01-07 14:05:12 +0000
@@ -205,17 +205,6 @@
#raise TransportError(msg='Error for path: %s' % (path,), orig_error=e)
raise
- def _remote_path(self, relpath):
- # XXX: It seems that ftplib does not handle Unicode paths
- # at the same time, medusa won't handle utf8 paths So if
- # we .encode(utf8) here (see ConnectedTransport
- # implementation), then we get a Server failure. while
- # if we use str(), we get a UnicodeError, and the test
- # suite just skips testing UnicodePaths.
- relative = str(urlutils.unescape(relpath))
- remote_path = self._combine_paths(self._path, relative)
- return remote_path
-
def has(self, relpath):
"""Does the target location exist?"""
# FIXME jam 20060516 We *do* ask about directories in the test suite
More information about the bazaar-commits
mailing list