Пример #1
0
def get_oembed_response(oembed_url, max_width=None, max_height=None):
    """Fetches an OEmbed response for a given URL.

    Deprecated: use get_first_oembed_response.

    :param oembed_url: the OEmbed URL.
    :param max_width: (optional) the maximum width of the embedded resource.
    :param max_height: (optional) the maximum height of the embedded resource.
    :returns: an PyEmbedResponse, representing the resource to embed.
    :raises PyEmbedError: if there is an error fetching the response.
    """

    response = requests.get(__format_url(oembed_url, max_width, max_height))

    if not response.ok:
        raise PyEmbedConsumerError('Failed to get %s (status code %s)' % (
            oembed_url, response.status_code))

    content_type = response.headers['content-type'].split(';')[0]
    return parse.parse_oembed(response.text, content_type)
Пример #2
0
def get_oembed_response(oembed_url, max_width=None, max_height=None):
    """Fetches an OEmbed response for a given URL.

    Deprecated: use get_first_oembed_response.

    :param oembed_url: the OEmbed URL.
    :param max_width: (optional) the maximum width of the embedded resource.
    :param max_height: (optional) the maximum height of the embedded resource.
    :returns: an PyEmbedResponse, representing the resource to embed.
    :raises PyEmbedError: if there is an error fetching the response.
    """

    response = requests.get(__format_url(oembed_url, max_width, max_height))

    if not response.ok:
        raise PyEmbedConsumerError('Failed to get %s (status code %s)' %
                                   (oembed_url, response.status_code))

    content_type = response.headers['content-type'].split(';')[0]
    return parse.parse_oembed(response.text, content_type)
Пример #3
0
def test_should_raise_on_invalid_format(oembed_format, function):
    filename = 'pyembed/core/test/fixtures/parse/link.%s' % oembed_format
    content_type = {'json': 'text/json', 'xml': 'application/xml'}.get(oembed_format)

    with pytest.raises(parse.PyEmbedParseError):
        parse.parse_oembed(open(filename).read(), content_type)
Пример #4
0
def test_should_select_parse_function(oembed_format, function):
    filename = 'pyembed/core/test/fixtures/parse/link.%s' % oembed_format
    content_type = {'json': 'application/json', 'xml': 'text/xml'}.get(oembed_format)

    assert parse.parse_oembed(open(filename).read(), content_type).title == 'Lots of Bees'