_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q9700
RemoteServiceAdminEvent.fromexportreg
train
def fromexportreg(cls, bundle, export_reg): # type: (Bundle, ExportRegistration) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from an ExportRegistration """ exc = export_reg.get_exception() if exc: return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_ERROR, bundle,
python
{ "resource": "" }
q9701
RemoteServiceAdminEvent.fromexportupdate
train
def fromexportupdate(cls, bundle, export_reg): # type: (Bundle, ExportRegistration) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from the update of an ExportRegistration """ exc = export_reg.get_exception() if exc: return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_ERROR, bundle,
python
{ "resource": "" }
q9702
RemoteServiceAdminEvent.fromimportupdate
train
def fromimportupdate(cls, bundle, import_reg): # type: (Bundle, ImportRegistration) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from the update of an ImportRegistration """ exc = import_reg.get_exception() if exc: return RemoteServiceAdminEvent( RemoteServiceAdminEvent.IMPORT_ERROR, bundle, import_reg.get_import_container_id(), import_reg.get_remoteservice_id(), None, None, exc, import_reg.get_description(), ) return RemoteServiceAdminEvent(
python
{ "resource": "" }
q9703
RemoteServiceAdminEvent.fromimportunreg
train
def fromimportunreg( cls, bundle, cid, rsid, import_ref, exception, endpoint ): # type: (Bundle, Tuple[str, str], Tuple[Tuple[str, str], int], ImportReference, Optional[Tuple[Any, Any, Any]], EndpointDescription) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from the departure of an ImportRegistration
python
{ "resource": "" }
q9704
RemoteServiceAdminEvent.fromexportunreg
train
def fromexportunreg( cls, bundle, exporterid, rsid, export_ref, exception, endpoint ): # type: (Bundle, Tuple[str, str], Tuple[Tuple[str, str], int], ExportReference, Optional[Tuple[Any, Any, Any]], EndpointDescription) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from the departure of an ExportRegistration
python
{ "resource": "" }
q9705
RemoteServiceAdminEvent.fromimporterror
train
def fromimporterror(cls, bundle, importerid, rsid, exception, endpoint): # type: (Bundle, Tuple[str, str], Tuple[Tuple[str, str], int], Optional[Tuple[Any, Any, Any]], EndpointDescription) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from an import error """
python
{ "resource": "" }
q9706
RemoteServiceAdminEvent.fromexporterror
train
def fromexporterror(cls, bundle, exporterid, rsid, exception, endpoint): # type: (Bundle, Tuple[str, str], Tuple[Tuple[str, str], int], Optional[Tuple[Any, Any, Any]], EndpointDescription) -> RemoteServiceAdminEvent """ Creates a RemoteServiceAdminEvent object from an export error """
python
{ "resource": "" }
q9707
IPopoWaitingList._try_instantiate
train
def _try_instantiate(self, ipopo, factory, component): # type: (Any, str, str) -> None """ Tries to instantiate a component from the queue. Hides all exceptions. :param ipopo: The iPOPO service :param factory: Component factory :param component: Component name """ try: # Get component properties with self.__lock: properties = self.__queue[factory][component]
python
{ "resource": "" }
q9708
IPopoWaitingList.service_changed
train
def service_changed(self, event): # type: (ServiceEvent) -> None """ Handles an event about the iPOPO service """ kind
python
{ "resource": "" }
q9709
IPopoWaitingList.handle_ipopo_event
train
def handle_ipopo_event(self, event): # type: (IPopoEvent) -> None """ Handles an iPOPO event :param event: iPOPO event bean """ kind = event.get_kind() if kind == IPopoEvent.REGISTERED: # A factory has been registered try: with use_ipopo(self.__context) as ipopo: factory = event.get_factory_name() with self.__lock: # Copy the list of components names for this factory
python
{ "resource": "" }
q9710
IPopoWaitingList.add
train
def add(self, factory, component, properties=None): # type: (str, str, dict) -> None """ Enqueues the instantiation of the given component :param factory: Factory name :param component: Component name :param properties: Component properties :raise ValueError: Component name already reserved in the queue :raise Exception: Error instantiating the component """ with self.__lock: if component in self.__names: raise ValueError( "Component name already queued: {0}".format(component) ) # Normalize properties if properties is None: properties = {} # Store component description self.__names[component] = factory
python
{ "resource": "" }
q9711
_create_server
train
def _create_server( shell, server_address, port, cert_file=None, key_file=None, key_password=None, ca_file=None, ): """ Creates the TCP console on the given address and port :param shell: The remote shell handler :param server_address: Server bound address :param port: Server port :param cert_file: Path to the server certificate :param key_file: Path to the server private key :param key_password: Password for the key file :param ca_file: Path to Certificate Authority to authenticate clients :return: A tuple: Server thread, TCP server object, Server active flag
python
{ "resource": "" }
q9712
_run_interpreter
train
def _run_interpreter(variables, banner): """ Runs a Python interpreter console and blocks until the user exits it. :param variables: Interpreters variables (locals) :param banner: Start-up banners """ # Script-only imports import code try: import readline import rlcompleter
python
{ "resource": "" }
q9713
RemoteConsole.send
train
def send(self, data): """ Tries to send data to the client. :param data: Data to be sent :return: True if the data was sent, False on error """ if data is not None: data = data.encode("UTF-8") try: self.wfile.write(data) self.wfile.flush() return True except IOError:
python
{ "resource": "" }
q9714
RemoteConsole.handle
train
def handle(self): """ Handles a TCP client """ _logger.info( "RemoteConsole client connected: [%s]:%d", self.client_address[0], self.client_address[1], ) # Prepare the session session = beans.ShellSession( beans.IOHandler(self.rfile, self.wfile), {"remote_client_ip": self.client_address[0]}, ) # Print the banner def get_ps1(): """ Gets the prompt string from the session of the shell service :return: The prompt string """ try: return session.get("PS1") except KeyError: return self._shell.get_ps1() self.send(self._shell.get_banner()) self.send(get_ps1()) try: while self._active.get_value(): # Wait for data rlist = select([self.connection], [], [], .5)[0] if not rlist: # Nothing to do (poll timed out) continue data = self.rfile.readline() if not data: # End of stream (client gone) break # Strip the line line = data.strip() if not data: # Empty line continue # Execute it try: self._shell.handle_line(line, session) except KeyboardInterrupt: # Stop there
python
{ "resource": "" }
q9715
ThreadingTCPServerFamily.get_request
train
def get_request(self): """ Accepts a new client. Sets up SSL wrapping if necessary. :return: A tuple: (client socket, client address tuple) """ # Accept the client client_socket, client_address = self.socket.accept() if ssl is not None and self.cert_file: # Setup an SSL context to accept clients with a certificate # signed by a known chain of authority. # Other clients will be rejected during handshake. context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) try: # Force a valid/signed client-side certificate context.verify_mode = ssl.CERT_REQUIRED # Load the server certificate context.load_cert_chain( certfile=self.cert_file,
python
{ "resource": "" }
q9716
ThreadingTCPServerFamily.process_request
train
def process_request(self, request, client_address): """ Starts a new thread to process the request, adding the client address in its name. """ thread = threading.Thread( name="RemoteShell-{0}-Client-{1}".format( self.server_address[1], client_address[:2]
python
{ "resource": "" }
q9717
_HTTPServletRequest.get_header
train
def get_header(self, name, default=None): """ Retrieves the value of a header """
python
{ "resource": "" }
q9718
_HTTPServletResponse.end_headers
train
def end_headers(self): """ Ends the headers part """ # Send them all at once for name, value in self._headers.items():
python
{ "resource": "" }
q9719
_RequestHandler.log_error
train
def log_error(self, message, *args, **kwargs): # pylint: disable=W0221 """ Log server error """
python
{ "resource": "" }
q9720
_RequestHandler.log_request
train
def log_request(self, code="-", size="-"): """ Logs a request to the server """
python
{ "resource": "" }
q9721
_RequestHandler.send_no_servlet_response
train
def send_no_servlet_response(self): """ Default response sent when no servlet is found for the requested path """ # Use the helper to send the error page response =
python
{ "resource": "" }
q9722
_RequestHandler.send_exception
train
def send_exception(self, response): """ Sends an exception page with a 500 error code. Must be called from inside the exception handling block. :param response: The response handler """
python
{ "resource": "" }
q9723
_HttpServerFamily.server_bind
train
def server_bind(self): """ Override server_bind to store the server name, even in IronPython. See https://ironpython.codeplex.com/workitem/29477 """ TCPServer.server_bind(self) host, port = self.socket.getsockname()[:2] self.server_port = port try:
python
{ "resource": "" }
q9724
encode_list
train
def encode_list(key, list_): # type: (str, Iterable) -> Dict[str, str] """ Converts a list into a space-separated string and puts it in a dictionary :param key: Dictionary key to store the list :param
python
{ "resource": "" }
q9725
package_name
train
def package_name(package): # type: (str) -> str """ Returns the package name of the given module name """ if not package:
python
{ "resource": "" }
q9726
encode_osgi_props
train
def encode_osgi_props(ed): # type: (EndpointDescription) -> Dict[str, str] """ Prepares a dictionary of OSGi properties for the given EndpointDescription """ result_props = {} intfs = ed.get_interfaces() result_props[OBJECTCLASS] = " ".join(intfs) for intf in intfs: pkg_name = package_name(intf) ver = ed.get_package_version(pkg_name) if ver and not ver == (0, 0, 0): result_props[ENDPOINT_PACKAGE_VERSION_] = ".".join( str(v) for v in ver ) result_props[ENDPOINT_ID] = ed.get_id() result_props[ENDPOINT_SERVICE_ID] = "{0}".format(ed.get_service_id()) result_props[ENDPOINT_FRAMEWORK_UUID] = ed.get_framework_uuid() imp_configs = ed.get_imported_configs() if imp_configs: result_props[SERVICE_IMPORTED_CONFIGS] = " ".join( ed.get_imported_configs()
python
{ "resource": "" }
q9727
decode_list
train
def decode_list(input_props, name): # type: (Dict[str, str], str) -> List[str] """ Decodes a space-separated list """
python
{ "resource": "" }
q9728
decode_osgi_props
train
def decode_osgi_props(input_props): # type: (Dict[str, Any]) -> Dict[str, Any] """ Decodes the OSGi properties of the given endpoint properties """ result_props = {} intfs = decode_list(input_props, OBJECTCLASS) result_props[OBJECTCLASS] = intfs for intf in intfs: package_key = ENDPOINT_PACKAGE_VERSION_ + package_name(intf) intfversionstr = input_props.get(package_key, None) if intfversionstr: result_props[package_key] = intfversionstr result_props[ENDPOINT_ID] = input_props[ENDPOINT_ID] result_props[ENDPOINT_SERVICE_ID] = input_props[ENDPOINT_SERVICE_ID] result_props[ENDPOINT_FRAMEWORK_UUID] = input_props[ENDPOINT_FRAMEWORK_UUID] imp_configs = decode_list(input_props, SERVICE_IMPORTED_CONFIGS) if imp_configs:
python
{ "resource": "" }
q9729
decode_endpoint_props
train
def decode_endpoint_props(input_props): # type: (Dict) -> Dict[str, Any] """ Decodes the endpoint properties from the given dictionary """ ed_props = decode_osgi_props(input_props) ed_props[ECF_ENDPOINT_CONTAINERID_NAMESPACE] = input_props[ ECF_ENDPOINT_CONTAINERID_NAMESPACE ] ed_props[ECF_RSVC_ID] = int(input_props[ECF_RSVC_ID]) ed_props[ECF_ENDPOINT_ID] = input_props[ECF_ENDPOINT_ID] ed_props[ECF_ENDPOINT_TIMESTAMP] = int(input_props[ECF_ENDPOINT_TIMESTAMP]) target_id = input_props.get(ECF_ENDPOINT_CONNECTTARGET_ID, None) if target_id: ed_props[ECF_ENDPOINT_CONNECTTARGET_ID] = target_id id_filters = decode_list(input_props, ECF_ENDPOINT_IDFILTER_IDS) if id_filters: ed_props[ECF_ENDPOINT_IDFILTER_IDS] = id_filters rs_filter = input_props.get(ECF_ENDPOINT_REMOTESERVICE_FILTER, None) if rs_filter: ed_props[ECF_ENDPOINT_REMOTESERVICE_FILTER] = rs_filter async_intfs = input_props.get(ECF_SERVICE_EXPORTED_ASYNC_INTERFACES, None) if async_intfs:
python
{ "resource": "" }
q9730
encode_endpoint_props
train
def encode_endpoint_props(ed): """ Encodes the properties of the given EndpointDescription """ props = encode_osgi_props(ed) props[ECF_RSVC_ID] = "{0}".format(ed.get_remoteservice_id()[1]) props[ECF_ENDPOINT_ID] = "{0}".format(ed.get_container_id()[1]) props[ECF_ENDPOINT_CONTAINERID_NAMESPACE] = "{0}".format( ed.get_container_id()[0] ) props[ECF_ENDPOINT_TIMESTAMP] = "{0}".format(ed.get_timestamp()) ctid = ed.get_connect_target_id()
python
{ "resource": "" }
q9731
EndpointDescription.is_same_service
train
def is_same_service(self, endpoint): # type: (EndpointDescription) -> bool """ Tests if this endpoint and the given one have the same framework UUID and service ID :param endpoint: Another endpoint :return: True if both endpoints represent the same remote service
python
{ "resource": "" }
q9732
MqttClient.generate_id
train
def generate_id(cls, prefix="pelix-"): """ Generates a random MQTT client ID :param prefix: Client ID prefix (truncated to 8 chars) :return: A client ID of 22 or 23 characters """ if not prefix: # Normalize string prefix = "" else: # Truncate long prefixes prefix = prefix[:8] # Prepare the missing part nb_bytes = (23 - len(prefix)) // 2 random_bytes = os.urandom(nb_bytes) if sys.version_info[0] >=
python
{ "resource": "" }
q9733
MqttClient.set_will
train
def set_will(self, topic, payload, qos=0, retain=False): """ Sets up the will message :param topic: Topic of the will message :param payload: Content of the message :param qos: Quality of Service :param retain: The message will be retained
python
{ "resource": "" }
q9734
MqttClient.connect
train
def connect(self, host="localhost", port=1883, keepalive=60): """ Connects to the MQTT server. The client will automatically try to reconnect to this server when the connection is lost. :param host: MQTT server host :param port: MQTT server port :param keepalive: Maximum period in seconds between communications with the broker :raise ValueError: Invalid host or port """
python
{ "resource": "" }
q9735
MqttClient.disconnect
train
def disconnect(self): """ Disconnects from the MQTT server """ # Stop the timer self.__stop_timer() # Unlock all publishers for event in self.__in_flight.values(): event.set() # Disconnect from the server self.__mqtt.disconnect()
python
{ "resource": "" }
q9736
MqttClient.publish
train
def publish(self, topic, payload, qos=0, retain=False, wait=False): """ Sends a message through the MQTT connection :param topic: Message topic :param payload: Message content :param qos: Quality of Service :param retain: Retain flag :param wait: If True, prepares an event to wait for the message to be published :return: The local message ID, None on error """ result = self.__mqtt.publish(topic, payload, qos, retain)
python
{ "resource": "" }
q9737
MqttClient.__start_timer
train
def __start_timer(self, delay): """ Starts the reconnection timer :param delay: Delay (in seconds) before calling the reconnection method """
python
{ "resource": "" }
q9738
MqttClient.__reconnect
train
def __reconnect(self): """ Tries to connect to the MQTT server """ # Cancel the timer, if any self.__stop_timer() try: # Try to reconnect the server result_code = self.__mqtt.reconnect() if result_code: # Something wrong happened message = "Error connecting the MQTT server: {0} ({1})".format( result_code, paho.error_string(result_code) ) _logger.error(message)
python
{ "resource": "" }
q9739
MqttClient.__on_connect
train
def __on_connect(self, client, userdata, flags, result_code): # pylint: disable=W0613 """ Client connected to the server :param client: Connected Paho client :param userdata: User data (unused) :param flags: Response flags sent by the broker :param result_code: Connection result code (0: success, others: error) """ if result_code:
python
{ "resource": "" }
q9740
MqttClient.__on_disconnect
train
def __on_disconnect(self, client, userdata, result_code): # pylint: disable=W0613 """ Client has been disconnected from the server :param client: Client that received the message :param userdata: User data (unused) :param result_code: Disconnection reason (0: expected, 1: error) """ if result_code: # rc != 0: unexpected disconnection _logger.error( "Unexpected disconnection from the MQTT server: %s (%d)", paho.connack_string(result_code), result_code,
python
{ "resource": "" }
q9741
MqttClient.__on_message
train
def __on_message(self, client, userdata, msg): # pylint: disable=W0613 """ A message has been received from a server :param client: Client that received the message :param userdata: User data (unused) :param msg: A MQTTMessage bean """ # Notify the
python
{ "resource": "" }
q9742
MqttClient.__on_publish
train
def __on_publish(self, client, userdata, mid): # pylint: disable=W0613 """ A message has been published by a server :param client: Client that received the message :param userdata: User data
python
{ "resource": "" }
q9743
to_import_properties
train
def to_import_properties(properties): # type: (dict) -> dict """ Returns a dictionary where export properties have been replaced by import ones :param properties: A dictionary of service properties (with export keys) :return: A dictionary with import properties """ # Copy the given dictionary props = properties.copy() # Add the "imported" property props[pelix.remote.PROP_IMPORTED] = True # Remote service ID try: props[pelix.remote.PROP_ENDPOINT_SERVICE_ID] = props.pop( pelix.constants.SERVICE_ID ) except KeyError: # No service ID pass # Replace the
python
{ "resource": "" }
q9744
compute_exported_specifications
train
def compute_exported_specifications(svc_ref): # type: (pelix.framework.ServiceReference) -> List[str] """ Computes the list of specifications exported by the given service :param svc_ref: A ServiceReference :return: The list of exported specifications (or an empty list) """ if svc_ref.get_property(pelix.remote.PROP_EXPORT_NONE): # The export of this service is explicitly forbidden, stop here return [] # Service specifications specs = svc_ref.get_property(pelix.constants.OBJECTCLASS) # Exported specifications exported_specs = svc_ref.get_property(pelix.remote.PROP_EXPORTED_INTERFACES) if exported_specs and exported_specs != "*": # A set of specifications is exported, replace "objectClass" iterable_exports = pelix.utilities.to_iterable(exported_specs, False) all_exported_specs = [ spec for spec in specs if spec in iterable_exports
python
{ "resource": "" }
q9745
format_specifications
train
def format_specifications(specifications): # type: (Iterable[str]) -> List[str] """ Transforms the interfaces names into URI strings, with the interface implementation language as a scheme. :param specifications: Specifications to transform :return: The transformed names """ transformed = set() for original in specifications:
python
{ "resource": "" }
q9746
ExportEndpoint.get_properties
train
def get_properties(self): # type: () -> dict """ Returns merged properties :return: Endpoint merged properties """ # Get service properties properties = self.__reference.get_properties() # Merge with local properties properties.update(self.__properties) # Some properties can't be merged for key
python
{ "resource": "" }
q9747
ExportEndpoint.make_import_properties
train
def make_import_properties(self): # type: () -> dict """ Returns the properties of this endpoint where export properties have been replaced by import ones :return: A dictionary with import properties """ # Convert merged properties
python
{ "resource": "" }
q9748
EndpointDescription.__check_properties
train
def __check_properties(props): # type: (dict) -> None """ Checks that the given dictionary doesn't have export keys and has import keys :param props: Properties to validate :raise ValueError: Invalid properties """ # Mandatory properties mandatory = ( pelix.remote.PROP_ENDPOINT_ID, pelix.remote.PROP_IMPORTED_CONFIGS, pelix.constants.OBJECTCLASS, ) for key in mandatory: if key not in props:
python
{ "resource": "" }
q9749
EndpointDescription.matches
train
def matches(self, ldap_filter): # type: (Any[str, pelix.ldapfilter.LDAPFilter]) -> bool """ Tests the properties of this EndpointDescription against the given filter :param ldap_filter: A filter :return: True if
python
{ "resource": "" }
q9750
EndpointDescription.to_import
train
def to_import(self): # type: () -> ImportEndpoint """ Converts an EndpointDescription bean to an ImportEndpoint :return: An ImportEndpoint bean """ # Properties properties = self.get_properties() # Framework UUID fw_uid = self.get_framework_uuid() # Endpoint name try: # From Pelix UID name = properties[pelix.remote.PROP_ENDPOINT_NAME] except KeyError: # Generated name = "{0}.{1}".format(fw_uid, self.get_service_id())
python
{ "resource": "" }
q9751
EndpointDescription.from_export
train
def from_export(cls, endpoint): # type: (ExportEndpoint) -> EndpointDescription """ Converts an ExportEndpoint bean to an EndpointDescription :param endpoint: An ExportEndpoint bean :return: An EndpointDescription bean """ assert isinstance(endpoint, ExportEndpoint) # Service properties properties = endpoint.get_properties() # Set import keys properties[pelix.remote.PROP_ENDPOINT_ID] = endpoint.uid properties[pelix.remote.PROP_IMPORTED_CONFIGS] = endpoint.configurations properties[ pelix.remote.PROP_EXPORTED_INTERFACES ] = endpoint.specifications # Remove export keys for key in ( pelix.remote.PROP_EXPORTED_CONFIGS,
python
{ "resource": "" }
q9752
EDEFReader._parse_description
train
def _parse_description(self, node): # type: (ElementTree.Element) -> EndpointDescription """ Parse an endpoint description node :param node: The endpoint description node :return: The parsed EndpointDescription bean :raise KeyError: Attribute missing :raise ValueError: Invalid description """
python
{ "resource": "" }
q9753
EDEFReader._parse_property
train
def _parse_property(self, node): # type: (ElementTree.Element) -> Tuple[str, Any] """ Parses a property node :param node: The property node :return: A (name, value) tuple :raise KeyError: Attribute missing """ # Get information name = node.attrib[ATTR_NAME] vtype = node.attrib.get(ATTR_VALUE_TYPE, TYPE_STRING) # Look for a value as a single child node try: value_node = next(iter(node))
python
{ "resource": "" }
q9754
EDEFReader._parse_value_node
train
def _parse_value_node(self, vtype, node): # type: (str, ElementTree.Element) -> Any """ Parses a value node :param vtype: The value type :param node: The value node :return: The parsed value """ kind = node.tag if kind == TAG_XML: # Raw XML value return next(iter(node)) elif kind == TAG_LIST or kind == TAG_ARRAY: # List return [ self._convert_value(vtype, value_node.text)
python
{ "resource": "" }
q9755
EDEFReader.parse
train
def parse(self, xml_str): # type: (str) -> List[EndpointDescription] """ Parses an EDEF XML string :param xml_str: An XML string :return: The list of parsed EndpointDescription """ # Parse the document root = ElementTree.fromstring(xml_str) if root.tag != TAG_ENDPOINT_DESCRIPTIONS:
python
{ "resource": "" }
q9756
EDEFWriter._make_endpoint
train
def _make_endpoint(self, root_node, endpoint): # type: (ElementTree.Element, EndpointDescription) -> None """ Converts the given endpoint bean to an XML Element :param root_node: The XML root Element :param endpoint: An EndpointDescription bean """ endpoint_node = ElementTree.SubElement( root_node, TAG_ENDPOINT_DESCRIPTION ) for name, value in endpoint.get_properties().items(): # Compute value type vtype = self._get_type(name, value) # Prepare the property node prop_node = ElementTree.SubElement( endpoint_node, TAG_PROPERTY, {ATTR_NAME: name} ) if vtype == XML_VALUE: # Special case, we have to store the value as a child # without a value-type attribute prop_node.append(value) continue # Set the value type prop_node.set(ATTR_VALUE_TYPE,
python
{ "resource": "" }
q9757
EDEFWriter._make_xml
train
def _make_xml(self, endpoints): # type: (List[EndpointDescription]) -> ElementTree.Element """ Converts the given endpoint description beans into an XML Element :param endpoints: A list of EndpointDescription beans :return: A string containing an XML document """ root
python
{ "resource": "" }
q9758
EDEFWriter.write
train
def write(self, endpoints, filename): # type: (List[EndpointDescription], str) -> None """ Writes the given endpoint descriptions to the given file :param endpoints:
python
{ "resource": "" }
q9759
is_from_parent
train
def is_from_parent(cls, attribute_name, value=None): # type: (type, str, bool) -> bool """ Tests if the current attribute value is shared by a parent of the given class. Returns None if the attribute value is None. :param cls: Child class with the requested attribute :param attribute_name: Name of the attribute to be tested :param value: The exact value in the child class (optional) :return: True if the attribute value is shared with a parent class """ if value is None: try: # Get the current value value = getattr(cls, attribute_name)
python
{ "resource": "" }
q9760
get_factory_context
train
def get_factory_context(cls): # type: (type) -> FactoryContext """ Retrieves the factory context object associated to a factory. Creates it if needed :param cls: The factory class :return: The factory class context """ context = getattr(cls, constants.IPOPO_FACTORY_CONTEXT, None) if context is None:
python
{ "resource": "" }
q9761
get_method_description
train
def get_method_description(method): # type: (Callable) -> str """ Retrieves a description of the given method. If possible, the description contains the source file name and line. :param method: A method :return: A description of the method (at least its name) :raise AttributeError: Given object has no __name__ attribute """ try: try: line_no = inspect.getsourcelines(method)[1] except IOError: # Error reading the source file
python
{ "resource": "" }
q9762
validate_method_arity
train
def validate_method_arity(method, *needed_args): # type: (Callable, *str) -> None """ Tests if the decorated method has a sufficient number of parameters. :param method: The method to be tested :param needed_args: The name (for description only) of the needed arguments, without "self". :return: Nothing :raise TypeError: Invalid number of parameter """ nb_needed_args = len(needed_args) # Test the number of parameters arg_spec = get_method_arguments(method) method_args = arg_spec.args try: # Remove the self argument when present if method_args[0] == "self": del method_args[0] except IndexError: pass nb_args = len(method_args) if arg_spec.varargs is not None: # Variable arguments if nb_args != 0: # Other arguments detected raise TypeError( "When using '*args', the decorated {0} method must only " "accept the
python
{ "resource": "" }
q9763
_ipopo_setup_callback
train
def _ipopo_setup_callback(cls, context): # type: (type, FactoryContext) -> None """ Sets up the class _callback dictionary :param cls: The class to handle :param context: The factory class context """ assert inspect.isclass(cls) assert isinstance(context, FactoryContext) if context.callbacks is not None: callbacks = context.callbacks.copy() else: callbacks = {} functions = inspect.getmembers(cls, inspect.isroutine) for _, func in functions: if not hasattr(func, constants.IPOPO_METHOD_CALLBACKS): # No attribute, get the next member continue method_callbacks = getattr(func, constants.IPOPO_METHOD_CALLBACKS) if not isinstance(method_callbacks, list): # Invalid content _logger.warning( "Invalid callback information %s in %s", constants.IPOPO_METHOD_CALLBACKS, get_method_description(func), ) continue # Keeping it allows inheritance : by removing it, only the first # child will see the attribute
python
{ "resource": "" }
q9764
_ipopo_setup_field_callback
train
def _ipopo_setup_field_callback(cls, context): # type: (type, FactoryContext) -> None """ Sets up the class _field_callback dictionary :param cls: The class to handle :param context: The factory class context """ assert inspect.isclass(cls) assert isinstance(context, FactoryContext) if context.field_callbacks is not None: callbacks = context.field_callbacks.copy() else: callbacks = {} functions = inspect.getmembers(cls, inspect.isroutine) for name, func in functions: if not hasattr(func, constants.IPOPO_METHOD_FIELD_CALLBACKS): # No attribute, get the next member continue method_callbacks = getattr(func, constants.IPOPO_METHOD_FIELD_CALLBACKS) if not isinstance(method_callbacks, list): # Invalid content _logger.warning( "Invalid attribute %s in %s", constants.IPOPO_METHOD_FIELD_CALLBACKS, name, ) continue # Keeping it allows inheritance : by removing it, only the first # child will see the attribute ->
python
{ "resource": "" }
q9765
_append_object_entry
train
def _append_object_entry(obj, list_name, entry): # type: (Any, str, Any) -> None """ Appends the given entry in the given object list. Creates the list field if needed. :param obj: The object that contains the list :param list_name: The name of the list member in *obj*
python
{ "resource": "" }
q9766
_get_specifications
train
def _get_specifications(specifications): """ Computes the list of strings corresponding to the given specifications :param specifications: A string, a class or a list of specifications :return: A list of strings :raise ValueError: Invalid specification found """ if not specifications or specifications is object: raise ValueError("No specifications given") elif inspect.isclass(specifications): if Provides.USE_MODULE_QUALNAME: if sys.version_info < (3, 3, 0): raise ValueError( "Qualified name capability requires Python 3.3+" ) # Get the name of the class if not specifications.__module__: return [specifications.__qualname__] return [ "{0}.{1}".format( specifications.__module__, specifications.__qualname__ ) ] else: # Legacy behavior
python
{ "resource": "" }
q9767
PostRegistration
train
def PostRegistration(method): # pylint: disable=C0103 """ The service post-registration callback decorator is called after a service of the component has been registered to the framework. The decorated method must accept the :class:`~pelix.framework.ServiceReference` of the registered service as argument:: @PostRegistration def callback_method(self, service_reference): ''' service_reference: The ServiceReference of the provided service ''' # ... :param method: The decorated method :raise TypeError: The decorated
python
{ "resource": "" }
q9768
PostUnregistration
train
def PostUnregistration(method): # pylint: disable=C0103 """ The service post-unregistration callback decorator is called after a service of the component has been unregistered from the framework. The decorated method must accept the :class:`~pelix.framework.ServiceReference` of the registered service as argument:: @PostUnregistration def callback_method(self, service_reference): ''' service_reference: The ServiceReference of the provided service ''' # ... :param method: The decorated method :raise TypeError: The decorated
python
{ "resource": "" }
q9769
_ShellUtils.bundlestate_to_str
train
def bundlestate_to_str(state): """ Converts a bundle state integer to a string """ states = { pelix.Bundle.INSTALLED: "INSTALLED", pelix.Bundle.ACTIVE: "ACTIVE", pelix.Bundle.RESOLVED: "RESOLVED", pelix.Bundle.STARTING: "STARTING",
python
{ "resource": "" }
q9770
_ShellUtils.make_table
train
def make_table(headers, lines, prefix=None): """ Generates an ASCII table according to the given headers and lines :param headers: List of table headers (N-tuple) :param lines: List of table lines (N-tuples) :param prefix: Optional prefix for each line :return: The ASCII representation of the table :raise ValueError: Different number of columns between headers and lines """ # Normalize the prefix prefix = str(prefix or "") # Maximum lengths lengths = [len(title) for title in headers] # Store the number of columns (0-based) nb_columns = len(lengths) - 1 # Lines str_lines = [] for idx, line in enumerate(lines): # Recompute lengths str_line = [] str_lines.append(str_line) column = -1 try: for column, entry in enumerate(line): str_entry = str(entry) str_line.append(str_entry) if len(str_entry) > lengths[column]: lengths[column] = len(str_entry) except IndexError: # Line too small/big raise ValueError( "Different sizes for header and lines " "(line {0})".format(idx + 1) ) except (TypeError, AttributeError): # Invalid type of line raise ValueError( "Invalid type of line: %s", type(line).__name__ ) else: if column != nb_columns: # Check if all lines have the same number of columns
python
{ "resource": "" }
q9771
_ShellService.bind_handler
train
def bind_handler(self, svc_ref): """ Called if a command service has been found. Registers the methods of this service. :param svc_ref: A reference to the found service :return: True if the commands have been registered """ if svc_ref in self._bound_references: # Already bound service return False # Get the service handler = self._context.get_service(svc_ref) # Get its name space namespace = handler.get_namespace() commands = [] # Register all
python
{ "resource": "" }
q9772
_ShellService.unbind_handler
train
def unbind_handler(self, svc_ref): """ Called if a command service is gone. Unregisters its commands. :param svc_ref: A reference to the unbound service :return: True if the commands have been unregistered """ if svc_ref not in self._bound_references: # Unknown reference return False # Unregister its commands namespace, commands = self._reference_commands[svc_ref] for command in commands:
python
{ "resource": "" }
q9773
_ShellService.bundle_details
train
def bundle_details(self, io_handler, bundle_id): """ Prints the details of the bundle with the given ID or name """ bundle = None try: # Convert the given ID into an integer bundle_id = int(bundle_id) except ValueError: # Not an integer, suppose it's a bundle name for bundle in self._context.get_bundles(): if bundle.get_symbolic_name() == bundle_id: break else: # Bundle not found bundle = None else: # Integer ID: direct access try: bundle = self._context.get_bundle(bundle_id) except constants.BundleException: pass if bundle is None: # No matching bundle io_handler.write_line("Unknown bundle ID: {0}", bundle_id) return False lines = [ "ID......: {0}".format(bundle.get_bundle_id()), "Name....: {0}".format(bundle.get_symbolic_name()), "Version.: {0}".format(bundle.get_version()), "State...: {0}".format( self._utils.bundlestate_to_str(bundle.get_state()) ), "Location: {0}".format(bundle.get_location()), "Published services:", ]
python
{ "resource": "" }
q9774
_ShellService.bundles_list
train
def bundles_list(self, io_handler, name=None): """ Lists the bundles in the framework and their state. Possibility to filter on the bundle name. """ # Head of the table headers = ("ID", "Name", "State", "Version") # Get the bundles bundles = self._context.get_bundles() # The framework is not in the result of get_bundles() bundles.insert(0, self._context.get_framework()) if name is not None: # Filter the list bundles = [ bundle for bundle in bundles if name in bundle.get_symbolic_name() ] # Make the entries lines = [ [ str(entry) for entry in (
python
{ "resource": "" }
q9775
_ShellService.service_details
train
def service_details(self, io_handler, service_id): """ Prints the details of the service with the given ID """ svc_ref = self._context.get_service_reference( None, "({0}={1})".format(constants.SERVICE_ID, service_id) ) if svc_ref is None: io_handler.write_line("Service not found: {0}", service_id) return False lines = [ "ID............: {0}".format( svc_ref.get_property(constants.SERVICE_ID)
python
{ "resource": "" }
q9776
_ShellService.services_list
train
def services_list(self, io_handler, specification=None): """ Lists the services in the framework. Possibility to filter on an exact specification. """ # Head of the table headers = ("ID", "Specifications", "Bundle", "Ranking") # Lines references = ( self._context.get_all_service_references(specification, None) or [] ) # Construct the list of services lines = [ [ str(entry) for entry in ( ref.get_property(constants.SERVICE_ID), ref.get_property(constants.OBJECTCLASS), ref.get_bundle(), ref.get_property(constants.SERVICE_RANKING), )
python
{ "resource": "" }
q9777
_ShellService.properties_list
train
def properties_list(self, io_handler): """ Lists the properties of the framework """ # Get the framework framework = self._context.get_framework() # Head of the table headers = ("Property Name", "Value") # Lines
python
{ "resource": "" }
q9778
_ShellService.property_value
train
def property_value(self, io_handler, name): """ Prints the value of the given property, looking into framework properties then environment
python
{ "resource": "" }
q9779
_ShellService.environment_list
train
def environment_list(self, io_handler): """ Lists the framework process environment variables """ # Head of the table headers = ("Environment Variable", "Value") # Lines lines = [item for item in os.environ.items()]
python
{ "resource": "" }
q9780
_ShellService.change_dir
train
def change_dir(self, session, path): """ Changes the working directory """ if path == "-": # Previous directory path = self._previous_path or "." try:
python
{ "resource": "" }
q9781
_ShellService.start
train
def start(self, io_handler, bundle_id, *bundles_ids): """ Starts the bundles with the given IDs. Stops on first failure. """ for bid in (bundle_id,) + bundles_ids: try: # Got an int => it's a bundle ID bid = int(bid) except ValueError: # Got something else, we will try to install it first bid = self.install(io_handler, bid) bundle = self.__get_bundle(io_handler, bid) if
python
{ "resource": "" }
q9782
_ShellService.stop
train
def stop(self, io_handler, bundle_id, *bundles_ids): """ Stops the bundles with the given IDs. Stops on first failure. """ for bid in (bundle_id,) + bundles_ids: bundle = self.__get_bundle(io_handler, bid) if bundle is not None: io_handler.write_line( "Stopping bundle {0} ({1})...",
python
{ "resource": "" }
q9783
_ShellService.install
train
def install(self, io_handler, module_name): """ Installs the bundle with the given module name """ bundle = self._context.install_bundle(module_name)
python
{ "resource": "" }
q9784
TemporalDependency.__cancel_timer
train
def __cancel_timer(self): """ Cancels the timer, and calls its target method immediately """ if self.__timer is not None: self.__timer.cancel()
python
{ "resource": "" }
q9785
TemporalDependency.__unbind_call
train
def __unbind_call(self, still_valid): """ Calls the iPOPO unbind method """ with self._lock: if self.__timer is not None: # Timeout expired, we're not valid anymore self.__timer = None
python
{ "resource": "" }
q9786
_JabsorbRpcServlet.do_POST
train
def do_POST(self, request, response): # pylint: disable=C0103 """ Handle a POST request :param request: The HTTP request bean :param response: The HTTP response handler """ # Get the request JSON content data = jsonrpclib.loads(to_str(request.read_data())) # Convert from Jabsorb data = jabsorb.from_jabsorb(data) # Dispatch try: result = self._unmarshaled_dispatch(data, self._simple_dispatch) except NoMulticallResult: # No result (never happens, but who knows...) result = None
python
{ "resource": "" }
q9787
RestDispatcher._rest_dispatch
train
def _rest_dispatch(self, request, response): # type: (AbstractHTTPServletRequest, AbstractHTTPServletResponse) -> None """ Dispatches the request :param request: Request bean :param response: Response bean """ # Extract request information http_verb = request.get_command() sub_path = request.get_sub_path() # Find the best matching method, according to the number of # readable arguments max_valid_args = -1 best_method = None best_args = None best_match = None for route, method in self.__routes.get(http_verb, {}).items(): # Parse the request path match = route.match(sub_path) if not match: continue # Count the number of valid arguments method_args = self.__methods_args[method] nb_valid_args = 0 for name in method_args: try: match.group(name) nb_valid_args += 1 except IndexError: # Argument not found pass if nb_valid_args > max_valid_args: # Found a better match max_valid_args = nb_valid_args best_method = method best_args = method_args best_match = match if best_method is None: # No match: return a 404 plain text error response.send_content( 404, "No method to handle path {0}".format(sub_path), "text/plain", ) else: # Found a method # ... convert arguments kwargs = {} if best_args: for name, converter in best_args.items(): try:
python
{ "resource": "" }
q9788
RestDispatcher._setup_rest_dispatcher
train
def _setup_rest_dispatcher(self): """ Finds all methods to call when handling a route """ for _, method in inspect.getmembers(self, inspect.isroutine): try: config = getattr(method, HTTP_ROUTE_ATTRIBUTE) except AttributeError: # Not a REST method continue for route in config["routes"]:
python
{ "resource": "" }
q9789
StoredInstance.check_event
train
def check_event(self, event): # type: (ServiceEvent) -> bool """ Tests if the given service event must be handled or ignored, based on the state of the iPOPO service and on the content of the event. :param event: A service event
python
{ "resource": "" }
q9790
StoredInstance.bind
train
def bind(self, dependency, svc, svc_ref): # type: (Any, Any, ServiceReference) -> None """ Called by a dependency manager to inject a new service and update the component life cycle. """
python
{ "resource": "" }
q9791
StoredInstance.update
train
def update(self, dependency, svc, svc_ref, old_properties, new_value=False): # type: (Any, Any, ServiceReference, dict, bool) -> None """ Called by a dependency manager when the properties of an injected dependency have been updated. :param dependency: The dependency handler :param svc: The injected service :param svc_ref: The reference of the injected service
python
{ "resource": "" }
q9792
StoredInstance.unbind
train
def unbind(self, dependency, svc, svc_ref): # type: (Any, Any, ServiceReference) -> None """ Called by a dependency manager to remove an injected service and to update the component life cycle.
python
{ "resource": "" }
q9793
StoredInstance.set_controller_state
train
def set_controller_state(self, name, value): # type: (str, bool) -> None """ Sets the state of the controller with the given name :param name: The name of the controller :param value: The new value of the controller """
python
{ "resource": "" }
q9794
StoredInstance.update_property
train
def update_property(self, name, old_value, new_value): # type: (str, Any, Any) -> None """ Handles a property changed event :param name: The changed property name :param old_value: The previous property value :param new_value: The new property value
python
{ "resource": "" }
q9795
StoredInstance.update_hidden_property
train
def update_hidden_property(self, name, old_value, new_value): # type: (str, Any, Any) -> None """ Handles an hidden property changed event :param name: The changed property name :param old_value: The previous property value :param new_value: The new property value
python
{ "resource": "" }
q9796
StoredInstance.get_handlers
train
def get_handlers(self, kind=None): """ Retrieves the handlers of the given kind. If kind is None, all handlers are returned. :param kind: The kind of the handlers to return :return: A list of handlers, or an empty list """ with self._lock: if kind is not None: try:
python
{ "resource": "" }
q9797
StoredInstance.check_lifecycle
train
def check_lifecycle(self): """ Tests if the state of the component must be updated, based on its own state and on the state of its dependencies """ with self._lock: # Validation flags was_valid = self.state == StoredInstance.VALID can_validate = self.state not in ( StoredInstance.VALIDATING, StoredInstance.VALID, ) # Test the validity of all handlers handlers_valid = self.__safe_handlers_callback(
python
{ "resource": "" }
q9798
StoredInstance.update_bindings
train
def update_bindings(self): # type: () -> bool """ Updates the bindings of the given component :return: True if the component can be validated """ with self._lock: all_valid = True for handler in self.get_handlers(handlers_const.KIND_DEPENDENCY): # Try to bind
python
{ "resource": "" }
q9799
StoredInstance.retry_erroneous
train
def retry_erroneous(self, properties_update): # type: (dict) -> int """ Removes the ERRONEOUS state from a component and retries a validation :param properties_update: A dictionary to update component properties :return: The new state of the component """ with self._lock: if self.state != StoredInstance.ERRONEOUS: # Not in erroneous state: ignore return self.state # Update properties if
python
{ "resource": "" }