code: def sync(self, resync=False):
          
          if resync:
              self._clear()
  
          while True:
              logger.debug('Starting reminder sync: %s', self._reminder_version)
              changes = self._reminders_api.list()
  
              if 'task' in changes:
                  self._parseTasks(changes['task'])
  
              self._reminder_version = changes['storageVersion']
              logger.debug('Finishing sync: %s', self._reminder_version)
              history = self._reminders_api.history(self._reminder_version)
              if self._reminder_version == history['highestStorageVersion']:
                  break
  
          while True:
              logger.debug('Starting keep sync: %s', self._keep_version)
  
              labels_updated = any((i.dirty for i in self._labels.values()))
              changes = self._keep_api.changes(
                  target_version=self._keep_version,
                  nodes=[i.save() for i in self._findDirtyNodes()],
                  labels=[i.save() for i in self._labels.values()] if labels_updated else None,
              )
  
              if changes.get('forceFullResync'):
                  raise exception.ResyncRequiredException('Full resync required')
  
              if changes.get('upgradeRecommended'):
                  raise exception.UpgradeRecommendedException('Upgrade recommended')
  
              if 'userInfo' in changes:
                  self._parseUserInfo(changes['userInfo'])
  
              if 'nodes' in changes:
                  self._parseNodes(changes['nodes'])
  
              self._keep_version = changes['toVersion']
              logger.debug('Finishing sync: %s', self._keep_version)
              if not changes['truncated']:
                  break
  
          if _node.DEBUG:
              self._clean()
docs: Sync the local Keep tree with the server. If resyncing, local changes will be detroyed. Otherwise, local changes to notes, labels and reminders will be detected and synced up.
  
          Args:
              resync (bool): Whether to resync data.
  
          Raises:
              SyncException: If there is a consistency issue.