diff --git a/src/pyicloud_ipd/base.py b/src/pyicloud_ipd/base.py index e53f6f502..2bb8bb2f6 100644 --- a/src/pyicloud_ipd/base.py +++ b/src/pyicloud_ipd/base.py @@ -9,21 +9,21 @@ import http.cookiejar as cookielib import getpass -from pyicloud_ipd.exceptions import ( - PyiCloudConnectionException, +from pyicloud.exceptions import ( PyiCloudFailedLoginException, - PyiCloudAPIResponseError, - PyiCloud2SARequiredError, - PyiCloudServiceNotActivatedErrror + PyiCloudAPIResponseException, + PyiCloud2SARequiredException, + PyiCloudServiceNotActivatedException, ) -from pyicloud_ipd.services import ( +from pyicloud.services import ( FindMyiPhoneServiceManager, CalendarService, UbiquityService, ContactsService, RemindersService, PhotosService, - AccountService + AccountService, + DriveService, ) from pyicloud_ipd.utils import get_password_from_keyring diff --git a/src/pyicloud_ipd/exceptions.py b/src/pyicloud_ipd/exceptions.py index ef9c91729..80b7a6919 100644 --- a/src/pyicloud_ipd/exceptions.py +++ b/src/pyicloud_ipd/exceptions.py @@ -1,39 +1,50 @@ - -class PyiCloudException(Exception): - pass +"""Library exceptions.""" -class PyiCloudConnectionException(PyiCloudException): - pass - -class PyiCloudNoDevicesException(PyiCloudException): +class PyiCloudException(Exception): + """Generic iCloud exception.""" pass -class PyiCloudAPIResponseError(PyiCloudException): - def __init__(self, reason, code): +# API +class PyiCloudAPIResponseException(PyiCloudException): + """iCloud response exception.""" + def __init__(self, reason, code=None, retry=False): self.reason = reason self.code = code - message = reason + message = reason or "" if code: message += " (%s)" % code + if retry: + message += ". Retrying ..." + + super().__init__(message) - super(PyiCloudAPIResponseError, self).__init__(message) +class PyiCloudServiceNotActivatedException(PyiCloudAPIResponseException): + """iCloud service not activated exception.""" + pass + +# Login class PyiCloudFailedLoginException(PyiCloudException): + """iCloud failed login exception.""" pass -class PyiCloud2SARequiredError(PyiCloudException): - def __init__(self, url): - message = "Two-step authentication required for %s" % url - super(PyiCloud2SARequiredError, self).__init__(message) +class PyiCloud2SARequiredException(PyiCloudException): + """iCloud 2SA required exception.""" + def __init__(self, apple_id): + message = "Two-step authentication required for account: %s" % apple_id + super().__init__(message) -class NoStoredPasswordAvailable(PyiCloudException): +class PyiCloudNoStoredPasswordAvailableException(PyiCloudException): + """iCloud no stored password exception.""" pass -class PyiCloudServiceNotActivatedErrror(PyiCloudAPIResponseError): +# Webservice specific +class PyiCloudNoDevicesException(PyiCloudException): + """iCloud no device exception.""" pass