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

def get_hash(self, length=HASH_LENGTH):
        """
        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
        """

        data_hash = ""
        if not self.data_str:
            return data_hash

        encoded_data_str = self.data_str
        if sys.version_info.major == 2:
            # In Py2, only unicode needs to be encoded.
            if isinstance(self.data_str, unicode):
                encoded_data_str = self.data_str.encode('utf-8')
        else:
            # data_str should always be unicode on python 3
            encoded_data_str = self.data_str.encode('utf-8')

        data_hash = hashlib.sha1(encoded_data_str).hexdigest()

        return data_hash[:length]