Yet Another PEP: Query Protocol Interface or __query__

Aahz Maruch aahz at
Wed Mar 21 02:47:35 CET 2001

[posted & e-mailed]

In article <Pine.LNX.4.21.0103201837570.21343-100000 at>,
Clark C. Evans <cce at> wrote:
>    A new built-in method, __query__ is proposed.  This method has
>    a single argument, an interface protocol identifier, and either
>    returns an object supporting the given protocol, or throws an
>    unknown exception.
>    An interface protocol identifier is a lower-case string having
>    a reverse DNS host name string:   TLD '.' DOMAIN ['.' NAME ]*
>    Where TLD is a top level domain such as 'com' or ''.  DOMAIN
>    is a registered name in the given TLD.  And one or more optional
>    NAME separated by a period.  NAME is a sequence of one or more
>    alphabetic characters including the dash '-' character.  See the
>    relevant ITEF specifications for specific details.

It's not at all clear to me why this domain thing is being suggested.
Is there supposed to be some kind of lookup mechanism associated with
it?  Why is this a string instead of a sequence object (tuple or list)?
Most importantly, how does one find out what interfaces an object *does*

>Example Usage
>    >>> class EggsOnly:
>            def eggs(self,str): print "eggs!" + str
>            def __query__(self,protocol):
>                if protocol == "org.python.example.eggs": return self
>                raise "unknown: " + protocol
>    >>> class EggsAndHam:
>            def ham(self,str): print "ham!"+str
>            def __query__(self,protocol):
>                if protocol == "org.python.example.ham": return self
>                if protocol == "org.python.example.eggs":
>                    return EggsOnly()
>                raise "unknown" + protocol

This seems to be implying that it is appropriate to return a brand-new
object with no association with the original object.  Is that correct?

Does it make sense to have something like:

class HamAndEggs:
    def __query__(self, protocol):
        if protocol.find("org.python.example.ham") == 0:
            return self
h = HamAndEggs()
e = h.__query__("org.python.example.ham.eggs")
                      --- Aahz  <*>  (Copyright 2001 by aahz at

Androgynous poly kinky vanilla queer het Pythonista
Hugs and backrubs -- I break Rule 6

"I won't accept a model of the universe in which free will, omniscient
gods, and atheism are simultaneously true."  -- M

More information about the Python-list mailing list