[PATCH] devel: make printmimestructure py3 compatible

Tomi Ollila tomi.ollila at iki.fi
Tue Jun 12 01:35:09 PDT 2018


On Mon, Jun 11 2018, Daniel Kahn Gillmor wrote:

> Make printmimestructure work in python3 as well as python2.
>
> PEP 394 suggests that python scripts that work with both python2 and
> python3 should have a #!/usr/bin/python command line, so do that too.

I did not see PEP 394 suggesting to change 

-#!/usr/bin/env python
+#!/usr/bin/python

just that 'python' should be able to run both python2 and python3 code.

after the above change the code will not run on (those stupid) systems
that install python to e.g. /usr/local/bin/.

While I am not against this change, the commit message is misleading.

Tomi


> ---
>  devel/printmimestructure | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/devel/printmimestructure b/devel/printmimestructure
> index 34d12930..afa0590e 100755
> --- a/devel/printmimestructure
> +++ b/devel/printmimestructure
> @@ -1,4 +1,4 @@
> -#!/usr/bin/env python
> +#!/usr/bin/python
>  # -*- coding: utf-8 -*-
>  
>  # Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
> @@ -19,6 +19,8 @@
>  # If you want to number the parts, i suggest piping the output through
>  # something like "cat -n"
>  
> +from __future__ import print_function
> +
>  import email
>  import sys
>  
> @@ -34,7 +36,7 @@ def test(z, prefix=''):
>              if d[0] in [ 'attachment', 'inline' ]:
>                  disposition = ' ' + d[0]
>      if (z.is_multipart()):
> -        print prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes'
> +        print(prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes')
>          if prefix.endswith('â””'):
>              prefix = prefix.rpartition('â””')[0] + ' '
>          if prefix.endswith('├'):
> @@ -47,6 +49,6 @@ def test(z, prefix=''):
>          test(parts[i], prefix + 'â””')
>          # FIXME: show epilogue?
>      else:
> -        print prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes'
> +        print(prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes')
>  
>  test(email.message_from_file(sys.stdin), 'â””')
> -- 
> 2.17.1
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list