def lengthOf(obj, names, kwargs):
    """
    A validator to test whether or not some named properties have a
    specific length.  The length is specified in one of two ways: either
    a C{range} keyword set with a C{range} / C{xrange} / C{list} object
    containing valid values, or a C{length} keyword with the exact length
    allowed.

    For those named properties that do not have the specified length
    (or that are C{None}), an error will be recorded in C{obj.errors}.

    @param obj: The object whose properties need to be tested.
    @param names: The names of the properties to test.
    @param kwargs: Keyword arguments.  Right now, all but
    C{message}, C{range}, and C{length} values are ignored.
    """
    xr = kwargs.get('range', [kwargs.get('length', 1)])
    minmax = str(min(xr)), str(max(xr))
    if minmax[0] == minmax[1]:
        message = kwargs.get('message', 'must have a length of %s.' % minmax[0]
            )
    else:
        message = kwargs.get('message', 
            'must have a length between %s and %s (inclusive).' % minmax)
    for name in names:
        val = getattr(obj, name, '')
        if val is None or not len(val) in xr:
            obj.errors.add(name, message)
