generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 28
Add smithy-xml package #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arandito
wants to merge
2
commits into
smithy-lang:feat/add-query-protocol
Choose a base branch
from
arandito:add-smithy-xml
base: feat/add-query-protocol
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...smithy-xml/.changes/next-release/smithy-xml-feature-f4925439be784276a4639947064c99f9.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "type": "feature", | ||
| "description": "Added initial support for XML deserialization in Smithy clients." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Changelog | ||
jonathan343 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # smithy-xml | ||
|
|
||
| This package provides generic XML serialization and deserialization support | ||
| for Smithy clients and servers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| [project] | ||
| name = "smithy-xml" | ||
| dynamic = ["version"] | ||
| requires-python = ">=3.12" | ||
| authors = [ | ||
| {name = "Amazon Web Services"}, | ||
| ] | ||
| description = "XML serialization and deserialization support for Smithy tooling." | ||
| readme = "README.md" | ||
| license = {text = "Apache License 2.0"} | ||
| keywords = ["smithy", "sdk", "xml"] | ||
| classifiers = [ | ||
| "Development Status :: 2 - Pre-Alpha", | ||
| "Intended Audience :: Developers", | ||
| "Intended Audience :: System Administrators", | ||
| "Natural Language :: English", | ||
| "License :: OSI Approved :: Apache Software License", | ||
| "Operating System :: OS Independent", | ||
| "Programming Language :: Python", | ||
| "Programming Language :: Python :: 3 :: Only", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Programming Language :: Python :: 3.14", | ||
| "Programming Language :: Python :: Implementation :: CPython", | ||
| "Topic :: Software Development :: Libraries" | ||
| ] | ||
| dependencies = [ | ||
| "smithy-core", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| "Changelog" = "https://github.com/smithy-lang/smithy-python/blob/develop/packages/smithy-xml/CHANGELOG.md" | ||
| "Code" = "https://github.com/smithy-lang/smithy-python/blob/develop/packages/smithy-xml/" | ||
| "Issue tracker" = "https://github.com/smithy-lang/smithy-python/issues" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [tool.hatch.version] | ||
| path = "src/smithy_xml/__init__.py" | ||
|
|
||
| [tool.hatch.build] | ||
| exclude = [ | ||
| "tests", | ||
| ] | ||
|
|
||
| [tool.ruff] | ||
| src = ["src"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from io import BytesIO | ||
| from xml.etree.ElementTree import iterparse | ||
|
|
||
| from smithy_core.codecs import Codec | ||
| from smithy_core.deserializers import ShapeDeserializer | ||
| from smithy_core.interfaces import BytesReader, BytesWriter | ||
| from smithy_core.serializers import ShapeSerializer | ||
| from smithy_core.types import TimestampFormat | ||
|
|
||
| from ._private.deserializers import XMLShapeDeserializer as _XMLShapeDeserializer | ||
| from ._private.readers import XMLEventReader as _XMLEventReader | ||
| from .settings import XMLSettings | ||
|
|
||
| __version__ = "0.1.0" | ||
| __all__ = ("XMLCodec", "XMLSettings") | ||
|
|
||
|
|
||
| class XMLCodec(Codec): | ||
| """A codec for converting shapes to/from XML.""" | ||
|
|
||
| def __init__( | ||
jonathan343 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self, | ||
| use_timestamp_format: bool = True, | ||
| default_timestamp_format: TimestampFormat = TimestampFormat.DATE_TIME, | ||
| default_namespace: str | None = None, | ||
| ) -> None: | ||
| """Initializes an XMLCodec. | ||
|
|
||
| :param use_timestamp_format: Whether the codec should use the | ||
| `smithy.api#timestampFormat` trait, if present. | ||
| :param default_timestamp_format: The default timestamp format to use if the | ||
| `smithy.api#timestampFormat` trait is not enabled or not present. | ||
| :param default_namespace: Default XML namespace (`xmlns`) applied to the root | ||
| element during serialization. | ||
| """ | ||
| self._settings = XMLSettings( | ||
| use_timestamp_format=use_timestamp_format, | ||
| default_timestamp_format=default_timestamp_format, | ||
| default_namespace=default_namespace, | ||
| ) | ||
|
|
||
| @property | ||
| def media_type(self) -> str: | ||
| return "application/xml" | ||
|
|
||
| def create_serializer(self, sink: BytesWriter) -> ShapeSerializer: | ||
| raise NotImplementedError("XML serialization is not supported") | ||
|
|
||
| def create_deserializer( | ||
| self, | ||
| source: bytes | BytesReader, | ||
| *, | ||
| wrapper_elements: tuple[str, ...] = (), | ||
| ) -> ShapeDeserializer: | ||
| if isinstance(source, bytes): | ||
| source = BytesIO(source) | ||
| reader = _XMLEventReader( | ||
| iterparse(source, events=("start", "end")) # noqa: S314 | ||
| ) | ||
| return _XMLShapeDeserializer( | ||
| settings=self._settings, reader=reader, wrapper_elements=wrapper_elements | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking might be worth pulling this into a separate PR that targets develop so we can get this released early. My though process is:
smithy-xmlhas a dependency onsmithy-core(unbounded) we will have cases where people using versions that exist today such as (e.g., 0.3.0) which won't work.smithy-xmllikesmithy-core>=<version>. However, to do this we'll need a specific version we know has these traits.In reality, people using smithy-xml will be using it through some aws client that pins the proper dependencies. So I'm not too worried about it. But also if this is in a patch bump, the aws clients do things like
~=which still makes it possible for us to have weird casesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to keep here for now so the code works and tests are passing. But something we may want to consider doing in parallel and then rebase later