<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _get_serv(ret=None, commit=False):
    '''
    Return a mysql cursor
    '''
    _options = _get_options(ret)

    connect = True
    if __context__ and 'mysql_returner_conn' in __context__:
        try:
            log.debug('Trying to reuse MySQL connection pool')
            conn = __context__['mysql_returner_conn']
            conn.ping()
            connect = False
        except OperationalError as exc:
            log.debug('OperationalError on ping: %s', exc)

    if connect:
        log.debug('Generating new MySQL connection pool')
        try:
            # An empty ssl_options dictionary passed to MySQLdb.connect will
            # effectively connect w/o SSL.
            ssl_options = {}
            if _options.get('ssl_ca'):
                ssl_options['ca'] = _options.get('ssl_ca')
            if _options.get('ssl_cert'):
                ssl_options['cert'] = _options.get('ssl_cert')
            if _options.get('ssl_key'):
                ssl_options['key'] = _options.get('ssl_key')
            conn = MySQLdb.connect(host=_options.get('host'),
                                   user=_options.get('user'),
                                   passwd=_options.get('pass'),
                                   db=_options.get('db'),
                                   port=_options.get('port'),
                                   ssl=ssl_options)

            try:
                __context__['mysql_returner_conn'] = conn
            except TypeError:
                pass
        except OperationalError as exc:
            raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc))

    cursor = conn.cursor()

    try:
        yield cursor
    except MySQLdb.DatabaseError as err:
        error = err.args
        sys.stderr.write(six.text_type(error))
        cursor.execute("ROLLBACK")
        raise err
    else:
        if commit:
            cursor.execute("COMMIT")
        else:
            cursor.execute("ROLLBACK")