Example #1
0
# This file is part of OctoHub.
#
# OctoHub is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.

from typing import Optional, cast
import re

from octohub.utils import AttrDict, OctoResponse, get_logger
from octohub.exceptions import ResponseError, OctoHubError

import requests

log = get_logger('response')


def _get_content_type(response: requests.Response) -> Optional[str]:
    """Parse response and return content-type"""
    try:
        content_type = response.headers['Content-Type']
        return content_type.split(';', 1)[0]
    except KeyError:
        return None


def _parse_link(header_link: str) -> AttrDict:
    """Parse header link and return AttrDict[rel].uri|params"""
    links = AttrDict()
    for s in header_link.split(','):
Example #2
0
# Copyright (c) 2013 Alon Swartz <*****@*****.**>
#
# This file is part of OctoHub.
#
# OctoHub is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.

import re

from octohub.utils import AttrDict, get_logger
from octohub.exceptions import ResponseError, OctoHubError

log = get_logger('response')

def _get_content_type(response):
    """Parse response and return content-type"""
    try:
        content_type = response.headers['Content-Type']
        content_type = content_type.split(';', 1)[0]
    except KeyError:
        content_type = None

    return content_type

def _parse_link(header_link):
    """Parse header link and return AttrDict[rel].uri|params"""
    links = AttrDict()
    for s in header_link.split(','):
        link = AttrDict()