Skip to content

Commit c47bad5

Browse files
committed
more_formatting
1 parent 8605868 commit c47bad5

7 files changed

Lines changed: 49 additions & 43 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Most documentation is currently written in Markdown, making it easy to add, modi
1414

1515
## Issues
1616

17-
Issues are created [here](https://github.com/EnAccess/OpenPAYGO-python/issues/new/choose)
17+
Create new issues in the
18+
[issue tracker](https://github.com/EnAccess/OpenPAYGO-python/issues/new/choose)
1819

1920
### How to Contribute to Issues
2021

openpaygo/metrics_shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def load_secret_key_from_hex(cls, secret_key):
150150
secret_key_bytes = bytes(secret_key)
151151
if len(secret_key_bytes) != 16:
152152
raise ValueError(
153-
"The secret key provided is not correctly formatted, it should be 16 "
153+
"The secret key provided is not correctly formatted, it should be "
154+
"16 "
154155
"bytes. "
155156
)
156157
return secret_key_bytes

openpaygo/simulators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .device_simulator import DeviceSimulator as DeviceSimulator
22
from .server_simulator import SingleDeviceServerSimulator as SingleDeviceServerSimulator
33

4-
__all__ = ["DeviceSimulator", "SingleDeviceServerSimulator"]
4+
__all__ = ["DeviceSimulator", "SingleDeviceServerSimulator"]

openpaygo/simulators/device_simulator.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def __init__(
3131
self.used_counts = []
3232

3333
def print_status(self):
34-
print('-------------------------')
35-
print('Expiration Date: '+ str(self.expiration_date))
36-
print('Current count: '+str(self.count))
37-
print('PAYG Enabled: '+str(self.payg_enabled))
38-
print('Active: '+str(self.is_active()))
39-
print('-------------------------')
34+
print("-------------------------")
35+
print("Expiration Date: " + str(self.expiration_date))
36+
print("Current count: " + str(self.count))
37+
print("PAYG Enabled: " + str(self.payg_enabled))
38+
print("Active: " + str(self.is_active()))
39+
print("-------------------------")
4040

4141
def is_active(self):
4242
return self.expiration_date > datetime.now()
@@ -47,24 +47,26 @@ def enter_token(self, token, show_result=True):
4747
return self._update_device_status_from_token(token_int, show_result)
4848
else:
4949
token_int = int(token)
50-
return self._update_device_status_from_extended_token(token_int, show_result)
50+
return self._update_device_status_from_extended_token(
51+
token_int, show_result
52+
)
5153

5254
def get_days_remaining(self):
5355
if self.payg_enabled:
5456
td = self.expiration_date - datetime.now()
55-
days, hours, minutes = td.days, td.seconds//3600, (td.seconds//60)%60
56-
days = days + (hours + minutes/60)/24
57+
days, hours, minutes = td.days, td.seconds // 3600, (td.seconds // 60) % 60
58+
days = days + (hours + minutes / 60) / 24
5759
return round(days)
5860
else:
59-
return 'infinite'
61+
return "infinite"
6062

6163
def _update_device_status_from_token(self, token, show_result=True):
6264
if (
6365
self.token_entry_blocked_until > datetime.now()
6466
and self.waiting_period_enabled
6567
):
6668
if show_result:
67-
print('TOKEN_ENTRY_BLOCKED')
69+
print("TOKEN_ENTRY_BLOCKED")
6870
return False
6971

7072
token_value, token_type, token_count, updated_counts = (
@@ -80,22 +82,22 @@ def _update_device_status_from_token(self, token, show_result=True):
8082
if token_value is None:
8183
if token_type == TokenType.ALREADY_USED:
8284
if show_result:
83-
print('OLD_TOKEN')
85+
print("OLD_TOKEN")
8486
return -2
8587
if show_result:
86-
print('TOKEN_INVALID')
88+
print("TOKEN_INVALID")
8789
self.invalid_token_count += 1
8890
self.token_entry_blocked_until = datetime.now() + timedelta(
8991
minutes=2**self.invalid_token_count
9092
)
9193
return -1
9294
elif token_value == -2:
9395
if show_result:
94-
print('OLD_TOKEN')
96+
print("OLD_TOKEN")
9597
return -2
9698
else:
9799
if show_result:
98-
print('TOKEN_VALID', ' | Value:', token_value)
100+
print("TOKEN_VALID", " | Value:", token_value)
99101
if (
100102
token_count > self.count
101103
or token_value == OpenPAYGOTokenShared.COUNTER_SYNC_VALUE
@@ -112,7 +114,7 @@ def _update_device_status_from_extended_token(self, token, show_result=True):
112114
and self.waiting_period_enabled
113115
):
114116
if show_result:
115-
print('TOKEN_ENTRY_BLOCKED')
117+
print("TOKEN_ENTRY_BLOCKED")
116118

117119
token_value, token_count = (
118120
OpenPAYGOTokenDecoder.get_activation_value_count_from_extended_token(
@@ -125,14 +127,14 @@ def _update_device_status_from_extended_token(self, token, show_result=True):
125127
)
126128
if token_value is None:
127129
if show_result:
128-
print('TOKEN_INVALID')
130+
print("TOKEN_INVALID")
129131
self.invalid_token_count += 1
130132
self.token_entry_blocked_until = datetime.now() + timedelta(
131133
minutes=2**self.invalid_token_count
132134
)
133135
else:
134136
if show_result:
135-
print('Special token entered, value: '+str(token_value))
137+
print("Special token entered, value: " + str(token_value))
136138

137139
def _update_device_status_from_token_value(self, token_value, token_type):
138140
if token_value <= OpenPAYGOTokenShared.MAX_ACTIVATION_VALUE:
@@ -143,14 +145,15 @@ def _update_device_status_from_token_value(self, token_value, token_type):
143145
elif token_value == OpenPAYGOTokenShared.PAYG_DISABLE_VALUE:
144146
self.payg_enabled = False
145147
elif token_value != OpenPAYGOTokenShared.COUNTER_SYNC_VALUE:
146-
# We do nothing if its the sync counter value, the counter has been synced already
147-
print('COUNTER_SYNCED')
148+
# We do nothing if its the sync counter value, the counter has been synced
149+
# already
150+
print("COUNTER_SYNCED")
148151
else:
149152
# If it's another value we also do nothing, as they are not defined
150-
print('UNKNOWN_COMMAND')
153+
print("UNKNOWN_COMMAND")
151154

152155
def _update_expiration_date_from_value(self, toke_value, token_type):
153-
number_of_days = toke_value/self.time_divider
156+
number_of_days = toke_value / self.time_divider
154157
if token_type == TokenType.SET_TIME:
155158
self.expiration_date = datetime.now() + timedelta(days=number_of_days)
156159
else:

openpaygo/simulators/server_simulator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def __init__(
2424
self.restricted_digit_set = restricted_digit_set
2525

2626
def print_status(self):
27-
print('Expiration Date: '+ str(self.expiration_date))
28-
print('Current count: '+str(self.count))
29-
print('PAYG Enabled: '+str(self.payg_enabled))
27+
print("Expiration Date: " + str(self.expiration_date))
28+
print("Current count: " + str(self.count))
29+
print("PAYG Enabled: " + str(self.payg_enabled))
3030

3131
def generate_payg_disable_token(self):
3232
self.count, token = OpenPAYGOTokenEncoder.generate_token(
@@ -35,7 +35,7 @@ def generate_payg_disable_token(self):
3535
value=0,
3636
count=self.count,
3737
token_type=TokenType.DISABLE_PAYG,
38-
restricted_digit_set=self.restricted_digit_set
38+
restricted_digit_set=self.restricted_digit_set,
3939
)
4040
return SingleDeviceServerSimulator._format_token(token)
4141

@@ -46,7 +46,7 @@ def generate_counter_sync_token(self):
4646
value=0,
4747
count=self.count,
4848
token_type=TokenType.COUNTER_SYNC,
49-
restricted_digit_set=self.restricted_digit_set
49+
restricted_digit_set=self.restricted_digit_set,
5050
)
5151
return SingleDeviceServerSimulator._format_token(token)
5252

@@ -77,7 +77,7 @@ def _generate_token_from_value(self, value, mode):
7777
value=value,
7878
count=self.count,
7979
token_type=mode,
80-
restricted_digit_set=self.restricted_digit_set
80+
restricted_digit_set=self.restricted_digit_set,
8181
)
8282
return SingleDeviceServerSimulator._format_token(token)
8383

@@ -89,10 +89,10 @@ def _get_value_to_activate(self, new_time, reference_time, force_maximum=False):
8989
return 0
9090
else:
9191
days = self._timedelta_to_days(new_time - reference_time)
92-
value = int(round(days*self.time_divider, 0))
92+
value = int(round(days * self.time_divider, 0))
9393
if value > OpenPAYGOTokenShared.MAX_ACTIVATION_VALUE:
9494
if not force_maximum:
95-
raise Exception('TOO_MANY_DAYS_TO_ACTIVATE')
95+
raise Exception("TOO_MANY_DAYS_TO_ACTIVATE")
9696
else:
9797
# Will need to be activated again after those days
9898
return OpenPAYGOTokenShared.MAX_ACTIVATION_VALUE
@@ -106,5 +106,5 @@ def _timedelta_to_days(this_timedelta):
106106
def _format_token(token):
107107
token = str(token)
108108
if len(token) < 9:
109-
token = '0' * (9 - len(token)) + token
109+
token = "0" * (9 - len(token)) + token
110110
return token

openpaygo/token_shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def load_secret_key_from_hex(cls, secret_key):
6565
secret_key_bytes = bytes(secret_key)
6666
if len(secret_key_bytes) != 16:
6767
raise ValueError(
68-
"The secret key provided is not correctly formatted, it should be 16 "
68+
"The secret key provided is not correctly formatted, it should be "
69+
"16 "
6970
"bytes. "
7071
)
7172
return secret_key_bytes

test/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
To run the test, first, create and activate a virtual environment. Then install the module and run the test:
44

5-
```
6-
$ cd tests
7-
$ python -m venv env
8-
$ source env/bin/activate
9-
$ python -m pip install -e ..
10-
$ python simple_scenario_test.py
5+
```bash
6+
cd tests
7+
python -m venv env
8+
source env/bin/activate
9+
python -m pip install -e ..
10+
python simple_scenario_test.py
1111
```
1212

1313
You can do it for full test procedure as well:
1414

15-
```
16-
$ python full_test_procedure.py
15+
```bash
16+
python full_test_procedure.py
1717
```

0 commit comments

Comments
 (0)