Make json conversion functions private
This commit is contained in:
parent
ea2d972666
commit
4a72201617
@ -430,7 +430,7 @@ class DiscordWebSocket:
|
||||
msg = self._zlib.decompress(self._buffer)
|
||||
msg = msg.decode('utf-8')
|
||||
self._buffer = bytearray()
|
||||
msg = utils.from_json(msg)
|
||||
msg = utils._from_json(msg)
|
||||
|
||||
_log.debug('For Shard ID %s: WebSocket Event: %s', self.shard_id, msg)
|
||||
event = msg.get('t')
|
||||
@ -595,7 +595,7 @@ class DiscordWebSocket:
|
||||
|
||||
async def send_as_json(self, data):
|
||||
try:
|
||||
await self.send(utils.to_json(data))
|
||||
await self.send(utils._to_json(data))
|
||||
except RuntimeError as exc:
|
||||
if not self._can_handle_close():
|
||||
raise ConnectionClosed(self.socket, shard_id=self.shard_id) from exc
|
||||
@ -603,7 +603,7 @@ class DiscordWebSocket:
|
||||
async def send_heartbeat(self, data):
|
||||
# This bypasses the rate limit handling code since it has a higher priority
|
||||
try:
|
||||
await self.socket.send_str(utils.to_json(data))
|
||||
await self.socket.send_str(utils._to_json(data))
|
||||
except RuntimeError as exc:
|
||||
if not self._can_handle_close():
|
||||
raise ConnectionClosed(self.socket, shard_id=self.shard_id) from exc
|
||||
@ -629,7 +629,7 @@ class DiscordWebSocket:
|
||||
}
|
||||
}
|
||||
|
||||
sent = utils.to_json(payload)
|
||||
sent = utils._to_json(payload)
|
||||
_log.debug('Sending "%s" to change status', sent)
|
||||
await self.send(sent)
|
||||
|
||||
@ -735,7 +735,7 @@ class DiscordVoiceWebSocket:
|
||||
|
||||
async def send_as_json(self, data):
|
||||
_log.debug('Sending voice websocket frame: %s.', data)
|
||||
await self.ws.send_str(utils.to_json(data))
|
||||
await self.ws.send_str(utils._to_json(data))
|
||||
|
||||
send_heartbeat = send_as_json
|
||||
|
||||
@ -895,7 +895,7 @@ class DiscordVoiceWebSocket:
|
||||
# This exception is handled up the chain
|
||||
msg = await asyncio.wait_for(self.ws.receive(), timeout=30.0)
|
||||
if msg.type is aiohttp.WSMsgType.TEXT:
|
||||
await self.received_message(utils.from_json(msg.data))
|
||||
await self.received_message(utils._from_json(msg.data))
|
||||
elif msg.type is aiohttp.WSMsgType.ERROR:
|
||||
_log.debug('Received %s', msg)
|
||||
raise ConnectionClosed(self.ws, shard_id=None) from msg.data
|
||||
|
@ -99,7 +99,7 @@ async def json_or_text(response: aiohttp.ClientResponse) -> Union[Dict[str, Any]
|
||||
text = await response.text(encoding='utf-8')
|
||||
try:
|
||||
if response.headers['content-type'] == 'application/json':
|
||||
return utils.from_json(text)
|
||||
return utils._from_json(text)
|
||||
except KeyError:
|
||||
# Thanks Cloudflare
|
||||
pass
|
||||
@ -231,7 +231,7 @@ class HTTPClient:
|
||||
# some checking if it's a JSON request
|
||||
if 'json' in kwargs:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
kwargs['data'] = utils.to_json(kwargs.pop('json'))
|
||||
kwargs['data'] = utils._to_json(kwargs.pop('json'))
|
||||
|
||||
try:
|
||||
reason = kwargs.pop('reason')
|
||||
@ -493,7 +493,7 @@ class HTTPClient:
|
||||
if stickers:
|
||||
payload['sticker_ids'] = stickers
|
||||
|
||||
form.append({'name': 'payload_json', 'value': utils.to_json(payload)})
|
||||
form.append({'name': 'payload_json', 'value': utils._to_json(payload)})
|
||||
if len(files) == 1:
|
||||
file = files[0]
|
||||
form.append(
|
||||
@ -1657,7 +1657,7 @@ class HTTPClient:
|
||||
form: List[Dict[str, Any]] = [
|
||||
{
|
||||
'name': 'payload_json',
|
||||
'value': utils.to_json(payload),
|
||||
'value': utils._to_json(payload),
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -479,17 +479,17 @@ def _bytes_to_base64_data(data: bytes) -> str:
|
||||
|
||||
if HAS_ORJSON:
|
||||
|
||||
def to_json(obj: Any) -> str: # type: ignore
|
||||
def _to_json(obj: Any) -> str: # type: ignore
|
||||
return orjson.dumps(obj).decode('utf-8')
|
||||
|
||||
from_json = orjson.loads # type: ignore
|
||||
_from_json = orjson.loads # type: ignore
|
||||
|
||||
else:
|
||||
|
||||
def to_json(obj: Any) -> str:
|
||||
def _to_json(obj: Any) -> str:
|
||||
return json.dumps(obj, separators=(',', ':'), ensure_ascii=True)
|
||||
|
||||
from_json = json.loads
|
||||
_from_json = json.loads
|
||||
|
||||
|
||||
def _parse_ratelimit_header(request: Any, *, use_clock: bool = False) -> float:
|
||||
|
@ -116,7 +116,7 @@ class AsyncWebhookAdapter:
|
||||
|
||||
if payload is not None:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
to_send = utils.to_json(payload)
|
||||
to_send = utils._to_json(payload)
|
||||
|
||||
if auth_token is not None:
|
||||
headers['Authorization'] = f'Bot {auth_token}'
|
||||
@ -481,7 +481,7 @@ def handle_message_parameters(
|
||||
files = [file]
|
||||
|
||||
if files:
|
||||
multipart.append({'name': 'payload_json', 'value': utils.to_json(payload)})
|
||||
multipart.append({'name': 'payload_json', 'value': utils._to_json(payload)})
|
||||
payload = None
|
||||
if len(files) == 1:
|
||||
file = files[0]
|
||||
|
@ -117,7 +117,7 @@ class WebhookAdapter:
|
||||
|
||||
if payload is not None:
|
||||
headers['Content-Type'] = 'application/json'
|
||||
to_send = utils.to_json(payload)
|
||||
to_send = utils._to_json(payload)
|
||||
|
||||
if auth_token is not None:
|
||||
headers['Authorization'] = f'Bot {auth_token}'
|
||||
|
Loading…
x
Reference in New Issue
Block a user