Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The data returned by the list_folders method is a list of three-tuples. #39

Open
wants to merge 3 commits into
base: m
Choose a base branch
from

Conversation

rstewart2702
Copy link

The data in each three tuple are extracted by the iteration in the program
into:
flags, a tuple or iterable of bytestrings
delimiter, a bytestring
folder_name, an encoded string (Unicode, according to the Python3 standard)

This change adds code to invoke the bytestring type's decode method, which is
necessary to convert the bytestring data into Unicode data acceptable in the
later incarnations of Python.

The data in each three tuple are extracted by the iteration in the program
into:
  flags, a tuple or iterable of bytestrings
  delimiter, a bytestring
  folder_name, an encoded string (Unicode, according to the Python3 standard)

This change adds code to invoke the bytestring type's decode method, which is
necessary to convert the bytestring data into Unicode data acceptable in the
later incarnations of Python.
@brandon-rhodes
Copy link
Owner

I suppose Menno must have continued development on imaplib, and introduced an incompatibility. Could you try installing imapclient==0.13.0 and see whether that fixes your problem?

@rstewart2702
Copy link
Author

Still get the same error:

>>> data = c.list_folders()
>>> data[0]
((b'\\HasNoChildren',), b'/', 'Caroline_math')
>>> for flags, delimiter, folder_name in data:
...     print('  %-30s%s %s' % (' '.join(flags), delimiter, folder_name))
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: sequence item 0: expected str instance, bytes found
>>> 

And that's with:

pip freeze
IMAPClient==0.13
six==1.16.0

@brandon-rhodes
Copy link
Owner

Well, drat. I wonder what could have changed since I ran the examples myself and published them?

I spent about an hour trying to get the Network Playground up and running again and, wow, 14.04 is very old and can't even install Python packages any more. I wonder if I should try modernizing it? It would be on my own time, as the publisher isn't funding further work on the project at this point. I don't have a good feeling for whether getting things running again would be just a couple of hours of work or something more like a full week.

My main goal is not to break this script for anyone for whom it was already working.

What operating system were you running the script under, in case that makes a difference?

( ( b' '.join(flags) ).decode() ,
delimiter.decode() ,
folder_name ) )
print(' %-30s%s %s' % ( b' '.join(flags), delimiter, folder_name ) )
Copy link
Owner

Choose a reason for hiding this comment

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

Nice! I like how your syntax is moving more towards PEP-8. There's just a little extraneous whitespace to clean up and you'll have arrived. (And then you'll just be waiting on me to figure out how to get a test environment running again, and who knows how long that might take me. Alas!)

Copy link
Author

@rstewart2702 rstewart2702 Jul 29, 2021

Choose a reason for hiding this comment

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

Thanks for the encouragement; this is my first real-live pull request, ever.

I'll pull out the whitespace and push again.

Your book is very helpful, and I'm going to promote it in the "Python and IMAP" article I'm working on.

@rstewart2702
Copy link
Author

I'm running under Windows 10, with Python 3.9.4.
PEP 461 was informative, and may help explain, but I didn't read it in detail.

I also pushed a different proposed change to the branch, which is "smaller" or less invasive...

@brandon-rhodes
Copy link
Owner

Thanks, that does look less invasive! I'll try to arrange for a test tomorrow or next week.

@rstewart2702
Copy link
Author

For what it's worth: I haven't had time to test this hypothesis, but my money's on the changes introduced to the official Python release at 3.5, specifically, changes introduced by "PEP 461 -- Adding % formatting to bytes and bytearray".

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.

2 participants