<commit_before># Copyright (c) 2013, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import cybox
import cybox.bindings.process_object as process_binding
from cybox.objects.port_object import Port
from cybox.objects.address_object import Address
from cybox.objects.network_connection_object import NetworkConnection
from cybox.common.environment_variable_list import EnvironmentVariableList
from cybox.common import ObjectProperties, String, DateTime, UnsignedInteger, Duration

class Process(ObjectProperties):
    _XSI_NS = "ProcessObj"
    _XSI_TYPE = "ProcessObjectType"

    def __init__(self):
        super(Process, self).__init__()
        self.is_hidden = None
        self.pid = None
        self.name = None
        self.creation_time = None
        self.parent_pid = None
        self.child_pid_list = []
        self.image_info = None
        self.argument_list = []
        self.environment_variable_list = None
        self.kernel_time = None
        self.port_list = []
        self.network_connection_list = []
        self.start_time = None
        self.status = None
        self.username = None
        self.user_time = None
        self.extracted_features = None

    def to_obj(self, process_obj = None):
        if process_obj == None:
            process_obj = process_binding.ProcessObjectType()
            process_obj.set_xsi_type(self._XSI_NS + ':' + self._XSI_TYPE)
        
        if self.is_hidden is not None: process_obj.set_is_hidden(self.is_hidden)
        if self.pid is not None: process_obj.set_PID(self.pid.to_obj())
        if self.name is not None: process_obj.set_Name(self.name.to_obj())
        if self.creation_time is not None: process_obj.set_Creation_Time(self.creation_time.to_obj())
        if self.parent_pid is not None: process_obj.set_Parent_PID(self.parent_pid.to_obj())
        if len(self.child_pid_list) > 0:
            child_pid_list_obj = process_binding.ChildPIDListType() 
            for child_pid_obj in self.child_pid_list:
                child_pid_list_obj.add_Child_PID(child_pid_obj.to_obj())
            process_obj.set_Child_PID_List(child_pid_list_obj)
        if self.image_info is not None: process_obj.set_Image_Info(self.image_info.to_obj())
        if len(self.argument_list) > 0: 
            argument_list_obj = process_binding.ArgumentListType()
            for argument_obj in self.argument_list:
                argument_list_obj.add_Argument(argument_obj.to_obj())
            process_obj.set_Argument_List(argument_list_obj)
        if self.environment_variable_list is not None: process_obj.set_Environment_Variable_List(self.environment_variable_list.to_obj())
        if self.kernel_time is not None: process_obj.set_Kernel_Time(self.kernel_time.to_obj())
        if len(self.port_list) > 0: 
            port_list_obj = process_binding.PortListType()
            for port_obj in self.port_list:
                port_list_obj.add_Port(port_obj.to_obj())
            process_obj.set_Port_List(port_list_obj)
        if len(self.network_connection_list) > 0:
            netcon_list_obj = process_binding.NetworkConnectionListType()
            for network_conn_obj in self.network_connection_list:
                netcon_list_obj.add_Network_Connection(network_conn_obj.to_obj())
            process_obj.set_Network_Connection_List(netcon_list_obj)
        if self.start_time is not None: process_obj.set_Start_Time(self.start_time.to_obj())
        if self.status is not None: pass
        if self.username is not None: process_obj.set_Username(self.username.to_obj())
        if self.user_time is not None: process_obj.set_User_Time(self.usertime.to_obj())
        if self.extracted_features is not None: pass

        return process_obj

    def to_dict(self):
        process_dict = {}

        if self.is_hidden is not None: process_dict['is_hidden'] = self.is_hidden
        if self.pid is not None: process_dict['pid'] = self.pid.to_dict()
        if self.name is not None: process_dict['name'] = self.name.to_dict()
        if self.creation_time is not None: process_dict['creation_time'] = self.creation_time.to_dict()
        if self.parent_pid is not None: process_dict['parent_pid'] = self.parent_pid.to_dict()
        if self.child_pid_list is not None:
            child_pid_list = []
            for child_pid_obj in self.child_pid_list:
                child_pid_list.append(child_pid_obj.to_dict())
            process_dict['child_pid_list'] = child_pid_list
        if self.image_info is not None: process_dict['image_info'] = self.image_info.to_dict()
        if self.argument_list is not None: 
            argument_list = []
            for argument_obj in self.argument_list:
                argument_list.append(argument_obj.to_dict())
            process_dict['argument_list'] = argument_list
        if self.environment_variable_list is not None: process_dict['environment_variable_list'] = self.environment_variable_list.to_list()
        if self.kernel_time is not None: process_dict['kernel_time'] = self.kernel_time.to_dict()
        if self.port_list is not None: 
            port_list = []
            for port_obj in self.port_list:
                port_list.append(port_obj.to_dict())
            process_dict['port_list'] = port_list
        if self.network_connection_list is not None : 
            netcon_list = []
            for network_conn_obj in self.network_connection_list:
                netcon_list.append(network_conn_obj.to_dict())
            process_dict['network_connection_list'] = netcon_list
        if self.start_time is not None: process_dict['start_time'] = self.start_time.to_dict()
        if self.status is not None: pass
        if self.username is not None: process_dict['username'] = self.username.to_dict()
        if self.user_time is not None: process_dict['user_time'] = self.user_time.to_dict()
        if self.extracted_features is not None : pass

        return process_dict
    
    @staticmethod
    def from_dict(process_dict, process_cls = None):
        if not process_dict:
            return None                <commit_msg>Added length checks for several list-based entities in to_dict<commit_after># Copyright (c) 2013, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import cybox
