Barry Warsaw writes:
 > Since I didn't understand what keytype actually provided, even after
 > reading the docs on it several times, I've never found a need for it
 > <wink>.

Sounds like I need to improve the docs for this.

Changing the keytype allows different interpretations for keys.  The
only thing required of keys at the lowest level of the parser is that
keys do not contain spaces.  The "basic-key" datatype is used to
create a case-insensitive handling to keys.  Setting keytype to
"identifier" would require that all keys in sections of that type be
Python identifiers, and would be case-sensitive.  Another keytype
might allow email addresses to be used as keys:

def email_address(text):
    user, host = text.split("@")
    host = host.lower()  # normalize what can be normalized
    return "[EMAIL PROTECTED]" % (user, host)

This can be especially useful when implementing a section type that
acts as a mapping:

<sectiontype name="email-mapping"
  <key name="+"

where the additional datatype simply discards the section object and
returns the key-value mapping:

def mapping(section):
    return section.mapping

 > Even with the above, I'm still not 100% sure what specifying keytypes
 > does for me, or why or when I'd want to use it.  On the face of the
 > above, if it makes it easier to use generalize base section types, then
 > it might be a good idea.

The specific base section type I wanted to provide as part of a
"standard library" of section type was just such a mapping section as
described above.  If both of the proposals are considered acceptable,
I'd be able to provide a basic type that could be specialized to use
email addresses as keys very simply:

<import package="ZConfig.components.basic" />

<sectiontype name="email-mapping"
             extends="ZConfig.components.basic.mapping" />

No need to monkey around with the weird <key name="+" .../> stuff.  ;-)


Fred L. Drake, Jr.  <fred at>
PythonLabs at Zope Corporation

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to