Hi tkeo,
On sourceforge I found a p7zip command line program and built it on Mac OS X and then was able to unpack your nlib.patch.zip.
Many of the changes you had were similar to what I had, and others fixed real porting bugs. But there are a few things I can not integrate from your patch:
1. in compatibility_utils.py, under Windows, you can not use the following code, as it will break almost on Windows machines that do not use the cp you use.
+
+ # Conversion of argv to unicode without using cdll.kernel32.GetCommandLineW
+ FILE_SYSTEM_ENCODING = sys.getfilesystemencoding()
+ uargv = []
+ in_double_quotations = False
+ for arg in sys.argv:
+ if not isinstance(arg, unicode):
+ arg = arg.decode(FILE_SYSTEM_ENCODING)
+ if in_double_quotations:
+ if arg[-1] == u'"':
+ in_double_quotations = False
+ arg = arg[:-1]
+ uargv[-1] = uargv[-1] + u' ' + arg
+ else:
+ if arg[0] == u'"':
+ arg = arg[1:]
+ if arg[-1] == u'"':
+ arg = arg[:-1]
+ else:
+ in_double_quotations = True
+ uargv.append(arg)
+ return uargv
+
It is much better to use the kernel32 call, and kindleunpack.py has always used this routine (see utf8_utils.py for utf8_argv) in one form or another. It is needed for full unicode (at least utf-16) compliance on all Windows machines under python 2.
2. The code below should only be used as a last resort.
+if sys.version_info[0] == 2:
+ reload(sys)
+ sys.setdefaultencoding('utf-8')
It hides the automatic upconversions that happen when mixing unicode and bytestrings. Those are exactly the things we need to find and track down and fix. These often happen when printing. The early change I made should have taken care of that. If not, I need a traceback. Luckily python 3 always barfs when trying to mix bytes and unicode so we should be able to find and fix those. We want stdout to be utf-8 encoded so it works on all machines and not just on one specific windows cp. Please send me the traceback of the problem you meant this to fix.
3. And finally:
@@ -333,7 +333,7 @@
flowpart = flows[num]
if fmt == b'inline':
tag = flowpart
- else:
+ elif pdir is not None and fnm is not None:
replacement = b'"../' + utf8_str(pdir) + b'/' + utf8_str(fnm) + b'"'
tag = flow_pattern.sub(replacement, tag, 1)
self.used[fnm] = 'used'
Why are these extra conditions needed? Are then needed in kindleunpack v075 as well? If not, this code is probably just hiding some other underlying problem we need to track down.
Thanks,
KevinH
ps. Is there any way you can get you IDE to stop caring about extra whitespace at the end of lines? Either way I'll run everything through reindent.py to clean up any extra whitspace in the source.
Last edited by KevinH; 10-08-2014 at 06:23 PM.
|