1#!/usr/bin/env python3
 2
 3import json
 4from datetime import datetime
 5from datetime import timezone
 6from typing import Optional
 7
 8from chart.project import SID
 9
10
11TIME_DECODER = '%Y-%m-%d %H:%M:%S.%f'
12
13
14class UnknownToken(Exception):
15    """Exception raised when unknown token is encountered during parsing."""
16
17    def __init__(self, msg):
18        super(UnknownToken, self).__init__(msg)
19
20
21def utc_to_timestamp(dt):
22    return dt.replace(tzinfo=timezone.utc).timestamp()
23
24
25def json_converter(o):
26    """Custom Converter (just datetime for now) of objects to string for json dumps."""
27    if isinstance(o, datetime):
28        return o.strftime(TIME_DECODER)
29
30
31def jsondumps(data):
32    """Dump dict data dict as json using custom converter."""
33    return json.dumps(data, default=json_converter)
34
35
36def is_sublist(l, lol):
37    """Checks if a list `l` is a subset of a list of lists `lol`"""
38    for sublist in lol:
39        temp = [i for i in sublist if i in l]
40        if sorted(temp) == sorted(l):
41            return True
42    return False