• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python factory.getclass函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_wrap_store_fs_pull_submission_type

def test_wrap_store_fs_pull_submission_type(store_fs_file_store):
    fs_file = store_fs_file_store
    fs_file.push()
    with open(fs_file.file_path, "r+") as target:
        ttk = getclass(target)(target.read())
        target.seek(0)
        ttk.units[1].target = "BAR"
        target.write(str(ttk))
        target.truncate()
    fs_file.pull()
    assert (
        fs_file.store.units[0].submission_set.latest().type
        == SubmissionTypes.SYSTEM)
开发者ID:ggalancs,项目名称:pootle,代码行数:13,代码来源:files.py


示例17: _update_from_upload_file

def _update_from_upload_file(store, 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)
    if store.state < PARSED:
        store.update(store.file.store)
    test_store = getclass(upload)(upload.read())
    store_revision = parse_pootle_revision(test_store)
    store.update(test_store, store_revision=store_revision,
                 user=user, submission_type=submission_type)
开发者ID:AshishNamdev,项目名称:pootle,代码行数:13,代码来源:store.py


示例18: test_unit_ts_plurals

def test_unit_ts_plurals(store_po, test_fs):
    with test_fs.open(['data', 'ts', 'add_plurals.ts']) as f:
        file_store = getclass(f)(f.read())
    unit = Unit(store=store_po)
    unit_ts = file_store.units[0]
    unit.update(unit_ts)
    assert unit.hasplural()
    unit.save()
    unit = Unit.objects.get(id=unit.id)
    assert unit.hasplural()
    unit.save()
    unit = Unit.objects.get(id=unit.id)
    assert unit.hasplural()
开发者ID:claudep,项目名称:pootle,代码行数:13,代码来源:unit.py


示例19: deserialize

 def deserialize(self, create=False):
     if not create and not self.file_exists:
         return
     if self.file_exists:
         with open(self.file_path) as f:
             f = AttributeProxy(f)
             f.location_root = self.store_fs.project.local_fs_path
             store_file = (
                 self.store.syncer.file_class(f)
                 if self.store and self.store.syncer.file_class
                 else getclass(f)(f.read()))
         return store_file
     if self.store_exists:
         return self.store.deserialize(self.store.serialize())
开发者ID:claudep,项目名称:pootle,代码行数:14,代码来源:files.py


示例20: create_store

def create_store(pootle_path=None, store_revision=None, units=None):
    _units = []
    for src, target in units or []:
        _units.append(STRING_UNIT % {"src": src, "target": target})
    units = "\n\n".join(_units)
    x_pootle_headers = ""
    if pootle_path and store_revision:
        x_pootle_headers = (STRING_POOTLE_HEADERS.strip()
                            % {"pootle_path": pootle_path,
                               "revision": store_revision})
    string_store = STRING_STORE % {"x_pootle_headers": x_pootle_headers,
                                   "units": units}
    io_store = io.BytesIO(string_store.encode())
    return getclass(io_store)(io_store.read())
开发者ID:yar0d,项目名称:pootle,代码行数:14,代码来源:utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python factory.getobject函数代码示例发布时间:2022-05-27
下一篇:
Python dtd.unquotefromdtd函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap