def analyze_name(name, canonical=None):
 original_n = name
 name = name.strip()
 res = {}
 imdbIndex = ''
 opi = name.rfind('(')
 cpi = name.rfind(')')
 if ((opi not in ((-1), 0)) and (cpi > opi)):
  if re_index.match(name[opi:(cpi + 1)]):
   imdbIndex = name[(opi + 1):cpi]
   name = name[:opi].rstrip()
  else:
   name = re_parentheses.sub('', name).strip()
 if (not name):
  raise IMDbParserError(('invalid name: "%s"' % original_n))
 if (canonical is not None):
  if canonical:
   name = canonicalName(name)
  else:
   name = normalizeName(name)
 res['name'] = name
 if imdbIndex:
  res['imdbIndex'] = imdbIndex
 return res

def analyze_name ( name , canonical = None ) : original_n = name name = name . strip ( ) res = { } imdbIndex = '' opi = name . rfind ( '(' ) cpi = name . rfind ( ')' ) if ( ( opi not in ( ( - 1 ) , 0 ) ) and ( cpi > opi ) ) : if re_index . match ( name [ opi : ( cpi + 1 ) ] ) : imdbIndex = name [ ( opi + 1 ) : cpi ] name = name [ : opi ] . rstrip ( ) else : name = re_parentheses . sub ( '' , name ) . strip ( ) if ( not name ) : raise IMDbParserError ( ( 'invalid name: "%s"' % original_n ) ) if ( canonical is not None ) : if canonical : name = canonicalName ( name ) else : name = normalizeName ( name ) res [ 'name' ] = name if imdbIndex : res [ 'imdbIndex' ] = imdbIndex return res
return a dictionary with the name and the optional imdbindex keys .