Skip to content

Commit d3b8445

Browse files
committed
style: format code according to PEP8 standard
1 parent 30f7bfe commit d3b8445

File tree

9 files changed

+67
-31
lines changed

9 files changed

+67
-31
lines changed

openpaygo/metrics_request.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import copy
2-
from typing import Optional, List, Dict, Any, Union
3-
from .models import MetricsDataFormat, MetricsHistoricalDataStep
2+
from typing import Any, Dict, List, Optional, Union
3+
44
from .metrics_shared import OpenPAYGOMetricsShared
5+
from .models import MetricsDataFormat, MetricsHistoricalDataStep
56

67

78
class MetricsRequestHandler(object):
89
def __init__(
9-
self, serial_number: str, data_format: Optional[Union[Dict[str, Any], MetricsDataFormat]] = None, secret_key: Optional[str] = None, auth_method: Optional[str] = None
10+
self,
11+
serial_number: str,
12+
data_format: Optional[Union[Dict[str, Any], MetricsDataFormat]] = None,
13+
secret_key: Optional[str] = None,
14+
auth_method: Optional[str] = None,
1015
) -> None:
1116
self.secret_key = secret_key
1217
self.auth_method = auth_method
@@ -15,12 +20,18 @@ def __init__(
1520
}
1621
if data_format is not None:
1722
if isinstance(data_format, dict):
18-
self.data_format: Optional[Dict[str, Any]] = MetricsDataFormat.model_validate(data_format).model_dump(exclude_none=True)
23+
self.data_format: Optional[Dict[str, Any]] = (
24+
MetricsDataFormat.model_validate(data_format).model_dump(
25+
exclude_none=True
26+
)
27+
)
1928
else:
20-
self.data_format: Optional[Dict[str, Any]] = data_format.model_dump(exclude_none=True)
29+
self.data_format: Optional[Dict[str, Any]] = data_format.model_dump(
30+
exclude_none=True
31+
)
2132
else:
2233
self.data_format: Optional[Dict[str, Any]] = None
23-
34+
2435
if self.data_format:
2536
if self.data_format.get("id"):
2637
self.request_dict["data_format_id"] = self.data_format.get("id")
@@ -38,15 +49,19 @@ def set_timestamp(self, timestamp: int) -> None:
3849
def set_data(self, data: Dict[str, Any]) -> None:
3950
self.data = data
4051

41-
def set_historical_data(self, historical_data: List[Union[Dict[str, Any], MetricsHistoricalDataStep]]) -> None:
52+
def set_historical_data(
53+
self, historical_data: List[Union[Dict[str, Any], MetricsHistoricalDataStep]]
54+
) -> None:
4255
validated_historical_data = []
4356
for time_step in historical_data:
4457
if isinstance(time_step, dict):
45-
step = MetricsHistoricalDataStep.model_validate(time_step).model_dump(exclude_none=True, mode='json')
58+
step = MetricsHistoricalDataStep.model_validate(time_step).model_dump(
59+
exclude_none=True, mode="json"
60+
)
4661
else:
47-
step = time_step.model_dump(exclude_none=True, mode='json')
62+
step = time_step.model_dump(exclude_none=True, mode="json")
4863
validated_historical_data.append(step)
49-
64+
5065
if self.data_format and not self.data_format.get("historical_data_interval"):
5166
for time_step in validated_historical_data:
5267
if not time_step.get("timestamp"):

openpaygo/metrics_response.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import copy
22
import json
33
from datetime import datetime, timedelta
4-
from typing import Optional, List, Dict, Any, Union
4+
from typing import Any, Dict, List, Optional, Union
55

6-
from .models import MetricsDataFormat
76
from .metrics_shared import OpenPAYGOMetricsShared
7+
from .models import MetricsDataFormat
88

99

