def _manageRoles(mo):
 firstHalf = mo.group(1)
 secondHalf = mo.group(2)
 newRoles = []
 roles = secondHalf.split(' / ')
 for role in roles:
  role = role.strip()
  if (not role):
   continue
  roleID = analyze_imdbid(role)
  if (roleID is None):
   roleID = u'/'
  else:
   roleID += u'/'
  newRoles.append((u'<div class="_imdbpyrole" roleid="%s">%s</div>' % (roleID, role.strip())))
 return ((firstHalf + u' / '.join(newRoles)) + mo.group(3))

def _manageRoles ( mo ) : firstHalf = mo . group ( 1 ) secondHalf = mo . group ( 2 ) newRoles = [ ] roles = secondHalf . split ( ' / ' ) for role in roles : role = role . strip ( ) if ( not role ) : continue roleID = analyze_imdbid ( role ) if ( roleID is None ) : roleID = u'/' else : roleID += u'/' newRoles . append ( ( u'<div class="_imdbpyrole" roleid="%s">%s</div>' % ( roleID , role . strip ( ) ) ) ) return ( ( firstHalf + u' / ' . join ( newRoles ) ) + mo . group ( 3 ) )
perform some transformation on the html .