當前位置: 首頁>>代碼示例>>Python>>正文


Python AutoFormat.parse方法代碼示例

本文整理匯總了Python中weblate.trans.formats.AutoFormat.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python AutoFormat.parse方法的具體用法?Python AutoFormat.parse怎麽用?Python AutoFormat.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weblate.trans.formats.AutoFormat的用法示例。


在下文中一共展示了AutoFormat.parse方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_content

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import parse [as 別名]
    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)
開發者ID:ccfwwm,項目名稱:weblate,代碼行數:11,代碼來源:test_formats.py

示例2: upload

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import parse [as 別名]
    def upload(self, request, project, language, fileobj, method):
        '''
        Handles dictionary upload.
        '''
        from weblate.trans.models.changes 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
            word, created = self.get_or_create(
                project=project,
                language=language,
                source=source,
                defaults={
                    'target': target,
                },
            )

            # Already existing entry found
            if not created:
                # Same as current -> ignore
                if target == word.target:
                    continue
                if method == 'add':
                    # Add word
                    word = self.create(
                        request,
                        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
開發者ID:Acidburn0zzz,項目名稱:weblate,代碼行數:53,代碼來源:dictionary.py

示例3: merge_upload

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import parse [as 別名]
    def merge_upload(self, request, fileobj, overwrite, author=None,
                     merge_header=True, method='', fuzzy='',
                     merge_comments=False):
        '''
        Top level handler for file uploads.
        '''
        filecopy = fileobj.read()
        fileobj.close()

        # Strip possible UTF-8 BOM
        if filecopy[:3] == codecs.BOM_UTF8:
            filecopy = filecopy[3:]

        # Load backend file
        try:
            # First try using own loader
            store = self.subproject.file_format_cls.parse(
                StringIOMode(fileobj.name, filecopy),
                self.subproject.template_store
            )
        except Exception:
            # Fallback to automatic detection
            store = AutoFormat.parse(
                StringIOMode(fileobj.name, filecopy),
            )

        # Optionally set authorship
        if author is None:
            author = get_author_name(request.user)

        # List translations we should process
        # Filter out those who don't want automatic update, but keep ourselves
        translations = Translation.objects.filter(
            language=self.language,
            subproject__project=self.subproject.project
        ).filter(
            Q(pk=self.pk) | Q(subproject__allow_translation_propagation=True)
        )

        ret = False

        if method in ('', 'fuzzy'):
            # Do actual merge
            if self.subproject.has_template():
                # Merge on units level
                ret = self.merge_translations(
                    request,
                    store,
                    overwrite,
                    (method == 'fuzzy'),
                    fuzzy
                )
            else:
                # Merge on file level
                for translation in translations:
                    ret |= translation.merge_store(
                        request,
                        author,
                        store,
                        overwrite,
                        merge_header,
                        (method == 'fuzzy'),
                        fuzzy,
                        merge_comments=merge_comments,
                    )
        else:
            # Add as sugestions
            ret = self.merge_suggestions(request, store, fuzzy)

        return ret, store.count_units()
開發者ID:franco999,項目名稱:weblate,代碼行數:72,代碼來源:translation.py

示例4: single_test

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import parse [as 別名]
 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))
開發者ID:ccfwwm,項目名稱:weblate,代碼行數:7,代碼來源:test_formats.py

示例5: single_test

# 需要導入模塊: from weblate.trans.formats import AutoFormat [as 別名]
# 或者: from weblate.trans.formats.AutoFormat import parse [as 別名]
 def single_test(self, filename, fileclass):
     with open(filename, 'r') as handle:
         store = AutoFormat.parse(handle)
         self.assertIsInstance(store, fileclass)
開發者ID:franco999,項目名稱:weblate,代碼行數:6,代碼來源:test_formats.py


注:本文中的weblate.trans.formats.AutoFormat.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。