python 2.7 - How exactly do the hashlib hashers treat input? -


the python 2.7 documentation has hashlib hashers:

hash.update(arg)      update hash object string arg. [...] 

but have seen people feed objects not strings, e.g. buffers, numpy ndarrays.

given python's duck typing, i'm not surprised possible specify non-string arguments.

the question is: how know hasher doing right thing argument?

i can't imagine hasher naïvely doing shallow iteration on argument because fail miserably ndarrays more 1 dimension - if shallow iteration, ndarray n-1 dimensions.

update unpacks arguments using s# format spec. means can either string, unicode or buffer interface.

you can't define a buffer interface in pure python, c libraries numpy can , - allows them passed hash.update.

things multiple dimension arrays work fine - on c level they're stored contiguous series of bytes.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -