#NEWLINE# def truncate_name( name , length = None , hash_len = 4 ) : #NEWLINE# #INDENT# 'Shortens a string to a repeatable mangled version with the given length.\n    ' #NEWLINE# if ( ( length is None ) or ( len ( name ) <= length ) ) : #NEWLINE# #INDENT# return name #NEWLINE# #UNINDENT# hsh = hashlib . md5 ( force_bytes ( name ) ) . hexdigest ( ) [ : hash_len ] #NEWLINE# return ( '%s%s' % ( name [ : ( length - hash_len ) ] , hsh ) )