'Create user `name` with password `password`.
Add a new user with permissions for this :class:`Database`.
.. note:: Will change the password if user `name` already exists.
:Parameters:
- `name`: the name of the user to create
- `password` (optional): the password of the user to create. Can not
be used with the ``userSource`` argument.
- `read_only` (optional): if ``True`` the user will be read only
- `**kwargs` (optional): optional fields for the user document
(e.g. ``userSource``, ``otherDBRoles``, or ``roles``). See
`<http://docs.mongodb.org/manual/reference/privilege-documents>`_
for more information.
.. note:: The use of optional keyword arguments like ``userSource``,
``otherDBRoles``, or ``roles`` requires MongoDB >= 2.4.0
.. versionchanged:: 2.5
Added kwargs support for optional fields introduced in MongoDB 2.4
.. versionchanged:: 2.2
Added support for read only users'

def add_user(self, name, password=None, read_only=None, **kwargs):

    if (not isinstance(name, string_type)):
        raise TypeError(('name    must    be    an    instance    of    %s' % (string_type.__name__,)))
    if (password is not None):
        if (not isinstance(password, string_type)):
            raise TypeError(('password    must    be    an    instance    of    %s' % (string_type.__name__,)))
        if (len(password) == 0):
            raise ValueError("password    can't    be    empty")
    if (read_only is not None):
        read_only = common.validate_boolean('read_only', read_only)
        if ('roles' in kwargs):
            raise ConfigurationError('Can    not    use    read_only    and    roles    together')
    try:
        uinfo = self.command('usersInfo', name)
        self._create_or_update_user((not uinfo['users']), name, password, read_only, **kwargs)
    except OperationFailure as exc:
        if (exc.code in common.COMMAND_NOT_FOUND_CODES):
            self._legacy_add_user(name, password, read_only, **kwargs)
            return
        elif (exc.code == 13):
            self._create_or_update_user(True, name, password, read_only, **kwargs)
        else:
            raise
