Skip to content

Commit a4fc098

Browse files
committed
Manual fixes
1 parent bd7c848 commit a4fc098

21 files changed

Lines changed: 268 additions & 429 deletions

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ rules:
6262
allowed-values:
6363
- "on"
6464
- "true"
65-
- "false"
65+
- "false"

icloudpy/base.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def request(self, method, url, **kwargs): # pylint: disable=arguments-differ
7272
if self.service.password_filter not in request_logger.filters:
7373
request_logger.addFilter(self.service.password_filter)
7474

75-
request_logger.debug("{} {} {}".format(method, url, kwargs.get("data", "")))
75+
request_logger.debug(f"{method} {url} {kwargs.get('data', '')}")
7676

7777
has_retried = kwargs.get("retried")
7878
kwargs.pop("retried", None)
@@ -89,7 +89,7 @@ def request(self, method, url, **kwargs): # pylint: disable=arguments-differ
8989
)
9090

9191
# Save session_data to file
92-
with open(self.service.session_path, "w") as outfile:
92+
with open(self.service.session_path, "w", encoding="utf-8") as outfile:
9393
json.dump(self.service.session_data, outfile)
9494
LOGGER.debug("Saved session data to file")
9595

@@ -222,7 +222,7 @@ def __init__(
222222
self.user = {"accountName": apple_id, "password": password}
223223
self.data = {}
224224
self.params = {}
225-
self.client_id = client_id or ("auth-%s" % str(uuid1()).lower())
225+
self.client_id = client_id or (f"auth-{str(uuid1()).lower()}")
226226
self.with_family = with_family
227227
self.auth_endpoint = auth_endpoint
228228
self.home_endpoint = home_endpoint
@@ -247,7 +247,7 @@ def __init__(
247247

248248
self.session_data = {}
249249
try:
250-
with open(self.session_path) as session_f:
250+
with open(self.session_path, encoding="utf-8") as session_f:
251251
self.session_data = json.load(session_f)
252252
except: # pylint: disable=bare-except
253253
LOGGER.info("Session file does not exist")
@@ -259,7 +259,7 @@ def __init__(
259259
self.session = ICloudPySession(self)
260260
self.session.verify = verify
261261
self.session.headers.update(
262-
{"Origin": self.home_endpoint, "Referer": "%s/" % self.home_endpoint}
262+
{"Origin": self.home_endpoint, "Referer": f"{self.home_endpoint}/"}
263263
)
264264

265265
cookiejar_path = self.cookiejar_path
@@ -334,7 +334,7 @@ def authenticate(self, force_refresh=False, service=None):
334334

335335
try:
336336
self.session.post(
337-
"%s/signin" % self.auth_endpoint,
337+
f"{self.auth_endpoint}/signin",
338338
params={"isRememberMeEnabled": "true"},
339339
data=json.dumps(data),
340340
headers=headers,
@@ -360,7 +360,7 @@ def _authenticate_with_token(self):
360360

361361
try:
362362
req = self.session.post(
363-
"%s/accountLogin" % self.setup_endpoint, data=json.dumps(data)
363+
f"{self.setup_endpoint}/accountLogin", data=json.dumps(data)
364364
)
365365
self.data = req.json()
366366
except ICloudPyAPIResponseException as error:
@@ -377,7 +377,7 @@ def _authenticate_with_credentials_service(self, service):
377377

378378
try:
379379
self.session.post(
380-
"%s/accountLogin" % self.setup_endpoint, data=json.dumps(data)
380+
f"{self.setup_endpoint}/accountLogin", data=json.dumps(data)
381381
)
382382

383383
self.data = self._validate_token()
@@ -389,7 +389,7 @@ def _validate_token(self):
389389
"""Checks if the current access token is still valid."""
390390
LOGGER.debug("Checking session token validity")
391391
try:
392-
req = self.session.post("%s/validate" % self.setup_endpoint, data="null")
392+
req = self.session.post(f"{self.setup_endpoint}/validate", data="null")
393393
LOGGER.debug("Session token is still valid")
394394
return req.json()
395395
except ICloudPyAPIResponseException as err:
@@ -453,15 +453,15 @@ def is_trusted_session(self):
453453
def trusted_devices(self):
454454
"""Returns devices trusted for two-step authentication."""
455455
request = self.session.get(
456-
"%s/listDevices" % self.setup_endpoint, params=self.params
456+
f"{self.setup_endpoint}/listDevices", params=self.params
457457
)
458458
return request.json().get("devices")
459459

460460
def send_verification_code(self, device):
461461
"""Requests that a verification code is sent to the given device."""
462462
data = json.dumps(device)
463463
request = self.session.post(
464-
"%s/sendVerificationCode" % self.setup_endpoint,
464+
f"{self.setup_endpoint}/sendVerificationCode",
465465
params=self.params,
466466
data=data,
467467
)
@@ -474,7 +474,7 @@ def validate_verification_code(self, device, code):
474474

475475
try:
476476
self.session.post(
477-
"%s/validateVerificationCode" % self.setup_endpoint,
477+
f"{self.setup_endpoint}/validateVerificationCode",
478478
params=self.params,
479479
data=data,
480480
)
@@ -502,7 +502,7 @@ def validate_2fa_code(self, code):
502502

503503
try:
504504
self.session.post(
505-
"%s/verify/trusteddevice/securitycode" % self.auth_endpoint,
505+
f"{self.auth_endpoint}/verify/trusteddevice/securitycode",
506506
data=json.dumps(data),
507507
headers=headers,
508508
)
@@ -530,7 +530,7 @@ def trust_session(self):
530530

531531
try:
532532
self.session.get(
533-
"%s/2sv/trust" % self.auth_endpoint,
533+
f"{self.auth_endpoint}/2sv/trust",
534534
headers=headers,
535535
)
536536
self._authenticate_with_token()
@@ -613,7 +613,7 @@ def drive(self):
613613
return self._drive
614614

615615
def __unicode__(self):
616-
return "iCloud API: %s" % self.user.get("accountName")
616+
return f"iCloud API: {self.user.get('accountName')}"
617617

618618
def __str__(self):
619619
as_unicode = self.__unicode__()
@@ -622,4 +622,4 @@ def __str__(self):
622622
return as_unicode
623623

624624
def __repr__(self):
625-
return "<%s>" % str(self)
625+
return f"<{str(self)}>"

icloudpy/cmdline.py

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,7 @@ def main(args=None):
259259
devices = api.trusted_devices
260260
for i, device in enumerate(devices):
261261
print(
262-
" %s: %s"
263-
% (
264-
i,
265-
device.get(
266-
"deviceName", "SMS to %s" % device.get("phoneNumber")
267-
),
268-
)
262+
f' {i}: {device.get("deviceName", "SMS to " + device.get("phoneNumber"))}'
269263
)
270264

271265
print("\nWhich device would you like to use?")
@@ -289,9 +283,7 @@ def main(args=None):
289283
if utils.password_exists_in_keyring(username):
290284
utils.delete_password_in_keyring(username)
291285

292-
message = "Bad username or password for {username}".format(
293-
username=username,
294-
)
286+
message = f"Bad username or password for {username}"
295287
password = None
296288

297289
failure_count += 1
@@ -319,28 +311,24 @@ def main(args=None):
319311
print("-" * 30)
320312
print(contents["name"])
321313
for key in contents:
322-
print("%20s - %s" % (key, contents[key]))
314+
print(f"{key} - {contents[key]}")
323315
elif command_line.list:
324316
print("-" * 30)
325-
print("Name - %s" % contents["name"])
326-
print("Display Name - %s" % contents["deviceDisplayName"])
327-
print("Location - %s" % contents["location"])
328-
print("Battery Level - %s" % contents["batteryLevel"])
329-
print("Battery Status- %s" % contents["batteryStatus"])
330-
print("Device Class - %s" % contents["deviceClass"])
331-
print("Device Model - %s" % contents["deviceModel"])
317+
print(f"Name - {contents['name']}")
318+
print(f"Display Name - {contents['deviceDisplayName']}")
319+
print(f"Location - {contents['location']}")
320+
print(f"Battery Level - {contents['batteryLevel']}")
321+
print(f"Battery Status- {contents['batteryStatus']}")
322+
print(f"Device Class - {contents['deviceClass']}")
323+
print(f"Device Model - {contents['deviceModel']}")
332324

333325
# Play a Sound on a device
334326
if command_line.sound:
335327
if command_line.device_id:
336328
dev.play_sound()
337329
else:
338330
raise RuntimeError(
339-
"\n\n\t\t%s %s\n\n"
340-
% (
341-
"Sounds can only be played on a singular device.",
342-
DEVICE_ERROR,
343-
)
331+
f"\n\n\t\tSounds can only be played on a singular device. {DEVICE_ERROR}\n\n"
344332
)
345333

346334
# Display a Message on the device
@@ -351,11 +339,7 @@ def main(args=None):
351339
)
352340
else:
353341
raise RuntimeError(
354-
"%s %s"
355-
% (
356-
"Messages can only be played on a singular device.",
357-
DEVICE_ERROR,
358-
)
342+
f"Messages can only be played on a singular device. {DEVICE_ERROR}"
359343
)
360344

361345
# Display a Silent Message on the device
@@ -368,12 +352,7 @@ def main(args=None):
368352
)
369353
else:
370354
raise RuntimeError(
371-
"%s %s"
372-
% (
373-
"Silent Messages can only be played "
374-
"on a singular device.",
375-
DEVICE_ERROR,
376-
)
355+
f"Silent Messages can only be played on a singular device. {DEVICE_ERROR}"
377356
)
378357

379358
# Enable Lost mode
@@ -386,11 +365,7 @@ def main(args=None):
386365
)
387366
else:
388367
raise RuntimeError(
389-
"%s %s"
390-
% (
391-
"Lost Mode can only be activated on a singular device.",
392-
DEVICE_ERROR,
393-
)
368+
f"Lost Mode can only be activated on a singular device. {DEVICE_ERROR}"
394369
)
395370
sys.exit(0)
396371

icloudpy/exceptions.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class ICloudPyException(Exception):
55
"""Generic iCloud exception."""
66

77

8-
98
# API
109
class ICloudPyAPIResponseException(ICloudPyException):
1110
"""iCloud response exception."""
@@ -15,7 +14,7 @@ def __init__(self, reason, code=None, retry=False):
1514
self.code = code
1615
message = reason or ""
1716
if code:
18-
message += " (%s)" % code
17+
message += f" ({code})"
1918
if retry:
2019
message += ". Retrying ..."
2120

@@ -26,27 +25,23 @@ class ICloudPyServiceNotActivatedException(ICloudPyAPIResponseException):
2625
"""iCloud service not activated exception."""
2726

2827

29-
3028
# Login
3129
class ICloudPyFailedLoginException(ICloudPyException):
3230
"""iCloud failed login exception."""
3331

3432

35-
3633
class ICloudPy2SARequiredException(ICloudPyException):
3734
"""iCloud 2SA required exception."""
3835

3936
def __init__(self, apple_id):
40-
message = "Two-step authentication required for account: %s" % apple_id
37+
message = f"Two-step authentication required for account:{apple_id}"
4138
super().__init__(message)
4239

4340

4441
class ICloudPyNoStoredPasswordAvailableException(ICloudPyException):
4542
"""iCloud no stored password exception."""
4643

4744

48-
4945
# Webservice specific
5046
class ICloudPyNoDevicesException(ICloudPyException):
5147
"""iCloud no device exception."""
52-

icloudpy/services/account.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ def __init__(self, service_root, session, params):
1818
self._family = []
1919
self._storage = None
2020

21-
self._acc_endpoint = "%s/setup/web" % self._service_root
22-
self._acc_devices_url = "%s/device/getDevices" % self._acc_endpoint
23-
self._acc_family_details_url = "%s/family/getFamilyDetails" % self._acc_endpoint
21+
self._acc_endpoint = f"{self._service_root}/setup/web"
22+
self._acc_devices_url = f"{self._acc_endpoint}/device/getDevices"
23+
self._acc_family_details_url = f"{self._acc_endpoint}/family/getFamilyDetails"
2424
self._acc_family_member_photo_url = (
25-
"%s/family/getMemberPhoto" % self._acc_endpoint
25+
f"{self._acc_endpoint}/family/getMemberPhoto"
2626
)
27+
2728
self._acc_storage_url = "https://setup.icloud.com/setup/ws/1/storageUsageInfo"
2829

2930
@property
@@ -69,11 +70,8 @@ def storage(self):
6970
return self._storage
7071

7172
def __unicode__(self):
72-
return "{{devices: {}, family: {}, storage: {} bytes free}}".format(
73-
len(self.devices),
74-
len(self.family),
75-
self.storage.usage.available_storage_in_bytes,
76-
)
73+
return f"{{devices: {len(self.devices)}, family: {len(self.family)}, \
74+
storage: {self.storage.usage.available_storage_in_bytes} bytes free}}"
7775

