Double underscore HTTPClient's internal session.
This commit is contained in:
		| @@ -89,7 +89,7 @@ class HTTPClient: | |||||||
|     def __init__(self, connector=None, *, proxy=None, proxy_auth=None, loop=None): |     def __init__(self, connector=None, *, proxy=None, proxy_auth=None, loop=None): | ||||||
|         self.loop = asyncio.get_event_loop() if loop is None else loop |         self.loop = asyncio.get_event_loop() if loop is None else loop | ||||||
|         self.connector = connector |         self.connector = connector | ||||||
|         self._session = None # filled in static_login |         self.__session = None # filled in static_login | ||||||
|         self._locks = weakref.WeakValueDictionary() |         self._locks = weakref.WeakValueDictionary() | ||||||
|         self._global_over = asyncio.Event(loop=self.loop) |         self._global_over = asyncio.Event(loop=self.loop) | ||||||
|         self._global_over.set() |         self._global_over.set() | ||||||
| @@ -102,8 +102,8 @@ class HTTPClient: | |||||||
|         self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__) |         self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__) | ||||||
|  |  | ||||||
|     def recreate(self): |     def recreate(self): | ||||||
|         if self._session.closed: |         if self.__session.closed: | ||||||
|             self._session = aiohttp.ClientSession(connector=self.connector, loop=self.loop) |             self.__session = aiohttp.ClientSession(connector=self.connector, loop=self.loop) | ||||||
|  |  | ||||||
|     async def request(self, route, *, files=None, header_bypass_delay=None, **kwargs): |     async def request(self, route, *, files=None, header_bypass_delay=None, **kwargs): | ||||||
|         bucket = route.bucket |         bucket = route.bucket | ||||||
| @@ -155,7 +155,7 @@ class HTTPClient: | |||||||
|                     for f in files: |                     for f in files: | ||||||
|                         f.reset(seek=tries) |                         f.reset(seek=tries) | ||||||
|  |  | ||||||
|                 async with self._session.request(method, url, **kwargs) as r: |                 async with self.__session.request(method, url, **kwargs) as r: | ||||||
|                     log.debug('%s %s with %s has returned %s', method, url, kwargs.get('data'), r.status) |                     log.debug('%s %s with %s has returned %s', method, url, kwargs.get('data'), r.status) | ||||||
|  |  | ||||||
|                     # even errors have text involved in them so this is safe to call |                     # even errors have text involved in them so this is safe to call | ||||||
| @@ -221,7 +221,7 @@ class HTTPClient: | |||||||
|             raise HTTPException(r, data) |             raise HTTPException(r, data) | ||||||
|  |  | ||||||
|     async def get_attachment(self, url): |     async def get_attachment(self, url): | ||||||
|         async with self._session.get(url) as resp: |         async with self.__session.get(url) as resp: | ||||||
|             if resp.status == 200: |             if resp.status == 200: | ||||||
|                 return await resp.read() |                 return await resp.read() | ||||||
|             elif resp.status == 404: |             elif resp.status == 404: | ||||||
| @@ -234,8 +234,8 @@ class HTTPClient: | |||||||
|     # state management |     # state management | ||||||
|  |  | ||||||
|     async def close(self): |     async def close(self): | ||||||
|         if self._session: |         if self.__session: | ||||||
|             await self._session.close() |             await self.__session.close() | ||||||
|  |  | ||||||
|     def _token(self, token, *, bot=True): |     def _token(self, token, *, bot=True): | ||||||
|         self.token = token |         self.token = token | ||||||
| @@ -246,7 +246,7 @@ class HTTPClient: | |||||||
|  |  | ||||||
|     async def static_login(self, token, *, bot): |     async def static_login(self, token, *, bot): | ||||||
|         # Necessary to get aiohttp to stop complaining about session creation |         # Necessary to get aiohttp to stop complaining about session creation | ||||||
|         self._session = aiohttp.ClientSession(connector=self.connector, loop=self.loop) |         self.__session = aiohttp.ClientSession(connector=self.connector, loop=self.loop) | ||||||
|         old_token, old_bot = self.token, self.bot_token |         old_token, old_bot = self.token, self.bot_token | ||||||
|         self._token(token, bot=bot) |         self._token(token, bot=bot) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -487,7 +487,8 @@ class Webhook: | |||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def from_state(cls, data, state): |     def from_state(cls, data, state): | ||||||
|         return cls(data, adapter=AsyncWebhookAdapter(session=state.http._session), state=state) |         session = state.http._HTTPClient__session | ||||||
|  |         return cls(data, adapter=AsyncWebhookAdapter(session=session), state=state) | ||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def guild(self): |     def guild(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user