def get_hash(self, length=HASH_LENGTH):
data_hash = "<STR_LIT>"<EOL>if not self.data_str:<EOL><INDENT>return data_hash<EOL><DEDENT>encoded_data_str = self.data_str<EOL>if sys.version_info.major == <NUM_LIT:2>:<EOL><INDENT>if isinstance(self.data_str, unicode):<EOL><INDENT>encoded_data_str = self.data_str.encode('<STR_LIT:utf-8>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>encoded_data_str = self.data_str.encode('<STR_LIT:utf-8>')<EOL><DEDENT>data_hash = hashlib.sha1(encoded_data_str).hexdigest()<EOL>return data_hash[:length]<EOL>
Generate and return a hash of data that can be used as suffix of logicalId

:return: Hash of data if it was present
:rtype string