コード例 #1
0
    def test_content(self):
        """Test content based guess from ttkit"""
        with open(TEST_PO, 'rb') as handle:
            data = handle.read()

        handle = BytesIO(data)
        store = AutoFormat.parse(handle)
        self.assertIsInstance(store, AutoFormat)
        self.assertIsInstance(store.store, pofile)
コード例 #2
0
ファイル: dictionary.py プロジェクト: Proboss049/weblate
    def upload(self, request, project, language, fileobj, method):
        """Handle dictionary upload."""
        from weblate.trans.models.change import Change
        store = AutoFormat.parse(fileobj)

        ret = 0

        # process all units
        for dummy, unit in store.iterate_merge(False):
            source = unit.get_source()
            target = unit.get_target()

            # Ignore too long words
            if len(source) > 190 or len(target) > 190:
                continue

            # Get object
            try:
                word, created = self.get_or_create(
                    project=project,
                    language=language,
                    source=source,
                    defaults={
                        'target': target,
                    },
                )
            except Dictionary.MultipleObjectsReturned:
                word = self.filter(
                    project=project,
                    language=language,
                    source=source
                )[0]
                created = False

            # Already existing entry found
            if not created:
                # Same as current -> ignore
                if target == word.target:
                    continue
                if method == 'add':
                    # Add word
                    word = self.create(
                        user=request.user,
                        action=Change.ACTION_DICTIONARY_UPLOAD,
                        project=project,
                        language=language,
                        source=source,
                        target=target
                    )
                elif method == 'overwrite':
                    # Update word
                    word.target = target
                    word.save()

            ret += 1

        return ret
コード例 #3
0
ファイル: tests_formats.py プロジェクト: daleathan/weblate
    def test_content(self):
        """Test content based guess from ttkit"""
        with open(TEST_PO, 'rb') as handle:
            data = handle.read()

        handle = BytesIO(data)
        store = AutoFormat.parse(handle)
        self.assertIsInstance(store, AutoFormat)
        self.assertIsInstance(store.store, pofile)
コード例 #4
0
 def single_test(self, filename, fileclass):
     with open(filename, 'rb') as handle:
         store = AutoFormat.parse(handle)
         self.assertIsInstance(store, fileclass)
     self.assertEqual(fileclass, detect_filename(filename))
コード例 #5
0
ファイル: tests_formats.py プロジェクト: daleathan/weblate
 def single_test(self, filename, fileclass):
     with open(filename, 'rb') as handle:
         store = AutoFormat.parse(handle)
         self.assertIsInstance(store, fileclass)
     self.assertEqual(fileclass, detect_filename(filename))