parameters: (statement, index)
docstring: Convert a condition to its source representation.
  
          The index argument defines the index of this condition inside a
          ConditionBlock. If it is greater than 0, an "else" will be prepended
          to the result, if necessary.
docstring_summary: Convert a condition to its source representation.
docstring_tokens: Convert a condition to its source representation .
function: def condition_source(statement, index):
          """Convert a condition to its source representation.
  
          The index argument defines the index of this condition inside a
          ConditionBlock. If it is greater than 0, an "else" will be prepended
          to the result, if necessary.
          """
          prefix = ''
          if isinstance(statement, (EqCondition, IfdefCondition)) and index > 0:
              prefix = 'else '
  
          if isinstance(statement, IfdefCondition):
              s = statement.exp.s
  
              if statement.expected:
                  return '%sifdef %s' % (prefix, s)
  
              return '%sifndef %s' % (prefix, s)
  
          if isinstance(statement, EqCondition):
              args = [
                  statement.exp1.to_source(escape_comments=True),
                  statement.exp2.to_source(escape_comments=True)]
  
              use_quotes = False
              single_quote_present = False
              double_quote_present = False
              for i, arg in enumerate(args):
                  if len(arg) > 0 and (arg[0].isspace() or arg[-1].isspace()):
                      use_quotes = True
  
                      if "'" in arg:
                          single_quote_present = True
  
                      if '"' in arg:
                          double_quote_present = True
  
              # Quote everything if needed.
              if single_quote_present and double_quote_present:
                  raise Exception('Cannot format condition with multiple quotes.')
  
              if use_quotes:
                  for i, arg in enumerate(args):
                      # Double to single quotes.
                      if single_quote_present:
                          args[i] = '"' + arg + '"'
                      else:
                          args[i] = "'" + arg + "'"
  
              body = None
              if use_quotes:
                  body = ' '.join(args)
              else:
                  body = '(%s)' % ','.join(args)
  
              if statement.expected:
                  return '%sifeq %s' % (prefix, body)
  
              return '%sifneq %s' % (prefix, body)
  
          if isinstance(statement, ElseCondition):
              return 'else'
  
          raise Exception('Unhandled Condition statement: %s' %
                  statement.__class__)
function_tokens: def condition_source ( statement , index ) : prefix = '' if isinstance ( statement , ( EqCondition , IfdefCondition ) ) and index > 0 : prefix = 'else ' if isinstance ( statement , IfdefCondition ) : s = statement . exp . s if statement . expected : return '%sifdef %s' % ( prefix , s ) return '%sifndef %s' % ( prefix , s ) if isinstance ( statement , EqCondition ) : args = [ statement . exp1 . to_source ( escape_comments = True ) , statement . exp2 . to_source ( escape_comments = True ) ] use_quotes = False single_quote_present = False double_quote_present = False for i , arg in enumerate ( args ) : if len ( arg ) > 0 and ( arg [ 0 ] . isspace ( ) or arg [ - 1 ] . isspace ( ) ) : use_quotes = True if "'" in arg : single_quote_present = True if '"' in arg : double_quote_present = True # Quote everything if needed. if single_quote_present and double_quote_present : raise Exception ( 'Cannot format condition with multiple quotes.' ) if use_quotes : for i , arg in enumerate ( args ) : # Double to single quotes. if single_quote_present : args [ i ] = '"' + arg + '"' else : args [ i ] = "'" + arg + "'" body = None if use_quotes : body = ' ' . join ( args ) else : body = '(%s)' % ',' . join ( args ) if statement . expected : return '%sifeq %s' % ( prefix , body ) return '%sifneq %s' % ( prefix , body ) if isinstance ( statement , ElseCondition ) : return 'else' raise Exception ( 'Unhandled Condition statement: %s' % statement . __class__ )