diff --git a/conntrackt/iptables.py b/conntrackt/iptables.py --- a/conntrackt/iptables.py +++ b/conntrackt/iptables.py @@ -124,13 +124,15 @@ class Chain(object): """ # Set-up the "header". - rendering = ":%s %s [0:0]\n" % (self.name, self.default) + rendering = ":%s %s [0:0]" % (self.name, self.default) # Group the rules by description. - previous_description="" rules = list(self.rules) rules.sort(key=attrgetter("description")) + # Use this property to figure out if we need new line separator. + previous_description=None + # Process each rule. for rule in rules: if rule.description != previous_description: @@ -139,6 +141,7 @@ class Chain(object): rendering += "# %s\n" % rule.description previous_description = rule.description rendering += "%s\n" % rule + rendering += "\n" return rendering def __str__(self):