:mod:`lookout.core.data_requests` ================================= .. py:module:: lookout.core.data_requests Module Contents --------------- .. py:exception:: UnsatisfiedDriverVersionError(mismatched:Iterable[Tuple[str, str]]) Bases::class:`Exception` Exception which is raised if there is a mismatching Babelfish driver version. .. py:class:: DataService(address:str) Retrieves UASTs/files from the Lookout server. .. method:: get_data(self) Return a `DataStub` for the current thread. .. method:: get_bblfsh(self) Return a Babelfish `ProtocolServiceStub` for the current thread. .. method:: check_bblfsh_driver_versions(self, versions:Iterable[str]) Ensure that the Babelfish drivers match the required versions. The check is performed by `packaging.version`. :param versions: setup.py-like version specifiers, e.g. "javascript==1.3.0". :return: Nothing :raise UnsatisfiedDriverVersionError: if there is one or more mismatches. .. method:: shutdown(self) Close all the open network connections. .. method:: close_channel(self) Close the current channel and free all the associated resources. .. function:: handle_analyze_rpc_errors(func) Decorator to properly handle rps errors that is close related DataService channel before pass the exception. :param func: Method to decorate. :return: The decorated method. .. function:: with_changed_uasts(unicode:bool) Decorator to provide "changes" keyword argument to `**data` in `Analyzer.analyze()`. "changes" contain the list of `Change` - see lookout/core/server/sdk/service_data.proto. The changes will have only UASTs, no raw file contents. Decorated method should have a signature compatible with `Analyzer.analyze()`. :param unicode: Value indicating whether `content` and UAST positions should be converted to Unicode. False keeps DataService response untouched. :return: The decorated method. .. function:: with_changed_contents(unicode:bool) Decorator to provide "changes" keyword argument to `**data` in `Analyzer.analyze()`. "changes" contain the list of `Change` - see lookout/core/server/sdk/service_data.proto. The changes will have only raw file contents, no UASTs. Decorated method should have a signature compatible with `Analyzer.analyze()`. :param unicode: Value indicating whether `content` and UAST positions should be converted to Unicode. False keeps DataService response untouched. :return: The decorated method. .. function:: with_changed_uasts_and_contents(unicode:bool) Decorator to provide "changes" keyword argument to `**data` in `Analyzer.analyze()`. "changes" contain the list of `Change` - see lookout/core/server/sdk/service_data.proto. The changes will have both UASTs and raw file contents. Decorated method should have a signature compatible with `Analyzer.analyze()`. :param unicode: Value indicating whether `content` and UAST positions should be converted to Unicode. False keeps DataService response untouched. :return: The decorated method. .. function:: with_uasts(unicode:bool) Decorator to provide "files" keyword argument to `**data` in `Analyzer.train()`. They only contain the UASTs. "files" are the list of `File`-s with all the data for the passed Git repository URL and revision, see lookout/core/server/sdk/service_data.proto. Decorated method should have a signature compatible with `Analyzer.train()`. :param unicode: Value indicating whether `content` and UAST positions should be converted to Unicode. False keeps DataService response untouched. :return: The decorated method. .. function:: with_contents(unicode:bool) Decorator to provide "files" keyword argument to `**data` in `Analyzer.train()`. They only contain the raw file contents. "files" are the list of `File`-s with all the data for the passed Git repository URL and revision, see lookout/core/server/sdk/service_data.proto. Decorated method should have a signature compatible with `Analyzer.train()`. :param unicode: Value indicating whether `content` and UAST positions should be converted to Unicode. False keeps DataService response untouched. :return: The decorated method. .. function:: with_uasts_and_contents(unicode:bool) Decorator to provide "files" keyword argument to `**data` in `Analyzer.train()`. They contain both the raw file contents and the UASTs. "files" are the list of `File`-s with all the UASTs and raw file contents for the passed Git repository URL and revision, see lookout/core/server/sdk/service_data.proto. Decorated method should have a signature compatible with `Analyzer.train()`. :param unicode: Value indicating whether `content` and UAST positions should be converted to Unicode. False keeps DataService response untouched. :return: The decorated method. .. function:: request_changes(stub:DataStub, ptr_from:ReferencePointer, ptr_to:ReferencePointer, contents:bool, uast:bool, unicode:bool) Invoke GRPC API and get the changes. Used by `with_changed_uasts()` and Review events. :return: The stream of the gRPC invocation results. In theory, `.result()` would turn this into a synchronous call, but in practice, that function call hangs for some reason. .. function:: request_files(stub:DataStub, ptr:ReferencePointer, contents:bool, uast:bool, unicode:bool) Invoke GRPC API and get the files. Used by `with_uasts()` and Push events. :return: The stream of the gRPC invocation results. .. function:: parse_uast(stub:bblfsh.aliases.ProtocolServiceStub, code:str, filename:str, unicode:bool, language:Optional[str]=None) Return UAST for given file contents and name. :param stub: The Babelfish protocol stub. :param code: The contents of the file. :param filename: The name of the file, can be a full path. :param language: The name of the language. It is not required to set: Babelfish can autodetect it. :param unicode: Set to True if UAST position information should be converted to unicode positions. :return: The parsed UAST or undefined object if there was an error; the list of parsing errors.