# 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)
        service_dict['method'] = self.method.value
        service_dict['confidence'] = self.confidence

        set_dict_if_not_none(service_dict, 'version', self.version)
        set_dict_if_not_none(service_dict, 'product', self.product)
        set_dict_if_not_none(service_dict, 'extrainfo', self.extrainfo)

        set_dict_if_not_none(service_dict, 'tunnel', self.tunnel)
        set_dict_if_not_none(service_dict, 'proto', self.proto)
        set_dict_if_not_none(service_dict, 'rpcnum', self.rpcnum)
        set_dict_if_not_none(service_dict, 'lowver', self.lowver)
        set_dict_if_not_none(service_dict, 'highver', self.highver)
        set_dict_if_not_none(service_dict, 'hostname', self.hostname)
        set_dict_if_not_none(service_dict, 'ostype', self.ostype)
        set_dict_if_not_none(service_dict, 'devicetype', self.devicetype)
        set_dict_if_not_none(service_dict, 'servicefp', self.servicefp)

        if len(self.cpes) != 0:
            service_dict['cpes'] = self.cpes

        return service_dict

    @classmethod
    def from_dict(cls, service_dict):
        '''Converts a service dict back into NmapService'''
        this_service = NmapService(
            service_dict['name'],
            service_dict['confidence'],
            service_dict['method'])


# 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)

        service_dict['method'] = self.method.value
        service_dict['confidence'] = self.confidence

        set_dict_if_not_none(service_dict, 'version', self.version)
        set_dict_if_not_none(service_dict, 'product', self.product)
        set_dict_if_not_none(service_dict, 'extrainfo', self.extrainfo)

        set_dict_if_not_none(service_dict, 'tunnel', self.tunnel)
        set_dict_if_not_none(service_dict, 'proto', self.proto)
        set_dict_if_not_none(service_dict, 'rpcnum', self.rpcnum)
        set_dict_if_not_none(service_dict, 'lowver', self.lowver)
        set_dict_if_not_none(service_dict, 'highver', self.highver)
        set_dict_if_not_none(service_dict, 'hostname', self.hostname)
        set_dict_if_not_none(service_dict, 'ostype', self.ostype)
        set_dict_if_not_none(service_dict, 'devicetype', self.devicetype)
        set_dict_if_not_none(service_dict, 'servicefp', self.servicefp)

        if len(self.cpes) != 0:
            service_dict['cpes'] = self.cpes

        return service_dict

    @classmethod
    def from_dict(cls, service_dict):
        '''Converts a service dict back into NmapService'''
        this_service = NmapService(
            service_dict['name'],
            service_dict['confidence'],
            service_dict['method'])


        this_service.version = return_value_if_key_exists(