# Path: resources/lib/PhoneBooks/pyicloud/exceptions.py
# class PyiCloudAPIResponseError(PyiCloudException):
#     def __init__(self, reason, code):
#         self.reason = reason
#         self.code = code
#         message = reason
#         if code:
#             message += " (%s)" % code
# 
#         super(PyiCloudAPIResponseError, self).__init__(message)
# 
# class PyiCloudBinaryFeedParseError(Exception):
#     pass
# 
# class PyiCloudPhotoLibraryNotActivatedErrror(Exception):
#     pass


import sys
import json
import urllib
from datetime import datetime
from base64 import b64decode
from bitstring import ConstBitStream
from ..exceptions import (
    PyiCloudAPIResponseError,
    PyiCloudBinaryFeedParseError,
    PyiCloudPhotoLibraryNotActivatedErrror
)



class PhotosService(object):
    """ The 'Photos' iCloud service."""

    def __init__(self, service_root, session, params):
        self.session = session
        self.params = dict(params)

        self.prepostfetch = 200

        self._service_root = service_root
        self._service_endpoint = '%s/ph' % self._service_root

        try:
            request = self.session.get(
                '%s/startup' % self._service_endpoint,
                params=self.params
            )
            response = request.json()
            self.params.update({
                'syncToken': response['syncToken'],
                'clientInstanceId': self.params.pop('clientId')
            })
        except PyiCloudAPIResponseError as error:
            if error.code == 402:

# Path: resources/lib/PhoneBooks/pyicloud/exceptions.py
# class PyiCloudAPIResponseError(PyiCloudException):
#     def __init__(self, reason, code):
#         self.reason = reason
#         self.code = code
#         message = reason
#         if code:
#             message += " (%s)" % code
# 
#         super(PyiCloudAPIResponseError, self).__init__(message)
# 
# class PyiCloudBinaryFeedParseError(Exception):
#     pass
# 
# class PyiCloudPhotoLibraryNotActivatedErrror(Exception):
#     pass


# Path: resources/lib/PhoneBooks/pyicloud/services/photos.py
import sys
import json
import urllib
from datetime import datetime
from base64 import b64decode
from bitstring import ConstBitStream
from ..exceptions import (
    PyiCloudAPIResponseError,
    PyiCloudBinaryFeedParseError,
    PyiCloudPhotoLibraryNotActivatedErrror
)




class PhotosService(object):
    """ The 'Photos' iCloud service."""

    def __init__(self, service_root, session, params):
        self.session = session
        self.params = dict(params)

        self.prepostfetch = 200

        self._service_root = service_root
        self._service_endpoint = '%s/ph' % self._service_root

        try:
            request = self.session.get(
                '%s/startup' % self._service_endpoint,
                params=self.params
            )
            response = request.json()
            self.params.update({
                'syncToken': response['syncToken'],
                'clientInstanceId': self.params.pop('clientId')
            })
        except PyiCloudAPIResponseError as error:
            if error.code == 402:

                raise PyiCloudPhotoLibraryNotActivatedErrror(