๐Ÿ“ฆ Significant-Gravitas / vcrpy

๐Ÿ“„ compat.py ยท 27 lines
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
26
27import http.client
from io import BytesIO

"""
The python3 http.client api moved some stuff around, so this is an abstraction
layer that tries to cope with this move.
"""


def get_header(message, name):
    return message.getallmatchingheaders(name)


def get_header_items(message):
    for key, values in get_headers(message):
        for value in values:
            yield key, value


def get_headers(message):
    for key in set(message.keys()):
        yield key, message.get_all(key)


def get_httpmessage(headers):
    return http.client.parse_headers(BytesIO(headers))