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


Python plistlib.FMT_XML属性代码示例

本文整理汇总了Python中plistlib.FMT_XML属性的典型用法代码示例。如果您正苦于以下问题:Python plistlib.FMT_XML属性的具体用法?Python plistlib.FMT_XML怎么用?Python plistlib.FMT_XML使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在plistlib的用法示例。


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

示例1: dumps

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def dumps(value, fmt=FMT_XML, skipkeys=False, sort_keys=True):
    if _check_py3():
        return plistlib.dumps(value, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys).decode("utf-8")
    else:
        # We avoid using writePlistToString() as that uses
        # cStringIO and fails when Unicode strings are detected
        f = StringIO()
        dump(value, f, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys)
        return f.getvalue()

###                        ###
# Binary Plist Stuff For Py2 #
###                        ###

# From the python 3 plistlib.py source:  https://github.com/python/cpython/blob/3.7/Lib/plistlib.py
# Tweaked to function on Python 2 
开发者ID:corpnewt,项目名称:USBMap,代码行数:18,代码来源:plist.py

示例2: test_xml_encodings

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def test_xml_encodings(self):
        base = TESTDATA[plistlib.FMT_XML]

        for xml_encoding, encoding, bom in [
                    (b'utf-8', 'utf-8', codecs.BOM_UTF8),
                    (b'utf-16', 'utf-16-le', codecs.BOM_UTF16_LE),
                    (b'utf-16', 'utf-16-be', codecs.BOM_UTF16_BE),
                    # Expat does not support UTF-32
                    #(b'utf-32', 'utf-32-le', codecs.BOM_UTF32_LE),
                    #(b'utf-32', 'utf-32-be', codecs.BOM_UTF32_BE),
                ]:

            pl = self._create(fmt=plistlib.FMT_XML)
            with self.subTest(encoding=encoding):
                data = base.replace(b'UTF-8', xml_encoding)
                data = bom + data.decode('utf-8').encode(encoding)
                pl2 = plistlib.loads(data)
                self.assertEqual(dict(pl), dict(pl2)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_plistlib.py

示例3: get_dict_from_recipe_name

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def get_dict_from_recipe_name(recipe_name):
        recipes_directory = os.path.normpath(os.path.dirname(__file__) + "/../recipe/") + "/"

        # We get the required recipe
        recipe_path = recipes_directory + recipe_name

        # We get is as dict
        recipe_dict = plistlib.load(open(recipe_path, 'rb'), fmt=plistlib.FMT_XML)

        return recipe_dict 
开发者ID:OpenMDM,项目名称:OpenMDM,代码行数:12,代码来源:models.py

示例4: writePlist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def writePlist(value, pathOrFile):
    if not isinstance(pathOrFile, basestring):
        return dump(value, pathOrFile, fmt=FMT_XML, sort_keys=True, skipkeys=False)
    with open(pathOrFile, "wb") as f:
        return dump(value, f, fmt=FMT_XML, sort_keys=True, skipkeys=False)

###                ###
# Remapped Functions #
###                ### 
开发者ID:corpnewt,项目名称:USBMap,代码行数:11,代码来源:plist.py

示例5: dump

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    if _check_py3():
        plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
    else:
        if fmt == FMT_XML:
            # We need to monkey patch a bunch here too in order to avoid auto-sorting
            # of keys
            writer = plistlib.PlistWriter(fp)
            def writeDict(d):
                if d:
                    writer.beginElement("dict")
                    items = sorted(d.items()) if sort_keys else d.items()
                    for key, value in items:
                        if not isinstance(key, basestring):
                            if skipkeys:
                                continue
                            raise TypeError("keys must be strings")
                        writer.simpleElement("key", key)
                        writer.writeValue(value)
                    writer.endElement("dict")
                else:
                    writer.simpleElement("dict")
            writer.writeDict = writeDict
            writer.writeln("<plist version=\"1.0\">")
            writer.writeValue(value)
            writer.writeln("</plist>")
        elif fmt == FMT_BINARY:
            # Assume binary at this point
            writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
            writer.write(value)
        else:
            # Not a proper format
            raise ValueError("Unsupported format: {}".format(fmt)) 
开发者ID:corpnewt,项目名称:USBMap,代码行数:35,代码来源:plist.py

示例6: writePlist

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def writePlist(value, pathOrFile):
    if not isinstance(pathOrFile, _get_inst()):
        return dump(value, pathOrFile, fmt=FMT_XML, sort_keys=True, skipkeys=False)
    with open(pathOrFile, "wb") as f:
        return dump(value, f, fmt=FMT_XML, sort_keys=True, skipkeys=False)

###                ###
# Remapped Functions #
###                ### 
开发者ID:B0hrer,项目名称:thinkpad-x1c5-hackintosh,代码行数:11,代码来源:plist.py

示例7: dump

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    if _check_py3():
        plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
    else:
        if fmt == FMT_XML:
            # We need to monkey patch a bunch here too in order to avoid auto-sorting
            # of keys
            writer = plistlib.PlistWriter(fp)
            def writeDict(d):
                if d:
                    writer.beginElement("dict")
                    items = sorted(d.items()) if sort_keys else d.items()
                    for key, value in items:
                        if not isinstance(key, (str,unicode)):
                            if skipkeys:
                                continue
                            raise TypeError("keys must be strings")
                        writer.simpleElement("key", key)
                        writer.writeValue(value)
                    writer.endElement("dict")
                else:
                    writer.simpleElement("dict")
            writer.writeDict = writeDict
            writer.writeln("<plist version=\"1.0\">")
            writer.writeValue(value)
            writer.writeln("</plist>")
        elif fmt == FMT_BINARY:
            # Assume binary at this point
            writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
            writer.write(value)
        else:
            # Not a proper format
            raise ValueError("Unsupported format: {}".format(fmt)) 
开发者ID:B0hrer,项目名称:thinkpad-x1c5-hackintosh,代码行数:35,代码来源:plist.py

示例8: test_controlcharacters

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def test_controlcharacters(self):
        for i in range(128):
            c = chr(i)
            testString = "string containing %s" % c
            if i >= 32 or c in "\r\n\t":
                # \r, \n and \t are the only legal control chars in XML
                plistlib.dumps(testString, fmt=plistlib.FMT_XML)
            else:
                self.assertRaises(ValueError,
                                  plistlib.dumps,
                                  testString) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_plistlib.py

示例9: dump

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def dump(value, fp, *, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    """Write 'value' to a .plist file. 'fp' should be a (writable)
    file object.
    """
    if fmt not in _FORMATS:
        raise ValueError("Unsupported format: %r"%(fmt,))

    writer = PlistNoneWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
    writer.write(value) 
开发者ID:cmdmnt,项目名称:commandment,代码行数:11,代码来源:nonewriter.py

示例10: dumps

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def dumps(value, *, fmt=FMT_XML, skipkeys=False, sort_keys=True):
    """Return a bytes object with the contents for a .plist file.
    """
    fp = BytesIO()
    dump(value, fp, fmt=fmt, skipkeys=skipkeys, sort_keys=sort_keys)
    return fp.getvalue() 
开发者ID:cmdmnt,项目名称:commandment,代码行数:8,代码来源:nonewriter.py

示例11: readPlistFromString

# 需要导入模块: import plistlib [as 别名]
# 或者: from plistlib import FMT_XML [as 别名]
def readPlistFromString(s):
        return loads(s, fmt=FMT_XML) 
开发者ID:googlefonts,项目名称:ufo2ft,代码行数:4,代码来源:featureWriters_test.py


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