/usr/lib/python2.7/dist-packages/dijitso/signatures.py is in python-dijitso 2016.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # -*- coding: utf-8 -*-
# Copyright (C) 2015-2016 Martin Sandve Alnæs
#
# This file is part of DIJITSO.
#
# DIJITSO is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DIJITSO is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DIJITSO. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from six import string_types
import hashlib
# Arbitrarily chosen hash digest cutoff to keep filename lengths
# reasonably small. If this is too short hashes will collide!
HASHLENGTH = 12
def hashit(data):
"Return hash of anything with a repr implementation."
h = hashlib.sha1()
h.update(repr(data).encode('utf-8'))
return h.hexdigest()[:HASHLENGTH]
def canonicalize_params_for_hashing(params):
if params:
data = ()
else:
assert isinstance(params, dict)
keys = sorted(params)
assert all(isinstance(key, string_types) for key in keys)
items = []
for k in keys:
k = k.encode('utf-8')
v = params[k]
if isinstance(v, dict):
items.append((k, canonicalize_params_for_hashing(v)))
else:
items.append((k, repr(v).encode('utf-8')))
data = tuple(items)
return data
def hash_params(params):
return hashit(canonicalize_params_for_hashing(params))
|