Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use orjson instead of json #175

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ maintainers = [
dependencies = [
"async_timeout>=3.0.1;python_version<'3.11'",
"cryptography",
"orjson",
]
classifiers = [
"License :: OSI Approved :: Apache Software License",
Expand Down
10 changes: 5 additions & 5 deletions src/pylutron_caseta/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import asyncio
import functools
import json
import orjson as json
import logging
import socket
import ssl
import urllib.parse
from contextlib import asynccontextmanager
from pathlib import Path
from typing import Any, AsyncIterator, List, Optional, TextIO
from typing import Any, AsyncIterator, List, Optional, TextIO, BinaryIO
from urllib.parse import urlparse

import click
Expand Down Expand Up @@ -271,7 +271,7 @@ async def _connect(
@click.option(
"-o",
"--output",
type=click.File("w", encoding="utf8"),
type=click.File("wb"),
default="-",
help="Save the response into a file.",
)
Expand All @@ -289,7 +289,7 @@ async def leap(
data: Optional[str],
paging: Optional[str],
fail: bool,
output: TextIO,
output: BinaryIO,
verbose: bool,
):
"""
Expand Down Expand Up @@ -332,4 +332,4 @@ async def leap(
else:
output.write(json.dumps(response.Body))

output.write("\n")
output.write(b"\n")
4 changes: 2 additions & 2 deletions src/pylutron_caseta/leap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""LEAP protocol layer."""

import asyncio
import json
import orjson as json
jonoberheide marked this conversation as resolved.
Show resolved Hide resolved
import logging
import re
import uuid
Expand Down Expand Up @@ -68,7 +68,7 @@ def clean_up(future):
future.add_done_callback(clean_up)

try:
text = json.dumps(cmd).encode("UTF-8")
text = json.dumps(cmd)
_LOG.debug("sending %s", text)
self._writer.write(text + b"\r\n")

Expand Down
4 changes: 2 additions & 2 deletions src/pylutron_caseta/pairing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Guide the user through pairing and save the necessary files."""

import asyncio
import json
import orjson as json
import logging
import socket
import ssl
Expand Down Expand Up @@ -61,7 +61,7 @@ async def async_read_json(self, timeout):

async def async_write_json(self, obj):
"""Write an object."""
buffer = f"{json.dumps(obj)}\r\n".encode("ASCII")
buffer = json.dumps(obj) + b"\r\n"
self._writer.write(buffer)
jonoberheide marked this conversation as resolved.
Show resolved Hide resolved
LOGGER.debug("sent: %s", buffer)

Expand Down
Loading