def rename_files(container, file_map):
 overlap = set(file_map).intersection(set(file_map.itervalues()))
 if overlap:
  raise ValueError((u'Circular rename detected. The files %s are both rename targets and destinations' % u', '.join(overlap)))
 for (name, dest) in file_map.iteritems():
  if container.exists(dest):
   if ((name != dest) and (name.lower() == dest.lower())):
    continue
   raise ValueError(u'Cannot rename {0} to {1} as {1} already exists'.format(name, dest))
 if (len(tuple(file_map.itervalues())) != len(set(file_map.itervalues()))):
  raise ValueError(u'Cannot rename, the set of destination files contains duplicates')
 link_map = {}
 for (current_name, new_name) in file_map.iteritems():
  container.rename(current_name, new_name)
  if (new_name != container.opf_name):
   link_map[current_name] = new_name
 replace_links(container, link_map, replace_in_opf=True)

def rename_files ( container , file_map ) : overlap = set ( file_map ) . intersection ( set ( file_map . itervalues ( ) ) ) if overlap : raise ValueError ( ( u'Circular rename detected. The files %s are both rename targets and destinations' % u', ' . join ( overlap ) ) ) for ( name , dest ) in file_map . iteritems ( ) : if container . exists ( dest ) : if ( ( name != dest ) and ( name . lower ( ) == dest . lower ( ) ) ) : continue raise ValueError ( u'Cannot rename {0} to {1} as {1} already exists' . format ( name , dest ) ) if ( len ( tuple ( file_map . itervalues ( ) ) ) != len ( set ( file_map . itervalues ( ) ) ) ) : raise ValueError ( u'Cannot rename, the set of destination files contains duplicates' ) link_map = { } for ( current_name , new_name ) in file_map . iteritems ( ) : container . rename ( current_name , new_name ) if ( new_name != container . opf_name ) : link_map [ current_name ] = new_name replace_links ( container , link_map , replace_in_opf = True )
rename files in the container .