import errno


def _convert_errno_parm(code_should_be):
    """ Convert the code_should_be value to an integer
    If code_should_be isn't an integer, then try to use
    the code_should_be value as a errno "name" and extract
    the errno value from the errno module.
    """
    try:
        code = int(code_should_be)
    except ValueError:
        try:
            code = getattr(errno, code_should_be)
        except AttributeError:
            raise AssertionError("code_should_be '%s' is not a valid errno name" % code_should_be)
    return code