Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

brain_hashlib.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (c) 2016 Claudiu Popa <pcmanticore@gmail.com>
  2. # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
  3. # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
  4. import six
  5. import astroid
  6. def _hashlib_transform():
  7. template = '''
  8. class %(name)s(object):
  9. def __init__(self, value=''): pass
  10. def digest(self):
  11. return %(digest)s
  12. def copy(self):
  13. return self
  14. def update(self, value): pass
  15. def hexdigest(self):
  16. return ''
  17. @property
  18. def name(self):
  19. return %(name)r
  20. @property
  21. def block_size(self):
  22. return 1
  23. @property
  24. def digest_size(self):
  25. return 1
  26. '''
  27. algorithms = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
  28. classes = "".join(
  29. template % {'name': hashfunc, 'digest': 'b""' if six.PY3 else '""'}
  30. for hashfunc in algorithms)
  31. return astroid.parse(classes)
  32. astroid.register_module_extender(astroid.MANAGER, 'hashlib', _hashlib_transform)