original_docstring: Replace all function calls in source with dummy names,
      for the functions listed in callfns. Returns a pair (new_source, d)
      where d is a dict mapping the dummy names used to the function calls.
      
docstring: Replace all function calls in source with dummy names,
  for the functions listed in callfns. Returns a pair (new_source, d)
  where d is a dict mapping the dummy names used to the function calls.
docstring_tokens: Replace all function calls in source with dummy names for the functions listed in callfns . Returns a pair ( new_source d ) where d is a dict mapping the dummy names used to the function calls .
code: def replaceCallsWithDummies(source, callfns, used_dummies=None, notFirst=False):
      """Replace all function calls in source with dummy names,
      for the functions listed in callfns. Returns a pair (new_source, d)
      where d is a dict mapping the dummy names used to the function calls.
      """
      # This function used to work on lists of callfns directly, but I can't
      # see why it stopped working. So I just added this recursing part at
      # the front to reduce the problem to a singleton function name each time.
      if used_dummies is None:
          used_dummies = 0
      done = False
      dummies = {}
      output = ""
      currpos = 0
      doneFirst = False
      while not done:
          # find any callfns in source (now just always a singleton)
          findposlist_candidates = [source[currpos:].find(fname+'(') for fname in callfns]
          findposlist = []
          for candidate_pos in findposlist_candidates:
              # remove any that are actually only full funcname matches to longer strings
              # that happen to have that funcname at the end: e.g. functions ['if','f']
              # and find a match 'f(' in the string 'if('
              if currpos+candidate_pos-1 >= 0:
                  if not isNameToken(source[currpos+candidate_pos-1]):
                      findposlist.append(candidate_pos)
              else:
                  # no earlier character in source, so must be OK
                  findposlist.append(candidate_pos)
          findposlist = [ix for ix in findposlist if ix >= 0]
          findposlist.sort()
          if not doneFirst and notFirst and len(findposlist) > 0:
              findposlist = findposlist[1:]
              doneFirst = True
          try:
              findpos = findposlist[0]+currpos
          except IndexError:
              done = True
          if not done:
              # find start and end braces
              startbrace = source[findpos:].find('(')+findpos
              endbrace = findEndBrace(source[startbrace:])+startbrace
              sub_source = source[startbrace+1:endbrace]
              embedded_calls = [sub_source.find(fname+'(') for fname in callfns]
              try:
                  subpositions = [x for x in embedded_calls if x > 0]
                  if subpositions == []:
                      filtered_sub_source = sub_source
                      new_d = {}
                  else:
                      filtered_sub_source, new_d = \
                              replaceCallsWithDummies(sub_source,
                                                      callfns, used_dummies)
              except ValueError:
                  pass
              else:
                  if new_d != {}:
                      dummies.update(new_d)
                      used_dummies = max( (used_dummies, max(dummies.keys())) )
              used_dummies += 1
              dummies[used_dummies] = source[findpos:startbrace+1] + \
                                        filtered_sub_source + ')'
              output += source[currpos:findpos] + '__dummy%i__' % used_dummies
              currpos = endbrace+1
          else:
              output += source[currpos:]
      if dummies != {}:
          new_dummies = dummies.copy()
          for k, v in dummies.items():
              new_v, new_d = replaceCallsWithDummies(v, callfns,
                                          used_dummies, notFirst=True)
              new_dummies[k] = new_v
              if new_d != {}:
                  new_dummies.update(new_d)
                  used_dummies = max( (used_dummies, max(new_dummies.keys())) )
          dummies.update(new_dummies)
      return output, dummies
code_tokens: def replaceCallsWithDummies ( source , callfns , used_dummies = None , notFirst = False ) : if used_dummies is None : used_dummies = 0 done = False dummies = { } output = "" currpos = 0 doneFirst = False while not done : findposlist_candidates = [ source [ currpos : ] . find ( fname + '(' ) for fname in callfns ] findposlist = [ ] for candidate_pos in findposlist_candidates : if currpos + candidate_pos - 1 >= 0 : if not isNameToken ( source [ currpos + candidate_pos - 1 ] ) : findposlist . append ( candidate_pos ) else : findposlist . append ( candidate_pos ) findposlist = [ ix for ix in findposlist if ix >= 0 ] findposlist . sort ( ) if not doneFirst and notFirst and len ( findposlist ) > 0 : findposlist = findposlist [ 1 : ] doneFirst = True try : findpos = findposlist [ 0 ] + currpos except IndexError : done = True if not done : startbrace = source [ findpos : ] . find ( '(' ) + findpos endbrace = findEndBrace ( source [ startbrace : ] ) + startbrace sub_source = source [ startbrace + 1 : endbrace ] embedded_calls = [ sub_source . find ( fname + '(' ) for fname in callfns ] try : subpositions = [ x for x in embedded_calls if x > 0 ] if subpositions == [ ] : filtered_sub_source = sub_source new_d = { } else : filtered_sub_source , new_d = replaceCallsWithDummies ( sub_source , callfns , used_dummies ) except ValueError : pass else : if new_d != { } : dummies . update ( new_d ) used_dummies = max ( ( used_dummies , max ( dummies . keys ( ) ) ) ) used_dummies += 1 dummies [ used_dummies ] = source [ findpos : startbrace + 1 ] + filtered_sub_source + ')' output += source [ currpos : findpos ] + '__dummy%i__' % used_dummies currpos = endbrace + 1 else : output += source [ currpos : ] if dummies != { } : new_dummies = dummies . copy ( ) for k , v in dummies . items ( ) : new_v , new_d = replaceCallsWithDummies ( v , callfns , used_dummies , notFirst = True ) new_dummies [ k ] = new_v if new_d != { } : new_dummies . update ( new_d ) used_dummies = max ( ( used_dummies , max ( new_dummies . keys ( ) ) ) ) dummies . update ( new_dummies ) return output , dummies
short_docstring: Replace all function calls in source with dummy names,
  for the functions listed in callfns.
short_docstring_tokens: Replace all function calls in source with dummy names for the functions listed in callfns .
comment: """Replace all function calls in source with dummy names,
      for the functions listed in callfns. Returns a pair (new_source, d)
      where d is a dict mapping the dummy names used to the function calls.
      """$SEP$# This function used to work on lists of callfns directly, but I can't$SEP$# see why it stopped working. So I just added this recursing part at$SEP$# the front to reduce the problem to a singleton function name each time.$SEP$# find any callfns in source (now just always a singleton)$SEP$# remove any that are actually only full funcname matches to longer strings$SEP$# that happen to have that funcname at the end: e.g. functions ['if','f']$SEP$# and find a match 'f(' in the string 'if('$SEP$# no earlier character in source, so must be OK$SEP$# find start and end braces