7876
def __str__(self):
7977
as_unicode = self.__unicode__()
@@ -207,9 +205,8 @@ def __getitem__(self, key):
207205
return getattr(self, key)
208206

209207
def __unicode__(self):
210-
return "{{name: {}, age_classification: {}}}".format(
211-
self.full_name,
212-
self.age_classification,
208+
return (
209+
f"{{name: {self.full_name}, age_classification: {self.age_classification}}}"
213210
)
214211

215212
def __str__(self):
@@ -326,10 +323,7 @@ def quota_paid(self):
326323
return self.quota_data["paidQuota"]
327324

328325
def __unicode__(self):
329-
return "{}% used of {} bytes".format(
330-
self.used_storage_in_percent,
331-
self.total_storage_in_bytes,
332-
)
326+
return f"{self.used_storage_in_percent}% used of {self.total_storage_in_bytes} bytes"
333327

334328
def __str__(self):
335329
as_unicode = self.__unicode__()

icloudpy/services/calendar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def __init__(self, service_root, session, params):
1414
self.session = session
1515
self.params = params
1616
self._service_root = service_root
17-
self._calendar_endpoint = "%s/ca" % self._service_root
18-
self._calendar_refresh_url = "%s/events" % self._calendar_endpoint
19-
self._calendar_event_detail_url = "%s/eventdetail" % self._calendar_endpoint
20-
self._calendars = "%s/startup" % self._calendar_endpoint
17+
self._calendar_endpoint = f"{self._service_root}/ca"
18+
self._calendar_refresh_url = f"{self._calendar_endpoint}/events"
19+
self._calendar_event_detail_url = f"{self._calendar_endpoint}/eventdetail"
20+
self._calendars = f"{self._calendar_endpoint}/startup"
2121

2222
self.response = {}
2323

icloudpy/services/contacts.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def __init__(self, service_root, session, params):
1010
self.session = session
1111
self.params = params
1212
self._service_root = service_root
13-
self._contacts_endpoint = "%s/co" % self._service_root
14-
self._contacts_refresh_url = "%s/startup" % self._contacts_endpoint
15-
self._contacts_next_url = "%s/contacts" % self._contacts_endpoint
16-
self._contacts_changeset_url = "%s/changeset" % self._contacts_endpoint
13+
self._contacts_endpoint = f"{self._service_root}/co"
14+
self._contacts_refresh_url = f"{self._contacts_endpoint}/startup"
15+
self._contacts_next_url = f"{self._contacts_endpoint}/contacts"
16+
self._contacts_changeset_url = f"{self._contacts_endpoint}/changeset"
1717

1818
self.response = {}
1919

0 commit comments

Comments
 (0)