当前位置: 首页>>代码示例>>Python>>正文


Python factory.getclass函数代码示例

本文整理汇总了Python中translate.storage.factory.getclass函数的典型用法代码示例。如果您正苦于以下问题:Python getclass函数的具体用法?Python getclass怎么用?Python getclass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getclass函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_ts_plurals

def test_update_ts_plurals(store_po, test_fs):
    with test_fs.open(['data', 'ts', 'add_plurals.ts']) as f:
        file_store = getclass(f)(f.read())
    store_po.update(file_store)
    assert store_po.units[0].hasplural()

    with test_fs.open(['data', 'ts', 'update_plurals.ts']) as f:
        file_store = getclass(f)(f.read())
    store_po.update(file_store)
    assert store_po.units[0].hasplural()
开发者ID:AshishNamdev,项目名称:pootle,代码行数:10,代码来源:store.py

示例2: test_store_po_serializer

def test_store_po_serializer(test_fs, store_po):

    with test_fs.open("data/po/complex.po") as test_file:
        test_string = test_file.read()
        ttk_po = getclass(test_file)(test_string)

    store_po.update(store_po.deserialize(test_string))
    store_io = io.BytesIO(store_po.serialize())
    store_ttk = getclass(store_io)(store_io.read())
    assert len(store_ttk.units) == len(ttk_po.units)
开发者ID:AshishNamdev,项目名称:pootle,代码行数:10,代码来源:store.py

示例3: _getclass

 def _getclass(self, obj):
     try:
         return getclass(obj)
     except ValueError:
         raise ValueError(
             "Unable to find conversion class for Store '%s'"
             % self.store.name)
开发者ID:ainslied,项目名称:pootle,代码行数:7,代码来源:syncer.py

示例4: import_file

def import_file(file):
    f = getclass(file)(file.read())
    header = f.parseheader()
    pootle_path = header.get("X-Pootle-Path")
    if not pootle_path:
        raise ValueError(_("File %r missing X-Pootle-Path header\n") % (file.name))

    rev = header.get("X-Pootle-Revision")
    if not rev or not rev.isdigit():
        raise ValueError(
            _("File %r missing or invalid X-Pootle-Revision header\n") % (file.name)
        )
    rev = int(rev)

    try:
        store, created = Store.objects.get_or_create(pootle_path=pootle_path)
        if rev < store.get_max_unit_revision():
            # TODO we could potentially check at the unit level and only reject
            # units older than most recent. But that's in store.update().
            raise ValueError(
                _("File %r was rejected because its X-Pootle-Revision is too old.")
                % (file.name)
            )
    except Exception as e:
        raise ValueError(
            _("Could not create %r. Missing Project/Language? (%s)")
            % (file.name, e)
        )

    store.update(overwrite=True, store=f)
开发者ID:OpenSource-ECom,项目名称:pootle,代码行数:30,代码来源:utils.py

示例5: load_file

 def load_file(self, filename):
     cls = factory.getclass(filename)
     self.store = cls.parsefile(filename)
     self.index = int(self.config.phrase_index)
     self.config.register(lambda: self.index, "phrase_index")
     self.scroll(None, 0)
     self.config.file = filename
开发者ID:kitbs,项目名称:open-tran,代码行数:7,代码来源:open-tran.py

示例6: import_file

def import_file(file, user=None):
    f = getclass(file)(file.read())
    if not hasattr(f, "parseheader"):
        raise UnsupportedFiletypeError(_("Unsupported filetype '%s', only PO "
                                         "files are supported at this time\n")
                                       % file.name)
    header = f.parseheader()
    pootle_path = header.get("X-Pootle-Path")
    if not pootle_path:
        raise MissingPootlePathError(_("File '%s' missing X-Pootle-Path "
                                       "header\n") % file.name)

    rev = header.get("X-Pootle-Revision")
    if not rev or not rev.isdigit():
        raise MissingPootleRevError(_("File '%s' missing or invalid "
                                      "X-Pootle-Revision header\n")
                                    % file.name)
    rev = int(rev)

    try:
        store, created = Store.objects.get_or_create(pootle_path=pootle_path)
    except Exception as e:
        raise FileImportError(_("Could not create '%s'. Missing "
                                "Project/Language? (%s)") % (file.name, e))

    try:
        store.update(overwrite=True, store=f, user=user,
                     submission_type=SubmissionTypes.UPLOAD)
    except Exception as e:
        # This should not happen!
        logger.error("Error importing file: %s" % str(e))
        raise FileImportError(_("There was an error uploading your file"))
开发者ID:fabada,项目名称:pootle,代码行数:32,代码来源:utils.py

示例7: pytest_generate_tests

def pytest_generate_tests(metafunc):
    import pytest_pootle

    if "terminology_units" in metafunc.fixturenames:
        term_file = os.path.join(os.path.dirname(pytest_pootle.__file__), *("data", "po", "terminology.po"))
        with open(term_file) as f:
            _terms = [x.source for x in getclass(f)(f.read()).units[1:]]
        metafunc.parametrize("terminology_units", _terms)
开发者ID:unho,项目名称:pootle,代码行数:8,代码来源:pootle_terminology.py

示例8: test_store_po_deserializer

def test_store_po_deserializer(test_fs, store_po):

    with test_fs.open("data/po/complex.po") as test_file:
        test_string = test_file.read()
        ttk_po = getclass(test_file)(test_string)

    store_po.update(store_po.deserialize(test_string))
    assert len(ttk_po.units) - 1 == store_po.units.count()
