summaryrefslogtreecommitdiff
path: root/redis/commands/helpers.py
blob: b012621b3bc34a5508efc091591af7af4a24c22c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def list_or_args(keys, args):
    # returns a single new list combining keys and args
    try:
        iter(keys)
        # a string or bytes instance can be iterated, but indicates
        # keys wasn't passed as a list
        if isinstance(keys, (bytes, str)):
            keys = [keys]
        else:
            keys = list(keys)
    except TypeError:
        keys = [keys]
    if args:
        keys.extend(args)
    return keys


def nativestr(x):
    """Return the decoded binary string, or a string, depending on type."""
    return x.decode("utf-8", "replace") if isinstance(x, bytes) else x


def delist(x):
    """Given a list of binaries, return the stringified version."""
    return [nativestr(obj) for obj in x]