mirror of
https://github.com/corpnewt/gibMacOS.git
synced 2025-02-01 22:41:23 +01:00
Update plist.py from pymodules
This commit is contained in:
parent
afef3f3139
commit
f0461cbaab
@ -117,7 +117,8 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
|||||||
parser.StartElementHandler = p.handleBeginElement
|
parser.StartElementHandler = p.handleBeginElement
|
||||||
parser.EndElementHandler = p.handleEndElement
|
parser.EndElementHandler = p.handleEndElement
|
||||||
parser.CharacterDataHandler = p.handleData
|
parser.CharacterDataHandler = p.handleData
|
||||||
# We also need to monkey patch this to allow for other dict_types
|
# We also need to monkey patch this to allow for other dict_types, hex int support
|
||||||
|
# proper line output for data errors, and for unicode string decoding
|
||||||
def begin_dict(attrs):
|
def begin_dict(attrs):
|
||||||
d = dict_type()
|
d = dict_type()
|
||||||
p.addObject(d)
|
p.addObject(d)
|
||||||
@ -134,9 +135,15 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
|||||||
p.addObject(plistlib.Data.fromBase64(p.getData()))
|
p.addObject(plistlib.Data.fromBase64(p.getData()))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception("Data error at line {}: {}".format(parser.CurrentLineNumber,e))
|
raise Exception("Data error at line {}: {}".format(parser.CurrentLineNumber,e))
|
||||||
|
def end_string():
|
||||||
|
d = p.getData()
|
||||||
|
if isinstance(d,unicode):
|
||||||
|
d = d.encode("utf-8")
|
||||||
|
p.addObject(d)
|
||||||
p.begin_dict = begin_dict
|
p.begin_dict = begin_dict
|
||||||
p.end_integer = end_integer
|
p.end_integer = end_integer
|
||||||
p.end_data = end_data
|
p.end_data = end_data
|
||||||
|
p.end_string = end_string
|
||||||
if isinstance(fp, unicode):
|
if isinstance(fp, unicode):
|
||||||
# Encode unicode -> string; use utf-8 for safety
|
# Encode unicode -> string; use utf-8 for safety
|
||||||
fp = fp.encode("utf-8")
|
fp = fp.encode("utf-8")
|
||||||
|
Loading…
Reference in New Issue
Block a user