<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import hashlib <EOL> from abc import abstractmethod <EOL> from pants . util . meta import AbstractClass <EOL> class DefaultFingerprintHashingMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> def __hash__ ( self ) : <EOL> return hash ( type ( self ) ) <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) == type ( other ) <EOL> class FingerprintStrategy ( AbstractClass ) : <EOL> """<STR_LIT>""" <EOL> @ abstractmethod <EOL> def compute_fingerprint ( self , target ) : <EOL> """<STR_LIT>""" <EOL> def fingerprint_target ( self , target ) : <EOL> """<STR_LIT>""" <EOL> fingerprint = self . compute_fingerprint ( target ) <EOL> if fingerprint : <EOL> return '<STR_LIT>' . format ( fingerprint = fingerprint , name = type ( self ) . __name__ ) <EOL> else : <EOL> return None <EOL> @ abstractmethod <EOL> def __hash__ ( self ) : <EOL> """<STR_LIT>""" <EOL> @ abstractmethod <EOL> def __eq__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> class DefaultFingerprintStrategy ( DefaultFingerprintHashingMixin , FingerprintStrategy ) : <EOL> """<STR_LIT>""" <EOL> def compute_fingerprint ( self , target ) : <EOL> """<STR_LIT>""" <EOL> return target . payload . fingerprint ( ) <EOL> class TaskIdentityFingerprintStrategy ( FingerprintStrategy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , task ) : <EOL> self . _task = task <EOL> def _build_hasher ( self , target ) : <EOL> hasher = hashlib . sha1 ( ) <EOL> hasher . update ( target . payload . fingerprint ( ) or '<STR_LIT>' ) <EOL> hasher . update ( self . _task . fingerprint or '<STR_LIT>' ) <EOL> return hasher <EOL> def compute_fingerprint ( self , target ) : <EOL> """<STR_LIT>""" <EOL> hasher = self . _build_hasher ( target ) <EOL> return hasher . hexdigest ( ) <EOL> def __hash__ ( self ) : <EOL> return hash ( self . _task . fingerprint ) <EOL> def __eq__ ( self , other ) : <EOL> return self . _task . fingerprint == other . _task . fingerprint </s>