开发者ID:AshishNamdev,项目名称:pootle,代码行数:8,代码来源:store.py

示例9: test_update_with_non_ascii

def test_update_with_non_ascii(store0, test_fs):
    store0.state = PARSED
    orig_units = store0.units.count()
    with test_fs.open(['data', 'po', 'tutorial', 'en',
                       'tutorial_non_ascii.po']) as f:
        store = getclass(f)(f.read())
    store0.update(store)
    assert store0.units[orig_units].target == "Hèḽḽě, ŵôrḽḓ"
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:8,代码来源:store.py

示例10: test_update_from_ts

def test_update_from_ts(store0, test_fs):
    store0.parsed = True
    orig_units = store0.units.count()
    with test_fs.open(['data', 'ts', 'tutorial', 'en', 'tutorial.ts']) as f:
        store = getclass(f)(f.read())
    store0.update(store)
    assert(not store0.units[orig_units].hasplural())
    assert(store0.units[orig_units + 1].hasplural())
开发者ID:SafaAlfulaij,项目名称:pootle,代码行数:8,代码来源:store.py

示例11: test_update_with_non_ascii

def test_update_with_non_ascii(en_tutorial_po, test_fs):
    # Parse store
    en_tutorial_po.update_from_disk()
    tp = en_tutorial_po.translation_project
    with test_fs.open(['data', 'po', tp.real_path,
                       'tutorial_non_ascii.po']) as f:
        store = getclass(f)(f.read())
    en_tutorial_po.update(store)
    assert en_tutorial_po.units[0].target == "Hèllö, wôrld"
开发者ID:AshishNamdev,项目名称:pootle,代码行数:9,代码来源:store.py

示例12: test_update_from_ts

def test_update_from_ts(en_tutorial_po, test_fs):
    # Parse store
    en_tutorial_po.update_from_disk()
    tp = en_tutorial_po.translation_project
    with test_fs.open(['data', 'ts', tp.real_path, 'tutorial.ts']) as f:
        store = getclass(f)(f.read())
    en_tutorial_po.update(store)

    assert(not en_tutorial_po.units[1].hasplural())
    assert(en_tutorial_po.units[2].hasplural())
开发者ID:AshishNamdev,项目名称:pootle,代码行数:10,代码来源:store.py

示例13: _update_from_upload_file

def _update_from_upload_file(tutorial, update_file,
                             content_type="text/x-gettext-translation",
                             user=None, submission_type=None):
    with open(update_file, "r") as f:
        upload = SimpleUploadedFile(os.path.basename(update_file),
                                    f.read(),
                                    content_type)
    test_store = getclass(upload)(upload.read())
    tutorial.update(overwrite=False, only_newer=False)
    tutorial.update(overwrite=True, store=test_store,
                    user=user, submission_type=submission_type)
开发者ID:egr-kittner,项目名称:pootle,代码行数:11,代码来源:store.py

示例14: import_file

def import_file(file, prj, lang=None):
    f = getclass(file)(file.read())
    if not hasattr(f, "parseheader"):
        raise Exception("Format is not supported")

    header = f.parseheader()
    if not lang:
        lang = header['Language']
    if not lang:
        raise Exception("Language not set")
    for unit in f.getunits():
        extract_phrase(prj,unit,lang,f.getheaderplural()[1])
开发者ID:nnseva,项目名称:cloud-i18n,代码行数:12,代码来源:import_export.py

示例15: moz_env

def moz_env(post_db_setup, _django_cursor_wrapper, ios_pootle_file):

    from django.conf import settings

    from pytest_pootle.factories import (
        ProjectDBFactory, StoreDBFactory,
        TranslationProjectFactory)

    from pootle_fs.models import ProjectFS
    from pootle_language.models import Language

    with _django_cursor_wrapper:
        ios_project = ProjectDBFactory(
            source_language=Language.objects.get(code="en"),
            code="ios",
            localfiletype="xliff")
        ios_tp = TranslationProjectFactory(
            project=ios_project,
            language=Language.objects.get(code="language0"))
        ios_store = StoreDBFactory(
            parent=ios_tp.directory,
            translation_project=ios_tp,
            name="firefox-ios.xliff")
        ios_bytes = io.BytesIO(ios_pootle_file.encode("utf8"))
        ios_store.update(
            getclass(ios_bytes)(ios_bytes.read()))

        fs_dir = tempfile.mkdtemp()
        settings.POOTLE_FS_PATH = fs_dir

        repo_path = os.path.join(fs_dir, "__moz_ios_src__")
        Repo.init(repo_path, bare=True)

        with tmp_git(repo_path) as (tmp_repo_path, tmp_repo):
            config_file = os.path.join(tmp_repo_path, ".pootle.ini")
            with open(config_file, "w") as ini:
                config = (
                    "[default]\n"
                    "serializers = ios\n"
                    "deserializers = ios\n"
                    "translation_path = <lang>/<filename>.xliff")
                ini.write(config)
            tmp_repo.index.add([".pootle.ini"])
            tmp_repo.index.commit("Add Pootle configuration")
            tmp_repo.remotes.origin.push("master:master")

        ios_fs = ProjectFS.objects.create(
            project=ios_project,
            fs_type="git",
            url=repo_path)
        ios_plugin = ios_fs.plugin
        ios_plugin.add_translations()
开发者ID:phlax,项目名称:moz_pootle_fs,代码行数:52,代码来源:moz.py


注:本文中的translate.storage.factory.getclass函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。