|  | 
| 42 | 42 | 
 | 
| 43 | 43 | def is_table_available(name): | 
| 44 | 44 |     try: | 
|  | 45 | +        if name in Table.existing_table_names: | 
|  | 46 | +            return Table.existing_table_names[name] | 
| 45 | 47 |         Table(name) | 
|  | 48 | +        Table.existing_table_names[name] = True | 
| 46 | 49 |         return True | 
| 47 | 50 |     except IPTCError: | 
| 48 | 51 |         pass | 
|  | 52 | +    Table.existing_table_names[name] = False | 
| 49 | 53 |     return False | 
| 50 | 54 | 
 | 
| 51 | 55 | 
 | 
| @@ -669,6 +673,11 @@ class Target(IPTCModule): | 
| 669 | 673 |     does not take any value in the iptables extension, an empty string i.e. "" | 
| 670 | 674 |     should be used. | 
| 671 | 675 |     """ | 
|  | 676 | + | 
|  | 677 | +    STANDARD_TARGETS = ["", "ACCEPT", "DROP", "REJECT", "RETURN", "REDIRECT", "SNAT", "DNAT", \ | 
|  | 678 | +        "MASQUERADE", "MIRROR", "TOS", "MARK", "QUEUE", "LOG"] | 
|  | 679 | +    """This is the constant for all standard targets.""" | 
|  | 680 | + | 
| 672 | 681 |     def __init__(self, rule, name=None, target=None, revision=None, goto=None): | 
| 673 | 682 |         """ | 
| 674 | 683 |         *rule* is the Rule object this match belongs to; it can be changed | 
| @@ -784,6 +793,8 @@ def _create_buffer(self, target): | 
| 784 | 793 |             self.reset() | 
| 785 | 794 | 
 | 
| 786 | 795 |     def _is_standard_target(self): | 
|  | 796 | +        if self._name in Target.STANDARD_TARGETS: | 
|  | 797 | +            return False | 
| 787 | 798 |         for t in self._rule.tables: | 
| 788 | 799 |             if t.is_chain(self._name): | 
| 789 | 800 |                 return True | 
| @@ -1572,6 +1583,8 @@ class Table(object): | 
| 1572 | 1583 |     """This is the constant for all tables.""" | 
| 1573 | 1584 | 
 | 
| 1574 | 1585 |     _cache = dict() | 
|  | 1586 | +    existing_table_names = dict() | 
|  | 1587 | +    """Dictionary to check faster if a table is available.""" | 
| 1575 | 1588 | 
 | 
| 1576 | 1589 |     def __new__(cls, name, autocommit=None): | 
| 1577 | 1590 |         obj = Table._cache.get(name, None) | 
|  | 
0 commit comments