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

Radostin Stoyanov rstoyanov1 at gmail.com
Thu Sep 7 13:09:33 UTC 2017


On 07/09/17 12:45, 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 6dbea87..84d1629 100644
> --- a/src/virtBootstrap/utils.py
> +++ b/src/virtBootstrap/utils.py
> @@ -167,7 +167,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