當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。