Exemplo n.º 1
0
    def _convert_to_common_format(self, format, bundle):
        """
        Convert the bundle to the common format.

        This is a careful and possibly fragile process that may
        raise FutureFormatDetected exception. If that happens
        then desired_format (encoded in the function itself) must be
        changed and the code reviewed for any possible changes
        required to support the more recent format.
        """
        while True:
            # Break conditions, encoded separately for clarity
            if format == self._desired_format:
                # This is our desired break condition, when format
                # becomes (or starts as) the desired format
                break
            if DocumentEvolution.is_latest(bundle):
                # This is a less desired break condition, if we
                # got here then the only possible explanation is
                # that some program started with format > desired_format
                # and the DocumentEvolution API is updated to understand
                # it but we are not. In that case let's raise an exception
                raise FutureFormatDetected(format)
            # As long as the document format is old keep upgrading it
            # step-by-step. Evolution is done in place
            DocumentEvolution.evolve_document(bundle, one_step=True)
Exemplo n.º 2
0
    def _convert_to_common_format(self, format, bundle):
        """
        Convert the bundle to the common format.

        This is a careful and possibly fragile process that may
        raise FutureFormatDetected exception. If that happens
        then desired_format (encoded in the function itself) must be
        changed and the code reviewed for any possible changes
        required to support the more recent format.
        """
        while True:
            # Break conditions, encoded separately for clarity
            if format == self._desired_format:
                # This is our desired break condition, when format
                # becomes (or starts as) the desired format
                break
            if DocumentEvolution.is_latest(bundle):
                # This is a less desired break condition, if we
                # got here then the only possible explanation is
                # that some program started with format > desired_format
                # and the DocumentEvolution API is updated to understand
                # it but we are not. In that case let's raise an exception
                raise FutureFormatDetected(format)
            # As long as the document format is old keep upgrading it
            # step-by-step. Evolution is done in place
            DocumentEvolution.evolve_document(bundle, one_step=True)
Exemplo n.º 3
0
 def test_evolved_document_is_latest_format(self):
     self.assertFalse(DocumentEvolution.is_latest(self.doc))
     DocumentEvolution.evolve_document(self.doc, one_step=True)
     self.assertTrue(DocumentEvolution.is_latest(self.doc))
Exemplo n.º 4
0
 def test_evolved_document_is_latest_format(self):
     self.assertFalse(DocumentEvolution.is_latest(self.doc))
     DocumentEvolution.evolve_document(self.doc, one_step=True)
     self.assertTrue(DocumentEvolution.is_latest(self.doc))