md5 signatures aren't being deprecated -- just the md5 module. It is
being replaced by hashlib.md5. In current Python 2.6 importing the md5
module prints a deprecation warning. In current 3.0, the md5 module is
gone.
>>> import hashlib
>>> hashlib.md5(b"foo").digest()
'\xac\xbd\x18\xdbL\xc2\xf8\\\xed\xefeO\xcc\xc4\xa4\xd8'
works without warnings in both current 2.6 and 3.0.
Schiavo
Simon
And in 2.5 without the 'b' before the "foo".
Hello,
> Don't you already implement it for parser tables in PLY 2.5 ? I
> suppose it can be implemented the same way.
I thought so as well. However, I recently renamed a grammar rule and forgot to remove my parse table file. When running my program I got a KeyError on the name of the renamed (old) grammar rule name. I then figured the outdated check was simply not implemented...
I decided to check out the source code of Ply's yacc and found this:
(lines 1610-1622):
if isinstance(module,types.ModuleType):
parsetab = module
else:
exec "import %s as parsetab" % module
if (optimize) or (Signature.digest() == parsetab._lr_signature):
_lr_action = parsetab._lr_action
_lr_goto = parsetab._lr_goto
_lr_productions = parsetab._lr_productions
_lr_method = parsetab._lr_method
return 1
else:
return 0
What we see is that the parse table file is imported and then, if 'optimize' is enabled, it doesn't even matter if the digest matches or not... I think this is a bug in the implementation? I think the 'or' in line 2615 should be an 'and'?
I have some other questions:
- Why is the import executed, even if we don't use optimized mode?
- The signature is updated with __tabversion__, method, the start symbol, precedence rules and the doc-strings of grammar rules. I'm missing the token list and the names of the grammar rules. Why is this? (There may be other things missing?)
- The first time lr_read_tables is called (line 2705) in the yacc function, the signature only contains the __tabversion__, method and start symbol. I wonder if it can ever match the signature stored in the parse table file? (note that due to the 'or' in line 2615, the signature check if not even checked if optimize is enabled)
These are the questions I have after a quick glance at the code...
NOTE: source code I checked is for Ply 2.5
Dennis