[Python-Dev] [Python-checkins] cpython: Issue #15031: Refactor some code in importlib pertaining to validating (original) (raw)

Brett Cannon brett at python.org
Sat Jan 12 14:57:39 CET 2013


On Fri, Jan 11, 2013 at 9:55 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:

Nice improvement. Just a couple of minor cleanup suggestions.

On Sat, Jan 12, 2013 at 9:09 AM, brett.cannon <python-checkins at python.org> wrote: + else: + # To prevent having to make all messages have a conditional name. + name = 'bytecode' For consistency with other default/implied names, I suggest wrapping this in angle brackets: "")

Good suggestion.

+ if path is not None: + excdetails['path'] = path + magic = data[:4] + rawtimestamp = data[4:8] + rawsize = data[8:12] + if magic != MAGICBYTES: + msg = 'bad magic number in {!r}: {!r}'.format(name, magic) + raise ImportError(msg, **excdetails) + elif len(rawtimestamp) != 4: + message = 'bad timestamp in {!r}'.format(name) + verbosemessage(message) + raise EOFError(message) + elif len(rawsize) != 4: + message = 'bad size in {!r}'.format(name) + verbosemessage(message) + raise EOFError(message) For timestamp and size "incomplete" would probably be a better word than "bad" in the error messages (since we're only checking the length rather than the value).

True. Those were the original messages and in hindsight not accurate. Since we don't consider exception messages a backwards-compatible thing I'll update them.



More information about the Python-Dev mailing list