kevinhendricks / KindleUnpack

python based software to unpack Amazon / Kindlegen generated ebooks
GNU General Public License v3.0
957 stars 104 forks source link

Fix to match return of get_image_type to imghdr.what #6

Closed takeokt closed 9 years ago

takeokt commented 9 years ago

Hi Kevin,

I have modified to the type of return value from unicode to byte string in python 2.

Please merge my fork of the KindleUnpack.

Take care, tkeo

kevinhendricks commented 9 years ago

Hi tkeo,

No, I would rather the interface always return the string as full unicode instead of mixing return types. So we simply coerce to unicode and change downstream users to understand that. The general rule in KindleUnpack is that the only time a byte string is used is when it is the only way to handle things because byte offset file position information is needed (and therefore must be preserved ) when decoding mixed binary data.

Thanks,

Kevin

Sent from my iPad

On Jan 11, 2015, at 8:20 AM, takeokt notifications@github.com wrote:

Hi Kevin,

I have modified to the type of return value from unicode to byte string in python 2.

Please merge my fork of the KindleUnpack.

Take care, tkeo

You can merge this Pull Request by running

git pull https://github.com/takeokt/KindleUnpack python2and3 Or view, comment on, or merge it at:

https://github.com/kevinhendricks/KindleUnpack/pull/6

Commit Summary

Fix to match return of get_image_type to imghdr.what File Changes

M lib/mobi_cover.py (7) Patch Links:

https://github.com/kevinhendricks/KindleUnpack/pull/6.patch https://github.com/kevinhendricks/KindleUnpack/pull/6.diff — Reply to this email directly or view it on GitHub.

takeokt commented 9 years ago

Hi Kevin,

OK. The return value of get_image_type() is all ways unicode on python 3. On python 2, it is byte string if it is from imghdr.what(), however, it is assigned as a unicode in get_image_type(). Should them be unified to unicode?

Thanks, tkeo

kevinhendricks commented 9 years ago

Hi, Yes import unicodestr from compatibility_utils and use it to fix things as returning.

Then verify the all downstream calls to get_image_type treat it as full unicode (I think they already do but it can't hurt to doublecheck.

Thanks,

Kevin

Sent from my iPad

On Jan 11, 2015, at 8:11 PM, takeokt notifications@github.com wrote:

Hi Kevin,

OK. The return value of get_image_type() is all ways unicode on python 3. On python 2, it is byte string if it is from imghdr.what(), however, it is assigned as a unicode in get_image_type(). Should them be unified to unicode?

Thanks, tkeo

— Reply to this email directly or view it on GitHub.

takeokt commented 9 years ago

Hi, OK. I will do.

Thanks,