# Path: orangengine/models/base/baseaddress.py
# class BaseAddress(BaseObject):
# 
#     AddressTypes = enum('IPv4', 'DNS', 'RANGE', 'ANY')
#     TypeMap = bidict({
#         AddressTypes.IPv4: 'ipv4',
#         AddressTypes.DNS: 'dns',
#         AddressTypes.RANGE: 'range',
#         AddressTypes.ANY: 'any',
#     })
# 
#     def __init__(self, name, value, a_type):
#         """init address object"""
# 
#         self.name = name
#         self.value = value
#         self.a_type = a_type
# 
#     def __getattr__(self, item):
# 
#         if item == 'value':
#             return self.value
#         else:
#             raise AttributeError
# 
#     def table_value(self, with_names):
#         if with_names:
#             return self.name + " - " + self.value
#         else:
#             return self.value
# 
#     @classmethod
#     def from_criteria(cls, criteria):
#         """Create an instance from the provided criteria
#         """
# 
#         return cls(criteria['name'], criteria['value'], cls.TypeMap[criteria['type']])
# 
#     def serialize(self):
#         """Searialize self to a json acceptable data structure
#         """
#         return {
#             'name': self.name,
#             'type': self.TypeMap[self.a_type],
#             'value': self.value,
#         }
# 
# Path: orangengine/utils.py
# class bidict(dict):
#     """Bidirectional dictionary for two-way lookups
# 
#     Thanks to @Basj
#     http://stackoverflow.com/questions/3318625/efficient-bidirectional-hash-table-in-python
# 
#     Extended to allow blind access to the inverse dict by way of __getitem__
#     """
#     def __init__(self, *args, **kwargs):
#         super(bidict, self).__init__(*args, **kwargs)
#         self.inverse = {}
#         for key, value in self.iteritems():
#             self.inverse.setdefault(value, []).append(key)
# 
#     def __setitem__(self, key, value):
#         super(bidict, self).__setitem__(key, value)
#         self.inverse.setdefault(value, []).append(key)
# 
#     def __delitem__(self, key):
#         self.inverse.setdefault(self[key], []).remove(key)
#         if self[key] in self.inverse and not self.inverse[self[key]]:
#             del self.inverse[self[key]]
#         super(bidict, self).__delitem__(key)
# 
#     def __getitem__(self, item):
#         try:
#             value = super(bidict, self).__getitem__(item)
#         except KeyError:
#             value = self.inverse[item]
#             if value and len(value) == 1:
#                 value = value[0]
#         return value


from orangengine.models.base import BaseAddress
from orangengine.utils import bidict
from pandevice import objects
# -*- coding: utf-8 -*-



class PaloAltoAddress(BaseAddress):
    """Palo Alto Address

    Inherits from BaseAddress and provides access to the underlying pandevice object.
    Also provides and mapper for the type field.
    """

    TypeMap = bidict({
        BaseAddress.AddressTypes.IPv4: 'ip-netmask',
        BaseAddress.AddressTypes.RANGE: 'ip-range',

# Path: orangengine/models/base/baseaddress.py
# class BaseAddress(BaseObject):
# 
#     AddressTypes = enum('IPv4', 'DNS', 'RANGE', 'ANY')
#     TypeMap = bidict({
#         AddressTypes.IPv4: 'ipv4',
#         AddressTypes.DNS: 'dns',
#         AddressTypes.RANGE: 'range',
#         AddressTypes.ANY: 'any',
#     })
# 
#     def __init__(self, name, value, a_type):
#         """init address object"""
# 
#         self.name = name
#         self.value = value
#         self.a_type = a_type
# 
#     def __getattr__(self, item):
# 
#         if item == 'value':
#             return self.value
#         else:
#             raise AttributeError
# 
#     def table_value(self, with_names):
#         if with_names:
#             return self.name + " - " + self.value
#         else:
#             return self.value
# 
#     @classmethod
#     def from_criteria(cls, criteria):
#         """Create an instance from the provided criteria
#         """
# 
#         return cls(criteria['name'], criteria['value'], cls.TypeMap[criteria['type']])
# 
#     def serialize(self):
#         """Searialize self to a json acceptable data structure
#         """
#         return {
#             'name': self.name,
#             'type': self.TypeMap[self.a_type],
#             'value': self.value,
#         }
# 
# Path: orangengine/utils.py
# class bidict(dict):
#     """Bidirectional dictionary for two-way lookups
# 
#     Thanks to @Basj
#     http://stackoverflow.com/questions/3318625/efficient-bidirectional-hash-table-in-python
# 
#     Extended to allow blind access to the inverse dict by way of __getitem__
#     """
#     def __init__(self, *args, **kwargs):
#         super(bidict, self).__init__(*args, **kwargs)
#         self.inverse = {}
#         for key, value in self.iteritems():
#             self.inverse.setdefault(value, []).append(key)
# 
#     def __setitem__(self, key, value):
#         super(bidict, self).__setitem__(key, value)
#         self.inverse.setdefault(value, []).append(key)
# 
#     def __delitem__(self, key):
#         self.inverse.setdefault(self[key], []).remove(key)
#         if self[key] in self.inverse and not self.inverse[self[key]]:
#             del self.inverse[self[key]]
#         super(bidict, self).__delitem__(key)
# 
#     def __getitem__(self, item):
#         try:
#             value = super(bidict, self).__getitem__(item)
#         except KeyError:
#             value = self.inverse[item]
#             if value and len(value) == 1:
#                 value = value[0]
#         return value


# Path: orangengine/models/paloalto/address.py
from orangengine.models.base import BaseAddress
from orangengine.utils import bidict
from pandevice import objects

# -*- coding: utf-8 -*-



class PaloAltoAddress(BaseAddress):
    """Palo Alto Address

    Inherits from BaseAddress and provides access to the underlying pandevice object.
    Also provides and mapper for the type field.
    """

    TypeMap = bidict({
        BaseAddress.AddressTypes.IPv4: 'ip-netmask',
        BaseAddress.AddressTypes.RANGE: 'ip-range',

        BaseAddress.AddressTypes.DNS: 'fqdn',