original_docstring: Add an argument to calls in source, to the functions listed in callfns.
      
docstring: Add an argument to calls in source, to the functions listed in callfns.
docstring_tokens: Add an argument to calls in source to the functions listed in callfns .
code: def addArgToCalls(source, callfns, arg, notFirst=''):
      """Add an argument to calls in source, to the functions listed in callfns.
      """
      # 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 isinstance(callfns, list):
          if len(callfns) > 1:
              res = source
              for f in callfns:
                  res = addArgToCalls(res, [f], arg, notFirst)
              return res
      else:
          raise TypeError("Invalid list of function names")
      done = False
      output = ""
      currpos = 0
      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)
                      # remove so that findpos except clause doesn't get confused
                      findposlist_candidates.remove(candidate_pos)
              else:
                  # no earlier character in source, so must be OK
                  findposlist.append(candidate_pos)
                  # remove so that findpos except clause doesn't get confused
                  findposlist_candidates.remove(candidate_pos)
          try:
              findpos = min([x for x in findposlist if x >= 0]) + currpos
          except ValueError:
              # findposlist is empty
              done = True
              # commented this stuff out from before this function only ever
              # dealt with a singleton callfns list - probably the source of
              # the original bug!
  ##            if currpos < len(source) and len(findposlist_candidates) > 0 and \
  ##                       findposlist_candidates[0] >= 0:
  ##                currpos += findposlist_candidates[0] + 2
  ##                output += source[:findposlist_candidates[0]+2]
  ##                continue
  ##            else:
  ##                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
                  else:
                      filtered_sub_source = addArgToCalls(sub_source,callfns,arg,notFirst)
              except ValueError:
                  pass
              # add unchanged part to output
              # insert arg before end brace
              if currpos==0 and callfns == [notFirst]:
                  notFirst = ''
                  addStr = ''
              else:
                  if filtered_sub_source == '':
                      addStr = arg
                  else:
                      addStr = ', ' + arg
              output += source[currpos:startbrace+1] + filtered_sub_source \
                      + addStr + ')'
              currpos = endbrace+1
          else:
              output += source[currpos:]
      return output
code_tokens: def addArgToCalls ( source , callfns , arg , notFirst = '' ) : if isinstance ( callfns , list ) : if len ( callfns ) > 1 : res = source for f in callfns : res = addArgToCalls ( res , [ f ] , arg , notFirst ) return res else : raise TypeError ( "Invalid list of function names" ) done = False output = "" currpos = 0 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 ) findposlist_candidates . remove ( candidate_pos ) else : findposlist . append ( candidate_pos ) findposlist_candidates . remove ( candidate_pos ) try : findpos = min ( [ x for x in findposlist if x >= 0 ] ) + currpos except ValueError : 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 else : filtered_sub_source = addArgToCalls ( sub_source , callfns , arg , notFirst ) except ValueError : pass if currpos == 0 and callfns == [ notFirst ] : notFirst = '' addStr = '' else : if filtered_sub_source == '' : addStr = arg else : addStr = ', ' + arg output += source [ currpos : startbrace + 1 ] + filtered_sub_source + addStr + ')' currpos = endbrace + 1 else : output += source [ currpos : ] return output
short_docstring: Add an argument to calls in source, to the functions listed in callfns.
short_docstring_tokens: Add an argument to calls in source to the functions listed in callfns .
comment: """Add an argument to calls in source, to the functions listed in callfns.
      """$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$# remove so that findpos except clause doesn't get confused$SEP$# no earlier character in source, so must be OK$SEP$# remove so that findpos except clause doesn't get confused$SEP$# findposlist is empty$SEP$# commented this stuff out from before this function only ever$SEP$# dealt with a singleton callfns list - probably the source of$SEP$# the original bug!$SEP$##            if currpos < len(source) and len(findposlist_candidates) > 0 and \$SEP$##                       findposlist_candidates[0] >= 0:$SEP$##                currpos += findposlist_candidates[0] + 2$SEP$##                output += source[:findposlist_candidates[0]+2]$SEP$##                continue$SEP$##            else:$SEP$##                done = True$SEP$# find start and end braces$SEP$# add unchanged part to output$SEP$# insert arg before end brace