Skip to content

Commit

Permalink
Merge pull request #199 from pnuckowski/move-requestinfo-to-compat
Browse files Browse the repository at this point in the history
move RequestInfo to compat
  • Loading branch information
pnuckowski committed Oct 28, 2021
2 parents 98549d4 + be8625d commit fa5c85b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 17 additions & 1 deletion aioresponses/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from aiohttp import __version__ as aiohttp_version, StreamReader
from multidict import MultiDict
from yarl import URL
from pkg_resources import parse_version
from yarl import URL

if sys.version_info < (3, 7):
from re import _pattern_type as Pattern
else:
Expand Down Expand Up @@ -46,9 +47,24 @@ def normalize_url(url: 'Union[URL, str]') -> 'URL':
return url.with_query(urlencode(sorted(parse_qsl(url.query_string))))


try:
from aiohttp import RequestInfo
except ImportError:
class RequestInfo(object):
__slots__ = ('url', 'method', 'headers', 'real_url')

def __init__(
self, url: URL, method: str, headers: Dict, real_url: str
):
self.url = url
self.method = method
self.headers = headers
self.real_url = real_url

__all__ = [
'URL',
'Pattern',
'RequestInfo',
'AIOHTTP_VERSION',
'merge_params',
'stream_reader_factory',
Expand Down
6 changes: 1 addition & 5 deletions aioresponses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
stream_reader_factory,
merge_params,
normalize_url,
RequestInfo,
)
if AIOHTTP_VERSION >= StrictVersion('3.1.0'):
try:
from aiohttp import RequestInfo
except ImportError:
RequestInfo = Mock()


class CallbackResult:
Expand Down

0 comments on commit fa5c85b

Please sign in to comment.