Пример #1
0
def _best_mime():
    """ Returns the best match between the requested mime type and the
    ones supported by Eve. Along with the mime, also the corresponding
    render function is returns.

    .. versionchanged:: 0.8
       Support for optional renderers via RENDERERS. XML and JSON
       configuration keywords removed.

    .. versionchanged:: 0.3
       Support for optional renderers via XML and JSON configuration keywords.
    """
    supported = []
    renders = {}
    for renderer_cls in app.config.get('RENDERERS'):
        renderer = import_from_string(renderer_cls)
        for mime_type in renderer.mime:
            supported.append(mime_type)
            renders[mime_type] = renderer

    if len(supported) == 0:
        abort(500, description=debug_error_message(
            'Configuration error: no supported mime types')
        )

    best_match = request.accept_mimetypes.best_match(supported) or \
        supported[0]
    return best_match, renders[best_match]
Пример #2
0
def _best_mime():
    """ Returns the best match between the requested mime type and the
    ones supported by Eve. Along with the mime, also the corresponding
    render function is returns.

    .. versionchanged:: 0.8
       Support for optional renderers via RENDERERS. XML and JSON
       configuration keywords removed.

    .. versionchanged:: 0.3
       Support for optional renderers via XML and JSON configuration keywords.
    """
    supported = []
    renders = {}
    for renderer_cls in app.config.get("RENDERERS"):
        renderer = import_from_string(renderer_cls)
        for mime_type in renderer.mime:
            supported.append(mime_type)
            renders[mime_type] = renderer

    if len(supported) == 0:
        abort(
            500,
            description=debug_error_message(
                "Configuration error: no supported mime types"),
        )

    best_match = request.accept_mimetypes.best_match(supported) or supported[0]
    return best_match, renders[best_match]
def _best_mime():
    """ Returns the best match between the requested mime type and the
    ones supported by Eve. Along with the mime, also the corresponding
    render function is returns.

    .. versionchanged:: 0.8
       Support for optional renderers via RENDERERS. XML and JSON
       configuration keywords removed.

    .. versionchanged:: 0.3
       Support for optional renderers via XML and JSON configuration keywords.
    """
    supported = []
    renders = {}
    for renderer_cls in app.config.get('RENDERERS'):
        renderer = import_from_string(renderer_cls)
        for mime_type in renderer.mime:
            #### >>> Added code
            if request.base_url.endswith('.{}'.format(
                    getattr(renderer, "tag", "json").lower())):
                supported = []
                renders = {}
                supported.append(mime_type)
                renders[mime_type] = renderer
                break
            #### <<< Added code
            supported.append(mime_type)
            renders[mime_type] = renderer

    if len(supported) == 0:
        abort(500,
              description=debug_error_message(
                  'Configuration error: no supported mime types'))

    best_match = request.accept_mimetypes.best_match(supported) or \
                 supported[0]
    return best_match, renders[best_match]
Пример #4
0
 def test_import_from_string(self):
     dt = import_from_string("datetime.datetime")
     self.assertEqual(dt, datetime)
Пример #5
0
 def test_import_from_string(self):
     dt = import_from_string("datetime.datetime")
     self.assertEqual(dt, datetime)