mirror of https://github.com/corpnewt/gibMacOS.git
Update plist.py from pymodules
This commit is contained in:
parent
3e49ef255a
commit
afef3f3139
|
@ -91,8 +91,18 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||||
# Monkey patch!
|
# Monkey patch!
|
||||||
def end_integer():
|
def end_integer():
|
||||||
d = p.get_data()
|
d = p.get_data()
|
||||||
p.add_object(int(d,16) if d.lower().startswith("0x") else int(d))
|
value = int(d,16) if d.lower().startswith("0x") else int(d)
|
||||||
|
if -1 << 63 <= value < 1 << 63:
|
||||||
|
p.add_object(value)
|
||||||
|
else:
|
||||||
|
raise OverflowError("Integer overflow at line {}".format(p.parser.CurrentLineNumber))
|
||||||
|
def end_data():
|
||||||
|
try:
|
||||||
|
p.add_object(plistlib._decode_base64(p.get_data()))
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception("Data error at line {}: {}".format(p.parser.CurrentLineNumber,e))
|
||||||
p.end_integer = end_integer
|
p.end_integer = end_integer
|
||||||
|
p.end_data = end_data
|
||||||
return p.parse(fp)
|
return p.parse(fp)
|
||||||
elif not _is_binary(fp):
|
elif not _is_binary(fp):
|
||||||
# Is not binary - assume a string - and try to load
|
# Is not binary - assume a string - and try to load
|
||||||
|
@ -103,6 +113,10 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||||
# Create a new PlistParser object - then we need to set up
|
# Create a new PlistParser object - then we need to set up
|
||||||
# the values and parse.
|
# the values and parse.
|
||||||
p = plistlib.PlistParser()
|
p = plistlib.PlistParser()
|
||||||
|
parser = ParserCreate()
|
||||||
|
parser.StartElementHandler = p.handleBeginElement
|
||||||
|
parser.EndElementHandler = p.handleEndElement
|
||||||
|
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
|
||||||
def begin_dict(attrs):
|
def begin_dict(attrs):
|
||||||
d = dict_type()
|
d = dict_type()
|
||||||
|
@ -110,13 +124,19 @@ def load(fp, fmt=None, use_builtin_types=None, dict_type=dict):
|
||||||
p.stack.append(d)
|
p.stack.append(d)
|
||||||
def end_integer():
|
def end_integer():
|
||||||
d = p.getData()
|
d = p.getData()
|
||||||
p.addObject(int(d,16) if d.lower().startswith("0x") else int(d))
|
value = int(d,16) if d.lower().startswith("0x") else int(d)
|
||||||
|
if -1 << 63 <= value < 1 << 63:
|
||||||
|
p.addObject(value)
|
||||||
|
else:
|
||||||
|
raise OverflowError("Integer overflow at line {}".format(parser.CurrentLineNumber))
|
||||||
|
def end_data():
|
||||||
|
try:
|
||||||
|
p.addObject(plistlib.Data.fromBase64(p.getData()))
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception("Data error at line {}: {}".format(parser.CurrentLineNumber,e))
|
||||||
p.begin_dict = begin_dict
|
p.begin_dict = begin_dict
|
||||||
p.end_integer = end_integer
|
p.end_integer = end_integer
|
||||||
parser = ParserCreate()
|
p.end_data = end_data
|
||||||
parser.StartElementHandler = p.handleBeginElement
|
|
||||||
parser.EndElementHandler = p.handleEndElement
|
|
||||||
parser.CharacterDataHandler = p.handleData
|
|
||||||
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