summaryrefslogtreecommitdiff
path: root/src/tablib/utils.py
blob: 39de8ce4e0239a4884ce9e827b3337138ff8804b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
from io import BytesIO, StringIO


def normalize_input(stream):
    """
    Accept either a str/bytes stream or a file-like object and always return a
    file-like object.
    """
    if isinstance(stream, str):
        return StringIO(stream)
    elif isinstance(stream, bytes):
        return BytesIO(stream)
    return stream