[Python-3000] struni and the Apple four-character-codes

Jeffrey Yasskin jyasskin at gmail.com
Fri Jul 27 05:38:45 CEST 2007


I've sent the patch as http://python.org/sf/1761465 using Guido's
suggestion of using bytes, but I do philosophically prefer Talin's and
Ronald's suggestions.

On 7/25/07, Ronald Oussoren <ronaldoussoren at mac.com> wrote:
> I've CC-ed Jack Jansen as he has maintained the Mac libraries for ages (from way before OS9 was shiny and new).

Did you mean to add him to this thread?

> On Wednesday, July 25, 2007, at 07:18AM, "Jeffrey Yasskin" <jyasskin at gmail.com> wrote:
> > 5) Make a new hashable class for these codes which converts them to
> >and from ints and bytes and becomes the general argument type for the
> >apple platform interface. [Cleanest, but lots of work that I'm not
> >volunteering to do]
>
> A 6th option is a subclass of int. It's constructor would accept a string containing the 4CC and the repr/str method would return the string representation of the code.  IMHO this is the cleanest representation of 4CCs in Python because those codes are basicy a "neat" way to enter integer literals in C.

Naïve question: How does that differ from option (5)? Just the
isinstance() behavior?

I said this would take a lot of work because I think the new type
needs to be implemented in C to be returned from PyMac_GetOSType(),
and it seemed like a bigger API change than just switching to bytes,
but it turns out that switching to bytes isn't particularly trivial
either when you have to cast for every use in a dict, so maybe the new
type would be easier.

> This would also solve a problem that PyObjC users sometimes run into: Several C/Objective-C APIs return a dictionary where one  of the values is an integer and where one would commonly use 4CCs to write down literals. This currently causes unexpected failures but would do the right thing with this option.

I don't think that option (6) by itself solves with that particular
problem. If you call str() on one of those ints, you'd just get a
number, which is different from what would happen if you call str() on
the 4CC type. It might help though by handling comparisons correctly.

On 7/26/07, Alex Holkner <aholkner at cs.rmit.edu.au> wrote:
> Providing a convenience str() method may be handy, but the internal
> representation must be integer.

Where are you getting "must"? In current python, they're 'str'
instances, not ints. The C interface between python and apple code
converts, of course, but python can do whatever makes the most sense
to us.

-- 
Namasté,
Jeffrey Yasskin


More information about the Python-3000 mailing list