Ejemplo n.º 1
0
    def checkName(self, name, object):
        """Limit ids

        Ids can only contain printable, non-space, 7-bit ASCII strings:

        >>> from zope.pluggableauth.plugins.idpicker import IdPicker
        >>> IdPicker({}).checkName(u'1', None)
        True

        >>> IdPicker({}).checkName(u'bob', None)
        True

        >>> try:
        ...     IdPicker({}).checkName(u'bob\xfa', None)
        ... except UserError, e:
        ...     print(e)
        ...     # doctest: +NORMALIZE_WHITESPACE
        Ids must contain only printable 7-bit non-space ASCII characters

        >>> try:
        ...     IdPicker({}).checkName(u'big bob', None)
        ... except UserError, e:
        ...     print(e)
        ...     # doctest: +NORMALIZE_WHITESPACE
        Ids must contain only printable 7-bit non-space ASCII characters

        Ids also can't be over 100 characters long:

        >>> IdPicker({}).checkName(u'x' * 100, None)
        True

        >>> IdPicker({}).checkName(u'x' * 101, None)
        Traceback (most recent call last):
        ...
        UserError: Ids can't be more than 100 characters long.

        """
        NameChooser.checkName(self, name, object)
        if not ok(name):
            raise UserError(
                _("Ids must contain only printable 7-bit non-space"
                  " ASCII characters")
                )
        if len(name) > 100:
            raise UserError(
                _("Ids can't be more than 100 characters long.")
                )
        return True