This is a work in progress update of UFOReader and UFOWriter that supports UFO in its package and zipped forms. Reading works. Writing is not yet implemented. I'm building a base file system (that lives on top of fs for now and maybe in the long term) that the reader and writer then subclass. This base class implements the file system interaction so that the reader and writer can be blissfully ignorant about file systems. Additionally, I ran into a problem with the local plistlib.py creating an import error, so I've temporarily renamed it plistlibShim.py so that I can continue working. Did I mention that this is a work in progress? It's a work in progress.
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""
|
|
A py23 shim to plistlib. Reimplements plistlib under py2 naming.
|
|
"""
|
|
from __future__ import absolute_import
|
|
import sys
|
|
try:
|
|
from plistlib import (
|
|
load as readPlist, dump as writePlist,
|
|
loads as readPlistFromString, dumps as writePlistToString)
|
|
from plistlib import _PlistParser, _PlistWriter
|
|
# Public API changed in Python 3.4
|
|
if sys.version_info >= (3, 4):
|
|
class PlistWriter(_PlistWriter):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
if "indentLevel" in kwargs:
|
|
kwargs["indent_level"] = kwargs["indentLevel"]
|
|
del kwargs["indentLevel"]
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def writeValue(self, *args, **kwargs):
|
|
super().write_value(*args, **kwargs)
|
|
|
|
def writeData(self, *args, **kwargs):
|
|
super().write_data(*args, **kwargs)
|
|
|
|
def writeDict(self, *args, **kwargs):
|
|
super().write_dict(*args, **kwargs)
|
|
|
|
def writeArray(self, *args, **kwargs):
|
|
super().write_array(*args, **kwargs)
|
|
|
|
class PlistParser(_PlistParser):
|
|
|
|
def __init__(self):
|
|
super().__init__(use_builtin_types=True, dict_type=dict)
|
|
|
|
def parseElement(self, *args, **kwargs):
|
|
super().parse_element(*args, **kwargs)
|
|
|
|
def handleBeginElement(self, *args, **kwargs):
|
|
super().handle_begin_element(*args, **kwargs)
|
|
|
|
def handleData(self, *args, **kwargs):
|
|
super().handle_data(*args, **kwargs)
|
|
|
|
def handleEndElement(self, *args, **kwargs):
|
|
super().handle_end_element(*args, **kwargs)
|
|
else:
|
|
PlistWriter = _PlistWriter
|
|
PlistParser = _PlistParser
|
|
except ImportError:
|
|
from plistlib import readPlist, writePlist, readPlistFromString, writePlistToString
|
|
from plistlib import PlistParser, PlistWriter
|