Den tors 7 dec. 2023 kl 09:51 skrev Ruediger Pluem <rpl...@apache.org>:

> I stumbled accross a Python 3 compatibility issue in
> tools/hook-scripts/mailer/mailer.py.
>
> The call of self.cfg.which_groups in line 565 passes an empty string as
> first parameter.
> In which_groups this empty string is passed to to_str in line 1489.
> In line 88 to_str does x.decode('utf-8')
> In Python 2 str objects have a decode method at least in later Python 3
> versions they have not. Hence I propose the following patch which fixes the
> issue for me:
>
> Index: mailer.py
> ===================================================================
> --- mailer.py   (revision 1914422)
> +++ mailer.py   (working copy)
> @@ -562,7 +562,7 @@
>
>      # collect the set of groups and the unique sets of params for the
> options
>      self.groups = { }
> -    for (group, params) in self.cfg.which_groups('', None):
> +    for (group, params) in self.cfg.which_groups(b'', None):
>        # turn the params into a hashable object and stash it away
>        param_list = sorted(params.items())
>        self.groups[group, tuple(param_list)] = params
>
>
> If I would get a go ahead here on list I would commit.
>
> Regards
>
> RĂ¼diger
>

There was some work done on mailer.py by Greg Stein, started here:
https://lists.apache.org/thread/v5bh1j8qz8kk0jv1tlctxqt1k454tz0h
However I don't think that touched these parts of the code.

I think there is more to this than that simple fix, but I'm no expert in
Python or in the Python bindings. There are two more calls to
which_groups():

Line 491, called with the return from
svn.repos.ChangeCollector(...).get_changes().items() (first argument in a
tuple). I don't know which encoding this uses.

Line 663, called with the return from sys.stdin.buffer.readlines(), already
processed by to_str() once.

In particular the call on 663 should be double decoded unless I'm missing
something.

So depending on what get_changes() return, maybe we should remove the
to_str() from which_groups() instead?

Note that we are still somewhat supporting Python 2 so we need to make sure
any changes does work on Python 2 as well.

Kind regards,
Daniel

Reply via email to