[Python-ideas] str.split with padding

Bruce Leban bruce at leapyear.org
Sat Mar 14 07:04:26 CET 2009

On Fri, Mar 13, 2009 at 9:59 PM, Lie Ryan <lie.1296 at gmail.com> wrote:

> Steven D'Aprano wrote:
>> Email being sent locally may contain zero @ signs, and email being sent
>> externally can contain one or more @ signs. Andy's code:
>> user, hostname= address.split('@', 1, True)
>> will fail on syntactically valid email addresses like this:
>> fred(away @ the pub)@example.com
> From Wikipedia:
> RFC invalid e-mail addresses
>    * Abc.example.com <http://abc.example.com/> (character @ is missing)
>    * Abc. at example.com (character dot(.) is last in local part)
>    * Abc..123 at example.com (character dot(.) is double)
>    * A at b@c at example.com (only one @ is allowed outside quotations marks)
>    * ()[]\;:,<>@example.com (none of the characters before the @ in this
> example, are allowed outside quotation marks)
> Your example is valid email address if and only if it is enclosed in
> quotation mark: "fred(away @ the pub)"@example.com
That is valid but not because you can have nested email addresses like
that.** The (...) part is a comment. I wouldn't bet that very many mail
clients handle that according to the rfc. Many don't handle quoted strings
either. And there are those that have a narrow view of which characters
(Hint: if you don't want to get mail from hotmail users, just make sure your
email address has '/' in it.)
http://www.ietf.org/rfc/rfc0822.txt  **Way back people wrote nested email
addresses with % replacing the @ in the nested address (sna%foo at bar). I
haven't seen that for a while.

On topic:

Making split more complicated seems like overspecialization. Wouldn't a
generic padding function be more useful? FWIW, this has been discussed
before. http://bugs.python.org/issue5034

--- Bruce (sorry for the digression)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090313/def47e29/attachment.html>

More information about the Python-ideas mailing list