Skip to content

handle non-ascii usernames in _parse_userauth_request on py2 - #1724

Open
graingert wants to merge 1 commit into
paramiko:mainfrom
graingert:patch-1
Open

graingert wants to merge 1 commit into
paramiko:mainfrom
graingert:patch-1

Conversation

@graingert

Copy link
Copy Markdown

No description provided.

@graingert graingert changed the title handle non-ascii usernames in _parse_userauth_request handle non-ascii usernames in _parse_userauth_request on py2 Jul 23, 2020

@MrMino MrMino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From pyformat.info:

If you just want to render the output of str(...) or repr(...) you can use the !s or !r conversion flags.

This should be the preferred default for all .format()s that render log messages.

@graingert

Copy link
Copy Markdown
Author

Imho log lines should use the lazy _log(DEBUG, "%(kw)r", {"kw": kw}) form

@graingert

Copy link
Copy Markdown
Author

also you can do this to lazily evaluate repr/formats when using modern f-string/.format:

class _LazyLog(object):
    def __init__(self, fn):
        self.__fn = fn

    def __str__(self):  # python log system calls str(msg) just before logging it
        return self.__fn()


class Transport:
    ...
    def _log(self, level, fn, **kwargs):
        return self.logger.log(level, _LazyLog(fn), **kwargs)

then you can use it like this on py3:

    self._log(
        DEBUG,
        lambda: f"Auth request ({method=}) {service=},{username=}",
        extra={"eg": "eg},
    )

or

    self._log(
        DEBUG,
        lambda: "Auth request (method={method!r}) service={service!r},username={username!r}".format(
            method=method,
            service=service,
            username=username,
        ),
        extra={"eg": "eg},
    )

on py2

@graingert

Copy link
Copy Markdown
Author

@bitprophet ^

@bitprophet bitprophet added this to the Next bugfix milestone Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants