def to_binary()

in datahub/utils/converters.py [0:0]


def to_binary(text, encoding='utf-8'):
    if text is None:
        return text
    if isinstance(text, six.text_type):
        return text.encode(encoding)
    elif isinstance(text, (six.binary_type, bytearray)):
        return bytes(text)
    return str(text).encode(encoding) if six.PY3 else str(text)