Skip to content

Commit

Permalink
move RequestInfo to compat
Browse files Browse the repository at this point in the history
  • Loading branch information
pnuckowski committed Oct 28, 2021
1 parent 98549d4 commit 7fcae85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 15 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,22 @@ 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 7fcae85

Please sign in to comment.