def tobytes(s):
    """force_bytes(s) -> bytes

    Ensures the given argument is of type bytes

    Example:

        >>> force_bytes(b'abc')
        b'abc'
        >>> force_bytes('abc')
        b'abc'
        >>> force_bytes(1)
        Traceback (most recent call last):
            ...
        TypeError: Expecting a value of type bytes or str, got 1
    """
    if isinstance(s, bytes):
        return s
    elif isinstance(s, str):
        return s.encode('utf8')
    else:
        raise TypeError('Expecting a value of type bytes or str, got %r' % s)