def list(self, chain):
        """ List current rules """

        if self.user_is_root():
            if len(chain) > 0:
                print chain
                # Check chain
                if not self.is_valid_chain(chain):
                    return

                chains = [chain]
            else:
                chains = self.current_table.iterkeys()

            # Output buffer
            output = []

            for chain in chains:
                # Chain table header
                chain_output = [
                    "Chain %s (policy ACCEPT)" % chain,
                    "target     prot opt source               destination",
                ]

                # Format the rules
                for rule in self.current_table[chain]:
                    chain_output.append(
                        "%-10s %-4s %-3s %-20s %-20s %s %s" % rule,
                    )

                # Create one string
                output.append("\n".join(chain_output))

            # Done
            self.writeln_and_exit("\n\n".join(output))
        else:
            self.no_permission()
dataset/ETHPy150Open basilfx/kippo-extra/kippo_extra/commands/iptables.py/command_iptables.list/original