Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 1 addition & 74 deletions src/icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _intern(username: str, password: str) -> None:


def skip_created_generator(
name: str, formatted: str
name: str, formatted: str | None
) -> datetime.datetime | datetime.timedelta | None:
"""Converts ISO dates to datetime and interval in days to timeinterval using supplied name as part of raised exception in case of the error"""
if formatted is None:
Expand Down Expand Up @@ -746,67 +746,6 @@ def delete_photo_dry_run(
)


# RetrierT = TypeVar("RetrierT")


# def retrier(
# func: Callable[[], RetrierT], error_handler: Callable[[Exception, int], None]
# ) -> RetrierT:
# """Run main func and retry helper if receive session error"""
# attempts = 0
# while True:
# try:
# return func()
# except Exception as ex:
# attempts += 1
# error_handler(ex, attempts)
# if attempts > constants.MAX_RETRIES:
# raise


# def session_error_handle_builder(
# logger: Logger, icloud: PyiCloudService, ex: Exception, attempt: int
# ) -> None:
# """Handles session errors in the PhotoAlbum photos iterator"""
# if "Invalid global session" in str(ex):
# if constants.MAX_RETRIES == 0:
# logger.error("Session error, re-authenticating...")
# if attempt > constants.MAX_RETRIES:
# logger.error("iCloud re-authentication failed. Please try again later.")
# raise ex
# logger.error("Session error, re-authenticating...")
# if attempt > 1:
# # If the first re-authentication attempt failed,
# # start waiting a few seconds before retrying in case
# # there are some issues with the Apple servers
# time.sleep(constants.WAIT_SECONDS * attempt)
# icloud.authenticate()


# def internal_error_handle_builder(logger: logging.Logger, ex: Exception, attempt: int) -> None:
# """Handles session errors in the PhotoAlbum photos iterator"""
# if "INTERNAL_ERROR" in str(ex):
# if attempt > constants.MAX_RETRIES:
# logger.error("Internal Error at Apple.")
# raise ex
# logger.error("Internal Error at Apple, retrying...")
# # start waiting a few seconds before retrying in case
# # there are some issues with the Apple servers
# time.sleep(constants.WAIT_SECONDS * attempt)


def compose_handlers(
handlers: Sequence[Callable[[Exception, int], None]],
) -> Callable[[Exception, int], None]:
"""Compose multiple error handlers"""

def composed(ex: Exception, retries: int) -> None:
for handler in handlers:
handler(ex, retries)

return composed


def dump_responses(dumper: Callable[[Any], None], responses: List[Mapping[str, Any]]) -> None:
# dump captured responses
for entry in responses:
Expand Down Expand Up @@ -927,15 +866,6 @@ def append_response(captured: List[Mapping[str, Any]], response: Mapping[str, An

logger.debug(f"Looking up all {photo_video_phrase}{album_phrase}...")

# session_exception_handler = partial(
# session_error_handle_builder, logger, icloud
# )
# internal_error_handler = partial(internal_error_handle_builder, logger)

# error_handler = compose_handlers(
# [session_exception_handler, internal_error_handler]
# )

albums: Iterable[PhotoAlbum] = (
list(map_(library_object.albums.__getitem__, user_config.albums))
if len(user_config.albums) > 0
Expand All @@ -950,9 +880,6 @@ def sum_(inp: Iterable[int]) -> int:

photos_count: int | None = compose(sum_, album_lengths)(albums)
for photo_album in albums:
# errors are handled at top level now. TODO remove all error handling
# photos.exception_handler = error_handler

photos_enumerator: Iterable[PhotoAsset] = photo_album

# Optional: Only download the x most recent photos.
Expand Down
2 changes: 1 addition & 1 deletion src/icloudpd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def log_level(inp: str) -> LogLevel:


def parse_timestamp_or_timedelta_tz_error(
formatted: str,
formatted: str | None,
) -> datetime.datetime | datetime.timedelta | None:
"""Convert ISO dates to datetime with tz and interval in days to time interval. Raise exception in case of error."""
if formatted is None:
Expand Down
2 changes: 1 addition & 1 deletion src/icloudpd/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IPDLogger(logging.Logger):

def __init__(self, name: str, level: int = INFO):
logging.Logger.__init__(self, name, level)
self.tqdm = None
self.tqdm: Any = None

# If tdqm progress bar is not set, we just write regular log messages
def set_tqdm(self, tdqm: Any) -> None:
Expand Down
24 changes: 12 additions & 12 deletions src/pyicloud_ipd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,23 +834,23 @@ def devices(self) -> Sequence[AppleDevice]:
))

@property
def account(self): # type: ignore
service_root = self._gget_webservice_url("account") # type: ignore
return AccountService( # type: ignore
def account(self): # type: ignore
service_root = self._get_webservice_url("account")
return AccountService( # type: ignore
service_root,
self.session,
self.params
)

@property
def iphone(self): # type: ignore
def iphone(self): # type: ignore
return self.devices[0]

@property
def files(self): # type: ignore
def files(self): # type: ignore
if not hasattr(self, '_files'):
service_root = self._get_webservice_url("ubiquity")
self._files = UbiquityService( # type: ignore
self._files = UbiquityService( # type: ignore
service_root,
self.session,
self.params
Expand All @@ -874,19 +874,19 @@ def photos(self) -> PhotosService:
return self._photos

@property
def calendar(self): # type: ignore
def calendar(self): # type: ignore
service_root = self._get_webservice_url("calendar")
return CalendarService(service_root, self.session, self.params)# type: ignore
return CalendarService(service_root, self.session, self.params) # type: ignore

@property
def contacts(self): # type: ignore
def contacts(self): # type: ignore
service_root = self._get_webservice_url("contacts")
return ContactsService(service_root, self.session, self.params)# type: ignore
return ContactsService(service_root, self.session, self.params) # type: ignore

@property
def reminders(self): # type: ignore
def reminders(self): # type: ignore
service_root = self._get_webservice_url("reminders")
return RemindersService(service_root, self.session, self.params)# type: ignore
return RemindersService(service_root, self.session, self.params) # type: ignore

def __unicode__(self) -> str:
return 'iCloud API: %s' % self.apple_id
Expand Down
16 changes: 1 addition & 15 deletions src/pyicloud_ipd/services/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ def __init__(self, service:PhotosService, service_endpoint: str, name: str, list
self.offset = 0
self.query_filter = query_filter
self.page_size = page_size
self.exception_handler: Optional[Callable[[Exception, int], None]] = None

if zone_id:
self._zone_id: Dict[str, Any] = zone_id
Expand Down Expand Up @@ -376,22 +375,9 @@ def photos_request(self) -> Response:

@property
def photos(self) -> Generator["PhotoAsset", Any, None]:
exception_retries = 0

while(True):
try:
request = self.photos_request()
except PyiCloudAPIResponseException as ex:
if self.exception_handler:
exception_retries += 1
self.exception_handler(ex, exception_retries)
if exception_retries > 5:
raise
continue
else:
raise

exception_retries = 0
request = self.photos_request()

# url = ('%s/records/query?' % self.service_endpoint) + \
# urlencode(self.service.params)
Expand Down
Loading