Skip to content

Python: [Feature]: Single shared data-URI parser and media-type sniffer used by all packages #8913

Description

Description

Problem

Data-URI parsing and media-type detection are implemented several times, and each copy has been fixed separately:

Proposal

  1. Add one internal helper in core, e.g. parse_data_uri(uri) -> DataUri(media_type, params, is_base64, data). It follows RFC 2397: default media type text/plain;charset=US-ASCII, arbitrary key=value params, base64 only when the last param is base64, percent-decoding for non-base64, and a clear ValueError / ContentError on malformed input.
  2. Add one sniffer with strict signatures: BMP DIB-header check, SVG requiring an <svg root, the MPEG frame-sync mask, WebP/WAV RIFF subtype, and b64decode(validate=True).
  3. Replace the ad-hoc data: handling found in about 15 modules (A2A, hosting-A2A, AG-UI, Gemini, OpenAI Responses/Chat Completions, core MCP, hosting-MCP, DevUI, Foundry hosting, Content Understanding, skills) with the shared helper.
  4. Add a shared table-driven test corpus (valid and invalid URIs, magic-byte samples) run once in core.

Expected behavior

Every package accepts and rejects exactly the same data URIs and reports the same media type.

Code Sample

from agent_framework._types import parse_data_uri

u = parse_data_uri("data:text/plain;charset=utf-8,hello%20world")
u.media_type   # "text/plain"
u.params       # {"charset": "utf-8"}
u.data         # b"hello world"

Language/SDK

Python

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentmcpUsage: [Issues, PRs], Target: MCPpythonUsage: [Issues, PRs], Target: PythonskillsUsage: [Issues, PRs], Target: skills related features

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions