Parser#

class Parser(**properties: Any)#

Superclasses: 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 DataFormat enumeration.

In order to parse data, a new parser is created with new() and then the authenticate and parsed signals should be connected to. Data is then fed to the parser via parse_data or parse_stream.

During the parsed signal the attributes that make up the currently parsed item can be retrieved using the get_parsed_attributes function.

Constructors#

class Parser
classmethod new() Parser#

Create a new Parser

Methods#

class Parser
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 authenticate signal.

Parameters:

password – a password to try

format_disable(format: DataFormat) None#

Disable parsing of the given format. Use ALL to disable all the formats.

Parameters:

format – The format identifier

format_enable(format: DataFormat) None#

Enable parsing of the given format. Use ALL to enable all the formats.

Parameters:

format – The format identifier

format_supported(format: DataFormat) bool#

Check whether the given format is supported by the parser.

Parameters:

format – The format identifier

get_filename() str#

Get the filename of the parser item.

get_parsed() Parsed#

Get the currently parsed item

get_parsed_attributes() Attributes | None#

Get the attributes which make up the currently parsed item. This is generally only valid during the parsed signal.

get_parsed_block() bytes | None#

Get the raw data block that represents this parsed object. This is only valid during the parsed signal.

get_parsed_bytes() Bytes#

Get the raw data block that represents this parsed object. This is only valid during the parsed signal.

get_parsed_description() str | None#

Get a description for the type of the currently parsed item. This is generally only valid during the parsed signal.

get_parsed_format() DataFormat#

Get the format of the raw data block that represents this parsed object. This corresponds with the data returned from get_parsed_block.

This is only valid during the parsed signal.

get_parsed_label() str | None#

Get the label of the currently parsed item. This is generally only valid during the parsed signal.

parse_bytes(data: Bytes) bool#

Parse the data. The parsed and authenticate signals may fire during the parsing.

Parameters:

data – the data to parse

parse_data(data: Sequence[int]) bool#

Parse the data. The parsed and authenticate signals may fire during the parsing.

A copy of the data will be made. Use parse_bytes to avoid this.

Parameters:

data – the data to parse

parse_stream(input: InputStream, cancellable: Cancellable | None = None) bool#

Parse items from the data in a InputStream. This function may block while reading from the input stream. Use parse_stream_async for a non-blocking variant.

The parsed and authenticate signals may fire during the parsing.

Parameters:
  • input – The input stream

  • cancellable – An optional cancellation object

parse_stream_async(input: InputStream, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None#

Parse items from the data in a InputStream. This function completes asyncronously and doesn’t block.

The parsed and authenticate signals may fire during the parsing.

Parameters:
  • input – The input stream

  • cancellable – An optional cancellation object

  • callback – Called when the operation result is ready.

  • user_data – Data to pass to callback

parse_stream_finish(result: AsyncResult) bool#

Complete an operation to parse a stream.

Parameters:

result – The operation result

set_filename(filename: str | None = None) None#

Sets the filename of the parser item.

Parameters:

filename – a string of the filename of the parser item

Properties#

class Parser
props.parsed_attributes: Attributes#

The type of the None singleton.

props.parsed_description: str#

The type of the None singleton.

props.parsed_label: str#

The type of the None singleton.

Signals#

class Parser.signals
authenticate(count: int) bool#

The type of the None singleton.

Parameters:

count – the number of times this item has been authenticated

parsed() None#

The type of the None singleton.

Virtual Methods#

class Parser
do_authenticate(count: int) bool#

The type of the None singleton.

Parameters:

count

do_parsed() None#

The type of the None singleton.

Fields#

class Parser
parent#
pv#