# Path: paramiko/util.py
# def safe_string(s):
#     out = b""
#     for c in s:
#         i = byte_ord(c)
#         if 32 <= i <= 127:
#             out += byte_chr(i)
#         else:
#             out += b("%{:02X}".format(i))
#     return out
# 
# Path: paramiko/py3compat.py
# def byte_ord(c):
#     # In case we're handed a string instead of an int.
#     if not isinstance(c, int):
#         c = ord(c)
#     return c


from binascii import hexlify
from hashlib import sha1
from paramiko.util import safe_string
from paramiko.py3compat import byte_ord
import errno
import os
import unittest
import paramiko
import paramiko.util

        self.assertTrue(paramiko.util.retry_on_signal(raises_intr) is None)
        assert 0 == intr_errors_remaining[0]
        assert 4 == call_count[0]

        def raises_ioerror_not_eintr():
            raise IOError(errno.ENOENT, "file", "file not found")

        self.assertRaises(
            IOError,
            lambda: paramiko.util.retry_on_signal(raises_ioerror_not_eintr),
        )

        def raises_other_exception():
            raise AssertionError("foo")

        self.assertRaises(
            AssertionError,
            lambda: paramiko.util.retry_on_signal(raises_other_exception),
        )

    def test_clamp_value(self):
        assert 32768 == paramiko.util.clamp_value(32767, 32768, 32769)
        assert 32767 == paramiko.util.clamp_value(32767, 32765, 32769)
        assert 32769 == paramiko.util.clamp_value(32767, 32770, 32769)

    def test_safe_string(self):
        vanilla = b"vanilla"
        has_bytes = b"has \7\3 bytes"
        safe_vanilla = safe_string(vanilla)

# Path: paramiko/util.py
# def safe_string(s):
#     out = b""
#     for c in s:
#         i = byte_ord(c)
#         if 32 <= i <= 127:
#             out += byte_chr(i)
#         else:
#             out += b("%{:02X}".format(i))
#     return out
# 
# Path: paramiko/py3compat.py
# def byte_ord(c):
#     # In case we're handed a string instead of an int.
#     if not isinstance(c, int):
#         c = ord(c)
#     return c


# Path: tests/test_util.py
from binascii import hexlify
from hashlib import sha1
from paramiko.util import safe_string
from paramiko.py3compat import byte_ord
import errno
import os
import unittest
import paramiko
import paramiko.util


        self.assertTrue(paramiko.util.retry_on_signal(raises_intr) is None)
        assert 0 == intr_errors_remaining[0]
        assert 4 == call_count[0]

        def raises_ioerror_not_eintr():
            raise IOError(errno.ENOENT, "file", "file not found")

        self.assertRaises(
            IOError,
            lambda: paramiko.util.retry_on_signal(raises_ioerror_not_eintr),
        )

        def raises_other_exception():
            raise AssertionError("foo")

        self.assertRaises(
            AssertionError,
            lambda: paramiko.util.retry_on_signal(raises_other_exception),
        )

    def test_clamp_value(self):
        assert 32768 == paramiko.util.clamp_value(32767, 32768, 32769)
        assert 32767 == paramiko.util.clamp_value(32767, 32765, 32769)
        assert 32769 == paramiko.util.clamp_value(32767, 32770, 32769)

    def test_safe_string(self):
        vanilla = b"vanilla"
        has_bytes = b"has \7\3 bytes"
        safe_vanilla = safe_string(vanilla)

        safe_has_bytes = safe_string(has_bytes)