# Path: ndr/utils.py
# def set_dict_if_not_none(the_dict, key, value):
#     '''Wrapper function for easing serialization pain'''
#     if value is None:
#         return
# 
#     the_dict[key] = value
# 
# def set_value_if_dict_exists(the_dict, key):
#     '''Wrapper function for deserialization code'''
#     if key not in the_dict:
#         return
# 
#     return the_dict[key]
# 
# def return_value_if_key_exists(the_dict, key):
#     '''Wrapper function for helping deserialization'''
#     if key in the_dict:
#         return the_dict[key]
# 
#     return None


import ipaddress
import xml.etree.ElementTree as ET
import yaml
import ndr
        import json
from enum import Enum
from ndr.utils import (set_dict_if_not_none,
                       set_value_if_dict_exists,
                       return_value_if_key_exists)
        host.mac_address = mac_address
        host.vendor = vendor

        # Add hostnames
        hostnames_block = xml.find("hostnames")
        if hostnames_block is not None:
            # Walk the host attributes and do MAGIC
            for hostname in hostnames_block:
                host.hostnames.append(NmapHostname(
                    hostname.attrib['name'], hostname.attrib['type']))

        # Handle ports
        ports_block = xml.find("ports")
        if ports_block is not None:
            for port in ports_block.findall("port"):
                state = port.find("state")
                port_obj = NmapPort(
                    port.attrib['protocol'],
                    port.attrib['portid'],
                    state.attrib['state'],
                    state.attrib['reason'],
                    state.attrib['reason_ttl'])

                service_block = port.find("service")
                if service_block is not None:
                    service = NmapService(service_block.attrib['name'],
                                          service_block.attrib['conf'],
                                          service_block.attrib['method'])

                    xml_pv = service_block.attrib

# Path: ndr/utils.py
# def set_dict_if_not_none(the_dict, key, value):
#     '''Wrapper function for easing serialization pain'''
#     if value is None:
#         return
# 
#     the_dict[key] = value
# 
# def set_value_if_dict_exists(the_dict, key):
#     '''Wrapper function for deserialization code'''
#     if key not in the_dict:
#         return
# 
#     return the_dict[key]
# 
# def return_value_if_key_exists(the_dict, key):
#     '''Wrapper function for helping deserialization'''
#     if key in the_dict:
#         return the_dict[key]
# 
#     return None


# Path: ndr/nmap.py
import ipaddress
import xml.etree.ElementTree as ET
import yaml
import ndr
        import json
from enum import Enum
from ndr.utils import (set_dict_if_not_none,
                       set_value_if_dict_exists,
                       return_value_if_key_exists)

        host.mac_address = mac_address
        host.vendor = vendor

        # Add hostnames
        hostnames_block = xml.find("hostnames")
        if hostnames_block is not None:
            # Walk the host attributes and do MAGIC
            for hostname in hostnames_block:
                host.hostnames.append(NmapHostname(
                    hostname.attrib['name'], hostname.attrib['type']))

        # Handle ports
        ports_block = xml.find("ports")
        if ports_block is not None:
            for port in ports_block.findall("port"):
                state = port.find("state")
                port_obj = NmapPort(
                    port.attrib['protocol'],
                    port.attrib['portid'],
                    state.attrib['state'],
                    state.attrib['reason'],
                    state.attrib['reason_ttl'])

                service_block = port.find("service")
                if service_block is not None:
                    service = NmapService(service_block.attrib['name'],
                                          service_block.attrib['conf'],
                                          service_block.attrib['method'])

                    xml_pv = service_block.attrib

                    service.tunnel = set_value_if_dict_exists(xml_pv, 'tunnel')