Skip to content

gh-83913: encode UIDs in XML as CF$UID - #18622

Open
Artoria2e5 wants to merge 17 commits into
python:mainfrom
Artoria2e5:patch-1
Open

Artoria2e5 wants to merge 17 commits into
python:mainfrom
Artoria2e5:patch-1

Conversation

@Artoria2e5

@Artoria2e5 Artoria2e5 commented Feb 23, 2020 •

Copy link
Copy Markdown

This commit lets the XML writer encode UIDs in XML as a dictionary with a single key CF$UID pointing to an integer value. This is how Apple handles UIDs when writing XMLs.

It also makes the XML parser convert such dictionaries back to :class:plistlib.UID objects, so XML plists round-trip. The parse side handles UIDs nested in dicts and arrays, and dictionaries that merely contain a CF$UID key alongside other keys are left alone.

Updated in November 2026: bumped the documentation version entries to 3.16, documented :data:plistlib.CFUID_KEY, fixed the NEWS entry's line endings (which broke the "generated files" CI job), made the parser track the enclosing key per dictionary instead of a single reused attribute, added tests for the XML format, and removed a broken, unused fragment from the macOS test-data generator. AI assistance was used for this update.

Comment thread Lib/plistlib.py Resolved
Comment thread Lib/test/test_plistlib.py Resolved
@Artoria2e5

Artoria2e5 commented Apr 20, 2020 •

Copy link
Copy Markdown
Author

Uhh, hello? @serhiy-storchaka care to take a look?

Just in case someone quotes "NSKeyedArchiver only does binary" - it doesn't. The swift version accepts both XML and Binary as output (https://github.com/apple/swift-corelibs-foundation/blob/master/Sources/Foundation/NSKeyedArchiver.swift) and they got plenty of test cases with XML CF$UID at https://github.com/apple/swift-corelibs-foundation/tree/2a5bc4d8a0b073532e60410682f5eb8f00144870/Tests/Foundation/Resources.

@bigfootjon bigfootjon left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider this more advise than a review, but since I wrote the PR for plistlib.UID support I thought I might chime in.

Just in case someone quotes "NSKeyedArchiver only does binary" - it doesn't

Yes I realize this now and regret the error, I just recently hit the problem this PR is trying to address.

Comment thread Lib/test/test_plistlib.py Resolved
Comment thread Lib/plistlib.py Resolved
Comment thread Doc/library/plistlib.rst Resolved
Comment thread Doc/library/plistlib.rst Resolved
Comment thread Lib/plistlib.py Resolved
Comment thread Doc/library/plistlib.rst Resolved

@bigfootjon bigfootjon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few more thoughts (sorry this took me so long)

I don't actually have commit rights in cpython so take these suggestions with a grain of salt.

Comment thread Doc/library/plistlib.rst Resolved
Comment thread Lib/plistlib.py Resolved
Comment thread Lib/test/test_plistlib.py Resolved
Comment thread Doc/library/plistlib.rst Resolved
@brandtbucher
brandtbucher removed their request for review November 17, 2022 21:27
@ghost

ghost commented Apr 19, 2023 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@Artoria2e5

Copy link
Copy Markdown
Author

It's quite cool that the PR is still alive -- thanks for the edits @arhadthedev! Just the sort of motivation I need to actually see things to completion :)

In other news the CLA thing is giving me Internal Server Error. I will use the manual form.

Comment thread Doc/library/plistlib.rst Resolved
@2xB

2xB commented Jul 3, 2023 •

Copy link
Copy Markdown

Just ran into the same issue of files with errors occuring when writing PLists containing UIDs and this PR works perfectly. Is there anything one can help with for merging this fix?

Btw. the resulting files are identical w.r.t. UIDs to what plistutil under Linux produces.

Artoria2e5 and others added 13 commits July 4, 2023 01:27
This commit lets the XML writer encode UIDs in XML as a dictionary with a single key CF$UID pointing to an integer value. This is how Apple handles UIDs when writing XMLs.

It appears significantly harder to get the parser to replace a value it has just written, so I am not attempting it yet. I mean, I know how to replace it when the parent is a list, but when it is a dictionary it seems that I will need some extra key-saving along the stack.
The apple ref does not mention UID at all. Use a source that does.
@2xB

2xB commented Jul 14, 2023

Copy link
Copy Markdown

Another advantage of this PR is btw. that it also fixes loading XML files that contain UIDs, e.g. generated by plistutil. Currently UIDs in XML files are not interpreted at all.

No idea if it works. It's all NS to me!
@Artoria2e5 Artoria2e5 closed this Jul 14, 2023
@Artoria2e5 Artoria2e5 reopened this Jul 14, 2023
@Artoria2e5
Artoria2e5 requested a review from a team as a code owner July 14, 2023 09:13
@Artoria2e5

Copy link
Copy Markdown
Author

Aight, I should be able to get to a mac some time soon.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 7, 2026
@serhiy-storchaka serhiy-storchaka changed the title bpo-39732: encode UIDs in XML as CF$UID gh-83913: encode UIDs in XML as CF$UID Aug 12, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 14, 2026
# Conflicts:
#	Doc/library/plistlib.rst
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 22, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #36060153 | 📁 Comparing 7d887ac against main (c6796a1)

  🔍 Preview build  

204 files changed · + 1 added · ± 203 modified

+ Added

± Modified

Encode UID objects as a dictionary with a single CFUID_KEY key when
writing XML, and convert such dictionaries back to UID objects when
parsing. Track the key of the enclosing dictionary per dict so that
nested structures are handled correctly.

Also document CFUID_KEY, add XML tests, and drop a broken, unused
fragment from the macOS testdata generator.
Co-Authored-By: Skadi "Skadeep" Deepseek <noreply@deepseek.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants