Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

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

#271

(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'

Reported by zw · May 25th, 2012 @ 10:23 AM

State: invalid
Milestone: 1.2.0 Release
Assigned to: Martin S. Martin S.

Activity

  1. Martin S.
    Martin S.
    • 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. ;)

    May 30th, 2012 @ 01:40 PM

  2. Nikias Bassen
    Nikias Bassen
    • 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>
    

    November 8th, 2012 @ 08:43 PM

  3. Martin S.
    Martin S.
    • 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.

    May 27th, 2014 @ 09:44 AM

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.