# Path: onedrived/od_api_helper.py
# def item_request_call(repo, request_func, *args, **kwargs):
#     while True:
#         try:
#             return request_func(*args, **kwargs)
#         except onedrivesdk.error.OneDriveError as e:
#             logging.error('Encountered API Error: %s.', e)
#             if e.code == onedrivesdk.error.ErrorCode.ActivityLimitReached:
#                 time.sleep(THROTTLE_PAUSE_SEC)
#             elif e.code == onedrivesdk.error.ErrorCode.Unauthenticated:
#                 repo.authenticator.refresh_session(repo.account_id)
#             else:
#                 raise e
#         except requests.ConnectionError as e:
#             logging.error('Encountered connection error: %s. Retry in %d sec.', e, THROTTLE_PAUSE_SEC)
#             time.sleep(THROTTLE_PAUSE_SEC)


import logging
import os
import onedrivesdk
import onedrivesdk.error
from . import update_mtime
from ..od_api_helper import item_request_call
        if curr_part == total_part:
            logging.debug('All %d parts of file "%s" have been uploaded.', total_part, self.local_abspath)
        else:
            logging.debug('Uploading file "%s": Part %d / %d.', self.local_abspath, curr_part + 1, total_part)

    def handle(self):
        logging.info('Uploading file "%s" to OneDrive.', self.local_abspath)
        occupy_task = self.task_pool.occupy_path(self.local_abspath, self)
        if occupy_task is not self:
            logging.warning('Cannot upload "%s" because %s.', self.local_abspath,
                            "path is blacklisted" if occupy_task is None else str(occupy_task) + ' is in progress')
            return False
        try:
            item_stat = os.stat(self.local_abspath)
            if item_stat.st_size < self.PUT_FILE_SIZE_THRESHOLD_BYTES:
                item_request = self.parent_dir_request.children[self.item_name]
                returned_item = item_request_call(self.repo, item_request.upload, self.local_abspath)
                if returned_item is None:
                    logging.warning('Upload API did not return metadata of remote item for "%s". '
                                    'Make an explicit request.', self.local_abspath)
                    returned_item = item_request_call(self.repo, item_request.get)
            else:
                logging.info('Uploading large file "%s" in chunks of 10MB.', self.local_abspath)
                item_request = self.repo.authenticator.client.item(drive=self.repo.drive.id, path=self.rel_path)
                returned_item = item_request_call(self.repo, item_request.upload_async,
                                                  local_path=self.local_abspath, upload_status=self.update_progress)
                if not isinstance(returned_item, onedrivesdk.Item):
                    if hasattr(returned_item, '_prop_dict'):
                        returned_item = onedrivesdk.Item(returned_item._prop_dict)
                    else:

# Path: onedrived/od_api_helper.py
# def item_request_call(repo, request_func, *args, **kwargs):
#     while True:
#         try:
#             return request_func(*args, **kwargs)
#         except onedrivesdk.error.OneDriveError as e:
#             logging.error('Encountered API Error: %s.', e)
#             if e.code == onedrivesdk.error.ErrorCode.ActivityLimitReached:
#                 time.sleep(THROTTLE_PAUSE_SEC)
#             elif e.code == onedrivesdk.error.ErrorCode.Unauthenticated:
#                 repo.authenticator.refresh_session(repo.account_id)
#             else:
#                 raise e
#         except requests.ConnectionError as e:
#             logging.error('Encountered connection error: %s. Retry in %d sec.', e, THROTTLE_PAUSE_SEC)
#             time.sleep(THROTTLE_PAUSE_SEC)


# Path: onedrived/od_tasks/upload_file.py
import logging
import os
import onedrivesdk
import onedrivesdk.error
from . import update_mtime
from ..od_api_helper import item_request_call

        if curr_part == total_part:
            logging.debug('All %d parts of file "%s" have been uploaded.', total_part, self.local_abspath)
        else:
            logging.debug('Uploading file "%s": Part %d / %d.', self.local_abspath, curr_part + 1, total_part)

    def handle(self):
        logging.info('Uploading file "%s" to OneDrive.', self.local_abspath)
        occupy_task = self.task_pool.occupy_path(self.local_abspath, self)
        if occupy_task is not self:
            logging.warning('Cannot upload "%s" because %s.', self.local_abspath,
                            "path is blacklisted" if occupy_task is None else str(occupy_task) + ' is in progress')
            return False
        try:
            item_stat = os.stat(self.local_abspath)
            if item_stat.st_size < self.PUT_FILE_SIZE_THRESHOLD_BYTES:
                item_request = self.parent_dir_request.children[self.item_name]
                returned_item = item_request_call(self.repo, item_request.upload, self.local_abspath)
                if returned_item is None:
                    logging.warning('Upload API did not return metadata of remote item for "%s". '
                                    'Make an explicit request.', self.local_abspath)
                    returned_item = item_request_call(self.repo, item_request.get)
            else:
                logging.info('Uploading large file "%s" in chunks of 10MB.', self.local_abspath)
                item_request = self.repo.authenticator.client.item(drive=self.repo.drive.id, path=self.rel_path)
                returned_item = item_request_call(self.repo, item_request.upload_async,
                                                  local_path=self.local_abspath, upload_status=self.update_progress)
                if not isinstance(returned_item, onedrivesdk.Item):
                    if hasattr(returned_item, '_prop_dict'):
                        returned_item = onedrivesdk.Item(returned_item._prop_dict)
                    else:

                        returned_item = item_request_call(self.repo, item_request.get)