import cybox.bindings.process_object as process_binding
from cybox.objects.port_object import Port
from cybox.objects.address_object import Address
from cybox.objects.network_connection_object import NetworkConnection
from cybox.common.environment_variable_list import EnvironmentVariableList
from cybox.common import ObjectProperties, String, DateTime, UnsignedInteger, Duration

class Process(ObjectProperties):
    _XSI_NS = "ProcessObj"
    _XSI_TYPE = "ProcessObjectType"

    def __init__(self):
        super(Process, self).__init__()
        self.is_hidden = None
        self.pid = None
        self.name = None
        self.creation_time = None
        self.parent_pid = None
        self.child_pid_list = []
        self.image_info = None
        self.argument_list = []
        self.environment_variable_list = None
        self.kernel_time = None
        self.port_list = []
        self.network_connection_list = []
        self.start_time = None
        self.status = None
        self.username = None
        self.user_time = None
        self.extracted_features = None

    def to_obj(self, process_obj = None):
        if process_obj == None:
            process_obj = process_binding.ProcessObjectType()
            process_obj.set_xsi_type(self._XSI_NS + ':' + self._XSI_TYPE)
        
        if self.is_hidden is not None: process_obj.set_is_hidden(self.is_hidden)
        if self.pid is not None: process_obj.set_PID(self.pid.to_obj())
        if self.name is not None: process_obj.set_Name(self.name.to_obj())
        if self.creation_time is not None: process_obj.set_Creation_Time(self.creation_time.to_obj())
        if self.parent_pid is not None: process_obj.set_Parent_PID(self.parent_pid.to_obj())
        if len(self.child_pid_list) > 0:
            child_pid_list_obj = process_binding.ChildPIDListType() 
            for child_pid_obj in self.child_pid_list:
                child_pid_list_obj.add_Child_PID(child_pid_obj.to_obj())
            process_obj.set_Child_PID_List(child_pid_list_obj)
        if self.image_info is not None: process_obj.set_Image_Info(self.image_info.to_obj())
        if len(self.argument_list) > 0: 
            argument_list_obj = process_binding.ArgumentListType()
            for argument_obj in self.argument_list:
                argument_list_obj.add_Argument(argument_obj.to_obj())
            process_obj.set_Argument_List(argument_list_obj)
        if self.environment_variable_list is not None: process_obj.set_Environment_Variable_List(self.environment_variable_list.to_obj())
        if self.kernel_time is not None: process_obj.set_Kernel_Time(self.kernel_time.to_obj())
        if len(self.port_list) > 0: 
            port_list_obj = process_binding.PortListType()
            for port_obj in self.port_list:
                port_list_obj.add_Port(port_obj.to_obj())
            process_obj.set_Port_List(port_list_obj)
        if len(self.network_connection_list) > 0:
            netcon_list_obj = process_binding.NetworkConnectionListType()
            for network_conn_obj in self.network_connection_list:
                netcon_list_obj.add_Network_Connection(network_conn_obj.to_obj())
            process_obj.set_Network_Connection_List(netcon_list_obj)
        if self.start_time is not None: process_obj.set_Start_Time(self.start_time.to_obj())
        if self.status is not None: pass
        if self.username is not None: process_obj.set_Username(self.username.to_obj())
        if self.user_time is not None: process_obj.set_User_Time(self.usertime.to_obj())
        if self.extracted_features is not None: pass

        return process_obj

    def to_dict(self):
        process_dict = {}

        if self.is_hidden is not None: process_dict['is_hidden'] = self.is_hidden
        if self.pid is not None: process_dict['pid'] = self.pid.to_dict()
        if self.name is not None: process_dict['name'] = self.name.to_dict()
        if self.creation_time is not None: process_dict['creation_time'] = self.creation_time.to_dict()
        if self.parent_pid is not None: process_dict['parent_pid'] = self.parent_pid.to_dict()
        if len(self.child_pid_list) > 0:
            child_pid_list = []
            for child_pid_obj in self.child_pid_list:
                child_pid_list.append(child_pid_obj.to_dict())
            process_dict['child_pid_list'] = child_pid_list
        if self.image_info is not None: process_dict['image_info'] = self.image_info.to_dict()
        if len(self.argument_list) > 0: 
            argument_list = []
            for argument_obj in self.argument_list:
                argument_list.append(argument_obj.to_dict())
            process_dict['argument_list'] = argument_list
        if self.environment_variable_list is not None: process_dict['environment_variable_list'] = self.environment_variable_list.to_list()
        if self.kernel_time is not None: process_dict['kernel_time'] = self.kernel_time.to_dict()
        if len(self.port_list) > 0: 
            port_list = []
            for port_obj in self.port_list:
                port_list.append(port_obj.to_dict())
            process_dict['port_list'] = port_list
        if len(self.network_connection_list) > 0: 
            netcon_list = []
            for network_conn_obj in self.network_connection_list:
                netcon_list.append(network_conn_obj.to_dict())
            process_dict['network_connection_list'] = netcon_list
        if self.start_time is not None: process_dict['start_time'] = self.start_time.to_dict()
        if self.status is not None: pass
        if self.username is not None: process_dict['username'] = self.username.to_dict()
        if self.user_time is not None: process_dict['user_time'] = self.user_time.to_dict()
        if self.extracted_features is not None : pass

        return process_dict
    
    @staticmethod
    def from_dict(process_dict, process_cls = None):
        if not process_dict:
            return None                
{'fraction_non_alphanumeric': 0.08177379983726607, 'fraction_numerical': 0.0016273393002441008, 'mean_word_length': 2.8907882241215574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055113', 'n_tokens_mistral': 3734, 'n_tokens_neox': 3648, 'n_words': 752}