id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
9,700
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromexportreg
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, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, None, exc, export_reg.get_description(), ) return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_REGISTRATION, bundle, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, export_reg.get_export_reference(), None, export_reg.get_description(), )
python
def fromexportreg(cls, bundle, export_reg): # type: (Bundle, ExportRegistration) -> RemoteServiceAdminEvent exc = export_reg.get_exception() if exc: return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_ERROR, bundle, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, None, exc, export_reg.get_description(), ) return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_REGISTRATION, bundle, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, export_reg.get_export_reference(), None, export_reg.get_description(), )
[ "def", "fromexportreg", "(", "cls", ",", "bundle", ",", "export_reg", ")", ":", "# type: (Bundle, ExportRegistration) -> RemoteServiceAdminEvent", "exc", "=", "export_reg", ".", "get_exception", "(", ")", "if", "exc", ":", "return", "RemoteServiceAdminEvent", "(", "Re...
Creates a RemoteServiceAdminEvent object from an ExportRegistration
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "an", "ExportRegistration" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L799-L826
9,701
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromexportupdate
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, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, export_reg.get_export_reference(), None, export_reg.get_description(), ) return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_UPDATE, bundle, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, export_reg.get_export_reference(), None, export_reg.get_description(), )
python
def fromexportupdate(cls, bundle, export_reg): # type: (Bundle, ExportRegistration) -> RemoteServiceAdminEvent exc = export_reg.get_exception() if exc: return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_ERROR, bundle, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, export_reg.get_export_reference(), None, export_reg.get_description(), ) return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_UPDATE, bundle, export_reg.get_export_container_id(), export_reg.get_remoteservice_id(), None, export_reg.get_export_reference(), None, export_reg.get_description(), )
[ "def", "fromexportupdate", "(", "cls", ",", "bundle", ",", "export_reg", ")", ":", "# type: (Bundle, ExportRegistration) -> RemoteServiceAdminEvent", "exc", "=", "export_reg", ".", "get_exception", "(", ")", "if", "exc", ":", "return", "RemoteServiceAdminEvent", "(", ...
Creates a RemoteServiceAdminEvent object from the update of an ExportRegistration
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "the", "update", "of", "an", "ExportRegistration" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L829-L857
9,702
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromimportupdate
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( RemoteServiceAdminEvent.IMPORT_UPDATE, bundle, import_reg.get_import_container_id(), import_reg.get_remoteservice_id(), import_reg.get_import_reference(), None, None, import_reg.get_description(), )
python
def fromimportupdate(cls, bundle, import_reg): # type: (Bundle, ImportRegistration) -> RemoteServiceAdminEvent 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( RemoteServiceAdminEvent.IMPORT_UPDATE, bundle, import_reg.get_import_container_id(), import_reg.get_remoteservice_id(), import_reg.get_import_reference(), None, None, import_reg.get_description(), )
[ "def", "fromimportupdate", "(", "cls", ",", "bundle", ",", "import_reg", ")", ":", "# type: (Bundle, ImportRegistration) -> RemoteServiceAdminEvent", "exc", "=", "import_reg", ".", "get_exception", "(", ")", "if", "exc", ":", "return", "RemoteServiceAdminEvent", "(", ...
Creates a RemoteServiceAdminEvent object from the update of an ImportRegistration
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "the", "update", "of", "an", "ImportRegistration" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L860-L888
9,703
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromimportunreg
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 """ return RemoteServiceAdminEvent( typ=RemoteServiceAdminEvent.IMPORT_UNREGISTRATION, bundle=bundle, cid=cid, rsid=rsid, import_ref=import_ref, exception=exception, endpoint=endpoint, )
python
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 return RemoteServiceAdminEvent( typ=RemoteServiceAdminEvent.IMPORT_UNREGISTRATION, bundle=bundle, cid=cid, rsid=rsid, import_ref=import_ref, exception=exception, endpoint=endpoint, )
[ "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) -> R...
Creates a RemoteServiceAdminEvent object from the departure of an ImportRegistration
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "the", "departure", "of", "an", "ImportRegistration" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L891-L907
9,704
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromexportunreg
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 """ return RemoteServiceAdminEvent( typ=RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, bundle=bundle, cid=exporterid, rsid=rsid, export_ref=export_ref, exception=exception, endpoint=endpoint, )
python
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 return RemoteServiceAdminEvent( typ=RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, bundle=bundle, cid=exporterid, rsid=rsid, export_ref=export_ref, exception=exception, endpoint=endpoint, )
[ "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]], EndpointDescriptio...
Creates a RemoteServiceAdminEvent object from the departure of an ExportRegistration
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "the", "departure", "of", "an", "ExportRegistration" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L910-L926
9,705
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromimporterror
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 """ return RemoteServiceAdminEvent( RemoteServiceAdminEvent.IMPORT_ERROR, bundle, importerid, rsid, None, None, exception, endpoint, )
python
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 return RemoteServiceAdminEvent( RemoteServiceAdminEvent.IMPORT_ERROR, bundle, importerid, rsid, None, None, exception, endpoint, )
[ "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", "retur...
Creates a RemoteServiceAdminEvent object from an import error
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "an", "import", "error" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L929-L943
9,706
tcalmant/ipopo
pelix/rsa/__init__.py
RemoteServiceAdminEvent.fromexporterror
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 """ return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_ERROR, bundle, exporterid, rsid, None, None, exception, endpoint, )
python
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 return RemoteServiceAdminEvent( RemoteServiceAdminEvent.EXPORT_ERROR, bundle, exporterid, rsid, None, None, exception, endpoint, )
[ "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", "retur...
Creates a RemoteServiceAdminEvent object from an export error
[ "Creates", "a", "RemoteServiceAdminEvent", "object", "from", "an", "export", "error" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/__init__.py#L946-L960
9,707
tcalmant/ipopo
pelix/ipopo/waiting.py
IPopoWaitingList._try_instantiate
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] except KeyError: # Component not in queue return else: try: # Try instantiation ipopo.instantiate(factory, component, properties) except TypeError: # Unknown factory: try later pass except ValueError as ex: # Already known component _logger.error("Component already running: %s", ex) except Exception as ex: # Other error _logger.exception("Error instantiating component: %s", ex)
python
def _try_instantiate(self, ipopo, factory, component): # type: (Any, str, str) -> None try: # Get component properties with self.__lock: properties = self.__queue[factory][component] except KeyError: # Component not in queue return else: try: # Try instantiation ipopo.instantiate(factory, component, properties) except TypeError: # Unknown factory: try later pass except ValueError as ex: # Already known component _logger.error("Component already running: %s", ex) except Exception as ex: # Other error _logger.exception("Error instantiating component: %s", ex)
[ "def", "_try_instantiate", "(", "self", ",", "ipopo", ",", "factory", ",", "component", ")", ":", "# type: (Any, str, str) -> None", "try", ":", "# Get component properties", "with", "self", ".", "__lock", ":", "properties", "=", "self", ".", "__queue", "[", "fa...
Tries to instantiate a component from the queue. Hides all exceptions. :param ipopo: The iPOPO service :param factory: Component factory :param component: Component name
[ "Tries", "to", "instantiate", "a", "component", "from", "the", "queue", ".", "Hides", "all", "exceptions", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/waiting.py#L93-L121
9,708
tcalmant/ipopo
pelix/ipopo/waiting.py
IPopoWaitingList.service_changed
def service_changed(self, event): # type: (ServiceEvent) -> None """ Handles an event about the iPOPO service """ kind = event.get_kind() if kind == ServiceEvent.REGISTERED: # iPOPO service registered: register to factory events with use_ipopo(self.__context) as ipopo: ipopo.add_listener(self)
python
def service_changed(self, event): # type: (ServiceEvent) -> None kind = event.get_kind() if kind == ServiceEvent.REGISTERED: # iPOPO service registered: register to factory events with use_ipopo(self.__context) as ipopo: ipopo.add_listener(self)
[ "def", "service_changed", "(", "self", ",", "event", ")", ":", "# type: (ServiceEvent) -> None", "kind", "=", "event", ".", "get_kind", "(", ")", "if", "kind", "==", "ServiceEvent", ".", "REGISTERED", ":", "# iPOPO service registered: register to factory events", "wit...
Handles an event about the iPOPO service
[ "Handles", "an", "event", "about", "the", "iPOPO", "service" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/waiting.py#L161-L170
9,709
tcalmant/ipopo
pelix/ipopo/waiting.py
IPopoWaitingList.handle_ipopo_event
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 components = self.__queue[factory].copy() for component in components: self._try_instantiate(ipopo, factory, component) except BundleException: # iPOPO not yet started pass except KeyError: # No components for this new factory pass
python
def handle_ipopo_event(self, event): # type: (IPopoEvent) -> None 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 components = self.__queue[factory].copy() for component in components: self._try_instantiate(ipopo, factory, component) except BundleException: # iPOPO not yet started pass except KeyError: # No components for this new factory pass
[ "def", "handle_ipopo_event", "(", "self", ",", "event", ")", ":", "# type: (IPopoEvent) -> None", "kind", "=", "event", ".", "get_kind", "(", ")", "if", "kind", "==", "IPopoEvent", ".", "REGISTERED", ":", "# A factory has been registered", "try", ":", "with", "u...
Handles an iPOPO event :param event: iPOPO event bean
[ "Handles", "an", "iPOPO", "event" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/waiting.py#L172-L197
9,710
tcalmant/ipopo
pelix/ipopo/waiting.py
IPopoWaitingList.add
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 self.__queue.setdefault(factory, {})[component] = properties try: with use_ipopo(self.__context) as ipopo: # Try to instantiate the component right now self._try_instantiate(ipopo, factory, component) except BundleException: # iPOPO not yet started pass
python
def add(self, factory, component, properties=None): # type: (str, str, dict) -> None 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 self.__queue.setdefault(factory, {})[component] = properties try: with use_ipopo(self.__context) as ipopo: # Try to instantiate the component right now self._try_instantiate(ipopo, factory, component) except BundleException: # iPOPO not yet started pass
[ "def", "add", "(", "self", ",", "factory", ",", "component", ",", "properties", "=", "None", ")", ":", "# type: (str, str, dict) -> None", "with", "self", ".", "__lock", ":", "if", "component", "in", "self", ".", "__names", ":", "raise", "ValueError", "(", ...
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
[ "Enqueues", "the", "instantiation", "of", "the", "given", "component" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/waiting.py#L199-L230
9,711
tcalmant/ipopo
pelix/shell/remote.py
_create_server
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 """ # Set up the request handler creator active_flag = SharedBoolean(True) def request_handler(*rh_args): """ Constructs a RemoteConsole as TCP request handler """ return RemoteConsole(shell, active_flag, *rh_args) # Set up the server server = ThreadingTCPServerFamily( (server_address, port), request_handler, cert_file, key_file, key_password, ca_file, ) # Set flags server.daemon_threads = True server.allow_reuse_address = True # Activate the server server.server_bind() server.server_activate() # Serve clients server_thread = threading.Thread( target=server.serve_forever, name="RemoteShell-{0}".format(port) ) server_thread.daemon = True server_thread.start() return server_thread, server, active_flag
python
def _create_server( shell, server_address, port, cert_file=None, key_file=None, key_password=None, ca_file=None, ): # Set up the request handler creator active_flag = SharedBoolean(True) def request_handler(*rh_args): """ Constructs a RemoteConsole as TCP request handler """ return RemoteConsole(shell, active_flag, *rh_args) # Set up the server server = ThreadingTCPServerFamily( (server_address, port), request_handler, cert_file, key_file, key_password, ca_file, ) # Set flags server.daemon_threads = True server.allow_reuse_address = True # Activate the server server.server_bind() server.server_activate() # Serve clients server_thread = threading.Thread( target=server.serve_forever, name="RemoteShell-{0}".format(port) ) server_thread.daemon = True server_thread.start() return server_thread, server, active_flag
[ "def", "_create_server", "(", "shell", ",", "server_address", ",", "port", ",", "cert_file", "=", "None", ",", "key_file", "=", "None", ",", "key_password", "=", "None", ",", "ca_file", "=", "None", ",", ")", ":", "# Set up the request handler creator", "activ...
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
[ "Creates", "the", "TCP", "console", "on", "the", "given", "address", "and", "port" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/remote.py#L370-L425
9,712
tcalmant/ipopo
pelix/shell/remote.py
_run_interpreter
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 readline.set_completer(rlcompleter.Completer(variables).complete) readline.parse_and_bind("tab: complete") except ImportError: # readline is not available: ignore pass # Start the console shell = code.InteractiveConsole(variables) shell.interact(banner)
python
def _run_interpreter(variables, banner): # Script-only imports import code try: import readline import rlcompleter readline.set_completer(rlcompleter.Completer(variables).complete) readline.parse_and_bind("tab: complete") except ImportError: # readline is not available: ignore pass # Start the console shell = code.InteractiveConsole(variables) shell.interact(banner)
[ "def", "_run_interpreter", "(", "variables", ",", "banner", ")", ":", "# Script-only imports", "import", "code", "try", ":", "import", "readline", "import", "rlcompleter", "readline", ".", "set_completer", "(", "rlcompleter", ".", "Completer", "(", "variables", ")...
Runs a Python interpreter console and blocks until the user exits it. :param variables: Interpreters variables (locals) :param banner: Start-up banners
[ "Runs", "a", "Python", "interpreter", "console", "and", "blocks", "until", "the", "user", "exits", "it", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/remote.py#L565-L587
9,713
tcalmant/ipopo
pelix/shell/remote.py
RemoteConsole.send
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: # An error occurred, mask it # -> This allows to handle the command even if the client has been # disconnect (i.e. "echo stop 0 | nc localhost 9000") return False
python
def send(self, data): if data is not None: data = data.encode("UTF-8") try: self.wfile.write(data) self.wfile.flush() return True except IOError: # An error occurred, mask it # -> This allows to handle the command even if the client has been # disconnect (i.e. "echo stop 0 | nc localhost 9000") return False
[ "def", "send", "(", "self", ",", "data", ")", ":", "if", "data", "is", "not", "None", ":", "data", "=", "data", ".", "encode", "(", "\"UTF-8\"", ")", "try", ":", "self", ".", "wfile", ".", "write", "(", "data", ")", "self", ".", "wfile", ".", "...
Tries to send data to the client. :param data: Data to be sent :return: True if the data was sent, False on error
[ "Tries", "to", "send", "data", "to", "the", "client", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/remote.py#L138-L157
9,714
tcalmant/ipopo
pelix/shell/remote.py
RemoteConsole.handle
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 on interruption self.send("\nInterruption received.") return except IOError as ex: # I/O errors are fatal _logger.exception( "Error communicating with a client: %s", ex ) break except Exception as ex: # Other exceptions are not important import traceback self.send("\nError during last command: {0}\n".format(ex)) self.send(traceback.format_exc()) # Print the prompt self.send(get_ps1()) finally: _logger.info( "RemoteConsole client gone: [%s]:%d", self.client_address[0], self.client_address[1], ) try: # Be polite self.send("\nSession closed. Good bye.\n") self.finish() except IOError as ex: _logger.warning("Error cleaning up connection: %s", ex)
python
def handle(self): _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 on interruption self.send("\nInterruption received.") return except IOError as ex: # I/O errors are fatal _logger.exception( "Error communicating with a client: %s", ex ) break except Exception as ex: # Other exceptions are not important import traceback self.send("\nError during last command: {0}\n".format(ex)) self.send(traceback.format_exc()) # Print the prompt self.send(get_ps1()) finally: _logger.info( "RemoteConsole client gone: [%s]:%d", self.client_address[0], self.client_address[1], ) try: # Be polite self.send("\nSession closed. Good bye.\n") self.finish() except IOError as ex: _logger.warning("Error cleaning up connection: %s", ex)
[ "def", "handle", "(", "self", ")", ":", "_logger", ".", "info", "(", "\"RemoteConsole client connected: [%s]:%d\"", ",", "self", ".", "client_address", "[", "0", "]", ",", "self", ".", "client_address", "[", "1", "]", ",", ")", "# Prepare the session", "sessio...
Handles a TCP client
[ "Handles", "a", "TCP", "client" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/remote.py#L159-L243
9,715
tcalmant/ipopo
pelix/shell/remote.py
ThreadingTCPServerFamily.get_request
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, keyfile=self.key_file, password=self.key_password, ) if self.ca_file: # Load the given authority chain context.load_verify_locations(self.ca_file) else: # Load the default chain if none given context.load_default_certs(ssl.Purpose.CLIENT_AUTH) except Exception as ex: # Explicitly log the error as the default behaviour hides it _logger.error("Error setting up the SSL context: %s", ex) raise try: # SSL handshake client_stream = context.wrap_socket( client_socket, server_side=True ) except ssl.SSLError as ex: # Explicitly log the exception before re-raising it _logger.warning( "Error during SSL handshake with %s: %s", client_address, ex ) raise else: # Nothing to do, use the raw socket client_stream = client_socket return client_stream, client_address
python
def get_request(self): # 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, keyfile=self.key_file, password=self.key_password, ) if self.ca_file: # Load the given authority chain context.load_verify_locations(self.ca_file) else: # Load the default chain if none given context.load_default_certs(ssl.Purpose.CLIENT_AUTH) except Exception as ex: # Explicitly log the error as the default behaviour hides it _logger.error("Error setting up the SSL context: %s", ex) raise try: # SSL handshake client_stream = context.wrap_socket( client_socket, server_side=True ) except ssl.SSLError as ex: # Explicitly log the exception before re-raising it _logger.warning( "Error during SSL handshake with %s: %s", client_address, ex ) raise else: # Nothing to do, use the raw socket client_stream = client_socket return client_stream, client_address
[ "def", "get_request", "(", "self", ")", ":", "# Accept the client", "client_socket", ",", "client_address", "=", "self", ".", "socket", ".", "accept", "(", ")", "if", "ssl", "is", "not", "None", "and", "self", ".", "cert_file", ":", "# Setup an SSL context to ...
Accepts a new client. Sets up SSL wrapping if necessary. :return: A tuple: (client socket, client address tuple)
[ "Accepts", "a", "new", "client", ".", "Sets", "up", "SSL", "wrapping", "if", "necessary", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/remote.py#L301-L352
9,716
tcalmant/ipopo
pelix/shell/remote.py
ThreadingTCPServerFamily.process_request
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] ), target=self.process_request_thread, args=(request, client_address), ) thread.daemon = self.daemon_threads thread.start()
python
def process_request(self, request, client_address): thread = threading.Thread( name="RemoteShell-{0}-Client-{1}".format( self.server_address[1], client_address[:2] ), target=self.process_request_thread, args=(request, client_address), ) thread.daemon = self.daemon_threads thread.start()
[ "def", "process_request", "(", "self", ",", "request", ",", "client_address", ")", ":", "thread", "=", "threading", ".", "Thread", "(", "name", "=", "\"RemoteShell-{0}-Client-{1}\"", ".", "format", "(", "self", ".", "server_address", "[", "1", "]", ",", "cli...
Starts a new thread to process the request, adding the client address in its name.
[ "Starts", "a", "new", "thread", "to", "process", "the", "request", "adding", "the", "client", "address", "in", "its", "name", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/remote.py#L354-L367
9,717
tcalmant/ipopo
pelix/http/basic.py
_HTTPServletRequest.get_header
def get_header(self, name, default=None): """ Retrieves the value of a header """ return self._handler.headers.get(name, default)
python
def get_header(self, name, default=None): return self._handler.headers.get(name, default)
[ "def", "get_header", "(", "self", ",", "name", ",", "default", "=", "None", ")", ":", "return", "self", ".", "_handler", ".", "headers", ".", "get", "(", "name", ",", "default", ")" ]
Retrieves the value of a header
[ "Retrieves", "the", "value", "of", "a", "header" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L135-L139
9,718
tcalmant/ipopo
pelix/http/basic.py
_HTTPServletResponse.end_headers
def end_headers(self): """ Ends the headers part """ # Send them all at once for name, value in self._headers.items(): self._handler.send_header(name, value) self._handler.end_headers()
python
def end_headers(self): # Send them all at once for name, value in self._headers.items(): self._handler.send_header(name, value) self._handler.end_headers()
[ "def", "end_headers", "(", "self", ")", ":", "# Send them all at once", "for", "name", ",", "value", "in", "self", ".", "_headers", ".", "items", "(", ")", ":", "self", ".", "_handler", ".", "send_header", "(", "name", ",", "value", ")", "self", ".", "...
Ends the headers part
[ "Ends", "the", "headers", "part" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L219-L227
9,719
tcalmant/ipopo
pelix/http/basic.py
_RequestHandler.log_error
def log_error(self, message, *args, **kwargs): # pylint: disable=W0221 """ Log server error """ self._service.log(logging.ERROR, message, *args, **kwargs)
python
def log_error(self, message, *args, **kwargs): # pylint: disable=W0221 self._service.log(logging.ERROR, message, *args, **kwargs)
[ "def", "log_error", "(", "self", ",", "message", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# pylint: disable=W0221", "self", ".", "_service", ".", "log", "(", "logging", ".", "ERROR", ",", "message", ",", "*", "args", ",", "*", "*", "kwar...
Log server error
[ "Log", "server", "error" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L315-L320
9,720
tcalmant/ipopo
pelix/http/basic.py
_RequestHandler.log_request
def log_request(self, code="-", size="-"): """ Logs a request to the server """ self._service.log(logging.DEBUG, '"%s" %s', self.requestline, code)
python
def log_request(self, code="-", size="-"): self._service.log(logging.DEBUG, '"%s" %s', self.requestline, code)
[ "def", "log_request", "(", "self", ",", "code", "=", "\"-\"", ",", "size", "=", "\"-\"", ")", ":", "self", ".", "_service", ".", "log", "(", "logging", ".", "DEBUG", ",", "'\"%s\" %s'", ",", "self", ".", "requestline", ",", "code", ")" ]
Logs a request to the server
[ "Logs", "a", "request", "to", "the", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L322-L326
9,721
tcalmant/ipopo
pelix/http/basic.py
_RequestHandler.send_no_servlet_response
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 = _HTTPServletResponse(self) response.send_content(404, self._service.make_not_found_page(self.path))
python
def send_no_servlet_response(self): # Use the helper to send the error page response = _HTTPServletResponse(self) response.send_content(404, self._service.make_not_found_page(self.path))
[ "def", "send_no_servlet_response", "(", "self", ")", ":", "# Use the helper to send the error page", "response", "=", "_HTTPServletResponse", "(", "self", ")", "response", ".", "send_content", "(", "404", ",", "self", ".", "_service", ".", "make_not_found_page", "(", ...
Default response sent when no servlet is found for the requested path
[ "Default", "response", "sent", "when", "no", "servlet", "is", "found", "for", "the", "requested", "path" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L328-L334
9,722
tcalmant/ipopo
pelix/http/basic.py
_RequestHandler.send_exception
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 """ # Get a formatted stack trace stack = traceback.format_exc() # Log the error self.log_error( "Error handling request upon: %s\n%s\n", self.path, stack ) # Send the page response.send_content( 500, self._service.make_exception_page(self.path, stack) )
python
def send_exception(self, response): # Get a formatted stack trace stack = traceback.format_exc() # Log the error self.log_error( "Error handling request upon: %s\n%s\n", self.path, stack ) # Send the page response.send_content( 500, self._service.make_exception_page(self.path, stack) )
[ "def", "send_exception", "(", "self", ",", "response", ")", ":", "# Get a formatted stack trace", "stack", "=", "traceback", ".", "format_exc", "(", ")", "# Log the error", "self", ".", "log_error", "(", "\"Error handling request upon: %s\\n%s\\n\"", ",", "self", ".",...
Sends an exception page with a 500 error code. Must be called from inside the exception handling block. :param response: The response handler
[ "Sends", "an", "exception", "page", "with", "a", "500", "error", "code", ".", "Must", "be", "called", "from", "inside", "the", "exception", "handling", "block", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L336-L354
9,723
tcalmant/ipopo
pelix/http/basic.py
_HttpServerFamily.server_bind
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: self.server_name = socket.getfqdn(host) except ValueError: # Use the local host name in case of error, like CPython does self.server_name = socket.gethostname()
python
def server_bind(self): TCPServer.server_bind(self) host, port = self.socket.getsockname()[:2] self.server_port = port try: self.server_name = socket.getfqdn(host) except ValueError: # Use the local host name in case of error, like CPython does self.server_name = socket.gethostname()
[ "def", "server_bind", "(", "self", ")", ":", "TCPServer", ".", "server_bind", "(", "self", ")", "host", ",", "port", "=", "self", ".", "socket", ".", "getsockname", "(", ")", "[", ":", "2", "]", "self", ".", "server_port", "=", "port", "try", ":", ...
Override server_bind to store the server name, even in IronPython. See https://ironpython.codeplex.com/workitem/29477
[ "Override", "server_bind", "to", "store", "the", "server", "name", "even", "in", "IronPython", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/basic.py#L419-L432
9,724
tcalmant/ipopo
pelix/rsa/endpointdescription.py
encode_list
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 list_: A list of objects :return: A dictionary key->string or an empty dictionary """ if not list_: return {} return {key: " ".join(str(i) for i in list_)}
python
def encode_list(key, list_): # type: (str, Iterable) -> Dict[str, str] if not list_: return {} return {key: " ".join(str(i) for i in list_)}
[ "def", "encode_list", "(", "key", ",", "list_", ")", ":", "# type: (str, Iterable) -> Dict[str, str]", "if", "not", "list_", ":", "return", "{", "}", "return", "{", "key", ":", "\" \"", ".", "join", "(", "str", "(", "i", ")", "for", "i", "in", "list_", ...
Converts a list into a space-separated string and puts it in a dictionary :param key: Dictionary key to store the list :param list_: A list of objects :return: A dictionary key->string or an empty dictionary
[ "Converts", "a", "list", "into", "a", "space", "-", "separated", "string", "and", "puts", "it", "in", "a", "dictionary" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L89-L100
9,725
tcalmant/ipopo
pelix/rsa/endpointdescription.py
package_name
def package_name(package): # type: (str) -> str """ Returns the package name of the given module name """ if not package: return "" lastdot = package.rfind(".") if lastdot == -1: return package return package[:lastdot]
python
def package_name(package): # type: (str) -> str if not package: return "" lastdot = package.rfind(".") if lastdot == -1: return package return package[:lastdot]
[ "def", "package_name", "(", "package", ")", ":", "# type: (str) -> str", "if", "not", "package", ":", "return", "\"\"", "lastdot", "=", "package", ".", "rfind", "(", "\".\"", ")", "if", "lastdot", "==", "-", "1", ":", "return", "package", "return", "packag...
Returns the package name of the given module name
[ "Returns", "the", "package", "name", "of", "the", "given", "module", "name" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L103-L115
9,726
tcalmant/ipopo
pelix/rsa/endpointdescription.py
encode_osgi_props
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() ) intents = ed.get_intents() if intents: result_props[SERVICE_INTENTS] = " ".join(intents) remote_configs = ed.get_remote_configs_supported() if remote_configs: result_props[REMOTE_CONFIGS_SUPPORTED] = " ".join(remote_configs) remote_intents = ed.get_remote_intents_supported() if remote_intents: result_props[REMOTE_INTENTS_SUPPORTED] = " ".join(remote_intents) return result_props
python
def encode_osgi_props(ed): # type: (EndpointDescription) -> Dict[str, str] 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() ) intents = ed.get_intents() if intents: result_props[SERVICE_INTENTS] = " ".join(intents) remote_configs = ed.get_remote_configs_supported() if remote_configs: result_props[REMOTE_CONFIGS_SUPPORTED] = " ".join(remote_configs) remote_intents = ed.get_remote_intents_supported() if remote_intents: result_props[REMOTE_INTENTS_SUPPORTED] = " ".join(remote_intents) return result_props
[ "def", "encode_osgi_props", "(", "ed", ")", ":", "# type: (EndpointDescription) -> Dict[str, str]", "result_props", "=", "{", "}", "intfs", "=", "ed", ".", "get_interfaces", "(", ")", "result_props", "[", "OBJECTCLASS", "]", "=", "\" \"", ".", "join", "(", "intf...
Prepares a dictionary of OSGi properties for the given EndpointDescription
[ "Prepares", "a", "dictionary", "of", "OSGi", "properties", "for", "the", "given", "EndpointDescription" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L118-L151
9,727
tcalmant/ipopo
pelix/rsa/endpointdescription.py
decode_list
def decode_list(input_props, name): # type: (Dict[str, str], str) -> List[str] """ Decodes a space-separated list """ val_str = input_props.get(name, None) if val_str: return val_str.split(" ") return []
python
def decode_list(input_props, name): # type: (Dict[str, str], str) -> List[str] val_str = input_props.get(name, None) if val_str: return val_str.split(" ") return []
[ "def", "decode_list", "(", "input_props", ",", "name", ")", ":", "# type: (Dict[str, str], str) -> List[str]", "val_str", "=", "input_props", ".", "get", "(", "name", ",", "None", ")", "if", "val_str", ":", "return", "val_str", ".", "split", "(", "\" \"", ")",...
Decodes a space-separated list
[ "Decodes", "a", "space", "-", "separated", "list" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L154-L162
9,728
tcalmant/ipopo
pelix/rsa/endpointdescription.py
decode_osgi_props
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: result_props[SERVICE_IMPORTED_CONFIGS] = imp_configs intents = decode_list(input_props, SERVICE_INTENTS) if intents: result_props[SERVICE_INTENTS] = intents remote_configs = decode_list(input_props, REMOTE_CONFIGS_SUPPORTED) if remote_configs: result_props[REMOTE_CONFIGS_SUPPORTED] = remote_configs remote_intents = decode_list(input_props, REMOTE_INTENTS_SUPPORTED) if remote_intents: result_props[REMOTE_INTENTS_SUPPORTED] = remote_intents return result_props
python
def decode_osgi_props(input_props): # type: (Dict[str, Any]) -> Dict[str, Any] 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: result_props[SERVICE_IMPORTED_CONFIGS] = imp_configs intents = decode_list(input_props, SERVICE_INTENTS) if intents: result_props[SERVICE_INTENTS] = intents remote_configs = decode_list(input_props, REMOTE_CONFIGS_SUPPORTED) if remote_configs: result_props[REMOTE_CONFIGS_SUPPORTED] = remote_configs remote_intents = decode_list(input_props, REMOTE_INTENTS_SUPPORTED) if remote_intents: result_props[REMOTE_INTENTS_SUPPORTED] = remote_intents return result_props
[ "def", "decode_osgi_props", "(", "input_props", ")", ":", "# type: (Dict[str, Any]) -> Dict[str, Any]", "result_props", "=", "{", "}", "intfs", "=", "decode_list", "(", "input_props", ",", "OBJECTCLASS", ")", "result_props", "[", "OBJECTCLASS", "]", "=", "intfs", "f...
Decodes the OSGi properties of the given endpoint properties
[ "Decodes", "the", "OSGi", "properties", "of", "the", "given", "endpoint", "properties" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L165-L193
9,729
tcalmant/ipopo
pelix/rsa/endpointdescription.py
decode_endpoint_props
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: if async_intfs == "*": ed_props[ECF_SERVICE_EXPORTED_ASYNC_INTERFACES] = async_intfs else: async_intfs = decode_list( input_props, ECF_SERVICE_EXPORTED_ASYNC_INTERFACES ) if async_intfs: ed_props[ECF_SERVICE_EXPORTED_ASYNC_INTERFACES] = async_intfs for key in input_props.keys(): if not is_reserved_property(key): val = input_props.get(key, None) if val: ed_props[key] = val return ed_props
python
def decode_endpoint_props(input_props): # type: (Dict) -> Dict[str, Any] 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: if async_intfs == "*": ed_props[ECF_SERVICE_EXPORTED_ASYNC_INTERFACES] = async_intfs else: async_intfs = decode_list( input_props, ECF_SERVICE_EXPORTED_ASYNC_INTERFACES ) if async_intfs: ed_props[ECF_SERVICE_EXPORTED_ASYNC_INTERFACES] = async_intfs for key in input_props.keys(): if not is_reserved_property(key): val = input_props.get(key, None) if val: ed_props[key] = val return ed_props
[ "def", "decode_endpoint_props", "(", "input_props", ")", ":", "# type: (Dict) -> Dict[str, Any]", "ed_props", "=", "decode_osgi_props", "(", "input_props", ")", "ed_props", "[", "ECF_ENDPOINT_CONTAINERID_NAMESPACE", "]", "=", "input_props", "[", "ECF_ENDPOINT_CONTAINERID_NAME...
Decodes the endpoint properties from the given dictionary
[ "Decodes", "the", "endpoint", "properties", "from", "the", "given", "dictionary" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L196-L233
9,730
tcalmant/ipopo
pelix/rsa/endpointdescription.py
encode_endpoint_props
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() if ctid: props[ECF_ENDPOINT_CONNECTTARGET_ID] = "{0}".format(ctid) id_filters = ed.get_id_filters() if id_filters: props[ECF_ENDPOINT_IDFILTER_IDS] = " ".join([x[1] for x in id_filters]) rs_filter = ed.get_remoteservice_filter() if rs_filter: props[ECF_ENDPOINT_REMOTESERVICE_FILTER] = ed.get_remoteservice_filter() async_intfs = ed.get_async_interfaces() if async_intfs: props[ECF_SERVICE_EXPORTED_ASYNC_INTERFACES] = " ".join(async_intfs) all_props = ed.get_properties() other_props = { key: all_props[key] for key in all_props.keys() if not is_reserved_property(key) } return merge_dicts(props, other_props)
python
def encode_endpoint_props(ed): 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() if ctid: props[ECF_ENDPOINT_CONNECTTARGET_ID] = "{0}".format(ctid) id_filters = ed.get_id_filters() if id_filters: props[ECF_ENDPOINT_IDFILTER_IDS] = " ".join([x[1] for x in id_filters]) rs_filter = ed.get_remoteservice_filter() if rs_filter: props[ECF_ENDPOINT_REMOTESERVICE_FILTER] = ed.get_remoteservice_filter() async_intfs = ed.get_async_interfaces() if async_intfs: props[ECF_SERVICE_EXPORTED_ASYNC_INTERFACES] = " ".join(async_intfs) all_props = ed.get_properties() other_props = { key: all_props[key] for key in all_props.keys() if not is_reserved_property(key) } return merge_dicts(props, other_props)
[ "def", "encode_endpoint_props", "(", "ed", ")", ":", "props", "=", "encode_osgi_props", "(", "ed", ")", "props", "[", "ECF_RSVC_ID", "]", "=", "\"{0}\"", ".", "format", "(", "ed", ".", "get_remoteservice_id", "(", ")", "[", "1", "]", ")", "props", "[", ...
Encodes the properties of the given EndpointDescription
[ "Encodes", "the", "properties", "of", "the", "given", "EndpointDescription" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L236-L266
9,731
tcalmant/ipopo
pelix/rsa/endpointdescription.py
EndpointDescription.is_same_service
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 """ return ( self.get_framework_uuid() == endpoint.get_framework_uuid() and self.get_service_id() == endpoint.get_service_id() )
python
def is_same_service(self, endpoint): # type: (EndpointDescription) -> bool return ( self.get_framework_uuid() == endpoint.get_framework_uuid() and self.get_service_id() == endpoint.get_service_id() )
[ "def", "is_same_service", "(", "self", ",", "endpoint", ")", ":", "# type: (EndpointDescription) -> bool", "return", "(", "self", ".", "get_framework_uuid", "(", ")", "==", "endpoint", ".", "get_framework_uuid", "(", ")", "and", "self", ".", "get_service_id", "(",...
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
[ "Tests", "if", "this", "endpoint", "and", "the", "given", "one", "have", "the", "same", "framework", "UUID", "and", "service", "ID" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/endpointdescription.py#L582-L594
9,732
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.generate_id
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] >= 3: random_ints = [char for char in random_bytes] else: random_ints = [ord(char) for char in random_bytes] random_id = "".join("{0:02x}".format(value) for value in random_ints) return "{0}{1}".format(prefix, random_id)
python
def generate_id(cls, prefix="pelix-"): 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] >= 3: random_ints = [char for char in random_bytes] else: random_ints = [ord(char) for char in random_bytes] random_id = "".join("{0:02x}".format(value) for value in random_ints) return "{0}{1}".format(prefix, random_id)
[ "def", "generate_id", "(", "cls", ",", "prefix", "=", "\"pelix-\"", ")", ":", "if", "not", "prefix", ":", "# Normalize string", "prefix", "=", "\"\"", "else", ":", "# Truncate long prefixes", "prefix", "=", "prefix", "[", ":", "8", "]", "# Prepare the missing ...
Generates a random MQTT client ID :param prefix: Client ID prefix (truncated to 8 chars) :return: A client ID of 22 or 23 characters
[ "Generates", "a", "random", "MQTT", "client", "ID" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L141-L165
9,733
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.set_will
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 :raise ValueError: Invalid topic :raise TypeError: Invalid payload """ self.__mqtt.will_set(topic, payload, qos, retain=retain)
python
def set_will(self, topic, payload, qos=0, retain=False): self.__mqtt.will_set(topic, payload, qos, retain=retain)
[ "def", "set_will", "(", "self", ",", "topic", ",", "payload", ",", "qos", "=", "0", ",", "retain", "=", "False", ")", ":", "self", ".", "__mqtt", ".", "will_set", "(", "topic", ",", "payload", ",", "qos", ",", "retain", "=", "retain", ")" ]
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 :raise ValueError: Invalid topic :raise TypeError: Invalid payload
[ "Sets", "up", "the", "will", "message" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L194-L205
9,734
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.connect
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 """ # Disconnect first (it also stops the timer) self.disconnect() # Prepare the connection self.__mqtt.connect(host, port, keepalive) # Start the MQTT loop self.__mqtt.loop_start()
python
def connect(self, host="localhost", port=1883, keepalive=60): # Disconnect first (it also stops the timer) self.disconnect() # Prepare the connection self.__mqtt.connect(host, port, keepalive) # Start the MQTT loop self.__mqtt.loop_start()
[ "def", "connect", "(", "self", ",", "host", "=", "\"localhost\"", ",", "port", "=", "1883", ",", "keepalive", "=", "60", ")", ":", "# Disconnect first (it also stops the timer)", "self", ".", "disconnect", "(", ")", "# Prepare the connection", "self", ".", "__mq...
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
[ "Connects", "to", "the", "MQTT", "server", ".", "The", "client", "will", "automatically", "try", "to", "reconnect", "to", "this", "server", "when", "the", "connection", "is", "lost", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L207-L225
9,735
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.disconnect
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() # Stop the MQTT loop thread # Use a thread to avoid a dead lock in Paho thread = threading.Thread(target=self.__mqtt.loop_stop) thread.daemon = True thread.start() # Give it some time thread.join(4)
python
def disconnect(self): # 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() # Stop the MQTT loop thread # Use a thread to avoid a dead lock in Paho thread = threading.Thread(target=self.__mqtt.loop_stop) thread.daemon = True thread.start() # Give it some time thread.join(4)
[ "def", "disconnect", "(", "self", ")", ":", "# Stop the timer", "self", ".", "__stop_timer", "(", ")", "# Unlock all publishers", "for", "event", "in", "self", ".", "__in_flight", ".", "values", "(", ")", ":", "event", ".", "set", "(", ")", "# Disconnect fro...
Disconnects from the MQTT server
[ "Disconnects", "from", "the", "MQTT", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L227-L248
9,736
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.publish
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) if wait and not result[0]: # Publish packet sent, wait for it to return self.__in_flight[result[1]] = threading.Event() _logger.debug("Waiting for publication of %s", topic) return result[1]
python
def publish(self, topic, payload, qos=0, retain=False, wait=False): result = self.__mqtt.publish(topic, payload, qos, retain) if wait and not result[0]: # Publish packet sent, wait for it to return self.__in_flight[result[1]] = threading.Event() _logger.debug("Waiting for publication of %s", topic) return result[1]
[ "def", "publish", "(", "self", ",", "topic", ",", "payload", ",", "qos", "=", "0", ",", "retain", "=", "False", ",", "wait", "=", "False", ")", ":", "result", "=", "self", ".", "__mqtt", ".", "publish", "(", "topic", ",", "payload", ",", "qos", "...
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
[ "Sends", "a", "message", "through", "the", "MQTT", "connection" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L250-L268
9,737
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.__start_timer
def __start_timer(self, delay): """ Starts the reconnection timer :param delay: Delay (in seconds) before calling the reconnection method """ self.__timer = threading.Timer(delay, self.__reconnect) self.__timer.daemon = True self.__timer.start()
python
def __start_timer(self, delay): self.__timer = threading.Timer(delay, self.__reconnect) self.__timer.daemon = True self.__timer.start()
[ "def", "__start_timer", "(", "self", ",", "delay", ")", ":", "self", ".", "__timer", "=", "threading", ".", "Timer", "(", "delay", ",", "self", ".", "__reconnect", ")", "self", ".", "__timer", ".", "daemon", "=", "True", "self", ".", "__timer", ".", ...
Starts the reconnection timer :param delay: Delay (in seconds) before calling the reconnection method
[ "Starts", "the", "reconnection", "timer" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L300-L308
9,738
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.__reconnect
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) raise ValueError(message) except Exception as ex: # Something went wrong: log it _logger.error("Exception connecting server: %s", ex) finally: # Prepare a reconnection timer. It will be cancelled by the # on_connect callback self.__start_timer(10)
python
def __reconnect(self): # 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) raise ValueError(message) except Exception as ex: # Something went wrong: log it _logger.error("Exception connecting server: %s", ex) finally: # Prepare a reconnection timer. It will be cancelled by the # on_connect callback self.__start_timer(10)
[ "def", "__reconnect", "(", "self", ")", ":", "# Cancel the timer, if any", "self", ".", "__stop_timer", "(", ")", "try", ":", "# Try to reconnect the server", "result_code", "=", "self", ".", "__mqtt", ".", "reconnect", "(", ")", "if", "result_code", ":", "# Som...
Tries to connect to the MQTT server
[ "Tries", "to", "connect", "to", "the", "MQTT", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L318-L341
9,739
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.__on_connect
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: # result_code != 0: something wrong happened _logger.error( "Error connecting the MQTT server: %s (%d)", paho.connack_string(result_code), result_code, ) else: # Connection is OK: stop the reconnection timer self.__stop_timer() # Notify the caller, if any if self.on_connect is not None: try: self.on_connect(self, result_code) except Exception as ex: _logger.exception("Error notifying MQTT listener: %s", ex)
python
def __on_connect(self, client, userdata, flags, result_code): # pylint: disable=W0613 if result_code: # result_code != 0: something wrong happened _logger.error( "Error connecting the MQTT server: %s (%d)", paho.connack_string(result_code), result_code, ) else: # Connection is OK: stop the reconnection timer self.__stop_timer() # Notify the caller, if any if self.on_connect is not None: try: self.on_connect(self, result_code) except Exception as ex: _logger.exception("Error notifying MQTT listener: %s", ex)
[ "def", "__on_connect", "(", "self", ",", "client", ",", "userdata", ",", "flags", ",", "result_code", ")", ":", "# pylint: disable=W0613", "if", "result_code", ":", "# result_code != 0: something wrong happened", "_logger", ".", "error", "(", "\"Error connecting the MQT...
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)
[ "Client", "connected", "to", "the", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L343-L369
9,740
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.__on_disconnect
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, ) # Try to reconnect self.__stop_timer() self.__start_timer(2) # Notify the caller, if any if self.on_disconnect is not None: try: self.on_disconnect(self, result_code) except Exception as ex: _logger.exception("Error notifying MQTT listener: %s", ex)
python
def __on_disconnect(self, client, userdata, result_code): # pylint: disable=W0613 if result_code: # rc != 0: unexpected disconnection _logger.error( "Unexpected disconnection from the MQTT server: %s (%d)", paho.connack_string(result_code), result_code, ) # Try to reconnect self.__stop_timer() self.__start_timer(2) # Notify the caller, if any if self.on_disconnect is not None: try: self.on_disconnect(self, result_code) except Exception as ex: _logger.exception("Error notifying MQTT listener: %s", ex)
[ "def", "__on_disconnect", "(", "self", ",", "client", ",", "userdata", ",", "result_code", ")", ":", "# pylint: disable=W0613", "if", "result_code", ":", "# rc != 0: unexpected disconnection", "_logger", ".", "error", "(", "\"Unexpected disconnection from the MQTT server: %...
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)
[ "Client", "has", "been", "disconnected", "from", "the", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L371-L397
9,741
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.__on_message
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 caller, if any if self.on_message is not None: try: self.on_message(self, msg) except Exception as ex: _logger.exception("Error notifying MQTT listener: %s", ex)
python
def __on_message(self, client, userdata, msg): # pylint: disable=W0613 # Notify the caller, if any if self.on_message is not None: try: self.on_message(self, msg) except Exception as ex: _logger.exception("Error notifying MQTT listener: %s", ex)
[ "def", "__on_message", "(", "self", ",", "client", ",", "userdata", ",", "msg", ")", ":", "# pylint: disable=W0613", "# Notify the caller, if any", "if", "self", ".", "on_message", "is", "not", "None", ":", "try", ":", "self", ".", "on_message", "(", "self", ...
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
[ "A", "message", "has", "been", "received", "from", "a", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L399-L413
9,742
tcalmant/ipopo
pelix/misc/mqtt_client.py
MqttClient.__on_publish
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 (unused) :param mid: Message ID """ try: self.__in_flight[mid].set() except KeyError: pass
python
def __on_publish(self, client, userdata, mid): # pylint: disable=W0613 try: self.__in_flight[mid].set() except KeyError: pass
[ "def", "__on_publish", "(", "self", ",", "client", ",", "userdata", ",", "mid", ")", ":", "# pylint: disable=W0613", "try", ":", "self", ".", "__in_flight", "[", "mid", "]", ".", "set", "(", ")", "except", "KeyError", ":", "pass" ]
A message has been published by a server :param client: Client that received the message :param userdata: User data (unused) :param mid: Message ID
[ "A", "message", "has", "been", "published", "by", "a", "server" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/misc/mqtt_client.py#L415-L427
9,743
tcalmant/ipopo
pelix/remote/beans.py
to_import_properties
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 "export configs" configs = props.pop(pelix.remote.PROP_EXPORTED_CONFIGS, None) if configs: props[pelix.remote.PROP_IMPORTED_CONFIGS] = configs # Clear other export properties for key in ( pelix.remote.PROP_EXPORTED_INTENTS, pelix.remote.PROP_EXPORTED_INTENTS_EXTRA, pelix.remote.PROP_EXPORTED_INTERFACES, ): try: del props[key] except KeyError: # Key wasn't there pass return props
python
def to_import_properties(properties): # type: (dict) -> dict # 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 "export configs" configs = props.pop(pelix.remote.PROP_EXPORTED_CONFIGS, None) if configs: props[pelix.remote.PROP_IMPORTED_CONFIGS] = configs # Clear other export properties for key in ( pelix.remote.PROP_EXPORTED_INTENTS, pelix.remote.PROP_EXPORTED_INTENTS_EXTRA, pelix.remote.PROP_EXPORTED_INTERFACES, ): try: del props[key] except KeyError: # Key wasn't there pass return props
[ "def", "to_import_properties", "(", "properties", ")", ":", "# type: (dict) -> dict", "# Copy the given dictionary", "props", "=", "properties", ".", "copy", "(", ")", "# Add the \"imported\" property", "props", "[", "pelix", ".", "remote", ".", "PROP_IMPORTED", "]", ...
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
[ "Returns", "a", "dictionary", "where", "export", "properties", "have", "been", "replaced", "by", "import", "ones" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L699-L740
9,744
tcalmant/ipopo
pelix/remote/beans.py
compute_exported_specifications
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 ] else: # Export everything all_exported_specs = pelix.utilities.to_iterable(specs) # Authorized and rejected specifications export_only_specs = pelix.utilities.to_iterable( svc_ref.get_property(pelix.remote.PROP_EXPORT_ONLY), False ) if export_only_specs: # Filter specifications (keep authorized specifications) return [ spec for spec in all_exported_specs if spec in export_only_specs ] # Filter specifications (reject) rejected_specs = pelix.utilities.to_iterable( svc_ref.get_property(pelix.remote.PROP_EXPORT_REJECT), False ) return [spec for spec in all_exported_specs if spec not in rejected_specs]
python
def compute_exported_specifications(svc_ref): # type: (pelix.framework.ServiceReference) -> List[str] 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 ] else: # Export everything all_exported_specs = pelix.utilities.to_iterable(specs) # Authorized and rejected specifications export_only_specs = pelix.utilities.to_iterable( svc_ref.get_property(pelix.remote.PROP_EXPORT_ONLY), False ) if export_only_specs: # Filter specifications (keep authorized specifications) return [ spec for spec in all_exported_specs if spec in export_only_specs ] # Filter specifications (reject) rejected_specs = pelix.utilities.to_iterable( svc_ref.get_property(pelix.remote.PROP_EXPORT_REJECT), False ) return [spec for spec in all_exported_specs if spec not in rejected_specs]
[ "def", "compute_exported_specifications", "(", "svc_ref", ")", ":", "# type: (pelix.framework.ServiceReference) -> List[str]", "if", "svc_ref", ".", "get_property", "(", "pelix", ".", "remote", ".", "PROP_EXPORT_NONE", ")", ":", "# The export of this service is explicitly forbi...
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)
[ "Computes", "the", "list", "of", "specifications", "exported", "by", "the", "given", "service" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L746-L789
9,745
tcalmant/ipopo
pelix/remote/beans.py
format_specifications
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: try: lang, spec = _extract_specification_parts(original) transformed.add(_format_specification(lang, spec)) except ValueError: # Ignore invalid specifications pass return list(transformed)
python
def format_specifications(specifications): # type: (Iterable[str]) -> List[str] transformed = set() for original in specifications: try: lang, spec = _extract_specification_parts(original) transformed.add(_format_specification(lang, spec)) except ValueError: # Ignore invalid specifications pass return list(transformed)
[ "def", "format_specifications", "(", "specifications", ")", ":", "# type: (Iterable[str]) -> List[str]", "transformed", "=", "set", "(", ")", "for", "original", "in", "specifications", ":", "try", ":", "lang", ",", "spec", "=", "_extract_specification_parts", "(", "...
Transforms the interfaces names into URI strings, with the interface implementation language as a scheme. :param specifications: Specifications to transform :return: The transformed names
[ "Transforms", "the", "interfaces", "names", "into", "URI", "strings", "with", "the", "interface", "implementation", "language", "as", "a", "scheme", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L830-L848
9,746
tcalmant/ipopo
pelix/remote/beans.py
ExportEndpoint.get_properties
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 in pelix.constants.OBJECTCLASS, pelix.constants.SERVICE_ID: properties[key] = self.__reference.get_property(key) # Force the exported configurations properties[pelix.remote.PROP_EXPORTED_CONFIGS] = self.configurations return properties
python
def get_properties(self): # type: () -> dict # Get service properties properties = self.__reference.get_properties() # Merge with local properties properties.update(self.__properties) # Some properties can't be merged for key in pelix.constants.OBJECTCLASS, pelix.constants.SERVICE_ID: properties[key] = self.__reference.get_property(key) # Force the exported configurations properties[pelix.remote.PROP_EXPORTED_CONFIGS] = self.configurations return properties
[ "def", "get_properties", "(", "self", ")", ":", "# type: () -> dict", "# Get service properties", "properties", "=", "self", ".", "__reference", ".", "get_properties", "(", ")", "# Merge with local properties", "properties", ".", "update", "(", "self", ".", "__propert...
Returns merged properties :return: Endpoint merged properties
[ "Returns", "merged", "properties" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L152-L172
9,747
tcalmant/ipopo
pelix/remote/beans.py
ExportEndpoint.make_import_properties
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 props = to_import_properties(self.get_properties()) # Add the framework UID props[pelix.remote.PROP_ENDPOINT_FRAMEWORK_UUID] = self.__fw_uid return props
python
def make_import_properties(self): # type: () -> dict # Convert merged properties props = to_import_properties(self.get_properties()) # Add the framework UID props[pelix.remote.PROP_ENDPOINT_FRAMEWORK_UUID] = self.__fw_uid return props
[ "def", "make_import_properties", "(", "self", ")", ":", "# type: () -> dict", "# Convert merged properties", "props", "=", "to_import_properties", "(", "self", ".", "get_properties", "(", ")", ")", "# Add the framework UID", "props", "[", "pelix", ".", "remote", ".", ...
Returns the properties of this endpoint where export properties have been replaced by import ones :return: A dictionary with import properties
[ "Returns", "the", "properties", "of", "this", "endpoint", "where", "export", "properties", "have", "been", "replaced", "by", "import", "ones" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L174-L187
9,748
tcalmant/ipopo
pelix/remote/beans.py
EndpointDescription.__check_properties
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: raise ValueError("Missing property: {0}".format(key)) # Export/Import properties props_export = ( pelix.remote.PROP_EXPORTED_CONFIGS, pelix.remote.PROP_EXPORTED_INTERFACES, ) for key in props_export: if key in props: raise ValueError("Export property found: {0}".format(key))
python
def __check_properties(props): # type: (dict) -> None # 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: raise ValueError("Missing property: {0}".format(key)) # Export/Import properties props_export = ( pelix.remote.PROP_EXPORTED_CONFIGS, pelix.remote.PROP_EXPORTED_INTERFACES, ) for key in props_export: if key in props: raise ValueError("Export property found: {0}".format(key))
[ "def", "__check_properties", "(", "props", ")", ":", "# type: (dict) -> None", "# Mandatory properties", "mandatory", "=", "(", "pelix", ".", "remote", ".", "PROP_ENDPOINT_ID", ",", "pelix", ".", "remote", ".", "PROP_IMPORTED_CONFIGS", ",", "pelix", ".", "constants"...
Checks that the given dictionary doesn't have export keys and has import keys :param props: Properties to validate :raise ValueError: Invalid properties
[ "Checks", "that", "the", "given", "dictionary", "doesn", "t", "have", "export", "keys", "and", "has", "import", "keys" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L452-L479
9,749
tcalmant/ipopo
pelix/remote/beans.py
EndpointDescription.matches
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 properties matches the filter """ return pelix.ldapfilter.get_ldap_filter(ldap_filter).matches( self.__properties )
python
def matches(self, ldap_filter): # type: (Any[str, pelix.ldapfilter.LDAPFilter]) -> bool return pelix.ldapfilter.get_ldap_filter(ldap_filter).matches( self.__properties )
[ "def", "matches", "(", "self", ",", "ldap_filter", ")", ":", "# type: (Any[str, pelix.ldapfilter.LDAPFilter]) -> bool", "return", "pelix", ".", "ldapfilter", ".", "get_ldap_filter", "(", "ldap_filter", ")", ".", "matches", "(", "self", ".", "__properties", ")" ]
Tests the properties of this EndpointDescription against the given filter :param ldap_filter: A filter :return: True if properties matches the filter
[ "Tests", "the", "properties", "of", "this", "EndpointDescription", "against", "the", "given", "filter" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L605-L616
9,750
tcalmant/ipopo
pelix/remote/beans.py
EndpointDescription.to_import
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()) # Configuration / kind configurations = self.get_configuration_types() # Interfaces specifications = self.get_interfaces() return ImportEndpoint( self.get_id(), fw_uid, configurations, name, specifications, properties, )
python
def to_import(self): # type: () -> ImportEndpoint # 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()) # Configuration / kind configurations = self.get_configuration_types() # Interfaces specifications = self.get_interfaces() return ImportEndpoint( self.get_id(), fw_uid, configurations, name, specifications, properties, )
[ "def", "to_import", "(", "self", ")", ":", "# type: () -> ImportEndpoint", "# Properties", "properties", "=", "self", ".", "get_properties", "(", ")", "# Framework UUID", "fw_uid", "=", "self", ".", "get_framework_uuid", "(", ")", "# Endpoint name", "try", ":", "#...
Converts an EndpointDescription bean to an ImportEndpoint :return: An ImportEndpoint bean
[ "Converts", "an", "EndpointDescription", "bean", "to", "an", "ImportEndpoint" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L618-L652
9,751
tcalmant/ipopo
pelix/remote/beans.py
EndpointDescription.from_export
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, pelix.remote.PROP_EXPORTED_INTERFACES, pelix.remote.PROP_EXPORTED_INTENTS, pelix.remote.PROP_EXPORTED_INTENTS_EXTRA, ): try: del properties[key] except KeyError: pass # Other information properties[pelix.remote.PROP_ENDPOINT_NAME] = endpoint.name properties[ pelix.remote.PROP_ENDPOINT_FRAMEWORK_UUID ] = endpoint.framework return EndpointDescription(None, properties)
python
def from_export(cls, endpoint): # type: (ExportEndpoint) -> EndpointDescription 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, pelix.remote.PROP_EXPORTED_INTERFACES, pelix.remote.PROP_EXPORTED_INTENTS, pelix.remote.PROP_EXPORTED_INTENTS_EXTRA, ): try: del properties[key] except KeyError: pass # Other information properties[pelix.remote.PROP_ENDPOINT_NAME] = endpoint.name properties[ pelix.remote.PROP_ENDPOINT_FRAMEWORK_UUID ] = endpoint.framework return EndpointDescription(None, properties)
[ "def", "from_export", "(", "cls", ",", "endpoint", ")", ":", "# type: (ExportEndpoint) -> EndpointDescription", "assert", "isinstance", "(", "endpoint", ",", "ExportEndpoint", ")", "# Service properties", "properties", "=", "endpoint", ".", "get_properties", "(", ")", ...
Converts an ExportEndpoint bean to an EndpointDescription :param endpoint: An ExportEndpoint bean :return: An EndpointDescription bean
[ "Converts", "an", "ExportEndpoint", "bean", "to", "an", "EndpointDescription" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/beans.py#L655-L693
9,752
tcalmant/ipopo
pelix/rsa/edef.py
EDEFReader._parse_description
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 """ endpoint = {} for prop_node in node.findall(TAG_PROPERTY): name, value = self._parse_property(prop_node) endpoint[name] = value return EndpointDescription(None, endpoint)
python
def _parse_description(self, node): # type: (ElementTree.Element) -> EndpointDescription endpoint = {} for prop_node in node.findall(TAG_PROPERTY): name, value = self._parse_property(prop_node) endpoint[name] = value return EndpointDescription(None, endpoint)
[ "def", "_parse_description", "(", "self", ",", "node", ")", ":", "# type: (ElementTree.Element) -> EndpointDescription", "endpoint", "=", "{", "}", "for", "prop_node", "in", "node", ".", "findall", "(", "TAG_PROPERTY", ")", ":", "name", ",", "value", "=", "self"...
Parse an endpoint description node :param node: The endpoint description node :return: The parsed EndpointDescription bean :raise KeyError: Attribute missing :raise ValueError: Invalid description
[ "Parse", "an", "endpoint", "description", "node" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L165-L180
9,753
tcalmant/ipopo
pelix/rsa/edef.py
EDEFReader._parse_property
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)) value = self._parse_value_node(vtype, value_node) except StopIteration: # Value is an attribute value = self._convert_value(vtype, node.attrib[ATTR_VALUE]) return name, value
python
def _parse_property(self, node): # type: (ElementTree.Element) -> Tuple[str, Any] # 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)) value = self._parse_value_node(vtype, value_node) except StopIteration: # Value is an attribute value = self._convert_value(vtype, node.attrib[ATTR_VALUE]) return name, value
[ "def", "_parse_property", "(", "self", ",", "node", ")", ":", "# type: (ElementTree.Element) -> Tuple[str, Any]", "# Get information", "name", "=", "node", ".", "attrib", "[", "ATTR_NAME", "]", "vtype", "=", "node", ".", "attrib", ".", "get", "(", "ATTR_VALUE_TYPE...
Parses a property node :param node: The property node :return: A (name, value) tuple :raise KeyError: Attribute missing
[ "Parses", "a", "property", "node" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L182-L203
9,754
tcalmant/ipopo
pelix/rsa/edef.py
EDEFReader._parse_value_node
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) for value_node in node.findall(TAG_VALUE) ] elif kind == TAG_SET: # Set return set( self._convert_value(vtype, value_node.text) for value_node in node.findall(TAG_VALUE) ) else: # Unknown raise ValueError("Unknown value tag: {0}".format(kind))
python
def _parse_value_node(self, vtype, node): # type: (str, ElementTree.Element) -> Any 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) for value_node in node.findall(TAG_VALUE) ] elif kind == TAG_SET: # Set return set( self._convert_value(vtype, value_node.text) for value_node in node.findall(TAG_VALUE) ) else: # Unknown raise ValueError("Unknown value tag: {0}".format(kind))
[ "def", "_parse_value_node", "(", "self", ",", "vtype", ",", "node", ")", ":", "# type: (str, ElementTree.Element) -> Any", "kind", "=", "node", ".", "tag", "if", "kind", "==", "TAG_XML", ":", "# Raw XML value", "return", "next", "(", "iter", "(", "node", ")", ...
Parses a value node :param vtype: The value type :param node: The value node :return: The parsed value
[ "Parses", "a", "value", "node" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L205-L235
9,755
tcalmant/ipopo
pelix/rsa/edef.py
EDEFReader.parse
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: raise ValueError("Not an EDEF XML: {0}".format(root.tag)) # Parse content return [ self._parse_description(node) for node in root.findall(TAG_ENDPOINT_DESCRIPTION) ]
python
def parse(self, xml_str): # type: (str) -> List[EndpointDescription] # Parse the document root = ElementTree.fromstring(xml_str) if root.tag != TAG_ENDPOINT_DESCRIPTIONS: raise ValueError("Not an EDEF XML: {0}".format(root.tag)) # Parse content return [ self._parse_description(node) for node in root.findall(TAG_ENDPOINT_DESCRIPTION) ]
[ "def", "parse", "(", "self", ",", "xml_str", ")", ":", "# type: (str) -> List[EndpointDescription]", "# Parse the document", "root", "=", "ElementTree", ".", "fromstring", "(", "xml_str", ")", "if", "root", ".", "tag", "!=", "TAG_ENDPOINT_DESCRIPTIONS", ":", "raise"...
Parses an EDEF XML string :param xml_str: An XML string :return: The list of parsed EndpointDescription
[ "Parses", "an", "EDEF", "XML", "string" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L237-L254
9,756
tcalmant/ipopo
pelix/rsa/edef.py
EDEFWriter._make_endpoint
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, vtype) # Compute value node or attribute if isinstance(value, tuple): # Array self._add_container(prop_node, TAG_ARRAY, value) elif isinstance(value, list): # List self._add_container(prop_node, TAG_ARRAY, value) elif isinstance(value, set): # Set self._add_container(prop_node, TAG_SET, value) elif isinstance(value, type(root_node)): # XML (direct addition) prop_node.append(value) else: # Simple value -> Attribute prop_node.set(ATTR_VALUE, str(value))
python
def _make_endpoint(self, root_node, endpoint): # type: (ElementTree.Element, EndpointDescription) -> None 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, vtype) # Compute value node or attribute if isinstance(value, tuple): # Array self._add_container(prop_node, TAG_ARRAY, value) elif isinstance(value, list): # List self._add_container(prop_node, TAG_ARRAY, value) elif isinstance(value, set): # Set self._add_container(prop_node, TAG_SET, value) elif isinstance(value, type(root_node)): # XML (direct addition) prop_node.append(value) else: # Simple value -> Attribute prop_node.set(ATTR_VALUE, str(value))
[ "def", "_make_endpoint", "(", "self", ",", "root_node", ",", "endpoint", ")", ":", "# type: (ElementTree.Element, EndpointDescription) -> None", "endpoint_node", "=", "ElementTree", ".", "SubElement", "(", "root_node", ",", "TAG_ENDPOINT_DESCRIPTION", ")", "for", "name", ...
Converts the given endpoint bean to an XML Element :param root_node: The XML root Element :param endpoint: An EndpointDescription bean
[ "Converts", "the", "given", "endpoint", "bean", "to", "an", "XML", "Element" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L373-L422
9,757
tcalmant/ipopo
pelix/rsa/edef.py
EDEFWriter._make_xml
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 = ElementTree.Element(TAG_ENDPOINT_DESCRIPTIONS) for endpoint in endpoints: self._make_endpoint(root, endpoint) # Prepare pretty-printing self._indent(root) return root
python
def _make_xml(self, endpoints): # type: (List[EndpointDescription]) -> ElementTree.Element root = ElementTree.Element(TAG_ENDPOINT_DESCRIPTIONS) for endpoint in endpoints: self._make_endpoint(root, endpoint) # Prepare pretty-printing self._indent(root) return root
[ "def", "_make_xml", "(", "self", ",", "endpoints", ")", ":", "# type: (List[EndpointDescription]) -> ElementTree.Element", "root", "=", "ElementTree", ".", "Element", "(", "TAG_ENDPOINT_DESCRIPTIONS", ")", "for", "endpoint", "in", "endpoints", ":", "self", ".", "_make...
Converts the given endpoint description beans into an XML Element :param endpoints: A list of EndpointDescription beans :return: A string containing an XML document
[ "Converts", "the", "given", "endpoint", "description", "beans", "into", "an", "XML", "Element" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L424-L438
9,758
tcalmant/ipopo
pelix/rsa/edef.py
EDEFWriter.write
def write(self, endpoints, filename): # type: (List[EndpointDescription], str) -> None """ Writes the given endpoint descriptions to the given file :param endpoints: A list of EndpointDescription beans :param filename: Name of the file where to write the XML :raise IOError: Error writing the file """ with open(filename, "w") as filep: filep.write(self.to_string(endpoints))
python
def write(self, endpoints, filename): # type: (List[EndpointDescription], str) -> None with open(filename, "w") as filep: filep.write(self.to_string(endpoints))
[ "def", "write", "(", "self", ",", "endpoints", ",", "filename", ")", ":", "# type: (List[EndpointDescription], str) -> None", "with", "open", "(", "filename", ",", "\"w\"", ")", "as", "filep", ":", "filep", ".", "write", "(", "self", ".", "to_string", "(", "...
Writes the given endpoint descriptions to the given file :param endpoints: A list of EndpointDescription beans :param filename: Name of the file where to write the XML :raise IOError: Error writing the file
[ "Writes", "the", "given", "endpoint", "descriptions", "to", "the", "given", "file" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/rsa/edef.py#L468-L478
9,759
tcalmant/ipopo
pelix/ipopo/decorators.py
is_from_parent
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) except AttributeError: # No need to go further: the attribute does not exist return False for base in cls.__bases__: # Look for the value in each parent class try: return getattr(base, attribute_name) is value except AttributeError: pass # Attribute value not found in parent classes return False
python
def is_from_parent(cls, attribute_name, value=None): # type: (type, str, bool) -> bool if value is None: try: # Get the current value value = getattr(cls, attribute_name) except AttributeError: # No need to go further: the attribute does not exist return False for base in cls.__bases__: # Look for the value in each parent class try: return getattr(base, attribute_name) is value except AttributeError: pass # Attribute value not found in parent classes return False
[ "def", "is_from_parent", "(", "cls", ",", "attribute_name", ",", "value", "=", "None", ")", ":", "# type: (type, str, bool) -> bool", "if", "value", "is", "None", ":", "try", ":", "# Get the current value", "value", "=", "getattr", "(", "cls", ",", "attribute_na...
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
[ "Tests", "if", "the", "current", "attribute", "value", "is", "shared", "by", "a", "parent", "of", "the", "given", "class", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L64-L93
9,760
tcalmant/ipopo
pelix/ipopo/decorators.py
get_factory_context
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: # Class not yet manipulated context = FactoryContext() elif is_from_parent(cls, constants.IPOPO_FACTORY_CONTEXT): # Create a copy the context context = context.copy(True) # * Manipulation has not been applied yet context.completed = False else: # Nothing special to do return context # Context has been created or copied, inject the new bean setattr(cls, constants.IPOPO_FACTORY_CONTEXT, context) return context
python
def get_factory_context(cls): # type: (type) -> FactoryContext context = getattr(cls, constants.IPOPO_FACTORY_CONTEXT, None) if context is None: # Class not yet manipulated context = FactoryContext() elif is_from_parent(cls, constants.IPOPO_FACTORY_CONTEXT): # Create a copy the context context = context.copy(True) # * Manipulation has not been applied yet context.completed = False else: # Nothing special to do return context # Context has been created or copied, inject the new bean setattr(cls, constants.IPOPO_FACTORY_CONTEXT, context) return context
[ "def", "get_factory_context", "(", "cls", ")", ":", "# type: (type) -> FactoryContext", "context", "=", "getattr", "(", "cls", ",", "constants", ".", "IPOPO_FACTORY_CONTEXT", ",", "None", ")", "if", "context", "is", "None", ":", "# Class not yet manipulated", "conte...
Retrieves the factory context object associated to a factory. Creates it if needed :param cls: The factory class :return: The factory class context
[ "Retrieves", "the", "factory", "context", "object", "associated", "to", "a", "factory", ".", "Creates", "it", "if", "needed" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L96-L121
9,761
tcalmant/ipopo
pelix/ipopo/decorators.py
get_method_description
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 line_no = -1 return "'{method}' ({file}:{line})".format( method=method.__name__, file=inspect.getfile(method), line=line_no ) except TypeError: # Method can't be inspected return "'{0}'".format(method.__name__)
python
def get_method_description(method): # type: (Callable) -> str try: try: line_no = inspect.getsourcelines(method)[1] except IOError: # Error reading the source file line_no = -1 return "'{method}' ({file}:{line})".format( method=method.__name__, file=inspect.getfile(method), line=line_no ) except TypeError: # Method can't be inspected return "'{0}'".format(method.__name__)
[ "def", "get_method_description", "(", "method", ")", ":", "# type: (Callable) -> str", "try", ":", "try", ":", "line_no", "=", "inspect", ".", "getsourcelines", "(", "method", ")", "[", "1", "]", "except", "IOError", ":", "# Error reading the source file", "line_n...
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
[ "Retrieves", "a", "description", "of", "the", "given", "method", ".", "If", "possible", "the", "description", "contains", "the", "source", "file", "name", "and", "line", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L124-L146
9,762
tcalmant/ipopo
pelix/ipopo/decorators.py
validate_method_arity
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 'self' argument".format( get_method_description(method) ) ) elif arg_spec.keywords is not None: raise TypeError("Methods using '**kwargs' are not handled") elif nb_args != nb_needed_args: # "Normal" arguments raise TypeError( "The decorated method {0} must accept exactly {1} parameters: " "(self, {2})".format( get_method_description(method), nb_needed_args + 1, ", ".join(needed_args), ) )
python
def validate_method_arity(method, *needed_args): # type: (Callable, *str) -> None 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 'self' argument".format( get_method_description(method) ) ) elif arg_spec.keywords is not None: raise TypeError("Methods using '**kwargs' are not handled") elif nb_args != nb_needed_args: # "Normal" arguments raise TypeError( "The decorated method {0} must accept exactly {1} parameters: " "(self, {2})".format( get_method_description(method), nb_needed_args + 1, ", ".join(needed_args), ) )
[ "def", "validate_method_arity", "(", "method", ",", "*", "needed_args", ")", ":", "# type: (Callable, *str) -> None", "nb_needed_args", "=", "len", "(", "needed_args", ")", "# Test the number of parameters", "arg_spec", "=", "get_method_arguments", "(", "method", ")", "...
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
[ "Tests", "if", "the", "decorated", "method", "has", "a", "sufficient", "number", "of", "parameters", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L149-L196
9,763
tcalmant/ipopo
pelix/ipopo/decorators.py
_ipopo_setup_callback
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 -> Don't remove it # Store the call backs for _callback in method_callbacks: if _callback in callbacks and not is_from_parent( cls, callbacks[_callback].__name__, callbacks[_callback] ): _logger.warning( "Redefining the callback %s in class '%s'.\n" "\tPrevious callback : %s\n" "\tNew callback : %s", _callback, cls.__name__, get_method_description(callbacks[_callback]), get_method_description(func), ) callbacks[_callback] = func # Update the factory context context.callbacks.clear() context.callbacks.update(callbacks)
python
def _ipopo_setup_callback(cls, context): # type: (type, FactoryContext) -> None 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 -> Don't remove it # Store the call backs for _callback in method_callbacks: if _callback in callbacks and not is_from_parent( cls, callbacks[_callback].__name__, callbacks[_callback] ): _logger.warning( "Redefining the callback %s in class '%s'.\n" "\tPrevious callback : %s\n" "\tNew callback : %s", _callback, cls.__name__, get_method_description(callbacks[_callback]), get_method_description(func), ) callbacks[_callback] = func # Update the factory context context.callbacks.clear() context.callbacks.update(callbacks)
[ "def", "_ipopo_setup_callback", "(", "cls", ",", "context", ")", ":", "# type: (type, FactoryContext) -> None", "assert", "inspect", ".", "isclass", "(", "cls", ")", "assert", "isinstance", "(", "context", ",", "FactoryContext", ")", "if", "context", ".", "callbac...
Sets up the class _callback dictionary :param cls: The class to handle :param context: The factory class context
[ "Sets", "up", "the", "class", "_callback", "dictionary" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L202-L257
9,764
tcalmant/ipopo
pelix/ipopo/decorators.py
_ipopo_setup_field_callback
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 -> Don't remove it # Store the call backs for kind, field, if_valid in method_callbacks: fields_cbs = callbacks.setdefault(field, {}) if kind in fields_cbs and not is_from_parent( cls, fields_cbs[kind][0].__name__ ): _logger.warning( "Redefining the callback %s in '%s'. " "Previous callback : '%s' (%s). " "New callback : %s", kind, name, fields_cbs[kind][0].__name__, fields_cbs[kind][0], func, ) fields_cbs[kind] = (func, if_valid) # Update the factory context context.field_callbacks.clear() context.field_callbacks.update(callbacks)
python
def _ipopo_setup_field_callback(cls, context): # type: (type, FactoryContext) -> None 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 -> Don't remove it # Store the call backs for kind, field, if_valid in method_callbacks: fields_cbs = callbacks.setdefault(field, {}) if kind in fields_cbs and not is_from_parent( cls, fields_cbs[kind][0].__name__ ): _logger.warning( "Redefining the callback %s in '%s'. " "Previous callback : '%s' (%s). " "New callback : %s", kind, name, fields_cbs[kind][0].__name__, fields_cbs[kind][0], func, ) fields_cbs[kind] = (func, if_valid) # Update the factory context context.field_callbacks.clear() context.field_callbacks.update(callbacks)
[ "def", "_ipopo_setup_field_callback", "(", "cls", ",", "context", ")", ":", "# type: (type, FactoryContext) -> None", "assert", "inspect", ".", "isclass", "(", "cls", ")", "assert", "isinstance", "(", "context", ",", "FactoryContext", ")", "if", "context", ".", "f...
Sets up the class _field_callback dictionary :param cls: The class to handle :param context: The factory class context
[ "Sets", "up", "the", "class", "_field_callback", "dictionary" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L260-L317
9,765
tcalmant/ipopo
pelix/ipopo/decorators.py
_append_object_entry
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* :param entry: The entry to be added to the list :raise ValueError: Invalid attribute content """ # Get the list obj_list = getattr(obj, list_name, None) if obj_list is None: # We'll have to create it obj_list = [] setattr(obj, list_name, obj_list) assert isinstance(obj_list, list) # Set up the property, if needed if entry not in obj_list: obj_list.append(entry)
python
def _append_object_entry(obj, list_name, entry): # type: (Any, str, Any) -> None # Get the list obj_list = getattr(obj, list_name, None) if obj_list is None: # We'll have to create it obj_list = [] setattr(obj, list_name, obj_list) assert isinstance(obj_list, list) # Set up the property, if needed if entry not in obj_list: obj_list.append(entry)
[ "def", "_append_object_entry", "(", "obj", ",", "list_name", ",", "entry", ")", ":", "# type: (Any, str, Any) -> None", "# Get the list", "obj_list", "=", "getattr", "(", "obj", ",", "list_name", ",", "None", ")", "if", "obj_list", "is", "None", ":", "# We'll ha...
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* :param entry: The entry to be added to the list :raise ValueError: Invalid attribute content
[ "Appends", "the", "given", "entry", "in", "the", "given", "object", "list", ".", "Creates", "the", "list", "field", "if", "needed", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L335-L357
9,766
tcalmant/ipopo
pelix/ipopo/decorators.py
_get_specifications
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 return [specifications.__name__] elif is_string(specifications): # Specification name specifications = specifications.strip() if not specifications: raise ValueError("Empty specification given") return [specifications] elif isinstance(specifications, (list, tuple)): # List given: normalize its content results = [] for specification in specifications: results.extend(_get_specifications(specification)) return results else: raise ValueError( "Unhandled specifications type : {0}".format( type(specifications).__name__ ) )
python
def _get_specifications(specifications): 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 return [specifications.__name__] elif is_string(specifications): # Specification name specifications = specifications.strip() if not specifications: raise ValueError("Empty specification given") return [specifications] elif isinstance(specifications, (list, tuple)): # List given: normalize its content results = [] for specification in specifications: results.extend(_get_specifications(specification)) return results else: raise ValueError( "Unhandled specifications type : {0}".format( type(specifications).__name__ ) )
[ "def", "_get_specifications", "(", "specifications", ")", ":", "if", "not", "specifications", "or", "specifications", "is", "object", ":", "raise", "ValueError", "(", "\"No specifications given\"", ")", "elif", "inspect", ".", "isclass", "(", "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
[ "Computes", "the", "list", "of", "strings", "corresponding", "to", "the", "given", "specifications" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L839-L885
9,767
tcalmant/ipopo
pelix/ipopo/decorators.py
PostRegistration
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 element is not a valid function """ if not isinstance(method, types.FunctionType): raise TypeError("@PostRegistration can only be applied on functions") # Tests the number of parameters validate_method_arity(method, "service_reference") _append_object_entry( method, constants.IPOPO_METHOD_CALLBACKS, constants.IPOPO_CALLBACK_POST_REGISTRATION, ) return method
python
def PostRegistration(method): # pylint: disable=C0103 if not isinstance(method, types.FunctionType): raise TypeError("@PostRegistration can only be applied on functions") # Tests the number of parameters validate_method_arity(method, "service_reference") _append_object_entry( method, constants.IPOPO_METHOD_CALLBACKS, constants.IPOPO_CALLBACK_POST_REGISTRATION, ) return method
[ "def", "PostRegistration", "(", "method", ")", ":", "# pylint: disable=C0103", "if", "not", "isinstance", "(", "method", ",", "types", ".", "FunctionType", ")", ":", "raise", "TypeError", "(", "\"@PostRegistration can only be applied on functions\"", ")", "# Tests the n...
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 element is not a valid function
[ "The", "service", "post", "-", "registration", "callback", "decorator", "is", "called", "after", "a", "service", "of", "the", "component", "has", "been", "registered", "to", "the", "framework", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L1994-L2024
9,768
tcalmant/ipopo
pelix/ipopo/decorators.py
PostUnregistration
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 element is not a valid function """ if not isinstance(method, types.FunctionType): raise TypeError("@PostUnregistration can only be applied on functions") # Tests the number of parameters validate_method_arity(method, "service_reference") _append_object_entry( method, constants.IPOPO_METHOD_CALLBACKS, constants.IPOPO_CALLBACK_POST_UNREGISTRATION, ) return method
python
def PostUnregistration(method): # pylint: disable=C0103 if not isinstance(method, types.FunctionType): raise TypeError("@PostUnregistration can only be applied on functions") # Tests the number of parameters validate_method_arity(method, "service_reference") _append_object_entry( method, constants.IPOPO_METHOD_CALLBACKS, constants.IPOPO_CALLBACK_POST_UNREGISTRATION, ) return method
[ "def", "PostUnregistration", "(", "method", ")", ":", "# pylint: disable=C0103", "if", "not", "isinstance", "(", "method", ",", "types", ".", "FunctionType", ")", ":", "raise", "TypeError", "(", "\"@PostUnregistration can only be applied on functions\"", ")", "# Tests t...
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 element is not a valid function
[ "The", "service", "post", "-", "unregistration", "callback", "decorator", "is", "called", "after", "a", "service", "of", "the", "component", "has", "been", "unregistered", "from", "the", "framework", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/decorators.py#L2027-L2057
9,769
tcalmant/ipopo
pelix/shell/core.py
_ShellUtils.bundlestate_to_str
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", pelix.Bundle.STOPPING: "STOPPING", pelix.Bundle.UNINSTALLED: "UNINSTALLED", } return states.get(state, "Unknown state ({0})".format(state))
python
def bundlestate_to_str(state): states = { pelix.Bundle.INSTALLED: "INSTALLED", pelix.Bundle.ACTIVE: "ACTIVE", pelix.Bundle.RESOLVED: "RESOLVED", pelix.Bundle.STARTING: "STARTING", pelix.Bundle.STOPPING: "STOPPING", pelix.Bundle.UNINSTALLED: "UNINSTALLED", } return states.get(state, "Unknown state ({0})".format(state))
[ "def", "bundlestate_to_str", "(", "state", ")", ":", "states", "=", "{", "pelix", ".", "Bundle", ".", "INSTALLED", ":", "\"INSTALLED\"", ",", "pelix", ".", "Bundle", ".", "ACTIVE", ":", "\"ACTIVE\"", ",", "pelix", ".", "Bundle", ".", "RESOLVED", ":", "\"...
Converts a bundle state integer to a string
[ "Converts", "a", "bundle", "state", "integer", "to", "a", "string" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L80-L93
9,770
tcalmant/ipopo
pelix/shell/core.py
_ShellUtils.make_table
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 raise ValueError( "Different sizes for header and lines " "(line {0})".format(idx + 1) ) # Prepare the head (centered text) format_str = "{0}|".format(prefix) for column, length in enumerate(lengths): format_str += " {%d:^%d} |" % (column, length) head_str = format_str.format(*headers) # Prepare the separator, according the length of the headers string separator = "{0}{1}".format(prefix, "-" * (len(head_str) - len(prefix))) idx = head_str.find("|") while idx != -1: separator = "+".join((separator[:idx], separator[idx + 1 :])) idx = head_str.find("|", idx + 1) # Prepare the output output = [separator, head_str, separator.replace("-", "=")] # Compute the lines format_str = format_str.replace("^", "<") for line in str_lines: output.append(format_str.format(*line)) output.append(separator) # Force the last end of line output.append("") # Join'em return "\n".join(output)
python
def make_table(headers, lines, prefix=None): # 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 raise ValueError( "Different sizes for header and lines " "(line {0})".format(idx + 1) ) # Prepare the head (centered text) format_str = "{0}|".format(prefix) for column, length in enumerate(lengths): format_str += " {%d:^%d} |" % (column, length) head_str = format_str.format(*headers) # Prepare the separator, according the length of the headers string separator = "{0}{1}".format(prefix, "-" * (len(head_str) - len(prefix))) idx = head_str.find("|") while idx != -1: separator = "+".join((separator[:idx], separator[idx + 1 :])) idx = head_str.find("|", idx + 1) # Prepare the output output = [separator, head_str, separator.replace("-", "=")] # Compute the lines format_str = format_str.replace("^", "<") for line in str_lines: output.append(format_str.format(*line)) output.append(separator) # Force the last end of line output.append("") # Join'em return "\n".join(output)
[ "def", "make_table", "(", "headers", ",", "lines", ",", "prefix", "=", "None", ")", ":", "# Normalize the prefix", "prefix", "=", "str", "(", "prefix", "or", "\"\"", ")", "# Maximum lengths", "lengths", "=", "[", "len", "(", "title", ")", "for", "title", ...
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
[ "Generates", "an", "ASCII", "table", "according", "to", "the", "given", "headers", "and", "lines" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L96-L180
9,771
tcalmant/ipopo
pelix/shell/core.py
_ShellService.bind_handler
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 service methods directly for command, method in handler.get_methods(): self.register_command(namespace, command, method) commands.append(command) # Store the reference self._bound_references[svc_ref] = handler self._reference_commands[svc_ref] = (namespace, commands) return True
python
def bind_handler(self, svc_ref): 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 service methods directly for command, method in handler.get_methods(): self.register_command(namespace, command, method) commands.append(command) # Store the reference self._bound_references[svc_ref] = handler self._reference_commands[svc_ref] = (namespace, commands) return True
[ "def", "bind_handler", "(", "self", ",", "svc_ref", ")", ":", "if", "svc_ref", "in", "self", ".", "_bound_references", ":", "# Already bound service", "return", "False", "# Get the service", "handler", "=", "self", ".", "_context", ".", "get_service", "(", "svc_...
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
[ "Called", "if", "a", "command", "service", "has", "been", "found", ".", "Registers", "the", "methods", "of", "this", "service", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L239-L266
9,772
tcalmant/ipopo
pelix/shell/core.py
_ShellService.unbind_handler
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: self.unregister(namespace, command) # Release the service self._context.unget_service(svc_ref) del self._bound_references[svc_ref] del self._reference_commands[svc_ref] return True
python
def unbind_handler(self, svc_ref): 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: self.unregister(namespace, command) # Release the service self._context.unget_service(svc_ref) del self._bound_references[svc_ref] del self._reference_commands[svc_ref] return True
[ "def", "unbind_handler", "(", "self", ",", "svc_ref", ")", ":", "if", "svc_ref", "not", "in", "self", ".", "_bound_references", ":", "# Unknown reference", "return", "False", "# Unregister its commands", "namespace", ",", "commands", "=", "self", ".", "_reference_...
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
[ "Called", "if", "a", "command", "service", "is", "gone", ".", "Unregisters", "its", "commands", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L268-L289
9,773
tcalmant/ipopo
pelix/shell/core.py
_ShellService.bundle_details
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:", ] try: services = bundle.get_registered_services() if services: for svc_ref in services: lines.append("\t{0}".format(svc_ref)) else: lines.append("\tn/a") except constants.BundleException as ex: # Bundle in a invalid state lines.append("\tError: {0}".format(ex)) lines.append("Services used by this bundle:") try: services = bundle.get_services_in_use() if services: for svc_ref in services: lines.append("\t{0}".format(svc_ref)) else: lines.append("\tn/a") except constants.BundleException as ex: # Bundle in a invalid state lines.append("\tError: {0}".format(ex)) lines.append("") io_handler.write("\n".join(lines)) return None
python
def bundle_details(self, io_handler, bundle_id): 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:", ] try: services = bundle.get_registered_services() if services: for svc_ref in services: lines.append("\t{0}".format(svc_ref)) else: lines.append("\tn/a") except constants.BundleException as ex: # Bundle in a invalid state lines.append("\tError: {0}".format(ex)) lines.append("Services used by this bundle:") try: services = bundle.get_services_in_use() if services: for svc_ref in services: lines.append("\t{0}".format(svc_ref)) else: lines.append("\tn/a") except constants.BundleException as ex: # Bundle in a invalid state lines.append("\tError: {0}".format(ex)) lines.append("") io_handler.write("\n".join(lines)) return None
[ "def", "bundle_details", "(", "self", ",", "io_handler", ",", "bundle_id", ")", ":", "bundle", "=", "None", "try", ":", "# Convert the given ID into an integer", "bundle_id", "=", "int", "(", "bundle_id", ")", "except", "ValueError", ":", "# Not an integer, suppose ...
Prints the details of the bundle with the given ID or name
[ "Prints", "the", "details", "of", "the", "bundle", "with", "the", "given", "ID", "or", "name" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L315-L379
9,774
tcalmant/ipopo
pelix/shell/core.py
_ShellService.bundles_list
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 ( bundle.get_bundle_id(), bundle.get_symbolic_name(), self._utils.bundlestate_to_str(bundle.get_state()), bundle.get_version(), ) ] for bundle in bundles ] # Print'em all io_handler.write(self._utils.make_table(headers, lines)) if name is None: io_handler.write_line("{0} bundles installed", len(lines)) else: io_handler.write_line("{0} filtered bundles", len(lines))
python
def bundles_list(self, io_handler, name=None): # 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 ( bundle.get_bundle_id(), bundle.get_symbolic_name(), self._utils.bundlestate_to_str(bundle.get_state()), bundle.get_version(), ) ] for bundle in bundles ] # Print'em all io_handler.write(self._utils.make_table(headers, lines)) if name is None: io_handler.write_line("{0} bundles installed", len(lines)) else: io_handler.write_line("{0} filtered bundles", len(lines))
[ "def", "bundles_list", "(", "self", ",", "io_handler", ",", "name", "=", "None", ")", ":", "# Head of the table", "headers", "=", "(", "\"ID\"", ",", "\"Name\"", ",", "\"State\"", ",", "\"Version\"", ")", "# Get the bundles", "bundles", "=", "self", ".", "_c...
Lists the bundles in the framework and their state. Possibility to filter on the bundle name.
[ "Lists", "the", "bundles", "in", "the", "framework", "and", "their", "state", ".", "Possibility", "to", "filter", "on", "the", "bundle", "name", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L381-L423
9,775
tcalmant/ipopo
pelix/shell/core.py
_ShellService.service_details
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) ), "Rank..........: {0}".format( svc_ref.get_property(constants.SERVICE_RANKING) ), "Specifications: {0}".format( svc_ref.get_property(constants.OBJECTCLASS) ), "Bundle........: {0}".format(svc_ref.get_bundle()), "Properties....:", ] for key, value in sorted(svc_ref.get_properties().items()): lines.append("\t{0} = {1}".format(key, value)) lines.append("Bundles using this service:") for bundle in svc_ref.get_using_bundles(): lines.append("\t{0}".format(bundle)) lines.append("") io_handler.write("\n".join(lines)) return None
python
def service_details(self, io_handler, service_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) ), "Rank..........: {0}".format( svc_ref.get_property(constants.SERVICE_RANKING) ), "Specifications: {0}".format( svc_ref.get_property(constants.OBJECTCLASS) ), "Bundle........: {0}".format(svc_ref.get_bundle()), "Properties....:", ] for key, value in sorted(svc_ref.get_properties().items()): lines.append("\t{0} = {1}".format(key, value)) lines.append("Bundles using this service:") for bundle in svc_ref.get_using_bundles(): lines.append("\t{0}".format(bundle)) lines.append("") io_handler.write("\n".join(lines)) return None
[ "def", "service_details", "(", "self", ",", "io_handler", ",", "service_id", ")", ":", "svc_ref", "=", "self", ".", "_context", ".", "get_service_reference", "(", "None", ",", "\"({0}={1})\"", ".", "format", "(", "constants", ".", "SERVICE_ID", ",", "service_i...
Prints the details of the service with the given ID
[ "Prints", "the", "details", "of", "the", "service", "with", "the", "given", "ID" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L426-L459
9,776
tcalmant/ipopo
pelix/shell/core.py
_ShellService.services_list
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), ) ] for ref in references ] if not lines and specification: # No matching service found io_handler.write_line("No service provides '{0}'", specification) return False # Print'em all io_handler.write(self._utils.make_table(headers, lines)) io_handler.write_line("{0} services registered", len(lines)) return None
python
def services_list(self, io_handler, specification=None): # 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), ) ] for ref in references ] if not lines and specification: # No matching service found io_handler.write_line("No service provides '{0}'", specification) return False # Print'em all io_handler.write(self._utils.make_table(headers, lines)) io_handler.write_line("{0} services registered", len(lines)) return None
[ "def", "services_list", "(", "self", ",", "io_handler", ",", "specification", "=", "None", ")", ":", "# Head of the table", "headers", "=", "(", "\"ID\"", ",", "\"Specifications\"", ",", "\"Bundle\"", ",", "\"Ranking\"", ")", "# Lines", "references", "=", "(", ...
Lists the services in the framework. Possibility to filter on an exact specification.
[ "Lists", "the", "services", "in", "the", "framework", ".", "Possibility", "to", "filter", "on", "an", "exact", "specification", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L461-L496
9,777
tcalmant/ipopo
pelix/shell/core.py
_ShellService.properties_list
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 lines = [item for item in framework.get_properties().items()] # Sort lines lines.sort() # Print the table io_handler.write(self._utils.make_table(headers, lines))
python
def properties_list(self, io_handler): # Get the framework framework = self._context.get_framework() # Head of the table headers = ("Property Name", "Value") # Lines lines = [item for item in framework.get_properties().items()] # Sort lines lines.sort() # Print the table io_handler.write(self._utils.make_table(headers, lines))
[ "def", "properties_list", "(", "self", ",", "io_handler", ")", ":", "# Get the framework", "framework", "=", "self", ".", "_context", ".", "get_framework", "(", ")", "# Head of the table", "headers", "=", "(", "\"Property Name\"", ",", "\"Value\"", ")", "# Lines",...
Lists the properties of the framework
[ "Lists", "the", "properties", "of", "the", "framework" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L498-L515
9,778
tcalmant/ipopo
pelix/shell/core.py
_ShellService.property_value
def property_value(self, io_handler, name): """ Prints the value of the given property, looking into framework properties then environment variables. """ value = self._context.get_property(name) if value is None: # Avoid printing "None" value = "" io_handler.write_line(str(value))
python
def property_value(self, io_handler, name): value = self._context.get_property(name) if value is None: # Avoid printing "None" value = "" io_handler.write_line(str(value))
[ "def", "property_value", "(", "self", ",", "io_handler", ",", "name", ")", ":", "value", "=", "self", ".", "_context", ".", "get_property", "(", "name", ")", "if", "value", "is", "None", ":", "# Avoid printing \"None\"", "value", "=", "\"\"", "io_handler", ...
Prints the value of the given property, looking into framework properties then environment variables.
[ "Prints", "the", "value", "of", "the", "given", "property", "looking", "into", "framework", "properties", "then", "environment", "variables", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L517-L527
9,779
tcalmant/ipopo
pelix/shell/core.py
_ShellService.environment_list
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()] # Sort lines lines.sort() # Print the table io_handler.write(self._utils.make_table(headers, lines))
python
def environment_list(self, io_handler): # Head of the table headers = ("Environment Variable", "Value") # Lines lines = [item for item in os.environ.items()] # Sort lines lines.sort() # Print the table io_handler.write(self._utils.make_table(headers, lines))
[ "def", "environment_list", "(", "self", ",", "io_handler", ")", ":", "# Head of the table", "headers", "=", "(", "\"Environment Variable\"", ",", "\"Value\"", ")", "# Lines", "lines", "=", "[", "item", "for", "item", "in", "os", ".", "environ", ".", "items", ...
Lists the framework process environment variables
[ "Lists", "the", "framework", "process", "environment", "variables" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L529-L543
9,780
tcalmant/ipopo
pelix/shell/core.py
_ShellService.change_dir
def change_dir(self, session, path): """ Changes the working directory """ if path == "-": # Previous directory path = self._previous_path or "." try: previous = os.getcwd() os.chdir(path) except IOError as ex: # Can't change directory session.write_line("Error changing directory: {0}", ex) else: # Store previous path self._previous_path = previous session.write_line(os.getcwd())
python
def change_dir(self, session, path): if path == "-": # Previous directory path = self._previous_path or "." try: previous = os.getcwd() os.chdir(path) except IOError as ex: # Can't change directory session.write_line("Error changing directory: {0}", ex) else: # Store previous path self._previous_path = previous session.write_line(os.getcwd())
[ "def", "change_dir", "(", "self", ",", "session", ",", "path", ")", ":", "if", "path", "==", "\"-\"", ":", "# Previous directory", "path", "=", "self", ".", "_previous_path", "or", "\".\"", "try", ":", "previous", "=", "os", ".", "getcwd", "(", ")", "o...
Changes the working directory
[ "Changes", "the", "working", "directory" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L704-L721
9,781
tcalmant/ipopo
pelix/shell/core.py
_ShellService.start
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 bundle is not None: io_handler.write_line( "Starting bundle {0} ({1})...", bid, bundle.get_symbolic_name(), ) bundle.start() else: return False return None
python
def start(self, io_handler, bundle_id, *bundles_ids): 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 bundle is not None: io_handler.write_line( "Starting bundle {0} ({1})...", bid, bundle.get_symbolic_name(), ) bundle.start() else: return False return None
[ "def", "start", "(", "self", ",", "io_handler", ",", "bundle_id", ",", "*", "bundles_ids", ")", ":", "for", "bid", "in", "(", "bundle_id", ",", ")", "+", "bundles_ids", ":", "try", ":", "# Got an int => it's a bundle ID", "bid", "=", "int", "(", "bid", "...
Starts the bundles with the given IDs. Stops on first failure.
[ "Starts", "the", "bundles", "with", "the", "given", "IDs", ".", "Stops", "on", "first", "failure", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L750-L773
9,782
tcalmant/ipopo
pelix/shell/core.py
_ShellService.stop
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})...", bid, bundle.get_symbolic_name(), ) bundle.stop() else: return False return None
python
def stop(self, io_handler, bundle_id, *bundles_ids): 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})...", bid, bundle.get_symbolic_name(), ) bundle.stop() else: return False return None
[ "def", "stop", "(", "self", ",", "io_handler", ",", "bundle_id", ",", "*", "bundles_ids", ")", ":", "for", "bid", "in", "(", "bundle_id", ",", ")", "+", "bundles_ids", ":", "bundle", "=", "self", ".", "__get_bundle", "(", "io_handler", ",", "bid", ")",...
Stops the bundles with the given IDs. Stops on first failure.
[ "Stops", "the", "bundles", "with", "the", "given", "IDs", ".", "Stops", "on", "first", "failure", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L776-L792
9,783
tcalmant/ipopo
pelix/shell/core.py
_ShellService.install
def install(self, io_handler, module_name): """ Installs the bundle with the given module name """ bundle = self._context.install_bundle(module_name) io_handler.write_line("Bundle ID: {0}", bundle.get_bundle_id()) return bundle.get_bundle_id()
python
def install(self, io_handler, module_name): bundle = self._context.install_bundle(module_name) io_handler.write_line("Bundle ID: {0}", bundle.get_bundle_id()) return bundle.get_bundle_id()
[ "def", "install", "(", "self", ",", "io_handler", ",", "module_name", ")", ":", "bundle", "=", "self", ".", "_context", ".", "install_bundle", "(", "module_name", ")", "io_handler", ".", "write_line", "(", "\"Bundle ID: {0}\"", ",", "bundle", ".", "get_bundle_...
Installs the bundle with the given module name
[ "Installs", "the", "bundle", "with", "the", "given", "module", "name" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/shell/core.py#L813-L819
9,784
tcalmant/ipopo
pelix/ipopo/handlers/temporal.py
TemporalDependency.__cancel_timer
def __cancel_timer(self): """ Cancels the timer, and calls its target method immediately """ if self.__timer is not None: self.__timer.cancel() self.__unbind_call(True) self.__timer_args = None self.__timer = None
python
def __cancel_timer(self): if self.__timer is not None: self.__timer.cancel() self.__unbind_call(True) self.__timer_args = None self.__timer = None
[ "def", "__cancel_timer", "(", "self", ")", ":", "if", "self", ".", "__timer", "is", "not", "None", ":", "self", ".", "__timer", ".", "cancel", "(", ")", "self", ".", "__unbind_call", "(", "True", ")", "self", ".", "__timer_args", "=", "None", "self", ...
Cancels the timer, and calls its target method immediately
[ "Cancels", "the", "timer", "and", "calls", "its", "target", "method", "immediately" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/handlers/temporal.py#L347-L356
9,785
tcalmant/ipopo
pelix/ipopo/handlers/temporal.py
TemporalDependency.__unbind_call
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 self.__still_valid = still_valid self._ipopo_instance.unbind( self, self.__timer_args[0], self.__timer_args[1] )
python
def __unbind_call(self, still_valid): with self._lock: if self.__timer is not None: # Timeout expired, we're not valid anymore self.__timer = None self.__still_valid = still_valid self._ipopo_instance.unbind( self, self.__timer_args[0], self.__timer_args[1] )
[ "def", "__unbind_call", "(", "self", ",", "still_valid", ")", ":", "with", "self", ".", "_lock", ":", "if", "self", ".", "__timer", "is", "not", "None", ":", "# Timeout expired, we're not valid anymore", "self", ".", "__timer", "=", "None", "self", ".", "__s...
Calls the iPOPO unbind method
[ "Calls", "the", "iPOPO", "unbind", "method" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/handlers/temporal.py#L358-L369
9,786
tcalmant/ipopo
pelix/remote/transport/jabsorb_rpc.py
_JabsorbRpcServlet.do_POST
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 if result is not None: # Convert result to Jabsorb if "result" in result: result["result"] = jabsorb.to_jabsorb(result["result"]) # Store JSON result = jsonrpclib.jdumps(result) else: # It was a notification result = "" # Send the result response.send_content(200, result, "application/json-rpc")
python
def do_POST(self, request, response): # pylint: disable=C0103 # 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 if result is not None: # Convert result to Jabsorb if "result" in result: result["result"] = jabsorb.to_jabsorb(result["result"]) # Store JSON result = jsonrpclib.jdumps(result) else: # It was a notification result = "" # Send the result response.send_content(200, result, "application/json-rpc")
[ "def", "do_POST", "(", "self", ",", "request", ",", "response", ")", ":", "# pylint: disable=C0103", "# Get the request JSON content", "data", "=", "jsonrpclib", ".", "loads", "(", "to_str", "(", "request", ".", "read_data", "(", ")", ")", ")", "# Convert from J...
Handle a POST request :param request: The HTTP request bean :param response: The HTTP response handler
[ "Handle", "a", "POST", "request" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/remote/transport/jabsorb_rpc.py#L124-L157
9,787
tcalmant/ipopo
pelix/http/routing.py
RestDispatcher._rest_dispatch
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: str_value = best_match.group(name) except IndexError: # Argument is missing: do nothing pass else: if str_value: # Keep the default value when an argument is # missing, i.e. don't give it in kwargs if converter is not None: # Convert the argument kwargs[name] = converter(str_value) else: # Use the string value as is kwargs[name] = str_value # Prepare positional arguments extra_pos_args = [] if kwargs: # Ignore the first two parameters (request and response) method_args = get_method_arguments(best_method).args[:2] for pos_arg in method_args: try: extra_pos_args.append(kwargs.pop(pos_arg)) except KeyError: pass # ... call the method (exceptions will be handled by the server) best_method(request, response, *extra_pos_args, **kwargs)
python
def _rest_dispatch(self, request, response): # type: (AbstractHTTPServletRequest, AbstractHTTPServletResponse) -> None # 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: str_value = best_match.group(name) except IndexError: # Argument is missing: do nothing pass else: if str_value: # Keep the default value when an argument is # missing, i.e. don't give it in kwargs if converter is not None: # Convert the argument kwargs[name] = converter(str_value) else: # Use the string value as is kwargs[name] = str_value # Prepare positional arguments extra_pos_args = [] if kwargs: # Ignore the first two parameters (request and response) method_args = get_method_arguments(best_method).args[:2] for pos_arg in method_args: try: extra_pos_args.append(kwargs.pop(pos_arg)) except KeyError: pass # ... call the method (exceptions will be handled by the server) best_method(request, response, *extra_pos_args, **kwargs)
[ "def", "_rest_dispatch", "(", "self", ",", "request", ",", "response", ")", ":", "# type: (AbstractHTTPServletRequest, AbstractHTTPServletResponse) -> None", "# Extract request information", "http_verb", "=", "request", ".", "get_command", "(", ")", "sub_path", "=", "reques...
Dispatches the request :param request: Request bean :param response: Response bean
[ "Dispatches", "the", "request" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/routing.py#L280-L364
9,788
tcalmant/ipopo
pelix/http/routing.py
RestDispatcher._setup_rest_dispatcher
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"]: pattern, arguments = self.__convert_route(route) self.__methods_args.setdefault(method, {}).update(arguments) for http_verb in config["methods"]: self.__routes.setdefault(http_verb, {})[pattern] = method
python
def _setup_rest_dispatcher(self): 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"]: pattern, arguments = self.__convert_route(route) self.__methods_args.setdefault(method, {}).update(arguments) for http_verb in config["methods"]: self.__routes.setdefault(http_verb, {})[pattern] = method
[ "def", "_setup_rest_dispatcher", "(", "self", ")", ":", "for", "_", ",", "method", "in", "inspect", ".", "getmembers", "(", "self", ",", "inspect", ".", "isroutine", ")", ":", "try", ":", "config", "=", "getattr", "(", "method", ",", "HTTP_ROUTE_ATTRIBUTE"...
Finds all methods to call when handling a route
[ "Finds", "all", "methods", "to", "call", "when", "handling", "a", "route" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/http/routing.py#L366-L381
9,789
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.check_event
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 :return: True if the event can be handled, False if it must be ignored """ with self._lock: if self.state == StoredInstance.KILLED: # This call may have been blocked by the internal state lock, # ignore it return False return self.__safe_handlers_callback("check_event", event)
python
def check_event(self, event): # type: (ServiceEvent) -> bool with self._lock: if self.state == StoredInstance.KILLED: # This call may have been blocked by the internal state lock, # ignore it return False return self.__safe_handlers_callback("check_event", event)
[ "def", "check_event", "(", "self", ",", "event", ")", ":", "# type: (ServiceEvent) -> bool", "with", "self", ".", "_lock", ":", "if", "self", ".", "state", "==", "StoredInstance", ".", "KILLED", ":", "# This call may have been blocked by the internal state lock,", "# ...
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 :return: True if the event can be handled, False if it must be ignored
[ "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", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L167-L182
9,790
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.bind
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. """ with self._lock: self.__set_binding(dependency, svc, svc_ref) self.check_lifecycle()
python
def bind(self, dependency, svc, svc_ref): # type: (Any, Any, ServiceReference) -> None with self._lock: self.__set_binding(dependency, svc, svc_ref) self.check_lifecycle()
[ "def", "bind", "(", "self", ",", "dependency", ",", "svc", ",", "svc_ref", ")", ":", "# type: (Any, Any, ServiceReference) -> None", "with", "self", ".", "_lock", ":", "self", ".", "__set_binding", "(", "dependency", ",", "svc", ",", "svc_ref", ")", "self", ...
Called by a dependency manager to inject a new service and update the component life cycle.
[ "Called", "by", "a", "dependency", "manager", "to", "inject", "a", "new", "service", "and", "update", "the", "component", "life", "cycle", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L184-L192
9,791
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.update
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 :param old_properties: Previous properties of the dependency :param new_value: If True, inject the new value of the handler """ with self._lock: self.__update_binding( dependency, svc, svc_ref, old_properties, new_value ) self.check_lifecycle()
python
def update(self, dependency, svc, svc_ref, old_properties, new_value=False): # type: (Any, Any, ServiceReference, dict, bool) -> None with self._lock: self.__update_binding( dependency, svc, svc_ref, old_properties, new_value ) self.check_lifecycle()
[ "def", "update", "(", "self", ",", "dependency", ",", "svc", ",", "svc_ref", ",", "old_properties", ",", "new_value", "=", "False", ")", ":", "# type: (Any, Any, ServiceReference, dict, bool) -> None", "with", "self", ".", "_lock", ":", "self", ".", "__update_bind...
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 :param old_properties: Previous properties of the dependency :param new_value: If True, inject the new value of the handler
[ "Called", "by", "a", "dependency", "manager", "when", "the", "properties", "of", "an", "injected", "dependency", "have", "been", "updated", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L194-L210
9,792
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.unbind
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. """ with self._lock: # Invalidate first (if needed) self.check_lifecycle() # Call unbind() and remove the injection self.__unset_binding(dependency, svc, svc_ref) # Try a new configuration if self.update_bindings(): self.check_lifecycle()
python
def unbind(self, dependency, svc, svc_ref): # type: (Any, Any, ServiceReference) -> None with self._lock: # Invalidate first (if needed) self.check_lifecycle() # Call unbind() and remove the injection self.__unset_binding(dependency, svc, svc_ref) # Try a new configuration if self.update_bindings(): self.check_lifecycle()
[ "def", "unbind", "(", "self", ",", "dependency", ",", "svc", ",", "svc_ref", ")", ":", "# type: (Any, Any, ServiceReference) -> None", "with", "self", ".", "_lock", ":", "# Invalidate first (if needed)", "self", ".", "check_lifecycle", "(", ")", "# Call unbind() and r...
Called by a dependency manager to remove an injected service and to update the component life cycle.
[ "Called", "by", "a", "dependency", "manager", "to", "remove", "an", "injected", "service", "and", "to", "update", "the", "component", "life", "cycle", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L212-L227
9,793
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.set_controller_state
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 """ with self._lock: self._controllers_state[name] = value self.__safe_handlers_callback("on_controller_change", name, value)
python
def set_controller_state(self, name, value): # type: (str, bool) -> None with self._lock: self._controllers_state[name] = value self.__safe_handlers_callback("on_controller_change", name, value)
[ "def", "set_controller_state", "(", "self", ",", "name", ",", "value", ")", ":", "# type: (str, bool) -> None", "with", "self", ".", "_lock", ":", "self", ".", "_controllers_state", "[", "name", "]", "=", "value", "self", ".", "__safe_handlers_callback", "(", ...
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
[ "Sets", "the", "state", "of", "the", "controller", "with", "the", "given", "name" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L240-L250
9,794
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.update_property
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 """ with self._lock: self.__safe_handlers_callback( "on_property_change", name, old_value, new_value )
python
def update_property(self, name, old_value, new_value): # type: (str, Any, Any) -> None with self._lock: self.__safe_handlers_callback( "on_property_change", name, old_value, new_value )
[ "def", "update_property", "(", "self", ",", "name", ",", "old_value", ",", "new_value", ")", ":", "# type: (str, Any, Any) -> None", "with", "self", ".", "_lock", ":", "self", ".", "__safe_handlers_callback", "(", "\"on_property_change\"", ",", "name", ",", "old_v...
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
[ "Handles", "a", "property", "changed", "event" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L252-L264
9,795
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.update_hidden_property
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 """ with self._lock: self.__safe_handlers_callback( "on_hidden_property_change", name, old_value, new_value )
python
def update_hidden_property(self, name, old_value, new_value): # type: (str, Any, Any) -> None with self._lock: self.__safe_handlers_callback( "on_hidden_property_change", name, old_value, new_value )
[ "def", "update_hidden_property", "(", "self", ",", "name", ",", "old_value", ",", "new_value", ")", ":", "# type: (str, Any, Any) -> None", "with", "self", ".", "_lock", ":", "self", ".", "__safe_handlers_callback", "(", "\"on_hidden_property_change\"", ",", "name", ...
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
[ "Handles", "an", "hidden", "property", "changed", "event" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L266-L278
9,796
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.get_handlers
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: return self._handlers[kind][:] except KeyError: return [] return self.__all_handlers.copy()
python
def get_handlers(self, kind=None): with self._lock: if kind is not None: try: return self._handlers[kind][:] except KeyError: return [] return self.__all_handlers.copy()
[ "def", "get_handlers", "(", "self", ",", "kind", "=", "None", ")", ":", "with", "self", ".", "_lock", ":", "if", "kind", "is", "not", "None", ":", "try", ":", "return", "self", ".", "_handlers", "[", "kind", "]", "[", ":", "]", "except", "KeyError"...
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
[ "Retrieves", "the", "handlers", "of", "the", "given", "kind", ".", "If", "kind", "is", "None", "all", "handlers", "are", "returned", "." ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L280-L295
9,797
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.check_lifecycle
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( "is_valid", break_on_false=True ) if was_valid and not handlers_valid: # A dependency is missing self.invalidate(True) elif ( can_validate and handlers_valid and self._ipopo_service.running ): # We're all good self.validate(True)
python
def check_lifecycle(self): 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( "is_valid", break_on_false=True ) if was_valid and not handlers_valid: # A dependency is missing self.invalidate(True) elif ( can_validate and handlers_valid and self._ipopo_service.running ): # We're all good self.validate(True)
[ "def", "check_lifecycle", "(", "self", ")", ":", "with", "self", ".", "_lock", ":", "# Validation flags", "was_valid", "=", "self", ".", "state", "==", "StoredInstance", ".", "VALID", "can_validate", "=", "self", ".", "state", "not", "in", "(", "StoredInstan...
Tests if the state of the component must be updated, based on its own state and on the state of its dependencies
[ "Tests", "if", "the", "state", "of", "the", "component", "must", "be", "updated", "based", "on", "its", "own", "state", "and", "on", "the", "state", "of", "its", "dependencies" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L297-L322
9,798
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.update_bindings
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 self.__safe_handler_callback(handler, "try_binding") # Update the validity flag all_valid &= self.__safe_handler_callback( handler, "is_valid", only_boolean=True, none_as_true=True ) return all_valid
python
def update_bindings(self): # type: () -> bool with self._lock: all_valid = True for handler in self.get_handlers(handlers_const.KIND_DEPENDENCY): # Try to bind self.__safe_handler_callback(handler, "try_binding") # Update the validity flag all_valid &= self.__safe_handler_callback( handler, "is_valid", only_boolean=True, none_as_true=True ) return all_valid
[ "def", "update_bindings", "(", "self", ")", ":", "# type: () -> bool", "with", "self", ".", "_lock", ":", "all_valid", "=", "True", "for", "handler", "in", "self", ".", "get_handlers", "(", "handlers_const", ".", "KIND_DEPENDENCY", ")", ":", "# Try to bind", "...
Updates the bindings of the given component :return: True if the component can be validated
[ "Updates", "the", "bindings", "of", "the", "given", "component" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L324-L341
9,799
tcalmant/ipopo
pelix/ipopo/instance.py
StoredInstance.retry_erroneous
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 properties_update: self.context.properties.update(properties_update) # Reset state self.state = StoredInstance.INVALID self.error_trace = None # Retry self.check_lifecycle() # Check if the component is still erroneous return self.state
python
def retry_erroneous(self, properties_update): # type: (dict) -> int with self._lock: if self.state != StoredInstance.ERRONEOUS: # Not in erroneous state: ignore return self.state # Update properties if properties_update: self.context.properties.update(properties_update) # Reset state self.state = StoredInstance.INVALID self.error_trace = None # Retry self.check_lifecycle() # Check if the component is still erroneous return self.state
[ "def", "retry_erroneous", "(", "self", ",", "properties_update", ")", ":", "# type: (dict) -> int", "with", "self", ".", "_lock", ":", "if", "self", ".", "state", "!=", "StoredInstance", ".", "ERRONEOUS", ":", "# Not in erroneous state: ignore", "return", "self", ...
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
[ "Removes", "the", "ERRONEOUS", "state", "from", "a", "component", "and", "retries", "a", "validation" ]
2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1
https://github.com/tcalmant/ipopo/blob/2f9ae0c44cd9c34ef1a9d50837b3254e75678eb1/pelix/ipopo/instance.py#L350-L375