python / cpython

The Python programming language
https://www.python.org
Other
63.38k stars 30.35k forks source link

ftplib needs a rewrite to use bytes/buffers #45589

Closed brettcannon closed 16 years ago

brettcannon commented 17 years ago
BPO 1248
Nosy @brettcannon, @vstinner, @giampaolo, @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = created_at = labels = ['library'] title = 'ftplib needs a rewrite to use bytes/buffers' updated_at = user = 'https://github.com/brettcannon' ``` bugs.python.org fields: ```python activity = actor = 'vstinner' assignee = 'none' closed = True closed_date = closer = 'vstinner' components = ['Library (Lib)'] creation = creator = 'brett.cannon' dependencies = [] files = [] hgrepos = [] issue_num = 1248 keywords = [] message_count = 6.0 messages = ['56281', '73553', '75007', '75052', '75056', '75360'] nosy_count = 4.0 nosy_names = ['brett.cannon', 'vstinner', 'giampaolo.rodola', 'benjamin.peterson'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue1248' versions = ['Python 3.0'] ```

brettcannon commented 17 years ago

For instance, ftplib.FTP reads from sockets using socket.makefile(), but in text mode. That's bad when the data could be in the format of ASCII or binary data.

giampaolo commented 16 years ago

Actually the 'r' flag is used against the control connection which is not supposed to receive any "binary" data and in FTP.retrlines method which is supposed to retrieve data in line mode.

benjaminp commented 16 years ago

So can we close this?

vstinner commented 16 years ago

Function result type should be the same of the connection is in text mode or binary mode. As far as I remember, the text mode converts the newline byte sequence, not the charset. A text file could be stored as latin-1, utf-8, koi-8 or anything else. Am I wrong?

ftplib should use byte strings (as I did for POP3, IMAP4 or some other libraries) because the FTP protocol doesn't send the charset.

vstinner commented 16 years ago

So it's already possible to receive/send raw bytes, and forget my previous message.

I see a potential but minor problem: if the server is running a POSIX OS, it's not possible to open / rename / unlink a file with an invalid name. ftp might allow bytes filename, but I prefer to leave ftplib unchanged. If your FTP server is broken, fix your file system, fix your configuration or use an old FTP client to fix the problem.

vstinner commented 16 years ago

So can we close this?

Yes: retrbinary() and storbinary() can be used to get/send bytes.

Reopen the issue (or open another one) if we miss another problem.