requests request typing fix

This commit is contained in:
p1c2u 2021-03-24 13:06:35 +00:00
parent f316b81ba3
commit ff4a6c81ee

View file

@ -1,8 +1,8 @@
"""OpenAPI core contrib requests requests module""" """OpenAPI core contrib requests requests module"""
from typing import Union from __future__ import absolute_import
from werkzeug.datastructures import ImmutableMultiDict from werkzeug.datastructures import ImmutableMultiDict
from requests import Request, PreparedRequest from requests import Request
from urllib.parse import urlparse, parse_qs from six.moves.urllib.parse import urlparse, parse_qs
from openapi_core.validation.request.datatypes import ( from openapi_core.validation.request.datatypes import (
RequestParameters, OpenAPIRequest, RequestParameters, OpenAPIRequest,
@ -12,7 +12,7 @@ from openapi_core.validation.request.datatypes import (
class RequestsOpenAPIRequestFactory(object): class RequestsOpenAPIRequestFactory(object):
@classmethod @classmethod
def create(cls, request: Union[Request, PreparedRequest]) -> OpenAPIRequest: def create(cls, request):
""" """
Converts a requests request to an OpenAPI one Converts a requests request to an OpenAPI one
@ -40,12 +40,13 @@ class RequestsOpenAPIRequestFactory(object):
# gets deduced by path finder against spec # gets deduced by path finder against spec
path = {} path = {}
# Order matters because all python requests issued from a session include # Order matters because all python requests issued from a session
# Accept */* which does not necessarily match the content type # include Accept */* which does not necessarily match the content type
mimetype = request.headers.get('Content-Type') or \ mimetype = request.headers.get('Content-Type') or \
request.headers.get('Accept') request.headers.get('Accept')
# Headers - request.headers is not an instance of dict, which is expected # Headers - request.headers is not an instance of dict
# which is expected
header = dict(request.headers) header = dict(request.headers)
# Body # Body