def munge_title_to_name(name):
 if isinstance(name, unicode):
  name = substitute_ascii_equivalents(name)
 name = re.sub('[ .:/]', '-', name)
 name = re.sub('[^a-zA-Z0-9-_]', '', name).lower()
 name = re.sub('-+', '-', name)
 name = name.strip('-')
 max_length = (model.PACKAGE_NAME_MAX_LENGTH - 5)
 if (len(name) > max_length):
  year_match = re.match('.*?[_-]((?:\\d{2,4}[-/])?\\d{2,4})$', name)
  if year_match:
   year = year_match.groups()[0]
   name = ('%s-%s' % (name[:((max_length - len(year)) - 1)], year))
  else:
   name = name[:max_length]
 name = _munge_to_length(name, model.PACKAGE_NAME_MIN_LENGTH, model.PACKAGE_NAME_MAX_LENGTH)
 return name

def munge_title_to_name ( name ) : if isinstance ( name , unicode ) : name = substitute_ascii_equivalents ( name ) name = re . sub ( '[ .:/]' , '-' , name ) name = re . sub ( '[^a-zA-Z0-9-_]' , '' , name ) . lower ( ) name = re . sub ( '-+' , '-' , name ) name = name . strip ( '-' ) max_length = ( model . PACKAGE_NAME_MAX_LENGTH - 5 ) if ( len ( name ) > max_length ) : year_match = re . match ( '.*?[_-]((?:\\d{2,4}[-/])?\\d{2,4})$' , name ) if year_match : year = year_match . groups ( ) [ 0 ] name = ( '%s-%s' % ( name [ : ( ( max_length - len ( year ) ) - 1 ) ] , year ) ) else : name = name [ : max_length ] name = _munge_to_length ( name , model . PACKAGE_NAME_MIN_LENGTH , model . PACKAGE_NAME_MAX_LENGTH ) return name
munge a package title into a package name .