Skip to content

Commit

Permalink
Add special handling in PycodeSerializer for bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
SrirachaHorse committed Dec 8, 2023
1 parent 212ca4f commit 8889e5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/formats/dataclass/serializers/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def test_write_object_with_enum(self):
iterator = self.serializer.write_object(Namespace.SOAP11, 0, set())
self.assertEqual("Namespace.SOAP11", "".join(iterator))

def test_write_bytes_with_single_quote(self):
iterator = self.serializer.write_object(b"\xfaj'", 0, set())
self.assertEqual("b\"\\xfaj'\"", "".join(iterator))


def test_build_imports_with_nested_types(self):
expected = "from tests.fixtures.models import Parent\n"
actual = self.serializer.build_imports({Parent.Inner})
Expand Down
3 changes: 3 additions & 0 deletions xsdata/utils/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ def literal_value(value: Any) -> str:
if isinstance(value, QName):
return f'QName("{value.text}")'

if isinstance(value, bytes):
return repr(value)

return repr(value).replace("'", '"')

0 comments on commit 8889e5e

Please sign in to comment.