Example #1
0
 def __init__(self, token: str) -> None:
     '''
     Create a token.
     :param token: the token string.
     :raises MissingParameterError: if the token is None or whitespace only.
     '''
     check_string(token, "token")
     self.token = token
Example #2
0
    def __init__(self, token_hash: str) -> None:
        """
        Create a hashed token.

        :param token_hash: the hash of the token.
        :raises MissingParameterError: if the token hash is None or whitespace only.
        """
        check_string(token_hash, 'token_hash')
        self.token_hash = token_hash
Example #3
0
    def __init__(self, id_: str) -> None:
        '''
        Create a namespace ID.

        :param id_: A string identifier for a namespace, consisting of the characters a-zA-Z_0-9
            and no longer than 256 characters.
        :raises MissingParameterError: if the id is None or whitespace only.
        :raises IllegalParameterError: if the id does not match the requirements.
        '''
        check_string(id_, 'namespace id', 'a-zA-Z0-9_', 256)
        self.id = id_
Example #4
0
    def __init__(self, id_: str) -> None:
        '''
        Create an authentication source identifier.

        :param id_: A string identifier for the authentication source, consisting only of
            lowercase ASCII letters and no longer than 20 characters.
        :raises MissingParameterError: if the id is None or whitespace only.
        :raises IllegalParameterError: if the id does not match the requirements.
        '''
        check_string(id_, 'authsource id', self._LEGAL_CHARS, self._MAX_LEN)
        self.id = id_
Example #5
0
    def __init__(self, username: str) -> None:
        """
        Create a new user name.

        :param username: The name of the user matching the regex ^[a-z0-9]+$ and no longer
            than 100 characters.
        :raises MissingParameterError: if the user name is None or whitespace only.
        :raises IllegalUsernameError: if the user name does not meet the requirements.
        """
        try:
            check_string(username, 'username', 'a-z0-9', 100)
        except IllegalParameterError as e:
            raise IllegalUsernameError(e.message) from e
        self.name = username
Example #6
0
    def __init__(self, namespace_id: NamespaceID, data_id: str) -> None:
        """
        Create a new object ID.

        :param namespace_id: The ID of the namespace in which the data ID resides.
        :param data_id: The ID of the data unit, no more than 1000 characters.
        :raises TypeError: if the namespace ID is None.
        :raises MissingParameterError: if the data ID is None or whitespace only.
        :raises IllegalParameterError: if the data ID does not meet the requirements.
        """
        not_none(namespace_id, 'namespace_id')
        check_string(data_id, 'data id',
                     max_len=1000)  # should maybe check for control chars
        self.namespace_id = namespace_id
        self.id = data_id
def fail_check_string(string, name, illegal_characters, max_len, expected):
    with raises(Exception) as got:
        check_string(string, name, illegal_characters, max_len)
    assert_exception_correct(got.value, expected)
def test_check_string_pass():
    check_string('mystring', 'myname')
    check_string('foo', 'bar', max_len=3)
    check_string('foo', 'bar', legal_characters='fo')
    check_string('foo', 'bar', 'fo', 3)