Comments (8)
@paulr4 Any chance you could attach the plist as a file here?
from biplist.
Sure, here:
from biplist.
Oh. That file looks like it was printed in a Python interactive session. Those sequences like "\xae" are replacing the actual binary contents.
Do you have the original file generated by the program?
from biplist.
No, sorry, it was embedded in an SQLite file and I read it directly into Python variable from there. I wrote it to a file using plistfile.write(str(plist)), I guess that was my mistake. What should I have done?
from biplist.
I think I've got it - open the output file in binary mode ('wb') and write using bytes():
plistfile = open('tempfile','wb')
plistfile.write(bytes(plist))
from biplist.
Unfortunately I still can't get anything useful out of the file.
I've tried every combination of BinaryPlist, readPlist, and Parse I can think of, trying to adapt the examples given here, but no luck so far sadly.
from biplist.
Google's binplist project isn't the same as my biplist project.
If you're reading from a file on the filesystem, you can do something like:
>>> import biplist
>>> biplist.readPlist("/Users/andrew/Downloads/plistfile_new.plist")
{'$objects': ['$null', {'NS.keys': [Uid(2), Uid(4), Uid(6), Uid(8)], 'NS.objects': [Uid(10), Uid(12), Uid(14), Uid(16)], '$class': Uid(18)}, {'$class': Uid(3), 'NS.string': 'fullname'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(5), 'NS.string': 'address'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(7), 'NS.string': 'phone'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(9), 'NS.string': 'email'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(11), 'NS.string': 'Test Client'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(13), 'NS.string': '123 ABC Street'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(15), 'NS.string': '1234'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(17), 'NS.string': '[email protected]'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$classes': ['NSDictionary', 'NSObject'], '$classname': 'NSDictionary'}], '$archiver': 'NSKeyedArchiver', '$version': 100000, '$top': {'root': Uid(1)}}
If you're reading from SQLite into a variable, you can use StringIO
to turn that variable into a file-like object and read from there:
>>> import StringIO
>>> contents = open("plistfile.plist").read()
>>> file_like_object = StringIO.StringIO(contents)
>>> biplist.readPlist(file_like_object)
{'$objects': ['$null', {'NS.keys': [Uid(2), Uid(4), Uid(6), Uid(8)], 'NS.objects': [Uid(10), Uid(12), Uid(14), Uid(16)], '$class': Uid(18)}, {'$class': Uid(3), 'NS.string': 'fullname'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(5), 'NS.string': 'address'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(7), 'NS.string': 'phone'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(9), 'NS.string': 'email'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(11), 'NS.string': 'Test Client'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(13), 'NS.string': '123 ABC Street'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(15), 'NS.string': '1234'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$class': Uid(17), 'NS.string': '[email protected]'}, {'$classes': ['NSString', 'NSObject'], '$classname': 'NSString'}, {'$classes': ['NSDictionary', 'NSObject'], '$classname': 'NSDictionary'}], '$archiver': 'NSKeyedArchiver', '$version': 100000, '$top': {'root': Uid(1)}}
This particular plist is a keyed archive, used by the program to encode an object in memory. The format can be fairly opaque to decode.
If you're on OS X, you can use the Foundation bindings to more easily process the file, eg:
>>> import Foundation
>>> data = Foundation.NSData.dataWithContentsOfFile_("plistfile.plist")
>>> Foundation.NSKeyedUnarchiver.unarchiveObjectWithData_(data)
{
address = "123 ABC Street";
email = "[email protected]";
fullname = "Test Client";
phone = 1234;
}
from biplist.
Thank you for your help! I finally implemented this with the following code, where ClientDetails contains the impenetrable raw plist data:
import io
import biplist
tmp = io.BytesIO()
tmp.write(ClientDetails)
plist = biplist.readPlist(tmp)
tmp.close()
'plist' then contained a complicated nested arrangement of variables, which could at least be rooted through using usual python methods.
from biplist.
Related Issues (8)
- How to specify the file encoding?
- Weird encoding issue HOT 5
- module 'plistlib' has no attribute 'Data' HOT 1
- testsuite status of biplist-0.5 HOT 1
- How to write chinese into plist HOT 1
- ERROR: testLargeDates (test_valid.TestValidPlistFile) HOT 1
- Ints are being turned into Uids and vice versa when both are present in a plist. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from biplist.