#271 ✓invalid
zw

libplist: can't import single-node plist via Python bindings

Reported by zw | May 25th, 2012 @ 10:23 AM | in 1.2.0 Release

(Using Ubuntu python-plist 1.8-1, based on libplist++1, on Python 2.7.3.)

The Python bindings expose Structure_from_bin() and Structure_from_xml(), but both impose the limitation that the root key must be a dictionary or array. Importing a plist with a single data element, allowed by the Apple plist DTD, returns None. plutil and other C/C++ clients don't suffer from this problem as they can use plist_from_bin() / plist_from_xml() directly, so a workaround in Python is to use plutil, but if your plist is in memory that involves messy temp file work.

If breaking the existing API were no issue, I'd probably:

  • rename Structure as Collection (Structure doesn't tell me much)
  • move Structure::FromXml and ::FromBin to Node, and return a Node from them

As it stands, I'd probably add Node::FromXml and Node::FromBin and deprecate the equivalents in Structure. Perhaps a quick-and-dirty hack would be to expose plist_from_*() to Python, but perhaps they're too low-level.

A failing test case is attached; for me it complains:

Traceback (most recent call last):
  File "fail.py", line 9, in <module>
    print(plist.Structure_from_xml(xml).to_xml())
AttributeError: 'NoneType' object has no attribute 'to_xml'

Comments and changes to this ticket

  • Martin S.

    Martin S. May 30th, 2012 @ 01:40 PM

    • State changed from “new” to “open”
    • Tag set to api, bindings, cython, libplist, python, xml

    Thanks for reporting, breaking the API is no issue and using a class method of Node sounds much more reasonable to me, too. However, patches are very welcome. ;)

  • Nikias Bassen

    Nikias Bassen November 8th, 2012 @ 08:43 PM

    • Assigned user set to “Nikias Bassen”

    Is this still up-to-date? Instead of using Structure_from_xml I just used from_xml() like this and it worked:

    #!/usr/bin/python
    import plist
    
    xml = """
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <string>fail</string>
    </plist>
    """
    print(plist.from_xml(xml).to_xml())
    

    output:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <string>fail</string>
    </plist>
    
  • Martin S.

    Martin S. May 27th, 2014 @ 09:44 AM

    • State changed from “open” to “invalid”
    • Assigned user changed from “Nikias Bassen” to “Martin S.”
    • Milestone set to 1.2.0 Release

    As described by Nikias, it is indeed possible to get what you ask for.
    Please create a ticket on github.com if still not sufficient. Thanks.

    This ticket tracker is deprecated as we've moved to github.com/libimobiledevice.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A project around supporting the iPhone in Linux.

See http://libimobiledevice.org

People watching this ticket

Attachments

Pages