1010
class MetricsResponseHandler(object):
@@ -35,16 +35,24 @@ def __init__(
3535

3636
if data_format is not None:
3737
if isinstance(data_format, dict):
38-
self.data_format: Optional[Dict[str, Any]] = MetricsDataFormat.model_validate(data_format).model_dump(exclude_none=True)
38+
self.data_format: Optional[Dict[str, Any]] = (
39+
MetricsDataFormat.model_validate(data_format).model_dump(
40+
exclude_none=True
41+
)
42+
)
3943
else:
40-
self.data_format: Optional[Dict[str, Any]] = data_format.model_dump(exclude_none=True)
44+
self.data_format: Optional[Dict[str, Any]] = data_format.model_dump(
45+
exclude_none=True
46+
)
4147
else:
4248
self.data_format: Optional[Dict[str, Any]] = None
4349

4450
if not self.data_format and self.request_dict.get("data_format"):
4551
df = self.request_dict.get("data_format")
4652
if isinstance(df, dict):
47-
self.data_format = MetricsDataFormat.model_validate(df).model_dump(exclude_none=True)
53+
self.data_format = MetricsDataFormat.model_validate(df).model_dump(
54+
exclude_none=True
55+
)
4856
else:
4957
self.data_format = df
5058

@@ -68,7 +76,9 @@ def set_device_parameters(
6876
self.secret_key = secret_key
6977
if data_format is not None:
7078
if isinstance(data_format, dict):
71-
self.data_format = MetricsDataFormat.model_validate(data_format).model_dump(exclude_none=True)
79+
self.data_format = MetricsDataFormat.model_validate(
80+
data_format
81+
).model_dump(exclude_none=True)
7282
else:
7383
self.data_format = data_format.model_dump(exclude_none=True)
7484
if last_request_count:

openpaygo/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Optional, List, Any, Dict
1+
from typing import Any, Dict, List, Optional
2+
23
from pydantic import BaseModel, ConfigDict
34

45

@@ -12,7 +13,7 @@ class MetricsDataFormat(BaseModel):
1213
class MetricsHistoricalDataStep(BaseModel):
1314
timestamp: Optional[int] = None
1415
relative_time: Optional[int] = None
15-
model_config = ConfigDict(extra='allow')
16+
model_config = ConfigDict(extra="allow")
1617

1718

1819
class MetricsRequestData(BaseModel):
@@ -24,4 +25,4 @@ class MetricsRequestData(BaseModel):
2425
request_count: Optional[int] = None
2526
timestamp: Optional[int] = None
2627
auth: Optional[str] = None
27-
model_config = ConfigDict(extra='allow')
28+
model_config = ConfigDict(extra="allow")

openpaygo/token_decode.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from typing import List, Optional, Tuple, Union
2+
13
from .token_shared import OpenPAYGOTokenShared, TokenType
24
from .token_shared_extended import OpenPAYGOTokenSharedExtended
3-
from typing import Optional, List, Union, Tuple
45

56

67
class OpenPAYGOTokenDecoder(object):
@@ -134,7 +135,14 @@ def get_activation_value_count_and_type_from_token(
134135
return None, TokenType.INVALID, None, None
135136

136137
@classmethod
137-
def _count_is_valid(cls, count: int, last_count: int, value: int, type: int, used_counts: Optional[List[int]]) -> bool:
138+
def _count_is_valid(
139+
cls,
140+
count: int,
141+
last_count: int,
142+
value: int,
143+
type: int,
144+
used_counts: Optional[List[int]],
145+
) -> bool:
138146

139147
if value == OpenPAYGOTokenShared.COUNTER_SYNC_VALUE:
140148
if count > (last_count - cls.MAX_TOKEN_JUMP):
@@ -148,7 +156,13 @@ def _count_is_valid(cls, count: int, last_count: int, value: int, type: int, use
148156
return False
149157

150158
@classmethod
151-
def update_used_counts(cls, past_used_counts: Optional[List[int]], value: int, new_count: int, type: int) -> Optional[List[int]]:
159+
def update_used_counts(
160+
cls,
161+
past_used_counts: Optional[List[int]],
162+
value: int,
163+
new_count: int,
164+
type: int,
165+
) -> Optional[List[int]]:
152166
if not past_used_counts:
153167
return None
154168
highest_count = max(past_used_counts) if past_used_counts else 0

openpaygo/token_encode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from typing import Optional, Tuple
2+
13
from .token_shared import OpenPAYGOTokenShared, TokenType
24
from .token_shared_extended import OpenPAYGOTokenSharedExtended
3-
from typing import Optional, Union, Tuple
45

56

67
class OpenPAYGOTokenEncoder(object):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ zip-safe = false
6767
where = ["."]
6868

6969
[tool.ruff]
70+
[tool.ruff.lint]
7071
# Add some rules to ruff's default:
7172
# - isort: https://docs.astral.sh/ruff/rules/#isort-i
7273
# - pep8-naming: https://docs.astral.sh/ruff/rules/#pep8-naming-n

test/simple_scenario_test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ def assert_time_equals(time1, time2):
128128
)
129129

130130
print("\n")
131-
print(
132-
"Server: We generate a bunch of 1 day tokens, but only enter the latest " "one"
133-
)
131+
print("Server: We generate a bunch of 1 day tokens, but only enter the latest one")
134132
server_simulator.generate_token_from_date(datetime.now() + timedelta(days=1))
135133
server_simulator.generate_token_from_date(datetime.now() + timedelta(days=1))
136134
server_simulator.generate_token_from_date(datetime.now() + timedelta(days=1))
@@ -202,9 +200,7 @@ def assert_time_equals(time1, time2):
202200
device_simulator.enter_token(token_4)
203201
device_simulator.enter_token(token_3)
204202
device_simulator.enter_token(token_2)
205-
print(
206-
"Device: We check the device status , it should have +4 days (6 days " "total)"
207-
)
203+
print("Device: We check the device status , it should have +4 days (6 days total)")
208204
device_simulator.print_status()
209205
assert_time_equals(
210206
device_simulator.expiration_date, datetime.now() + timedelta(days=6)

test/simulators/device_simulator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class DeviceSimulator(object):
8-
98
def __init__(
109
self,
1110
starting_code,

test/simulators/server_simulator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class SingleDeviceServerSimulator(object):
8-
98
def __init__(
109
self,
1110
starting_code,

0 commit comments

Comments
 (0)