def consume_event(response: http.client.HTTPResponse) -> Tuple[str, Any]: _, event = consume_line(response) _, raw_data = consume_line(response) # Swallow the intermediate line response.readline() return event, json.loads(raw_data)
def consume_line(response: http.client.HTTPResponse) -> Tuple[str, str]: name, _, data = response.readline().decode('utf-8').rstrip('\n').partition(':') return name.strip(), data.strip()