From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (unknown [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id E44B41381F3 for ; Tue, 9 Jul 2013 23:07:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B4E6BE0C4F; Tue, 9 Jul 2013 22:51:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 55D1AE0BE4 for ; Tue, 9 Jul 2013 22:51:14 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2DF7533E971 for ; Mon, 8 Jul 2013 22:48:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id E81C2E5468 for ; Mon, 8 Jul 2013 22:47:58 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1373322877.7fafe288511b1b12fd7e18d6ec51e8d1c18f3640.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/digest.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 7fafe288511b1b12fd7e18d6ec51e8d1c18f3640 X-VCS-Branch: gsoc13/next Date: Mon, 8 Jul 2013 22:47:58 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 7c0ea18c-d662-4219-8705-4368daa6abd2 X-Archives-Hash: 634a05a4e43bcc527ff1473b05b84980 commit: 7fafe288511b1b12fd7e18d6ec51e8d1c18f3640 Author: André Erdmann mailerd de> AuthorDate: Mon Jul 8 22:34:37 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Mon Jul 8 22:34:37 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=7fafe288 roverlay/digest: try to use hashlib-provided funcs --- roverlay/digest.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/roverlay/digest.py b/roverlay/digest.py index a031889..49625ee 100644 --- a/roverlay/digest.py +++ b/roverlay/digest.py @@ -14,19 +14,64 @@ __all__ = [ 'whirlpool_file', ] -import hashlib -import portage.util.whirlpool - DEFAULT_BLOCKSIZE=16384 + +import hashlib + _HASH_CREATE_MAP = { 'md5' : hashlib.md5, 'sha1' : hashlib.sha1, 'sha256' : hashlib.sha256, 'sha512' : hashlib.sha512, - 'whirlpool' : portage.util.whirlpool.new, } +def hashlib_wrap ( name ): + """Creates a wrapper that uses hashlib.new() for the given name. + + arguments: + * name -- hash name, e.g. whirlpool + """ + def wrapped ( *args, **kwargs ): + return hashlib.new ( name, *args, **kwargs ) + # --- end of wrapped (...) --- + + h = hashlib.new + wrapped.__dict__.update ( h.__dict__ ) + wrapped.__name__ = name + wrapped.__doc__ = h.__doc__ + del h + return wrapped +# --- end of hashlib_wrap (...) --- + +def hashlib_supports ( name ): + """Returns True if the given hash type is supported, else False. + + arguments: + * name -- + """ + if name in getattr ( hashlib, 'algorithms_available', () ): + # python 2's hashlib has no algorithms_available attribute + return True + else: + ret = False + try: + hashlib.new ( name ) + except ValueError: + pass + else: + ret = True + return ret +# --- end of hashlib_supports (...) --- + +if hashlib_supports ( 'whirlpool' ): + _HASH_CREATE_MAP ['whirlpool'] = hashlib_wrap ( "whirlpool" ) +else: + import portage.util.whirlpool + _HASH_CREATE_MAP ['whirlpool'] = portage.util.whirlpool.new + +# -- end of imports / HASH_CREATE_MAP + def _generic_obj_hash ( hashobj, fh, binary_digest=False, blocksize=DEFAULT_BLOCKSIZE