:right-sidebar: True Parser =================================================================== .. currentmodule:: gi.repository.Gcr .. class:: Parser(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` A parser for parsing various types of files or data. A ``GcrParser`` can parse various certificate and key files such as OpenSSL PEM files, DER encoded certifictes, PKCS``8`` keys and so on. Each various format is identified by a value in the :obj:`~gi.repository.Gcr.DataFormat` enumeration. In order to parse data, a new parser is created with :func:`~gi.repository.Gcr.Parser.new` and then the :obj:`~gi.repository.Gcr.Parser.signals.authenticate` and :obj:`~gi.repository.Gcr.Parser.signals.parsed` signals should be connected to. Data is then fed to the parser via :obj:`~gi.repository.Parser.parse_data` or :obj:`~gi.repository.Parser.parse_stream`\. During the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal the attributes that make up the currently parsed item can be retrieved using the :obj:`~gi.repository.Parser.get_parsed_attributes` function. Constructors ------------ .. rst-class:: interim-class .. class:: Parser :no-index: .. classmethod:: new() -> ~gi.repository.Gcr.Parser Create a new :obj:`~gi.repository.Gcr.Parser` Methods ------- .. rst-class:: interim-class .. class:: Parser :no-index: .. method:: add_password(password: str | None = None) -> None Add a password to the set of passwords to try when parsing locked or encrypted items. This is usually called from the :obj:`~gi.repository.Gcr.Parser.signals.authenticate` signal. :param password: a password to try .. method:: do_authenticate(self, count: int) -> bool :param count: .. method:: do_parsed(self) -> None .. method:: format_disable(format: ~gi.repository.Gcr.DataFormat) -> None Disable parsing of the given format. Use :const:`~gi.repository.Gcr.DataFormat.ALL` to disable all the formats. :param format: The format identifier .. method:: format_enable(format: ~gi.repository.Gcr.DataFormat) -> None Enable parsing of the given format. Use :const:`~gi.repository.Gcr.DataFormat.ALL` to enable all the formats. :param format: The format identifier .. method:: format_supported(format: ~gi.repository.Gcr.DataFormat) -> bool Check whether the given format is supported by the parser. :param format: The format identifier .. method:: get_filename() -> str Get the filename of the parser item. .. method:: get_parsed() -> ~gi.repository.Gcr.Parsed Get the currently parsed item .. method:: get_parsed_attributes() -> ~gi.repository.Gck.Attributes | None Get the attributes which make up the currently parsed item. This is generally only valid during the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal. .. method:: get_parsed_block() -> list[int] | None Get the raw data block that represents this parsed object. This is only valid during the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal. .. method:: get_parsed_bytes() -> ~gi.repository.GLib.Bytes Get the raw data block that represents this parsed object. This is only valid during the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal. .. method:: get_parsed_description() -> str | None Get a description for the type of the currently parsed item. This is generally only valid during the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal. .. method:: get_parsed_format() -> ~gi.repository.Gcr.DataFormat Get the format of the raw data block that represents this parsed object. This corresponds with the data returned from :obj:`~gi.repository.Parser.get_parsed_block`\. This is only valid during the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal. .. method:: get_parsed_label() -> str | None Get the label of the currently parsed item. This is generally only valid during the :obj:`~gi.repository.Gcr.Parser.signals.parsed` signal. .. method:: parse_bytes(data: ~gi.repository.GLib.Bytes) -> bool Parse the data. The :obj:`~gi.repository.Gcr.Parser.signals.parsed` and :obj:`~gi.repository.Gcr.Parser.signals.authenticate` signals may fire during the parsing. :param data: the data to parse .. method:: parse_data(data: list[int]) -> bool Parse the data. The :obj:`~gi.repository.Gcr.Parser.signals.parsed` and :obj:`~gi.repository.Gcr.Parser.signals.authenticate` signals may fire during the parsing. A copy of the data will be made. Use :obj:`~gi.repository.Parser.parse_bytes` to avoid this. :param data: the data to parse .. method:: parse_stream(input: ~gi.repository.Gio.InputStream, cancellable: ~gi.repository.Gio.Cancellable | None = None) -> bool Parse items from the data in a :obj:`~gi.repository.Gio.InputStream`\. This function may block while reading from the input stream. Use :obj:`~gi.repository.Parser.parse_stream_async` for a non-blocking variant. The :obj:`~gi.repository.Gcr.Parser.signals.parsed` and :obj:`~gi.repository.Gcr.Parser.signals.authenticate` signals may fire during the parsing. :param input: The input stream :param cancellable: An optional cancellation object .. method:: parse_stream_async(input: ~gi.repository.Gio.InputStream, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[~gi.repository.GObject.Object | None, ~gi.repository.Gio.AsyncResult, ~typing.Any], None] | None = None, user_data: ~typing.Any = None) -> None Parse items from the data in a :obj:`~gi.repository.Gio.InputStream`\. This function completes asyncronously and doesn't block. The :obj:`~gi.repository.Gcr.Parser.signals.parsed` and :obj:`~gi.repository.Gcr.Parser.signals.authenticate` signals may fire during the parsing. :param input: The input stream :param cancellable: An optional cancellation object :param callback: Called when the operation result is ready. :param user_data: Data to pass to callback .. method:: parse_stream_finish(result: ~gi.repository.Gio.AsyncResult) -> bool Complete an operation to parse a stream. :param result: The operation result .. method:: set_filename(filename: str | None = None) -> None Sets the filename of the parser item. :param filename: a string of the filename of the parser item Properties ---------- .. rst-class:: interim-class .. class:: Parser :no-index: .. attribute:: props.parsed_attributes :type: ~gi.repository.Gck.Attributes The type of the None singleton. .. attribute:: props.parsed_description :type: str The type of the None singleton. .. attribute:: props.parsed_label :type: str The type of the None singleton. Signals ------- .. rst-class:: interim-class .. class:: Parser.signals :no-index: .. method:: authenticate(count: int) -> bool The type of the None singleton. :param count: the number of times this item has been authenticated .. method:: parsed() -> None The type of the None singleton. Virtual Methods --------------- .. rst-class:: interim-class .. class:: Parser :no-index: .. method:: do_authenticate(count: int) -> bool The type of the None singleton. :param count: .. method:: do_parsed() -> None The type of the None singleton. Fields ------ .. rst-class:: interim-class .. class:: Parser :no-index: .. attribute:: parent .. attribute:: pv