Skip to content

format_for modifies input BytesIO position #296

Description

@benoit74

When calling format_for, the input BytesIO position is modified. Not sure this is really expected behavior, at least it caused openzim/sotoki#410 ;

@rgaudin any views on which convention we should have on that aspect?

One example:

svg_content = """<svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60">
<rect width="100%" height="100%" fill="#001489"/>
</svg>
"""

svg_bytes = io.BytesIO()
svg_bytes.write(svg_content.encode())
print(svg_bytes.tell())
print(format_for(svg_bytes, from_suffix=False))
print(svg_bytes.tell())

Output:

> python test.py
138
SVG
18

Another example:

svg_content = """<svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60">
<rect width="100%" height="100%" fill="#001489"/>
</svg>
"""

svg_bytes = io.BytesIO()
svg_bytes.write(svg_content.encode())
svg_bytes.seek(0)
print(svg_bytes.tell())
print(format_for(svg_bytes, from_suffix=False))
print(svg_bytes.tell())

Output:

> python test.py
o
SVG
18

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions