[virt-tools-list] [virt-bootstrap][PATCH 2/7] python3 compat: python3 strings have no decode()

Radostin Stoyanov rstoyanov1 at gmail.com
Tue Sep 5 17:16:38 UTC 2017


On 05/09/17 17:41, Cédric Bosdonnat wrote:
> Since python3 strings are already Unicode-capable, there have no
> decode() function. Libguestfs content strings can be either python 2
> or 3 strings, only decode them to utf-8 for python2.
> ---
>  src/virtBootstrap/utils.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
> index 1fb3625..f696471 100644
> --- a/src/virtBootstrap/utils.py
> +++ b/src/virtBootstrap/utils.py
> @@ -168,7 +168,9 @@ class BuildImage(object):
>          self.g.mount('/dev/sda', '/')
>          success = False
>          if self.g.is_file('/etc/shadow'):
> -            shadow_content = self.g.read_file('/etc/shadow').decode('utf-8')
> +            shadow_content = self.g.read_file('/etc/shadow')
> +            if hasattr(shadow_content, 'decode'):
> +                shadow_content = shadow_content.decode('utf-8')
>              shadow_content = shadow_content.split('\n')
>              if shadow_content:
>                  # Note: 'shadow_content' is a list, pass-by-reference is used
ACK




More information about the virt-tools-list mailing list