def fix_id(ID):
 if re.match(u'^[A-Za-z_][A-Za-z0-9_\\.\\-]*$', ID):
  return ID
 if len(ID):
  corrected = ID
  if ((not len(corrected)) or re.match(u'^[^A-Za-z_]$', corrected[0])):
   corrected = (u'_' + corrected)
  corrected = (re.sub(u'[^A-Za-z_]', u'_', corrected[0]) + re.sub(u'[^A-Za-z0-9_\\.\\-]', u'_', corrected[1:]))
  return corrected
 return u''

def fix_id ( ID ) : if re . match ( u'^[A-Za-z_][A-Za-z0-9_\\.\\-]*$' , ID ) : return ID if len ( ID ) : corrected = ID if ( ( not len ( corrected ) ) or re . match ( u'^[^A-Za-z_]$' , corrected [ 0 ] ) ) : corrected = ( u'_' + corrected ) corrected = ( re . sub ( u'[^A-Za-z_]' , u'_' , corrected [ 0 ] ) + re . sub ( u'[^A-Za-z0-9_\\.\\-]' , u'_' , corrected [ 1 : ] ) ) return corrected return u''
given an arbitrary string .