Skip to content
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

Prevent Paramiko size mismatch errors in utf-8 strings #997

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pyinfra/operations/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import traceback
from datetime import timedelta
from fnmatch import fnmatch
from io import StringIO
from io import BytesIO

from jinja2 import TemplateRuntimeError, TemplateSyntaxError, UndefinedError

Expand Down Expand Up @@ -884,8 +884,8 @@ def put(
)

files.put(
name="Upload a StringIO object",
src=StringIO("file contents"),
name="Upload a BytesIO object",
src=BytesIO("file contents".encode("utf-8")),
dest="/etc/motd",
)
"""
Expand Down Expand Up @@ -1043,7 +1043,7 @@ def template(src, dest, user=None, group=None, mode=None, create_remote_dir=True
"entry 2"
]

template = StringIO("""
template = BytesIO("""
name: "{{ foo_variable }}"
dict_contents:
str1: "{{ foo_dict.str1 }}"
Expand All @@ -1052,7 +1052,7 @@ def template(src, dest, user=None, group=None, mode=None, create_remote_dir=True
{% for entry in foo_list %}
- "{{ entry }}"
{% endfor %}
""")
""".encode("utf-8"))

files.template(
name="Create a templated file",
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def template(src, dest, user=None, group=None, mode=None, create_remote_dir=True
),
)

output_file = StringIO(output)
output_file = BytesIO(output.encode("utf-8"))
# Set the template attribute for nicer debugging
output_file.template = src

Expand Down
Loading