def set_configuration_property(self, configuration_property): # retrieves the configuration configuration = configuration_property.get_data() # cleans the console configuration colony.map_clean(self.console_configuration) # copies the service configuration to the console configuration configuration colony.map_copy(configuration, self.console_configuration)
def set_startup_configuration_property(self, startup_configuration_property): # retrieves the startup configuration startup_configuration = startup_configuration_property.get_data() # cleans the startup configuration colony.map_clean(self.startup_configuration) # copies the startup configuration to the startup configuration colony.map_copy(startup_configuration, self.startup_configuration)
def set_handler_configuration_property(self, handler_configuration_property): # retrieves the handler configuration handler_configuration = handler_configuration_property.get_data() # cleans the handler configuration colony.map_clean(self.handler_configuration) # copies the handler configuration to the handler configuration colony.map_copy(handler_configuration, self.handler_configuration)
def _create_request_headers(self, request): # creates a new map for the request headers request_headers = {} # copies the original request headers to the request headers colony.map_copy(request.headers_map, request_headers) # iterates over all the headers to be removed for removal_header in REMOVAL_HEADERS: # in case the removal header does not exist # in the request headers, no need to continue if not removal_header in request_headers: # continues the loop continue # removes the header from the request headers del request_headers[removal_header] # returns the request headers return request_headers
def _get_socket(self, socket_name = "normal", socket_parameters = {}): """ Retrieves the socket for the given socket name using the socket provider plugins. :type socket_name: String :param socket_name: The name of the socket to be retrieved. :type socket_parameters: Dictionary :param socket_parameters: The parameters of the socket to be retrieved. :rtype: Socket :return: The socket for the given socket name. """ # retrieves the socket provider plugins map socket_provider_plugins_map = self.client_utils.socket_provider_plugins_map # in case the socket name is available in the socket # provider plugins map if socket_name in socket_provider_plugins_map: # retrieves the socket provider plugin from the socket provider plugins map socket_provider_plugin = socket_provider_plugins_map[socket_name] # creates the parameters for the socket provider, the # handshake process in case it's required must be forced # then copies the socket parameters to the parameters map parameters = { "do_handshake_on_connect" : True } colony.map_copy(socket_parameters, parameters) # creates a new socket with the socket provider plugin # and returns the created socket to the caller method socket = socket_provider_plugin.provide_socket_parameters(parameters) return socket else: # raises the socket provider not found exception raise exceptions.SocketProviderNotFound("socket provider %s not found" % socket_name)
def set_configuration_property(self, configuration_property): # retrieves the configuration and runs the clean operation # in it then copies the configuration to the target map configuration = configuration_property.get_data() colony.map_clean(self.info_user_configuration) colony.map_copy(configuration, self.info_user_configuration)
def autocomplete(self, request): """ Handles the given autocomplete request. This request should try to find a series of results that may be used as "tips" for the correct command. :type request: Request :param request: The request to be handled. """ # retrieves the reference to the plugin manager running # in the current context plugin_manager = self.plugin.manager # retrieves the json plugin for the encoding of the # response value (serialized value) json_plugin = self.plugin.json_plugin # retrieves the command that it's meant to be executed by # the current python virtual machine, then retrieves the # id of the interpreter instance to be used command = request.field("command", "") instance = request.field("instance", None) # in case no instance (identifier) is found a new randomly generated # value is created for it (secure generation) instance = instance or str(uuid.uuid4()) # creates the map containing the various local names to be used # in the interpreter, these are the values that will be made available # as entrance points to the end user locals = dict( manager = plugin_manager, plugins = plugin_manager.plugins ) # tries to retrieve the correct interpreter from the interpreters # map in case it does not exists creates a new one, then sets it # back in the interpreters map for latter usage, at the final part # of the execution updates the current locals reference interpreter = self.interpreters.get(instance, None) interpreter = interpreter or code.InteractiveInterpreter(locals = locals) self.interpreters[instance] = interpreter locals = interpreter.locals # copies the built in symbols (globally present) into the locals map # this allows the autocomplete to couple with these symbols colony.map_copy(__builtins__, locals) # creates a new list to hold the various commands to be sent as valid # autocomplete values for the client side commands = [] # splits the command into the various sub components so that its possible # to use the partials value to recursively resolve the appropriate sequence # to be iterated for searching command_split = command.rsplit(".") base = command_split[-1] partials = command_split[:-1] values, container = self._resolve_value(partials, locals) # calculates the offset position where the value used in the command calculus # is starting, this value may be used for the prefix calculation at the client offset = len(command) - len(base) # iterates over the complete list of values to test the # beginning of each name against the command name for value in values: # in case the current value does not start # with the command text must be skipped, otherwise # adds the local name to the list of valid commands # for the autocomplete operation if not value.startswith(base): continue # retrieves the object associated with the current value (name) # taking into account the type of the container object (different # strategies apply for different container types) if type(container) == dict: object = container[value] else: object = getattr(container, value) # retrieves the (python) object type and then uses it to convert # the type into the "normalized" string representation object_type = type(object) if object_type == types.FunctionType: object_type_s = "function" elif object_type == types.BuiltinFunctionType: object_type_s = "function" elif object_type == types.MethodType: object_type_s = "method" elif object_type == types.BuiltinMethodType: object_type_s = "method" else: object_type_s = "object" # retrieves the documentation part of the object, this is a raw # string and should be processed for correct handling doc = object.__doc__ doc, params, _return = self._process_doc(doc) # creates the map of options that contains the base documentation # string an also the tuple containing the parameters reference options = { "doc" : doc, "params" : params, "return" : _return } # adds the value and the object type values as a tuple to the list # of commands (to be interpreted by the client side) commands.append((value, object_type_s, options)) # iterates over all the base keywords in order to be able to # filter and add them to the commands list, these keywords # will have no extra values associated (basic keywords) for keyword in BASE_KEYWORDS: if not keyword.startswith(command): continue commands.append((keyword, "keyword", dict())) # iterates over all the space keywords in order to be able to # filter and add them to the commands list, these keywords # will have the extra space character appended for keyword in SPACE_KEYWORDS: if not keyword.startswith(command): continue commands.append((keyword, "keyword", dict(extra = " "))) # iterates over all the base keywords in order to be able to # filter and add them to the commands list, these keywords # will have the extra dot character appended for keyword in DOT_KEYWORDS: if not keyword.startswith(command): continue commands.append((keyword, "keyword", dict(extra = ":"))) # sorts the commands according to their default (alphabetic order) so # that they are presented to the end user in the best way possible commands.sort() # creates the response map and serializes it with json to create the # final result contents, should retrieve the appropriate mime type response = dict( result = commands, offset = offset, instance = instance ) self.serialize(request, response, serializer = json_plugin)
def console_command_extension_load(self, console_command_extension_plugin): # retrieves the commands map from the console command extension commands_map = console_command_extension_plugin.get_commands_map() # copies the plugin commands map to the commands map colony.map_copy(commands_map, self.commands_map)
def _create_headers_map(self, request, http_response, removal_response_headers = ()): # retrieves the url parser plugin url_parser_plugin = self.plugin.url_parser_plugin # creates a new map for the headers map headers_map = {} # copies the original request headers to the request headers colony.map_copy(http_response.headers_map, headers_map) # iterates over all the response headers to be removed for removal_response_header in removal_response_headers: # in case the removal response header does not exist # in the headers map, no need to continue if not removal_response_header in headers_map: # continues the loop continue # removes the response header from the headers map del headers_map[removal_response_header] # in case the location value exists in the headers map if LOCATION_VALUE in headers_map: # retrieves the location from the headers map location = headers_map[LOCATION_VALUE] # retrieves the proxy target proxy_target = request.properties.get(PROXY_TARGET_VALUE, DEFAULT_PROXY_TARGET) # creates the handler path from the handler base path # or from the handler path (depending on the valid one) handler_path = request.handler_base_path or request.handler_path # sets the valid handler path based on the length of the path handler_path = not handler_path == "/" and handler_path or "" # in case the location starts with the HTTP prefix or # with the https prefix (absolute path) if location.startswith(HTTP_PREFIX_VALUE) or location.startswith(HTTPS_PREFIX_VALUE): # replaces the proxy target for the handler path location = location.replace(proxy_target, handler_path) # in case the location starts with a slash (relative to host path) elif location.startswith("/"): # parses the url retrieving the url structure url_structure = url_parser_plugin.parse_url(proxy_target) # retrieves the resource reference from the url structure # or sets the default one (empty) in case it's not defined resource_reference = url_structure.resource_reference or "" # removes the resource reference from the location location = location.replace(resource_reference, "") # creates the location with the handler path and the original location location = handler_path + location # sets the location in the headers map headers_map[LOCATION_VALUE] = location # retrieves the protocol version number from the protocol # version string protocol_version_number = request.protocol_version.strip(HTTP_PROTOCOL_PREFIX_VALUE) # retrieves the host value from the request host = request.headers_map.get(HOST_VALUE, DEFAULT_HOST_VALUE) # retrieves the server identifier server_identifier = request.get_server_identifier() # sets the via header in the headers map headers_map[VIA_VALUE] = protocol_version_number + " " + host + " (" + server_identifier + ")" # returns the headers map return headers_map