[prev in list] [next in list] [prev in thread] [next in thread] 

List:       zope-dev
Subject:    Re: [Zope-dev] zope.schema and Python 3
From:       Brian Sutherland <brian () vanguardistas ! net>
Date:       2011-10-11 11:33:20
Message-ID: 20111011113320.GD50292 () Boo ! local
[Download RAW message or body]

On Tue, Oct 11, 2011 at 10:43:02AM +0200, Lennart Regebro wrote:
> On Tue, Oct 11, 2011 at 10:22, Brian Sutherland <brian@vanguardistas.net> wrote:
> > On Mon, Oct 10, 2011 at 01:14:26PM +0200, Brian Sutherland wrote:
> >> I've managed to port zope.schema to Python 3.2 on a branch
> >> (jinty-python3).
> >
> > One doubt which has just crept up on me is if these classes:
> >
> >    ASCII, ASCIILine, URI, Id, DottedName
> >
> > should still inherit from Bytes on Python 3. It seems more logical that
> > they should inherit from Text. I had to do some gymnastics to keep them
> > bytes on python 3 and feel all dirty about it.
> >
> > DottedName, in particular, describes itself as "Python-style dotted
> > names". But in Python 3 this code works:
> >
> >    >>> from 漢語 import Español
> >    >>> print(Español)
> >    <class '漢語.Español'>
> >
> > so a DottedName could be '漢語.Español' under Python 3. Definitely
> > unicode and not Bytes.
> >
> > However, changing the behaviour of these classes between Python 2 and 3
> > may be even more problematic.
> >
> > Another option is simply to have these classes raise NotImplementedError
> > in their validate() methods under Python 3 and wait till the solution
> > becomes more obvious.
> >
> > Anyone out there willing to assuage my doubts?
> 
> It seems to me that they should be `str`, all of them, except possibly
> URI. 

Yeah, seems like it. I made this change to all except URI.

> I'm unsure exactly how that changes the behavior. ASCII/ASCIILine
> should have validators to restrict them to ASCII only, reasonably, I
> don't know if they already do.

It has this:
    
    if not max(map(ord, value)) < 128:
        raise InvalidValue

which seems like it's enough.

-- 
Brian Sutherland
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic