Re: [Python-Dev] Should ftplib use UTF-8 instead of latin-1 encoding?

2009-01-24 Thread Alexey G.
On Fri, Jan 23, 2009 at 11:18:37PM +0100, "Martin v. L?wis" wrote:
> > I don't see how starting with an empty directory helps.  The filename
> > comes from the client, and the FTP server can't know what the actual
> > encoding of that filename is.
> 
> Sure it can. If the client supports RFC 2640, it will send file names
> in UTF-8. If the client does not support RFC 2640, the client must
> restrict itself to 7-bit file names (i.e. ASCII). If the client violates
> the protocol, the server must respond with error 501.

  Perhaps, that is true, but that is in the world of standards. In my life I
remember the situation when users uploaded files from Windows with names in 
CP866
encoding to UNIX-based ftp server, which by itself had KOI8-R as the encoding
for LC_CTYPE. Since administrator was unhappy being impossible to read the
names of files correctly, he found and installed specialized ("russified")
version of ftp daemon, which had configuration settings, that said what is the
network encoding and what is the filesystem encoding.
  So both ftp daemon and ftp clients violated RFC, but users and administrator
were happy.

  I think, we should preserve the ability of ftp client to download all files he
see in the listing from the server.
What to do with user specified filenames when they cannot be encoded into ascii
and server does not support UTF8, but violates RFC and allows 8-bit bytes in the
file names?

  The ideal ftp client will ask the user about the encoding he thiks filenames 
are
stored on the server side and then recode from user's encoding. It also allow 
the
user to try several variants, if first don't work. It will allow user to 
download
files with names in several different encodings from the same server using 
single
ftp session.
  Dumb client will send filename from user as bytes,
and will succeed, if user was able to specify filename verbatim.
Anything between that will make the idea of using Unicode as character encoding
for filenames absurd, since it will only break the i18n capabilities of the 
library.

  If python library will have file name encoding hardwired to latin1, but 
arguments will
only be unicode strings, well, a lot of people will not even notice that, since 
they
use only ascii part of utf-8. But then there will be again numerous 
"russification"-like
patches to python and to modules, which are incompatible with everything, but 
work well
in some very specific situations. This is the evil that was supposed to be 
defeated
with i18n and with the total adoption of Unicode.

Alexey G.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3142: Add a "while" clause to generator expressions

2009-01-20 Thread Alexey G. Shpagin
On Tue, Jan 20, 2009 at 09:24:32AM -0500, Gerald Britton wrote:
> hmmm...doesn't:
> 
> if n*n < 50 or raise StopIteration()
> 
> really mean, "Return an integer in the range 0-99 if n-squared is less
> than fifty or the statement 'raise StopIteration()' returns True" ?
> 
> I'm not sure that that will work.
Well, your variant will trigger syntax error (and will not work surely).

To make it work we need a function, that raises StopIteration.
exactly as I have suggested.

> 
> On Tue, Jan 20, 2009 at 9:18 AM,   wrote:
> > On Mon, Jan 19, 2009 at 10:10:00AM -0500, Gerald Britton wrote:
> >> Please find below PEP 3142: Add a "while" clause to generator
> >> expressions.  I'm looking for feedback and discussion.
> >>
> > ...
> >>   g = (n for n in range(100) while n*n < 50)
> >
> > May I suggest you this variant?
> >

> >    def raiseStopIteration():
> >raise StopIteration
> >
> >g = (n for n in range(100) if n*n < 50 or raiseStopIteration())

--
Alexey G. Shpagin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3142: Add a "while" clause to generator expressions

2009-01-20 Thread Alexey G. Shpagin
On Tue, Jan 20, 2009 at 10:45:27AM -0500, Gerald Britton wrote:
> OK, so your suggestion:
> 
>  g = (n for n in range(100) if n*n < 50 or raiseStopIteration())
> 
> really means "return in in the range 0-99 if n-squared is less than 50
> or the function raiseStopIteration() returns True".
> 
> How would this get the generator to stop once n*n >=50? It looks
> instead like the first time around, StopIteration will be raised and
> (presumably) the generator will terminate.

Just test it. After the generator is terminated, no one will call
 range(100).next()
method, if I really understand you.

Maybe (as suggested before with 'if ... else break`) we should rename
function raiseStopIteration() to else_break(),
since it looks to me being a 'if ... else break's implementation with functions.

Example will look like
 g = (n for n in range(100) if n*n < 50 or else_break())

That's to the matter of taste, I think.

--
Alexey G. Shpagin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com