Esempio n. 1
0
def test_bytesio(parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    b = BytesIO()
    plistlib.dump(pl, b, use_builtin_types=use_builtin_types)
    pl2 = plistlib.load(BytesIO(b.getvalue()),
                        use_builtin_types=use_builtin_types)
    assert pl == pl2
Esempio n. 2
0
def cleanupContentsList(glyphDirPath, doWarning=True):
    contentsFilePath = os.path.join(glyphDirPath, kContentsName)
    # maps glyph names to files.

    with open(contentsFilePath, 'r', encoding='utf-8') as fp:
        contentsDict = plistlib.load(fp)

    fileDict = {}
    fileList = os.listdir(glyphDirPath)
    for fileName in fileList:
        fileDict[fileName] = 1
    changed = 0

    # now update and write the processed processedGlyphDirPath
    # contents.plist file.
    itemList = list(contentsDict.items())
    for glyphName, fileName in itemList:
        if fileName not in fileDict:
            del contentsDict[glyphName]
            changed = 1
            if doWarning:
                print("Removing contents.plist entry where glif was missing: "
                      "%s, %s, %s" % (glyphName, fileName, glyphDirPath))

    if changed:
        with open(contentsFilePath, 'wb') as fp:
            plistlib.dump(contentsDict, fp)
Esempio n. 3
0
def test_bytesio(parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    b = BytesIO()
    plistlib.dump(pl, b, use_builtin_types=use_builtin_types)
    pl2 = plistlib.load(
        BytesIO(b.getvalue()), use_builtin_types=use_builtin_types
    )
    assert pl == pl2
Esempio n. 4
0
def test_keys_no_string():
    pl = {42: "aNumber"}

    with pytest.raises(TypeError):
        plistlib.dumps(pl)

    b = BytesIO()
    with pytest.raises(TypeError):
        plistlib.dump(pl, b)
Esempio n. 5
0
def test_keys_no_string():
    pl = {42: "aNumber"}

    with pytest.raises(TypeError):
        plistlib.dumps(pl)

    b = BytesIO()
    with pytest.raises(TypeError):
        plistlib.dump(pl, b)
Esempio n. 6
0
def ufo_path(tmp_path):
    ufodir = tmp_path / "TestFont.ufo"
    ufodir.mkdir()
    with (ufodir / "metainfo.plist").open("wb") as f:
        plistlib.dump({"creator": "pytest", "formatVersion": 3}, f)
    (ufodir / "glyphs").mkdir()
    with (ufodir / "layercontents.plist").open("wb") as f:
        plistlib.dump([("public.default", "glyphs")], f)
    return ufodir
Esempio n. 7
0
def writePlist(value, path_or_file):
    did_open = False
    if isinstance(path_or_file, str):
        path_or_file = open(path_or_file, "wb")
        did_open = True
    try:
        dump(value, path_or_file, use_builtin_types=False)
    finally:
        if did_open:
            path_or_file.close()
Esempio n. 8
0
def test_skipkeys():
    pl = {42: "aNumber", "snake": "aWord"}

    data = plistlib.dumps(pl, skipkeys=True, sort_keys=False)

    pl2 = plistlib.loads(data)
    assert pl2 == {"snake": "aWord"}

    fp = BytesIO()
    plistlib.dump(pl, fp, skipkeys=True, sort_keys=False)
    data = fp.getvalue()
    pl2 = plistlib.loads(fp.getvalue())
    assert pl2 == {"snake": "aWord"}
Esempio n. 9
0
def test_skipkeys():
    pl = {42: "aNumber", "snake": "aWord"}

    data = plistlib.dumps(pl, skipkeys=True, sort_keys=False)

    pl2 = plistlib.loads(data)
    assert pl2 == {"snake": "aWord"}

    fp = BytesIO()
    plistlib.dump(pl, fp, skipkeys=True, sort_keys=False)
    data = fp.getvalue()
    pl2 = plistlib.loads(fp.getvalue())
    assert pl2 == {"snake": "aWord"}
Esempio n. 10
0
def test_io(tmpdir, parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    testpath = tmpdir / "test.plist"
    with testpath.open("wb") as fp:
        plistlib.dump(pl, fp, use_builtin_types=use_builtin_types)

    with testpath.open("rb") as fp:
        pl2 = plistlib.load(fp, use_builtin_types=use_builtin_types)

    assert pl == pl2

    with pytest.raises(AttributeError):
        plistlib.dump(pl, "filename")

    with pytest.raises(AttributeError):
        plistlib.load("filename")
Esempio n. 11
0
def test_io(tmpdir, parametrized_pl):
    pl, use_builtin_types = parametrized_pl
    testpath = tmpdir / "test.plist"
    with testpath.open("wb") as fp:
        plistlib.dump(pl, fp, use_builtin_types=use_builtin_types)

    with testpath.open("rb") as fp:
        pl2 = plistlib.load(fp, use_builtin_types=use_builtin_types)

    assert pl == pl2

    with pytest.raises(AttributeError):
        plistlib.dump(pl, "filename")

    with pytest.raises(AttributeError):
        plistlib.load("filename")
Esempio n. 12
0
def test_keysort_bytesio(sort_keys):
    pl = collections.OrderedDict()
    pl["b"] = 1
    pl["a"] = 2
    pl["c"] = 3

    b = BytesIO()

    plistlib.dump(pl, b, sort_keys=sort_keys)
    pl2 = plistlib.load(BytesIO(b.getvalue()),
                        dict_type=collections.OrderedDict)

    assert dict(pl) == dict(pl2)
    if sort_keys:
        assert list(pl2.keys()) == ["a", "b", "c"]
    else:
        assert list(pl2.keys()) == ["b", "a", "c"]
Esempio n. 13
0
def test_keysort_bytesio(sort_keys):
    pl = collections.OrderedDict()
    pl["b"] = 1
    pl["a"] = 2
    pl["c"] = 3

    b = BytesIO()

    plistlib.dump(pl, b, sort_keys=sort_keys)
    pl2 = plistlib.load(
        BytesIO(b.getvalue()), dict_type=collections.OrderedDict
    )

    assert dict(pl) == dict(pl2)
    if sort_keys:
        assert list(pl2.keys()) == ["a", "b", "c"]
    else:
        assert list(pl2.keys()) == ["b", "a", "c"]