Skip to content

Commit

Permalink
switch types from dict to Dict
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikiforov authored May 23, 2024
1 parent 5f5df69 commit 1487305
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions src/pyicloud_ipd/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import Any, NoReturn, Optional, Sequence
from typing import Any, Dict, NoReturn, Optional, Sequence
from typing_extensions import override
import typing
from uuid import uuid1
Expand Down Expand Up @@ -232,9 +232,9 @@ def __init__(
if password is None:
password = get_password_from_keyring(apple_id)

self.user: dict[str, Any] = {"accountName": apple_id, "password": password}
self.data: dict[str, Any] = {}
self.params: dict[str, Any] = {}
self.user: Dict[str, Any] = {"accountName": apple_id, "password": password}
self.data: Dict[str, Any] = {}
self.params: Dict[str, Any] = {}
self.client_id: str = client_id or ("auth-%s" % str(uuid1()).lower())
self.with_family = with_family

Expand Down Expand Up @@ -426,19 +426,19 @@ def _authenticate_with_credentials_service(self, service: str) -> None:
msg = "Invalid email/password combination."
raise PyiCloudFailedLoginException(msg, error) from error

def _validate_token(self) -> dict[str, Any]:
def _validate_token(self) -> Dict[str, Any]:
"""Checks if the current access token is still valid."""
LOGGER.debug("Checking session token validity")
try:
req = self.session.post("%s/validate" % self.SETUP_ENDPOINT, data="null")
LOGGER.debug("Session token is still valid")
result: dict[str, Any] = req.json()
result: Dict[str, Any] = req.json()
return result
except PyiCloudAPIResponseException as err:
LOGGER.debug("Invalid authentication token")
raise err

def _get_auth_headers(self, overrides: Optional[dict[str, str]]=None) -> dict[str, str]:
def _get_auth_headers(self, overrides: Optional[Dict[str, str]]=None) -> Dict[str, str]:
headers = {
"Accept": "*/*",
"Content-Type": "application/json",
Expand Down Expand Up @@ -492,18 +492,18 @@ def is_trusted_session(self) -> bool:
return typing.cast(bool, self.data.get("hsaTrustedBrowser", False))

@property
def trusted_devices(self) -> Sequence[dict[str, Any]]:
def trusted_devices(self) -> Sequence[Dict[str, Any]]:
""" Returns devices trusted for two-step authentication."""
request = self.session.get(
'%s/listDevices' % self.SETUP_ENDPOINT,
params=self.params
)
devices: Optional[Sequence[dict[str, Any]]] = request.json().get('devices')
devices: Optional[Sequence[Dict[str, Any]]] = request.json().get('devices')
if devices:
return devices
return []

def send_verification_code(self, device: dict[str, Any]) -> bool:
def send_verification_code(self, device: Dict[str, Any]) -> bool:
""" Requests that a verification code is sent to the given device"""
data = json.dumps(device)
request = self.session.post(
Expand All @@ -513,7 +513,7 @@ def send_verification_code(self, device: dict[str, Any]) -> bool:
)
return typing.cast(bool, request.json().get('success', False))

def validate_verification_code(self, device: dict[str, Any], code: str) -> bool:
def validate_verification_code(self, device: Dict[str, Any], code: str) -> bool:
"""Verifies a verification code received on a trusted device."""
device.update({"verificationCode": code, "trustBrowser": True})
data = json.dumps(device)
Expand Down
20 changes: 10 additions & 10 deletions src/pyicloud_ipd/services/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re

from datetime import datetime
from typing import Any, Callable, Optional, Sequence
from typing import Any, Callable, Dict, Optional, Sequence
import typing

from requests import Response
Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(self, service, zone_id):
self.service = service
self.zone_id = zone_id

self._albums: Optional[dict[str, PhotoAlbum]] = None
self._albums: Optional[Dict[str, PhotoAlbum]] = None

url = ('%s/records/query?%s' %
(self.service._service_endpoint, urlencode(self.service.params)))
Expand All @@ -168,7 +168,7 @@ def __init__(self, service, zone_id):
'again in a few minutes'), None)

@property
def albums(self) -> dict[str, "PhotoAlbum"]:
def albums(self) -> Dict[str, "PhotoAlbum"]:
if not self._albums:
self._albums = {
name: PhotoAlbum(self.service, name, zone_id=self.zone_id, **props) # type: ignore[arg-type]
Expand Down Expand Up @@ -205,7 +205,7 @@ def albums(self) -> dict[str, "PhotoAlbum"]:

return self._albums

def _fetch_folders(self) -> Sequence[dict[str, Any]]:
def _fetch_folders(self) -> Sequence[Dict[str, Any]]:
url = ('%s/records/query?%s' %
(self.service._service_endpoint, urlencode(self.service.params)))
json_data = json.dumps({
Expand All @@ -220,7 +220,7 @@ def _fetch_folders(self) -> Sequence[dict[str, Any]]:
)
response = request.json()

return typing.cast(Sequence[dict[str, Any]], response['records'])
return typing.cast(Sequence[Dict[str, Any]], response['records'])

@property
def all(self) -> "PhotoAlbum":
Expand All @@ -232,15 +232,15 @@ class PhotosService(PhotoLibrary):
This also acts as a way to access the user's primary library.
"""
def __init__(self, service_root: str, session: Any, params: dict[str, Any]):
def __init__(self, service_root: str, session: Any, params: Dict[str, Any]):
self.session = session
self.params = dict(params)
self._service_root = service_root
self._service_endpoint = \
('%s/database/1/com.apple.photos.cloud/production/private'
% self._service_root)

self._libraries: Optional[dict[str, PhotoLibrary]] = None
self._libraries: Optional[Dict[str, PhotoLibrary]] = None

self.params.update({
'remapEnums': True,
Expand All @@ -259,7 +259,7 @@ def __init__(self, service_root: str, session: Any, params: dict[str, Any]):
service=self, zone_id={u'zoneName': u'PrimarySync'})

@property
def libraries(self) -> dict[str, PhotoLibrary]:
def libraries(self) -> Dict[str, PhotoLibrary]:
if not self._libraries:
try:
url = ('%s/zones/list' %
Expand Down Expand Up @@ -518,7 +518,7 @@ def __init__(self, service, master_record, asset_record):
self._master_record = master_record
self._asset_record = asset_record

self._versions: Optional[dict[str, dict[str, Any]]] = None
self._versions: Optional[Dict[str, Dict[str, Any]]] = None

ITEM_TYPES = {
u"public.heic": u"image",
Expand Down Expand Up @@ -620,7 +620,7 @@ def item_type_extension(self):
return 'unknown'

@property
def versions(self) -> dict[str, dict[str, Any]]:
def versions(self) -> Dict[str, Dict[str, Any]]:
if not self._versions:
self._versions = {}
if self.item_type == "movie":
Expand Down

0 comments on commit 1487305

Please sign in to comment.